fremoclock  1_3A01
FREMO Clock - Software for UTG
PushButton.c File Reference

Push button debouncing module for Atmel AVR. More...

Go to the source code of this file.

Macros

#define BUTTON_PRESSED   0
 Button pressed. More...
 
#define BUTTON_REPEAT   1
 Button autorepeat. More...
 
#define BUTTON_SERVED   7
 Button handled. More...
 

Enumerations

enum  button_t {
  BUTTON_ENTER = 0, BUTTON_BACK = 1, BUTTON_UP = 2, BUTTON_DOWN = 3,
  NUM_BUTTONS = 4
}
 Enum for buttons used. More...
 

Functions

static bool PushButtonSingleShotAction (button_t ucButton)
 Test if button is pressed. More...
 
void PushButtonInit (void)
 Initialization of module. More...
 
static uint8_t PushButtonReadStatus (button_t buttonIdx)
 Read status bits for the button. More...
 
static void PushButtonSetStatusServed (button_t ucButton)
 Set that button has already been handled. More...
 
bool PushButtonSingleShotEnter (void)
 Test if button enter is pressed. More...
 
bool PushButtonSingleShotBack (void)
 Test if button back is pressed. More...
 
bool PushButtonSingleShotUp (void)
 Test if button up is pressed. More...
 
bool PushButtonSingleShotDown (void)
 Test if button down is pressed. More...
 
uint8_t PushButtonGetUpDownValue (uint8_t ucbut, uint8_t ucmin, uint8_t ucmax)
 Get selection value by up and down button. More...
 
static void PushButtonPressed (button_t ucButton)
 Used by PushButtonInterrupt during interrupt service when button is down. More...
 
static void PushButtonRelease (button_t ucButton)
 Used by PushButtonInterrupt during interrupt service when button is up. More...
 
void PushButtonInterrupt (void)
 Called by timer interrupt every 10ms. More...
 

Variables

static const uint16_t BUTTON_PRESSED_VALUE = 5
 time in 10ms for button recognized as pressed More...
 
static const uint16_t BUTTON_REPEAT_VALUE = 50
 time in 10ms for button recognized as repeated More...
 
static const uint16_t UP_DOWN_WAIT = 250
 Value to wait in milliseconds. More...
 
static volatile uint16_t uiButtonDebounce [NUM_BUTTONS]
 Incremented every 10 mS as long as button is pushed. More...
 
static volatile uint8_t ucButtonStatus [NUM_BUTTONS]
 Status of the Buttons. More...
 

Detailed Description

Push button debouncing module for Atmel AVR.

Supplies debouncing for push buttons incl. autorepeat.

History:

  • 2007-02-25 ba: First implementation.
  • 2015-04-24 StS: Remove unnecessary whitespace and change to unified format
  • 2015-04-28 StS: Add Single Shot Actions (Enter, Back,...)
  • 2016-08-17 Pi: localize, bool, uint8_t, uint16_t, button_t const instead of #define where possible
Version
$Id: PushButton.c 159 2016-09-03 06:51:47Z pischky $
Author
Bernd Wisotzki

Definition in file PushButton.c.

Macro Definition Documentation

#define BUTTON_PRESSED   0

Button pressed.

Definition at line 61 of file PushButton.c.

#define BUTTON_REPEAT   1

Button autorepeat.

Definition at line 64 of file PushButton.c.

#define BUTTON_SERVED   7

Button handled.

Definition at line 67 of file PushButton.c.

Enumeration Type Documentation

enum button_t

Enum for buttons used.

Used as indices in arrays uiButtonDebounce and ucButtonStatus.

Enumerator
BUTTON_ENTER 

"ENTER" button

BUTTON_BACK 

"BACK" button (left arrow)

BUTTON_UP 

"UP" button (up arrow)

BUTTON_DOWN 

"DOWN" button (down arrow)

NUM_BUTTONS 

Number of push buttons (used for array size)

Definition at line 37 of file PushButton.c.

Function Documentation

uint8_t PushButtonGetUpDownValue ( uint8_t  ucbut,
uint8_t  ucmin,
uint8_t  ucmax 
)

Get selection value by up and down button.

Parameters
ucbutcurrent value
ucminminimal allowed value
ucmaxamximal allowd value
Returns
the selected value (between ucmin and ucmax)

Definition at line 217 of file PushButton.c.

Here is the call graph for this function:

void PushButtonInit ( void  )

Initialization of module.

Call once in main after start.

Definition at line 92 of file PushButton.c.

void PushButtonInterrupt ( void  )

Called by timer interrupt every 10ms.

Runs with global interrupts disabled. Read the ports used by push buttons and increment uiButtonDebounce when pressed. Update ucButtonStatus when uiButtonDebounce reaches BUTTON_PRESSED_VALUE or BUTTON_REPEAT_VALUE.

Definition at line 292 of file PushButton.c.

Here is the call graph for this function:

static void PushButtonPressed ( button_t  ucButton)
inlinestatic

Used by PushButtonInterrupt during interrupt service when button is down.

Runs with global interrupts disabled.

Definition at line 261 of file PushButton.c.

static uint8_t PushButtonReadStatus ( button_t  buttonIdx)
static

Read status bits for the button.

The read is done with interrupts disabled.

Parameters
buttonIdxthe button (BUTTON_ENTER, BUTTON_BACK, BUTTON_UP, ...)
Returns
the current status

Definition at line 116 of file PushButton.c.

static void PushButtonRelease ( button_t  ucButton)
inlinestatic

Used by PushButtonInterrupt during interrupt service when button is up.

Runs with global interrupts disabled.

Definition at line 278 of file PushButton.c.

static void PushButtonSetStatusServed ( button_t  ucButton)
static

Set that button has already been handled.

Sets BUTTON_SERVED bit in ucButtonStatus. This is done with interrupts disabled.

Definition at line 130 of file PushButton.c.

static bool PushButtonSingleShotAction ( button_t  ucButton)
static

Test if button is pressed.

Parameters
ucButtonthe button (BUTTON_ENTER, BUTTON_BACK, BUTTON_UP, ...)
Returns
  • true - button was pressed
  • false - button was not pressed

Definition at line 192 of file PushButton.c.

Here is the call graph for this function:

bool PushButtonSingleShotBack ( void  )

Test if button back is pressed.

Returns
  • true - button was pressed
  • false - button was not pressed

Definition at line 158 of file PushButton.c.

Here is the call graph for this function:

bool PushButtonSingleShotDown ( void  )

Test if button down is pressed.

Returns
  • true - button was pressed
  • false - button was not pressed

Definition at line 180 of file PushButton.c.

Here is the call graph for this function:

bool PushButtonSingleShotEnter ( void  )

Test if button enter is pressed.

Returns
  • true - button was pressed
  • false - button was not pressed

Definition at line 147 of file PushButton.c.

Here is the call graph for this function:

bool PushButtonSingleShotUp ( void  )

Test if button up is pressed.

Returns
  • true - button was pressed
  • false - button was not pressed

Definition at line 169 of file PushButton.c.

Here is the call graph for this function:

Variable Documentation

const uint16_t BUTTON_PRESSED_VALUE = 5
static

time in 10ms for button recognized as pressed

Definition at line 46 of file PushButton.c.

const uint16_t BUTTON_REPEAT_VALUE = 50
static

time in 10ms for button recognized as repeated

Definition at line 49 of file PushButton.c.

volatile uint8_t ucButtonStatus[NUM_BUTTONS]
static

Status of the Buttons.

Used as set (bit array) of BUTTON_PRESSED, BUTTON_REPEAT, BUTTON_SERVED. Accessed by PushButtonInterrupt, PushButtonReadStatus and PushButtonSetStatusServed.

Definition at line 83 of file PushButton.c.

volatile uint16_t uiButtonDebounce[NUM_BUTTONS]
static

Incremented every 10 mS as long as button is pushed.

Only used in PushButtonInterrupt()

Definition at line 75 of file PushButton.c.

const uint16_t UP_DOWN_WAIT = 250
static

Value to wait in milliseconds.

Definition at line 52 of file PushButton.c.