Handles 3 toggle switches connected to 3 dedicated GPIO lines. It is expected, that the port pin is driven low when the related button is pressed. Auto repeat is supported.
The following code sample shows how to use the button interface.
#include "buttons.h" char key; ButtonInit(); key = ButtonRead(500);
* $Id$ *
Definition in file buttons.c.
Go to the source code of this file.
Defines | |
#define | BTN_TC_ID TC1_ID |
Button scan timer ID. | |
#define | BTN_PIO_ID PIOB_ID |
PIO ID of the button interface. | |
#define | BTN_DOWN_BIT 24 |
PIO bit number of the button labeled DOWN. | |
#define | BTN_SELECT_BIT 25 |
PIO bit number of the button labeled SELECT. | |
#define | BTN_UP_BIT 26 |
PIO bit number of the button labeled UP. | |
#define | BTN_SCAN_FREQ 128UL |
Number of button scans per second. | |
#define | BTN_REPEAT_FIRST 100 |
Number of scans until the first repeat is triggered. | |
#define | BTN_REPEAT_NEXT 25 |
Number of scans until all following repeats are triggered. | |
#define | BTN_PIO_PE_REG PIOB_PER |
PIO enable register of the button interface. | |
#define | BTN_PIO_OD_REG PIOB_ODR |
PIO output disable register of the button interface. | |
#define | BTN_PIO_PDS_REG PIOB_PDSR |
Pin data status register of the button interface. | |
#define | BTN_PIO_PUE_REG PIOB_PUER |
Pull-up enable register of the button interface. | |
#define | BTN_SELECT _BV(BTN_SELECT_BIT) |
PIO bit mask of the SELECT button. | |
#define | BTN_UP _BV(BTN_UP_BIT) |
PIO bit mask of the UP button. | |
#define | BTN_DOWN _BV(BTN_DOWN_BIT) |
PIO bit mask of the DOWN button. | |
#define | sig_BTN_TC sig_TC1 |
Interrupt signal of the button scan timer. | |
#define | BTN_TC_CC_REG TC1_CCR |
Channel control register of the button scan timer. | |
#define | BTN_TC_CM_REG TC1_CMR |
Channel mode register of the button scan timer. | |
#define | BTN_TC_IE_REG TC1_IER |
Interrupt enable register of the button scan timer. | |
#define | BTN_TC_ID_REG TC1_IDR |
Interrupt disable register of the button scan timer. | |
#define | BTN_TC_S_REG TC1_SR |
Status register of the button scan timer. | |
#define | BTN_TC_RC_REG TC1_RC |
Register C of the button scan timer. | |
Functions | |
static void | ScanTimerInterrupt (void *arg) |
Button scan timer interrupt handler. | |
void | ButtonInit (void) |
Initialize the button interface. | |
char | ButtonRead (u_long tmo) |
Wait until the user pressed a button. | |
Variables | |
static HANDLE | btn_que |
Button event queue. | |
static volatile u_int | btn_pressed |
Last button code. |
#define BTN_TC_ID TC1_ID |
Button scan timer ID.
Specifies the timer/counter that will be used to generate periodical interrupts for scanning the buttons.
!
Definition at line 124 of file buttons.c.
Referenced by ButtonInit().
#define BTN_PIO_ID PIOB_ID |
PIO ID of the button interface.
All buttons must be connected to the same PIO port.
Definition at line 125 of file buttons.c.
Referenced by ButtonInit().
#define BTN_DOWN_BIT 24 |
#define BTN_SELECT_BIT 25 |
#define BTN_UP_BIT 26 |
#define BTN_SCAN_FREQ 128UL |
Number of button scans per second.
Definition at line 135 of file buttons.c.
Referenced by ButtonInit().
#define BTN_REPEAT_FIRST 100 |
Number of scans until the first repeat is triggered.
Definition at line 142 of file buttons.c.
Referenced by ScanTimerInterrupt().
#define BTN_REPEAT_NEXT 25 |
Number of scans until all following repeats are triggered.
Definition at line 149 of file buttons.c.
Referenced by ScanTimerInterrupt().
#define BTN_PIO_PE_REG PIOB_PER |
PIO enable register of the button interface.
The compiler evaluates BTN_PIO_ID to determine this register.
Definition at line 174 of file buttons.c.
Referenced by ButtonInit().
#define BTN_PIO_OD_REG PIOB_ODR |
PIO output disable register of the button interface.
The compiler evaluates BTN_PIO_ID to determine this register.
Definition at line 175 of file buttons.c.
Referenced by ButtonInit().
#define BTN_PIO_PDS_REG PIOB_PDSR |
Pin data status register of the button interface.
The compiler evaluates BTN_PIO_ID to determine this register.
Definition at line 176 of file buttons.c.
Referenced by ScanTimerInterrupt().
#define BTN_PIO_PUE_REG PIOB_PUER |
Pull-up enable register of the button interface.
The compiler evaluates BTN_PIO_ID to determine this register.
Definition at line 177 of file buttons.c.
Referenced by ButtonInit().
#define BTN_SELECT _BV(BTN_SELECT_BIT) |
PIO bit mask of the SELECT button.
Definition at line 197 of file buttons.c.
Referenced by ButtonInit(), ButtonRead(), and ScanTimerInterrupt().
#define BTN_UP _BV(BTN_UP_BIT) |
PIO bit mask of the UP button.
Definition at line 204 of file buttons.c.
Referenced by ButtonInit(), ButtonRead(), and ScanTimerInterrupt().
#define BTN_DOWN _BV(BTN_DOWN_BIT) |
PIO bit mask of the DOWN button.
Definition at line 211 of file buttons.c.
Referenced by ButtonInit(), ButtonRead(), and ScanTimerInterrupt().
#define sig_BTN_TC sig_TC1 |
Interrupt signal of the button scan timer.
The compiler evaluates BTN_TC_ID to determine the Nut/OS interrupt signal.
Definition at line 254 of file buttons.c.
Referenced by ButtonInit().
#define BTN_TC_CC_REG TC1_CCR |
Channel control register of the button scan timer.
The compiler evaluates BTN_TC_ID to determine this register.
Definition at line 255 of file buttons.c.
Referenced by ButtonInit().
#define BTN_TC_CM_REG TC1_CMR |
Channel mode register of the button scan timer.
The compiler evaluates BTN_TC_ID to determine this register.
Definition at line 256 of file buttons.c.
Referenced by ButtonInit().
#define BTN_TC_IE_REG TC1_IER |
Interrupt enable register of the button scan timer.
The compiler evaluates BTN_TC_ID to determine this register.
Definition at line 257 of file buttons.c.
Referenced by ButtonInit().
#define BTN_TC_ID_REG TC1_IDR |
Interrupt disable register of the button scan timer.
The compiler evaluates BTN_TC_ID to determine this register.
Definition at line 258 of file buttons.c.
Referenced by ButtonInit().
#define BTN_TC_S_REG TC1_SR |
Status register of the button scan timer.
The compiler evaluates BTN_TC_ID to determine this register.
Definition at line 259 of file buttons.c.
Referenced by ButtonInit().
#define BTN_TC_RC_REG TC1_RC |
Register C of the button scan timer.
The compiler evaluates BTN_TC_ID to determine this register.
Definition at line 260 of file buttons.c.
Referenced by ButtonInit().
static void ScanTimerInterrupt | ( | void * | arg | ) | [static] |
Button scan timer interrupt handler.
Definition at line 292 of file buttons.c.
References BTN_DOWN, BTN_PIO_PDS_REG, btn_pressed, btn_que, BTN_REPEAT_FIRST, BTN_REPEAT_NEXT, BTN_SELECT, and BTN_UP.
Referenced by ButtonInit().
void ButtonInit | ( | void | ) |
Initialize the button interface.
Configures and starts a continously running timer interrupt, which scans three GPIO lines. A low level on any line indicates, that the related button has been pressed by the user.
The application must call ButtonRead() to read the code of a pressed button.
Definition at line 336 of file buttons.c.
Referenced by UserIfInit().
char ButtonRead | ( | u_long | tmo | ) |
Wait until the user pressed a button.
This routine will not handle concurrently pressed buttons, but return the button with the highest priority. SELECT has the highest and UP has the lowest priority.
tmo | Maximum number of milliseconds to wait. |
Definition at line 394 of file buttons.c.
Referenced by UserIfMainMenu(), and UserIfThread().
HANDLE btn_que [static] |
Button event queue.
The button scan timer interrupt handler will post an event to this queue whenever a new button had been pressed or the repeat timer elapses with a button still pressed.
Definition at line 278 of file buttons.c.
Referenced by ButtonRead(), and ScanTimerInterrupt().
volatile u_int btn_pressed [static] |
Last button code.
For each button that had been pressed during the last scan interrupt, the related bit BTN_SELECT, BTN_DOWN or BTN_UP is set.
Definition at line 286 of file buttons.c.
Referenced by ButtonRead(), and ScanTimerInterrupt().