periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  * 2015 FreshTemp, LLC.
4  * 2014-2016 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
23 #ifndef PERIPH_CONF_H
24 #define PERIPH_CONF_H
25 
26 #include "periph_cpu.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
35 #define CLOCK_CORECLOCK (48000000U)
36 
41 #define USE_VREG_BUCK (1)
42 
47 static const tc32_conf_t timer_config[] = {
48  { /* Timer 0 - System Clock */
49  .dev = TC0,
50  .irq = TC0_IRQn,
51  .mclk = &MCLK->APBCMASK.reg,
52  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
53  .gclk_id = TC0_GCLK_ID,
54  .gclk_src = SAM0_GCLK_TIMER,
55  .flags = TC_CTRLA_MODE_COUNT32,
56  }
57 };
58 
59 /* Timer 0 configuration */
60 #define TIMER_0_CHANNELS 2
61 #define TIMER_0_ISR isr_tc0
62 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
69 static const uart_conf_t uart_config[] = {
70  { /* Virtual COM Port */
71  .dev = &SERCOM3->USART,
72  .rx_pin = GPIO_PIN(PA,23),
73  .tx_pin = GPIO_PIN(PA,22),
74 #ifdef MODULE_PERIPH_UART_HW_FC
75  .rts_pin = GPIO_UNDEF,
76  .cts_pin = GPIO_UNDEF,
77 #endif
78  .mux = GPIO_MUX_C,
79  .rx_pad = UART_PAD_RX_1,
80  .tx_pad = UART_PAD_TX_0,
81  .flags = UART_FLAG_NONE,
82  .gclk_src = SAM0_GCLK_MAIN,
83  },
84  { /* EXT1 header */
85  .dev = &SERCOM4->USART,
86  .rx_pin = GPIO_PIN(PB, 9),
87  .tx_pin = GPIO_PIN(PB, 8),
88 #ifdef MODULE_PERIPH_UART_HW_FC
89  .rts_pin = GPIO_UNDEF,
90  .cts_pin = GPIO_UNDEF,
91 #endif
92  .mux = GPIO_MUX_D,
93  .rx_pad = UART_PAD_RX_1,
94  .tx_pad = UART_PAD_TX_0,
95  .flags = UART_FLAG_NONE,
96  .gclk_src = SAM0_GCLK_MAIN,
97  },
98  { /* EXT2 header */
99  .dev = &SERCOM1->USART,
100  .rx_pin = GPIO_PIN(PA, 19),
101  .tx_pin = GPIO_PIN(PA, 18),
102 #ifdef MODULE_PERIPH_UART_HW_FC
103  .rts_pin = GPIO_UNDEF,
104  .cts_pin = GPIO_UNDEF,
105 #endif
106  .mux = GPIO_MUX_C,
107  .rx_pad = UART_PAD_RX_3,
108  .tx_pad = UART_PAD_TX_2,
109  .flags = UART_FLAG_NONE,
110  .gclk_src = SAM0_GCLK_MAIN,
111  }
112 };
113 
114 /* interrupt function name mapping */
115 #define UART_0_ISR isr_sercom3
116 #define UART_1_ISR isr_sercom4
117 #define UART_2_ISR isr_sercom1
118 
119 #define UART_NUMOF ARRAY_SIZE(uart_config)
126 /* PWM0 channels */
127 static const pwm_conf_chan_t pwm_chan0_config[] = {
128  /* GPIO pin, MUX value, TCC channel */
129  {
130  .pin = GPIO_PIN(PB, 10),
131  .mux = GPIO_MUX_F,
132  .chan = 4
133  },
134 };
135 
136 /* PWM device configuration */
137 static const pwm_conf_t pwm_config[] = {
138  {
139  .tim = TCC_CONFIG(TCC0),
140  .chan = pwm_chan0_config,
141  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
142  .gclk_src = SAM0_GCLK_TIMER,
143  },
144 };
145 
146 /* number of devices that are actually defined */
147 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
154 static const spi_conf_t spi_config[] = {
155  { /* EXT1 header */
156  .dev = &(SERCOM0->SPI),
157  .miso_pin = GPIO_PIN(PA, 4),
158  .mosi_pin = GPIO_PIN(PA, 6),
159  .clk_pin = GPIO_PIN(PA, 7),
160  .miso_mux = GPIO_MUX_D,
161  .mosi_mux = GPIO_MUX_D,
162  .clk_mux = GPIO_MUX_D,
163  .miso_pad = SPI_PAD_MISO_0,
164  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
165  .gclk_src = SAM0_GCLK_MAIN,
166 #ifdef MODULE_PERIPH_DMA
167  .tx_trigger = SERCOM0_DMAC_ID_TX,
168  .rx_trigger = SERCOM0_DMAC_ID_RX,
169 #endif
170  },
171  { /* EXT2, EXT3 header */
172  .dev = &(SERCOM5->SPI),
173  .miso_pin = GPIO_PIN(PB, 16),
174  .mosi_pin = GPIO_PIN(PB, 22),
175  .clk_pin = GPIO_PIN(PB, 23),
176  .miso_mux = GPIO_MUX_C,
177  .mosi_mux = GPIO_MUX_D,
178  .clk_mux = GPIO_MUX_D,
179  .miso_pad = SPI_PAD_MISO_0,
180  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
181  .gclk_src = SAM0_GCLK_MAIN,
182 #ifdef MODULE_PERIPH_DMA
183  /* no DMA on SERCOM5 */
184  .tx_trigger = DMA_TRIGGER_DISABLED,
185  .rx_trigger = DMA_TRIGGER_DISABLED,
186 #endif
187  }
188 };
189 
190 #define SPI_NUMOF ARRAY_SIZE(spi_config)
197 static const i2c_conf_t i2c_config[] = {
198  {
199  .dev = &(SERCOM2->I2CM),
200  .speed = I2C_SPEED_NORMAL,
201  .scl_pin = GPIO_PIN(PA, 9),
202  .sda_pin = GPIO_PIN(PA, 8),
203  .mux = GPIO_MUX_D,
204  .gclk_src = SAM0_GCLK_MAIN,
205  .flags = I2C_FLAG_NONE
206  }
207 };
208 
209 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
216 #define EXTERNAL_OSC32_SOURCE 1
217 #define INTERNAL_OSC32_SOURCE 0
218 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
225 #ifndef RTT_FREQUENCY
226 #define RTT_FREQUENCY (32768U)
227 #endif
235 /* ADC Default values */
236 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
237 
238 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
239 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
240 
241 static const adc_conf_chan_t adc_channels[] = {
242  /* port, pin, muxpos */
243  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 },
244  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA11 },
245  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }
246 };
247 
248 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
255  /* Must not exceed 12 MHz */
256 #define DAC_CLOCK SAM0_GCLK_TIMER
257  /* use Vcc as reference voltage */
258 #define DAC_VREF DAC_CTRLB_REFSEL_VDDANA
265 static const sam0_common_usb_config_t sam_usbdev_config[] = {
266  {
267  .dm = GPIO_PIN(PA, 24),
268  .dp = GPIO_PIN(PA, 25),
269  .d_mux = GPIO_MUX_G,
270  .device = &USB->DEVICE,
271  .gclk_src = SAM0_GCLK_48MHZ,
272  }
273 };
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif /* PERIPH_CONF_H */
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:46
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const uart_conf_t uart_config[]
UART configuration.
Definition: periph_conf.h:39
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:97
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:69
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:40
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:222
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:83
static const gpio_t adc_channels[]
Static array with declared ADC channels.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:278
@ UART_PAD_RX_1
select pad 1
@ UART_PAD_RX_3
select pad 3
@ PB
port B
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_0
use pad 0 for MISO line
#define DMA_TRIGGER_DISABLED
Indicates that the peripheral doesn't utilize the DMA controller.
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_0
select pad 0
@ UART_PAD_TX_2
select pad 2
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ GPIO_MUX_F
select peripheral function F
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA10
Alias for PIN18.
Definition: periph_cpu.h:137
#define ADC_INPUTCTRL_MUXPOS_PA11
Alias for PIN19.
Definition: periph_cpu.h:138
#define ADC_INPUTCTRL_MUXPOS_PA02
ADC pin aliases.
Definition: periph_cpu.h:119
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:74
@ SAM0_GCLK_TIMER
4/8MHz clock for timers
Definition: periph_cpu.h:71
@ SAM0_GCLK_48MHZ
48MHz clock
Definition: periph_cpu.h:73
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:299
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:300
PWM channel configuration data structure.
gpio_t pin
GPIO pin.
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
USB peripheral parameters.
SPI device configuration.
Definition: periph_cpu.h:337
SPI_t * dev
pointer to the used SPI device
Definition: periph_cpu.h:338
Timer device configuration.
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:265
UART device configuration.
Definition: periph_cpu.h:218
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:219