Piconomic FW Library  0.4.3 SVN 17
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers
kbd_matrix.h : Matrix Keyboard module

Description

Full featured matrix (row/column) keyboard scanning module.

File(s):

This module implements or makes provision for:

See also

This module is based on "kbmatrix.h" and "kbmatrix.c" found in the Atmel AT91 Software package

License:

----------------------------------------------------------------------------
ATMEL Microcontroller Software Support
----------------------------------------------------------------------------
Copyright (c) 2008, Atmel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the disclaimer below.
Atmel's name may not be used to endorse or promote products derived from
this software without specific prior written permission.
DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------

Data Structures

struct  kbd_matrix_key_state_t
 Key state bit mask (1 = key pressed; 0 = key released) More...
 
struct  kbd_matrix_key_t
 Linked list structure that describes which key has been pressed. More...
 
struct  kbd_matrix_t
 Keyboard matrix definition and state. More...
 

Macros

#define KBD_MATRIX_MAX_NR_KEYS   56
 Maximum number of keys that can be handled by the module. More...
 
#define KBD_MATRIX_NR_SAMPLES   4
 Number of samples that are necessary to debounce a keypress. More...
 
#define KBD_MATRIX_MAX_NR_KEYS_PRESSED   4
 Maximum number of keys that may be pressed simultaneously. More...
 
#define KBD_DELAY_BEFORE_REPEATING_KEY   200
 Delay before a pressed key will be repeated. More...
 
#define KBD_KEY_REPEAT_DELAY   20
 Delay between pressed key repeats. More...
 

Typedefs

typedef void(* kbd_matrix_on_key_event_t) (u8_t row, u8_t col, kbd_matrix_event_t event)
 Function that will be called when a key event has taken place. More...
 
typedef void(* kbd_matrix_set_row_t) (u8_t row, bool_t active)
 Function that will be called to set a row output. More...
 
typedef bool_t(* kbd_matrix_get_col_t) (u8_t col)
 Function that will be called to read a column input. More...
 
typedef void(* kbd_matrix_delay_t) (bool_t active)
 Function that will be called for row column scanning delay. More...
 

Enumerations

enum  kbd_matrix_event_t { KBD_MATRIX_EVENT_RELEASED = 0, KBD_MATRIX_EVENT_PRESSED = 1 }
 Key event types. More...
 

Data Structure Documentation

struct kbd_matrix_key_state_t

Key state bit mask (1 = key pressed; 0 = key released)

Definition at line 186 of file kbd_matrix.h.

struct kbd_matrix_key_t

Linked list structure that describes which key has been pressed.

Definition at line 192 of file kbd_matrix.h.

struct kbd_matrix_t

Keyboard matrix definition and state.

Definition at line 200 of file kbd_matrix.h.

Data Fields
u8_t nr_of_rows Number of rows in matrix.
u8_t nr_of_columns Number of columns in matrix.
kbd_matrix_key_state_t key_state Bit mask that stores the current state of the keys.
kbd_matrix_key_state_t key_history[KBD_MATRIX_NR_SAMPLES] Array of bit masks that stores the key state history.
u8_t key_history_index Wrapping index (used as a ring buffer)
list_t key_press_list Linked list of pressed keys.
kbd_matrix_key_t key_press_array[KBD_MATRIX_MAX_NR_KEYS_PRESSED] Storage for linked list to remember which keys are pressed.
u16_t key_repeat_counter
kbd_matrix_set_row_t set_row Function handler to write a row output.
kbd_matrix_get_col_t get_col Function handler to read a column input.
kbd_matrix_delay_t delay Function handler to read a column input.
kbd_matrix_on_key_event_t on_key_event_handler Function that will be called if a key is pressed or released.

Macro Definition Documentation

#define KBD_MATRIX_MAX_NR_KEYS   56

Maximum number of keys that can be handled by the module.

Definition at line 110 of file kbd_matrix.h.

#define KBD_MATRIX_NR_SAMPLES   4

Number of samples that are necessary to debounce a keypress.

Definition at line 118 of file kbd_matrix.h.

#define KBD_MATRIX_MAX_NR_KEYS_PRESSED   4

Maximum number of keys that may be pressed simultaneously.

Definition at line 123 of file kbd_matrix.h.

#define KBD_DELAY_BEFORE_REPEATING_KEY   200

Delay before a pressed key will be repeated.

Definition at line 128 of file kbd_matrix.h.

#define KBD_KEY_REPEAT_DELAY   20

Delay between pressed key repeats.

Definition at line 133 of file kbd_matrix.h.

Typedef Documentation

typedef void(* kbd_matrix_on_key_event_t) (u8_t row, u8_t col, kbd_matrix_event_t event)

Function that will be called when a key event has taken place.

Parameters
[in]rowRow address of key event
[in]colColumn address of key event
[in]eventKey event type: PRESSED or RELEASED

Definition at line 152 of file kbd_matrix.h.

typedef void(* kbd_matrix_set_row_t) (u8_t row, bool_t active)

Function that will be called to set a row output.

Parameters
[in]rowSpecifies which row that should be set
[in]activeSpecifies that row should be activated (normally active low)

Definition at line 161 of file kbd_matrix.h.

typedef bool_t(* kbd_matrix_get_col_t) (u8_t col)

Function that will be called to read a column input.

Return values
TRUEKey is being pressed
FALSEKey is not pressed (released)

Definition at line 169 of file kbd_matrix.h.

typedef void(* kbd_matrix_delay_t) (bool_t active)

Function that will be called for row column scanning delay.

If a row is set to active, there is a certain delay before the columns should be sampled.

If a row is set to inactive, there is a certain delay before the columns return to their inactive state.

Parameters
[in]activeSpecifies that row should be activated (normally active low)

Definition at line 183 of file kbd_matrix.h.

Enumeration Type Documentation

Key event types.

Enumerator
KBD_MATRIX_EVENT_RELEASED 

Key has been released.

KBD_MATRIX_EVENT_PRESSED 

Key has been pressed.

Definition at line 138 of file kbd_matrix.h.