747 lines
17 KiB
C
Executable File
747 lines
17 KiB
C
Executable File
/****************************************************************************
|
|
|
|
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 I2S_H
|
|
#define I2S_H
|
|
|
|
#include "iot_i2s_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define I2S_CHECK(a) \
|
|
if (!(a)) { \
|
|
return ERR_FAIL; \
|
|
} \
|
|
|
|
#ifndef OK
|
|
#define OK 0
|
|
#endif
|
|
|
|
typedef enum {
|
|
I2S_SADC = 0,
|
|
I2S_TX = 1,
|
|
I2S_RX = 2,
|
|
I2S_RX_MIC = 4,
|
|
}I2S_TYPE;
|
|
|
|
#define ENABLE 1
|
|
#define DISABLE 0
|
|
|
|
#define I2C_CLV_32X64K 32
|
|
#define I2C_CLV_44X64K 44
|
|
|
|
/**
|
|
* @brief i2s_tx_master_gpio_set() - select master send gpio pin
|
|
*
|
|
* @param port port_num
|
|
* @param bck i2s bck gpio
|
|
* @param ws i2s ws gpio
|
|
* @param data i2s data gpio
|
|
*
|
|
* @return 0 -- success
|
|
* @return other -- fail
|
|
*/
|
|
uint8_t iot_i2s_tx_master_gpio_set(uint8_t port, uint8_t bck, uint8_t ws, uint8_t data);
|
|
|
|
/**
|
|
* @brief i2s_tx_slav_gpio_set() - select slave send gpio pin
|
|
*
|
|
* @param port port_num
|
|
* @param bck i2s bck gpio
|
|
* @param ws i2s ws gpio
|
|
* @param data i2s data gpio
|
|
*
|
|
* @return 0 -- success
|
|
* @return other -- fail
|
|
*/
|
|
uint8_t iot_i2s_tx_slav_gpio_set(uint8_t port, uint8_t bck, uint8_t ws, uint8_t data);
|
|
|
|
/**
|
|
* @brief i2s_rx_master_gpio_set() - select master receive gpio pin
|
|
*
|
|
* @param port port num
|
|
* @param bck i2s bck gpio
|
|
* @param ws i2s ws gpio
|
|
* @param data i2s data gpio
|
|
*
|
|
* @return 0 -- success
|
|
* @return other -- fail
|
|
*/
|
|
uint8_t iot_i2s_rx_master_gpio_set
|
|
(uint8_t port, uint8_t bck, uint8_t ws, uint8_t data);
|
|
|
|
/**
|
|
* @brief i2s_rx_slav_gpio_set() - select slave receive gpio pin
|
|
*
|
|
* @param port port num
|
|
* @param bck i2s bck gpio
|
|
* @param ws i2s ws gpio
|
|
* @param data i2s data gpio
|
|
*
|
|
* @return 0 -- success
|
|
* @return other -- fail
|
|
*/
|
|
uint8_t iot_i2s_rx_slav_gpio_set
|
|
(uint8_t port, uint8_t bck, uint8_t ws, uint8_t data);
|
|
|
|
/**
|
|
* @brief i2s_clk_cfg() - config the i2s clock
|
|
*
|
|
* @param port port_num
|
|
* @param freq clock frequence
|
|
*
|
|
*/
|
|
void i2s_clk_cfg(uint8_t port, uint32_t freq);
|
|
|
|
/**
|
|
* @brief i2s_clk_div() - i2s clock division
|
|
*
|
|
* @param port port_num
|
|
* @param div division factor
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_clk_div(unsigned char port, uint32_t div);
|
|
|
|
/**
|
|
* @brief i2s_bit_mode_set() - config the i2s clock
|
|
*
|
|
* @param port port_num
|
|
* @param bm 0-16bit, 8-24bit
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
uint8_t i2s_bit_mode_set(unsigned char port, uint8_t bm);
|
|
|
|
/**
|
|
* @brief i2s_tx_msb_shift_set() - set the transimter in philips mode or not
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-nomal mode, 1-philips mode
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_tx_msb_shift_set(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_rx_msb_shift_set() - set the receiver in philips mode or not
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-nomal mode, 1-philips mode
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_rx_msb_shift_set(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_tx_start() - enable i2s transimit or not
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_tx_start(unsigned char port);
|
|
|
|
/**
|
|
* @brief i2s_tx_stop() - stop i2s transimit or not
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_tx_stop(unsigned char port);
|
|
|
|
/**
|
|
* @brief i2s_rx_start() - enable i2s transimit
|
|
*
|
|
* @param port port_num
|
|
* @param NULL
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_rx_start(unsigned char port);
|
|
|
|
/**
|
|
* @brief i2s_rx_stop() - disable i2s transimit
|
|
*
|
|
* @param port port_num
|
|
* @param NULL
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_rx_stop(unsigned char port);
|
|
|
|
/**
|
|
* @brief i2s_msb_right() - enable i2s MSB on right channel
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disable,1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_msb_right(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_right_first() - enable right channel first
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disable,1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_right_first(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_transive_mode() - set the i2s transive mode
|
|
*
|
|
* @param port port_num
|
|
* @param dir 0-write, 1-read
|
|
* @param mode 0-master, 1-slave
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_transive_mode(unsigned char port, unsigned char dir,unsigned char mode);
|
|
|
|
/**
|
|
* @brief i2s_tx_fifo_reset() - enable/disable tx fifo reset
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disabel, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_tx_fifo_reset(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_rx_fifo_reset() - enable/disable rx fifo reset
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disabel, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_rx_fifo_reset(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_rx_reset() - enable/disable rx interface reset
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disabel, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_rx_reset(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_tx_reset() - enable/disable tx interface reset
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disabel, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return non-0: error
|
|
*
|
|
*/
|
|
int i2s_tx_reset(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_int_raw_get() - get the raw interrupt status
|
|
*
|
|
* @param port port_num
|
|
* @param NULL
|
|
*
|
|
* @return 0: no interrupt
|
|
* @return non-0: interrupt status
|
|
*
|
|
*/
|
|
int i2s_int_raw_get(unsigned char port);
|
|
|
|
/**
|
|
* @brief i2s_int_raw_get() - get the raw bit interrupt status
|
|
*
|
|
* @param port port_num
|
|
* @param offset the interrupt bit
|
|
*
|
|
* @return 0: no interrupt
|
|
* @return 1: interrupt occured
|
|
*
|
|
*/
|
|
int i2s_int_raw_bit_get(unsigned char port, char offset);
|
|
|
|
/**
|
|
* @brief i2s_int_status_get() - get the interrupt status
|
|
*
|
|
* @param port port_num
|
|
* @param NULL
|
|
*
|
|
* @return 0: no interrupt
|
|
* @return non-0: interrupt status
|
|
*
|
|
*/
|
|
int i2s_int_status_get(unsigned char port);
|
|
|
|
/**
|
|
* @brief i2s_int_status_bit_get() - get the raw bit interrupt status
|
|
*
|
|
* @param port port_num
|
|
* @param offset the interrupt bit
|
|
*
|
|
* @return 0: no interrupt
|
|
* @return 1: interrupt occured
|
|
*
|
|
*/
|
|
int i2s_int_status_bit_get(unsigned char port, char offset);
|
|
|
|
/**
|
|
* @brief i2s_int_enable_set() - enable/disable the interrupt bits
|
|
*
|
|
* @param port port_num
|
|
* @param mask the interrupt bits
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_int_enable_set(unsigned char port, unsigned int mask);
|
|
|
|
/**
|
|
* @brief i2s_int_enable_bit_set() - enable/disable the interrupt bit
|
|
*
|
|
* @param port port_num
|
|
* @param offset the interrupt bit
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_int_enable_bit_set(unsigned char port, unsigned char offset, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_int_clear_set() - clear the interrupt flags
|
|
*
|
|
* @param port port_num
|
|
* @param mask the interrupt bit
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_int_clear_set(unsigned char port, unsigned int mask);
|
|
|
|
/**
|
|
* @brief i2s_int_clear_bit_set() - clear the interrupt flag
|
|
*
|
|
* @param port port_num
|
|
* @param offset the interrupt bit
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_int_clear_bit_set(unsigned char port, unsigned char offset, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_timing_set() - clear the interrupt flag
|
|
*
|
|
* @param port port_num
|
|
* @param offset signal offset
|
|
* @param val delay number
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_timing_set(unsigned char port, unsigned char offset,unsigned char val);
|
|
|
|
/**
|
|
* @brief i2s_fifo_cfg_set() - configuration fifo
|
|
*
|
|
* @param port port_num
|
|
* @param offset signal offset
|
|
* @param mask mask value
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_fifo_cfg_set(unsigned char port, unsigned int mask);
|
|
|
|
/**
|
|
* @brief i2s_fifo_rx_mode_set() - configuration fifo format
|
|
*
|
|
* @param port port_num
|
|
* @param mode 00-16 bit dual, 01-16bit single
|
|
* 02-24 bit dual, 03-24bit single
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_fifo_rx_mode_set(unsigned char port, unsigned int mode);
|
|
|
|
/**
|
|
* @brief i2s_fifo_tx_mode_set() - configuration fifo format
|
|
*
|
|
* @param port port_num
|
|
* @param mode 00-16 bit dual, 01-16bit single
|
|
* 02-24 bit dual, 03-24bit single
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_fifo_tx_mode_set(unsigned char port, unsigned int mode);
|
|
|
|
/**
|
|
* @brief i2s_dma_mode_en() - enable/disable dma mode
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_dma_mode_en(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_tx_data_num_set() - set send count of data
|
|
*
|
|
* @param port port_num
|
|
* @param num data number
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_tx_data_num_set(unsigned char port, unsigned char num);
|
|
|
|
/**
|
|
* @brief i2s_rx_data_num_set() - set receive count of data
|
|
*
|
|
* @param port port_num
|
|
* @param num data number
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_rx_data_num_set(unsigned char port, unsigned char num);
|
|
|
|
/**
|
|
* @brief i2s_rx_eof_num_set() - set frame lenth
|
|
*
|
|
* @param port port_num
|
|
* @param num data lenth
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_rx_eof_num_set(unsigned char port, unsigned int num);
|
|
|
|
/**
|
|
* @brief i2s_sigle_data_num_set() - set constan value when in single mode
|
|
*
|
|
* @param port port_num
|
|
* @param num data
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_sigle_data_num_set(unsigned char port, unsigned int num);
|
|
|
|
/**
|
|
* @brief i2s_tx_chan_mode_set() - set transimit mode
|
|
*
|
|
* @param port port_num
|
|
* @param mode 00-dual mode, 01-04 mono mode
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_tx_chan_mode_set(unsigned char port, unsigned char mode);
|
|
|
|
/**
|
|
* @brief i2s_rx_chan_mode_set() - set receive mode
|
|
*
|
|
* @param port port_num
|
|
* @param mode 00-dual mode, 01-04 mono mode
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_rx_chan_mode_set(unsigned char port, unsigned char mode);
|
|
|
|
/**
|
|
* @brief i2s_pdm_hp_bypass_en() - enable/disablel pdm hihg pass filter
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_hp_bypass_en(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_pdm_sadc_64bit_en() - chose one/four phase data to be processed
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-phase1, 1-4 phase0-3
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_sadc_64bit_en(unsigned char port, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_pdm_sadc_dump_en() - diable/enable sadc bypass
|
|
*
|
|
* @param port port_num
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_sadc_dump_en(unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_pdm_sadc_en() - diable/enable sadc function
|
|
*
|
|
* @param en 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_sadc_en(unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_sinc_dsap() - downsampling level set
|
|
*
|
|
* @param rate 0-downsampling by 1, 1-downsampling by 2
|
|
* 2-downsampling by 4, 3-downsampling by 82
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_sinc_dsap(unsigned char port, unsigned char rate);
|
|
|
|
/**
|
|
* @brief i2s_sinc_order() - set downsampling order
|
|
*
|
|
* @param port port_num
|
|
* @param order 0-no downsampling, 1-1 order
|
|
* 2-2 order
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_sinc_order(unsigned char port, unsigned char order);
|
|
|
|
/**
|
|
* @brief i2s_pdm_slave_mod_en() - set pdm mode
|
|
*
|
|
* @param port port_num
|
|
* @param dir 0-write, 1-read
|
|
* @param order 0-master mode, 1-slave mode
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_slave_mod_en(unsigned char port, unsigned char dir, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_pdm_tx_sd_scale() - set tx channel scale factor
|
|
*
|
|
* @param port port_num
|
|
* @param div divide factor
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_tx_sd_scale(unsigned char port, unsigned char div);
|
|
|
|
/**
|
|
* @brief i2s_pdm_tx_sd_scale() - set rx channel downsampling factor
|
|
*
|
|
* @param port port_num
|
|
* @param div divide factor
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_rx_hp_downsample(unsigned char port, unsigned char div);
|
|
|
|
/**
|
|
* @brief i2s_pdm_rx_tx_en() - disable/enable tx/rx
|
|
*
|
|
* @param port port_num
|
|
* @param dir 0-write, 1-read
|
|
* @param dir 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_rx_tx_en(unsigned char port, unsigned char dir, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_pdm_bck_div() - set pdm bck divide ratio
|
|
*
|
|
* @param port port_num
|
|
* @param dir 0-tx, 1-rx
|
|
* @param div divid ratio
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_bck_div(unsigned char port, unsigned char dir, unsigned char div);
|
|
|
|
/**
|
|
* @brief i2s_pdm_clk_cfg() - set i2s pdm mode clock
|
|
*
|
|
* @param port port_num
|
|
* @param freq the clock frequency
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
void i2s_pdm_clk_cfg(uint8_t port, uint32_t freq);
|
|
|
|
/**
|
|
* @brief i2s_pdm_set_lp_hp_scale() - set pdm hp lp
|
|
*
|
|
* @param port port_num
|
|
* @param val hplp value
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
void i2s_pdm_set_lp_hp_scale(unsigned char port, uint32_t val);
|
|
|
|
/**
|
|
* @brief i2s_pdm_sinc16() - set unsamped ratio
|
|
*
|
|
* @param port port_num
|
|
* @param dir 0-tx, 1-rx
|
|
* @param div 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_sinc16(unsigned char port, unsigned char dir, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_pdm_hp_bypass() - disable/enable high bypass
|
|
*
|
|
* @param port port_num
|
|
* @param dir 0-tx, 1-rx
|
|
* @param div 0-disable, 1-enable
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_hp_bypass(unsigned char port, unsigned char dir, unsigned char en);
|
|
|
|
/**
|
|
* @brief i2s_pdm_phase() - set tx/rx clock delay cycle
|
|
*
|
|
* @param port port_num
|
|
* @param dir 0-tx, 1-rx
|
|
* @param ph clock delay cycle
|
|
*
|
|
* @return 0: success
|
|
* @return 1: error
|
|
*
|
|
*/
|
|
int i2s_pdm_phase(unsigned char port, unsigned char dir, unsigned char ph);
|
|
|
|
/**
|
|
* @brief i2s_module_init() - initialize i2s module
|
|
*
|
|
* @param NULL
|
|
*
|
|
*/
|
|
void i2s_module_init(void);
|
|
|
|
int i2s_apb_enable(uint8_t port);
|
|
|
|
int i2s_hw_get_dma_dev(uint8_t port);
|
|
|
|
uint8_t i2s_gpio_func_sel(uint8_t gpio);
|
|
|
|
void i2s_gpio_sig_sel(uint8_t port, uint8_t mod, uint8_t *bck_id, uint8_t *data_id, uint8_t *ws_id);
|
|
|
|
uint8_t i2s_set_mclk(uint8_t gpio, uint32_t clk);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|