This section introduces the keypad driver APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enums, structures and functions.
More...
This section introduces the keypad driver APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enums, structures and functions.
Terms and acronyms
| Terms | Details |
| GPIO | For an introduction to General Purpose Inputs-Outputs, please refer to the GPIO module in HAL. |
| NVIC | The Nested Vectored Interrupt Controller (NVIC) is the interrupt controller of ARM Cortex-M.For more details, please refer to NVIC introduction in ARM Cortex-M4 Processor Technical Reference Manual . |
| keypad | The keypad is an input device controller that can get input events. |
Supported features
This module provides a generic design to get external key events. The keypad provides two different modes, the keypad mode and the power key mode.
- Keypad mode.
In this mode, an interrupt is triggered whenever a normal key is pressed or released. A callback function can be registered for the interrupt. The callback function is invoked whenever a key is pressed or released. hal_keypad_get_key() can be used in the callback function to get the key event and the key position number.
- Powerkey mode.
In this mode, an interrupt is triggered whenever the powerkey is pressed or released. A callback function can be registered for the interrupt. The callback function is invoked whenever the powerkey is pressed or released. hal_keypad_get_key() can be used in the callback function to get the key event and the key data.
How to use this driver
- Using the keypad mode.
To use the keypad driver in normal keypad mode, please refer to GPIO datasheet to determine which GPIOs should be selected to pinmux to keypad column and row pins. Note that if you use the EPT tool to configure the keypad pin settings, there is no need to configure the keypad GPIO pinmux anymore. Then call hal_keypad_init() to manually set the keypad mode, the key column and row and the debounce time. Call hal_keypad_init(), then call hal_keypad_register_callback() to register a callback. Call hal_keypad_enable() to start the keypad module. If a key is pressed or released on the keypad, the keypad triggers an interrupt to call the callback function. User should use hal_keypad_get_key() in the callback function to get the key event and the key position number. To ensure a reliable key scan, do not overload the callback function. Let the callback return as quick as possible.
- Using powerkey mode.
Call hal_keypad_powerkey_init() to initialize the keypad powerkey module. set the base environment and the key data value to use the powerkey mode. Call hal_keypad_powerkey_init(), then call hal_keypad_powerkey_register_callback() to register a callback. The powerkey module starts working once a callback function is registered. If the power key is pressed or released, the key triggers an interrupt and calls a callback function. User should use hal_keypad_powerkey_get_key() in callback function to get the key event and the key data values. To ensure a smooth key scan, do not overload the callback function. Let the callback return as quick as possible.
How to connect the EPT tool
- Normal keypad mode.
The normal keypad mode only supports keypad pins. The other GPIO pins cannot be used with the keypad driver. Two types of keypads are supported in the normal keypad mode: 3x3 single keys and 3x3 configurable double keys. The EPT tool configures the keypad pin columns and rows in GPIO setting page, it maps the symbol of key data to hardware key data, and selects the single or double key mode in keypad settings page.
- Powerkey mode.
The powerkey mode supports the powerkey pin only. The other pins cannot be used with the keypad driver. The powerkey driver supports power key only. The EPT tool maps the hardware key data to the powerkey symbol.
How to customize the keypad driver
The configurations related to the keypad are in the custom files under driver/board/mtxxxx_hdk/keypad. In these files, user can modify the debounce time, longpress and repeat time for the keys in the normal keypad mode. Modify the longpress and repeat time for the keys in the powerkey mode. These files provide functions to translate hardware key data to the symbol of EPT tool keypad data in normal keypad mode.
This function deinitializes the keypad module.
After calling this function, the callback is cleared, interrupts and keypad module are disabled.
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful.
HAL_KEYPAD_STATUS_ERROR, if #()hal_keypad_init has not been initialized or if there still has data in keypad buffer.
- See also
- hal_keypad_init()
This function disables the keypad module.
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful.
HAL_KEYPAD_STATUS_ERROR, if #()hal_keypad_init has not been initialized.
- See also
- hal_keypad_enable()
This function gets the keypad debounce time, the unit is in milliseconds.
- Parameters
-
| [in] | keypad_debounce | is a user defined pointer to get the current debounce time. |
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful.
- See also
- hal_keypad_set_debounce()
This function gets the key event.
The key event specifies if the current key state is pressed or released, and the data is the key position number, not the key value.
- Parameters
-
| [in] | keypad_event | is a pointer to the key event. For more details, please refer to hal_keypad_event_t. |
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful. HAL_KEYPAD_STATUS_ERROR, if there is no data in the buffer.
This function initialize the keypad module.
Call this function if the keypad is required.
- Parameters
-
| [in] | keypad_config | is the pointer to configuration. For more details, please refer to hal_keypad_config_t. |
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful.
HAL_KEYPAD_STATUS_ERROR, if #()hal_keypad_init has not been initialized.
- See also
- hal_keypad_deinit()
This function de-initializes the powerkey base environment.
After calling this function, the interrupt is disabled, the callback function is cleared.
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful. HAL_KEYPAD_STATUS_ERROR, powerkey deinitialization has failed.
- See also
- hal_keypad_powerkey_init().
This function gets the powerkey event.
The powerkey event specifies if the current key state is pressed or released, and the key data.
- Parameters
-
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful. HAL_KEYPAD_STATUS_ERROR, if all of the key data and event are read.
This function initializes the powerkey base environment.
After calling this function, the interrupt is enabled.
- Parameters
-
| [in] | powerkey_data | is the powerkey data defined by user. |
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful. HAL_KEYPAD_STATUS_ERROR, powerkey initialization has failed.
- See also
- hal_keypad_powerkey_deinit().
This function registers a callback function when in a powerkey mode.
The callback can only be registered after calling the function hal_keypad_powerkey_init(). The callback function will be called after the powerkey is pressed or released in the ISR routine. After register a callback function, the powerkey module is started.
- Parameters
-
| [in] | callback | is a pointer to the callback. This callback will be called when the powerkey release or press a key. |
| [in] | user_data | This variable pointer is defined by the user to record data. |
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful. HAL_KEYPAD_STATUS_ERROR, hal_keypad_powerkey_init() has not been called or the callback is null.
This function registers a callback function when in a normal key mode.
The callback can only be registered after calling the function hal_keypad_init(). The callback function is called after a key is pressed or released in the ISR routine.
- Parameters
-
| [in] | callback | is a function pointer to the callback. This callback is called when the keypad key is released or pressed. |
| [in] | user_data | This variable pointer is defined by the user to record the data. |
- Returns
- HAL_KEYPAD_STATUS_OK, if operation is successful. HAL_KEYPAD_STATUS_ERROR, hal_keypad_init() has not been called or callback is null.