Loading...
Searching...
No Matches
periph_conf_common.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Freie Universität Berlin
3 * SPDX-FileCopyrightText: 2016-2017 Inria
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
23
24#include "periph_cpu.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
61#define CLOCK_USE_PLL (1)
62
63#if CLOCK_USE_PLL
64/* edit these values to adjust the PLL output frequency */
65#define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
66#define CLOCK_PLL_DIV (1U) /* adjust to your needs */
67/* generate the actual used core clock frequency */
68#define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
69#else
70/* edit this value to your needs */
71#define CLOCK_DIV (1U)
72/* generate the actual core clock frequency */
73#define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
74#endif
76
81static const tc32_conf_t timer_config[] = {
82 { /* Timer 0 - System Clock */
83 .dev = TC3,
84 .irq = TC3_IRQn,
85 .pm_mask = PM_APBCMASK_TC3,
86 .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
87#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
88 .gclk_src = SAM0_GCLK_1MHZ,
89#else
90 .gclk_src = SAM0_GCLK_MAIN,
91#endif
92 .flags = TC_CTRLA_MODE_COUNT16,
93 },
94 { /* Timer 1 */
95 .dev = TC4,
96 .irq = TC4_IRQn,
97 .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
98 .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
99#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
100 .gclk_src = SAM0_GCLK_1MHZ,
101#else
102 .gclk_src = SAM0_GCLK_MAIN,
103#endif
104 .flags = TC_CTRLA_MODE_COUNT32,
105 }
106};
107
108#define TIMER_0_MAX_VALUE 0xffff
109
110/* interrupt function name mapping */
111#define TIMER_0_ISR isr_tc3
112#define TIMER_1_ISR isr_tc4
113
114#define TIMER_NUMOF ARRAY_SIZE(timer_config)
116
121#define PWM_0_EN 1
122
123#if PWM_0_EN
124/* PWM0 channels */
125static const pwm_conf_chan_t pwm_chan0_config[] = {
126 /* GPIO pin, MUX value, TCC channel */
127 { GPIO_PIN(PA, 10), GPIO_MUX_F, 2 }, /* ~2 */
128 { GPIO_PIN(PA, 11), GPIO_MUX_F, 3 }, /* ~3 */
129};
130#endif
131
132/* PWM device configuration */
133static const pwm_conf_t pwm_config[] = {
134#if PWM_0_EN
135 {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
136#endif
137};
138
139/* number of devices that are actually defined */
140#define PWM_NUMOF ARRAY_SIZE(pwm_config)
142
147
148/* ADC Default values */
149#define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
150
151#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
152#define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
153#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
154
155static const adc_conf_chan_t adc_channels[] = {
156 /* port, pin, muxpos */
157 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }, /* A0 */
158 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB02 }, /* A1 */
159 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB03 }, /* A2 */
160 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 }, /* A3 */
161 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 }, /* A4 */
162 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 }, /* A5 */
163 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 }, /* A6 */
164};
165
166#define ADC_NUMOF ARRAY_SIZE(adc_channels)
168
173static const i2c_conf_t i2c_config[] = {
174 {
175 .dev = &(SERCOM0->I2CM),
176 .speed = I2C_SPEED_NORMAL,
177 .scl_pin = GPIO_PIN(PA, 9),
178 .sda_pin = GPIO_PIN(PA, 8),
179 .mux = GPIO_MUX_C,
180 .gclk_src = SAM0_GCLK_MAIN,
181 .flags = I2C_FLAG_NONE
182 }
183};
184#define I2C_NUMOF ARRAY_SIZE(i2c_config)
186
191#ifndef RTT_FREQUENCY
192#define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
193#endif
195
200static const sam0_common_usb_config_t sam_usbdev_config[] = {
201 {
202 .dm = GPIO_PIN(PA, 24),
203 .dp = GPIO_PIN(PA, 25),
204 .d_mux = GPIO_MUX_G,
205 .device = &USB->DEVICE,
206 .gclk_src = SAM0_GCLK_MAIN,
207 }
208};
210
211#ifdef __cplusplus
212}
213#endif
214
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition periph_cpu.h:45
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:277
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:82
@ I2C_FLAG_NONE
No flags set.
@ PA
port A
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ GPIO_MUX_F
select peripheral function F
#define ADC_INPUTCTRL_MUXPOS_PA05
Alias for PIN5.
Definition periph_cpu.h:123
#define ADC_INPUTCTRL_MUXPOS_PB02
Alias for PIN10.
Definition periph_cpu.h:128
#define ADC_INPUTCTRL_MUXPOS_PA07
Alias for PIN7.
Definition periph_cpu.h:125
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition periph_cpu.h:75
#define ADC_INPUTCTRL_MUXPOS_PA04
Alias for PIN4.
Definition periph_cpu.h:122
#define ADC_INPUTCTRL_MUXPOS_PB03
Alias for PIN11.
Definition periph_cpu.h:129
#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
ADC Channel Configuration.
I2C configuration structure.
Definition periph_cpu.h:298
PWM channel configuration data structure.
PWM device configuration.
USB peripheral parameters.
Timer device configuration.