Driver for the KINT peripheral on RA MCUs. This module implements the Key Matrix Interface.
Overview
The KINT 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.
Features
- Detect rising or falling edges on KINT channels
- Callback for notifying the application when edges are detected on the configured channels
Configuration
Build Time Configurations for r_kint
The following build time configurations are defined in fsp_cfg/r_kint_cfg.h:
Configuration | Options | Default | Description |
Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Configurations for Input > Key Matrix (r_kint)
This module can be added to the Stacks tab via New Stack > Input > Key Matrix (r_kint).
Configuration | Options | Default | Description |
General |
Name | Name must be a valid C symbol | g_kint0 | Module name. |
Input |
Key Interrupt Flag Mask | MCU Specific Options | | Select channels to enable. |
Interrupts |
Trigger Type |
| Rising Edge | Specifies 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. |
Callback | Name must be a valid C symbol | kint_callback | A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the IRQ triggers. |
Key Interrupt Priority | MCU Specific Options | | Select the key interrupt priority. |
Clock Configuration
The KINT peripheral runs on PCLKB.
Pin Configuration
The KRn pins are key switch matrix row input pins.
Usage Notes
Connecting a Switch Matrix
The KINT module is designed to scan the rows of a switch matrix where each row is connected to a number of columns through switches. A periodic timer (or other mechanism) sets one column pin high at a time. Any switches that are pressed on the driven column cause a rising (or falling) edge on the row pin (KRn) causing an interrupt.
- Note
- In applications where multiple keys may be pressed at the same time it is recommended to put a diode inline with each switch to prevent ghosting.
Handling Multiple Pins
When an edge is detected on multiple pins at the same time, a single IRQ will be generated. A mask of all the pins that detected an edge will be passed to the callback.
Examples
Basic Example
This is a basic example of minimal use of the KINT in an application.
static volatile uint32_t g_channel_mask;
static volatile uint32_t g_kint_edge_detected = 0U;
{
g_kint_edge_detected = 1U;
}
void r_kint_example ()
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
while (0 == g_kint_edge_detected)
{
}
}
◆ kint_instance_ctrl_t
struct kint_instance_ctrl_t |
Channel instance control block. DO NOT INITIALIZE. Initialization occurs when keymatrix_api_t::open is called.
◆ R_KINT_Open()
Configure all the Key Input (KINT) channels and provides a handle for use with the rest of the KINT API functions. Implements keymatrix_api_t::open.
- Return values
-
FSP_SUCCESS | Initialization was successful. |
FSP_ERR_ASSERTION | One of the following parameters may be NULL: p_cfg, or p_ctrl or the callback. |
FSP_ERR_ALREADY_OPEN | The module has already been opened. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel mask is invalid. |
◆ R_KINT_Close()
Clear the KINT configuration and disable the KINT IRQ. Implements keymatrix_api_t::close.
- Return values
-
FSP_SUCCESS | Successful close. |
FSP_ERR_ASSERTION | The parameter p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | The module is not opened. |
◆ R_KINT_Enable()
This function enables interrupts for the KINT peripheral after clearing any pending requests. Implements keymatrix_api_t::enable.
- Return values
-
FSP_SUCCESS | Interrupt enabled successfully. |
FSP_ERR_ASSERTION | The p_ctrl parameter was null. |
FSP_ERR_NOT_OPEN | The peripheral is not opened. |
◆ R_KINT_Disable()
This function disables interrupts for the KINT peripheral. Implements keymatrix_api_t::disable.
- Return values
-
FSP_SUCCESS | Interrupt disabled successfully. |
FSP_ERR_ASSERTION | The p_ctrl parameter was null. |
FSP_ERR_NOT_OPEN | The channel is not opened. |