RA Flexible Software Package Documentation  Release v5.4.0

 
Key Matrix (r_kint)

Functions

fsp_err_t R_KINT_Open (keymatrix_ctrl_t *const p_api_ctrl, keymatrix_cfg_t const *const p_cfg)
 
fsp_err_t R_KINT_Close (keymatrix_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_KINT_Enable (keymatrix_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_KINT_Disable (keymatrix_ctrl_t *const p_api_ctrl)
 

Detailed Description

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

Configuration

Build Time Configurations for r_kint

The following build time configurations are defined in fsp_cfg/r_kint_cfg.h:

ConfigurationOptionsDefaultDescription
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).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_kint0 Module name.
Input
Key Interrupt Flag MaskMCU Specific OptionsSelect channels to enable.
Interrupts
Trigger Type
  • Falling Edge
  • Rising Edge
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.
CallbackName must be a valid C symbolkint_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 PriorityMCU Specific OptionsSelect 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;
/* Called from key_int_isr */
void r_kint_callback (keymatrix_callback_args_t * p_args)
{
g_channel_mask = p_args->channel_mask;
g_kint_edge_detected = 1U;
}
void r_kint_example ()
{
/* Configure the KINT. */
fsp_err_t err = R_KINT_Open(&g_kint_ctrl, &g_kint_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable the KINT. */
err = R_KINT_Enable(&g_kint_ctrl);
assert(FSP_SUCCESS == err);
while (0 == g_kint_edge_detected)
{
/* Wait for interrupt. */
}
}

Data Structures

struct  kint_instance_ctrl_t
 

Data Structure Documentation

◆ 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.

Function Documentation

◆ R_KINT_Open()

fsp_err_t R_KINT_Open ( keymatrix_ctrl_t *const  p_api_ctrl,
keymatrix_cfg_t const *const  p_cfg 
)

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_SUCCESSInitialization was successful.
FSP_ERR_ASSERTIONOne of the following parameters may be NULL: p_cfg, or p_ctrl or the callback.
FSP_ERR_ALREADY_OPENThe module has already been opened.
FSP_ERR_IP_CHANNEL_NOT_PRESENTThe channel mask is invalid.

◆ R_KINT_Close()

fsp_err_t R_KINT_Close ( keymatrix_ctrl_t *const  p_api_ctrl)

Clear the KINT configuration and disable the KINT IRQ. Implements keymatrix_api_t::close.

Return values
FSP_SUCCESSSuccessful close.
FSP_ERR_ASSERTIONThe parameter p_ctrl is NULL.
FSP_ERR_NOT_OPENThe module is not opened.

◆ R_KINT_Enable()

fsp_err_t R_KINT_Enable ( keymatrix_ctrl_t *const  p_api_ctrl)

This function enables interrupts for the KINT peripheral after clearing any pending requests. Implements keymatrix_api_t::enable.

Return values
FSP_SUCCESSInterrupt enabled successfully.
FSP_ERR_ASSERTIONThe p_ctrl parameter was null.
FSP_ERR_NOT_OPENThe peripheral is not opened.

◆ R_KINT_Disable()

fsp_err_t R_KINT_Disable ( keymatrix_ctrl_t *const  p_api_ctrl)

This function disables interrupts for the KINT peripheral. Implements keymatrix_api_t::disable.

Return values
FSP_SUCCESSInterrupt disabled successfully.
FSP_ERR_ASSERTIONThe p_ctrl parameter was null.
FSP_ERR_NOT_OPENThe channel is not opened.