Loading...
Searching...
No Matches
cc2538_gpio.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Loci Controls Inc.
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
9#pragma once
10
25
26#include <stdint.h>
27
28#include "cc2538.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
38enum {
39 PORT_A = 0,
40 PORT_B = 1,
41 PORT_C = 2,
42 PORT_D = 3,
43};
45
46#define GPIO_PORT_SHIFT 3
47#define GPIO_BITS_PER_PORT ( 1 << GPIO_PORT_SHIFT )
48#define GPIO_BIT_MASK ( GPIO_BITS_PER_PORT - 1 )
49
57#define PIN_MASK(n) ( 1 << (n) )
58
66#define GPIO_NUM_TO_PORT_NUM(gpio_num) ( (gpio_num) >> GPIO_PORT_SHIFT )
67
75#define GPIO_BIT_NUM(gpio_num) ( (gpio_num) & GPIO_BIT_MASK )
76
85#define GPIO_PXX_TO_NUM(port_num, bit_num) ( ((port_num) << GPIO_PORT_SHIFT) | (bit_num) )
86
94#define GPIO_NUM_TO_DEV(gpio_num) ( GPIO_A + GPIO_NUM_TO_PORT_NUM(gpio_num) )
95
101#define gpio_hardware_control(gpio_num) ( GPIO_NUM_TO_DEV(gpio_num)->AFSEL |= PIN_MASK(GPIO_BIT_NUM(gpio_num)) )
102
108#define gpio_software_control(gpio_num) ( GPIO_NUM_TO_DEV(gpio_num)->AFSEL &= ~PIN_MASK(GPIO_BIT_NUM(gpio_num)) )
109
115#define gpio_dir_output(gpio_num) ( GPIO_NUM_TO_DEV(gpio_num)->DIR |= PIN_MASK(GPIO_BIT_NUM(gpio_num)) )
116
122#define gpio_dir_input(gpio_num) ( GPIO_NUM_TO_DEV(gpio_num)->DIR &= ~PIN_MASK(GPIO_BIT_NUM(gpio_num)) )
123
129#define cc2538_gpio_read(gpio_num) ( (GPIO_NUM_TO_DEV(gpio_num)->DATA >> GPIO_BIT_NUM(gpio_num)) & 1 )
130
136#define cc2538_gpio_clear(gpio_num) ( GPIO_NUM_TO_DEV(gpio_num)->DATA &= ~PIN_MASK(GPIO_BIT_NUM(gpio_num)) )
137
144enum {
177};
179
209
213#define GPIO_BASE (0x400d9000)
214
219#define GPIO_PORTNUM_SHIFT (12U)
220#define GPIO_PORTNUM_MASK (0x00007000)
221#define GPIO_PIN_MASK (0x00000007)
222#define GPIO_PORT_MASK (0xfffff000)
224
230#define GPIO_A ((cc2538_gpio_t *)0x400d9000)
231#define GPIO_B ((cc2538_gpio_t *)0x400da000)
232#define GPIO_C ((cc2538_gpio_t *)0x400db000)
233#define GPIO_D ((cc2538_gpio_t *)0x400dc000)
235
239 typedef struct {
240 cc2538_reg_t SEL[32];
243 } cc2538_ioc_t;
244
272
273
301
302
306 typedef enum {
307 OVERRIDE_DISABLE = 0x0,
308 OVERRIDE_ANALOG = 0x1,
309 OVERRIDE_PULLDOWN = 0x2,
310 OVERRIDE_PULLUP = 0x4,
311 OVERRIDE_ENABLE = 0x8,
313
320#define IOC_OVERRIDE_OE 0x00000008
321#define IOC_OVERRIDE_PUE 0x00000004
322#define IOC_OVERRIDE_PDE 0x00000002
323#define IOC_OVERRIDE_ANA 0x00000001
324#define IOC_OVERRIDE_DIS 0x00000000
326
330#define IOC ((cc2538_ioc_t *)0x400d4000)
331
338#define IOC_PXX_OVER (IOC->OVER)
339#define IOC_PXX_SEL (IOC->SEL)
341
342#ifdef __cplusplus
343} /* end extern "C" */
344#endif
345
@ PORT_B
port B
Definition periph_cpu.h:47
@ PORT_C
port C
Definition periph_cpu.h:48
@ PORT_A
port A
Definition periph_cpu.h:46
@ PORT_D
port D
Definition periph_cpu.h:49
CC2538 MCU interrupt and register definitions.
volatile uint32_t cc2538_reg_t
Least-significant 32 bits of the IEEE address.
Definition cc2538.h:123
#define UART1_TXD
TxD pin of UART_DEV(1)
#define UART1_RXD
RxD pin of UART_DEV(1)
cc2538_ioc_pin_t
#define GPIO_PXX_TO_NUM(port_num, bit_num)
Gener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1_TX_SER
SSI1 STXSER EN.
@ GPT3_ICP2
GPT3 ICP2.
@ SSI1_TXD
SSI1 TXD.
@ GPT0_ICP1
GPT0 ICP1.
@ SSI0_TX_SER
SSI0 STXSER EN.
@ SSI1_CLK_OUT
SSI1 CLKOUT.
@ SSI0_FSS_OUT
SSI0 FSSOUT.
@ GPT3_ICP1
GPT3 ICP1.
@ UART1_RTS
UART1 RTS.
@ GPT0_ICP2
GPT0 ICP2.
@ SSI1_FSS_OUT
SSI1 FSSOUT.
@ GPT2_ICP1
GPT2 ICP1.
@ GPT1_ICP2
GPT1 ICP2.
@ I2C_SDA_OUT
I2C CMSSDA.
@ GPT2_ICP2
GPT2 ICP2.
@ GPT1_ICP1
GPT1 ICP1.
@ SSI0_TXD
SSI0 TXD.
@ SSI0_CLK_OUT
SSI0 CLKOUT.
@ I2C_SCL_OUT
I2C CMSSCL.
#define UART0_RXD
RxD of UART_DEV(0) used on all ESP32 boards.
#define UART0_TXD
TxD of UART_DEV(0) used on all ESP32 boards.
GPIO port component registers.
cc2538_reg_t AFSEL
GPIO_A Alternate Function / mode control select register.
cc2538_reg_t DATA
GPIO_A Data Register.
cc2538_reg_t IRQ_DETECT_UNMASK
GPIO_A IRQ Detect ACK for masked interrupts.
cc2538_reg_t DIR
GPIO_A data direction register.
cc2538_reg_t USB_IRQ_ACK
GPIO_A IRQ Detect ACK for USB.
cc2538_reg_t PI_IEN
GPIO_A The Power-up Interrupt Enable register.
cc2538_reg_t RESERVED3[118]
Reserved addresses.
cc2538_reg_t GPIOLOCK
GPIO_A Lock register.
cc2538_reg_t RESERVED2[63]
Reserved addresses.
cc2538_reg_t IBE
GPIO_A Interrupt Both-Edges register.
cc2538_reg_t RESERVED5[1]
Reserved addresses.
cc2538_reg_t RIS
GPIO_A Raw Interrupt Status register.
cc2538_reg_t IS
GPIO_A Interrupt Sense register.
cc2538_reg_t IC
GPIO_A Interrupt Clear register.
cc2538_reg_t PMUX
GPIO_A The PMUX register.
cc2538_reg_t IRQ_DETECT_ACK
GPIO_A IRQ Detect ACK register.
cc2538_reg_t RESERVED1[255]
Reserved addresses.
cc2538_reg_t MIS
GPIO_A Masked Interrupt Status register.
cc2538_reg_t RESERVED4[2]
Reserved addresses.
cc2538_reg_t GPIOCR
GPIO_A Commit Register.
cc2538_reg_t IEV
GPIO_A Interrupt Event Register.
cc2538_reg_t P_EDGE_CTRL
GPIO_A The Port Edge Control register.
cc2538_reg_t IE
GPIO_A Interrupt mask register.
cc2538_reg_t RESERVED6[567]
Reserved addresses.
IOC port component registers.
cc2538_reg_t PINS[21]
select input pin for special functions
cc2538_reg_t OVER[32]
override pin mode, enable alternate mode