The button module enables event-driven and polling access to the buttons of the SPiCboard.
More...
Detailed Description
The button module enables event-driven and polling access to the buttons of the SPiCboard.
The SPiCboard is equipped with two buttons. Button 0 is debounced in hardware, whereas Button 1 needs to be debounced in software by the button module. Debouncing is transparent to the application, that can use both buttons through the provided interface without the need to care about debouncing.
The debouncing code makes use of the timer module. When no listeners are registered for Button 1, the debouncing code is disabled and all alarms registered at the timer should be canceled.
The button module uses dynamic memory management to maintain the listener queues.
Typedef Documentation
Type for button event callback functions.
A button callback function is called on the interrupt level whenever an event at a button occurs that the function was registered for. The callback function is passed the button id and the type of event that occurred. This way, the same callback function can be registered for different buttons and events.
Enumeration Type Documentation
Identifiers for all available buttons.
- Enumerator:
BUTTON0 |
Button 0
|
BUTTON1 |
Button 1
|
Events for buttons.
Pressed and released events for buttons.
- Enumerator:
BTNPRESSED |
Button was pressed
|
BTNRELEASED |
Button was released
|
Function Documentation
Query the current state of a button.
- Parameters:
-
- Returns:
- The buttons current state (pressed or released) as a BUTTONEVENT
Register a callback function for a button event.
- Parameters:
-
| btn | the id of the button |
| eve | the type of event that the callback function should be invoked for. event types can be bitwise or'd to register a callback for both pressed and released events. |
| callback | pointer to the callback function. This function is called from the interrupt handler. |
- Return values:
-
- See also:
- sb_button_unregisterListener
-
buttoncallback_t
Unregister a callback function for a button event.
- Parameters:
-
| btn | the id of the button |
| eve | the type of event that the callback function should be invoked for. event types can be bitwise or'd to register a callback for both pressed and released events. |
| callback | pointer to the callback function |
- Returns:
- 0 on success, negative value on error
- Return values:
-
| 0 | success |
| -1 | the callback function was not registered with the given button/event combination |
- See also:
- sb_button_registerListener