Kamcho Library 02.00.03  lib.kamcho.02.00.03.287
gpio_device.h
Go to the documentation of this file.
1 
12 #ifndef __GPIO_DEVICE_H__
13 #define __GPIO_DEVICE_H__
14 
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include <stddef.h>
18 #include "hdf.h"
19 #include "errno.h"
20 
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);
46  char *Name;
48 
55 GPIO_Device_t *GPIO_devRequest(const char *name);
56 
64 int32_t GPIO_devRegisterIRQ(GPIO_Device_t *dev, void *cb);
65 
73 int32_t GPIO_devUnregisterIRQ(GPIO_Device_t *dev, void *cb);
74 
83 int32_t GPIO_devInit(GPIO_Device_t *dev, uint8_t pos, uint32_t mode);
84 
93 int32_t GPIO_devSet(GPIO_Device_t *dev, uint8_t pos, uint8_t state);
94 
102 int32_t GPIO_devRead(GPIO_Device_t *dev, uint8_t pos);
103 
112 int32_t GPIO_devInitPort(GPIO_Device_t *dev, uint8_t mask, uint32_t mode);
113 
122 int32_t GPIO_devPortSet(GPIO_Device_t *dev, uint8_t mask, uint8_t val);
123 
131 int32_t GPIO_devPortRead(GPIO_Device_t *dev, uint8_t mask);
132 
133 #endif /* __GPIO_DEVICE_H__ */
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