![]() |
Synergy Software Package User's Manual
|
The Key Matrix HAL module provides a high-level API for key input applications and uses the key-interrupt function peripheral on the Synergy MCU. A user-defined callback can be created to inform the CPU of a key press event.
This Key Matrix HAL module configures and controls the Key Interrupt (KINT) peripheral. It implements the following key functions:
The following hardware features are, or are not, supported by SSP for KINT.
Legend:
| Symbol | Meaning |
|---|---|
| ✓ | Available (Tested) |
| ⌧ | Not Available (Not tested/not functional or both) |
| N/A | Not supported by MCU |
| MCU Group | Vary Input from KR00 to KR07 |
|---|---|
| S124 | ✓ |
| S128 | ✓ |
| S1JA | ✓ |
| S3A1 | ✓ |
| S3A3 | ✓ |
| S3A6 | ✓ |
| S3A7 | ✓ |
| S5D3 | ✓ |
| S5D5 | ✓ |
| S5D9 | ✓ |
| S7G2 | ✓ |
The Key Matrix HAL module defines APIs for opening, closing, enabling and disabling key-interrupt functions. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
Key Matrix HAL Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| open | g_keymatrix_on_kint.p_api->open(g_kint.p_ctrl, g_kint.p_cfg_cfg)Initial configuration. |
| enable | g_keymatrix_on_kint.p_api->enable(g_kint.p_ctrl)Enable Key interrupt. |
| disable | g_keymatrix_on_kint.p_api->disable(g_kint.p_ctrl)Disable Key interrupt. |
| triggerSet | g_keymatrix_on_kint.p_api->triggerSet()Set trigger for Key interrupt. |
| close | g_keymatrix_on_kint.p_api->close(&g_ keymatrix)Allow driver to be reconfigured. May reduce power consumption. |
| versionGet | g_keymatrix_on_kint.p_api->versionGet(&version)Get version and store it in provided pointer version. |
Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | Function successfully completed. |
| SSP_ERR_ASSERTION | Parameter has invalid value. |
| SSP_ERR_INVALID_ARGUMENT | Argument is invalid. |
| SSP_ERR_HW_LOCKED | The API has already been opened. It must be closed before it can be opened again. |
| SSP_ERR_NOT_OPEN | The peripheral is not opened. |
The Key Matrix HAL module configures the Key Interrupt (KINT) peripheral to detect rising or falling edges on any of the KINT channels. When such an event is detected on any of the configured pins, the module generates an interrupt; the interrupt then calls the user callback (p_callback) with the callback argument keymatrix_callback_args_t that specifies the channel(s) on which the edge was detected using a bitmask.
Even though detection of an edge on any one channel generates the interrupt, the callback returns a bitmask keymatrix_channels_t of all the pins that were triggered at that time (if any other pins also detected an edge). Thus, an interrupt is not necessarily generated for edge detection on each pin if an edge was also detected on another pin before the callback was called. If a new edge is detected after the callback was called, then the interrupt is triggered again, resulting in a new callback. The bit mask in the user callback should be checked to identify the interrupt source channels.
This module can be used to implement a matrix keypad with edges on any two channels indicating the actual key that was pressed; alternatively, the module can be used as a single input to detect an edge on an input pin.
ELC_EVENT_KEY_INT.This section describes how to include the Key Matrix HAL Module in an application using the SSP configurator.
To add the Key Matrix Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the Key Matrix Driver is g_kint0. This name can be changed in the associated Properties window.)
Key Matrix HAL Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_kint0 Key Matrix Driver on r_kint | Threads | New Stack> Driver> Input> Key Matrix Driver on r_kint |
When the Key Matrix Driver on r_kint is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The Key Matrix HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.
One of the properties most often identified as requiring a change is the interrupt priority; this configuration setting is available with the Properties window of the associated module. Simply select the indicated module and then view the properties window; the interrupt settings are often toward the bottom of the properties list, so scroll down until they become available.
Configuration Settings for the Key Matrix HAL Module on r_kint
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enable or disable the parameter error checking. |
| Name | g_kint0 | Module name. |
| Channel 0-7 | Unused, Used Default: Unused | This is a bit-mask with each bit specifying if that channel is to be enabled or not. Select the channels to be used. |
| Trigger Type | Rising Edge, Falling Edge Default: Rising Edge | Specify if the enabled channels detect a rising edge or a falling edge. Note: Either all channels detecting a rising edge or all channels detecting a falling edge. |
| Interrupt enabled after initialization | True, False Default: False | Specify if the module interrupts must be enabled as part of the open call. |
| Callback | NULL | A user callback function can be registered in keymatrix_api_t::open. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time a configured edge is detected on any of the channels. Note: Without callback, the application cannot determine whether an event has occurred. Warning: Since the callback is called from an ISR, do not use blocking calls or lengthy processing. Spending excessive time in an ISR can affect the responsiveness of the system. |
| Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Priority 12 | Interrupt priority selection. |
The Key Matrix HAL module does not require a specific clock configuration.
The KINT peripheral module uses pins on the MCU to communicate to external devices. I/O pins must be selected and configured as required by the external device. The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example selection for the KINT pins:
Pin Selection for the Key Matrix HAL Module on r_kint
| Resource | ISDE Tab | Pin selection Sequence |
|---|---|---|
| KINT | Pins | Select Peripherals> Input:KINT> KINT0. |
Pin Configuration Settings for the Key Matrix HAL Module on r_kint
| Property | Value | Description |
|---|---|---|
| Operation Mode | Disabled, Custom Default: Disabled | Select Custom as the Operation Mode. |
| KRM0:7 | None, Pnn Default: None | Key Interrupt Pin selection. |
The typical steps in using the Key Matrix HAL module in an application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: