Keypad Driver
Keypad Overview
This is the keypad driver which detect key presses, and provide the necessary data to the microcontroller or the main program.
The keypad debounce time, keypad action, and key press time should be in the application side.
Usage
The API functions have the first argument as the strucure instance and next followed by config structure.
Configure keypad pins in keypad driver module open function.
When a key press is detected, an rcb callback function will be called to perform further actions with the pressed keys.
Return codes of API functions are defined in header file.
Application Interface
The below table captures the functions that are to be called from the application layer.
Function |
Description |
---|---|
rs_keypad_open |
Function to open the keypad module |
rs_keypad_process |
Function to process the keypad driver module |
Function |
Description |
---|---|
rcb_keypad_action |
Callback function gets keypad action and use for further need. |
Error Code
Every API’s for the keyad module returns some success or failure values. Please refer below section,
Keypad driver module Header Details
Documentation from the relevant header as follows:
Keypad Module.
This file contains the APIs for Keypad module
- Author
Embien RAPIDSEA Team
- Copyright
Embien Technologies India Pvt. Ltd.
Defines
- RS_KEYPAD_MAX_NUM_KEYS
Maximum number of keys supported.
- RS_KEY_IDLE_STATE
Macros for key state Key is in the idle state, not pressed
- RS_KEY_PRESSED
Key is in the pressed state
- RS_KEY_LONG_PRESSED
Key has been held down long enough to trigger a long press action
- RS_KEY_RELEASED
Key has been released after being pressed
- RS_KEY_WAIT_FOR_DEBOUNCE
Key is waiting for debounce time to stabilize the input signal
- RS_KEYPAD_ACTION_PRESSED
Macros for key action Action indicating that a key has been pressed
- RS_KEYPAD_ACTION_LONG_PRESSED
Action indicating that a key has been long-pressed
- RS_KEYPAD_ACTION_RELEASED
Action indicating that a key has been released
- RS_LONG_PRESS_TIME_INCREMENT_MS
Time increment in milliseconds for a long press action.
Typedefs
- typedef struct tag_rs_key_config rs_key_config_t
Contains configuration information for a key.
- typedef struct tag_rs_keypad_config rs_keypad_config_t
Contains information about keypad config.
- typedef struct tag_rs_key_info rs_key_info_t
Contains information about keys state.
- typedef struct tag_rs_keypad_instance rs_keypad_instance_t
Contains information about keypad instance.
Functions
- rs_handle_t rs_keypad_open(rs_keypad_instance_t *ptr_keypad_inst, rs_keypad_config_t *ptr_keypad_config)
Open and initialize the keypad.
This function initializes the keypad instance with the given configuration. It sets up the necessary hardware and software components to make the keypad ready for use.
Open and initialize the keypad.
- Parameters:
ptr_keypad_inst – [in] - Pointer to the keypad instance structure
ptr_keypad_config – [in] - Pointer to the keypad configuration structure
- Returns:
Handle to the keypad instance or an error code
- rs_ret_val_t rs_keypad_process(rs_handle_t keypad_handle)
Process the keypad inputs.
This function processes the current state of the keypad, updating the internal state and handling key presses or idles as needed.
- Parameters:
keypad_handle – [in] - Handle to the keypad instance
- Returns:
0 on success or error code
- rs_ret_val_t rs_keypad_close(rs_handle_t keypad_handle)
Close the keypad instance.
This function closes the keypad instance, releasing any resources and shutting down the keypad.
- Parameters:
keypad_handle – [in] - Handle to the keypad instance
- Returns:
0 on success or error code
- struct tag_rs_key_config
#include <rs_keypad.h>Contains configuration information for a key.
- struct tag_rs_keypad_config
#include <rs_keypad.h>Contains information about keypad config.
Public Members
- uint16_t num_keys
Maximum number of keys used.
- uint16_t debounce_time
Debounce Time for inputs in milliseconds.
- uint16_t long_press_time
Long press time for keys in milliseconds.
- rs_key_config_t key_config[RS_KEYPAD_MAX_NUM_KEYS]
Array holding port and pin information for up to 16 keys.
- struct tag_rs_key_info
#include <rs_keypad.h>Contains information about keys state.
- struct tag_rs_keypad_instance
#include <rs_keypad.h>Contains information about keypad instance.
Public Members
- rs_keypad_config_t *ptr_config
Pointer to the keypad configuration structure.
- rs_key_info_t key_info[RS_KEYPAD_MAX_NUM_KEYS]
Array holding information for up to 16 keys.
- void *ptr_arg
User Argument.