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 
25 #ifndef PERIPH_CONF_COMMON_H
26 #define PERIPH_CONF_COMMON_H
27 
28 #include "periph_cpu.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 
66 #define CLOCK_USE_PLL (1)
67 
68 #if CLOCK_USE_PLL
69 /* edit these values to adjust the PLL output frequency */
70 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
71 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
72 /* generate the actual used core clock frequency */
73 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
74 #else
75 /* edit this value to your needs */
76 #define CLOCK_DIV (1U)
77 /* generate the actual core clock frequency */
78 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
79 #endif
80 
86 static const tc32_conf_t timer_config[] = {
87  { /* Timer 0 - System Clock */
88  .dev = TC3,
89  .irq = TC3_IRQn,
90  .pm_mask = PM_APBCMASK_TC3,
91  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
92 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
93  .gclk_src = SAM0_GCLK_1MHZ,
94 #else
95  .gclk_src = SAM0_GCLK_MAIN,
96 #endif
97  .flags = TC_CTRLA_MODE_COUNT16,
98  },
99  { /* Timer 1 */
100  .dev = TC4,
101  .irq = TC4_IRQn,
102  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
103  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
104 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
105  .gclk_src = SAM0_GCLK_1MHZ,
106 #else
107  .gclk_src = SAM0_GCLK_MAIN,
108 #endif
109  .flags = TC_CTRLA_MODE_COUNT32,
110  }
111 };
112 
113 #define TIMER_0_MAX_VALUE 0xffff
114 
115 /* interrupt function name mapping */
116 #define TIMER_0_ISR isr_tc3
117 #define TIMER_1_ISR isr_tc4
118 
119 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
120 
126 #define PWM_0_EN 1
127 
128 #if PWM_0_EN
129 /* PWM0 channels */
130 static const pwm_conf_chan_t pwm_chan0_config[] = {
131  /* GPIO pin, MUX value, TCC channel */
132  { GPIO_PIN(PA, 10), GPIO_MUX_F, 2 }, /* ~2 */
133  { GPIO_PIN(PA, 11), GPIO_MUX_F, 3 }, /* ~3 */
134 };
135 #endif
136 
137 /* PWM device configuration */
138 static const pwm_conf_t pwm_config[] = {
139 #if PWM_0_EN
140  {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
141 #endif
142 };
143 
144 /* number of devices that are actually defined */
145 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
146 
153 /* ADC Default values */
154 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
155 
156 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
157 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
158 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
159 
160 static const adc_conf_chan_t adc_channels[] = {
161  /* port, pin, muxpos */
162  {GPIO_PIN(PA, 2), ADC_INPUTCTRL_MUXPOS_PIN0}, /* A0 */
163  {GPIO_PIN(PB, 2), ADC_INPUTCTRL_MUXPOS_PIN10}, /* A1 */
164  {GPIO_PIN(PB, 3), ADC_INPUTCTRL_MUXPOS_PIN11}, /* A2 */
165  {GPIO_PIN(PA, 4), ADC_INPUTCTRL_MUXPOS_PIN4}, /* A3 */
166  {GPIO_PIN(PA, 5), ADC_INPUTCTRL_MUXPOS_PIN5}, /* A4 */
167  {GPIO_PIN(PA, 6), ADC_INPUTCTRL_MUXPOS_PIN6}, /* A5 */
168  {GPIO_PIN(PA, 7), ADC_INPUTCTRL_MUXPOS_PIN7}, /* A6 */
169 };
170 
171 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
172 
178 static const i2c_conf_t i2c_config[] = {
179  {
180  .dev = &(SERCOM0->I2CM),
181  .speed = I2C_SPEED_NORMAL,
182  .scl_pin = GPIO_PIN(PA, 9),
183  .sda_pin = GPIO_PIN(PA, 8),
184  .mux = GPIO_MUX_C,
185  .gclk_src = SAM0_GCLK_MAIN,
186  .flags = I2C_FLAG_NONE
187  }
188 };
189 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
190 
196 #ifndef RTT_FREQUENCY
197 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
198 #endif
199 
205 static const sam0_common_usb_config_t sam_usbdev_config[] = {
206  {
207  .dm = GPIO_PIN(PA, 24),
208  .dp = GPIO_PIN(PA, 25),
209  .d_mux = GPIO_MUX_G,
210  .device = &USB->DEVICE,
211  .gclk_src = SAM0_GCLK_MAIN,
212  }
213 };
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif /* PERIPH_CONF_COMMON_H */
221 
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
I2C_SPEED_NORMAL
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: i2c.h:177
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
sam0_common_usb_config_t
USB peripheral parameters.
Definition: periph_cpu_common.h:774
sam0_common_usb_config_t::dm
gpio_t dm
D- line gpio
Definition: periph_cpu_common.h:775
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
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
GPIO_MUX_C
@ GPIO_MUX_C
select peripheral function C
Definition: periph_cpu_common.h:138
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
i2c_config
static const i2c_conf_t i2c_config[]
Static array with configuration for declared I2C devices.
Definition: periph_conf_common.h:106
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
GPIO_MUX_G
@ GPIO_MUX_G
select peripheral function G
Definition: periph_cpu_common.h:142
TCC_CONFIG
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
Definition: periph_cpu_common.h:297
i2c_conf_t::dev
I2C_TypeDef * dev
USART device used.
Definition: periph_cpu.h:247