EVE 1.0
Keypad driver
Collaboration diagram for Keypad driver:

Data Structures

struct  key_repeat_t
 The structure defines key repeat parameters. More...
 
struct  key_combi_t
 The structure defines combi key parameters. Note that it is possible to define individual debounce time for each group. Thus it is also the way to define an individual key with debouncing which differs from default KEY_PRELL_TIME : just define a "group of 1 key. More...
 

Enumerations

Functions called from application programs

void StartKeyScan (void)
 Start Keys scanning. More...
 
void KeyInterruptCb (void)
 This callback function must be called when a key interrupt is received by the platform. More...
 
void KeyDebounceTimeSet (uint16_t Time)
 Sets key debounce time. Default time is KEY_PRELL_TIME. More...
 
bool KeyStatusGet (uint8_t KeyIndex)
 Returns status of debounced key. More...
 

Application' keypad configuration and supplied functions.

The following is the keypad driver setup for application's board.h and board.c files.

struct key_repeat_t ConfigKeyRepeat [NUMBER_OF_REPEAT_KEYS]
 User defined array of key_repeat_t structures defines key repeat parameters.
 
struct key_combi_t ConfigKeyCombi [NUMBER_OF_COMBI_GROUPS]
 User defined array of key_combi_t structures defines combi key groups parameters.
 
static __inline uint32_t ReadKeyInput (void)
 Application supplied board-specific callback function for reading key inputs. More...
 
void KeyInterruptEnable (bool Enable)
 Application supplied board-specific callback function to enable or disable HW interrupts for all keys. More...
 
#define KEY_ENABLED   true/false
 
#define KEYS_HAVE_NO_INTERRUPT   true/false
 
#define REPEAT_KEY_ENABLED   true/false
 
#define REPEAT_KEY_STEP2_ENABLED   true/false
 
#define COMBI_KEYS_ENABLED   true/false
 
#define COMBI_KEY_RELEASE_ENABLED   true/false
 
#define NUMBER_OF_KEYS   <N>
 
#define NUMBER_OF_REPEAT_KEYS   <N>
 
#define NUMBER_OF_COMBI_GROUPS   <N>
 
#define KEY_SIGNAL_RECEIVER   <struct process *p>
 
#define SCAN_KEY_INTERVAL   <T>
 
#define KEY_PRELL_TIME   <T>
 

Detailed Description

This driver supports key debounce functionality if KEY_ENABLED is set true. The function KeyInterruptEnable() must be called to enables interrupts for all keys.

The number of scanned keys is given by NUMBER_OF_KEYS. Key debounce time is given by KEY_PRELL_TIME. When debouncing the interval is given by SCAN_KEY_INTERVAL. The keys are read by the inline function ReadKeyInput().

The following events are sent:

It is possible to send a repeated event when a key has been pressed for a given time. The event can be repeated at a given interval. This functionality is enabled if REPEAT_KEY_ENABLED is set true: The number of repeated keys is given by NUMBER_OF_REPEAT_KEYS. Repeat function is configured in table "struct key_repeat_t ConfigKeyRepeat[]" in Board.c The following events are sent:

It is possible to send a event when a combination of one or more keys have been pressed for a given time. This functionality is enabled if COMBI_KEYS_ENABLED is set true: The number of combi keys groups is given by NUMBER_OF_COMBI_GROUPS. Combi function is configured in table "struct key_combi_t ConfigKeyCombi[]" in Board.c The following events are sent:

All events are sent to process defined by KEY_SIGNAL_RECEIVER

Enumeration Type Documentation

Event numbers being sent to the application process. Event's void *data field contains key number.

Enumerator
KEY_PRESSED 

Key was pressed.

KEY_RELEASED 

Key was released.

KEY_REPEAT1 

Key press repeat after Step1Time.

KEY_REPEAT2 

Key press repeat after Step2Time.

COMBI_KEY_PRESSED 

Key combination was pressed.

COMBI_KEY_RELEASED 

Key combination was released.

EVENT_KEY__LAST 

Gives the size of allocated event numbers.

Definition at line 118 of file key.h.

Function Documentation

void StartKeyScan ( void  )

Start Keys scanning.

Only used if KEYS_HAVE_NO_INTERRUPT = true

void KeyInterruptCb ( void  )

This callback function must be called when a key interrupt is received by the platform.

Only used if KEYS_HAVE_NO_INTERRUPT == false

void KeyDebounceTimeSet ( uint16_t  Time)

Sets key debounce time. Default time is KEY_PRELL_TIME.

Parameters
TimeNew debounce time in ms
bool KeyStatusGet ( uint8_t  KeyIndex)

Returns status of debounced key.

Parameters
KeyIndexkey number from 0 to (NUMBER_OF_KEYS - 1)
Returns
true if key pressed, else false
static __inline uint32_t ReadKeyInput ( void  )
static

Application supplied board-specific callback function for reading key inputs.

The driver calls this function in order to get current keys status. It is an application responsibility to map actual internal GPIO or GPIO extender port pins to an int32_t array of bits used as key status in the driver.

Example for 2 inverted keys (pressing connects to ground) supporting press/release event generation:

1 #define KEY0 0
2 #define KEY1 1
3 uint32_t LastReadKeyInput;
4 static __inline uint32_t ReadKeyInput(void)
5 {
6  uint32_t KeyInput, KeyData;
7  LastReadKeyInput = KeyInput = ~GpioPortGet(); // Pins are inverted!
8  KeyData = ((KeyInput >> KEY0_PIN_NUMBERn) & 1) << KEY0;
9  KeyData |= ((KeyInput >> KEY1_PIN_NUMBERn) & 1) << KEY1;
10  return KeyData;
11 }
Returns
Keys bitmask. Each bit represents a key and settled if the key is currently pressed, cleared if released.
void KeyInterruptEnable ( bool  Enable)

Application supplied board-specific callback function to enable or disable HW interrupts for all keys.

This function must be called by application to enable interrupts in interrupt mode (KEYS_HAVE_NO_INTERRUPT == false) before the driver starts to work.

While working the driver uses the function. When a key is pressed/released, the key interrupt will disable further key interrupts, and starts the key debounce scheduler. The interrupts will be re-enabled again when the scheduler is not active.

Only used if KEYS_HAVE_NO_INTERRUPT = false.

Example for 2 inverted keys (pressing connects to ground) supporting press/release event generation:

1 uint32_t LastReadKeyInput;
2 void KeyInterruptEnable(bool Enable)
3 {
4  enum irq_mode_t NewMode;
5  NewMode = (LastReadKeyInput & (1 << KEY0_PIN_NUMBERn)) ? IRQ_MODE_RISING : IRQ_MODE_FALLING;
6  IrqEnableInternal(KEY0_PIN_NUMBERn, Enable ? NewMode : IRQ_MODE_DISABLED);
7  NewMode = (LastReadKeyInput & (1 << KEY1_PIN_NUMBERn)) ? IRQ_MODE_RISING : IRQ_MODE_FALLING;
8  IrqEnableInternal(KEY1_PIN_NUMBERn, Enable ? NewMode : IRQ_MODE_DISABLED);
9 }
Parameters
Enabletrue to enable interrupts, false to disable interrupts