RA Flexible Software Package Documentation
Release v5.7.0
|
|
Functions | |
fsp_err_t | RM_AUDIO_PLAYBACK_PWM_Open (audio_playback_ctrl_t *const p_api_ctrl, audio_playback_cfg_t const *const p_cfg) |
fsp_err_t | RM_AUDIO_PLAYBACK_PWM_Close (audio_playback_ctrl_t *const p_api_ctrl) |
fsp_err_t | RM_AUDIO_PLAYBACK_PWM_Start (audio_playback_ctrl_t *const p_api_ctrl) |
fsp_err_t | RM_AUDIO_PLAYBACK_PWM_Stop (audio_playback_ctrl_t *const p_api_ctrl) |
fsp_err_t | RM_AUDIO_PLAYBACK_PWM_Play (audio_playback_ctrl_t *const p_api_ctrl, void const *const p_buffer, uint32_t length) |
Driver for the Audio Playback middleware on RA MCUs. This module implements the AUDIO PLAYBACK Interface.
The Audio Playback with PWM middleware is used to play audio streams at user selected playback rate using Pulse Width Modulation hardware on GPT or AGT timers. This module can play 16-bit or 32-bit(available on selected MCUs) uncompressed, unsigned PCM audio stream when AGT is selected as PWM interface, and can play 32-bit uncompressed, unsigned PCM audio stream when GPT is used as PWM interface. Note some MCUs have 16-bit GPT timers/channels. In this case audio stream still needs to be 32 bits because the duty cycle register is 32-bit - just the upper 16 bits are ignored. The application code is expected to convert the signed PCM data to unsigned PCM data and scale it with the playback rate before starting the playback.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
DMAC Support |
| Disabled | Select if DMAC will be used. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Name | Name must be a valid C symbol | g_rm_audio_playback0 | Module name. |
Playback Speed (Hz) | Must be an integer and greater than 0 | 44100 | Enter playback sample rate in Hz. |
Interrupts | |||
Callback | Name must be a valid C symbol | g_rm_audio_playback0_callback | A user callback function. If this callback function is provided, it is called from the interrupt service routine (ISR) each time the playback completes. |
PWM Output Pin |
| Pin A | Select which timer output pin should be used for audio output. |
The Audio Playback with PWM module does not require a specific clock configuration.
Configure the PWM output pins for selected PWM HAL layer peripheral (AGT/GPT). One of the following pins needs to be selected and enabled as PWM output for selected channel n,
If GPT is used as PWM interface,
If AGT is used as PWM interface,
DMAC/DTC is used as a lower level transfer instance with this module and is operated in Normal mode to transfer 16 bit or 32 bit data from the audio stream buffer to the PWM peripheral AGT or GPT respectively. Destination address for transfer instance needs to be the Duty Cycle setting register GTCCR for GPT as PWM driver or AGTMA/AGTCMB in case of AGT as PWM driver. The Audio Playback with PWM module internally configures 'Transfer Size' as 2 Bytes if AGT is used for PWM generation, otherwise it configures 'Transfer Size" as 4 Bytes if GPT or AGTW is used for PWM generation. Refer the hardware manual to check whether the MCU supports AGT or the AGTW peripheral.
This is a basic example of minimal use of the RM_AUDIO_PLAYBACK_PWM in an application. This example shows how this driver can be used for playing a 16 bit uncompressed PCM audio from a single input buffer.
This is an example of using Audio Playback module to play audio stream. This application uses a double buffer to store PCM sine wave data. It starts playing in the main loop, then loads the next buffer if it is ready in the callback. If the next buffer is not ready, a flag is set in the callback so the application knows to restart playing in the main loop. This example also demonstrates conversion of signed PCM format data to unsigned PWM format data along with scaling the data samples for optimum PWM wave generation.
Data Structures | |
struct | audio_playback_pwm_instance_ctrl_t |
struct audio_playback_pwm_instance_ctrl_t |
AUDIO_PLAYBACK_PWM instance control block. DO NOT MODIFY. Initialization occurs when RM_AUDIO_PLAYBACK_PWM_Open() is called.
Data Fields | |
void(* | p_callback )(audio_playback_callback_args_t *p_args) |
void * | p_context |
audio_playback_cfg_t const * | p_cfg |
Pointer to the configuration structure. | |
uint32_t | open |
Used by driver to check if the control structure is valid. | |
timer_instance_t const * | p_lower_lvl_timer |
Timer API used to generate sampling frequency and GPT/AGT API used to access PWM hardware. | |
transfer_instance_t const * | p_lower_lvl_transfer |
Transfer API used to transfer data each sampling frequency. | |
void(* audio_playback_pwm_instance_ctrl_t::p_callback) (audio_playback_callback_args_t *p_args) |
Callback called when play is complete.
void* audio_playback_pwm_instance_ctrl_t::p_context |
Placeholder for user data. Passed to the user callback in audio_playback_callback_args_t.
fsp_err_t RM_AUDIO_PLAYBACK_PWM_Open | ( | audio_playback_ctrl_t *const | p_api_ctrl, |
audio_playback_cfg_t const *const | p_cfg | ||
) |
Opens and configures the Audio Playback with PWM driver. Sets playback speed and transfer rate to read the audio buffer.
Example:
FSP_SUCCESS | Audio Playback module successfully configured. |
FSP_ERR_ALREADY_OPEN | Module already open. |
FSP_ERR_ASSERTION | One or more pointers point to NULL or callback is NULL. |
fsp_err_t RM_AUDIO_PLAYBACK_PWM_Close | ( | audio_playback_ctrl_t *const | p_api_ctrl | ) |
Closes the module driver. Enables module stop mode.
FSP_SUCCESS | Module successfully closed. |
FSP_ERR_NOT_OPEN | Driver not open. |
FSP_ERR_ASSERTION | Pointer pointing to NULL. |
fsp_err_t RM_AUDIO_PLAYBACK_PWM_Start | ( | audio_playback_ctrl_t *const | p_api_ctrl | ) |
Start the PWM HAL driver (AGT or GPT) and timer HAL (AGT or GPT) drivers.
FSP_SUCCESS | Audio playback hardware started successfully. |
FSP_ERR_ASSERTION | The parameter p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Driver not open. This function calls |
fsp_err_t RM_AUDIO_PLAYBACK_PWM_Stop | ( | audio_playback_ctrl_t *const | p_api_ctrl | ) |
Stop the PWM HAL driver (AGT or GPT) and timer HAL driver (AGT or GPT).
FSP_SUCCESS | Audio playback hardware stopped successfully. |
FSP_ERR_ASSERTION | The parameter p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Driver not open. This function calls |
fsp_err_t RM_AUDIO_PLAYBACK_PWM_Play | ( | audio_playback_ctrl_t *const | p_api_ctrl, |
void const *const | p_buffer, | ||
uint32_t | length | ||
) |
Play a single audio buffer by input samples to the PWM HAL (AGT or GPT) at the sampling frequency configured by the timer.
FSP_SUCCESS | Buffer playback began successfully. |
FSP_ERR_ASSERTION | The parameter p_ctrl or p_buffer is NULL or buffer length is greater than 0x10000. |
FSP_ERR_NOT_OPEN | Driver not open.. This function calls |