00001 #ifndef BUTTON_H00002 #define BUTTON_H00003
00004 #include <stdint.h>00005
00006
00007 /** 00008
00009 *00010 * \addtogroup Button00011 *00012 * \brief The button module enables event-driven and polling access00013 * to the buttons of the SPiCboard.00014 *00015 * The SPiCboard is equipped with two buttons. Button 0 is debounced in00016 * hardware, whereas Button 1 needs to be debounced in software by the00017 * button module. Debouncing is transparent to the application, that00018 * can use both buttons through the provided interface without the00019 * need to care about debouncing.00020 *00021 * The debouncing code makes use of the timer module. When no listeners00022 * are registered for Button 1, the debouncing code is disabled and all00023 * alarms registered at the timer should be canceled.00024 *00025 * The button module uses dynamic memory management to maintain the00026 * listener queues.00027 * 00028 * @{00029 * \file button.h00030 * \version \$Rev: 4311 $00031 */00032
00033 /**00034 * \brief Identifiers for all available buttons.00035 *00036 */00037typedefenum {
00038BUTTON0 = 4, /**< Button 0 */00039BUTTON1 = 8 /**< Button 1 */00040 } BUTTON;
00041
00042 /**00043 * \brief Events for buttons.00044 *00045 * Pressed and released events for buttons. 00046 */00047typedefenum {
00048BTNPRESSED = 1, /**< Button was pressed */00049BTNRELEASED = 2 /**< Button was released */00050 } BUTTONEVENT;
00051
00052 /**00053 * \brief Type for button event callback functions.00054 *00055 * A button callback function is called on the interrupt level whenever00056 * an event at a button occurs that the function was registered for.00057 * The callback function is passed the button id and the type of event00058 * that occurred. This way, the same callback function can be registered00059 * for different buttons and events.00060 */00061typedef void (*buttoncallback_t) (BUTTON, BUTTONEVENT);
00062
00063 /**00064 * \brief Register a callback function for a button event.00065 *00066 * \param btn the id of the button00067 * \param eve the type of event that the callback function should be invoked for.00068 * event types can be bitwise or'd to register a callback for both00069 * pressed and released events.00070 * \param callback pointer to the callback function. This function is called from the00071 * interrupt handler.00072 * \retval 0 success,00073 * \retval !0 error00074 * \sa sb_button_unregisterListener 00075 * \sa buttoncallback_t00076 */00077 int8_t sb_button_registerListener(BUTTON btn, BUTTONEVENT eve, buttoncallback_t callback);
00078
00079 /**00080 * \brief Unregister a callback function for a button event.00081 *00082 *00083 * \param btn the id of the button00084 * \param eve the type of event that the callback function should be invoked for.00085 * event types can be bitwise or'd to register a callback for both00086 * pressed and released events.00087 * \param callback pointer to the callback function00088 * \return 0 on success, negative value on error00089 * \retval 0 success00090 * \retval -1 the callback function was not registered with the given button/event combination00091 * \sa sb_button_registerListener00092 *00093 */00094 int8_t sb_button_unregisterListener(BUTTON btn, BUTTONEVENT eve, buttoncallback_t callback);
00095
00096 /**00097 * \brief Query the current state of a button.00098 *00099 * \param btn id of the button00100 * \return The buttons current state (pressed or released) as a \ref BUTTONEVENT00101 */00102 BUTTONEVENTsb_button_getState(BUTTON btn);
00103
00104 /** @}*/00105
00106 #endif00107