periph_cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universit├Ąt Berlin
3  * 2015 Hamburg University of Applied Sciences
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 
22 #ifndef PERIPH_CPU_H
23 #define PERIPH_CPU_H
24 
25 #include "cpu.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #define HAVE_GPIO_T
35 typedef uint32_t gpio_t;
41 #define GPIO_UNDEF (0xffffffff)
42 
46 #define GPIO_PIN(x, y) (((uint32_t)PIOA + (x << 9)) | y)
47 
52 #define PERIPH_SPI_NEEDS_INIT_CS
53 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
54 #define PERIPH_SPI_NEEDS_TRANSFER_REG
55 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
56 
61 #define CPUID_LEN (16U)
62 
66 #define TIMER_MAX_VAL (0xffffffff)
67 
71 #define TIMER_CHANNELS (3)
72 
81 #define GPIO_MODE(io, pu, od) (io | (pu << 1) | (od << 2))
82 
90 #define ADC_NUMOF (16U)
91 
103 #define DAC_NUMOF (2U)
104 
105 #ifndef DOXYGEN
106 
110 #define HAVE_GPIO_MODE_T
111 typedef enum {
112  GPIO_IN = GPIO_MODE(0, 0, 0),
113  GPIO_IN_PD = 0xf,
114  GPIO_IN_PU = GPIO_MODE(0, 1, 0),
115  GPIO_OUT = GPIO_MODE(1, 0, 0),
116  GPIO_OD = GPIO_MODE(1, 0, 1),
117  GPIO_OD_PU = GPIO_MODE(1, 1, 1),
118 } gpio_mode_t;
125 #define HAVE_GPIO_FLANK_T
126 typedef enum {
127  GPIO_RISING = 1,
128  GPIO_FALLING = 2,
129  GPIO_BOTH = 3
130 } gpio_flank_t;
132 #endif /* ndef DOXYGEN */
133 
137 enum {
138  PA = 0,
139  PB = 1,
140  PC = 2,
141  PD = 3,
142 };
143 
147 typedef enum {
150 } gpio_mux_t;
151 
152 #ifndef DOXYGEN
153 
157 #define HAVE_SPI_MODE_T
158 typedef enum {
159  SPI_MODE_0 = (SPI_CSR_NCPHA),
160  SPI_MODE_1 = (0),
161  SPI_MODE_2 = (SPI_CSR_CPOL | SPI_CSR_NCPHA),
162  SPI_MODE_3 = (SPI_CSR_CPOL)
163 } spi_mode_t;
170 #define HAVE_SPI_CLK_T
171 typedef enum {
172  SPI_CLK_100KHZ = (100000),
173  SPI_CLK_400KHZ = (400000),
174  SPI_CLK_1MHZ = (1000000),
175  SPI_CLK_5MHZ = (5000000),
176  SPI_CLK_10MHZ = (10000000)
177 } spi_clk_t;
179 #endif /* ndef DOXYGEN */
180 
181 #ifndef DOXYGEN
182 
186 #define HAVE_ADC_RES_T
187 typedef enum {
188  ADC_RES_6BIT = 0x1,
189  ADC_RES_8BIT = 0x2,
190  ADC_RES_10BIT = ADC_MR_LOWRES_BITS_10,
191  ADC_RES_12BIT = ADC_MR_LOWRES_BITS_12,
192  ADC_RES_14BIT = 0x4,
193  ADC_RES_16BIT = 0x8
194 } adc_res_t;
196 #endif /* ndef DOXYGEN */
197 
201 typedef struct {
202  Tc *dev;
203  uint8_t id_ch0;
204 } timer_conf_t;
205 
209 typedef struct {
210  Uart *dev;
211  gpio_t rx_pin;
212  gpio_t tx_pin;
213  gpio_mux_t mux;
214  uint8_t pmc_id;
215  uint8_t irqn;
216 } uart_conf_t;
217 
221 typedef struct {
222  gpio_t pin;
223  uint8_t hwchan;
225 
229 typedef struct {
230  Spi *dev;
231  uint8_t id;
232  gpio_t clk;
233  gpio_t mosi;
234  gpio_t miso;
236 } spi_conf_t;
237 
244 void gpio_init_mux(gpio_t pin, gpio_mux_t mux);
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif /* PERIPH_CPU_H */
251 
alternate function B
Definition: periph_cpu.h:149
CPOL=0, CPHA=1.
Definition: spi.h:159
configure as output in push-pull mode
Definition: gpio.h:117
Uart * dev
U(S)ART device used.
Definition: periph_cpu.h:210
emit interrupt on rising flank
Definition: gpio.h:131
uint8_t irqn
interrupt number of the device
Definition: periph_cpu.h:215
ADC resolution: 12 bit.
Definition: adc.h:96
PWM channel configuration.
Definition: periph_cpu.h:274
gpio_mux_t
GPIO mux configuration.
Definition: periph_cpu.h:147
Tc * dev
timer device
Definition: periph_cpu.h:202
adc_res_t
Possible ADC resolution settings.
Definition: adc.h:92
gpio_mux_t mux
pin MUX setting
Definition: periph_cpu.h:235
port A
Definition: periph_cpu.h:87
port B
Definition: periph_cpu.h:88
CPOL=0, CPHA=0.
Definition: spi.h:158
drive the SPI bus with 100KHz
Definition: spi.h:174
port C
Definition: periph_cpu.h:89
uint8_t id_ch0
ID of the timer&#39;s first channel.
Definition: periph_cpu.h:203
drive the SPI bus with 400KHz
Definition: spi.h:175
uint8_t pmc_id
bit in the PMC register of the device
Definition: periph_cpu.h:214
uint8_t id
corresponding ID of that module
Definition: periph_cpu.h:231
emit interrupt on both flanks
Definition: gpio.h:132
gpio_flank_t
Definition of possible active flanks for external interrupt mode.
Definition: gpio.h:129
spi_mode_t
Available SPI modes, defining the configuration of clock polarity and clock phase.
Definition: spi.h:157
ADC resolution: 14 bit.
Definition: adc.h:97
ADC resolution: 10 bit.
Definition: adc.h:95
CPOL=1, CPHA=1.
Definition: spi.h:161
port D
Definition: periph_cpu.h:90
spi_clk_t
SPI clock speed values.
Definition: periph_cpu.h:83
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:86
Spi * dev
SPI module to use.
Definition: periph_cpu.h:230
ADC resolution: 16 bit.
Definition: adc.h:98
gpio_mux_t
Available MUX values for configuring a pin&#39;s alternate function.
drive the SPI bus with 5MHz
Definition: spi.h:177
ADC resolution: 8 bit.
Definition: adc.h:94
alternate function A
Definition: periph_cpu.h:148
uint8_t hwchan
the HW channel used for a logical channel
Definition: periph_cpu.h:223
ADC resolution: 6 bit.
Definition: adc.h:93
drive the SPI bus with 10MHz
Definition: spi.h:178
emit interrupt on falling flank
Definition: gpio.h:130
drive the SPI bus with 1MHz
Definition: spi.h:176
configure as input with pull-up resistor
Definition: gpio.h:116
void gpio_init_mux(gpio_t pin, uint8_t over, uint8_t sel, uint8_t func)
Configure an alternate function for the given pin.
UART device configuration.
Definition: periph_cpu.h:166
gpio_mode_t
Available pin modes.
Definition: gpio.h:113
configure as input without pull resistor
Definition: gpio.h:114
gpio_t clk
pin mapped to the CLK line
Definition: periph_cpu.h:232
configure as output in open-drain mode without pull resistor
Definition: gpio.h:118
CPOL=1, CPHA=0.
Definition: spi.h:160
SPI configuration structure type.
Definition: periph_cpu.h:271
configure as input with pull-down resistor
Definition: gpio.h:115
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:120
#define GPIO_MODE(io, pu, od)
Generate GPIO mode bitfields.
Definition: periph_cpu.h:81
Timer configuration.
Definition: periph_cpu.h:286