Friedrich-Alexander-Universität Erlangen-Nürnberg  /   Technische Fakultät  /   Department Informatik

SPiCboard library (libspicboard, revision 14925) API documentation

Found a bug or something ambiguous? Mail us to get it fixed!

button.h
Go to the documentation of this file.
1 #ifndef BUTTON_H
2 #define BUTTON_H
3 
4 #include <stdint.h>
5 
6 
7 /**
8 
9  *
10  * \addtogroup Button
11  *
12  * \brief The button module enables event-driven and polling access
13  * to the buttons of the SPiCboard.
14  *
15  * The SPiCboard is equipped with two buttons. Button 0 is debounced in
16  * hardware, whereas Button 1 needs to be debounced in software by the
17  * button module. Debouncing is transparent to the application, that
18  * can use both buttons through the provided interface without the
19  * need to care about debouncing.
20  *
21  * The debouncing code makes use of the timer module. When no callbacks
22  * are registered for Button 1, the debouncing code is disabled and all
23  * alarms registered at the timer should be canceled.
24  *
25  * The button module uses dynamic memory management to maintain the
26  * callback queues.
27  *
28  * @{
29  * \file button.h
30  * \version \$Rev: 7715 $
31  */
32 
33 /**
34  * \brief Identifiers for all available buttons.
35  *
36  */
37 typedef enum {
38  BUTTON0 = 4, /**< Button 0 */
39  BUTTON1 = 8 /**< Button 1 */
40 } BUTTON;
41 
42 /**
43  * \brief States for buttons.
44  *
45  * Pressed and released states for buttons.
46  */
47 typedef enum {
48  BUTTONSTATE_PRESSED = 1, /**< Button is pressed */
49  BUTTONSTATE_RELEASED = 2 /**< Button is released */
50 } BUTTONSTATE;
51 
52 /**
53  * \brief Events for buttons.
54  *
55  * Pressed and released events for buttons.
56  */
57 typedef enum {
58  BUTTONEVENT_PRESSED = 1, /**< Button was pressed */
59  BUTTONEVENT_RELEASED = 2 /**< Button was released */
60 } BUTTONEVENT;
61 
62 /**
63  * \brief Type for button event callback functions.
64  *
65  * A button callback function is called on the interrupt level whenever
66  * an event at a button occurs that the function was registered for.
67  * The callback function is passed the button id and the type of event
68  * that occurred. This way, the same callback function can be registered
69  * for different buttons and events.
70  */
71 typedef void (*BUTTONCALLBACK) (BUTTON, BUTTONEVENT);
72 
73 /**
74  * \brief Register a callback function for a button event.
75  *
76  * \param btn the id of the button
77  * \param eve the type of event that the callback function should be invoked for.
78  * event types can be bitwise or'd to register a callback for both
79  * pressed and released events.
80  * \param callback pointer to the callback function. This function is called from the
81  * interrupt handler.
82  * \retval 0 success,
83  * \retval !0 error
84  * \sa sb_button_unregisterCallback
85  */
87 
88 /**
89  * \brief Unregister a callback function for a button event.
90  *
91  *
92  * \param btn the id of the button
93  * \param eve the type of event that the callback function should be invoked for.
94  * event types can be bitwise or'd to register a callback for both
95  * pressed and released events.
96  * \param callback pointer to the callback function
97  * \return 0 on success, negative value on error
98  * \retval 0 success
99  * \retval -1 the callback function was not registered with the given button/event combination
100  * \sa sb_button_registerCallback
101  */
103 
104 /**
105  * \brief Query the current state of a button.
106  *
107  * \param btn id of the button
108  * \return The buttons current state (pressed or released) as a \ref BUTTONSTATE
109  */
111 
112 /** @}*/
113 
114 #endif
115 
int8_t sb_button_registerCallback(BUTTON btn, BUTTONEVENT eve, BUTTONCALLBACK callback)
Register a callback function for a button event.
BUTTONEVENT
Events for buttons.
Definition: button.h:57
Definition: button.h:39
Definition: button.h:49
BUTTON
Identifiers for all available buttons.
Definition: button.h:37
int8_t sb_button_unregisterCallback(BUTTON btn, BUTTONEVENT eve, BUTTONCALLBACK callback)
Unregister a callback function for a button event.
BUTTONSTATE sb_button_getState(BUTTON btn)
Query the current state of a button.
BUTTONSTATE
States for buttons.
Definition: button.h:47
Definition: button.h:48
Definition: button.h:38
Definition: button.h:58
Definition: button.h:59
void(* BUTTONCALLBACK)(BUTTON, BUTTONEVENT)
Type for button event callback functions.
Definition: button.h:71