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",
84 if (buttons_initialized ==
false) {
85 pynq_error(
"wait_until_button_state: buttons weren't initialized\n");
88 pynq_error(
"get_button_state: invalid button=%d, must be 0..%d-1\n", button,
93 pynq_error(
"get_button_state: button %d has not been set as input\n",
96 struct timeval call, close;
98 gettimeofday(&call, NULL);
99 const unsigned int check =
103 gettimeofday(&close, NULL);
104 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
105 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
110 if (buttons_initialized ==
false) {
111 pynq_error(
"sleep_msec_button: buttons weren't initialized\n");
114 pynq_error(
"sleep_msec_button_pushed: invalid button=%d, must be 0..%d-1\n",
120 "sleep_msec_button_pushed: button %d has not been set as input\n",
124 struct timeval call, close;
127 gettimeofday(&call, NULL);
133 (void)gettimeofday(&close, NULL);
134 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
135 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
136 }
while (dTime < ms);
141 if (buttons_initialized ==
false) {
142 pynq_error(
"sleep_msec_buttons_pushed: buttons weren't initialized\n");
144 if (button_states == NULL) {
145 pynq_error(
"sleep_msec_buttons_pushed: button_states is NULL\n");
147 struct timeval call, close;
151 (void)gettimeofday(&call, NULL);
160 (void)gettimeofday(&close, NULL);
161 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
162 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
163 }
while (dTime < ms);
178 if (buttons_initialized ==
false) {
179 pynq_error(
"wait_until_any_button_pushed: buttons weren't initialized\n");
184 "wait_until_any_button_pushed: button %d has not been set as input\n",
199 if (buttons_initialized ==
false) {
200 pynq_error(
"wait_until_any_button_released: buttons weren't initialized\n");
204 pynq_error(
"wait_until_any_button_released: button %d has not been set "
218 if (switches_initialized ==
false) {
219 pynq_error(
"get_switch_state: switches weren't initialized\n");
222 pynq_error(
"get_switch_state: invalid switch_num=%d, must be 0..%i-1\n",
gpio_direction_t gpio_get_direction(const io_t pin)
Returns the direction the set pin is initialized in.
void gpio_set_direction(const io_t pin, const gpio_direction_t dir)
Set the IO pin as in input or output.
gpio_level_t gpio_get_level(const io_t pin)
Return the level of the IO pin.
@ IO_SW0
Switch input pins.
@ IO_BTN0
Button input pins.