KEYSCAN - Keypad Scanner Driver
Description
Keyscan driver.
Introduction
A low-energy keypad scanner (KEYSCAN) which can scan up to a 6x8 matrix of keyboard switches. The KEYSCAN peripheral contains logic for debounce and settling time, allowing it to scan through the switch matrix autonomously in EM0 and EM1, and interrupt the processor when a key press is detected.
Configuration Options
Some properties of the KEYSCAN driver are compile-time configurable. These properties are stored in a file named keyscan_driver_config.h. A template for this file, containing default values, is in the keyscan/config folder. Currently the configuration options are as follows:
- Number of columns in keyscan.
- Number of rows in keyscan.
- Duration of the scan period per column.
- Duration of debounce period once a key press is detected.
- Duration of the stable period after the debounce stage.
- Enable or disable single-press functionality.
To configure KEYSCAN, provide a custom configuration file. This is an example keyscan_driver_config.h file:
Usage
The expected flow of execution is:
- Initialize the driver.
- Register an event callback to be called on Keyscan event.
- Start the scan.
- Interrupt-based event to read the keypresses.
Initialization is done by calling sl_keyscan_driver_init() . It will prepare the internal structure and GPIO configuration.
When initialization is done successfully, scanning can be started by calling sl_keyscan_driver_start_scan() .
Here is a complete example:
Data Structures |
|
struct | sl_keyscan_driver_process_keyscan_event_handle_t |
An Event Handle.
|
|
Functions |
|
sl_status_t | sl_keyscan_driver_init (void) |
Initializes the keyscan driver.
|
|
void | sl_keyscan_driver_subscribe_event ( sl_keyscan_driver_process_keyscan_event_handle_t *event_handle) |
Registers an event callback to be called on Keyscan event.
|
|
void | sl_keyscan_driver_unsubscribe_event ( sl_keyscan_driver_process_keyscan_event_handle_t *event_handle) |
Unregisters an event callback to be called on Keyscan event.
|
|
sl_status_t | sl_keyscan_driver_start_scan (void) |
Starts the keyscan scan.
|
|
sl_status_t | sl_keyscan_driver_stop_scan (void) |
Stops the keyscan scan.
|
|
Typedefs |
|
typedef void(* | sl_keyscan_driver_process_keyscan_event ) (uint8_t *p_keyscan_matrix, sl_keyscan_driver_status_t status) |
A Keyscan event handler.
|
|
Enumerations |
|
enum |
sl_keyscan_driver_status_t
{
SL_KEYSCAN_STATUS_KEYPRESS_VALID = 0, SL_KEYSCAN_STATUS_KEYPRESS_INVALID , SL_KEYSCAN_STATUS_KEYPRESS_RELEASED } |
KEYSCAN status values.
|
|
Function Documentation
◆ sl_keyscan_driver_init()
sl_status_t sl_keyscan_driver_init | ( | void |
|
) |
Initializes the keyscan driver.
- Returns
- 0 if successful. Error code otherwise.
◆ sl_keyscan_driver_subscribe_event()
void sl_keyscan_driver_subscribe_event | ( | sl_keyscan_driver_process_keyscan_event_handle_t * |
event_handle
|
) |
Registers an event callback to be called on Keyscan event.
- Parameters
-
[in] event_handle
Event handle to register
- Note
- An EFM_ASSERT is thrown if the handle is NULL.
- Must be called before init function.
Registers an event callback to be called on Keyscan event.
◆ sl_keyscan_driver_unsubscribe_event()
void sl_keyscan_driver_unsubscribe_event | ( | sl_keyscan_driver_process_keyscan_event_handle_t * |
event_handle
|
) |
Unregisters an event callback to be called on Keyscan event.
- Parameters
-
[in] event_handle
Event handle which must be unregistered (must have been registered previously).
- Note
- An EFM_ASSERT is thrown if the handle is not found or is NULL.
Unregisters an event callback to be called on Keyscan event.
◆ sl_keyscan_driver_start_scan()
sl_status_t sl_keyscan_driver_start_scan | ( | void |
|
) |
Starts the keyscan scan.
- Returns
- 0 if successful. Error code otherwise.
◆ sl_keyscan_driver_stop_scan()
sl_status_t sl_keyscan_driver_stop_scan | ( | void |
|
) |
Stops the keyscan scan.
- Returns
- 0 if successful. Error code otherwise.
Typedef Documentation
◆ sl_keyscan_driver_process_keyscan_event
typedef void(* sl_keyscan_driver_process_keyscan_event) (uint8_t *p_keyscan_matrix, sl_keyscan_driver_status_t status) |
A Keyscan event handler.
Enumeration Type Documentation
◆ sl_keyscan_driver_status_t
KEYSCAN status values.