Skip to content

Commit 14ab5ea

Browse files
khoatranyjKhiemNguyenT
authored andcommitted
hal: renesas: ra: initial support for r_sci_b_i2c
Add support for Renesas RA r_sci_b_i2c Signed-off-by: Thao Luong <[email protected]>
1 parent cc13230 commit 14ab5ea

File tree

4 files changed

+1529
-0
lines changed

4 files changed

+1529
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_LPM
4444
fsp/src/r_lpm/r_lpm.c)
4545
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_I2C_IIC
4646
fsp/src/r_iic_master/r_iic_master.c)
47+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SCI_B_I2C
48+
fsp/src/r_sci_b_i2c/r_sci_b_i2c.c)
4749
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_GPT
4850
fsp/src/r_gpt/r_gpt.c)
4951
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_AGT
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @addtogroup SCI_B_I2C
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_SCI_B_I2C_H
13+
#define R_SCI_B_I2C_H
14+
15+
#include "bsp_api.h"
16+
#include "r_sci_b_i2c_cfg.h"
17+
#include "r_i2c_master_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+
/** SCI clock source */
31+
typedef enum e_sci_b_i2c_clock_source
32+
{
33+
SCI_B_I2C_CLOCK_SOURCE_SCISPICLK = 0,
34+
SCI_B_I2C_CLOCK_SOURCE_PCLK,
35+
} sci_b_i2c_clock_source_t;
36+
37+
/** I2C clock settings */
38+
typedef struct st_sci_b_i2c_clock_settings
39+
{
40+
bool bitrate_modulation; ///< Bit-rate Modulation Function enable or disable
41+
uint8_t brr_value; ///< Bit rate register settings
42+
uint8_t clk_divisor_value; ///< Clock Select settings
43+
uint8_t mddr_value; ///< Modulation Duty Register settings
44+
uint8_t cycles_value; ///< SDA Delay Output Cycles Select
45+
uint8_t snfr_value; ///< Noise Filter Setting Register value
46+
sci_b_i2c_clock_source_t clock_source; ///< Clock source (PCLK or SCISPICLK)
47+
} sci_b_i2c_clock_settings_t;
48+
49+
/** I2C control structure. DO NOT INITIALIZE. */
50+
typedef struct st_sci_b_i2c_instance_ctrl
51+
{
52+
i2c_master_cfg_t const * p_cfg; // Pointer to the configuration structure
53+
uint32_t slave; // The address of the slave device
54+
i2c_master_addr_mode_t addr_mode; // Indicates how slave fields should be interpreted
55+
uint32_t open; // Flag to determine if the device is open
56+
R_SCI_B0_Type * p_reg; // Base register for this channel
57+
58+
IRQn_Type rxi_irq; // Receive IRQ number
59+
IRQn_Type txi_irq; // Transmit IRQ number
60+
IRQn_Type tei_irq; // Transmit end IRQ number
61+
62+
/* Current transfer information. */
63+
uint8_t * p_buff; // Holds the data associated with the transfer */
64+
uint32_t total; // Holds the total number of data bytes to transfer */
65+
uint32_t remain; // Tracks the remaining data bytes to transfer */
66+
uint32_t loaded; // Tracks the number of data bytes written to the register */
67+
68+
uint8_t addr_low; // Holds the last address byte to issue */
69+
uint8_t addr_high; // Holds the first address byte to issue in 10-bit mode */
70+
uint8_t addr_total; // Holds the total number of address bytes to transfer */
71+
uint8_t addr_remain; // Tracks the remaining address bytes to transfer */
72+
uint8_t addr_loaded; // Tracks the number of address bytes written to the register */
73+
74+
volatile bool read; // Holds the direction of the data byte transfer */
75+
volatile bool restart; // Holds whether or not the restart should be issued when done */
76+
volatile bool err; // Tracks whether or not an error occurred during processing */
77+
volatile bool restarted; // Tracks whether or not a restart was issued during the previous transfer */
78+
volatile bool do_dummy_read; // Tracks whether a dummy read is issued on the first RX */
79+
volatile bool activation_on_rxi; // Tracks whether the transfer is activated on RXI interrupt */
80+
volatile bool activation_on_txi; // Tracks whether the transfer is activated on TXI interrupt */
81+
82+
/* Pointer to callback and optional working memory */
83+
void (* p_callback)(i2c_master_callback_args_t *);
84+
i2c_master_callback_args_t * p_callback_memory;
85+
86+
/* Pointer to context to be passed into callback function */
87+
void const * p_context;
88+
} sci_b_i2c_instance_ctrl_t;
89+
90+
/** SCI I2C extended configuration */
91+
typedef struct st_sci_b_i2c_extended_cfg
92+
{
93+
sci_b_i2c_clock_settings_t clock_settings; ///< I2C Clock settings
94+
} sci_b_i2c_extended_cfg_t;
95+
96+
/**********************************************************************************************************************
97+
* Exported global variables
98+
**********************************************************************************************************************/
99+
100+
/** @cond INC_HEADER_DEFS_SEC */
101+
/** Filled in Interface API structure for this Instance. */
102+
extern i2c_master_api_t const g_i2c_master_on_sci_b;
103+
104+
/** @endcond */
105+
106+
/***********************************************************************************************************************
107+
* Public APIs
108+
**********************************************************************************************************************/
109+
fsp_err_t R_SCI_B_I2C_Open(i2c_master_ctrl_t * const p_api_ctrl, i2c_master_cfg_t const * const p_cfg);
110+
fsp_err_t R_SCI_B_I2C_Close(i2c_master_ctrl_t * const p_api_ctrl);
111+
fsp_err_t R_SCI_B_I2C_Read(i2c_master_ctrl_t * const p_api_ctrl,
112+
uint8_t * const p_dest,
113+
uint32_t const bytes,
114+
bool const restart);
115+
fsp_err_t R_SCI_B_I2C_Write(i2c_master_ctrl_t * const p_api_ctrl,
116+
uint8_t * const p_src,
117+
uint32_t const bytes,
118+
bool const restart);
119+
fsp_err_t R_SCI_B_I2C_Abort(i2c_master_ctrl_t * const p_api_ctrl);
120+
fsp_err_t R_SCI_B_I2C_SlaveAddressSet(i2c_master_ctrl_t * const p_api_ctrl,
121+
uint32_t const slave,
122+
i2c_master_addr_mode_t const addr_mode);
123+
fsp_err_t R_SCI_B_I2C_CallbackSet(i2c_master_ctrl_t * const p_api_ctrl,
124+
void ( * p_callback)(i2c_master_callback_args_t *),
125+
void const * const p_context,
126+
i2c_master_callback_args_t * const p_callback_memory);
127+
fsp_err_t R_SCI_B_I2C_StatusGet(i2c_master_ctrl_t * const p_api_ctrl, i2c_master_status_t * p_status);
128+
129+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
130+
FSP_FOOTER
131+
132+
#endif
133+
134+
/*******************************************************************************************************************//**
135+
* @} (end defgroup SCI_B_I2C)
136+
**********************************************************************************************************************/

0 commit comments

Comments
 (0)