-
Notifications
You must be signed in to change notification settings - Fork 7
/
generate.py
99 lines (90 loc) · 3.06 KB
/
generate.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from cffi import FFI
ffi = FFI()
ffi.set_source("_fbsd_gpio",
"""
#include <libgpio.h>
#include <sys/gpio.h>
""",
libraries=['gpio'])
ffi.cdef("""
/* From sys/gpio.h and libgpio.h */
/* Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org> */
/* Copyright (c) 2013-2014 Rui Paulo <rpaulo@FreeBSD.org> */
/* Copyright (c) 2009 Marc Balmer <marc@msys.ch> */
/* Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> */
/* GPIO pin states */
#define GPIO_PIN_LOW 0x00 /* low level (logical 0) */
#define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */
/* Max name length of a pin */
#define GPIOMAXNAME 64
#define GPIO_INVALID_HANDLE -1
typedef int gpio_handle_t;
typedef uint32_t gpio_pin_t;
/*
* Structure describing a GPIO pin configuration.
*/
typedef struct {
gpio_pin_t g_pin;
char g_name[GPIOMAXNAME];
uint32_t g_caps;
uint32_t g_flags;
} gpio_config_t;
typedef enum {
GPIO_VALUE_INVALID = -1,
GPIO_VALUE_LOW = GPIO_PIN_LOW,
GPIO_VALUE_HIGH = GPIO_PIN_HIGH
} gpio_value_t;
/*
* Open /dev/gpiocN or a specific device.
*/
gpio_handle_t gpio_open(unsigned int);
gpio_handle_t gpio_open_device(const char *);
void gpio_close(gpio_handle_t);
/*
* Get a list of all the GPIO pins.
*/
int gpio_pin_list(gpio_handle_t, gpio_config_t **);
/*
* GPIO pin configuration.
*
* Retrieve the configuration of a specific GPIO pin. The pin number is
* passed through the gpio_config_t structure.
*/
int gpio_pin_config(gpio_handle_t, gpio_config_t *);
/*
* Sets the GPIO pin name. The pin number and pin name to be set are passed
* as parameters.
*/
int gpio_pin_set_name(gpio_handle_t, gpio_pin_t, char *);
/*
* Sets the GPIO flags on a specific GPIO pin. The pin number and the flags
* to be set are passed through the gpio_config_t structure.
*/
int gpio_pin_set_flags(gpio_handle_t, gpio_config_t *);
/*
* GPIO pin values.
*/
int gpio_pin_get(gpio_handle_t, gpio_pin_t);
int gpio_pin_set(gpio_handle_t, gpio_pin_t, int);
int gpio_pin_toggle(gpio_handle_t, gpio_pin_t);
/*
* Helper functions to set pin states.
*/
int gpio_pin_low(gpio_handle_t, gpio_pin_t);
int gpio_pin_high(gpio_handle_t, gpio_pin_t);
/*
* Helper functions to configure pins.
*/
int gpio_pin_input(gpio_handle_t, gpio_pin_t);
int gpio_pin_output(gpio_handle_t, gpio_pin_t);
int gpio_pin_opendrain(gpio_handle_t, gpio_pin_t);
int gpio_pin_pushpull(gpio_handle_t, gpio_pin_t);
int gpio_pin_tristate(gpio_handle_t, gpio_pin_t);
int gpio_pin_pullup(gpio_handle_t, gpio_pin_t);
int gpio_pin_pulldown(gpio_handle_t, gpio_pin_t);
int gpio_pin_invin(gpio_handle_t, gpio_pin_t);
int gpio_pin_invout(gpio_handle_t, gpio_pin_t);
int gpio_pin_pulsate(gpio_handle_t, gpio_pin_t);
""")
if __name__ == "__main__":
ffi.compile()