libpynq
(release 5EID0-2023 version 0.3.0 of 2024-04-25 09:42 )
buttons.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2023 Eindhoven University of Technology
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in all
12
copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
SOFTWARE.
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
86
typedef
enum
{
BUTTON0
,
BUTTON1
,
BUTTON2
,
BUTTON3
,
NUM_BUTTONS
}
button_index_t
;
87
94
typedef
enum
{
SWITCH0
,
SWITCH1
,
NUM_SWITCHES
}
switches_index_t
;
95
99
extern
void
switches_init
(
void
);
100
104
extern
void
switches_destroy
(
void
);
105
109
extern
void
buttons_init
(
void
);
110
114
extern
void
buttons_destroy
(
void
);
115
123
extern
int
get_button_state
(
const
int
button);
124
135
extern
int
wait_until_button_state
(
const
int
button,
const
int
state);
136
147
extern
int
sleep_msec_button_pushed
(
const
int
button,
const
int
msec);
148
157
extern
void
sleep_msec_buttons_pushed
(
int
button_states[],
const
int
ms);
158
167
extern
int
wait_until_button_pushed
(
const
int
button);
168
177
extern
int
wait_until_button_released
(
const
int
button);
178
186
extern
int
wait_until_any_button_pushed
(
void
);
187
195
extern
int
wait_until_any_button_released
(
void
);
196
203
extern
int
get_switch_state
(
const
int
switch_num);
204
209
#endif
wait_until_button_released
int wait_until_button_released(const int button)
Wait until the given button is not pushed (which may be immediately).
Definition:
buttons.c:173
wait_until_button_state
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:85
SWITCH1
@ SWITCH1
Definition:
buttons.h:94
switches_init
void switches_init(void)
Initialise the switches before they can be used.
Definition:
buttons.c:57
wait_until_button_pushed
int wait_until_button_pushed(const int button)
Wait until the given button is pushed (which may be immediately).
Definition:
buttons.c:168
get_switch_state
int get_switch_state(const int switch_num)
Definition:
buttons.c:219
button_index_t
button_index_t
Enum of buttons.
Definition:
buttons.h:86
sleep_msec_buttons_pushed
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:142
sleep_msec_button_pushed
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:111
buttons_init
void buttons_init(void)
Initialise the buttons before they can be used.
Definition:
buttons.c:39
wait_until_any_button_pushed
int wait_until_any_button_pushed(void)
Wait until any button is not pushed (which may be immediately).
Definition:
buttons.c:178
buttons_destroy
void buttons_destroy(void)
Unitialize the buttons.
Definition:
buttons.c:50
BUTTON0
@ BUTTON0
Definition:
buttons.h:86
BUTTON3
@ BUTTON3
Definition:
buttons.h:86
BUTTON1
@ BUTTON1
Definition:
buttons.h:86
SWITCH0
@ SWITCH0
Definition:
buttons.h:94
BUTTON2
@ BUTTON2
Definition:
buttons.h:86
NUM_BUTTONS
@ NUM_BUTTONS
Definition:
buttons.h:86
NUM_SWITCHES
@ NUM_SWITCHES
Definition:
buttons.h:94
gpio.h
wait_until_any_button_released
int wait_until_any_button_released(void)
Wait until the given button is not pushed (which may be immediately).
Definition:
buttons.c:199
switches_index_t
switches_index_t
Enum of switches. Functions use a switch numbered from 0..NUM_SWITCHES-1. Alternatively,...
Definition:
buttons.h:94
switches_destroy
void switches_destroy(void)
Unitialize the buttons.
Definition:
buttons.c:66
get_button_state
int get_button_state(const int button)
Return the state of the button (BUTTON_(NOT_)PUSHED).
Definition:
buttons.c:73
library
buttons.h
Generated on Thu Apr 25 2024 09:42:47 for libpynq by
1.8.17