-
Notifications
You must be signed in to change notification settings - Fork 7
/
i_tiny_gpio.h
50 lines (38 loc) · 1016 Bytes
/
i_tiny_gpio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*!
* @file
* @brief Abstract GPIO.
*/
#ifndef i_tiny_gpio_h
#define i_tiny_gpio_h
#include <stdint.h>
#include <stdbool.h>
enum {
tiny_gpio_direction_input,
tiny_gpio_direction_output
};
typedef uint8_t tiny_gpio_direction_t;
struct i_tiny_gpio_api_t;
typedef struct {
const struct i_tiny_gpio_api_t* api;
} i_tiny_gpio_t;
typedef struct i_tiny_gpio_api_t {
/*!
* Set the direction of the GPIO.
*/
void (*set_direction)(i_tiny_gpio_t* self, tiny_gpio_direction_t direction);
/*!
* Read the state of the GPIO (must be configured as an input).
*/
bool (*read)(i_tiny_gpio_t* self);
/*!
* Write the state of the GPIO (must be configured as an input).
*/
void (*write)(i_tiny_gpio_t* self, bool state);
} i_tiny_gpio_api_t;
#define tiny_gpio_set_direction(self, direction) \
(self)->api->set_direction((self), (direction))
#define tiny_gpio_read(self) \
(self)->api->read((self))
#define tiny_gpio_write(self, state) \
(self)->api->write((self), (state))
#endif