webradio/buttons.c-Dateireferenz


Ausführliche Beschreibung

Simple button interface.

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);

Zu beachten:
The macro USE_BUTTONS must be set to 1 to activate this code.
 * $Id$
 * 

Definiert in Datei buttons.c.

gehe zum Quellcode dieser Datei

Makrodefinitionen

#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.

Funktionen

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.

Variablen

static HANDLE btn_que
 Button event queue.
static volatile u_int btn_pressed
 Last button code.


Makro-Dokumentation

#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.

!

Definiert in Zeile 124 der Datei buttons.c.

Wird benutzt von ButtonInit().

#define BTN_PIO_ID   PIOB_ID

PIO ID of the button interface.

All buttons must be connected to the same PIO port.

Definiert in Zeile 125 der Datei buttons.c.

Wird benutzt von ButtonInit().

#define BTN_DOWN_BIT   24

PIO bit number of the button labeled DOWN.

This button is used to reduce the volume or move to the previous menu item.

If not specified, this button will not be available.

Definiert in Zeile 126 der Datei buttons.c.

#define BTN_SELECT_BIT   25

PIO bit number of the button labeled SELECT.

This button is used to enter menu mode or to select the currently displayed menu item.

If not specified, this button will not be available.

Definiert in Zeile 127 der Datei buttons.c.

#define BTN_UP_BIT   26

PIO bit number of the button labeled UP.

This button is used to increase the volume or move to the next menu item.

If not specified, this button will not be available.

Definiert in Zeile 128 der Datei buttons.c.

#define BTN_SCAN_FREQ   128UL

Number of button scans per second.

Definiert in Zeile 135 der Datei buttons.c.

Wird benutzt von ButtonInit().

#define BTN_REPEAT_FIRST   100

Number of scans until the first repeat is triggered.

Definiert in Zeile 142 der Datei buttons.c.

Wird benutzt von ScanTimerInterrupt().

#define BTN_REPEAT_NEXT   25

Number of scans until all following repeats are triggered.

Definiert in Zeile 149 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 174 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 175 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 176 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 177 der Datei buttons.c.

Wird benutzt von ButtonInit().

#define BTN_SELECT   _BV(BTN_SELECT_BIT)

PIO bit mask of the SELECT button.

Definiert in Zeile 197 der Datei buttons.c.

Wird benutzt von ButtonInit(), ButtonRead() und ScanTimerInterrupt().

#define BTN_UP   _BV(BTN_UP_BIT)

PIO bit mask of the UP button.

Definiert in Zeile 204 der Datei buttons.c.

Wird benutzt von ButtonInit(), ButtonRead() und ScanTimerInterrupt().

#define BTN_DOWN   _BV(BTN_DOWN_BIT)

PIO bit mask of the DOWN button.

Definiert in Zeile 211 der Datei buttons.c.

Wird benutzt von ButtonInit(), ButtonRead() und 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.

Definiert in Zeile 254 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 255 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 256 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 257 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 258 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 259 der Datei buttons.c.

Wird benutzt von 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.

Definiert in Zeile 260 der Datei buttons.c.

Wird benutzt von ButtonInit().


Dokumentation der Funktionen

static void ScanTimerInterrupt ( void *  arg  )  [static]

Button scan timer interrupt handler.

Definiert in Zeile 292 der Datei buttons.c.

Benutzt BTN_DOWN, BTN_PIO_PDS_REG, btn_pressed, btn_que, BTN_REPEAT_FIRST, BTN_REPEAT_NEXT, BTN_SELECT und BTN_UP.

Wird benutzt von 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.

Definiert in Zeile 336 der Datei buttons.c.

Wird benutzt von 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.

Parameter:
tmo Maximum number of milliseconds to wait.
Rückgabe:
Key code of the button, either KEYCODE_SELECT, KEYCODE_DOWN or KEYCODE_UP. If no button had been pressed within the given time, then zero is returned.

Definiert in Zeile 394 der Datei buttons.c.

Wird benutzt von UserIfMainMenu() und UserIfThread().


Variablen-Dokumentation

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.

Definiert in Zeile 278 der Datei buttons.c.

Wird benutzt von ButtonRead() und 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.

Definiert in Zeile 286 der Datei buttons.c.

Wird benutzt von ButtonRead() und ScanTimerInterrupt().


© 2008 by egnite GmbH - besuchen Sie www.ethernut.de