periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Freie Universität Berlin
3  * 2016 UC Berkeley
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
10 #pragma once
11 
26 #include <stdint.h>
27 
28 #include "cpu.h"
29 #include "periph_cpu.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
67 #define CLOCK_USE_PLL (1)
68 
69 #if CLOCK_USE_PLL
70 /* edit these values to adjust the PLL output frequency */
71 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
72 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
73 /* generate the actual used core clock frequency */
74 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
75 #elif CLOCK_USE_XOSC32_DFLL
76 /* Settings for 32 kHz external oscillator and 48 MHz DFLL */
77 #define CLOCK_CORECLOCK (48000000U)
78 #define CLOCK_XOSC32K (32768UL)
79 #define CLOCK_8MHZ (1)
80 #define GEN2_ULP32K (1)
81 #else
82 /* edit this value to your needs */
83 #define CLOCK_DIV (1U)
84 /* generate the actual core clock frequency */
85 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
86 #endif
93 #ifndef RTT_FREQUENCY
94 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
95 #endif
102 static const tc32_conf_t timer_config[] = {
103  { /* Timer 0 - System Clock */
104  .dev = TC3,
105  .irq = TC3_IRQn,
106  .pm_mask = PM_APBCMASK_TC3,
107  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
108 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
109  .gclk_src = SAM0_GCLK_1MHZ,
110 #else
111  .gclk_src = SAM0_GCLK_MAIN,
112 #endif
113  .flags = TC_CTRLA_MODE_COUNT16,
114  },
115  { /* Timer 1 */
116  .dev = TC4,
117  .irq = TC4_IRQn,
118  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
119  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
120 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
121  .gclk_src = SAM0_GCLK_1MHZ,
122 #else
123  .gclk_src = SAM0_GCLK_MAIN,
124 #endif
125  .flags = TC_CTRLA_MODE_COUNT32,
126  }
127 };
128 
129 #define TIMER_0_MAX_VALUE 0xffff
130 
131 /* interrupt function name mapping */
132 #define TIMER_0_ISR isr_tc3
133 #define TIMER_1_ISR isr_tc4
134 
135 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
143 /* ADC Default values */
144 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
145 
146 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
147 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
148 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
149 
150 static const adc_conf_chan_t adc_channels[] = {
151  /* port, pin, muxpos */
152  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
153  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 },
154  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA08 },
155 };
156 
157 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
164 #define PWM_0_EN 1
165 #define PWM_1_EN 1
166 
167 #if PWM_0_EN
168 /* PWM0 channels */
169 static const pwm_conf_chan_t pwm_chan0_config[] = {
170  /* GPIO pin, MUX value, TCC channel */
171  {GPIO_PIN(PA, 6), GPIO_MUX_E, 0},
172  {GPIO_PIN(PA, 7), GPIO_MUX_E, 1},
173 };
174 #endif
175 #if PWM_1_EN
176 /* PWM1 channels */
177 static const pwm_conf_chan_t pwm_chan1_config[] = {
178  /* GPIO pin, MUX value, TCC channel */
179  {GPIO_PIN(PA, 18), GPIO_MUX_F, 2},
180  {GPIO_PIN(PA, 19), GPIO_MUX_F, 3},
181 };
182 #endif
183 
184 /* PWM device configuration */
185 static const pwm_conf_t pwm_config[] = {
186 #if PWM_0_EN
187  {TCC_CONFIG(TCC1), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
188 #endif
189 #if PWM_1_EN
190  {TCC_CONFIG(TCC0), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
191 #endif
192 };
193 
194 /* number of devices that are actually defined */
195 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
202 static const spi_conf_t spi_config[] = {
203  {
204  .dev = &SERCOM4->SPI,
205  .miso_pin = GPIO_PIN(PC, 19),
206  .mosi_pin = GPIO_PIN(PB, 30),
207  .clk_pin = GPIO_PIN(PC, 18),
208  .miso_mux = GPIO_MUX_F,
209  .mosi_mux = GPIO_MUX_F,
210  .clk_mux = GPIO_MUX_F,
211  .miso_pad = SPI_PAD_MISO_0,
212  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
213  .gclk_src = SAM0_GCLK_MAIN,
214 #ifdef MODULE_PERIPH_DMA
215  .tx_trigger = SERCOM4_DMAC_ID_TX,
216  .rx_trigger = SERCOM4_DMAC_ID_RX,
217 #endif
218  }
219 };
220 
221 #define SPI_NUMOF ARRAY_SIZE(spi_config)
228 static const i2c_conf_t i2c_config[] = {
229  {
230  .dev = &(SERCOM3->I2CM),
231  .speed = I2C_SPEED_FAST,
232  .scl_pin = GPIO_PIN(PA, 17),
233  .sda_pin = GPIO_PIN(PA, 16),
234  .mux = GPIO_MUX_D,
235  .gclk_src = SAM0_GCLK_MAIN,
236  .flags = I2C_FLAG_NONE
237  }
238 };
239 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
246 #define RANDOM_NUMOF (0U)
249 #ifdef __cplusplus
250 }
251 #endif
252 
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
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 pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:221
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:82
static const gpio_t adc_channels[]
Static array with declared ADC channels.
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: periph_cpu.h:278
@ 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 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_F
select peripheral function F
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition: periph_cpu.h:75
#define ADC_INPUTCTRL_MUXPOS_PA08
Alias for PIN16.
Definition: periph_cpu.h:134
#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 SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:73
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
PWM channel configuration data structure.
PWM device configuration.
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