periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Baptiste Clenet <bapclenet@gmail.com>
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 
9 #pragma once
10 
21 #include "periph_cpu.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
30 #define CLOCK_CORECLOCK (48000000U)
31 
36 static const tc32_conf_t timer_config[] = {
37  { /* Timer 0 - System Clock */
38  .dev = TC0,
39  .irq = TC0_IRQn,
40  .mclk = &MCLK->APBCMASK.reg,
41  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
42  .gclk_id = TC0_GCLK_ID,
43  .gclk_src = SAM0_GCLK_TIMER,
44  .flags = TC_CTRLA_MODE_COUNT32,
45  }
46 };
47 
48 /* Timer 0 configuration */
49 #define TIMER_0_CHANNELS 2
50 #define TIMER_0_ISR isr_tc0
51 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
58 static const uart_conf_t uart_config[] = {
59  { /* Virtual COM Port */
60  .dev = &SERCOM0->USART,
61  .rx_pin = GPIO_PIN(PA,5),
62  .tx_pin = GPIO_PIN(PA,4),
63 #ifdef MODULE_PERIPH_UART_HW_FC
64  .rts_pin = GPIO_UNDEF,
65  .cts_pin = GPIO_UNDEF,
66 #endif
67  .mux = GPIO_MUX_D,
68  .rx_pad = UART_PAD_RX_1,
69  .tx_pad = UART_PAD_TX_0,
70  .flags = UART_FLAG_NONE,
71  .gclk_src = SAM0_GCLK_MAIN,
72  }
73 };
74 
75 /* interrupt function name mapping */
76 #define UART_0_ISR isr_sercom0
77 
78 #define UART_NUMOF ARRAY_SIZE(uart_config)
85 static const spi_conf_t spi_config[] = {
86  { /* Internal AT86RF212B */
87  .dev = &(SERCOM4->SPI),
88  .miso_pin = GPIO_PIN(PC, 19),
89  .mosi_pin = GPIO_PIN(PB, 30),
90  .clk_pin = GPIO_PIN(PC, 18),
91  .miso_mux = GPIO_MUX_F,
92  .mosi_mux = GPIO_MUX_F,
93  .clk_mux = GPIO_MUX_F,
94  .miso_pad = SPI_PAD_MISO_0,
95  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
96  .gclk_src = SAM0_GCLK_MAIN,
97 #ifdef MODULE_PERIPH_DMA
98  .tx_trigger = SERCOM4_DMAC_ID_TX,
99  .rx_trigger = SERCOM4_DMAC_ID_RX,
100 #endif
101  },
102  { /* EXT1 & EXT3 Pin Header */
103  .dev = &(SERCOM5->SPI),
104  .miso_pin = GPIO_PIN(PB, 2),
105  .mosi_pin = GPIO_PIN(PB, 22),
106  .clk_pin = GPIO_PIN(PB, 23),
107  .miso_mux = GPIO_MUX_D,
108  .mosi_mux = GPIO_MUX_D,
109  .clk_mux = GPIO_MUX_D,
110  .miso_pad = SPI_PAD_MISO_0,
111  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
112  .gclk_src = SAM0_GCLK_MAIN,
113 #ifdef MODULE_PERIPH_DMA
114  /* The SAML21 doesn't support DMA triggers on SERCOM5 */
115  .tx_trigger = DMA_TRIGGER_DISABLED,
116  .rx_trigger = DMA_TRIGGER_DISABLED,
117 #endif
118  }
119 };
120 
121 #define SPI_NUMOF ARRAY_SIZE(spi_config)
128 static const i2c_conf_t i2c_config[] = {
129  { /* EXT1 & EXT3 Pin Header */
130  .dev = &(SERCOM1->I2CM),
131  .speed = I2C_SPEED_NORMAL,
132  .scl_pin = GPIO_PIN(PA, 17),
133  .sda_pin = GPIO_PIN(PA, 16),
134  .mux = GPIO_MUX_C,
135  .gclk_src = SAM0_GCLK_MAIN,
136  .flags = I2C_FLAG_NONE
137  }
138 };
139 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
146 #define EXTERNAL_OSC32_SOURCE 1
147 #define INTERNAL_OSC32_SOURCE 0
148 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
155 #ifndef RTT_FREQUENCY
156 #define RTT_FREQUENCY (32768U)
157 #endif
165 /* ADC Default values */
166 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
167 
168 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
169 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
170 
171 static const adc_conf_chan_t adc_channels[] = {
172  /* port, pin, muxpos */
173  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 }, /* EXT1, pin 3 */
174  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 }, /* EXT1, pin 4 */
175  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 },
176  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA11 },
177  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }
178 };
179 
180 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
187 static const sam0_common_usb_config_t sam_usbdev_config[] = {
188  {
189  .dm = GPIO_PIN(PA, 24),
190  .dp = GPIO_PIN(PA, 25),
191  .d_mux = GPIO_MUX_G,
192  .device = &USB->DEVICE,
193  .gclk_src = SAM0_GCLK_48MHZ,
194  }
195 };
198 #ifdef __cplusplus
199 }
200 #endif
201 
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const uart_conf_t uart_config[]
UART configuration.
Definition: periph_conf.h:38
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:96
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:68
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:39
static const gpio_t adc_channels[]
Static array with declared ADC channels.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:277
@ UART_PAD_RX_1
select pad 1
@ PB
port B
@ PC
port C
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_0
use pad 0 for MISO line
#define DMA_TRIGGER_DISABLED
Indicates that the peripheral doesn't utilize the DMA controller.
@ 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
@ GPIO_MUX_F
select peripheral function F
@ 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:136
#define ADC_INPUTCTRL_MUXPOS_PA11
Alias for PIN19.
Definition: periph_cpu.h:137
#define ADC_INPUTCTRL_MUXPOS_PA07
Alias for PIN7.
Definition: periph_cpu.h:125
#define ADC_INPUTCTRL_MUXPOS_PA06
Alias for PIN6.
Definition: periph_cpu.h:124
#define ADC_INPUTCTRL_MUXPOS_PA02
ADC pin aliases.
Definition: periph_cpu.h:118
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:73
@ SAM0_GCLK_TIMER
4/8MHz clock for timers
Definition: periph_cpu.h:70
@ SAM0_GCLK_48MHZ
48MHz clock
Definition: periph_cpu.h:72
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
USB peripheral parameters.
SPI device configuration.
Definition: periph_cpu.h:336
SPI_t * dev
pointer to the used SPI device
Definition: periph_cpu.h:337
Timer device configuration.
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:264
UART device configuration.
Definition: periph_cpu.h:217
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:218