periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Antonio Galea
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 (48000000U)
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_TIMER,
52  .flags = TC_CTRLA_MODE_COUNT32,
53  }
54 };
55 
56 /* Timer 0 configuration */
57 #define TIMER_0_CHANNELS 2
58 #define TIMER_0_ISR isr_tc0
59 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
66 static const uart_conf_t uart_config[] = {
67  {
68  .dev = &SERCOM3->USART,
69  .rx_pin = GPIO_PIN(PA, 23),
70  .tx_pin = GPIO_PIN(PA, 22),
71 #ifdef MODULE_PERIPH_UART_HW_FC
72  .rts_pin = GPIO_UNDEF,
73  .cts_pin = GPIO_UNDEF,
74 #endif
75  .mux = GPIO_MUX_C,
76  .rx_pad = UART_PAD_RX_1,
77  .tx_pad = UART_PAD_TX_0,
78  .flags = UART_FLAG_NONE,
79  .gclk_src = SAM0_GCLK_MAIN,
80  }
81 };
82 
83 /* interrupt function name mapping */
84 #define UART_0_ISR isr_sercom3
85 
86 #define UART_NUMOF ARRAY_SIZE(uart_config)
93 static const spi_conf_t spi_config[] = {
94  {
95  .dev = &(SERCOM0->SPI),
96  .miso_pin = GPIO_PIN(PA, 4),
97  .mosi_pin = GPIO_PIN(PA, 6),
98  .clk_pin = GPIO_PIN(PA, 7),
99  .miso_mux = GPIO_MUX_D,
100  .mosi_mux = GPIO_MUX_D,
101  .clk_mux = GPIO_MUX_D,
102  .miso_pad = SPI_PAD_MISO_0,
103  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
104  .gclk_src = SAM0_GCLK_MAIN,
105 #ifdef MODULE_PERIPH_DMA
106  .tx_trigger = SERCOM0_DMAC_ID_TX,
107  .rx_trigger = SERCOM0_DMAC_ID_RX,
108 #endif
109  }
110 };
111 
112 #define SPI_NUMOF ARRAY_SIZE(spi_config)
119 static const i2c_conf_t i2c_config[] = {
120  {
121  .dev = &(SERCOM2->I2CM),
122  .speed = I2C_SPEED_NORMAL,
123  .scl_pin = GPIO_PIN(PA, 9),
124  .sda_pin = GPIO_PIN(PA, 8),
125  .mux = GPIO_MUX_D,
126  .gclk_src = SAM0_GCLK_MAIN,
127  .flags = I2C_FLAG_NONE
128  }
129 };
130 
131 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
138 #define EXTERNAL_OSC32_SOURCE 1
139 #define INTERNAL_OSC32_SOURCE 0
140 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
147 #ifndef RTT_FREQUENCY
148 #define RTT_FREQUENCY (32768U)
149 #endif
150 
158 /* ADC Default values */
159 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
160 
161 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
162 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
163 
164 static const adc_conf_chan_t adc_channels[] = {
165  /* port, pin, muxpos */
166  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 },
167  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA11 },
168  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 },
169  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA03 }
170 };
171 
172 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
179 static const sam0_common_usb_config_t sam_usbdev_config[] = {
180  {
181  .dm = GPIO_PIN(PA, 24),
182  .dp = GPIO_PIN(PA, 25),
183  .d_mux = GPIO_MUX_G,
184  .device = &USB->DEVICE,
185  .gclk_src = SAM0_GCLK_48MHZ,
186  }
187 };
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #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 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
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_0
use pad 0 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_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 ADC_INPUTCTRL_MUXPOS_PA11
Alias for PIN19.
Definition: periph_cpu.h:138
#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
@ SAM0_GCLK_TIMER
4/8MHz clock for timers
Definition: periph_cpu.h:71
@ SAM0_GCLK_48MHZ
48MHz clock
Definition: periph_cpu.h:73
ADC Channel Configuration.
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.
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