periph_cpu.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <stdint.h>
23 #include "cpu.h"
24 
29 #define __IO volatile
36 #define PM_NUM_MODES (4)
42 typedef struct {
44  __IO uint32_t DIR;
46  uint32_t _reserved[3];
50  __IO uint32_t MASK;
54  __IO uint32_t PIN;
56  __IO uint32_t SET;
58  __IO uint32_t CLR;
59 } FIO_PORT_t;
60 
64 #define FIO_PORTS ((FIO_PORT_t*)FIO_BASE_ADDR)
65 
69 #define PINSEL ((__IO uint32_t *)(PINSEL_BASE_ADDR))
70 
74 #define PINMODE ((__IO uint32_t *)(PINSEL_BASE_ADDR + 0x40))
75 
82 int gpio_init_mux(unsigned pin, unsigned mux);
83 
87 #define GPIO_PIN(port, pin) (port<<5 | pin)
88 
89 #ifndef DOXYGEN
90 #define HAVE_GPIO_FLANK_T
91 typedef enum {
92  GPIO_FALLING = 1,
93  GPIO_RISING = 2,
94  GPIO_BOTH = 3
95 } gpio_flank_t;
96 #endif /* ifndef DOXYGEN */
97 
101 typedef struct {
102  lpc23xx_uart_t *dev;
103  uint8_t irq_prio_rx;
104  uint8_t pinsel_rx;
105  uint8_t pinsel_tx;
106  uint32_t pinsel_msk_rx;
107  uint32_t pinsel_msk_tx;
108 } uart_conf_t;
109 
113 typedef struct {
114  lpc23xx_spi_t *dev;
115  uint8_t pinsel_mosi;
116  uint8_t pinsel_miso;
117  uint8_t pinsel_clk;
118  uint32_t pinsel_msk_mosi;
119  uint32_t pinsel_msk_miso;
120  uint32_t pinsel_msk_clk;
121 } spi_conf_t;
122 
126 #define TIMER_CHANNEL_NUMOF (4U)
127 
131 #define PERIPH_TIMER_PROVIDES_SET
132 
137 #define PERIPH_SPI_NEEDS_INIT_CS
138 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
139 #define PERIPH_SPI_NEEDS_TRANSFER_REG
140 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
143 #ifndef DOXYGEN
148 #define HAVE_SPI_CLK_T
149 typedef enum {
150  SPI_CLK_100KHZ = 100,
151  SPI_CLK_400KHZ = 400,
152  SPI_CLK_1MHZ = 1000,
153  SPI_CLK_5MHZ = 5000,
154  SPI_CLK_10MHZ = 10000
155 } spi_clk_t;
157 #endif /* ndef DOXYGEN */
158 
169 #define DAC_NUMOF (1U)
170 
171 #ifndef DOXYGEN
176 #define HAVE_ADC_RES_T
177 typedef enum {
178  ADC_RES_16BIT = 0xff,
179  ADC_RES_14BIT = 0xfe,
180  ADC_RES_12BIT = 0xfd,
181  ADC_RES_10BIT = 0b000,
182  ADC_RES_9BIT = 0b001,
183  ADC_RES_8BIT = 0b010,
184  ADC_RES_7BIT = 0b011,
185  ADC_RES_6BIT = 0b100,
186  ADC_RES_5BIT = 0b101,
187  ADC_RES_4BIT = 0b110,
188  ADC_RES_3BIT = 0b111,
189 } adc_res_t;
191 #endif /* ndef DOXYGEN */
192 
196 typedef struct {
197  uint8_t chan;
198  uint8_t pinsel;
199  uint32_t pinsel_msk;
200 } adc_conf_t;
201 
202 #ifndef DOXYGEN
207 #define HAVE_I2C_SPEED_T
208 typedef enum {
209  I2C_SPEED_LOW = 10000,
210  I2C_SPEED_NORMAL = 100000,
211  I2C_SPEED_FAST = 400000,
212 } i2c_speed_t;
214 #endif /* ndef DOXYGEN */
215 
219 typedef struct {
220  lpc23xx_i2c_t *dev;
221  i2c_speed_t speed;
222  uint8_t irq_prio;
223  uint8_t pinsel_sda;
224  uint8_t pinsel_scl;
225  uint32_t pinsel_msk_sda;
226  uint32_t pinsel_msk_scl;
227 } i2c_conf_t;
228 
233 #define PERIPH_I2C_NEED_READ_REG
234 #define PERIPH_I2C_NEED_WRITE_REG
242 #if defined(MODULE_PERIPH_RTC) && !defined(RTC_NORMALIZE_COMPAT)
243 #define RTC_NORMALIZE_COMPAT (1)
244 #endif
247 #ifdef __cplusplus
248 }
249 #endif
250 
gpio_flank_t
Definition: periph_cpu.h:176
i2c_speed_t
Definition: periph_cpu.h:272
spi_clk_t
Definition: periph_cpu.h:348
void gpio_init_mux(gpio_t pin, uint8_t over, uint8_t sel, uint8_t func)
Configure an alternate function for the given pin.
gpio_t adc_conf_t
ADC configuration wrapper.
Definition: periph_cpu.h:333
adc_res_t
Possible ADC resolution settings.
Definition: adc.h:92
@ ADC_RES_16BIT
ADC resolution: 16 bit.
Definition: adc.h:98
@ ADC_RES_8BIT
ADC resolution: 8 bit.
Definition: adc.h:94
@ ADC_RES_14BIT
ADC resolution: 14 bit.
Definition: adc.h:97
@ ADC_RES_6BIT
ADC resolution: 6 bit.
Definition: adc.h:93
@ ADC_RES_10BIT
ADC resolution: 10 bit.
Definition: adc.h:95
@ ADC_RES_12BIT
ADC resolution: 12 bit.
Definition: adc.h:96
@ GPIO_FALLING
emit interrupt on falling flank
Definition: periph_cpu.h:109
@ GPIO_RISING
emit interrupt on rising flank
Definition: periph_cpu.h:110
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:111
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:274
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition: periph_cpu.h:273
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: periph_cpu.h:275
@ 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
#define __IO
LPC2387 MCU defines.
Definition: periph_cpu.h:29
Native CPU header.
Fast GPIO register definition struct.
Definition: periph_cpu.h:42
__IO uint32_t MASK
Set bits to ignore corresponding bits when accessing PIN, SET or CLR register of this port.
Definition: periph_cpu.h:50
__IO uint32_t SET
Output pins are set to high by setting the corresponding bit.
Definition: periph_cpu.h:56
__IO uint32_t DIR
Direction: Output if corresponding bit is set, otherwise input.
Definition: periph_cpu.h:44
__IO uint32_t PIN
The current state of each pin of this port is accessible here (regardless of direction): If bit is se...
Definition: periph_cpu.h:54
__IO uint32_t CLR
Output pins are set to low by setting the corresponding bit.
Definition: periph_cpu.h:58
uint8_t pinsel
PINSEL# of the ADC pin
Definition: periph_cpu.h:198
uint32_t pinsel_msk
PINSEL Mask for ADC pin.
Definition: periph_cpu.h:199
I2C configuration structure.
Definition: periph_cpu.h:295
uint32_t pinsel_msk_scl
SCL PINSEL Mask
Definition: periph_cpu.h:226
uint8_t pinsel_sda
PINSEL# of the SDA pin
Definition: periph_cpu.h:223
uint8_t pinsel_scl
PINSEL# of the SCL pin
Definition: periph_cpu.h:224
lpc23xx_i2c_t * dev
pointer to the I2C device
Definition: periph_cpu.h:220
uint8_t irq_prio
priority of the I2C IRQ
Definition: periph_cpu.h:222
uint32_t pinsel_msk_sda
SDA PINSEL Mask
Definition: periph_cpu.h:225
SPI device configuration.
Definition: periph_cpu.h:333
lpc23xx_spi_t * dev
pointer to the SPI device
Definition: periph_cpu.h:114
uint8_t pinsel_miso
PINSEL# of the MISO pin
Definition: periph_cpu.h:116
uint32_t pinsel_msk_clk
CLK PINSEL Mask
Definition: periph_cpu.h:120
uint8_t pinsel_clk
PINSEL# of the CLK pin
Definition: periph_cpu.h:117
uint8_t pinsel_mosi
PINSEL# of the MOSI pin
Definition: periph_cpu.h:115
uint32_t pinsel_msk_mosi
MOSI PINSEL Mask
Definition: periph_cpu.h:118
uint32_t pinsel_msk_miso
MISO PINSEL Mask
Definition: periph_cpu.h:119
UART device configuration.
Definition: periph_cpu.h:214
uint8_t pinsel_rx
PINSEL# of the RX pin
Definition: periph_cpu.h:104
lpc23xx_uart_t * dev
pointer to the UART device
Definition: periph_cpu.h:102
uint32_t pinsel_msk_tx
TX PINSEL Mask
Definition: periph_cpu.h:107
uint8_t pinsel_tx
PINSEL# of the TX pin
Definition: periph_cpu.h:105
uint8_t irq_prio_rx
priority of the RX IRQ
Definition: periph_cpu.h:103
uint32_t pinsel_msk_rx
RX PINSEL Mask
Definition: periph_cpu.h:106