rp2040/driver/inc/gpio.h
2025-06-01 15:54:05 +08:00

91 lines
3.2 KiB
C

#ifndef __HARDWARE_GPIO_H__
#define __HARDWARE_GPIO_H__
#include "reg.h"
#include "gpio_reg.h"
#define GPIO_FUNC_XIP (0 << 0U) /* not available for GPIO0~29 */
#define GPIO_FUNC_SPI (1 << 0U) /* only available for GPIO0~29 */
#define GPIO_FUNC_UART (2 << 0U) /* only available for GPIO0~29 */
#define GPIO_FUNC_I2C (3 << 0U) /* only available for GPIO0~29 */
#define GPIO_FUNC_PWM (4 << 0U) /* only available for GPIO0~29 */
#define GPIO_FUNC_SIO (5 << 0U) /* available for all GPIO */
#define GPIO_FUNC_PIO0 (6 << 0U) /* only available for GPIO0~29 */
#define GPIO_FUNC_PIO1 (7 << 0U) /* only available for GPIO0~29 */
#define GPIO_FUNC_CLOCK (8 << 0U) /* only available for GPIO20~25 */
#define GPIO_FUNC_USB (9 << 0U)
#define GPIO_FUNC_NULL (0x1F << 0U)
#define GPIO_OVER_OUT_NORMAL (0 << 8U)
#define GPIO_OVER_OUT_INVERSE (1 << 8U)
#define GPIO_OVER_OUT_LOW (2 << 8U)
#define GPIO_OVER_OUT_HIGH (3 << 8U)
#define GPIO_OVER_OE_NORMAL (0 << 12U)
#define GPIO_OVER_OE_INVERSE (1 << 12U)
#define GPIO_OVER_OE_DISABLE (2 << 12U)
#define GPIO_OVER_OE_ENABLE (3 << 12U)
#define GPIO_OVER_IN_NORMAL (0 << 16U)
#define GPIO_OVER_IN_INVERSE (1 << 16U)
#define GPIO_OVER_IN_LOW (2 << 16U)
#define GPIO_OVER_IN_HIGH (3 << 16U)
#define GPIO_OVER_IRQ_NORMAL (0 << 2U)
#define GPIO_OVER_IRQ_INVERSE (1 << 2U)
#define GPIO_OVER_IRQ_LOW (2 << 2U)
#define GPIO_OVER_IRQ_HIGH (3 << 2U)
#define GPIO_SLEW_FAST (1ULL << (0 + 32))
#define GPIO_SCHMITT (1ULL << (1 + 32))
#define GPIO_PULL_DOWN (1ULL << (2 + 32))
#define GPIO_PULL_UP (1ULL << (3 + 32))
#define GPIO_DRIVE_2MA (0ULL << (4 + 32))
#define GPIO_DRIVE_4MA (1ULL << (4 + 32))
#define GPIO_DRIVE_8MA (2ULL << (4 + 32))
#define GPIO_DRIVE_12MA (3ULL << (4 + 32))
#define GPIO_PAD_IE (1ULL << (6 + 32))
#define GPIO_PAD_OD (1ULL << (7 + 32))
#define GPIO_IRQ_NULL (0)
#define GPIO_IRQ_LEVEL_LOW (1)
#define GPIO_IRQ_LEVEL_HIGH (2)
#define GPIO_IRQ_EDGE_FALL (4)
#define GPIO_IRQ_EDGE_RISE (8)
#define GPIO_PADS_VOLTAGE_3V3 (0)
#define GPIO_PADS_VOLTAGE_1V8 (1)
#ifdef __cplusplus
extern "C" {
#endif
uint8_t gpio_read(uint8_t pin);
void gpio_set(uint8_t pin);
void gpio_clear(uint8_t pin);
void gpio_init(uint8_t pin, uint64_t cfg);
uint8_t gpio_irq_get_raw_status(uint8_t pin, uint8_t irq);
void gpio_irq_raw_status_clear(uint8_t pin, uint8_t irq);
void gpio_irq_enable_proc0(uint8_t pin, uint8_t irq);
void gpio_irq_disable_proc0(uint8_t pin, uint8_t irq);
void gpio_irq_force_proc0(uint8_t pin, uint8_t irq);
void gpio_irq_deforce_proc0(uint8_t pin, uint8_t irq);
uint8_t gpio_irq_get_status_proc0(uint8_t pin, uint8_t irq);
void gpio_irq_enable_proc1(uint8_t pin, uint8_t irq);
void gpio_irq_disable_proc1(uint8_t pin, uint8_t irq);
void gpio_irq_force_proc1(uint8_t pin, uint8_t irq);
void gpio_irq_deforce_proc1(uint8_t pin, uint8_t irq);
uint8_t gpio_irq_get_status_proc1(uint8_t pin, uint8_t irq);
void gpio_irq_enable_dormant(uint8_t pin, uint8_t irq);
void gpio_irq_disable_dormant(uint8_t pin, uint8_t irq);
void gpio_irq_force_dormant(uint8_t pin, uint8_t irq);
void gpio_irq_deforce_dormant(uint8_t pin, uint8_t irq);
uint8_t gpio_irq_get_status_dormant(uint8_t pin, uint8_t irq);
#ifdef __cplusplus
}
#endif
#endif /* __HARDWARE_GPIO_H__ */