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 
76 #define TIMER_CHANNEL_NUMOF (1)
77 
81 #define RTT_MAX_VALUE (0xffffffff)
82 
91 #define GPIO_MODE(io, pu, od) (io | (pu << 1) | (od << 2))
92 
100 #define ADC_NUMOF (16U)
101 
113 #define DAC_NUMOF (2U)
114 
115 #ifndef DOXYGEN
116 
120 #define HAVE_GPIO_MODE_T
121 typedef enum {
122  GPIO_IN = GPIO_MODE(0, 0, 0),
123  GPIO_IN_PD = 0xf,
124  GPIO_IN_PU = GPIO_MODE(0, 1, 0),
125  GPIO_OUT = GPIO_MODE(1, 0, 0),
126  GPIO_OD = GPIO_MODE(1, 0, 1),
127  GPIO_OD_PU = GPIO_MODE(1, 1, 1),
128 } gpio_mode_t;
135 #define HAVE_GPIO_FLANK_T
136 typedef enum {
137  GPIO_RISING = 1,
138  GPIO_FALLING = 2,
139  GPIO_BOTH = 3
140 } gpio_flank_t;
142 #endif /* ndef DOXYGEN */
143 
147 enum {
148  PA = 0,
149  PB = 1,
150  PC = 2,
151  PD = 3,
152 };
153 
157 typedef enum {
160 } gpio_mux_t;
161 
162 #ifndef DOXYGEN
163 
167 #define HAVE_SPI_MODE_T
168 typedef enum {
169  SPI_MODE_0 = (SPI_CSR_NCPHA),
170  SPI_MODE_1 = (0),
171  SPI_MODE_2 = (SPI_CSR_CPOL | SPI_CSR_NCPHA),
172  SPI_MODE_3 = (SPI_CSR_CPOL)
173 } spi_mode_t;
180 #define HAVE_SPI_CLK_T
181 typedef enum {
182  SPI_CLK_100KHZ = (100000),
183  SPI_CLK_400KHZ = (400000),
184  SPI_CLK_1MHZ = (1000000),
185  SPI_CLK_5MHZ = (5000000),
186  SPI_CLK_10MHZ = (10000000)
187 } spi_clk_t;
189 #endif /* ndef DOXYGEN */
190 
191 #ifndef DOXYGEN
192 
196 #define HAVE_ADC_RES_T
197 typedef enum {
198  ADC_RES_6BIT = 0x1,
199  ADC_RES_8BIT = 0x2,
200  ADC_RES_10BIT = ADC_MR_LOWRES_BITS_10,
201  ADC_RES_12BIT = ADC_MR_LOWRES_BITS_12,
202  ADC_RES_14BIT = 0x4,
203  ADC_RES_16BIT = 0x8
204 } adc_res_t;
206 #endif /* ndef DOXYGEN */
207 
211 typedef struct {
212  Tc *dev;
213  uint8_t id_ch0;
214 } timer_conf_t;
215 
219 typedef struct {
220  Uart *dev;
221  gpio_t rx_pin;
222  gpio_t tx_pin;
223  gpio_mux_t mux;
224  uint8_t pmc_id;
225  uint8_t irqn;
226 } uart_conf_t;
227 
231 typedef struct {
232  gpio_t pin;
233  uint8_t hwchan;
235 
239 typedef struct {
240  Spi *dev;
241  uint8_t id;
242  gpio_t clk;
243  gpio_t mosi;
244  gpio_t miso;
246 } spi_conf_t;
247 
254 void gpio_init_mux(gpio_t pin, gpio_mux_t mux);
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /* PERIPH_CPU_H */
261 
spi_conf_t::id
uint8_t id
corresponding ID of that module
Definition: periph_cpu.h:241
SPI_CLK_400KHZ
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: periph_cpu.h:653
GPIO_MODE
#define GPIO_MODE(io, pu, od)
Generate GPIO mode bitfields.
Definition: periph_cpu.h:91
SPI_MODE_3
@ SPI_MODE_3
CPOL=1, CPHA=1.
Definition: spi.h:161
spi_conf_t::mux
gpio_mux_t mux
pin MUX setting
Definition: periph_cpu.h:245
pwm_chan_conf_t
PWM channel configuration.
Definition: periph_cpu.h:281
SPI_CLK_100KHZ
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: periph_cpu.h:652
ADC_RES_6BIT
@ ADC_RES_6BIT
ADC resolution: 6 bit.
Definition: adc.h:94
PC
@ PC
port C
Definition: periph_cpu.h:150
GPIO_IN_PD
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition: gpio.h:120
GPIO_MUX_A
@ GPIO_MUX_A
alternate function A
Definition: periph_cpu.h:158
SPI_MODE_0
@ SPI_MODE_0
CPOL=0, CPHA=0.
Definition: spi.h:158
GPIO_OD
@ GPIO_OD
configure as output in open-drain mode without pull resistor
Definition: gpio.h:123
PD
@ PD
port D
Definition: periph_cpu.h:151
ADC_RES_14BIT
@ ADC_RES_14BIT
ADC resolution: 14 bit.
Definition: adc.h:98
adc_res_t
adc_res_t
Possible ADC resolution settings.
Definition: adc.h:93
gpio_mux_t
gpio_mux_t
GPIO mux configuration.
Definition: periph_cpu.h:157
GPIO_OUT
@ GPIO_OUT
configure as output in push-pull mode
Definition: gpio.h:122
ADC_RES_16BIT
@ ADC_RES_16BIT
ADC resolution: 16 bit.
Definition: adc.h:99
spi_mode_t
spi_mode_t
Available SPI modes, defining the configuration of clock polarity and clock phase.
Definition: spi.h:157
ADC_RES_8BIT
@ ADC_RES_8BIT
ADC resolution: 8 bit.
Definition: adc.h:95
GPIO_FALLING
@ GPIO_FALLING
emit interrupt on falling flank
Definition: periph_cpu.h:81
GPIO_IN_PU
@ GPIO_IN_PU
configure as input with pull-up resistor
Definition: gpio.h:121
GPIO_RISING
@ GPIO_RISING
emit interrupt on rising flank
Definition: periph_cpu.h:82
PB
@ PB
port B
Definition: periph_cpu.h:149
PA
@ PA
port A
Definition: periph_cpu.h:148
SPI_CLK_10MHZ
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: periph_cpu.h:656
spi_clk_t
uint32_t spi_clk_t
SPI clock type.
Definition: periph_cpu.h:662
GPIO_IN
@ GPIO_IN
configure as input without pull resistor
Definition: gpio.h:119
spi_conf_t::dev
Spi * dev
SPI module to use.
Definition: periph_cpu.h:240
gpio_init_mux
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_conf_t
UART device configuration.
Definition: periph_cpu.h:166
gpio_mux_t
gpio_mux_t
Available MUX values for configuring a pin's alternate function.
Definition: periph_cpu_common.h:135
SPI_CLK_5MHZ
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: periph_cpu.h:655
gpio_flank_t
gpio_flank_t
Definition: periph_cpu.h:80
GPIO_OD_PU
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:125
GPIO_BOTH
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:83
timer_conf_t
Timer configuration.
Definition: periph_cpu.h:288
spi_conf_t::clk
gpio_t clk
pin mapped to the CLK line
Definition: periph_cpu.h:242
timer_conf_t::id_ch0
uint8_t id_ch0
ID of the timer's first channel.
Definition: periph_cpu.h:213
GPIO_MUX_B
@ GPIO_MUX_B
alternate function B
Definition: periph_cpu.h:159
gpio_mode_t
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:70
ADC_RES_10BIT
@ ADC_RES_10BIT
ADC resolution: 10 bit.
Definition: adc.h:96
ADC_RES_12BIT
@ ADC_RES_12BIT
ADC resolution: 12 bit.
Definition: adc.h:97
uart_conf_t::pmc_id
uint8_t pmc_id
bit in the PMC register of the device
Definition: periph_cpu.h:224
timer_conf_t::dev
Tc * dev
timer device
Definition: periph_cpu.h:212
gpio_t
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:91
pwm_chan_conf_t::hwchan
uint8_t hwchan
the HW channel used for a logical channel
Definition: periph_cpu.h:233
SPI_CLK_1MHZ
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: periph_cpu.h:654
uart_conf_t::dev
Uart * dev
U(S)ART device used.
Definition: periph_cpu.h:220
spi_conf_t
SPI configuration structure type.
Definition: periph_cpu.h:273
SPI_MODE_1
@ SPI_MODE_1
CPOL=0, CPHA=1.
Definition: spi.h:159
SPI_MODE_2
@ SPI_MODE_2
CPOL=1, CPHA=0.
Definition: spi.h:160