periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 Mesotic SAS
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
19 #include "periph_cpu.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
28 #define CLOCK_CORECLOCK (16000000U)
29 
34 #define USE_VREG_BUCK (1)
35 
40 static const tc32_conf_t timer_config[] = {
41  { /* Timer 0 - System Clock */
42  .dev = TC0,
43  .irq = TC0_IRQn,
44  .mclk = &MCLK->APBCMASK.reg,
45  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
46  .gclk_id = TC0_GCLK_ID,
47  .gclk_src = SAM0_GCLK_MAIN,
48  .flags = TC_CTRLA_MODE_COUNT32,
49  },
50  {
51  .dev = TC2,
52  .irq = TC2_IRQn,
53  .mclk = &MCLK->APBCMASK.reg,
54  .mclk_mask = MCLK_APBCMASK_TC2_Msk,
55  .gclk_id = TC2_GCLK_ID,
56  .gclk_src = SAM0_GCLK_MAIN,
57  .flags = TC_CTRLA_MODE_COUNT16,
58  }
59 };
60 
61 /* Timer 0 configuration */
62 #define TIMER_0_CHANNELS 2
63 #define TIMER_0_ISR isr_tc0
64 
65 /* Timer 1 configuration */
66 #define TIMER_1_CHANNELS 2
67 #define TIMER_1_ISR isr_tc2
68 #define TIMER_1_MAX_VALUE 0xffff
69 
70 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
77 static const uart_conf_t uart_config[] = {
78  { /* Virtual COM Port */
79  .dev = &SERCOM2->USART,
80  .rx_pin = GPIO_PIN(PA, 25),
81  .tx_pin = GPIO_PIN(PA, 24),
82 #ifdef MODULE_PERIPH_UART_HW_FC
83  .rts_pin = GPIO_UNDEF,
84  .cts_pin = GPIO_UNDEF,
85 #endif
86  .mux = GPIO_MUX_D,
87  .rx_pad = UART_PAD_RX_3,
88  .tx_pad = UART_PAD_TX_2,
89  .flags = UART_FLAG_NONE,
90  .gclk_src = SAM0_GCLK_MAIN,
91  },
92  { /* EXT1 */
93  /* For SAML11, see boards/saml11/doc.txt
94  * to properly enable this SERCOM */
95  .dev = &SERCOM1->USART,
96  .rx_pin = GPIO_PIN(PA, 9),
97  .tx_pin = GPIO_PIN(PA, 8),
98 #ifdef MODULE_PERIPH_UART_HW_FC
99  .rts_pin = GPIO_UNDEF,
100  .cts_pin = GPIO_UNDEF,
101 #endif
102  .mux = GPIO_MUX_C,
103  .rx_pad = UART_PAD_RX_1,
104  .tx_pad = UART_PAD_TX_0,
105  .flags = UART_FLAG_NONE,
106  .gclk_src = SAM0_GCLK_MAIN,
107  }
108 };
109 
110 /* interrupt function name mapping */
111 #define UART_0_ISR isr_sercom2_2
112 #define UART_0_ISR_TX isr_sercom2_0
113 #define UART_1_ISR isr_sercom1_2
114 #define UART_1_ISR_TX isr_sercom1_0
115 
116 #define UART_NUMOF ARRAY_SIZE(uart_config)
123 #define PWM_0_EN 1
124 #define PWM_1_EN 0
125 
126 #if PWM_0_EN
127 /* PWM0 channels */
128 static const pwm_conf_chan_t pwm_chan0_config[] = {
129  /* GPIO pin, MUX value, TC channel */
130  { GPIO_PIN(PA, 18), GPIO_MUX_E, 0 },
131  { GPIO_PIN(PA, 19), GPIO_MUX_E, 1 },
132 };
133 #endif
134 #if PWM_1_EN
135 /* PWM1 channels */
136 static const pwm_conf_chan_t pwm_chan1_config[] = {
137  /* GPIO pin, MUX value, TC channel */
138  { GPIO_PIN(PA, 7), GPIO_MUX_E, 1 }, /* LED */
139 };
140 #endif
141 
142 /* PWM device configuration */
143 static const pwm_conf_t pwm_config[] = {
144 #if PWM_0_EN
145  { .tim = TC_CONFIG(TC2),
146  .chan = pwm_chan0_config,
147  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
148  .gclk_src = SAM0_GCLK_MAIN,
149  },
150 #endif
151 #if PWM_1_EN
152  /* conflicts with xtimer config (TC0_TC1) */
153  { .tim = TC_CONFIG(TC1),
154  .chan = pwm_chan1_config,
155  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
156  .gclk_src = SAM0_GCLK_MAIN,
157  },
158 #endif
159 };
160 
161 /* number of devices that are actually defined */
162 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
169 static const spi_conf_t spi_config[] = {
170  {
171  .dev = &(SERCOM0->SPI),
172  .miso_pin = GPIO_PIN(PA, 4),
173  .mosi_pin = GPIO_PIN(PA, 14),
174  .clk_pin = GPIO_PIN(PA, 15),
175  .miso_mux = GPIO_MUX_D,
176  .mosi_mux = GPIO_MUX_D,
177  .clk_mux = GPIO_MUX_D,
178  .miso_pad = SPI_PAD_MISO_0,
179  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
180  .gclk_src = SAM0_GCLK_MAIN,
181 #ifdef MODULE_PERIPH_DMA
182  .tx_trigger = SERCOM0_DMAC_ID_TX,
183  .rx_trigger = SERCOM0_DMAC_ID_RX,
184 #endif
185  }
186 };
187 
188 #define SPI_NUMOF ARRAY_SIZE(spi_config)
195 static const i2c_conf_t i2c_config[] = {
196  {
197  .dev = &(SERCOM1->I2CM),
198  .speed = I2C_SPEED_NORMAL,
199  .scl_pin = GPIO_PIN(PA, 17),
200  .sda_pin = GPIO_PIN(PA, 16),
201  .mux = GPIO_MUX_C,
202  .gclk_src = SAM0_GCLK_MAIN,
203  .flags = I2C_FLAG_NONE
204  }
205 };
206 
207 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
214 #define EXTERNAL_OSC32_SOURCE 1
215 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
222 #ifndef RTT_FREQUENCY
223 #define RTT_FREQUENCY (32768U)
224 #endif
232 /* ADC Default values */
233 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
234 
235 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
236 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
237 
238 static const adc_conf_chan_t adc_channels[] = {
239  /* port, pin, muxpos */
240  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 },
241 };
242 
243 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
250 #define DAC_CLOCK SAM0_GCLK_32KHZ
251  /* use Vcc as reference voltage */
252 #define DAC_VREF DAC_CTRLB_REFSEL_AVCC
255 #ifdef __cplusplus
256 }
257 #endif
258 
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const uart_conf_t uart_config[]
UART configuration.
Definition: periph_conf.h:35
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:93
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:65
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:36
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:218
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:82
static const gpio_t adc_channels[]
Static array with declared ADC channels.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:277
@ UART_PAD_RX_1
select pad 1
@ UART_PAD_RX_3
select pad 3
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
#define TC_CONFIG(tim)
Static initializer for TC timer configuration.
@ SPI_PAD_MISO_0
use pad 0 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_0
select pad 0
@ UART_PAD_TX_2
select pad 2
@ GPIO_MUX_E
select peripheral function E
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_C
select peripheral function C
@ 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:136
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:73
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
PWM channel configuration data structure.
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
SPI device configuration.
Definition: periph_cpu.h:336
SPI_t * dev
pointer to the used SPI device
Definition: periph_cpu.h:337
Timer device configuration.
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:264
UART device configuration.
Definition: periph_cpu.h:217
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:218