12 #ifndef __GPIO_DEVICE_H__
13 #define __GPIO_DEVICE_H__
21 #define GPIO_MODE_INPUT 1 << 0
22 #define GPIO_MODE_OUTPUT 1 << 1
23 #define GPIO_MODE_PULLUP 1 << 2
24 #define GPIO_MODE_PULLDOWN 1 << 3
25 #define GPIO_MODE_INTERRUPT 1 << 4
30 typedef const struct GPIO_Device_t {
31 void (*EnablePullUp)(uint8_t pos,
bool bit);
32 void (*EnablePullDown)(uint8_t pos,
bool bit);
33 void (*EnableOutput)(uint8_t pos,
bool bit);
34 void (*EnableInput)(uint8_t pos,
bool bit);
35 void (*EnableInterrupt)(uint8_t pos,
bool bit);
36 void (*Set)(uint8_t pos, uint8_t bit);
37 uint8_t (*Read)(uint8_t pos);
38 void (*EnablePortPullUp)(
bool bit, uint8_t mask);
39 void (*EnablePortPullDown)(
bool bit, uint8_t mask);
40 void (*EnablePortOutput)(
bool bit, uint8_t mask);
41 void (*EnablePortInput)(
bool bit, uint8_t mask);
42 void (*EnablePortInterrupt)(
bool bit, uint8_t mask);
43 void (*PortSet)(uint8_t val, uint8_t mask);
44 uint8_t (*PortRead)(uint8_t mask);
int32_t GPIO_devRegisterIRQ(GPIO_Device_t *dev, void *cb)
Register a callback function to GPIO interrupt handler.
Definition: gpio_device.c:223
A structure to represent GPIO device.
Definition: gpio_device.h:30
int32_t GPIO_devUnregisterIRQ(GPIO_Device_t *dev, void *cb)
Unregister a callback function to GPIO interrupt handler.
Definition: gpio_device.c:233
int32_t GPIO_devSet(GPIO_Device_t *dev, uint8_t pos, uint8_t state)
Set GPIO pin state.
Definition: gpio_device.c:160
int32_t GPIO_devInitPort(GPIO_Device_t *dev, uint8_t mask, uint32_t mode)
Initialize a GPIO port.
Definition: gpio_device.c:262
const struct GPIO_Device_t GPIO_Device_t
A structure to represent GPIO device.
IRQn_Type IRQ
Definition: gpio_device.h:45
enum IRQn IRQn_Type
The enumeration of Interrupt Number Assignments.
char * Name
Definition: gpio_device.h:46
int32_t GPIO_devPortRead(GPIO_Device_t *dev, uint8_t mask)
Read GPIO pin state.
Definition: gpio_device.c:318
GPIO_Device_t * GPIO_devRequest(const char *name)
Request a GPIO Device.
Definition: gpio_device.c:249
int32_t GPIO_devPortSet(GPIO_Device_t *dev, uint8_t mask, uint8_t val)
Set GPIO port.
Definition: gpio_device.c:310
int32_t GPIO_devInit(GPIO_Device_t *dev, uint8_t pos, uint32_t mode)
Initialize a GPIO pin.
Definition: gpio_device.c:175
int32_t GPIO_devRead(GPIO_Device_t *dev, uint8_t pos)
Read GPIO pin state.
Definition: gpio_device.c:168