periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Mesotic SAS
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 
20 #ifndef PERIPH_CONF_H
21 #define PERIPH_CONF_H
22 
23 #include "periph_cpu.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
32 #define CLOCK_CORECLOCK (16000000U)
33 
38 #define USE_VREG_BUCK (1)
39 
44 static const tc32_conf_t timer_config[] = {
45  { /* Timer 0 - System Clock */
46  .dev = TC0,
47  .irq = TC0_IRQn,
48  .mclk = &MCLK->APBCMASK.reg,
49  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
50  .gclk_id = TC0_GCLK_ID,
51  .gclk_src = SAM0_GCLK_MAIN,
52  .flags = TC_CTRLA_MODE_COUNT32,
53  },
54  {
55  .dev = TC2,
56  .irq = TC2_IRQn,
57  .mclk = &MCLK->APBCMASK.reg,
58  .mclk_mask = MCLK_APBCMASK_TC2_Msk,
59  .gclk_id = TC2_GCLK_ID,
60  .gclk_src = SAM0_GCLK_MAIN,
61  .flags = TC_CTRLA_MODE_COUNT16,
62  }
63 };
64 
65 /* Timer 0 configuration */
66 #define TIMER_0_CHANNELS 2
67 #define TIMER_0_ISR isr_tc0
68 
69 /* Timer 1 configuration */
70 #define TIMER_1_CHANNELS 2
71 #define TIMER_1_ISR isr_tc2
72 #define TIMER_1_MAX_VALUE 0xffff
73 
74 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
81 static const uart_conf_t uart_config[] = {
82  { /* Virtual COM Port */
83  .dev = &SERCOM2->USART,
84  .rx_pin = GPIO_PIN(PA, 25),
85  .tx_pin = GPIO_PIN(PA, 24),
86 #ifdef MODULE_PERIPH_UART_HW_FC
87  .rts_pin = GPIO_UNDEF,
88  .cts_pin = GPIO_UNDEF,
89 #endif
90  .mux = GPIO_MUX_D,
91  .rx_pad = UART_PAD_RX_3,
92  .tx_pad = UART_PAD_TX_2,
93  .flags = UART_FLAG_NONE,
94  .gclk_src = SAM0_GCLK_MAIN,
95  },
96  { /* EXT1 */
97  /* For SAML11, see boards/saml11/doc.txt
98  * to properly enable this SERCOM */
99  .dev = &SERCOM1->USART,
100  .rx_pin = GPIO_PIN(PA, 9),
101  .tx_pin = GPIO_PIN(PA, 8),
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_1,
108  .tx_pad = UART_PAD_TX_0,
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_sercom2_2
116 #define UART_0_ISR_TX isr_sercom2_0
117 #define UART_1_ISR isr_sercom1_2
118 #define UART_1_ISR_TX isr_sercom1_0
119 
120 #define UART_NUMOF ARRAY_SIZE(uart_config)
127 #define PWM_0_EN 1
128 #define PWM_1_EN 0
129 
130 #if PWM_0_EN
131 /* PWM0 channels */
132 static const pwm_conf_chan_t pwm_chan0_config[] = {
133  /* GPIO pin, MUX value, TC channel */
134  { GPIO_PIN(PA, 18), GPIO_MUX_E, 0 },
135  { GPIO_PIN(PA, 19), GPIO_MUX_E, 1 },
136 };
137 #endif
138 #if PWM_1_EN
139 /* PWM1 channels */
140 static const pwm_conf_chan_t pwm_chan1_config[] = {
141  /* GPIO pin, MUX value, TC channel */
142  { GPIO_PIN(PA, 7), GPIO_MUX_E, 1 }, /* LED */
143 };
144 #endif
145 
146 /* PWM device configuration */
147 static const pwm_conf_t pwm_config[] = {
148 #if PWM_0_EN
149  { .tim = TC_CONFIG(TC2),
150  .chan = pwm_chan0_config,
151  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
152  .gclk_src = SAM0_GCLK_MAIN,
153  },
154 #endif
155 #if PWM_1_EN
156  /* conflicts with xtimer config (TC0_TC1) */
157  { .tim = TC_CONFIG(TC1),
158  .chan = pwm_chan1_config,
159  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
160  .gclk_src = SAM0_GCLK_MAIN,
161  },
162 #endif
163 };
164 
165 /* number of devices that are actually defined */
166 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
173 static const spi_conf_t spi_config[] = {
174  {
175  .dev = &(SERCOM0->SPI),
176  .miso_pin = GPIO_PIN(PA, 4),
177  .mosi_pin = GPIO_PIN(PA, 14),
178  .clk_pin = GPIO_PIN(PA, 15),
179  .miso_mux = GPIO_MUX_D,
180  .mosi_mux = GPIO_MUX_D,
181  .clk_mux = GPIO_MUX_D,
182  .miso_pad = SPI_PAD_MISO_0,
183  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
184  .gclk_src = SAM0_GCLK_MAIN,
185 #ifdef MODULE_PERIPH_DMA
186  .tx_trigger = SERCOM0_DMAC_ID_TX,
187  .rx_trigger = SERCOM0_DMAC_ID_RX,
188 #endif
189  }
190 };
191 
192 #define SPI_NUMOF ARRAY_SIZE(spi_config)
199 static const i2c_conf_t i2c_config[] = {
200  {
201  .dev = &(SERCOM1->I2CM),
202  .speed = I2C_SPEED_NORMAL,
203  .scl_pin = GPIO_PIN(PA, 17),
204  .sda_pin = GPIO_PIN(PA, 16),
205  .mux = GPIO_MUX_C,
206  .gclk_src = SAM0_GCLK_MAIN,
207  .flags = I2C_FLAG_NONE
208  }
209 };
210 
211 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
218 #define EXTERNAL_OSC32_SOURCE 1
219 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
226 #ifndef RTT_FREQUENCY
227 #define RTT_FREQUENCY (32768U)
228 #endif
236 /* ADC Default values */
237 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
238 
239 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
240 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
241 
242 static const adc_conf_chan_t adc_channels[] = {
243  /* port, pin, muxpos */
244  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 },
245 };
246 
247 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
254 #define DAC_CLOCK SAM0_GCLK_32KHZ
255  /* use Vcc as reference voltage */
256 #define DAC_VREF DAC_CTRLB_REFSEL_AVCC
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #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
@ 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:137
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:74
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.
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
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