periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Baptiste Clenet <bapclenet@gmail.com>
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 "periph_cpu.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
31 #define CLOCK_CORECLOCK (48000000U)
32 
37 static const tc32_conf_t timer_config[] = {
38  { /* Timer 0 - System Clock */
39  .dev = TC0,
40  .irq = TC0_IRQn,
41  .mclk = &MCLK->APBCMASK.reg,
42  .mclk_mask = MCLK_APBCMASK_TC0 | MCLK_APBCMASK_TC1,
43  .gclk_id = TC0_GCLK_ID,
44  .gclk_src = SAM0_GCLK_8MHZ,
45  .flags = TC_CTRLA_MODE_COUNT32,
46  }
47 };
48 
49 /* Timer 0 configuration */
50 #define TIMER_0_CHANNELS 2
51 #define TIMER_0_ISR isr_tc0
52 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
53 
59 static const uart_conf_t uart_config[] = {
60  { /* Virtual COM Port */
61  .dev = &SERCOM0->USART,
62  .rx_pin = GPIO_PIN(PA,5),
63  .tx_pin = GPIO_PIN(PA,4),
64 #ifdef MODULE_PERIPH_UART_HW_FC
65  .rts_pin = GPIO_UNDEF,
66  .cts_pin = GPIO_UNDEF,
67 #endif
68  .mux = GPIO_MUX_D,
69  .rx_pad = UART_PAD_RX_1,
70  .tx_pad = UART_PAD_TX_0,
71  .flags = UART_FLAG_NONE,
72  .gclk_src = SAM0_GCLK_MAIN,
73  }
74 };
75 
76 /* interrupt function name mapping */
77 #define UART_0_ISR isr_sercom0
78 
79 #define UART_NUMOF ARRAY_SIZE(uart_config)
80 
86 static const spi_conf_t spi_config[] = {
87  { /* Internal AT86RF212B */
88  .dev = &(SERCOM4->SPI),
89  .miso_pin = GPIO_PIN(PC, 19),
90  .mosi_pin = GPIO_PIN(PB, 30),
91  .clk_pin = GPIO_PIN(PC, 18),
92  .miso_mux = GPIO_MUX_F,
93  .mosi_mux = GPIO_MUX_F,
94  .clk_mux = GPIO_MUX_F,
95  .miso_pad = SPI_PAD_MISO_0,
96  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
97  .gclk_src = SAM0_GCLK_MAIN,
98 #ifdef MODULE_PERIPH_DMA
99  .tx_trigger = SERCOM4_DMAC_ID_TX,
100  .rx_trigger = SERCOM4_DMAC_ID_RX,
101 #endif
102  },
103  { /* EXT1 & EXT3 Pin Header */
104  .dev = &(SERCOM5->SPI),
105  .miso_pin = GPIO_PIN(PB, 2),
106  .mosi_pin = GPIO_PIN(PB, 22),
107  .clk_pin = GPIO_PIN(PB, 23),
108  .miso_mux = GPIO_MUX_D,
109  .mosi_mux = GPIO_MUX_D,
110  .clk_mux = GPIO_MUX_D,
111  .miso_pad = SPI_PAD_MISO_0,
112  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
113  .gclk_src = SAM0_GCLK_MAIN,
114 #ifdef MODULE_PERIPH_DMA
115  /* The SAML21 doesn't support DMA triggers on SERCOM5 */
116  .tx_trigger = DMA_TRIGGER_DISABLED,
117  .rx_trigger = DMA_TRIGGER_DISABLED,
118 #endif
119  }
120 };
121 
122 #define SPI_NUMOF ARRAY_SIZE(spi_config)
123 
129 static const i2c_conf_t i2c_config[] = {
130  { /* EXT1 & EXT3 Pin Header */
131  .dev = &(SERCOM1->I2CM),
132  .speed = I2C_SPEED_NORMAL,
133  .scl_pin = GPIO_PIN(PA, 17),
134  .sda_pin = GPIO_PIN(PA, 16),
135  .mux = GPIO_MUX_C,
136  .gclk_src = SAM0_GCLK_MAIN,
137  .flags = I2C_FLAG_NONE
138  }
139 };
140 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
141 
147 #define EXTERNAL_OSC32_SOURCE 1
148 #define INTERNAL_OSC32_SOURCE 0
149 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
150 
156 #ifndef RTT_FREQUENCY
157 #define RTT_FREQUENCY (32768U)
158 #endif
159 
167 /* ADC Default values */
168 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
169 
170 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
171 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
172 
173 static const adc_conf_chan_t adc_channels[] = {
174  /* port, pin, muxpos */
175  {GPIO_PIN(PA, 6), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN6)}, /* EXT1, pin 3 */
176  {GPIO_PIN(PA, 7), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN7)}, /* EXT1, pin 4 */
177  {GPIO_PIN(PA, 10), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN18)},
178  {GPIO_PIN(PA, 11), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN19)},
179  {GPIO_PIN(PA, 2), ADC_INPUTCTRL_MUXPOS(ADC_INPUTCTRL_MUXPOS_AIN0)}
180 };
181 
182 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
183 
189 static const sam0_common_usb_config_t sam_usbdev_config[] = {
190  {
191  .dm = GPIO_PIN(PA, 24),
192  .dp = GPIO_PIN(PA, 25),
193  .d_mux = GPIO_MUX_G,
194  .device = &USB->DEVICE,
195  .gclk_src = SAM0_GCLK_48MHZ,
196  }
197 };
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif /* PERIPH_CONF_H */
204 
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
DMA_TRIGGER_DISABLED
#define DMA_TRIGGER_DISABLED
Indicates that the peripheral doesn't utilize the DMA controller.
Definition: periph_cpu_common.h:852
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
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
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
PC
@ PC
port C
Definition: periph_cpu_common.h:90
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
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