ca13734bf0
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers, middleware (CAN stack, diagnostics, safety), applications, board support, build/test tooling, and documentation.
114 lines
2.9 KiB
C
114 lines
2.9 KiB
C
/**
|
|
* @file gpio_driver.h
|
|
* @brief GPIO driver interface
|
|
*/
|
|
|
|
#ifndef GPIO_DRIVER_H
|
|
#define GPIO_DRIVER_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "kernel.h"
|
|
|
|
/* GPIO Configuration Constants */
|
|
#define GPIO_MAX_PORTS 8
|
|
#define GPIO_MAX_PINS_PER_PORT 16
|
|
#define GPIO_MAX_INTERRUPTS 32
|
|
|
|
/* GPIO Modes */
|
|
typedef enum {
|
|
GPIO_MODE_INPUT = 0,
|
|
GPIO_MODE_OUTPUT = 1,
|
|
GPIO_MODE_ALTERNATE = 2,
|
|
GPIO_MODE_ANALOG = 3
|
|
} GpioMode_t;
|
|
|
|
/* GPIO Output Types */
|
|
typedef enum {
|
|
GPIO_OUTPUT_PUSH_PULL = 0,
|
|
GPIO_OUTPUT_OPEN_DRAIN = 1
|
|
} GpioOutputType_t;
|
|
|
|
/* GPIO Pull Configuration */
|
|
typedef enum {
|
|
GPIO_PULL_NONE = 0,
|
|
GPIO_PULL_UP = 1,
|
|
GPIO_PULL_DOWN = 2
|
|
} GpioPull_t;
|
|
|
|
/* GPIO Speed */
|
|
typedef enum {
|
|
GPIO_SPEED_LOW = 0,
|
|
GPIO_SPEED_MEDIUM = 1,
|
|
GPIO_SPEED_HIGH = 2,
|
|
GPIO_SPEED_VERY_HIGH = 3
|
|
} GpioSpeed_t;
|
|
|
|
/* GPIO Alternate Functions */
|
|
typedef enum {
|
|
GPIO_AF0 = 0,
|
|
GPIO_AF1 = 1,
|
|
GPIO_AF2 = 2,
|
|
GPIO_AF3 = 3,
|
|
GPIO_AF4 = 4,
|
|
GPIO_AF5 = 5,
|
|
GPIO_AF6 = 6,
|
|
GPIO_AF7 = 7,
|
|
GPIO_AF8 = 8,
|
|
GPIO_AF9 = 9,
|
|
GPIO_AF10 = 10,
|
|
GPIO_AF11 = 11,
|
|
GPIO_AF12 = 12,
|
|
GPIO_AF13 = 13,
|
|
GPIO_AF14 = 14,
|
|
GPIO_AF15 = 15
|
|
} GpioAlternateFunction_t;
|
|
|
|
/* GPIO Interrupt Triggers */
|
|
typedef enum {
|
|
GPIO_INTERRUPT_NONE = 0,
|
|
GPIO_INTERRUPT_RISING = 1,
|
|
GPIO_INTERRUPT_FALLING = 2,
|
|
GPIO_INTERRUPT_BOTH = 3
|
|
} GpioInterruptTrigger_t;
|
|
|
|
/* GPIO Pin Configuration */
|
|
typedef struct {
|
|
uint8_t port;
|
|
uint8_t pin;
|
|
GpioMode_t mode;
|
|
GpioOutputType_t output_type;
|
|
GpioPull_t pull;
|
|
GpioSpeed_t speed;
|
|
GpioAlternateFunction_t alternate_function;
|
|
} GpioPinConfig_t;
|
|
|
|
/* GPIO Interrupt Configuration */
|
|
typedef struct {
|
|
uint8_t port;
|
|
uint8_t pin;
|
|
GpioInterruptTrigger_t trigger;
|
|
void (*callback)(uint8_t port, uint8_t pin);
|
|
} GpioInterruptConfig_t;
|
|
|
|
/* GPIO Driver Interface */
|
|
KernelStatus_t gpio_init(const GpioPinConfig_t* config);
|
|
KernelStatus_t gpio_deinit(uint8_t port, uint8_t pin);
|
|
KernelStatus_t gpio_set_mode(uint8_t port, uint8_t pin, GpioMode_t mode);
|
|
KernelStatus_t gpio_set_output_type(uint8_t port, uint8_t pin, GpioOutputType_t type);
|
|
KernelStatus_t gpio_set_pull(uint8_t port, uint8_t pin, GpioPull_t pull);
|
|
KernelStatus_t gpio_set_speed(uint8_t port, uint8_t pin, GpioSpeed_t speed);
|
|
KernelStatus_t gpio_set_alternate_function(uint8_t port, uint8_t pin,
|
|
GpioAlternateFunction_t af);
|
|
KernelStatus_t gpio_write(uint8_t port, uint8_t pin, bool value);
|
|
KernelStatus_t gpio_write_port(uint8_t port, uint16_t value);
|
|
bool gpio_read(uint8_t port, uint8_t pin);
|
|
uint16_t gpio_read_port(uint8_t port);
|
|
KernelStatus_t gpio_toggle(uint8_t port, uint8_t pin);
|
|
KernelStatus_t gpio_configure_interrupt(const GpioInterruptConfig_t* config);
|
|
KernelStatus_t gpio_enable_interrupt(uint8_t port, uint8_t pin);
|
|
KernelStatus_t gpio_disable_interrupt(uint8_t port, uint8_t pin);
|
|
void gpio_process_interrupt(uint8_t port);
|
|
|
|
#endif /* GPIO_DRIVER_H */
|