periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Benjamin Valentin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef PERIPH_CONF_H
20 #define PERIPH_CONF_H
21 
22 #include <stdint.h>
23 
24 #include "cpu.h"
25 #include "periph_cpu.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
62 #define CLOCK_USE_PLL (1)
63 
64 #if CLOCK_USE_PLL
65 /* edit these values to adjust the PLL output frequency */
66 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
67 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
68 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
69 #else
70 /* edit this value to your needs */
71 #define CLOCK_DIV (1U)
72 /* generate the actual core clock frequency */
73 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
74 #endif
75 
81 static const tc32_conf_t timer_config[] = {
82  { /* Timer 0 - System Clock */
83  .dev = TC3,
84  .irq = TC3_IRQn,
85  .pm_mask = PM_APBCMASK_TC3,
86  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
87 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
88  .gclk_src = SAM0_GCLK_1MHZ,
89 #else
90  .gclk_src = SAM0_GCLK_MAIN,
91 #endif
92  .flags = TC_CTRLA_MODE_COUNT16,
93  },
94  { /* Timer 1 */
95  .dev = TC4,
96  .irq = TC4_IRQn,
97  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
98  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
99 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
100  .gclk_src = SAM0_GCLK_1MHZ,
101 #else
102  .gclk_src = SAM0_GCLK_MAIN,
103 #endif
104  .flags = TC_CTRLA_MODE_COUNT32,
105  }
106 };
107 
108 #define TIMER_0_MAX_VALUE 0xffff
109 
110 /* interrupt function name mapping */
111 #define TIMER_0_ISR isr_tc3
112 #define TIMER_1_ISR isr_tc4
113 
114 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
115 
121 static const uart_conf_t uart_config[] = {
122  {
123  .dev = &SERCOM2->USART,
124  .rx_pin = GPIO_PIN(PA, 9), /* D5 */
125  .tx_pin = GPIO_PIN(PA, 8), /* D4 */
126  .mux = GPIO_MUX_D,
127  .rx_pad = UART_PAD_RX_1,
128  .tx_pad = UART_PAD_TX_0,
129  .flags = UART_FLAG_NONE,
130  .gclk_src = SAM0_GCLK_MAIN,
131  },
132  {
133  .dev = &SERCOM0->USART,
134  .rx_pin = GPIO_PIN(PA, 5), /* D1 */
135  .tx_pin = GPIO_PIN(PA, 4), /* D0 */
136  .mux = GPIO_MUX_D,
137  .rx_pad = UART_PAD_RX_1,
138  .tx_pad = UART_PAD_TX_0,
139  .flags = UART_FLAG_NONE,
140  .gclk_src = SAM0_GCLK_MAIN,
141  }
142 };
143 
144 /* interrupt function name mapping */
145 #define UART_0_ISR isr_sercom2
146 #define UART_1_ISR isr_sercom0
147 
148 #define UART_NUMOF ARRAY_SIZE(uart_config)
149 
155 #define PWM_0_EN 1
156 #define PWM_1_EN 1
157 
158 #if PWM_0_EN
159 /* PWM0 channels */
160 static const pwm_conf_chan_t pwm_chan0_config[] = {
161  /* GPIO pin, MUX value, TCC channel */
162  { GPIO_PIN(PA, 4), GPIO_MUX_E, 0 },
163  { GPIO_PIN(PA, 5), GPIO_MUX_E, 1 },
164  { GPIO_PIN(PA, 19), GPIO_MUX_F, 3 },
165  { GPIO_PIN(PA, 22), GPIO_MUX_F, 4 },
166  { GPIO_PIN(PA, 23), GPIO_MUX_F, 5 },
167 };
168 #endif
169 #if PWM_1_EN
170 /* PWM1 channels */
171 static const pwm_conf_chan_t pwm_chan1_config[] = {
172  /* GPIO pin, MUX value, TCC channel */
173  { GPIO_PIN(PA, 6), GPIO_MUX_E, 0 },
174  { GPIO_PIN(PA, 7), GPIO_MUX_E, 1 },
175 };
176 #endif
177 
178 /* PWM device configuration */
179 static const pwm_conf_t pwm_config[] = {
180 #if PWM_0_EN
181  {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
182 #endif
183 #if PWM_1_EN
184  {TCC_CONFIG(TCC1), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
185 #endif
186 };
187 
188 /* number of devices that are actually defined */
189 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
190 
196 static const spi_conf_t spi_config[] = {
197  { /* Flash */
198  .dev = &SERCOM1->SPI,
199  .miso_pin = GPIO_PIN(PA, 18),
200  .mosi_pin = GPIO_PIN(PA, 16),
201  .clk_pin = GPIO_PIN(PA, 17),
202  .miso_mux = GPIO_MUX_C,
203  .mosi_mux = GPIO_MUX_C,
204  .clk_mux = GPIO_MUX_C,
205  .miso_pad = SPI_PAD_MISO_2,
206  .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
207  .gclk_src = SAM0_GCLK_MAIN,
208 #ifdef MODULE_PERIPH_DMA
209  .tx_trigger = SERCOM1_DMAC_ID_TX,
210  .rx_trigger = SERCOM1_DMAC_ID_RX,
211 #endif
212  },
213  { /* D0 … D2 (user pins) */
214  .dev = &SERCOM0->SPI,
215  .miso_pin = GPIO_PIN(PA, 6), /* D2 */
216  .mosi_pin = GPIO_PIN(PA, 4), /* D0 */
217  .clk_pin = GPIO_PIN(PA, 5), /* D1 */
218  .miso_mux = GPIO_MUX_D,
219  .mosi_mux = GPIO_MUX_D,
220  .clk_mux = GPIO_MUX_D,
221  .miso_pad = SPI_PAD_MISO_2,
222  .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
223  .gclk_src = SAM0_GCLK_MAIN,
224 #ifdef MODULE_PERIPH_DMA
225  .tx_trigger = SERCOM0_DMAC_ID_TX,
226  .rx_trigger = SERCOM0_DMAC_ID_RX,
227 #endif
228  },
229 };
230 
231 #define SPI_NUMOF ARRAY_SIZE(spi_config)
232 
238 static const i2c_conf_t i2c_config[] = {
239  {
240  .dev = &(SERCOM2->I2CM),
241  .speed = I2C_SPEED_NORMAL,
242  .scl_pin = GPIO_PIN(PA, 9), /* D5 */
243  .sda_pin = GPIO_PIN(PA, 8), /* D4 */
244  .mux = GPIO_MUX_D,
245  .gclk_src = SAM0_GCLK_MAIN,
246  .flags = I2C_FLAG_NONE
247  }
248 };
249 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
250 
256 #ifndef RTT_FREQUENCY
257 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
258 #endif
259 
265 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
266 
267 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
268 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
269 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
270 
271 static const adc_conf_chan_t adc_channels[] = {
272  /* port, pin, muxpos */
273  {GPIO_PIN(PA, 4), ADC_INPUTCTRL_MUXPOS_PIN4},
274  {GPIO_PIN(PA, 5), ADC_INPUTCTRL_MUXPOS_PIN5},
275  {GPIO_PIN(PA, 6), ADC_INPUTCTRL_MUXPOS_PIN6},
276  {GPIO_PIN(PA, 7), ADC_INPUTCTRL_MUXPOS_PIN7},
277  {GPIO_PIN(PA, 8), ADC_INPUTCTRL_MUXPOS_PIN16},
278  {GPIO_PIN(PA, 9), ADC_INPUTCTRL_MUXPOS_PIN17},
279 };
280 
281 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
282 
289 static const sam0_common_usb_config_t sam_usbdev_config[] = {
290  {
291  .dm = GPIO_PIN(PA, 24),
292  .dp = GPIO_PIN(PA, 25),
293  .d_mux = GPIO_MUX_G,
294  .device = &USB->DEVICE,
295  .gclk_src = SAM0_GCLK_MAIN,
296  }
297 };
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #endif /* PERIPH_CONF_H */
305 
GPIO_MUX_F
@ GPIO_MUX_F
select peripheral function F
Definition: periph_cpu_common.h:141
SAM0_GCLK_MAIN
@ SAM0_GCLK_MAIN
48 MHz main clock
Definition: periph_cpu.h:59
GPIO_MUX_E
@ GPIO_MUX_E
select peripheral function E
Definition: periph_cpu_common.h:140
I2C_SPEED_NORMAL
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: i2c.h:177
UART_PAD_TX_0
@ UART_PAD_TX_0
select pad 0
Definition: periph_cpu_common.h:161
I2C_FLAG_NONE
@ I2C_FLAG_NONE
No flags set.
Definition: periph_cpu_common.h:407
UART_FLAG_NONE
@ UART_FLAG_NONE
No flags set.
Definition: periph_cpu_common.h:171
sam0_common_usb_config_t
USB peripheral parameters.
Definition: periph_cpu_common.h:774
sam0_common_usb_config_t::dm
gpio_t dm
D- line gpio
Definition: periph_cpu_common.h:775
ARRAY_SIZE
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: kernel_defines.h:122
pwm_conf_t
PWM device configuration.
Definition: periph_cpu_common.h:153
UART_PAD_RX_1
@ UART_PAD_RX_1
select pad 1
Definition: periph_cpu_common.h:152
pwm_conf_chan_t
PWM channel configuration data structure.
Definition: periph_cpu_common.h:307
uart_conf_t
UART device configuration.
Definition: periph_cpu.h:166
adc_channels
static const gpio_t adc_channels[]
Static array with declared ADC channels.
Definition: periph_conf_common.h:53
tc32_conf_t::dev
Tc * dev
pointer to the used Timer device
Definition: periph_cpu_common.h:462
GPIO_MUX_C
@ GPIO_MUX_C
select peripheral function C
Definition: periph_cpu_common.h:138
SPI_PAD_MOSI_0_SCK_1
@ SPI_PAD_MOSI_0_SCK_1
use pad 0 for MOSI, pad 1 for SCK
Definition: periph_cpu_common.h:337
uart_conf_t::dev
cc2538_uart_t * dev
pointer to the used UART device
Definition: periph_cpu.h:167
GPIO_PIN
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:35
adc_conf_chan_t
ADC Channel Configuration.
Definition: periph_cpu_common.h:765
tc32_conf_t
Timer device configuration.
Definition: periph_cpu_common.h:461
GPIO_MUX_D
@ GPIO_MUX_D
select peripheral function D
Definition: periph_cpu_common.h:139
PA
@ PA
port A
Definition: periph_cpu_common.h:88
SPI_PAD_MISO_2
@ SPI_PAD_MISO_2
use pad 0 for MISO line
Definition: periph_cpu_common.h:329
i2c_conf_t
I2C configuration options.
Definition: periph_cpu.h:128
SAM0_GCLK_1MHZ
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition: periph_cpu.h:60
GPIO_MUX_G
@ GPIO_MUX_G
select peripheral function G
Definition: periph_cpu_common.h:142
spi_conf_t::dev
SPI_Type * dev
SPI device to use.
Definition: periph_cpu.h:465
TCC_CONFIG
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
Definition: periph_cpu_common.h:297
spi_conf_t
SPI configuration structure type.
Definition: periph_cpu.h:273
i2c_conf_t::dev
I2C_TypeDef * dev
USART device used.
Definition: periph_cpu.h:247