Defines | Typedefs | Enumerations | Functions

keys.h File Reference

Key Scan and alphanumeric input machine header file. More...

#include <avr/pgmspace.h>
#include "xpal_disp_areas.h"

Go to the source code of this file.

Defines

#define HL_NOKEY   0
 Empty KEYCODE.
#define HL_KEY_PRESSED   0xFFFF
 Key has been processed.
#define BLD_SC(col, row, row_abc)   ((_BV(col)<<8) | (_BV(row_abc)<<8) | _BV(row))
 

#define HL_SCAN_SOFT1   BLD_SC(HL_KEY_COL0,HL_KEY_ROW0,HL_KEY_ROW_A_ID)
 Display SOFT1 - up left.
#define HL_SCAN_SOFT2   BLD_SC(HL_KEY_COL0,HL_KEY_ROW1,HL_KEY_ROW_A_ID)
 Display SOFT2.
#define HL_SCAN_SOFT3   BLD_SC(HL_KEY_COL0,HL_KEY_ROW2,HL_KEY_ROW_A_ID)
 Display SOFT3 - bottom left.
#define HL_SCAN_SOFT4   BLD_SC(HL_KEY_COL0,HL_KEY_ROW3,HL_KEY_ROW_A_ID)
 Display SOFT4 - below left.
#define HL_SCAN_SOFT5   BLD_SC(HL_KEY_COL0,HL_KEY_ROW4,HL_KEY_ROW_B_ID)
 Display SOFT5.
#define HL_SCAN_SOFT6   BLD_SC(HL_KEY_COL0,HL_KEY_ROW5,HL_KEY_ROW_B_ID)
 Display SOFT6.
#define HL_SCAN_SOFT7   BLD_SC(HL_KEY_COL0,HL_KEY_ROW6,HL_KEY_ROW_B_ID)
 Display SOFT7.
#define HL_SCAN_SOFT8   BLD_SC(HL_KEY_COL0,HL_KEY_ROW7,HL_KEY_ROW_B_ID)
 Display SOFT8 - below right.
#define HL_SCAN_SOFT9   BLD_SC(HL_KEY_COL0,HL_KEY_ROW8,HL_KEY_ROW_B_ID)
 Display SOFT9 - up right.
#define HL_SCAN_SOFT10   BLD_SC(HL_KEY_COL0,HL_KEY_ROW9,HL_KEY_ROW_B_ID)
 Display SOFT10.
#define HL_SCAN_SOFT11   BLD_SC(HL_KEY_COL0,HL_KEY_ROW10,HL_KEY_ROW_B_ID)
 Display SOFT11 - bottom right
.
#define HL_SCAN_LEFT_II   BLD_SC(HL_KEY_COL2,HL_KEY_ROW0,HL_KEY_ROW_A_ID)
 Left Thumb - II.
#define HL_SCAN_LEFT_I   BLD_SC(HL_KEY_COL2,HL_KEY_ROW1,HL_KEY_ROW_A_ID)
 Left Thumb - I.
#define HL_SCAN_LEFT_ESC   BLD_SC(HL_KEY_COL2,HL_KEY_ROW2,HL_KEY_ROW_A_ID)
 Left Thumb - ESC.
#define HL_SCAN_LEFT_OK   BLD_SC(HL_KEY_COL2,HL_KEY_ROW3,HL_KEY_ROW_A_ID)
 Left Thumb - OK.
#define HL_SCAN_RIGHT_II   BLD_SC(HL_KEY_COL2,HL_KEY_ROW4,HL_KEY_ROW_B_ID)
 Right Thumb - II.
#define HL_SCAN_RIGHT_I   BLD_SC(HL_KEY_COL2,HL_KEY_ROW5,HL_KEY_ROW_B_ID)
 Right Thumb - I.
#define HL_SCAN_RIGHT_ESC   BLD_SC(HL_KEY_COL2,HL_KEY_ROW6,HL_KEY_ROW_B_ID)
 Right Thumb - ESC.
#define HL_SCAN_RIGHT_OK   BLD_SC(HL_KEY_COL2,HL_KEY_ROW7,HL_KEY_ROW_B_ID)
 Right Thumb - OK
.
#define HL_SCAN_NUM0   BLD_SC(HL_KEY_COL1,HL_KEY_ROW0,HL_KEY_ROW_A_ID)
 Number Area 0 - bottom center.
#define HL_SCAN_NUM1   BLD_SC(HL_KEY_COL1,HL_KEY_ROW1,HL_KEY_ROW_A_ID)
 Number Area 1.
#define HL_SCAN_NUM2   BLD_SC(HL_KEY_COL1,HL_KEY_ROW2,HL_KEY_ROW_A_ID)
 Number Area 2.
#define HL_SCAN_NUM3   BLD_SC(HL_KEY_COL1,HL_KEY_ROW3,HL_KEY_ROW_A_ID)
 Number Area 3.
#define HL_SCAN_NUM4   BLD_SC(HL_KEY_COL1,HL_KEY_ROW4,HL_KEY_ROW_B_ID)
 Number Area 4.
#define HL_SCAN_NUM5   BLD_SC(HL_KEY_COL1,HL_KEY_ROW5,HL_KEY_ROW_B_ID)
 Number Area 5.
#define HL_SCAN_NUM6   BLD_SC(HL_KEY_COL1,HL_KEY_ROW6,HL_KEY_ROW_B_ID)
 Number Area 6.
#define HL_SCAN_NUM7   BLD_SC(HL_KEY_COL1,HL_KEY_ROW7,HL_KEY_ROW_B_ID)
 Number Area 7.
#define HL_SCAN_NUM8   BLD_SC(HL_KEY_COL1,HL_KEY_ROW8,HL_KEY_ROW_B_ID)
 Number Area 8.
#define HL_SCAN_NUM9   BLD_SC(HL_KEY_COL1,HL_KEY_ROW9,HL_KEY_ROW_B_ID)
 Number Area 9.
#define HL_SCAN_STAR   BLD_SC(HL_KEY_COL1,HL_KEY_ROW10,HL_KEY_ROW_B_ID)
 Number Area *.
#define HL_SCAN_POUND   BLD_SC(HL_KEY_COL1,HL_KEY_ROW11,HL_KEY_ROW_B_ID)
 Number Area #
.
#define HL_SCAN_POWER   BLD_SC(HL_KEY_COL3,HL_KEY_ROW0,HL_KEY_ROW_A_ID)
 Power Key.
#define HL_KEYSTATE_SAME   0x01
 Scan Code is the same as during the last call of hlKeyTmTick().
#define HL_KEYSTATE_OTHER   0x02
 Scan Code is different as during the last call of hlKeyTmTick().
#define HL_KEYSTATE_PWR   0x04
 Current Scan Code is for Power key.
#define HL_KEYSTATE_PREVIOUS   0x08
 Scan Code is equal to the last key down.
#define HL_KEY_DEBOUNCE_CYCLES   1
 Key recognized after n poll cycles.
#define HL_KEY_STAY_AKTIVE   4
 cycles to stay active after key up
#define HL_KEY_WAIT_ALT_FKT   50
 wait for same key again, polls to keep splash screen open
#define HL_KEY_MAX_KEY_FUNCT   3
 maximum number of key codes per key
#define HL_KEY_INT_MIN_CYCLE   5
 minimum number of timer cycles to run after a key interrupt, max 126.
#define HL_KEY_PWR_ON_SEQUENCE   -1
 system is debouncing a power on cycle
#define HL_KEY_BUFSZ   8
 size of key buffer

Typedefs

typedef uint16_t keyscan_t
 type for key scan code

Enumerations

enum  hl_key_DebounceStates {
  KEY_UP = 0, ALLOW_SLEEP = 1, MOVING_DOWN = 2, KEY_DOWN = 3,
  MOVING_UP = 4, OFF_KEY_UP = 5, PWR_OFF = 6, KEY_PROCESSED = 7,
  POWER_ON = 8
}
 

Key Debounce States:

More...

Functions

void hl_Key_Init (void)
 Initialize key scan system.
uint16_t hlKeyTmTick (void)
 Provide regular CPU time to the key scan engine.
uint8_t hlGetKeySc (keyscan_t *Key)
 peek a key from the key buffer
void hlAllKeyWakeup (void)
 init wakeup on all keys
void hlRow3KeyWakeup (void)
 init wakeup on row 3 keys only

Detailed Description

Key Scan and alphanumeric input machine header file.


Define Documentation

#define BLD_SC (   col,
  row,
  row_abc 
)    ((_BV(col)<<8) | (_BV(row_abc)<<8) | _BV(row))


Merge the col, row and RowGroup to a 16bit scan code.


Enumeration Type Documentation

Key Debounce States:

Enumerator:
KEY_UP 

All keys are up.

ALLOW_SLEEP 

KeyUp state with sleep and IRQ wakeUp.

MOVING_DOWN 

KeyDown recognized, but still unstable.

KEY_DOWN 

Key stable down, key not processed.

MOVING_UP 

Unstable down state recognized, check if key is moving up.

OFF_KEY_UP 

Wait until power key is save up again.

PWR_OFF 

PowerOff state, wake on IRQ3 only.

KEY_PROCESSED 

KeyDown, key processed, waiting for KeyUp or other key.

POWER_ON 

Wake on IRQ3, check if power key.

             {
  KEY_UP        = 0, 
  ALLOW_SLEEP   = 1, 
  MOVING_DOWN   = 2, 
  KEY_DOWN      = 3, 
  MOVING_UP     = 4, 
  OFF_KEY_UP    = 5, 
  PWR_OFF       = 6, 
  KEY_PROCESSED = 7, 
  POWER_ON      = 8, 
} hl_key_DebounceStates;


Function Documentation

void hl_Key_Init ( void   ) 

Initialize key scan system.

Must be called at program start, before hlKeyTmTick() is called for the first time

Initialize key scan system.

Init has to be called once at program start

                      {

        hlMatrixInit();

        LastScCode = CurrentScCode = HL_NOKEY;  
        ScanCnt = 0;
        KeyScBufW=0; 
        KeyScBufR=0; 
        KeyScBufCC=0;
        KeyPwrManVar=HL_PWR_ALLOW_IDLE;
//      IntCycleCnt = 0;

        DState = KEY_UP;

        hl_asyn_RegisterFastTimer( (cb_function_t)(&hlKeyTmTick), NULL);
        hl_RegisterPwrCb( (cb_function_t)(&KeyPwrCallBack), NULL);

}

void hlAllKeyWakeup ( void   ) 

init wakeup on all keys

Function will activate interrupts for all 4 key rows

                          {
        // Init key interrupts

        // Init Matrix to be ready for low level IRQ on port D
        hlMatrixInit();

        // all int's low level sens
        EICRA = 0x00;

        // Clear pending interrupts
        EIFR |= (_BV(INTF0) | _BV(INTF1) | _BV(INTF2) | _BV(INTF3));

        // Allow
        EIMSK |= (_BV(INT0) | _BV(INT1) | _BV(INT2) | _BV(INT3));
}

uint8_t hlGetKeySc ( keyscan_t Key  ) 

peek a key from the key buffer

Get input keys from the character buffer

Parameters:
[out] Key Pointer to store the key value
Returns:
returns number of keys in buffer or 0 if empty

                                  {

        if(KeyScBufCC > 0){
                // There is something in the buffer
                *Key = KeyScBuf[KeyScBufR];

                KeyScBufR++;
                if(KeyScBufR >= HL_KEY_BUFSZ){
                        KeyScBufR=0;
                }               
                return KeyScBufCC--; // ------------------------------------->
        }else{

                return HL_NOKEY;   // ------------------------------------->
        }
}

uint16_t hlKeyTmTick ( void   ) 

Provide regular CPU time to the key scan engine.

For ergonomic reasons, a calling interval of 20ms is a good trade off in between fluid operation and CPU time consumption

Provide regular CPU time to the key scan engine.

Function to be called by a timer with the polling interval frequency

                          {



        ksc = hlKeyScan();

        // debug !!!
        // printf("\r\n");

        ksc = hlKeyDebounce(ksc);

        if(ksc != HL_NOKEY){

                // KeyBuffer will always contain the last 8 keys
                KeyScBuf[KeyScBufW]=ksc;
                KeyScBufW++;
                KeyScBufCC++;
                if(KeyScBufW >= HL_KEY_BUFSZ){
                        KeyScBufW=0;
                }
                if (KeyScBufCC > HL_KEY_BUFSZ){
                        KeyScBufCC--;
                        // Buffer is full, forget the oldest entry
                        KeyScBufR++;
                        if(KeyScBufR >= HL_KEY_BUFSZ){
                                KeyScBufR=0;
                        }               
                }
        }
        return 0;
}

void hlRow3KeyWakeup ( void   ) 

init wakeup on row 3 keys only

Function will activate the interrupt for key row 3 only. On the base board, the power key is the only one key in this row.

                           {
        // Init key interrupts

        // Init Matrix to be ready for low level IRQ on port D
        hlMatrixInit();

        // all int's low level sens
        EICRA = 0x00;

        // Clear pending interrupts
        EIFR |= _BV(INTF3);

        // Allow
        EIMSK |= _BV(INT3);
}