Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 HAW Hamburg
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 <stdint.h>
24
25#include "cpu.h"
26#include "periph_cpu.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
63#define CLOCK_USE_PLL (1)
64
65#if CLOCK_USE_PLL
66/* edit these values to adjust the PLL output frequency */
67#define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
68#define CLOCK_PLL_DIV (1U) /* adjust to your needs */
69#define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
70#else
71/* edit this value to your needs */
72#define CLOCK_DIV (1U)
73/* generate the actual core clock frequency */
74#define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
75#endif
82static const tc32_conf_t timer_config[] = {
83 { /* Timer 0 - System Clock */
84 .dev = TC3,
85 .irq = TC3_IRQn,
86 .pm_mask = PM_APBCMASK_TC3,
87 .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
88#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
89 .gclk_src = SAM0_GCLK_1MHZ,
90#else
91 .gclk_src = SAM0_GCLK_MAIN,
92#endif
93 .flags = TC_CTRLA_MODE_COUNT16,
94 },
95 { /* Timer 1 */
96 .dev = TC4,
97 .irq = TC4_IRQn,
98 .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
99 .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
100#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
101 .gclk_src = SAM0_GCLK_1MHZ,
102#else
103 .gclk_src = SAM0_GCLK_MAIN,
104#endif
105 .flags = TC_CTRLA_MODE_COUNT32,
106 }
107};
108
109#define TIMER_0_MAX_VALUE 0xffff
110
111/* interrupt function name mapping */
112#define TIMER_0_ISR isr_tc3
113#define TIMER_1_ISR isr_tc4
114
115#define TIMER_NUMOF ARRAY_SIZE(timer_config)
122static const uart_conf_t uart_config[] = {
123 {
124 .dev = &SERCOM3->USART,
125 .rx_pin = GPIO_PIN(PA, 23),
126 .tx_pin = GPIO_PIN(PA, 22),
127#ifdef MODULE_PERIPH_UART_HW_FC
128 .rts_pin = GPIO_UNDEF,
129 .cts_pin = GPIO_UNDEF,
130#endif
131 .mux = GPIO_MUX_C,
132 .rx_pad = UART_PAD_RX_1,
133 .tx_pad = UART_PAD_TX_0,
134 .flags = UART_FLAG_NONE,
135 .gclk_src = SAM0_GCLK_MAIN,
136 },
137 {
138 .dev = &SERCOM4->USART,
139 .rx_pin = GPIO_PIN(PB, 9),
140 .tx_pin = GPIO_PIN(PB, 8),
141#ifdef MODULE_PERIPH_UART_HW_FC
142 .rts_pin = GPIO_UNDEF,
143 .cts_pin = GPIO_UNDEF,
144#endif
145 .mux = GPIO_MUX_D,
146 .rx_pad = UART_PAD_RX_1,
147 .tx_pad = UART_PAD_TX_0,
148 .flags = UART_FLAG_NONE,
149 .gclk_src = SAM0_GCLK_MAIN,
150 }
151};
152
153/* interrupt function name mapping */
154#define UART_0_ISR isr_sercom3
155#define UART_1_ISR isr_sercom4
156
157#define UART_NUMOF ARRAY_SIZE(uart_config)
164static const spi_conf_t spi_config[] = {
165 {
166 .dev = &SERCOM1->SPI,
167 .miso_pin = GPIO_PIN(PA, 19),
168 .mosi_pin = GPIO_PIN(PA, 16),
169 .clk_pin = GPIO_PIN(PA, 17),
170 .miso_mux = GPIO_MUX_C,
171 .mosi_mux = GPIO_MUX_C,
172 .clk_mux = GPIO_MUX_C,
173 .miso_pad = SPI_PAD_MISO_3,
174 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
175 .gclk_src = SAM0_GCLK_MAIN,
176#ifdef MODULE_PERIPH_DMA
177 .tx_trigger = SERCOM1_DMAC_ID_TX,
178 .rx_trigger = SERCOM1_DMAC_ID_RX,
179#endif
180 }
181};
182
183#define SPI_NUMOF ARRAY_SIZE(spi_config)
190static const i2c_conf_t i2c_config[] = {
191 {
192 .dev = &(SERCOM0->I2CM),
193 .speed = I2C_SPEED_NORMAL,
194 .scl_pin = GPIO_PIN(PA, 8),
195 .sda_pin = GPIO_PIN(PA, 9),
196 .mux = GPIO_MUX_C,
197 .gclk_src = SAM0_GCLK_MAIN,
198 .flags = I2C_FLAG_NONE
199 },
200 {
201 .dev = &(SERCOM2->I2CM),
202 .speed = I2C_SPEED_NORMAL,
203 .scl_pin = GPIO_PIN(PA, 12),
204 .sda_pin = GPIO_PIN(PA, 13),
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#ifndef RTT_FREQUENCY
219#define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtc_rtt.c` */
220#endif
228/* ADC Default values */
229#define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
230
231#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
232#define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
233#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
234
235/* Digital pins (1 to 6) on the board can be configured as analog inputs */
236static const adc_conf_chan_t adc_channels[] = {
237 /* port, pin, muxpos */
238 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 }, /* Digital 1 */
239 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 }, /* Digital 2 */
240 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 }, /* Digital 3 */
241 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 }, /* Digital 4 */
242 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA03 }, /* Digital 5 */
243 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }, /* Digital 6 */
244};
245
246#define ADC_NUMOF ARRAY_SIZE(adc_channels)
253static const sam0_common_usb_config_t sam_usbdev_config[] = {
254 {
255 .dm = GPIO_PIN(PA, 24),
256 .dp = GPIO_PIN(PA, 25),
257 .d_mux = GPIO_MUX_G,
258 .device = &USB->DEVICE,
259 .gclk_src = SAM0_GCLK_MAIN,
260 }
261};
264#ifdef __cplusplus
265}
266#endif
267
268#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
@ UART_PAD_RX_1
select pad 1
@ PB
port B
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_3
use pad 3 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
@ GPIO_MUX_C
select peripheral function C
@ SPI_PAD_MOSI_0_SCK_1
use pad 0 for MOSI, pad 1 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA05
Alias for PIN5.
Definition periph_cpu.h:124
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition periph_cpu.h:76
#define ADC_INPUTCTRL_MUXPOS_PA07
Alias for PIN7.
Definition periph_cpu.h:126
#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 ADC_INPUTCTRL_MUXPOS_PA03
Alias for PIN1.
Definition periph_cpu.h:120
#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