periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universität Berlin
3  * 2016 Inria
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
24 #ifndef PERIPH_CONF_H
25 #define PERIPH_CONF_H
26 
27 #include <stdint.h>
28 
29 #include "cpu.h"
30 #include "periph_cpu.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
67 #define CLOCK_USE_PLL (1)
68 
69 #if CLOCK_USE_PLL
70 /* edit these values to adjust the PLL output frequency */
71 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
72 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
73 /* generate the actual used core clock frequency */
74 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
75 #else
76 /* edit this value to your needs */
77 #define CLOCK_DIV (1U)
78 /* generate the actual core clock frequency */
79 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
80 #endif
81 
87 static const tc32_conf_t timer_config[] = {
88  { /* Timer 0 - System Clock */
89  .dev = TC3,
90  .irq = TC3_IRQn,
91  .pm_mask = PM_APBCMASK_TC3,
92  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
93 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
94  .gclk_src = SAM0_GCLK_1MHZ,
95 #else
96  .gclk_src = SAM0_GCLK_MAIN,
97 #endif
98  .flags = TC_CTRLA_MODE_COUNT16,
99  },
100  { /* Timer 1 */
101  .dev = TC4,
102  .irq = TC4_IRQn,
103  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
104  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
105 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
106  .gclk_src = SAM0_GCLK_1MHZ,
107 #else
108  .gclk_src = SAM0_GCLK_MAIN,
109 #endif
110  .flags = TC_CTRLA_MODE_COUNT32,
111  }
112 };
113 
114 #define TIMER_0_MAX_VALUE 0xffff
115 
116 /* interrupt function name mapping */
117 #define TIMER_0_ISR isr_tc3
118 #define TIMER_1_ISR isr_tc4
119 
120 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
121 
127 static const uart_conf_t uart_config[] = {
128  {
129  .dev = &SERCOM5->USART,
130  .rx_pin = GPIO_PIN(PB,23),
131  .tx_pin = GPIO_PIN(PB,22),
132 #ifdef MODULE_PERIPH_UART_HW_FC
133  .rts_pin = GPIO_UNDEF,
134  .cts_pin = GPIO_UNDEF,
135 #endif
136  .mux = GPIO_MUX_D,
137  .rx_pad = UART_PAD_RX_3,
138  .tx_pad = UART_PAD_TX_2,
139  .flags = UART_FLAG_NONE,
140  .gclk_src = SAM0_GCLK_MAIN,
141  },
142  {
143  .dev = &SERCOM0->USART,
144  .rx_pin = GPIO_PIN(PA,11),
145  .tx_pin = GPIO_PIN(PA,10),
146 #ifdef MODULE_PERIPH_UART_HW_FC
147  .rts_pin = GPIO_UNDEF,
148  .cts_pin = GPIO_UNDEF,
149 #endif
150  .mux = GPIO_MUX_C,
151  .rx_pad = UART_PAD_RX_3,
152  .tx_pad = UART_PAD_TX_2,
153  .flags = UART_FLAG_NONE,
154  .gclk_src = SAM0_GCLK_MAIN,
155  }
156 };
157 
158 /* interrupt function name mapping */
159 #define UART_0_ISR isr_sercom5
160 #define UART_1_ISR isr_sercom0
161 
162 #define UART_NUMOF ARRAY_SIZE(uart_config)
163 
169 #define PWM_0_EN 1
170 #define PWM_1_EN 1
171 
172 #if PWM_0_EN
173 /* PWM0 channels */
174 static const pwm_conf_chan_t pwm_chan0_config[] = {
175  /* GPIO pin, MUX value, TCC channel */
176  { GPIO_PIN(PA, 8), GPIO_MUX_E, 0 },
177  { GPIO_PIN(PA, 9), GPIO_MUX_E, 1 },
178 };
179 #endif
180 #if PWM_1_EN
181 /* PWM1 channels */
182 static const pwm_conf_chan_t pwm_chan1_config[] = {
183  /* GPIO pin, MUX value, TCC channel */
184  { GPIO_PIN(PA, 6), GPIO_MUX_E, 0 },
185  { GPIO_PIN(PA, 7), GPIO_MUX_E, 1 },
186 };
187 #endif
188 
189 /* PWM device configuration */
190 static const pwm_conf_t pwm_config[] = {
191 #if PWM_0_EN
192  {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
193 #endif
194 #if PWM_1_EN
195  {TCC_CONFIG(TCC1), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
196 #endif
197 };
198 
199 /* number of devices that are actually defined */
200 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
201 
208 /* ADC Default values */
209 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
210 
211 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
212 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
213 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
214 
215 static const adc_conf_chan_t adc_channels[] = {
216  /* port, pin, muxpos */
217  {GPIO_PIN(PA, 2), ADC_INPUTCTRL_MUXPOS_PIN0}, /* A0 */
218  {GPIO_PIN(PB, 8), ADC_INPUTCTRL_MUXPOS_PIN2}, /* A1 */
219  {GPIO_PIN(PB, 9), ADC_INPUTCTRL_MUXPOS_PIN3}, /* A2 */
220  {GPIO_PIN(PA, 4), ADC_INPUTCTRL_MUXPOS_PIN4}, /* A3 */
221  {GPIO_PIN(PA, 5), ADC_INPUTCTRL_MUXPOS_PIN5}, /* A4 */
222  {GPIO_PIN(PB, 2), ADC_INPUTCTRL_MUXPOS_PIN10}, /* A5 */
223 };
224 
225 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
226 
232 static const spi_conf_t spi_config[] = {
233  {
234  .dev = &SERCOM4->SPI,
235  .miso_pin = GPIO_PIN(PA, 12),
236  .mosi_pin = GPIO_PIN(PB, 10),
237  .clk_pin = GPIO_PIN(PB, 11),
238  .miso_mux = GPIO_MUX_D,
239  .mosi_mux = GPIO_MUX_D,
240  .clk_mux = GPIO_MUX_D,
241  .miso_pad = SPI_PAD_MISO_0,
242  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
243  .gclk_src = SAM0_GCLK_MAIN,
244  }
245 };
246 
247 #define SPI_NUMOF ARRAY_SIZE(spi_config)
248 
255 static const i2c_conf_t i2c_config[] = {
256  {
257  .dev = &(SERCOM3->I2CM),
258  .speed = I2C_SPEED_FAST,
259  .scl_pin = GPIO_PIN(PA, 23),
260  .sda_pin = GPIO_PIN(PA, 22),
261  .mux = GPIO_MUX_C,
262  .gclk_src = SAM0_GCLK_MAIN,
263  .flags = I2C_FLAG_NONE
264  }
265 };
266 
267 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
268 
274 #ifndef RTT_FREQUENCY
275 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
276 #endif
277 
283 static const sam0_common_usb_config_t sam_usbdev_config[] = {
284  {
285  .dm = GPIO_PIN(PA, 24),
286  .dp = GPIO_PIN(PA, 25),
287  .d_mux = GPIO_MUX_G,
288  .device = &USB->DEVICE,
289  .gclk_src = SAM0_GCLK_MAIN,
290  }
291 };
294 #ifdef __cplusplus
295 }
296 #endif
297 
298 #endif /* PERIPH_CONF_H */
299 
UART_PAD_RX_3
@ UART_PAD_RX_3
select pad 3
Definition: periph_cpu_common.h:154
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_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
PB
@ PB
port B
Definition: periph_cpu_common.h:89
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
SPI_PAD_MISO_0
@ SPI_PAD_MISO_0
use pad 0 for MISO line
Definition: periph_cpu_common.h:327
pwm_conf_chan_t
PWM channel configuration data structure.
Definition: periph_cpu_common.h:307
UART_PAD_TX_2
@ UART_PAD_TX_2
select pad 2
Definition: periph_cpu_common.h:162
GPIO_UNDEF
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
Definition: periph_cpu_common.h:52
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
uart_conf_t::dev
cc2538_uart_t * dev
pointer to the used UART device
Definition: periph_cpu.h:167
SPI_PAD_MOSI_2_SCK_3
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
Definition: periph_cpu_common.h:338
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
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
I2C_SPEED_FAST
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: i2c.h:178
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