Skip to content

Commit 1bca707

Browse files
committed
hal: renesas: ra: add I2C slave support
Add comprehensive I2C slave support for Renesas RA microcontrollers: * Add I2C slave source files (r_iic_slave.c, r_iica_slave.c, r_iic_b_slave.c) from fsp * Add corresponding header files in fsp/inc/instances/ * Add configuration files for each slave implementation * Update CMakeLists.txt to include conditional compilation * Follow the same pattern as existing master implementations The implementation supports three variants: - Standard IIC slave - Enhanced IICA slave - I3C-capable IIC_B slave This provides a complete I2C solution for slave modes on RA microcontrollers. Signed-off-by: Vincent Jardin <[email protected]>
1 parent 0164f2f commit 1bca707

File tree

10 files changed

+3833
-0
lines changed

10 files changed

+3833
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SCI_I2C
5454
fsp/src/r_sci_i2c/r_sci_i2c.c)
5555
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SCI_B_I2C
5656
fsp/src/r_sci_b_i2c/r_sci_b_i2c.c)
57+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_I2C_IIC_SLAVE
58+
fsp/src/r_iic_slave/r_iic_slave.c)
59+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_I2C_IICA_SLAVE
60+
fsp/src/r_iica_slave/r_iica_slave.c)
61+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_I2C_IIC_B_SLAVE
62+
fsp/src/r_iic_b_slave/r_iic_b_slave.c)
5763
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SSI
5864
fsp/src/r_ssi/r_ssi.c)
5965
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_GPT
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @addtogroup IIC_B_SLAVE
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_IIC_B_SLAVE_H
13+
#define R_IIC_B_SLAVE_H
14+
15+
#include "bsp_api.h"
16+
#include "r_iic_b_slave_cfg.h"
17+
#include "r_i2c_slave_api.h"
18+
19+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
20+
FSP_HEADER
21+
22+
/***********************************************************************************************************************
23+
* Macro definitions
24+
***********************************************************************************************************************/
25+
26+
/***********************************************************************************************************************
27+
* Typedef definitions
28+
***********************************************************************************************************************/
29+
30+
/* IIC Slave transaction enumeration */
31+
typedef enum e_iic_b_slave_transfer_dir_option
32+
{
33+
IIC_B_SLAVE_TRANSFER_DIR_MASTER_READ_SLAVE_WRITE = 0x0,
34+
IIC_B_SLAVE_TRANSFER_DIR_MASTER_WRITE_SLAVE_READ = 0x1,
35+
IIC_B_SLAVE_TRANSFER_DIR_NOT_ESTABLISHED = 0x2
36+
} iic_b_slave_transfer_dir_t;
37+
38+
/** I2C clock settings */
39+
typedef struct iic_b_slave_clock_settings
40+
{
41+
uint8_t cks_value; ///< Internal Reference Clock Select
42+
uint8_t brl_value; ///< Low-level period of SCL clock
43+
uint8_t digital_filter_stages; ///< Number of digital filter stages based on brl_value
44+
} iic_b_slave_clock_settings_t;
45+
46+
/* I2C control structure. DO NOT INITIALIZE. */
47+
typedef struct st_iic_b_slave_instance_ctrl
48+
{
49+
i2c_slave_cfg_t const * p_cfg; // Information describing I2C device
50+
uint32_t open; // Flag to determine if the device is open
51+
R_I3C0_Type * p_reg; // Base register for this channel
52+
53+
/* Current transfer information. */
54+
uint8_t * p_buff; // Holds the data associated with the transfer
55+
uint32_t total; // Holds the total number of data bytes to transfer
56+
uint32_t remain; // Tracks the remaining data bytes to transfer
57+
uint32_t loaded; // Tracks the number of data bytes written to the register
58+
uint32_t transaction_count; // Tracks the actual number of transactions
59+
volatile bool notify_request; // Track whether the master request is notified to the application
60+
volatile iic_b_slave_transfer_dir_t direction; // Holds the direction of the data byte transfer
61+
volatile bool do_dummy_read; // Tracks whether a dummy read is issued on the first RX
62+
volatile bool transaction_completed; // Tracks whether previous transaction restarted
63+
#if (IIC_B_SLAVE_CFG_DTC_ENABLE)
64+
volatile bool activation_on_rxi; // Tracks whether the transfer is activated on RXI interrupt
65+
volatile bool activation_on_txi; // Tracks whether the transfer is activated on TXI interrupt
66+
#endif
67+
68+
/* Pointer to callback and optional working memory */
69+
void (* p_callback)(i2c_slave_callback_args_t *);
70+
i2c_slave_callback_args_t * p_callback_memory;
71+
72+
/* Pointer to context to be passed into callback function */
73+
void * p_context;
74+
} iic_b_slave_instance_ctrl_t;
75+
76+
/** R_IIC_SLAVE extended configuration */
77+
typedef struct st_iic_b_slave_extended_cfg
78+
{
79+
iic_b_slave_clock_settings_t clock_settings; ///< I2C Clock settings
80+
} iic_b_slave_extended_cfg_t;
81+
82+
/**********************************************************************************************************************
83+
* Exported global variables
84+
***********************************************************************************************************************/
85+
86+
/** @cond INC_HEADER_DEFS_SEC */
87+
/** Filled in Interface API structure for this Instance. */
88+
extern i2c_slave_api_t const g_i2c_slave_on_iic_b;
89+
90+
/** @endcond */
91+
92+
/***********************************************************************************************************************
93+
* Public Function Prototypes
94+
**********************************************************************************************************************/
95+
96+
fsp_err_t R_IIC_B_SLAVE_Open(i2c_slave_ctrl_t * const p_api_ctrl, i2c_slave_cfg_t const * const p_cfg);
97+
fsp_err_t R_IIC_B_SLAVE_Read(i2c_slave_ctrl_t * const p_api_ctrl, uint8_t * const p_dest, uint32_t const bytes);
98+
fsp_err_t R_IIC_B_SLAVE_Write(i2c_slave_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint32_t const bytes);
99+
fsp_err_t R_IIC_B_SLAVE_Close(i2c_slave_ctrl_t * const p_api_ctrl);
100+
fsp_err_t R_IIC_B_SLAVE_CallbackSet(i2c_slave_ctrl_t * const p_api_ctrl,
101+
void ( * p_callback)(i2c_slave_callback_args_t *),
102+
void * const p_context,
103+
i2c_slave_callback_args_t * const p_callback_memory);
104+
105+
/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
106+
FSP_FOOTER
107+
108+
#endif // R_IIC_B_SLAVE_H
109+
110+
/*******************************************************************************************************************//**
111+
* @} (end defgroup IIC_B_SLAVE)
112+
***********************************************************************************************************************/
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @addtogroup IIC_SLAVE
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_IIC_SLAVE_H
13+
#define R_IIC_SLAVE_H
14+
15+
#include "bsp_api.h"
16+
#include "r_iic_slave_cfg.h"
17+
#include "r_i2c_slave_api.h"
18+
19+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
20+
FSP_HEADER
21+
22+
/***********************************************************************************************************************
23+
* Macro definitions
24+
***********************************************************************************************************************/
25+
26+
/***********************************************************************************************************************
27+
* Typedef definitions
28+
***********************************************************************************************************************/
29+
30+
/* IIC Slave transaction enumeration */
31+
typedef enum e_iic_slave_transfer_dir_option
32+
{
33+
IIC_SLAVE_TRANSFER_DIR_MASTER_READ_SLAVE_WRITE = 0x0,
34+
IIC_SLAVE_TRANSFER_DIR_MASTER_WRITE_SLAVE_READ = 0x1,
35+
IIC_SLAVE_TRANSFER_DIR_NOT_ESTABLISHED = 0x2
36+
} iic_slave_transfer_dir_t;
37+
38+
/** I2C clock settings */
39+
typedef struct iic_slave_clock_settings
40+
{
41+
uint8_t cks_value; ///< Internal Reference Clock Select
42+
uint8_t brl_value; ///< Low-level period of SCL clock
43+
uint8_t digital_filter_stages; ///< Number of digital filter stages based on brl_value
44+
} iic_slave_clock_settings_t;
45+
46+
/* I2C control structure. DO NOT INITIALIZE. */
47+
typedef struct st_iic_slave_instance_ctrl
48+
{
49+
i2c_slave_cfg_t const * p_cfg; // Information describing I2C device
50+
uint32_t open; // Flag to determine if the device is open
51+
R_IIC0_Type * p_reg; // Base register for this channel
52+
53+
/* Current transfer information. */
54+
uint8_t * p_buff; // Holds the data associated with the transfer
55+
uint32_t total; // Holds the total number of data bytes to transfer
56+
uint32_t remain; // Tracks the remaining data bytes to transfer
57+
uint32_t loaded; // Tracks the number of data bytes written to the register
58+
uint32_t transaction_count; // Tracks the actual number of transactions
59+
volatile bool notify_request; // Track whether the master request is notified to the application
60+
volatile iic_slave_transfer_dir_t direction; // Holds the direction of the data byte transfer
61+
volatile bool do_dummy_read; // Tracks whether a dummy read is issued on the first RX
62+
#if (IIC_SLAVE_CFG_DTC_ENABLE)
63+
volatile bool activation_on_rxi; // Tracks whether the transfer is activated on RXI interrupt
64+
volatile bool activation_on_txi; // Tracks whether the transfer is activated on TXI interrupt
65+
#endif
66+
volatile bool start_interrupt_enabled; // Tracks whether the start interrupt is enabled
67+
volatile bool transaction_completed; // Tracks whether previous transaction restarted
68+
69+
/* Pointer to callback and optional working memory */
70+
void (* p_callback)(i2c_slave_callback_args_t *);
71+
i2c_slave_callback_args_t * p_callback_memory;
72+
73+
/* Pointer to context to be passed into callback function */
74+
void * p_context;
75+
} iic_slave_instance_ctrl_t;
76+
77+
/** R_IIC_SLAVE extended configuration */
78+
typedef struct st_iic_slave_extended_cfg
79+
{
80+
iic_slave_clock_settings_t clock_settings; ///< I2C Clock settings
81+
} iic_slave_extended_cfg_t;
82+
83+
/**********************************************************************************************************************
84+
* Exported global variables
85+
***********************************************************************************************************************/
86+
87+
/** @cond INC_HEADER_DEFS_SEC */
88+
/** Filled in Interface API structure for this Instance. */
89+
extern i2c_slave_api_t const g_i2c_slave_on_iic;
90+
91+
/** @endcond */
92+
93+
/***********************************************************************************************************************
94+
* Public Function Prototypes
95+
**********************************************************************************************************************/
96+
97+
fsp_err_t R_IIC_SLAVE_Open(i2c_slave_ctrl_t * const p_api_ctrl, i2c_slave_cfg_t const * const p_cfg);
98+
fsp_err_t R_IIC_SLAVE_Read(i2c_slave_ctrl_t * const p_api_ctrl, uint8_t * const p_dest, uint32_t const bytes);
99+
fsp_err_t R_IIC_SLAVE_Write(i2c_slave_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint32_t const bytes);
100+
fsp_err_t R_IIC_SLAVE_Close(i2c_slave_ctrl_t * const p_api_ctrl);
101+
fsp_err_t R_IIC_SLAVE_CallbackSet(i2c_slave_ctrl_t * const p_api_ctrl,
102+
void ( * p_callback)(i2c_slave_callback_args_t *),
103+
void * const p_context,
104+
i2c_slave_callback_args_t * const p_callback_memory);
105+
106+
/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
107+
FSP_FOOTER
108+
109+
#endif // R_IIC_SLAVE_H
110+
111+
/*******************************************************************************************************************//**
112+
* @} (end defgroup IIC_SLAVE)
113+
***********************************************************************************************************************/
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @addtogroup IICA_SLAVE
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_IICA_SLAVE_H
13+
#define R_IICA_SLAVE_H
14+
15+
#include "bsp_api.h"
16+
#include "r_iica_slave_cfg.h"
17+
#include "r_i2c_slave_api.h"
18+
19+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
20+
FSP_HEADER
21+
22+
/***********************************************************************************************************************
23+
* Macro definitions
24+
***********************************************************************************************************************/
25+
26+
/***********************************************************************************************************************
27+
* Typedef definitions
28+
***********************************************************************************************************************/
29+
30+
/** IICA clock settings */
31+
typedef struct iica_slave_clock_settings
32+
{
33+
uint8_t operation_clock; // Internal Reference Clock Select
34+
uint8_t cks_value; // Transfer clock value
35+
uint8_t iicwh_value; // High-level period of SCL clock
36+
uint8_t iicwl_value; // Low-level period of SCL clock
37+
uint8_t digital_filter; // Digital filter operation select
38+
} iica_slave_clock_settings_t;
39+
40+
/** Configuration settings for IICA pins */
41+
typedef struct iica_slave_pin_settings
42+
{
43+
bsp_io_port_pin_t pin; ///< The pin
44+
uint32_t cfg; ///< Configuration for the pin
45+
} iica_slave_pin_settings_t;
46+
47+
/* IICA control structure. DO NOT INITIALIZE. */
48+
typedef struct st_iica_slave_instance_ctrl
49+
{
50+
i2c_slave_cfg_t const * p_cfg; // Information describing IICA device
51+
uint32_t open; // Flag to determine if the device is open
52+
R_IICA0_Type * p_reg; // Base register for this channel
53+
54+
/* Current transfer information. */
55+
uint8_t * p_buff; // Holds the data associated with the transfer
56+
uint32_t total; // Holds the total number of data bytes to transfer
57+
uint32_t loaded; // Tracks the number of data bytes written to the register (will clear util next call of read/write)
58+
uint32_t total_loaded; // Tracks the number of data bytes written to the register (will clear util stop)
59+
60+
/* Pointer to callback and optional working memory */
61+
void (* p_callback)(i2c_slave_callback_args_t *);
62+
63+
/* Pointer to context to be passed into callback function */
64+
void * p_context;
65+
66+
uint8_t communication_dir; // Communication direction: 0 for read, R_IICA_IICS0_TRC_Msk for write
67+
uint8_t communication_mode; // Communication mode: 0 for clear, 1 for data communication is performed
68+
bool tenbitaddr_matched; // Saves 10 bit address match status
69+
i2c_slave_addr_mode_t addr_mode; // Indicates how slave fields should be interpreted
70+
} iica_slave_instance_ctrl_t;
71+
72+
/** R_IICA_SLAVE extended configuration */
73+
typedef struct st_iica_slave_extended_cfg
74+
{
75+
iica_slave_clock_settings_t clock_settings; // IICA clock settings
76+
iica_slave_pin_settings_t sda_pin_settings; ///< SDAA pin setting
77+
iica_slave_pin_settings_t scl_pin_settings; ///< SCLAA pin setting
78+
} iica_slave_extended_cfg_t;
79+
80+
/**********************************************************************************************************************
81+
* Exported global variables
82+
***********************************************************************************************************************/
83+
84+
/** @cond INC_HEADER_DEFS_SEC */
85+
/** Filled in Interface API structure for this Instance. */
86+
extern i2c_slave_api_t const g_iica_slave_on_iica;
87+
88+
/** @endcond */
89+
90+
/***********************************************************************************************************************
91+
* Public Function Prototypes
92+
**********************************************************************************************************************/
93+
94+
fsp_err_t R_IICA_SLAVE_Open(i2c_slave_ctrl_t * const p_api_ctrl, i2c_slave_cfg_t const * const p_cfg);
95+
fsp_err_t R_IICA_SLAVE_Read(i2c_slave_ctrl_t * const p_api_ctrl, uint8_t * const p_dest, uint32_t const bytes);
96+
fsp_err_t R_IICA_SLAVE_Write(i2c_slave_ctrl_t * const p_api_ctrl, uint8_t * const p_src, uint32_t const bytes);
97+
fsp_err_t R_IICA_SLAVE_Close(i2c_slave_ctrl_t * const p_api_ctrl);
98+
fsp_err_t R_IICA_SLAVE_CallbackSet(i2c_slave_ctrl_t * const p_api_ctrl,
99+
void ( * p_callback)(i2c_slave_callback_args_t *),
100+
void * const p_context,
101+
i2c_slave_callback_args_t * const p_callback_memory);
102+
103+
/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
104+
FSP_FOOTER
105+
106+
#endif // R_IICA_SLAVE_H
107+
108+
/*******************************************************************************************************************//**
109+
* @} (end defgroup IICA_SLAVE)
110+
***********************************************************************************************************************/

0 commit comments

Comments
 (0)