periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Kees Bakker, SODAQ
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef PERIPH_CONF_H
20 #define PERIPH_CONF_H
21 
22 #include <stdint.h>
23 
24 #include "cpu.h"
25 #include "periph_cpu.h"
26 #include "cfg_clock_default.h"
27 #include "cfg_rtc_default.h"
28 #include "cfg_rtt_default.h"
29 #include "cfg_spi_default.h"
30 #include "cfg_timer_default.h"
31 #include "cfg_usbdev_default.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
42 static const uart_conf_t uart_config[] = {
43  {
44  .dev = &SERCOM0->USART,
45  .rx_pin = GPIO_PIN(PA,9),
46  .tx_pin = GPIO_PIN(PA,10),
47 #ifdef MODULE_PERIPH_UART_HW_FC
48  .rts_pin = GPIO_UNDEF,
49  .cts_pin = GPIO_UNDEF,
50 #endif
51  .mux = GPIO_MUX_C,
52  .rx_pad = UART_PAD_RX_1,
53  .tx_pad = UART_PAD_TX_2,
54  .flags = UART_FLAG_NONE,
55  .gclk_src = SAM0_GCLK_MAIN,
56  },
57  {
58  .dev = &SERCOM5->USART,
59  .rx_pin = GPIO_PIN(PB,31),
60  .tx_pin = GPIO_PIN(PB,30),
61 #ifdef MODULE_PERIPH_UART_HW_FC
62  .rts_pin = GPIO_UNDEF,
63  .cts_pin = GPIO_UNDEF,
64 #endif
65  .mux = GPIO_MUX_D,
66  .rx_pad = UART_PAD_RX_1,
67  .tx_pad = UART_PAD_TX_0_RTS_2_CTS_3,
68  .flags = UART_FLAG_NONE,
69  .gclk_src = SAM0_GCLK_MAIN,
70  },
71  {
72  .dev = &SERCOM4->USART,
73  .rx_pin = GPIO_PIN(PB,13),
74  .tx_pin = GPIO_PIN(PB,14),
75 #ifdef MODULE_PERIPH_UART_HW_FC
76  .rts_pin = GPIO_UNDEF,
77  .cts_pin = GPIO_UNDEF,
78 #endif
79  .mux = GPIO_MUX_C,
80  .rx_pad = UART_PAD_RX_1,
81  .tx_pad = UART_PAD_TX_2,
82  .flags = UART_FLAG_NONE,
83  .gclk_src = SAM0_GCLK_MAIN,
84  },
85  {
86  .dev = &SERCOM1->USART,
87  .rx_pin = GPIO_PIN(PA,17),
88  .tx_pin = GPIO_PIN(PA,18),
89 #ifdef MODULE_PERIPH_UART_HW_FC
90  .rts_pin = GPIO_UNDEF,
91  .cts_pin = GPIO_UNDEF,
92 #endif
93  .mux = GPIO_MUX_C,
94  .rx_pad = UART_PAD_RX_1,
95  .tx_pad = UART_PAD_TX_2,
96  .flags = UART_FLAG_NONE,
97  .gclk_src = SAM0_GCLK_MAIN,
98  },
99 };
100 
101 /* interrupt function name mapping */
102 #define UART_0_ISR isr_sercom0
103 #define UART_1_ISR isr_sercom5
104 #define UART_2_ISR isr_sercom4
105 #define UART_3_ISR isr_sercom1
106 
107 #define UART_NUMOF ARRAY_SIZE(uart_config)
108 
115 /* ADC Default values */
116 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
117 
118 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
119 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_DIV2
120 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC1
121 
122 static const adc_conf_chan_t adc_channels[] = {
123  /* port, muxpos/pin */
124  /* Use the Arduino pin number order */
125  {GPIO_PIN(PA, 2), ADC_INPUTCTRL_MUXPOS_PIN0}, /* ADC/AIN[0], A0 */
126  {GPIO_PIN(PA, 6), ADC_INPUTCTRL_MUXPOS_PIN6}, /* ADC/AIN[6], A1 */
127  {GPIO_PIN(PA, 5), ADC_INPUTCTRL_MUXPOS_PIN5}, /* ADC/AIN[5], A2 */
128  {GPIO_PIN(PA, 4), ADC_INPUTCTRL_MUXPOS_PIN4}, /* ADC/AIN[4], A3 */
129  {GPIO_PIN(PB, 9), ADC_INPUTCTRL_MUXPOS_PIN3}, /* ADC/AIN[3], A4 */
130  {GPIO_PIN(PB, 8), ADC_INPUTCTRL_MUXPOS_PIN2}, /* ADC/AIN[2], A5 */
131  {GPIO_PIN(PB, 7), ADC_INPUTCTRL_MUXPOS_PIN15}, /* ADC/AIN[15], A6 */
132  {GPIO_PIN(PB, 6), ADC_INPUTCTRL_MUXPOS_PIN14}, /* ADC/AIN[14], A7 */
133  {GPIO_PIN(PB, 5), ADC_INPUTCTRL_MUXPOS_PIN13}, /* ADC/AIN[13], A8 */
134  {GPIO_PIN(PB, 4), ADC_INPUTCTRL_MUXPOS_PIN12}, /* ADC/AIN[12], A9 */
135  {GPIO_PIN(PA, 7), ADC_INPUTCTRL_MUXPOS_PIN7}, /* ADC/AIN[7], A10 */
136  {GPIO_PIN(PB, 3), ADC_INPUTCTRL_MUXPOS_PIN11}, /* ADC/AIN[11], A11 */
137  {GPIO_PIN(PB, 2), ADC_INPUTCTRL_MUXPOS_PIN10}, /* ADC/AIN[10], A12 */
138  {GPIO_PIN(PB, 1), ADC_INPUTCTRL_MUXPOS_PIN9}, /* ADC/AIN[9], A13 (pin also used for DTR) */
139 
140  {GPIO_PIN(PB, 0), ADC_INPUTCTRL_MUXPOS_PIN8}, /* ADC/AIN[8], BATVOLT */
141 };
142 
143 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
144 
150 #define PWM_0_EN 1
151 #define PWM_1_EN 1
152 
153 #if PWM_0_EN
154 /* PWM0 channels */
155 static const pwm_conf_chan_t pwm_chan0_config[] = {
156  /* GPIO pin, MUX value, TCC channel */
157  { GPIO_PIN(PA, 6), GPIO_MUX_E, 0 },
158  { GPIO_PIN(PA, 7), GPIO_MUX_E, 1 },
159 };
160 #endif
161 #if PWM_1_EN
162 /* PWM1 channels */
163 static const pwm_conf_chan_t pwm_chan1_config[] = {
164  /* GPIO pin, MUX value, TCC channel */
165  { GPIO_PIN(PA, 16), GPIO_MUX_F, 0 },
166  { GPIO_PIN(PA, 18), GPIO_MUX_F, 2 },
167  { GPIO_PIN(PA, 19), GPIO_MUX_F, 3 }
168 };
169 #endif
170 
171 /* PWM device configuration */
172 static const pwm_conf_t pwm_config[] = {
173 #if PWM_0_EN
174  {TCC_CONFIG(TCC1), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
175 #endif
176 #if PWM_1_EN
177  {TCC_CONFIG(TCC0), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
178 #endif
179 };
180 
181 /* number of devices that are actually defined */
182 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
183 
189 static const i2c_conf_t i2c_config[] = {
190  {
191  .dev = &(SERCOM2->I2CM),
192  .speed = I2C_SPEED_NORMAL,
193  .scl_pin = GPIO_PIN(PA, 13),
194  .sda_pin = GPIO_PIN(PA, 12),
195  .mux = GPIO_MUX_C,
196  .gclk_src = SAM0_GCLK_MAIN,
197  .flags = I2C_FLAG_NONE
198  }
199 };
200 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
201 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif /* PERIPH_CONF_H */
208 
GPIO_MUX_F
@ GPIO_MUX_F
select peripheral function F
Definition: periph_cpu_common.h:141
UART_PAD_TX_0_RTS_2_CTS_3
@ UART_PAD_TX_0_RTS_2_CTS_3
TX is pad 0, on top RTS on pad 2 and CTS on pad 3.
Definition: periph_cpu_common.h:163
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_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
UART_FLAG_NONE
@ UART_FLAG_NONE
No flags set.
Definition: periph_cpu_common.h:171
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
UART_PAD_RX_1
@ UART_PAD_RX_1
select pad 1
Definition: periph_cpu_common.h:152
cfg_rtc_default.h
Default RTC configuration for SODAQ boards.
pwm_conf_chan_t
PWM channel configuration data structure.
Definition: periph_cpu_common.h:307
UART_PAD_TX_2
@ UART_PAD_TX_2
select pad 2
Definition: periph_cpu_common.h:162
GPIO_UNDEF
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
Definition: periph_cpu_common.h:52
uart_conf_t
UART device configuration.
Definition: periph_cpu.h:166
adc_channels
static const gpio_t adc_channels[]
Static array with declared ADC channels.
Definition: periph_conf_common.h:53
GPIO_MUX_C
@ GPIO_MUX_C
select peripheral function C
Definition: periph_cpu_common.h:138
uart_conf_t::dev
cc2538_uart_t * dev
pointer to the used UART device
Definition: periph_cpu.h:167
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
GPIO_MUX_D
@ GPIO_MUX_D
select peripheral function D
Definition: periph_cpu_common.h:139
cfg_usbdev_default.h
Default usbdev configuration for SODAQ boards.
PA
@ PA
port A
Definition: periph_cpu_common.h:88
i2c_conf_t
I2C configuration options.
Definition: periph_cpu.h:128
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