WM8731 example for SAM.
Data Structures | |
struct | wav_header |
Macros | |
#define | BITS_BY_SLOT (16) |
Bits per slot. More... | |
#define | DMA_CH 0 |
#define | MAX_WAV_SIZE 0x800000 |
Maximum size in bytes of the WAV file. More... | |
#define | RECORD_ADDRESS (WAV_FILE_ADDRESS + MAX_WAV_SIZE) |
Address at which the recorded sample is stored. More... | |
#define | SAMPLE_RATE (48000) |
Wav feature. More... | |
#define | SLOT_BY_FRAME (2) |
Wav slot per frame. More... | |
#define | WAV_CHUNKID 0x46464952 |
#define | WAV_FORMAT 0x45564157 |
#define | WAV_SUBCHUNKID 0x20746D66 |
Functions | |
static void | configure_console (void) |
Configure the console UART. More... | |
static void | display_menu (void) |
Displays the user menu on the DBGU. More... | |
static void | display_wav_info (void) |
Display the information of the WAV file (sample rate, stereo/mono and frame size). More... | |
void | DMAC_Handler (void) |
ISR for DMA interrupt. More... | |
static void | init_dac (void) |
Initial the WM8731 to play back the sample WAV file. More... | |
static void | init_dma (void) |
DMA driver configuration. More... | |
static void | init_ssc (void) |
Initial the ssc interface. More... | |
static void | init_twi_wm8731 (void) |
int | main (void) |
ssc_dma_audio Application entry point. More... | |
static void | ssc_dma (void *p_buffer, uint16_t us_size) |
Start DMA sending data. More... | |
static void | start_play_wav (uint32_t ul_wav_data_address, uint32_t ul_wav_size) |
Play a WAV file pre-loaded in PSRAM/SDRAM. More... | |
static void | stop_play_wav (void) |
Stop the current playback (if any). More... | |
Variables | |
static uint8_t | g_uc_is_wav_available = 0 |
Indicates if there is wav data. More... | |
static uint8_t | g_uc_is_wav_playing = 0 |
Indicates if the WAV file is currently being played. More... | |
static uint32_t | g_ul_remaining_bytes |
Number of samples that have not yet been transmitted. More... | |
static uint32_t | g_ul_transmitted_bytes |
Number of samples which have already been transmitted. More... | |
static struct wav_header * | p_wav_file |
Pointer to the playback WAV file header. More... | |
#define BITS_BY_SLOT (16) |
Bits per slot.
Referenced by init_ssc().
#define DMA_CH 0 |
Referenced by DMAC_Handler(), init_dma(), ssc_dma(), and stop_play_wav().
#define MAX_WAV_SIZE 0x800000 |
Maximum size in bytes of the WAV file.
#define RECORD_ADDRESS (WAV_FILE_ADDRESS + MAX_WAV_SIZE) |
Address at which the recorded sample is stored.
#define SAMPLE_RATE (48000) |
Wav feature.
Referenced by init_ssc().
#define SLOT_BY_FRAME (2) |
Wav slot per frame.
#define WAV_CHUNKID 0x46464952 |
Referenced by main().
#define WAV_FORMAT 0x45564157 |
Referenced by main().
#define WAV_SUBCHUNKID 0x20746D66 |
|
static |
Configure the console UART.
References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
|
static |
Displays the user menu on the DBGU.
References g_uc_is_wav_available, and g_uc_is_wav_playing.
Referenced by DMAC_Handler(), and main().
|
static |
Display the information of the WAV file (sample rate, stereo/mono and frame size).
References wav_header::audio_format, wav_header::bits_per_sample, wav_header::block_align, wav_header::byte_rate, wav_header::chunk_id, wav_header::chunk_size, wav_header::format, wav_header::num_channels, wav_header::sample_rate, wav_header::sub_chunk1_id, wav_header::sub_chunk1_size, wav_header::sub_chunk2_id, wav_header::sub_chunk2_size, and uart_read().
Referenced by main().
void DMAC_Handler | ( | void | ) |
ISR for DMA interrupt.
References wav_header::bits_per_sample, display_menu(), DMA_CH, dmac_get_status(), g_uc_is_wav_playing, g_ul_remaining_bytes, Min, and ssc_dma().
|
static |
Initial the WM8731 to play back the sample WAV file.
References init_twi_wm8731(), pmc_disable_pck(), pmc_enable_pck(), PMC_PCK_0, pmc_switch_pck_to_mainck(), wm8731_dac_select(), wm8731_power_mode_dac(), WM8731_REG_DIGITAL_AUDIO_INTERFACE_FORMAT_I2S, WM8731_REG_DIGITAL_AUDIO_INTERFACE_FORMAT_IWL_16_BIT, wm8731_reset(), wm8731_set_active(), wm8731_set_dac_soft_mute(), wm8731_set_digital_audio_data_bit_length(), and wm8731_set_sampling_control().
Referenced by main().
|
static |
DMA driver configuration.
References DMA_CH, dmac_channel_disable(), dmac_channel_set_configuration(), dmac_enable(), dmac_enable_interrupt(), dmac_init(), DMAC_PRIORITY_ROUND_ROBIN, dmac_set_priority_mode(), and pmc_enable_periph_clk().
Referenced by main().
|
static |
Initial the ssc interface.
References BITS_BY_SLOT, pmc_enable_periph_clk(), SAMPLE_RATE, ssc_disable_interrupt(), ssc_disable_tx(), ssc_reset(), ssc_set_clock_divider(), ssc_set_transmitter(), sysclk_get_peripheral_hz(), clock_opt_t::ul_ckg, clock_opt_t::ul_cki, clock_opt_t::ul_cko, clock_opt_t::ul_cks, data_frame_opt_t::ul_datlen, data_frame_opt_t::ul_datnb, data_frame_opt_t::ul_fsedge, data_frame_opt_t::ul_fslen, data_frame_opt_t::ul_fslen_ext, data_frame_opt_t::ul_fsos, data_frame_opt_t::ul_msbf, clock_opt_t::ul_period, clock_opt_t::ul_start_sel, and clock_opt_t::ul_sttdly.
Referenced by main().
|
static |
References twi_options::chip, twi_options::master_clk, twi_options::speed, sysclk_get_peripheral_hz(), twi_master_setup(), TWI_WM8731, and WM8731_SLAVE_ADDRESS.
Referenced by init_dac().
int main | ( | void | ) |
ssc_dma_audio Application entry point.
References board_init(), BOARD_NAME, wav_header::chunk_id, configure_console(), display_menu(), display_wav_info(), wav_header::format, g_uc_is_wav_available, g_uc_is_wav_playing, init_dac(), init_dma(), init_ssc(), pmc_enable_periph_clk(), wav_header::sample_rate, SDRAM_MICRON_MT48LC16M16A2, sdramc_init(), smc_set_cycle_timing(), smc_set_mode(), smc_set_pulse_timing(), smc_set_setup_timing(), start_play_wav(), stop_play_wav(), wav_header::sub_chunk1_size, wav_header::sub_chunk2_size, sysclk_get_peripheral_hz(), sysclk_init(), uart_read(), WAV_CHUNKID, WAV_FORMAT, and xmodem_receive_file().
|
static |
Start DMA sending data.
p_buffer | Pointer to the data to be transmitted. |
us_size | Size of the data to be transmitted. |
References DMA_CH, dmac_channel_enable(), dmac_channel_single_buf_transfer_init(), NULL, ssc_enable_tx(), dma_transfer_descriptor_t::ul_ctrlA, dma_transfer_descriptor_t::ul_ctrlB, dma_transfer_descriptor_t::ul_descriptor_addr, dma_transfer_descriptor_t::ul_destination_addr, and dma_transfer_descriptor_t::ul_source_addr.
Referenced by DMAC_Handler(), and start_play_wav().
|
static |
Play a WAV file pre-loaded in PSRAM/SDRAM.
ul_wav_data_address | The address of the WAVE file. |
ul_wav_size | Wave file size. |
References wav_header::bits_per_sample, g_uc_is_wav_playing, g_ul_remaining_bytes, g_ul_transmitted_bytes, Min, and ssc_dma().
Referenced by main().
|
static |
Stop the current playback (if any).
References DMA_CH, dmac_channel_stop_transfer(), g_uc_is_wav_playing, and ssc_disable_tx().
Referenced by main().
|
static |
Indicates if there is wav data.
Referenced by display_menu(), and main().
|
static |
Indicates if the WAV file is currently being played.
Referenced by display_menu(), DMAC_Handler(), main(), start_play_wav(), and stop_play_wav().
|
static |
Number of samples that have not yet been transmitted.
Referenced by DMAC_Handler(), and start_play_wav().
|
static |
Number of samples which have already been transmitted.
Referenced by start_play_wav().
|
static |
Pointer to the playback WAV file header.