HPM SDK
HPMicro Software Development Kit
hpm_wm8960.c File Reference
#include "hpm_wm8960.h"

Macros

#define HPM_WM8960_MCLK_TOLERANCE   (4U)
 

Functions

hpm_stat_t wm8960_init (wm8960_control_t *control, wm8960_config_t *config)
 WM8960 initialize function. More...
 
hpm_stat_t wm8960_deinit (wm8960_control_t *control)
 Deinit the WM8960 codec. More...
 
hpm_stat_t wm8960_set_protocol (wm8960_control_t *control, wm8960_protocol_t protocol)
 Set the audio transfer protocol. More...
 
hpm_stat_t wm8960_set_module (wm8960_control_t *control, wm8960_module_t module, bool enable)
 Enable/disable expected module. More...
 
hpm_stat_t wm8960_set_data_route (wm8960_control_t *control, wm8960_config_t *config)
 Set audio data route in WM8960. More...
 
hpm_stat_t wm8960_set_left_input (wm8960_control_t *control, wm8960_input_t input)
 Set left audio input source in WM8960. More...
 
hpm_stat_t wm8960_set_right_input (wm8960_control_t *control, wm8960_input_t input)
 Set right audio input source in WM8960. More...
 
hpm_stat_t wm8960_set_volume (wm8960_control_t *control, wm8960_module_t module, uint32_t volume)
 Set the volume of different modules in WM8960. More...
 
static bool wm8960_check_clock_tolerance (uint32_t source, uint32_t target)
 
hpm_stat_t wm8960_set_data_format (wm8960_control_t *control, uint32_t sysclk, uint32_t sample_rate, uint32_t bits)
 Configure the data format of audio data. More...
 
hpm_stat_t wm8960_config_input_to_output_mixer (wm8960_control_t *control, uint32_t play_source)
 SET the WM8960 play source. More...
 
hpm_stat_t wm8960_write_reg (wm8960_control_t *control, uint8_t reg, uint16_t val)
 Write register to WM8960 using I2C. More...
 
hpm_stat_t wm8960_read_reg (uint8_t reg, uint16_t *val)
 Read register from WM8960 using I2C. More...
 
hpm_stat_t wm8960_modify_reg (wm8960_control_t *control, uint8_t reg, uint16_t mask, uint16_t val)
 Modify some bits in the register using I2C. More...
 

Variables

static const uint16_t wm8960_default_reg_val [56U]
 
static uint16_t wm8960_reg_val [56U]
 

Macro Definition Documentation

◆ HPM_WM8960_MCLK_TOLERANCE

#define HPM_WM8960_MCLK_TOLERANCE   (4U)

Function Documentation

◆ wm8960_check_clock_tolerance()

static bool wm8960_check_clock_tolerance ( uint32_t  source,
uint32_t  target 
)
static

◆ wm8960_config_input_to_output_mixer()

hpm_stat_t wm8960_config_input_to_output_mixer ( wm8960_control_t control,
uint32_t  play_source 
)

SET the WM8960 play source.

Parameters
controlWM8960 control structure.
play_sourceplay source
Returns
kStatus_WM8904_Success if successful, different code otherwise..

◆ wm8960_deinit()

hpm_stat_t wm8960_deinit ( wm8960_control_t control)

Deinit the WM8960 codec.

This function close all modules in WM8960 to save power.

Parameters
controlWM8960 control structure pointer.

◆ wm8960_init()

hpm_stat_t wm8960_init ( wm8960_control_t control,
wm8960_config_t config 
)

WM8960 initialize function.

Parameters
controlWM8960 control structure.
configWM8960 configuration structure.

◆ wm8960_modify_reg()

hpm_stat_t wm8960_modify_reg ( wm8960_control_t control,
uint8_t  reg,
uint16_t  mask,
uint16_t  val 
)

Modify some bits in the register using I2C.

Parameters
controlWM8960 control structure.
regThe register address in WM8960.
maskThe mask code for the bits want to write. The bit you want to write should be 0.
valValue needs to write into the register.

◆ wm8960_read_reg()

hpm_stat_t wm8960_read_reg ( uint8_t  reg,
uint16_t *  val 
)

Read register from WM8960 using I2C.

Parameters
regThe register address in WM8960.
valValue written to.

◆ wm8960_set_data_format()

hpm_stat_t wm8960_set_data_format ( wm8960_control_t control,
uint32_t  sysclk,
uint32_t  sample_rate,
uint32_t  bits 
)

Configure the data format of audio data.

This function would configure the registers about the sample rate, bit depths.

Parameters
controlWM8960 control structure pointer.
sysclksystem clock of the codec which can be generated by MCLK or PLL output.
sample_rateSample rate of audio file running in WM8960. WM8960 now supports 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, 44.1k, 48k and 96k sample rate.
bitsBit depth of audio file (WM8960 only supports 16bit, 20bit, 24bit and 32 bit in HW).

◆ wm8960_set_data_route()

hpm_stat_t wm8960_set_data_route ( wm8960_control_t control,
wm8960_config_t config 
)

Set audio data route in WM8960.

This function would set the data route according to route.

Parameters
controlWM8960 control structure.
configAudio configure structure in WM8960.

◆ wm8960_set_left_input()

hpm_stat_t wm8960_set_left_input ( wm8960_control_t control,
wm8960_input_t  input 
)

Set left audio input source in WM8960.

Parameters
controlWM8960 control structure.
inputAudio input source.

◆ wm8960_set_module()

hpm_stat_t wm8960_set_module ( wm8960_control_t control,
wm8960_module_t  module,
bool  enable 
)

Enable/disable expected module.

Parameters
controlWM8960 control structure.
moduleModule expected to enable.
enableEnable or disable moudles.

◆ wm8960_set_protocol()

hpm_stat_t wm8960_set_protocol ( wm8960_control_t control,
wm8960_protocol_t  protocol 
)

Set the audio transfer protocol.

Parameters
controlWM8960 control structure.
protocolAudio data transfer protocol.

◆ wm8960_set_right_input()

hpm_stat_t wm8960_set_right_input ( wm8960_control_t control,
wm8960_input_t  input 
)

Set right audio input source in WM8960.

Parameters
controlWM8960 control structure.
inputAudio input source.

◆ wm8960_set_volume()

hpm_stat_t wm8960_set_volume ( wm8960_control_t control,
wm8960_module_t  module,
uint32_t  volume 
)

Set the volume of different modules in WM8960.

This function would set the volume of WM8960 modules. Uses need to appoint the module. The function assume that left channel and right channel has the same volume.

Module:wm8960_module_adc, volume range value: 0 is mute, 1-255 is -97db to 30db Module:wm8960_module_dac, volume range value: 0 is mute, 1-255 is -127db to 0db Module:wm8960_module_headphone, volume range value: 0 - 2F is mute, 0x30 - 0x7F is -73db to 6db Module:wm8960_module_ana_in, volume range value: 0 - 0x3F is -17.25db to 30db Module:wm8960_module_speaker, volume range value: 0 - 2F is mute, 0x30 - 0x7F is -73db to 6db

Parameters
controlWM8960 control structure.
moduleModule to set volume, it can be ADC, DAC, Headphone and so on.
volumeVolume value need to be set.

◆ wm8960_write_reg()

hpm_stat_t wm8960_write_reg ( wm8960_control_t control,
uint8_t  reg,
uint16_t  val 
)

Write register to WM8960 using I2C.

Parameters
controlWM8960 control structure.
regThe register address in WM8960.
valValue needs to write into the register.

Variable Documentation

◆ wm8960_default_reg_val

const uint16_t wm8960_default_reg_val[56U]
static
Initial value:
= {
0x0097, 0x0097, 0x0000, 0x0000, 0x0000, 0x0008, 0x0000, 0x000a, 0x01c0, 0x0000, 0x00ff, 0x00ff, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x007b, 0x0100, 0x0032, 0x0000, 0x00c3, 0x00c3, 0x01c0, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0100, 0x0100, 0x0050, 0x0050, 0x0050, 0x0050, 0x0000, 0x0000, 0x0000, 0x0000,
0x0040, 0x0000, 0x0000, 0x0050, 0x0050, 0x0000, 0x0002, 0x0037, 0x004d, 0x0080, 0x0008, 0x0031, 0x0026, 0x00e9,
}

◆ wm8960_reg_val

uint16_t wm8960_reg_val[56U]
static