这个页面的 最新开发版本 可能比这个发布的 2.3-beta.1 版本新。

CODEC_I2S API 参考

CODEC_I2S

enum wm_drv_codec_i2s_type_t

codec i2s work modules

Values:

enumerator WM_DRV_CODEC_I2S_MODE_NONE
enumerator WM_DRV_CODEC_I2S_MODE_IN

Use ADC, only support input

enumerator WM_DRV_CODEC_I2S_MODE_OUT

Use DAC, only support output Use ADC and DAC, support input and output

enumerator WM_DRV_CODEC_I2S_MODE_INOUT

Use ADC and DAC, support input and output, The voice from mic will mix to output

enumerator WM_DRV_CODEC_I2S_MODE_INOUT_MIX_MIC_OUT
enumerator WM_DRV_CODEC_I2S_MODE_MAX
enum wm_drv_codec_i2s_output_type_t

codec i2s output type

Values:

enumerator WM_DRV_CODEC_I2S_OUTPORT_SPEAKER

Output to speaker

enumerator WM_DRV_CODEC_I2S_OUTPORT_HEADPHONE

Output to headphone Output to speaker and headphone

enumerator WM_DRV_CODEC_I2S_OUTPORT_SPEAKER_HEADPHONE
struct wm_drv_codec_i2s_cfg_t

codec i2s config

Public Members

enum wm_i2s_mode mode

master or slave mode

enum wm_i2s_std std

codec i2s protocol standard

wm_drv_codec_i2s_type_t type

codec type use

uint32_t mclk

mclk,unit hz ,set to 0 before init

struct wm_drv_codec_i2s_ctx_t

codec i2s context

Public Members

void *mutex

mutex to access codec api

bool is_start

start or not

void *hw

codec hardware infomation

wm_device_t *i2s_dev

i2s controller device

wm_drv_codec_i2s_cfg_t cfg

configuration for codec

wm_device_t *ctrl_dev

i2c contol device

uint16_t ctrl_addr

i2c address

uint32_t sample_rate

sample rate

wm_gpio_num_t power_pin

power pin

void *pri

private data

struct wm_drv_codec_i2s_ops_t

codec i2s ops struct

Public Members

int (*set_volume)(wm_device_t *device, int vol)

vol : 0~100

int (*set_mic_volume)(wm_device_t *device, int vol)

vol : 0~100

int (*set_reg)(wm_device_t *device, int reg, int value)

Set value to codec register

int (*get_reg)(wm_device_t *device, int reg, int *value)

Get valule from codec register

wm_device_t *wm_drv_codec_i2s_init(const char *name, wm_drv_codec_i2s_cfg_t *cfg)

Initializes the WM DRV_I2S_CODEC device.

This function initializes the WM DRV_I2S_CODEC device with the given configuration. It allocates memory for the device structure, sets the device name, and initializes the device operations structure with the provided function pointers.

参数:
  • name[in] The name of the device to be initialized.

  • cfg[in] A pointer to the configuration structure for the device.

返回:

A pointer to the initialized device structure on success, or NULL on failure.

int wm_drv_codec_i2s_deinit(wm_device_t *device)

Deinitializes the WM DRV_I2S_CODEC device.

This function deinitializes the WM DRV_I2S_CODEC device and frees any allocated resources. It calls the deinit function pointer in the device operations structure to perform the actual deinitialization.

参数:

device[in] A pointer to the device structure representing the WM DRV_I2S_CODEC device.

返回:

WM_SUCCESS on success, or an appropriate error code on failure.

int wm_drv_codec_i2s_set_format(wm_device_t *device, uint32_t sample_rate_hz, enum wm_i2s_bits bits, enum wm_i2s_chan_type channel)

set codec audio format

备注

Called before starting read/write

参数:
  • device[in] A pointer to the codec device to be deinitialized.

  • sample_rate_hz[in] sample rate, unit Hz.

  • bits[in] the sample bits witdh

  • channel[in] channel type

返回:

  • WM_ERR_SUCESS: If the deinitialization is successful.

  • others: If the deinitialization fails

int wm_drv_codec_i2s_start(wm_device_t *device)

Starts the I2S codec device for data transfer.

This function initializes the I2S codec device for data transfer, enabling the device to start receiving or transmitting data based on the configured mode.

备注

This function should be called after the device has been initialized and configured.

参数:

device[in] A pointer to the device structure representing the I2S codec device.

返回:

WM_SUCCESS on success, or an appropriate error code on failure.

int wm_drv_codec_i2s_stop(wm_device_t *device)

Stops the I2S codec device for data transfer.

This function disables the I2S codec device, stopping it from receiving or transmitting data. It is typically called when the device is no longer needed for data transfer.

备注

This function should be called after the device has been initialized and configured. It is important to ensure that the device is properly deinitialized after stopping to free any allocated resources.

参数:

device[in] A pointer to the device structure representing the I2S codec device.

返回:

WM_SUCCESS on success, or an appropriate error code on failure.

int wm_drv_codec_i2s_set_mute(wm_device_t *device, bool mute)

set output mute.

参数:
  • device[in] A pointer to the device structure representing the I2S codec device.

  • mute[in] ture:mute output, false: not mute

返回:

  • WM_ERR_SUCCESS

  • WM_ERR_INVALID_PARAM

int wm_drv_codec_i2s_set_volume(wm_device_t *device, int vol)

set output volume level.

参数:
  • device[in] A pointer to the device structure representing the I2S codec device.

  • vol[in] volume level, from 0 to 100

返回:

  • WM_ERR_SUCCESS

  • WM_ERR_INVALID_PARAM

int wm_drv_codec_i2s_set_mic_mute(wm_device_t *device, bool mute)

set mic mute.

参数:
  • device[in] A pointer to the device structure representing the I2S codec device.

  • mute[in] ture:mute output, false: not mute

返回:

  • WM_ERR_SUCCESS

  • WM_ERR_INVALID_PARAM

int wm_drv_codec_i2s_set_mic_volume(wm_device_t *device, int vol)

set mic level

参数:
  • device[in] A pointer to the device structure representing the I2S codec device.

  • vol[in] volume level, 0~100.

返回:

  • WM_ERR_SUCCESS

  • WM_ERR_INVALID_PARAM

int wm_drv_codec_i2s_set_reg(wm_device_t *device, int reg, int value)

Set value to codec register.

参数:
  • device[in] A pointer to the device structure representing the I2S codec device.

  • reg[in] codec register address

  • value[in] the value to set

返回:

  • WM_ERR_SUCCESS

  • WM_ERR_INVALID_PARAM

int wm_drv_codec_i2s_get_reg(wm_device_t *device, int reg, int *value)

Get valule from codec register.

参数:
  • device[in] A pointer to the device structure representing the I2S codec device.

  • reg[in] codec register address

  • value[out] the value to set

返回:

  • WM_ERR_SUCCESS

  • WM_ERR_INVALID_PARAM

int wm_drv_codec_i2s_dump(wm_device_t *device)

Prints debug information about the I2S codec device.

This function prints debug information about the I2S codec device, including relevant configuration settings, internal state, and any other relevant information. It is intended for debugging purposes and should not be used in production code.

备注

This function should be called after the device has been initialized and configured. The output of this function may vary depending on the specific implementation of the I2S codec device.

参数:

device[in] A pointer to the device structure representing the I2S codec device.

返回:

WM_SUCCESS on success, or an appropriate error code on failure.