Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Franz Freitag, Justus Krebs, Nick Weiler
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
21#ifndef PERIPH_CONF_H
22#define PERIPH_CONF_H
23
24#include <stdint.h>
25
26#include "cpu.h"
27#include "periph_cpu.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
64#define CLOCK_USE_PLL (1)
65
66#if CLOCK_USE_PLL
67/* edit these values to adjust the PLL output frequency */
68#define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
69#define CLOCK_PLL_DIV (1U) /* adjust to your needs */
70#define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
71#else
72/* edit this value to your needs */
73#define CLOCK_DIV (1U)
74/* generate the actual core clock frequency */
75#define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
76#endif
83static const tc32_conf_t timer_config[] = {
84 { /* Timer 0 - System Clock */
85 .dev = TC3,
86 .irq = TC3_IRQn,
87 .pm_mask = PM_APBCMASK_TC3,
88 .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
89#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
90 .gclk_src = SAM0_GCLK_1MHZ,
91#else
92 .gclk_src = SAM0_GCLK_MAIN,
93#endif
94 .flags = TC_CTRLA_MODE_COUNT16,
95 },
96 { /* Timer 1 */
97 .dev = TC4,
98 .irq = TC4_IRQn,
99 .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
100 .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
101#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
102 .gclk_src = SAM0_GCLK_1MHZ,
103#else
104 .gclk_src = SAM0_GCLK_MAIN,
105#endif
106 .flags = TC_CTRLA_MODE_COUNT32,
107 }
108};
109
110#define TIMER_0_MAX_VALUE 0xffff
111
112/* interrupt function name mapping */
113#define TIMER_0_ISR isr_tc3
114#define TIMER_1_ISR isr_tc4
115
116#define TIMER_NUMOF ARRAY_SIZE(timer_config)
123static const uart_conf_t uart_config[] = {
124 {
125 .dev = &SERCOM4->USART,
126 .rx_pin = GPIO_PIN(PB, 9), /* D5 */
127 .tx_pin = GPIO_PIN(PB, 8), /* D4 */
128 .mux = GPIO_MUX_D,
129 .rx_pad = UART_PAD_RX_1,
130 .tx_pad = UART_PAD_TX_0,
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_sercom4
138
139#define UART_NUMOF ARRAY_SIZE(uart_config)
146static const spi_conf_t spi_config[] = {
147 { /* D0 … D2 (user pins) */
148 .dev = &SERCOM0->SPI,
149 .miso_pin = GPIO_PIN(PA, 5), /* D9 */
150 .mosi_pin = GPIO_PIN(PA, 6), /* D10 */
151 .clk_pin = GPIO_PIN(PA, 7), /* D8 */
152 .miso_mux = GPIO_MUX_D,
153 .mosi_mux = GPIO_MUX_D,
154 .clk_mux = GPIO_MUX_D,
155 .miso_pad = SPI_PAD_MISO_1,
156 .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
157 .gclk_src = SAM0_GCLK_MAIN,
158#ifdef MODULE_PERIPH_DMA
159 .tx_trigger = SERCOM0_DMAC_ID_TX,
160 .rx_trigger = SERCOM0_DMAC_ID_RX,
161#endif
162 },
163};
164
165#define SPI_NUMOF ARRAY_SIZE(spi_config)
172static const i2c_conf_t i2c_config[] = {
173 {
174 .dev = &(SERCOM2->I2CM),
175 .speed = I2C_SPEED_NORMAL,
176 .scl_pin = GPIO_PIN(PA, 9), /* D5 */
177 .sda_pin = GPIO_PIN(PA, 8), /* D4 */
178 .mux = GPIO_MUX_D,
179 .gclk_src = SAM0_GCLK_MAIN,
180 .flags = I2C_FLAG_NONE
181 }
182};
183#define I2C_NUMOF ARRAY_SIZE(i2c_config)
190#ifndef RTT_FREQUENCY
191#define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
192#endif
199#define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
200
201#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
202#define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
203#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
204
205static const adc_conf_chan_t adc_channels[] = {
206 /* port, pin, muxpos */
208 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 },
209 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 },
210 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
211 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 },
212 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA08 },
213 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA09 },
214 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB08 },
215 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB09 }
216};
217
218#define ADC_NUMOF ARRAY_SIZE(adc_channels)
225static const sam0_common_usb_config_t sam_usbdev_config[] = {
226 {
227 .dm = GPIO_PIN(PA, 24),
228 .dp = GPIO_PIN(PA, 25),
229 .d_mux = GPIO_MUX_G,
230 .device = &USB->DEVICE,
231 .gclk_src = SAM0_GCLK_MAIN,
232 }
233};
236#ifdef __cplusplus
237}
238#endif
239
240#endif /* PERIPH_CONF_H */
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition periph_cpu.h:46
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:278
@ UART_PAD_RX_1
select pad 1
@ PB
port B
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_1
use pad 1 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_0
select pad 0
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA05
Alias for PIN5.
Definition periph_cpu.h:124
#define ADC_INPUTCTRL_MUXPOS_PB08
Alias for PIN2.
Definition periph_cpu.h:121
#define ADC_INPUTCTRL_MUXPOS_PA08
Alias for PIN16.
Definition periph_cpu.h:135
#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_PA07
Alias for PIN7.
Definition periph_cpu.h:126
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition periph_cpu.h:76
#define ADC_INPUTCTRL_MUXPOS_PA04
Alias for PIN4.
Definition periph_cpu.h:123
#define ADC_INPUTCTRL_MUXPOS_PA06
Alias for PIN6.
Definition periph_cpu.h:125
#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
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