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 
24 #ifndef PERIPH_CONF_H
25 #define PERIPH_CONF_H
26 
27 #include <stdint.h>
28 
29 #include "cpu.h"
30 #include "periph_cpu.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
68 #define CLOCK_USE_PLL (1)
69 
70 #if CLOCK_USE_PLL
71 /* edit these values to adjust the PLL output frequency */
72 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
73 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
74 /* generate the actual used core clock frequency */
75 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
76 #elif CLOCK_USE_XOSC32_DFLL
77 /* Settings for 32 kHz external oscillator and 48 MHz DFLL */
78 #define CLOCK_CORECLOCK (48000000U)
79 #define CLOCK_XOSC32K (32768UL)
80 #define CLOCK_8MHZ (1)
81 #define GEN2_ULP32K (1)
82 #else
83 /* edit this value to your needs */
84 #define CLOCK_DIV (1U)
85 /* generate the actual core clock frequency */
86 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
87 #endif
88 
94 #ifndef RTT_FREQUENCY
95 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
96 #endif
97 
103 static const tc32_conf_t timer_config[] = {
104  { /* Timer 0 - System Clock */
105  .dev = TC3,
106  .irq = TC3_IRQn,
107  .pm_mask = PM_APBCMASK_TC3,
108  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
109 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
110  .gclk_src = SAM0_GCLK_1MHZ,
111 #else
112  .gclk_src = SAM0_GCLK_MAIN,
113 #endif
114  .flags = TC_CTRLA_MODE_COUNT16,
115  },
116  { /* Timer 1 */
117  .dev = TC4,
118  .irq = TC4_IRQn,
119  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
120  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
121 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
122  .gclk_src = SAM0_GCLK_1MHZ,
123 #else
124  .gclk_src = SAM0_GCLK_MAIN,
125 #endif
126  .flags = TC_CTRLA_MODE_COUNT32,
127  }
128 };
129 
130 #define TIMER_0_MAX_VALUE 0xffff
131 
132 /* interrupt function name mapping */
133 #define TIMER_0_ISR isr_tc3
134 #define TIMER_1_ISR isr_tc4
135 
136 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
137 
144 /* ADC Default values */
145 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
146 
147 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
148 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
149 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
150 
151 static const adc_conf_chan_t adc_channels[] = {
152  /* port, pin, muxpos */
153  {GPIO_PIN(PA, 6), ADC_INPUTCTRL_MUXPOS_PIN6},
154  {GPIO_PIN(PA, 7), ADC_INPUTCTRL_MUXPOS_PIN7},
155  {GPIO_PIN(PA, 8), ADC_INPUTCTRL_MUXPOS_PIN16},
156 };
157 
158 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
159 
165 #define PWM_0_EN 1
166 #define PWM_1_EN 1
167 
168 #if PWM_0_EN
169 /* PWM0 channels */
170 static const pwm_conf_chan_t pwm_chan0_config[] = {
171  /* GPIO pin, MUX value, TCC channel */
172  {GPIO_PIN(PA, 6), GPIO_MUX_E, 0},
173  {GPIO_PIN(PA, 7), GPIO_MUX_E, 1},
174 };
175 #endif
176 #if PWM_1_EN
177 /* PWM1 channels */
178 static const pwm_conf_chan_t pwm_chan1_config[] = {
179  /* GPIO pin, MUX value, TCC channel */
180  {GPIO_PIN(PA, 18), GPIO_MUX_F, 2},
181  {GPIO_PIN(PA, 19), GPIO_MUX_F, 3},
182 };
183 #endif
184 
185 
186 /* PWM device configuration */
187 static const pwm_conf_t pwm_config[] = {
188 #if PWM_0_EN
189  {TCC_CONFIG(TCC1), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
190 #endif
191 #if PWM_1_EN
192  {TCC_CONFIG(TCC0), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
193 #endif
194 };
195 
196 /* number of devices that are actually defined */
197 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
198 
204 static const spi_conf_t spi_config[] = {
205  {
206  .dev = &SERCOM4->SPI,
207  .miso_pin = GPIO_PIN(PC, 19),
208  .mosi_pin = GPIO_PIN(PB, 30),
209  .clk_pin = GPIO_PIN(PC, 18),
210  .miso_mux = GPIO_MUX_F,
211  .mosi_mux = GPIO_MUX_F,
212  .clk_mux = GPIO_MUX_F,
213  .miso_pad = SPI_PAD_MISO_0,
214  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
215  .gclk_src = SAM0_GCLK_MAIN,
216 #ifdef MODULE_PERIPH_DMA
217  .tx_trigger = SERCOM4_DMAC_ID_TX,
218  .rx_trigger = SERCOM4_DMAC_ID_RX,
219 #endif
220  }
221 };
222 
223 #define SPI_NUMOF ARRAY_SIZE(spi_config)
224 
230 static const i2c_conf_t i2c_config[] = {
231  {
232  .dev = &(SERCOM3->I2CM),
233  .speed = I2C_SPEED_FAST,
234  .scl_pin = GPIO_PIN(PA, 17),
235  .sda_pin = GPIO_PIN(PA, 16),
236  .mux = GPIO_MUX_D,
237  .gclk_src = SAM0_GCLK_MAIN,
238  .flags = I2C_FLAG_NONE
239  }
240 };
241 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
242 
247 #define RANDOM_NUMOF (0U)
248 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* PERIPH_CONF_H */
255 
GPIO_MUX_F
@ GPIO_MUX_F
select peripheral function F
Definition: periph_cpu_common.h:141
SAM0_GCLK_MAIN
@ SAM0_GCLK_MAIN
48 MHz main clock
Definition: periph_cpu.h:59
GPIO_MUX_E
@ GPIO_MUX_E
select peripheral function E
Definition: periph_cpu_common.h:140
I2C_FLAG_NONE
@ I2C_FLAG_NONE
No flags set.
Definition: periph_cpu_common.h:407
PB
@ PB
port B
Definition: periph_cpu_common.h:89
ARRAY_SIZE
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: kernel_defines.h:122
pwm_conf_t
PWM device configuration.
Definition: periph_cpu_common.h:153
SPI_PAD_MISO_0
@ SPI_PAD_MISO_0
use pad 0 for MISO line
Definition: periph_cpu_common.h:327
pwm_conf_chan_t
PWM channel configuration data structure.
Definition: periph_cpu_common.h:307
adc_channels
static const gpio_t adc_channels[]
Static array with declared ADC channels.
Definition: periph_conf_common.h:53
tc32_conf_t::dev
Tc * dev
pointer to the used Timer device
Definition: periph_cpu_common.h:462
SPI_PAD_MOSI_2_SCK_3
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
Definition: periph_cpu_common.h:338
GPIO_PIN
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:35
adc_conf_chan_t
ADC Channel Configuration.
Definition: periph_cpu_common.h:765
tc32_conf_t
Timer device configuration.
Definition: periph_cpu_common.h:461
GPIO_MUX_D
@ GPIO_MUX_D
select peripheral function D
Definition: periph_cpu_common.h:139
PC
@ PC
port C
Definition: periph_cpu_common.h:90
PA
@ PA
port A
Definition: periph_cpu_common.h:88
i2c_conf_t
I2C configuration options.
Definition: periph_cpu.h:128
SAM0_GCLK_1MHZ
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition: periph_cpu.h:60
I2C_SPEED_FAST
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: i2c.h:178
spi_conf_t::dev
SPI_Type * dev
SPI device to use.
Definition: periph_cpu.h:465
TCC_CONFIG
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
Definition: periph_cpu_common.h:297
spi_conf_t
SPI configuration structure type.
Definition: periph_cpu.h:273
i2c_conf_t::dev
I2C_TypeDef * dev
USART device used.
Definition: periph_cpu.h:247