34#define LOG_DOMAIN "buttons"
36static bool buttons_initialized =
false;
37static bool switches_initialized =
false;
40 if (buttons_initialized ==
true) {
41 pynq_error(
"buttons_destroy: buttons already initialized\n");
47 buttons_initialized =
true;
51 if (buttons_initialized ==
false) {
52 pynq_error(
"buttons_destroy: buttons weren't initialized\n");
57 if (switches_initialized ==
true) {
58 pynq_error(
"switches_destroy: switches already initialized\n");
62 switches_initialized =
true;
66 if (switches_initialized ==
false) {
67 pynq_error(
"switches_destroy: switches weren't initialized\n");
72 if (buttons_initialized ==
false) {
73 pynq_error(
"get_button_state: buttons weren't initialized\n");
76 pynq_error(
"get_button_state: invalid button=%d, must be 0..%d-1\n",
85 if (buttons_initialized ==
false) {
86 pynq_error(
"wait_until_button_state: buttons weren't initialized\n");
89 pynq_error(
"get_button_state: invalid button=%d, must be 0..%d-1\n", button,
94 pynq_error(
"get_button_state: button %d has not been set as input\n",
97 struct timeval call, close;
99 gettimeofday(&call, NULL);
100 const unsigned int check =
104 gettimeofday(&close, NULL);
105 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
106 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
111 if (buttons_initialized ==
false) {
112 pynq_error(
"sleep_msec_button: buttons weren't initialized\n");
115 pynq_error(
"sleep_msec_button_pushed: invalid button=%d, must be 0..%d-1\n",
121 "sleep_msec_button_pushed: button %d has not been set as input\n",
125 struct timeval call, close;
128 gettimeofday(&call, NULL);
134 (void)gettimeofday(&close, NULL);
135 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
136 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
137 }
while (dTime < ms);
142 if (buttons_initialized ==
false) {
143 pynq_error(
"sleep_msec_buttons_pushed: buttons weren't initialized\n");
145 if (button_states == NULL) {
146 pynq_error(
"sleep_msec_buttons_pushed: button_states is NULL\n");
148 struct timeval call, close;
152 (void)gettimeofday(&call, NULL);
161 (void)gettimeofday(&close, NULL);
162 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
163 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
164 }
while (dTime < ms);
179 if (buttons_initialized ==
false) {
180 pynq_error(
"wait_until_any_button_pushed: buttons weren't initialized\n");
185 "wait_until_any_button_pushed: button %d has not been set as input\n",
200 if (buttons_initialized ==
false) {
201 pynq_error(
"wait_until_any_button_released: buttons weren't initialized\n");
205 pynq_error(
"wait_until_any_button_released: button %d has not been set "
219 if (switches_initialized ==
false) {
220 pynq_error(
"get_switch_state: switches weren't initialized\n");
223 pynq_error(
"get_switch_state: invalid switch_num=%d, must be 0..%i-1\n",
gpio_direction_t gpio_get_direction(const gpio_t pin)
Returns the direction the set pin is initialized in.
gpio_level_t gpio_get_level(const gpio_t pin)
Return the level of the GPIO pin.
void gpio_set_direction(const gpio_t pin, const gpio_direction_t direction)
Set the GPIO pin as in input or output.
#define SWB_BTN0
Button input pins.
#define SWB_SW0
Switch input pins.