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 | MCLK_APBCMASK_TC1,
53  .gclk_id = TC0_GCLK_ID,
54  .gclk_src = SAM0_GCLK_8MHZ,
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)
63 
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 };
99 
100 /* interrupt function name mapping */
101 #define UART_0_ISR isr_sercom3
102 #define UART_1_ISR isr_sercom4
103 
104 #define UART_NUMOF ARRAY_SIZE(uart_config)
105 
111 #define PWM_0_EN 1
112 
113 #if PWM_0_EN
114 /* PWM0 channels */
115 static const pwm_conf_chan_t pwm_chan0_config[] = {
116  /* GPIO pin, MUX value, TCC channel */
117  { GPIO_PIN(PB, 10), GPIO_MUX_F, 4 },
118 };
119 #endif
120 
121 /* PWM device configuration */
122 static const pwm_conf_t pwm_config[] = {
123 #if PWM_0_EN
124  { .tim = TCC_CONFIG(TCC0),
125  .chan = pwm_chan0_config,
126  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
127  .gclk_src = SAM0_GCLK_8MHZ,
128  },
129 #endif
130 };
131 
132 /* number of devices that are actually defined */
133 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
134 
140 static const spi_conf_t spi_config[] = {
141  {
142  .dev = &(SERCOM0->SPI),
143  .miso_pin = GPIO_PIN(PA, 4),
144  .mosi_pin = GPIO_PIN(PA, 6),
145  .clk_pin = GPIO_PIN(PA, 7),
146  .miso_mux = GPIO_MUX_D,
147  .mosi_mux = GPIO_MUX_D,
148  .clk_mux = GPIO_MUX_D,
149  .miso_pad = SPI_PAD_MISO_0,
150  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
151  .gclk_src = SAM0_GCLK_MAIN,
152 #ifdef MODULE_PERIPH_DMA
153  .tx_trigger = SERCOM0_DMAC_ID_TX,
154  .rx_trigger = SERCOM0_DMAC_ID_RX,
155 #endif
156  }
157 };
158 
159 #define SPI_NUMOF ARRAY_SIZE(spi_config)
160 
166 static const i2c_conf_t i2c_config[] = {
167  {
168  .dev = &(SERCOM2->I2CM),
169  .speed = I2C_SPEED_NORMAL,
170  .scl_pin = GPIO_PIN(PA, 9),
171  .sda_pin = GPIO_PIN(PA, 8),
172  .mux = GPIO_MUX_D,
173  .gclk_src = SAM0_GCLK_MAIN,
174  .flags = I2C_FLAG_NONE
175  }
176 };
177 
178 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
179 
185 #define EXTERNAL_OSC32_SOURCE 1
186 #define INTERNAL_OSC32_SOURCE 0
187 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
188 
194 #ifndef RTT_FREQUENCY
195 #define RTT_FREQUENCY (32768U)
196 #endif
197 
204 /* ADC Default values */
205 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
206 
207 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
208 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
209 
210 static const adc_conf_chan_t adc_channels[] = {
211  /* port, pin, muxpos */
212  {GPIO_PIN(PA, 10), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN18)},
213  {GPIO_PIN(PA, 11), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN19)},
214  {GPIO_PIN(PA, 2), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN0)}
215 };
216 
217 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
218 
224  /* Must not exceed 12 MHz */
225 #define DAC_CLOCK SAM0_GCLK_8MHZ
226  /* use Vcc as reference voltage */
227 #define DAC_VREF DAC_CTRLB_REFSEL_VDDANA
228 
234 static const sam0_common_usb_config_t sam_usbdev_config[] = {
235  {
236  .dm = GPIO_PIN(PA, 24),
237  .dp = GPIO_PIN(PA, 25),
238  .d_mux = GPIO_MUX_G,
239  .device = &USB->DEVICE,
240  .gclk_src = SAM0_GCLK_48MHZ,
241  }
242 };
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* PERIPH_CONF_H */
250 
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
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
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
UART_PAD_RX_1
@ UART_PAD_RX_1
select pad 1
Definition: periph_cpu_common.h:152
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
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
SAM0_GCLK_48MHZ
@ SAM0_GCLK_48MHZ
48MHz clock
Definition: periph_cpu.h:49
PA
@ PA
port A
Definition: periph_cpu_common.h:88
SAM0_GCLK_8MHZ
@ SAM0_GCLK_8MHZ
8MHz clock
Definition: periph_cpu.h:47
i2c_conf_t
I2C configuration options.
Definition: periph_cpu.h:128
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
pwm_conf_t::tim
tc_tcc_cfg_t tim
timer configuration
Definition: periph_cpu_common.h:317