Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

buttons.h File Reference


Detailed Description

Simple button interface header.

 *
 * $Log$
 *
 * 

Definition in file buttons.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define KEYCODE_UP   'U'
 Key code of the UP button.
#define KEYCODE_DOWN   'D'
 Key code of the DOWN button.
#define KEYCODE_SELECT   'S'
 Key code of the SELECT button.

Functions

void ButtonInit (void)
 Initialize the button interface.
char ButtonRead (u_long tmo)
 Wait until the user pressed a button.


Define Documentation

#define KEYCODE_UP   'U'
 

Key code of the UP button.

This code is returned by ButtonRead(), if the user presses the right button on the Calypso Board.

Definition at line 54 of file buttons.h.

#define KEYCODE_DOWN   'D'
 

Key code of the DOWN button.

This code is returned by ButtonRead(), if the user presses the left button on the Calypso Board.

Definition at line 62 of file buttons.h.

#define KEYCODE_SELECT   'S'
 

Key code of the SELECT button.

This code is returned by ButtonRead(), if the user presses the middle button on the Calypso Board.

Definition at line 70 of file buttons.h.


Function Documentation

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 313 of file buttons.c.

00315 {
00316     int dummy;
00317 
00318     /* Enable scan timer clock. */
00319     outr(PMC_PCER, _BV(BTN_TC_ID) | _BV(BTN_PIO_ID));
00320     /* Disable the Clock Counter */
00321     outr(BTN_TC_CC_REG, TC_CLKDIS);
00322     /* Disable all interrupts */
00323     outr(BTN_TC_ID_REG, 0xFFFFFFFF);
00324     /* Clear the status register. */
00325     dummy = inr(BTN_TC_S_REG);
00326     /* Select divider and compare trigger */
00327     outr(BTN_TC_CM_REG, TC_CLKS_MCK32 | TC_CPCTRG);
00328     /* Enable the Clock counter */
00329     outr(BTN_TC_CC_REG, TC_CLKEN);
00330     /* Validate the RC compare interrupt */
00331     outr(BTN_TC_IE_REG, TC_CPCS);
00332 
00333     /* Register timer interrupt handler. */
00334     NutRegisterIrqHandler(&sig_BTN_TC, ScanTimerInterrupt, 0);
00335     /* Set to lowest priority. */
00336     NutIrqSetPriority(&sig_BTN_TC, 0);
00337 
00338     /* Enable timer interrupts */
00339     NutIrqEnable(&sig_BTN_TC);
00340 
00341     /* Set compare value for specified scan frequency. */
00342 #if defined(AT91_PLL_MAINCK)
00343     outr(BTN_TC_RC_REG, At91GetMasterClock() / (32 * BTN_SCAN_FREQ));
00344 #else
00345     outr(BTN_TC_RC_REG, NutGetCpuClock() / (32 * BTN_SCAN_FREQ));
00346 #endif
00347 
00348     /* Initialize GPIO lines for buttons. */
00349     outr(BTN_PIO_PE_REG, BTN_SELECT | BTN_UP | BTN_DOWN);
00350     outr(BTN_PIO_OD_REG, BTN_SELECT | BTN_UP | BTN_DOWN);
00351     outr(BTN_PIO_PUE_REG, BTN_SELECT | BTN_UP | BTN_DOWN);
00352 
00353     /* Software trigger starts the scan timer. */
00354     outr(BTN_TC_CC_REG, TC_SWTRG);

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.

Parameters:
tmo Maximum number of milliseconds to wait.
Returns:
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.

Definition at line 369 of file buttons.c.

00371 {
00372     /* Wait for a button event from the interrupt handler. */
00373     if (NutEventWait(&btn_que, tmo) == 0) {
00374         /* Copy the volatile value to a local variable. */
00375         u_int pressed = btn_pressed;
00376 
00377         if (pressed & BTN_SELECT) {
00378             return KEYCODE_SELECT;
00379         }
00380         if (pressed & BTN_DOWN) {
00381             return KEYCODE_DOWN;
00382         }
00383         if (pressed & BTN_UP) {
00384             return KEYCODE_UP;
00385         }
00386     }
00387     return 0;


Generated on Fri Feb 23 17:28:50 2007 for SAM Internet Radio by  doxygen 1.4.4