Skip to content

Commit dd66061

Browse files
khoatranyjKhiemNguyenT
authored andcommitted
hal: renesas: ra: Initial support for I2S SSIE of Renesas RA
Initial support for I2S SSIE of Renesas RA Signed-off-by: Khoa Tran <[email protected]>
1 parent e6cbdba commit dd66061

File tree

5 files changed

+1689
-0
lines changed

5 files changed

+1689
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SCI_I2C
5050
fsp/src/r_sci_i2c/r_sci_i2c.c)
5151
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SCI_B_I2C
5252
fsp/src/r_sci_b_i2c/r_sci_b_i2c.c)
53+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SSI
54+
fsp/src/r_ssi/r_ssi.c)
5355
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_GPT
5456
fsp/src/r_gpt/r_gpt.c)
5557
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_AGT

drivers/ra/fsp/inc/api/r_i2s_api.h

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
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+
* @ingroup RENESAS_CONNECTIVITY_INTERFACES
9+
* @defgroup I2S_API I2S Interface
10+
* @brief Interface for I2S audio communication.
11+
*
12+
* @section I2S_API_SUMMARY Summary
13+
* @brief The I2S (Inter-IC Sound) interface provides APIs and definitions for I2S audio communication.
14+
*
15+
* @{
16+
**********************************************************************************************************************/
17+
18+
#ifndef R_I2S_API_H
19+
#define R_I2S_API_H
20+
21+
/***********************************************************************************************************************
22+
* Includes
23+
**********************************************************************************************************************/
24+
25+
/* Register definitions, common services and error codes. */
26+
#include "bsp_api.h"
27+
#ifndef BSP_OVERRIDE_I2S_INCLUDE
28+
#include "r_timer_api.h"
29+
#endif
30+
#include "r_transfer_api.h"
31+
32+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
33+
FSP_HEADER
34+
35+
/**********************************************************************************************************************
36+
* Macro definitions
37+
**********************************************************************************************************************/
38+
39+
/**********************************************************************************************************************
40+
* Typedef definitions
41+
**********************************************************************************************************************/
42+
#ifndef BSP_OVERRIDE_I2S_PCM_WIDTH_T
43+
44+
/** Audio PCM width */
45+
typedef enum e_i2s_pcm_width
46+
{
47+
I2S_PCM_WIDTH_8_BITS = 0, ///< Using 8-bit PCM
48+
I2S_PCM_WIDTH_16_BITS = 1, ///< Using 16-bit PCM
49+
I2S_PCM_WIDTH_18_BITS = 2, ///< Using 18-bit PCM
50+
I2S_PCM_WIDTH_20_BITS = 3, ///< Using 20-bit PCM
51+
I2S_PCM_WIDTH_22_BITS = 4, ///< Using 22-bit PCM
52+
I2S_PCM_WIDTH_24_BITS = 5, ///< Using 24-bit PCM
53+
I2S_PCM_WIDTH_32_BITS = 6, ///< Using 32-bit PCM
54+
} i2s_pcm_width_t;
55+
#endif
56+
57+
#ifndef BSP_OVERRIDE_I2S_WORD_LENGTH_T
58+
59+
/** Audio system word length. */
60+
typedef enum e_i2s_word_length
61+
{
62+
I2S_WORD_LENGTH_8_BITS = 0, ///< Using 8-bit system word length
63+
I2S_WORD_LENGTH_16_BITS = 1, ///< Using 16-bit system word length
64+
I2S_WORD_LENGTH_24_BITS = 2, ///< Using 24-bit system word length
65+
I2S_WORD_LENGTH_32_BITS = 3, ///< Using 32-bit system word length
66+
I2S_WORD_LENGTH_48_BITS = 4, ///< Using 48-bit system word length
67+
I2S_WORD_LENGTH_64_BITS = 5, ///< Using 64-bit system word length
68+
I2S_WORD_LENGTH_128_BITS = 6, ///< Using 128-bit system word length
69+
I2S_WORD_LENGTH_256_BITS = 7, ///< Using 256-bit system word length
70+
} i2s_word_length_t;
71+
#endif
72+
73+
/** Events that can trigger a callback function */
74+
typedef enum e_i2s_event
75+
{
76+
I2S_EVENT_IDLE, ///< Communication is idle
77+
I2S_EVENT_TX_EMPTY, ///< Transmit buffer is below FIFO trigger level
78+
I2S_EVENT_RX_FULL, ///< Receive buffer is above FIFO trigger level
79+
} i2s_event_t;
80+
81+
#ifndef BSP_OVERRIDE_I2S_MODE_T
82+
83+
/** I2S communication mode */
84+
typedef enum e_i2s_mode
85+
{
86+
I2S_MODE_SLAVE = 0, ///< Slave mode
87+
I2S_MODE_MASTER = 1, ///< Master mode
88+
} i2s_mode_t;
89+
#endif
90+
91+
/** Mute audio samples. */
92+
typedef enum e_i2s_mute
93+
{
94+
I2S_MUTE_OFF = 0, ///< Disable mute
95+
I2S_MUTE_ON = 1, ///< Enable mute
96+
} i2s_mute_t;
97+
98+
/** Whether to continue WS (word select line) transmission during idle state. */
99+
typedef enum e_i2s_ws_continue
100+
{
101+
I2S_WS_CONTINUE_ON = 0, ///< Enable WS continue mode
102+
I2S_WS_CONTINUE_OFF = 1, ///< Disable WS continue mode
103+
} i2s_ws_continue_t;
104+
105+
/** Possible status values returned by @ref i2s_api_t::statusGet. */
106+
typedef enum e_i2s_state
107+
{
108+
I2S_STATE_IN_USE, ///< I2S is in use
109+
I2S_STATE_STOPPED ///< I2S is stopped
110+
} i2s_state_t;
111+
112+
/** Callback function parameter data */
113+
typedef struct st_i2s_callback_args
114+
{
115+
/** Placeholder for user data. Set in @ref i2s_api_t::open function in @ref i2s_cfg_t. */
116+
void const * p_context;
117+
i2s_event_t event; ///< The event can be used to identify what caused the callback (overflow or error).
118+
} i2s_callback_args_t;
119+
120+
/** I2S control block. Allocate an instance specific control block to pass into the I2S API calls.
121+
*/
122+
typedef void i2s_ctrl_t;
123+
124+
/** I2S status. */
125+
typedef struct st_i2s_status
126+
{
127+
i2s_state_t state; ///< Current I2S state
128+
} i2s_status_t;
129+
130+
/** User configuration structure, used in open function */
131+
typedef struct st_i2s_cfg
132+
{
133+
/** Select a channel corresponding to the channel number of the hardware. */
134+
uint32_t channel;
135+
i2s_pcm_width_t pcm_width; ///< Audio PCM data width
136+
i2s_word_length_t word_length; ///< Audio word length, bits must be >= i2s_cfg_t::pcm_width bits
137+
i2s_ws_continue_t ws_continue; ///< Whether to continue WS transmission during idle state.
138+
i2s_mode_t operating_mode; ///< Master or slave mode
139+
140+
/** To use DMA for transmitting link a Transfer instance here. Set to NULL if unused. */
141+
transfer_instance_t const * p_transfer_tx;
142+
143+
/** To use DMA for receiving link a Transfer instance here. Set to NULL if unused. */
144+
transfer_instance_t const * p_transfer_rx;
145+
146+
/** Callback provided when an I2S ISR occurs. Set to NULL for no CPU interrupt. */
147+
void (* p_callback)(i2s_callback_args_t * p_args);
148+
149+
/** Placeholder for user data. Passed to the user callback in @ref i2s_callback_args_t. */
150+
void const * p_context;
151+
void const * p_extend; ///< Extension parameter for hardware specific settings.
152+
uint8_t rxi_ipl; ///< Receive interrupt priority
153+
uint8_t txi_ipl; ///< Transmit interrupt priority
154+
uint8_t idle_err_ipl; ///< Idle/Error interrupt priority
155+
IRQn_Type txi_irq; ///< Transmit IRQ number
156+
IRQn_Type rxi_irq; ///< Receive IRQ number
157+
IRQn_Type int_irq; ///< Idle/Error IRQ number
158+
} i2s_cfg_t;
159+
160+
/** I2S functions implemented at the HAL layer will follow this API. */
161+
typedef struct st_i2s_api
162+
{
163+
/** Initial configuration.
164+
*
165+
* @pre Peripheral clocks and any required output pins should be configured prior to calling this function.
166+
* @note To reconfigure after calling this function, call @ref i2s_api_t::close first.
167+
* @param[in] p_ctrl Pointer to control block. Must be declared by user. Elements set here.
168+
* @param[in] p_cfg Pointer to configuration structure. All elements of this structure must be set by user.
169+
*/
170+
fsp_err_t (* open)(i2s_ctrl_t * const p_ctrl, i2s_cfg_t const * const p_cfg);
171+
172+
/** Stop communication. Communication is stopped when callback is called with I2S_EVENT_IDLE.
173+
*
174+
*
175+
* @param[in] p_ctrl Control block set in @ref i2s_api_t::open call for this instance.
176+
*/
177+
fsp_err_t (* stop)(i2s_ctrl_t * const p_ctrl);
178+
179+
/** Enable or disable mute.
180+
*
181+
* @param[in] p_ctrl Control block set in @ref i2s_api_t::open call for this instance.
182+
* @param[in] mute_enable Whether to enable or disable mute.
183+
*/
184+
fsp_err_t (* mute)(i2s_ctrl_t * const p_ctrl, i2s_mute_t const mute_enable);
185+
186+
/** Write I2S data. All transmit data is queued when callback is called with I2S_EVENT_TX_EMPTY.
187+
* Transmission is complete when callback is called with I2S_EVENT_IDLE.
188+
*
189+
* @param[in] p_ctrl Control block set in @ref i2s_api_t::open call for this instance.
190+
* @param[in] p_src Buffer of PCM samples. Must be 4 byte aligned.
191+
* @param[in] bytes Number of bytes in the buffer. Recommended requesting a multiple of 8 bytes. If not
192+
* a multiple of 8, padding 0s will be added to transmission to make it a multiple of 8.
193+
*/
194+
fsp_err_t (* write)(i2s_ctrl_t * const p_ctrl, void const * const p_src, uint32_t const bytes);
195+
196+
/** Read I2S data. Reception is complete when callback is called with I2S_EVENT_RX_EMPTY.
197+
*
198+
* @param[in] p_ctrl Control block set in @ref i2s_api_t::open call for this instance.
199+
* @param[in] p_dest Buffer to store PCM samples. Must be 4 byte aligned.
200+
* @param[in] bytes Number of bytes in the buffer. Recommended requesting a multiple of 8 bytes. If not
201+
* a multiple of 8, receive will stop at the multiple of 8 below requested bytes.
202+
*/
203+
fsp_err_t (* read)(i2s_ctrl_t * const p_ctrl, void * const p_dest, uint32_t const bytes);
204+
205+
/** Simultaneously write and read I2S data. Transmission and reception are complete when
206+
* callback is called with I2S_EVENT_IDLE.
207+
*
208+
* @param[in] p_ctrl Control block set in @ref i2s_api_t::open call for this instance.
209+
* @param[in] p_src Buffer of PCM samples. Must be 4 byte aligned.
210+
* @param[in] p_dest Buffer to store PCM samples. Must be 4 byte aligned.
211+
* @param[in] bytes Number of bytes in the buffers. Recommended requesting a multiple of 8 bytes. If not
212+
* a multiple of 8, padding 0s will be added to transmission to make it a multiple of 8,
213+
* and receive will stop at the multiple of 8 below requested bytes.
214+
*/
215+
fsp_err_t (* writeRead)(i2s_ctrl_t * const p_ctrl, void const * const p_src, void * const p_dest,
216+
uint32_t const bytes);
217+
218+
/** Get current status and store it in provided pointer p_status.
219+
*
220+
* @param[in] p_ctrl Control block set in @ref i2s_api_t::open call for this instance.
221+
* @param[out] p_status Current status of the driver.
222+
*/
223+
fsp_err_t (* statusGet)(i2s_ctrl_t * const p_ctrl, i2s_status_t * const p_status);
224+
225+
/** Allows driver to be reconfigured and may reduce power consumption.
226+
*
227+
* @param[in] p_ctrl Control block set in @ref i2s_api_t::open call for this instance.
228+
*/
229+
fsp_err_t (* close)(i2s_ctrl_t * const p_ctrl);
230+
231+
/**
232+
* Specify callback function and optional context pointer and working memory pointer.
233+
*
234+
* @param[in] p_ctrl Pointer to the I2S control block.
235+
* @param[in] p_callback Callback function
236+
* @param[in] p_context Pointer to send to callback function
237+
* @param[in] p_working_memory Pointer to volatile memory where callback structure can be allocated.
238+
* Callback arguments allocated here are only valid during the callback.
239+
*/
240+
fsp_err_t (* callbackSet)(i2s_ctrl_t * const p_ctrl, void (* p_callback)(i2s_callback_args_t *),
241+
void const * const p_context, i2s_callback_args_t * const p_callback_memory);
242+
} i2s_api_t;
243+
244+
/** This structure encompasses everything that is needed to use an instance of this interface. */
245+
typedef struct st_i2s_instance
246+
{
247+
i2s_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
248+
i2s_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
249+
i2s_api_t const * p_api; ///< Pointer to the API structure for this instance
250+
} i2s_instance_t;
251+
252+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
253+
FSP_FOOTER
254+
255+
#endif
256+
257+
/*******************************************************************************************************************//**
258+
* @} (end defgroup I2S_API)
259+
**********************************************************************************************************************/

drivers/ra/fsp/inc/instances/r_ssi.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 SSI
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_SSI_H
13+
#define R_SSI_H
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "r_i2s_api.h"
19+
20+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
21+
FSP_HEADER
22+
23+
/***********************************************************************************************************************
24+
* Macro definitions
25+
**********************************************************************************************************************/
26+
27+
/***********************************************************************************************************************
28+
* Typedef definitions
29+
**********************************************************************************************************************/
30+
31+
/** Audio clock source. */
32+
typedef enum e_ssi_audio_clock
33+
{
34+
SSI_AUDIO_CLOCK_EXTERNAL = 0, ///< Audio clock source is the AUDIO_CLK input pin
35+
SSI_AUDIO_CLOCK_INTERNAL = 1, ///< Audio clock source is internal connection to a MCU specific GPT channel output
36+
} ssi_audio_clock_t;
37+
38+
/** Bit clock division ratio. Bit clock frequency = audio clock frequency / bit clock division ratio. */
39+
typedef enum e_ssi_clock_div
40+
{
41+
SSI_CLOCK_DIV_1 = 0, ///< Clock divisor 1
42+
SSI_CLOCK_DIV_2 = 1, ///< Clock divisor 2
43+
SSI_CLOCK_DIV_4 = 2, ///< Clock divisor 4
44+
SSI_CLOCK_DIV_6 = 8, ///< Clock divisor 6
45+
SSI_CLOCK_DIV_8 = 3, ///< Clock divisor 8
46+
SSI_CLOCK_DIV_12 = 9, ///< Clock divisor 12
47+
SSI_CLOCK_DIV_16 = 4, ///< Clock divisor 16
48+
SSI_CLOCK_DIV_24 = 10, ///< Clock divisor 24
49+
SSI_CLOCK_DIV_32 = 5, ///< Clock divisor 32
50+
SSI_CLOCK_DIV_48 = 11, ///< Clock divisor 48
51+
SSI_CLOCK_DIV_64 = 6, ///< Clock divisor 64
52+
SSI_CLOCK_DIV_96 = 12, ///< Clock divisor 96
53+
SSI_CLOCK_DIV_128 = 7, ///< Clock divisor 128
54+
} ssi_clock_div_t;
55+
56+
/** Channel instance control block. DO NOT INITIALIZE. Initialization occurs when @ref i2s_api_t::open is called. */
57+
typedef struct st_ssi_instance_ctrl
58+
{
59+
uint32_t open; // Whether or not this control block is initialized
60+
i2s_cfg_t const * p_cfg; // Initial configurations.
61+
R_SSI0_Type * p_reg; // Pointer to SSI register base address
62+
63+
/* Source buffer pointer used to fill hardware FIFO from transmit ISR. */
64+
void const * p_tx_src;
65+
66+
/* Size of source buffer used to fill hardware FIFO from transmit ISR. */
67+
uint32_t tx_src_samples;
68+
69+
/* Destination buffer pointer used to fill from hardware FIFO in receive ISR. */
70+
void * p_rx_dest;
71+
72+
/* Size of destination buffer used to fill from hardware FIFO in receive ISR. */
73+
uint32_t rx_dest_samples;
74+
transfer_size_t fifo_access_size; // Access the FIFO as 1 byte, 2 bytes, or 4 bytes
75+
76+
/* Pointer to callback and optional working memory */
77+
void (* p_callback)(i2s_callback_args_t *);
78+
i2s_callback_args_t * p_callback_memory;
79+
void const * p_context; // < User defined context passed into callback function
80+
} ssi_instance_ctrl_t;
81+
82+
/** SSI configuration extension. This extension is optional. */
83+
typedef struct st_ssi_extended_cfg
84+
{
85+
ssi_audio_clock_t audio_clock; ///< Audio clock source, default is SSI_AUDIO_CLOCK_EXTERNAL
86+
ssi_clock_div_t bit_clock_div; ///< Select bit clock division ratio
87+
} ssi_extended_cfg_t;
88+
89+
/**********************************************************************************************************************
90+
* Exported global variables
91+
**********************************************************************************************************************/
92+
93+
/** @cond INC_HEADER_DEFS_SEC */
94+
extern const i2s_api_t g_i2s_on_ssi;
95+
96+
/** @endcond */
97+
98+
/**********************************************************************************************************************
99+
* Function Prototypes
100+
**********************************************************************************************************************/
101+
102+
fsp_err_t R_SSI_Open(i2s_ctrl_t * const p_ctrl, i2s_cfg_t const * const p_cfg);
103+
fsp_err_t R_SSI_Stop(i2s_ctrl_t * const p_ctrl);
104+
fsp_err_t R_SSI_StatusGet(i2s_ctrl_t * const p_ctrl, i2s_status_t * const p_status);
105+
fsp_err_t R_SSI_Write(i2s_ctrl_t * const p_ctrl, void const * const p_src, uint32_t const bytes);
106+
fsp_err_t R_SSI_Read(i2s_ctrl_t * const p_ctrl, void * const p_dest, uint32_t const bytes);
107+
fsp_err_t R_SSI_WriteRead(i2s_ctrl_t * const p_ctrl, void const * const p_src, void * const p_dest,
108+
uint32_t const bytes);
109+
fsp_err_t R_SSI_Mute(i2s_ctrl_t * const p_ctrl, i2s_mute_t const mute_enable);
110+
fsp_err_t R_SSI_Close(i2s_ctrl_t * const p_ctrl);
111+
fsp_err_t R_SSI_CallbackSet(i2s_ctrl_t * const p_api_ctrl,
112+
void ( * p_callback)(i2s_callback_args_t *),
113+
void const * const p_context,
114+
i2s_callback_args_t * const p_callback_memory);
115+
116+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
117+
FSP_FOOTER
118+
119+
#endif // R_SSI_H
120+
121+
/*******************************************************************************************************************//**
122+
* @} (end defgroup SSI)
123+
**********************************************************************************************************************/

0 commit comments

Comments
 (0)