Loading...
Searching...
No Matches
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
33extern "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
94#ifndef RTT_FREQUENCY
95#define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
96#endif
103static 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)
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
151static const adc_conf_chan_t adc_channels[] = {
152 /* port, pin, muxpos */
154 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 },
155 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA08 },
156};
157
158#define ADC_NUMOF ARRAY_SIZE(adc_channels)
165#define PWM_0_EN 1
166#define PWM_1_EN 1
167
168#if PWM_0_EN
169/* PWM0 channels */
170static 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 */
178static 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/* PWM device configuration */
186static const pwm_conf_t pwm_config[] = {
187#if PWM_0_EN
188 {TCC_CONFIG(TCC1), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
189#endif
190#if PWM_1_EN
191 {TCC_CONFIG(TCC0), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
192#endif
193};
194
195/* number of devices that are actually defined */
196#define PWM_NUMOF ARRAY_SIZE(pwm_config)
203static const spi_conf_t spi_config[] = {
204 {
205 .dev = &SERCOM4->SPI,
206 .miso_pin = GPIO_PIN(PC, 19),
207 .mosi_pin = GPIO_PIN(PB, 30),
208 .clk_pin = GPIO_PIN(PC, 18),
209 .miso_mux = GPIO_MUX_F,
210 .mosi_mux = GPIO_MUX_F,
211 .clk_mux = GPIO_MUX_F,
212 .miso_pad = SPI_PAD_MISO_0,
213 .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
214 .gclk_src = SAM0_GCLK_MAIN,
215#ifdef MODULE_PERIPH_DMA
216 .tx_trigger = SERCOM4_DMAC_ID_TX,
217 .rx_trigger = SERCOM4_DMAC_ID_RX,
218#endif
219 }
220};
221
222#define SPI_NUMOF ARRAY_SIZE(spi_config)
229static const i2c_conf_t i2c_config[] = {
230 {
231 .dev = &(SERCOM3->I2CM),
232 .speed = I2C_SPEED_FAST,
233 .scl_pin = GPIO_PIN(PA, 17),
234 .sda_pin = GPIO_PIN(PA, 16),
235 .mux = GPIO_MUX_D,
236 .gclk_src = SAM0_GCLK_MAIN,
237 .flags = I2C_FLAG_NONE
238 }
239};
240#define I2C_NUMOF ARRAY_SIZE(i2c_config)
247#define RANDOM_NUMOF (0U)
250#ifdef __cplusplus
251}
252#endif
253
254#endif /* PERIPH_CONF_H */
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition periph_cpu.h:46
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition periph_cpu.h:279
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:83
@ 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:76
#define ADC_INPUTCTRL_MUXPOS_PA08
Alias for PIN16.
Definition periph_cpu.h:135
#define ADC_INPUTCTRL_MUXPOS_PA07
Alias for PIN7.
Definition periph_cpu.h:126
#define ADC_INPUTCTRL_MUXPOS_PA06
Alias for PIN6.
Definition periph_cpu.h:125
#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
PWM channel configuration data structure.
PWM device configuration.
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