Loading...
Searching...
No Matches
periph_conf_common.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Freie Universität Berlin
3 * 2016-2017 Inria
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
27#include "periph_cpu.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
64#define CLOCK_USE_PLL (1)
65
66#if CLOCK_USE_PLL
67/* edit these values to adjust the PLL output frequency */
68#define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
69#define CLOCK_PLL_DIV (1U) /* adjust to your needs */
70/* generate the actual used core clock frequency */
71#define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
72#else
73/* edit this value to your needs */
74#define CLOCK_DIV (1U)
75/* generate the actual core clock frequency */
76#define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
77#endif
79
84static const tc32_conf_t timer_config[] = {
85 { /* Timer 0 - System Clock */
86 .dev = TC3,
87 .irq = TC3_IRQn,
88 .pm_mask = PM_APBCMASK_TC3,
89 .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
90#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
91 .gclk_src = SAM0_GCLK_1MHZ,
92#else
93 .gclk_src = SAM0_GCLK_MAIN,
94#endif
95 .flags = TC_CTRLA_MODE_COUNT16,
96 },
97 { /* Timer 1 */
98 .dev = TC4,
99 .irq = TC4_IRQn,
100 .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
101 .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
102#if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
103 .gclk_src = SAM0_GCLK_1MHZ,
104#else
105 .gclk_src = SAM0_GCLK_MAIN,
106#endif
107 .flags = TC_CTRLA_MODE_COUNT32,
108 }
109};
110
111#define TIMER_0_MAX_VALUE 0xffff
112
113/* interrupt function name mapping */
114#define TIMER_0_ISR isr_tc3
115#define TIMER_1_ISR isr_tc4
116
117#define TIMER_NUMOF ARRAY_SIZE(timer_config)
119
124#define PWM_0_EN 1
125
126#if PWM_0_EN
127/* PWM0 channels */
128static const pwm_conf_chan_t pwm_chan0_config[] = {
129 /* GPIO pin, MUX value, TCC channel */
130 { GPIO_PIN(PA, 10), GPIO_MUX_F, 2 }, /* ~2 */
131 { GPIO_PIN(PA, 11), GPIO_MUX_F, 3 }, /* ~3 */
132};
133#endif
134
135/* PWM device configuration */
136static const pwm_conf_t pwm_config[] = {
137#if PWM_0_EN
138 {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
139#endif
140};
141
142/* number of devices that are actually defined */
143#define PWM_NUMOF ARRAY_SIZE(pwm_config)
145
150
151/* ADC Default values */
152#define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
153
154#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
155#define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
156#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
157
158static const adc_conf_chan_t adc_channels[] = {
159 /* port, pin, muxpos */
160 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }, /* A0 */
161 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB02 }, /* A1 */
162 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB03 }, /* A2 */
163 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 }, /* A3 */
164 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 }, /* A4 */
165 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 }, /* A5 */
166 { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 }, /* A6 */
167};
168
169#define ADC_NUMOF ARRAY_SIZE(adc_channels)
171
176static const i2c_conf_t i2c_config[] = {
177 {
178 .dev = &(SERCOM0->I2CM),
179 .speed = I2C_SPEED_NORMAL,
180 .scl_pin = GPIO_PIN(PA, 9),
181 .sda_pin = GPIO_PIN(PA, 8),
182 .mux = GPIO_MUX_C,
183 .gclk_src = SAM0_GCLK_MAIN,
184 .flags = I2C_FLAG_NONE
185 }
186};
187#define I2C_NUMOF ARRAY_SIZE(i2c_config)
189
194#ifndef RTT_FREQUENCY
195#define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
196#endif
198
203static const sam0_common_usb_config_t sam_usbdev_config[] = {
204 {
205 .dm = GPIO_PIN(PA, 24),
206 .dp = GPIO_PIN(PA, 25),
207 .d_mux = GPIO_MUX_G,
208 .device = &USB->DEVICE,
209 .gclk_src = SAM0_GCLK_MAIN,
210 }
211};
213
214#ifdef __cplusplus
215}
216#endif
217
#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.