libpynq (release 5EWC0-2023 version 0.2.2 of 2023-09-24 22:22)
Loading...
Searching...
No Matches
buttons.h
Go to the documentation of this file.
1/*
2Copyright (c) 2023 Eindhoven University of Technology
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22#ifndef BUTTONS_H
23#define BUTTONS_H
24
25#include <gpio.h>
26
74#define BUTTON_NOT_PUSHED 0
75#define BUTTON_PUSHED 1
76#define SWITCH_OFF 0
77#define SWITCH_ON 1
78
87
95
99extern void switches_init(void);
100
104extern void switches_destroy(void);
105
109extern void buttons_init(void);
110
114extern void buttons_destroy(void);
115
123extern int get_button_state(const int button);
124
135extern int wait_until_button_state(const int button, const int state);
136
147extern int sleep_msec_button_pushed(const int button, const int msec);
148
157extern void sleep_msec_buttons_pushed(int button_states[], const int ms);
158
167extern int wait_until_button_pushed(const int button);
168
177extern int wait_until_button_released(const int button);
178
186extern int wait_until_any_button_pushed(void);
187
195extern int wait_until_any_button_released(void);
196
203extern int get_switch_state(const int switch_num);
204
209#endif
int sleep_msec_button_pushed(const int button, const int msec)
Check if the given button is pushed in msec milliseconds. The function does NOT return early.
Definition buttons.c:110
int wait_until_button_pushed(const int button)
Wait until the given button is pushed (which may be immediately).
Definition buttons.c:167
void switches_init(void)
Initialise the switches before they can be used.
Definition buttons.c:56
int wait_until_any_button_pushed(void)
Wait until any button is not pushed (which may be immediately).
Definition buttons.c:177
void buttons_destroy(void)
Unitialize the buttons.
Definition buttons.c:50
switches_index_t
Enum of switches. Functions use a switch numbered from 0..NUM_SWITCHES-1. Alternatively,...
Definition buttons.h:94
int wait_until_any_button_released(void)
Wait until the given button is not pushed (which may be immediately).
Definition buttons.c:198
void switches_destroy(void)
Unitialize the buttons.
Definition buttons.c:65
button_index_t
Enum of buttons.
Definition buttons.h:86
int wait_until_button_state(const int button, const int state)
Wait until the given button is in state (which may be immediately).
Definition buttons.c:84
int wait_until_button_released(const int button)
Wait until the given button is not pushed (which may be immediately).
Definition buttons.c:172
int get_switch_state(const int switch_num)
Definition buttons.c:218
int get_button_state(const int button)
Return the state of the button (BUTTON_(NOT_)PUSHED).
Definition buttons.c:71
void buttons_init(void)
Initialise the buttons before they can be used.
Definition buttons.c:39
void sleep_msec_buttons_pushed(int button_states[], const int ms)
Check if any button is pushed in msec milliseconds. The function does NOT return early.
Definition buttons.c:141
@ NUM_SWITCHES
Definition buttons.h:94
@ SWITCH0
Definition buttons.h:94
@ SWITCH1
Definition buttons.h:94
@ BUTTON0
Definition buttons.h:86
@ BUTTON1
Definition buttons.h:86
@ BUTTON2
Definition buttons.h:86
@ BUTTON3
Definition buttons.h:86
@ NUM_BUTTONS
Definition buttons.h:86