periph_cpu.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
19 #include "periph_conf.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
28 #if !defined(CPUID_LEN) || defined(DOXYGEN)
29 # define CPUID_LEN (4U)
30 #endif
31 
35 #if !defined(PM_NUM_MODES) || defined(DOXYGEN)
36 # define PM_NUM_MODES (1U)
37 #endif
38 
42 #define PROVIDES_PM_LAYERED_OFF
43 
44 /* GPIO configuration only if the module is available (=Linux) */
45 #if defined(MODULE_PERIPH_GPIO_LINUX) || defined(DOXYGEN)
46 # include <linux/gpio.h>
47 
48 /* MARK: - GPIO Configuration */
56 # define GPIO_PORT_SHIFT (24)
57 
61 # define GPIO_PIN(port, pin) (gpio_t)((port << GPIO_PORT_SHIFT) | pin)
62 
66 # define HAVE_GPIO_MODE_T
70 # if !defined(GPIOHANDLE_REQUEST_PULL_DOWN) || defined(DOXYGEN)
71 # if defined(GPIOHANDLE_REQUEST_BIAS_PULL_DOWN)
72 # define GPIOHANDLE_REQUEST_PULL_DOWN GPIOHANDLE_REQUEST_BIAS_PULL_DOWN
73 # else
74 # define GPIOHANDLE_REQUEST_PULL_DOWN (0xFF)
75 # endif
76 # endif
80 # if !defined(GPIOHANDLE_REQUEST_PULL_UP) || defined(DOXYGEN)
81 # if defined(GPIOHANDLE_REQUEST_BIAS_PULL_UP)
82 # define GPIOHANDLE_REQUEST_PULL_UP GPIOHANDLE_REQUEST_BIAS_PULL_UP
83 # else
84 # define GPIOHANDLE_REQUEST_PULL_UP (0xFF)
85 # endif
86 # endif
87 
96 typedef enum {
97  GPIO_IN = GPIOHANDLE_REQUEST_INPUT,
98  GPIO_IN_PD = GPIOHANDLE_REQUEST_INPUT | GPIOHANDLE_REQUEST_PULL_DOWN,
99  GPIO_IN_PU = GPIOHANDLE_REQUEST_INPUT | GPIOHANDLE_REQUEST_PULL_UP,
100  GPIO_OUT = GPIOHANDLE_REQUEST_OUTPUT,
101  GPIO_OD = GPIOHANDLE_REQUEST_OPEN_DRAIN,
102  GPIO_OD_PU = GPIOHANDLE_REQUEST_OPEN_DRAIN | GPIOHANDLE_REQUEST_PULL_UP
103 } gpio_mode_t;
104 
108 # define HAVE_GPIO_FLANK_T
109 
113 typedef enum {
114  GPIO_FALLING = GPIOEVENT_EVENT_FALLING_EDGE,
115  GPIO_RISING = GPIOEVENT_EVENT_RISING_EDGE,
120 #elif defined(MODULE_PERIPH_GPIO_MOCK)
121 
127 typedef struct {
128  int value;
129  int mode;
130  int flank;
131  void (*cb)(void *arg);
132  void *arg;
133 } gpio_mock_t;
134 
135 # define GPIO_UNDEF 0
136 
137 # if !defined(GPIO_PORT_MAX) || defined(DOXYGEN)
138 # define GPIO_PORT_MAX (16)
139 # endif
140 
141 # if !defined(GPIO_PIN_MAX) || defined(DOXYGEN)
142 # define GPIO_PIN_MAX (32)
143 # endif
144 
148 extern gpio_mock_t gpio_mock[GPIO_PORT_MAX][GPIO_PIN_MAX];
149 
150 # define HAVE_GPIO_T
154 typedef gpio_mock_t* gpio_t;
155 
160 # define GPIO_PIN(port, pin) \
161  (((port >= 0) && (pin >= 0) && (port < GPIO_PORT_MAX) && (pin < GPIO_PIN_MAX)) \
162  ? &gpio_mock[port][pin] \
163  : GPIO_UNDEF)
164 
165 #endif /* MODULE_PERIPH_GPIO_LINUX | DOXYGEN */
166 
170 #define PERIPH_TIMER_PROVIDES_SET
171 
172 /* MARK: - Power management configuration*/
177 #define PROVIDES_PM_OFF
178 #define PROVIDES_PM_SET_LOWEST
188 #define PERIPH_I2C_NEED_READ_REG
189 #define PERIPH_I2C_NEED_READ_REGS
190 #define PERIPH_I2C_NEED_WRITE_REG
191 #define PERIPH_I2C_NEED_WRITE_REGS
192 
193 #if defined(MODULE_PERIPH_I2C_MOCK) || defined(DOXYGEN)
197 typedef struct {
198  void *dummy;
199 } i2c_conf_t;
200 #endif
201 
202 /* Configuration for the wrapper around the Linux SPI API (periph_spidev_linux)
203  *
204  * Needs to go here, otherwise the SPI_NEEDS_ are defined after inclusion of
205  * spi.h.
206  */
207 #if defined(MODULE_PERIPH_SPIDEV_LINUX) || defined(DOXYGEN)
208 /* MARK: - SPI Configuration */
216 # define PERIPH_SPI_NEEDS_TRANSFER_BYTE
220 # define PERIPH_SPI_NEEDS_TRANSFER_REG
224 # define PERIPH_SPI_NEEDS_TRANSFER_REGS
225 
226 # ifndef DOXYGEN
230 # define HAVE_SPI_CLK_T
237 typedef enum {
238  SPI_CLK_100KHZ = (100000U),
239  SPI_CLK_400KHZ = (400000U),
240  SPI_CLK_1MHZ = (1000000U),
241  SPI_CLK_5MHZ = (5000000U),
242  SPI_CLK_10MHZ = (10000000U)
243 } spi_clk_t;
244 # endif /* ndef DOXYGEN */
246 #endif /* MODULE_PERIPH_SPI | DOXYGEN */
247 
251 #if !defined(EEPROM_SIZE) || defined(DOXYGEN)
252 # define EEPROM_SIZE (1024U) /* 1kB */
253 #endif
254 
255 #ifdef MODULE_PERIPH_CAN
256 # include "candev_linux.h"
257 #endif
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
gpio_flank_t
Definition: periph_cpu.h:176
@ GPIO_OUT
select GPIO MASK as output
Definition: periph_cpu.h:161
@ GPIO_IN
select GPIO MASK as input
Definition: periph_cpu.h:160
spi_clk_t
Definition: periph_cpu.h:348
Peripheral MCU configuration for the Zigduino board.
Implementation of simulated CAN controller driver using SocketCAN on Linux.
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:96
#define GPIOHANDLE_REQUEST_PULL_UP
Pull-up.
Definition: periph_cpu.h:84
#define GPIOHANDLE_REQUEST_PULL_DOWN
Pull-down.
Definition: periph_cpu.h:74
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:91
@ GPIO_FALLING
emit interrupt on falling flank
Definition: periph_cpu.h:114
@ GPIO_RISING
emit interrupt on rising flank
Definition: periph_cpu.h:115
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:116
@ GPIO_OD
configure as output in open-drain mode without pull resistor
Definition: gpio.h:123
@ GPIO_IN_PU
configure as input with pull-up resistor
Definition: gpio.h:121
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
Definition: gpio.h:125
@ GPIO_IN_PD
configure as input with pull-down resistor
Definition: gpio.h:120
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: periph_cpu.h:353
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: periph_cpu.h:352
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: periph_cpu.h:350
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: periph_cpu.h:351
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: periph_cpu.h:349
I2C configuration structure.
Definition: periph_cpu.h:295
void * dummy
dummy attribute
Definition: periph_cpu.h:198