Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Inria
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
25extern "C" {
26#endif
27
59#define CLOCK_USE_PLL (1)
60
61#if CLOCK_USE_PLL
62/* edit these values to adjust the PLL output frequency */
63#define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
64#define CLOCK_PLL_DIV (1U) /* adjust to your needs */
65/* generate the actual used core clock frequency */
66#define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
67#else
68/* edit this value to your needs */
69#define CLOCK_DIV (1U)
70/* generate the actual core clock frequency */
71#define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
72#endif
79static const tc32_conf_t timer_config[] = {
80 { /* Timer 0 - System Clock */
81 .dev = TC3,
82 .irq = TC3_IRQn,
83 .pm_mask = PM_APBCMASK_TC3,
84 .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
85#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
86 .gclk_src = SAM0_GCLK_1MHZ,
87#else
88 .gclk_src = SAM0_GCLK_MAIN,
89#endif
90 .flags = TC_CTRLA_MODE_COUNT16,
91 },
92 { /* Timer 1 */
93 .dev = TC4,
94 .irq = TC4_IRQn,
95 .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
96 .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
97#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
98 .gclk_src = SAM0_GCLK_1MHZ,
99#else
100 .gclk_src = SAM0_GCLK_MAIN,
101#endif
102 .flags = TC_CTRLA_MODE_COUNT32,
103 }
104};
105
106#define TIMER_0_MAX_VALUE 0xffff
107
108/* interrupt function name mapping */
109#define TIMER_0_ISR isr_tc3
110#define TIMER_1_ISR isr_tc4
111
112#define TIMER_NUMOF ARRAY_SIZE(timer_config)
119static const uart_conf_t uart_config[] = {
120 {
121 .dev = &SERCOM5->USART,
122 .rx_pin = GPIO_PIN(PB,23),
123 .tx_pin = GPIO_PIN(PB,22),
124#ifdef MODULE_SAM0_PERIPH_UART_HW_FC
125 .rts_pin = GPIO_UNDEF,
126 .cts_pin = GPIO_UNDEF,
127#endif
128 .mux = GPIO_MUX_D,
129 .rx_pad = UART_PAD_RX_3,
130 .tx_pad = UART_PAD_TX_2,
131 .flags = UART_FLAG_NONE,
132 .gclk_src = SAM0_GCLK_MAIN,
133 }
134};
135
136/* interrupt function name mapping */
137#define UART_0_ISR isr_sercom5
138
139#define UART_NUMOF ARRAY_SIZE(uart_config)
146#define PWM_0_EN 1
147#define PWM_1_EN 1
148
149#if PWM_0_EN
150/* PWM0 channels */
151static const pwm_conf_chan_t pwm_chan0_config[] = {
152 /* GPIO pin, MUX value, TCC channel */
153 { GPIO_PIN(PA, 4), GPIO_MUX_E, 0},
154 { GPIO_PIN(PA, 5), GPIO_MUX_E, 1},
155};
156#endif
157#if PWM_1_EN
158/* PWM1 channels */
159static const pwm_conf_chan_t pwm_chan1_config[] = {
160 /* GPIO pin, MUX value, TCC channel */
161 { GPIO_PIN(PA, 10), GPIO_MUX_E, 0 },
162 { GPIO_PIN(PA, 11), GPIO_MUX_E, 1 },
163};
164#endif
165
166/* PWM device configuration */
167static const pwm_conf_t pwm_config[] = {
168#if PWM_0_EN
169 {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
170#endif
171
172#if PWM_1_EN
173 {TCC_CONFIG(TCC1), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
174#endif
175};
176
177/* number of devices that are actually defined */
178#define PWM_NUMOF ARRAY_SIZE(pwm_config)
186/* ADC Default values */
187#define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
188
189#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
190#define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
191#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
192
193static const adc_conf_chan_t adc_channels[] = {
194 /* port, pin, muxpos */
195 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }, /* A0 */
196 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB02 }, /* A1 */
197 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA11 }, /* A2 */
198 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 }, /* A3 */
199 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB08 }, /* A4 */
200 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB09 }, /* A5 */
201 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA09 }, /* A6 */
202 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB03 }, /* A7 */
203};
204
205#define ADC_NUMOF ARRAY_SIZE(adc_channels)
212static const i2c_conf_t i2c_config[] = {
213 {
214 .dev = &(SERCOM4->I2CM),
215 .speed = I2C_SPEED_NORMAL,
216 .scl_pin = GPIO_PIN(PB, 9),
217 .sda_pin = GPIO_PIN(PB, 8),
218 .mux = GPIO_MUX_D,
219 .gclk_src = SAM0_GCLK_MAIN,
220 .flags = I2C_FLAG_NONE
221 }
222};
223#define I2C_NUMOF ARRAY_SIZE(i2c_config)
230static const spi_conf_t spi_config[] = {
231 { /* Connected to NINA W102 */
232 .dev = &SERCOM2->SPI,
233 .miso_pin = GPIO_PIN(PA, 13),
234 .mosi_pin = GPIO_PIN(PA, 12),
235 .clk_pin = GPIO_PIN(PA, 15),
236 .miso_mux = GPIO_MUX_C,
237 .mosi_mux = GPIO_MUX_C,
238 .clk_mux = GPIO_MUX_C,
239 .miso_pad = SPI_PAD_MISO_1,
240 .mosi_pad = SPI_PAD_MOSI_0_SCK_3,
241 .gclk_src = SAM0_GCLK_MAIN,
242 },
243 {
244 .dev = &SERCOM3->SPI,
245 .miso_pin = GPIO_PIN(PA, 19),
246 .mosi_pin = GPIO_PIN(PA, 16),
247 .clk_pin = GPIO_PIN(PA, 17),
248 .miso_mux = GPIO_MUX_D,
249 .mosi_mux = GPIO_MUX_D,
250 .clk_mux = GPIO_MUX_D,
251 .miso_pad = SPI_PAD_MISO_3,
252 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
253 .gclk_src = SAM0_GCLK_MAIN,
254 },
255};
256
257#define SPI_NUMOF ARRAY_SIZE(spi_config)
264#ifndef RTT_FREQUENCY
265#define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
266#endif
273static const sam0_common_usb_config_t sam_usbdev_config[] = {
274 {
275 .dm = GPIO_PIN(PA, 24),
276 .dp = GPIO_PIN(PA, 25),
277 .d_mux = GPIO_MUX_G,
278 .device = &USB->DEVICE,
279 .gclk_src = SAM0_GCLK_MAIN,
280 }
281};
284#ifdef __cplusplus
285}
286#endif
287
288#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.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:278
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:83
@ UART_PAD_RX_3
select pad 3
@ PB
port B
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_1
use pad 1 for MISO line
@ SPI_PAD_MISO_3
use pad 3 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_2
select pad 2
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
@ GPIO_MUX_E
select peripheral function E
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ SPI_PAD_MOSI_0_SCK_3
use pad 0 for MOSI, pad 3 for SCK
@ SPI_PAD_MOSI_0_SCK_1
use pad 0 for MOSI, pad 1 for SCK
#define ADC_INPUTCTRL_MUXPOS_PB08
Alias for PIN2.
Definition periph_cpu.h:121
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition periph_cpu.h:76
#define ADC_INPUTCTRL_MUXPOS_PB02
Alias for PIN10.
Definition periph_cpu.h:129
#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_PB09
Alias for PIN3.
Definition periph_cpu.h:122
#define ADC_INPUTCTRL_MUXPOS_PA09
Alias for PIN17.
Definition periph_cpu.h:136
#define ADC_INPUTCTRL_MUXPOS_PB03
Alias for PIN11.
Definition periph_cpu.h:130
#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
ADC Channel Configuration.
uint32_t inputctrl
ADC channel pin multiplexer value
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.
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.
Tc * dev
pointer to the used Timer device
UART device configuration.
Definition periph_cpu.h:218
USART_t * dev
pointer to the used UART device
Definition periph_cpu.h:219