320 lines
7.6 KiB
C
320 lines
7.6 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _IOT_I2S_API_H
|
|
#define _IOT_I2S_API_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** \defgroup BSP_APIs I2S APIs
|
|
* @brief I2S APIs
|
|
*
|
|
*
|
|
*/
|
|
|
|
/** @addtogroup I2S_APIs
|
|
* @{
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* @brief Usage:
|
|
|
|
uint32_t iot_dtest_dma_recv(uint8_t *buf, uint32_t len) {
|
|
//callback function
|
|
......;
|
|
}
|
|
|
|
uint32_t iot_dtest_dma_send(uint8_t *buf, uint32_t len) {
|
|
// callback function
|
|
}
|
|
|
|
// prepare i2s config struction, this example is to enable dual-channel
|
|
// transfer and receive config
|
|
i2s_config_t i2s_cfg = {0};
|
|
|
|
i2s_cfg.clk = 44000;
|
|
i2s_cfg.type = I2S_TYPE_MSTR_TX | I2S_TYPE_SLAV_RX;
|
|
i2s_cfg.bit_mode = I2S_BITS_24BIT;
|
|
i2s_cfg.msb_right = I2S_MSB_RIGHT_BIT1;
|
|
|
|
i2s_cfg.tx_cfg.data_fmt = I2S_DATA_FMT_DUAL_BIT16;
|
|
i2s_cfg.tx_cfg.chl_sel = I2S_CHL_SEL_DUAL;
|
|
i2s_cfg.tx_cfg.msb_shift = I2S_SHIFT_PHILIPS_ENA;
|
|
i2s_cfg.tx_cfg.tx_desc_num = 8;
|
|
i2s_cfg.tx_cfg.send = iot_dtest_dma_send;
|
|
|
|
i2s_cfg.rx_cfg.data_fmt = I2S_DATA_FMT_DUAL_BIT16;
|
|
i2s_cfg.rx_cfg.chl_sel = I2S_CHL_SEL_DUAL;
|
|
i2s_cfg.rx_cfg.msb_shift = I2S_SHIFT_PHILIPS_ENA;
|
|
i2s_cfg.rx_cfg.rx_eof_len = 160;
|
|
i2s_cfg.rx_cfg.recv = iot_dtest_dma_recv;
|
|
|
|
i2s_pin_sel_t pin_master = {8, 9, 10};
|
|
i2s_pin_sel_t pin_slave = {22, 23, 28};
|
|
i2s_cfg.pin_master = &pin_master;
|
|
i2s_cfg.pin_slave = &pin_slave;
|
|
|
|
// call init function
|
|
if (iot_i2s_module_init(&i2s_cfg)) {
|
|
// ... error
|
|
}
|
|
|
|
// send i2s data
|
|
while(1) {
|
|
if (iot_i2s_push_pool(data, data_len)) {
|
|
// some error, retry
|
|
} else {
|
|
// send data successful
|
|
break;
|
|
}
|
|
}
|
|
// call deinit function
|
|
if (iot_i2s_module_deinit(&i2s_cfg)) {
|
|
// ... error
|
|
}
|
|
*/
|
|
#define I2S_MASTER_MODE 0
|
|
#define I2S_SLAVE_MODE 1
|
|
|
|
#define I2S_PDM_MASTER_MODE 0
|
|
#define I2S_PDM_SLAVE_MODE 1
|
|
|
|
#define STANDARD_MODE 1
|
|
|
|
#define I2S_DIR_TX 1
|
|
#define I2S_DIR_RX 0
|
|
|
|
typedef uint32_t (*iot_i2s_dma_rcv_func) (unsigned char port, uint8_t* buf, uint32_t len);
|
|
typedef uint32_t (*iot_i2s_dma_send_func) (unsigned char port, uint8_t *buf, uint32_t len,
|
|
uint8_t seq_num);
|
|
|
|
typedef enum {
|
|
I2S_TYPE_MSTR_TX = 1,
|
|
I2S_TYPE_MSTR_RX = 2,
|
|
I2S_TYPE_SLAV_TX = 4,
|
|
I2S_TYPE_SLAV_RX = 8,
|
|
I2S_TYPE_PDM_MODE_MSTR_RX = 0x10,
|
|
I2S_TYPE_PDM_MODE_MSTR_TX = 0x20,
|
|
I2S_TYPE_PDM_MODE_SLAV_RX = 0x40,
|
|
I2S_TYPE_PDM_MODE_SLAV_TX = 0x80,
|
|
} i2s_type_t;
|
|
|
|
typedef enum {
|
|
I2S_BITS_16BIT = 0,
|
|
I2S_BITS_24BIT = 8,
|
|
} i2s_bits_sample_t;
|
|
|
|
typedef enum {
|
|
I2S_0 = 0,
|
|
I2S_1 = 1,
|
|
I2S_2 = 2,
|
|
I2S_3 = 3,
|
|
I2S_4 = 4,
|
|
I2S_MAX,
|
|
} i2s_port_t;
|
|
|
|
|
|
typedef enum {
|
|
I2S_DATA_FMT_DUAL_BIT16 = 0,
|
|
I2S_DATA_FMT_SIG_BIT16 = 1,
|
|
I2S_DATA_FMT_DUAL_BIT24 = 2,
|
|
I2S_DATA_FMT_SIG_BIT24 = 3,
|
|
} i2s_data_fmt_t;
|
|
|
|
typedef enum {
|
|
I2S_CHL_SEL_DUAL = 0,
|
|
I2S_CHL_SEL_SIG_LEFT = 1,
|
|
I2S_CHL_SEL_SIG_RIGHT = 2,
|
|
I2S_CHL_SEL_SIG_LEFT_REG = 3,
|
|
I2S_CHL_SEL_SIG_RIGHT_REG = 4,
|
|
} i2s_chl_sel_t;
|
|
|
|
typedef enum {
|
|
I2S_MSB_RIGHT_BIT0 = 0,
|
|
I2S_MSB_RIGHT_BIT1 = 1,
|
|
} i2s_msb_right_t;
|
|
|
|
typedef enum {
|
|
I2S_SHIFT_PHILIPS_DIS = 0,
|
|
I2S_SHIFT_PHILIPS_ENA =1,
|
|
} i2s_msb_shift_t;
|
|
|
|
typedef struct _i2s_pin_sel {
|
|
uint8_t bck;
|
|
uint8_t ws;
|
|
uint8_t data;
|
|
} i2s_pin_sel_t;
|
|
|
|
typedef struct _i2s_pdm_dir {
|
|
uint8_t dir;
|
|
uint8_t mode;
|
|
uint8_t phase;
|
|
uint8_t hp_bypass;
|
|
uint8_t sinc16;
|
|
uint8_t rx_hp_dsample;
|
|
uint8_t tx_sd_scale;
|
|
uint32_t clk;
|
|
i2s_pin_sel_t *pin;
|
|
} i2s_pdm_dir_t;
|
|
|
|
typedef struct _i2s_tx_cfg {
|
|
/** tx descript number */
|
|
uint8_t tx_desc_num;
|
|
/** tx dma send callback function */
|
|
iot_i2s_dma_send_func send;
|
|
/** tx channel format */
|
|
i2s_data_fmt_t data_fmt;
|
|
/** tx channel mode select */
|
|
i2s_chl_sel_t chl_sel;
|
|
/** set this bit to enable Philips mode */
|
|
i2s_msb_shift_t msb_shift;
|
|
} i2s_tx_cfg_t;
|
|
|
|
typedef struct _i2s_rx_cfg {
|
|
/** rx descript number */
|
|
uint8_t rx_desc_num;
|
|
/** rx frame length to indicate dma the end */
|
|
uint32_t rx_eof_len;
|
|
/** rx dma recv callback function */
|
|
iot_i2s_dma_rcv_func recv;
|
|
/** rx channel format */
|
|
i2s_data_fmt_t data_fmt;
|
|
/** rx channel mode select */
|
|
i2s_chl_sel_t chl_sel;
|
|
/** set this bit to enable Philips mode */
|
|
i2s_msb_shift_t msb_shift;
|
|
} i2s_rx_cfg_t;
|
|
|
|
typedef struct _i2s_config {
|
|
uint8_t port;
|
|
uint8_t rx_mic_mode;
|
|
uint32_t clk;
|
|
i2s_type_t type;
|
|
i2s_bits_sample_t bit_mode;
|
|
i2s_msb_right_t msb_right;
|
|
i2s_tx_cfg_t tx_cfg;
|
|
i2s_rx_cfg_t rx_cfg;
|
|
i2s_pin_sel_t *pin_master;
|
|
i2s_pin_sel_t *pin_slave;
|
|
} i2s_config_t;
|
|
|
|
typedef struct _i2s_pdm_cfg {
|
|
uint8_t port;
|
|
uint8_t rx_mic_mode;
|
|
i2s_type_t type;
|
|
i2s_pdm_dir_t *pdm_tx;
|
|
i2s_pdm_dir_t *pdm_rx;
|
|
iot_i2s_dma_rcv_func recv;
|
|
iot_i2s_dma_send_func send;
|
|
uint32_t lphp_filter;
|
|
} i2s_pdm_cfg_t;
|
|
|
|
/**
|
|
* @brief iot_i2s_module_init() - i2s module init function
|
|
* @param i2c_config: i2s configure instruction
|
|
*
|
|
* @return other -- fail
|
|
* @return 0 -- success
|
|
*
|
|
*/
|
|
uint8_t iot_i2s_module_init(i2s_config_t *cfg);
|
|
|
|
|
|
/**
|
|
* @brief iot_i2s_module_deinit() - i2s module deinit function
|
|
* @param i2c_config: i2s configure instruction
|
|
*
|
|
* @return other -- fail
|
|
* @return 0 -- success
|
|
*
|
|
*/
|
|
uint8_t iot_i2s_module_deinit(i2s_config_t *cfg);
|
|
|
|
|
|
/**
|
|
* @brief iot_i2s_push_pool() - push(write) data to I2S rx buffer
|
|
* @param port: IIS port num
|
|
* @param src: pointer to buffer
|
|
* @param size: the size of data
|
|
*
|
|
* @return other -- fail
|
|
* @return ERR_OK -- success
|
|
* @return ERR_BUSY -- ring buffer full
|
|
*
|
|
*/
|
|
uint8_t iot_i2s_push_pool(uint8_t port, char *src, uint32_t size);
|
|
|
|
|
|
/**
|
|
* @brief iot_i2s_start_record() - start I2S's record.
|
|
* @param port: IIS port num
|
|
*
|
|
* @return ERR_FAIL -- fail
|
|
* @return ERR_OK -- success
|
|
*
|
|
*/
|
|
uint8_t iot_i2s_start_record(uint8_t port);
|
|
|
|
|
|
/**
|
|
* @brief iot_i2s_pause_record() - pause I2S's record.
|
|
* @param port: IIS port num
|
|
*
|
|
* @return ERR_FAIL -- fail
|
|
* @return ERR_OK -- success
|
|
|
|
*
|
|
*/
|
|
uint8_t iot_i2s_pause_record(uint8_t port);
|
|
|
|
|
|
/**
|
|
* @brief iot_i2s_pdm_init() - i2s pdm init function
|
|
* @param i2s_pdm_cfg_t i2s configure instruction
|
|
*
|
|
* @return other -- fail
|
|
* @return 0 -- success
|
|
*
|
|
*/
|
|
uint8_t iot_i2s_pdm_init(i2s_pdm_cfg_t *cfg);
|
|
|
|
/**
|
|
* @brief iot_i2s_set_mclk() - i2s set mclk
|
|
* @param gpio gpio number
|
|
* @param clk mclk frequency
|
|
*
|
|
* @return other -- fail
|
|
* @return 0 -- success
|
|
*
|
|
*/
|
|
uint8_t iot_i2s_set_mclk(uint8_t gpio, uint32_t clk);
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // _IOT_LOG_API_H
|
|
|