1 #ifndef _BFLB_I2S_H 2 #define _BFLB_I2S_H 3 4 #include "bflb_core.h" 5 6 /** @addtogroup LHAL 7 * @{ 8 */ 9 10 /** @addtogroup I2S 11 * @{ 12 */ 13 14 /** @defgroup I2S_ROLE i2s role definition 15 * @{ 16 */ 17 #define I2S_ROLE_MASTER 0 18 #define I2S_ROLE_SLAVE 1 19 /** 20 * @} 21 */ 22 23 /** @defgroup I2S_FORMAT_MODE i2s mode definition 24 * @{ 25 */ 26 #define I2S_MODE_LEFT_JUSTIFIED 0 /* left-justified or Phillips standard */ 27 #define I2S_MODE_RIGHT_JUSTIFIED 1 /* right-justified */ 28 #define I2S_MODE_DSP_SHORT_FRAME_SYNC 2 /* dsp modeA/B short frame sync */ 29 #define I2S_MODE_DSP_LONG_FRAME_SYNC 3 /* dsp modeA/B long frame sync */ 30 /** 31 * @} 32 */ 33 34 /** @defgroup I2S_CHANNEL_MODE i2s mode definition 35 * @{ 36 */ 37 #define I2S_CHANNEL_MODE_NUM_1 0 38 #define I2S_CHANNEL_MODE_NUM_2 1 39 #define I2S_CHANNEL_MODE_NUM_3 2 /* only DSP mode, frame_size must equal data_size */ 40 #define I2S_CHANNEL_MODE_NUM_4 3 /* only DSP mode, frame_size must equal data_size */ 41 #define I2S_CHANNEL_MODE_NUM_6 4 /* only DSP mode, frame_size must equal data_size */ 42 /** 43 * @} 44 */ 45 46 /** @defgroup I2S_SLOT_WIDTH i2s slot width definition 47 * @{ 48 */ 49 #define I2S_SLOT_WIDTH_8 0 50 #define I2S_SLOT_WIDTH_16 1 51 #define I2S_SLOT_WIDTH_24 2 52 #define I2S_SLOT_WIDTH_32 3 53 /** 54 * @} 55 */ 56 57 /** @defgroup I2S_INTSTS i2s interrupt status definition 58 * @{ 59 */ 60 #define I2S_INTSTS_TX_FIFO (1 << 1) 61 #define I2S_INTSTS_RX_FIFO (1 << 2) 62 #define I2S_INTSTS_FIFO_ERR (1 << 3) 63 /** 64 * @} 65 */ 66 67 /** @defgroup I2S_CMD i2s feature control cmd definition 68 * @{ 69 */ 70 #define I2S_CMD_CLEAR_TX_FIFO (0x01) 71 #define I2S_CMD_CLEAR_RX_FIFO (0x02) 72 #define I2S_CMD_RX_DEGLITCH (0x03) 73 #define I2S_CMD_DATA_ENABLE (0x04) 74 #define I2S_CMD_CHANNEL_LR_MERGE (0x05) 75 #define I2S_CMD_CHANNEL_LR_EXCHG (0x06) 76 #define I2S_CMD_MUTE (0x07) 77 #define I2S_CMD_BIT_REVERSE (0x08) 78 /** 79 * @} 80 */ 81 82 /** @defgroup I2S_CMD_DATA_ENABLE_TYPE i2s data enable type 83 * @{ 84 */ 85 #define I2S_CMD_DATA_ENABLE_TX (1 << 1) 86 #define I2S_CMD_DATA_ENABLE_RX (1 << 2) 87 88 /** 89 * @} 90 */ 91 92 /** 93 * @brief I2S configuration structure 94 * 95 * @param bclk_freq_hz I2S bit frequence, Sampling_rate = bclk_freq_hz / frame_width / channel_num. 96 * @param role I2S role, use @ref I2S_ROLE 97 * @param format_mode I2S mode, use @ref I2S_FORMAT_MODE 98 * @param channel_mode I2S channel num, Only DSP mode supports more than 2 channels, use @ref I2S_CHANNEL_MODE 99 * @param frame_width I2S frame width, use @ref I2S_SLOT_WIDTH 100 * @param data_width I2S data order, frame_size must equal data_size in 3/4/6-channel mode, use @ref I2S_SLOT_WIDTH 101 * @param fs_offset_cycle I2S first bit offset of the data 102 * @param tx_fifo_threshold I2S tx fifo threshold, should be less than 16 103 * @param rx_fifo_threshold I2S rx fifo threshold, should be less than 16 104 */ 105 struct bflb_i2s_config_s { 106 uint32_t bclk_freq_hz; 107 uint8_t role; 108 uint8_t format_mode; 109 uint8_t channel_mode; 110 uint8_t frame_width; 111 uint8_t data_width; 112 uint8_t fs_offset_cycle; 113 114 uint8_t tx_fifo_threshold; 115 uint8_t rx_fifo_threshold; 116 }; 117 118 #ifdef __cplusplus 119 extern "C" { 120 #endif 121 122 /** 123 * @brief Initialize i2s. 124 * 125 * @param [in] dev device handle 126 * @param [in] config pointer to save i2s config 127 */ 128 void bflb_i2s_init(struct bflb_device_s *dev, const struct bflb_i2s_config_s *config); 129 130 /** 131 * @brief Deinitialize i2s. 132 * 133 * @param [in] dev device handle 134 */ 135 void bflb_i2s_deinit(struct bflb_device_s *dev); 136 137 /** 138 * @brief Enable i2s tx dma. 139 * 140 * @param [in] dev device handle 141 * @param [in] enable true means enable, otherwise disable. 142 */ 143 void bflb_i2s_link_txdma(struct bflb_device_s *dev, bool enable); 144 145 /** 146 * @brief Enable i2s rx dma. 147 * 148 * @param [in] dev device handle 149 * @param [in] enable true means enable, otherwise disable. 150 */ 151 void bflb_i2s_link_rxdma(struct bflb_device_s *dev, bool enable); 152 153 /** 154 * @brief Enable or disable i2s rx fifo threhold interrupt. 155 * 156 * @param [in] dev device handle 157 * @param [in] mask true means disable, false means enable 158 */ 159 void bflb_i2s_txint_mask(struct bflb_device_s *dev, bool mask); 160 161 /** 162 * @brief Enable or disable i2s rx fifo threhold interrupt. 163 * 164 * @param [in] dev device handle 165 * @param [in] mask true means disable, false means enable 166 */ 167 void bflb_i2s_rxint_mask(struct bflb_device_s *dev, bool mask); 168 169 /** 170 * @brief Enable or disable i2s error interrupt. 171 * 172 * @param [in] dev device handle 173 * @param [in] mask true means disable, false means enable 174 */ 175 void bflb_i2s_errint_mask(struct bflb_device_s *dev, bool mask); 176 177 /** 178 * @brief Get i2s interrupt status. 179 * 180 * @param [in] dev device handle 181 * @return interrupt status, use @ref I2S_INTSTS 182 */ 183 uint32_t bflb_i2s_get_intstatus(struct bflb_device_s *dev); 184 185 /** 186 * @brief Control i2s feature. 187 * 188 * @param [in] dev device handle 189 * @param [in] cmd feature command, use @ref I2S_CMD 190 * @param [in] arg user data 191 * @return A negated errno value on failure. 192 */ 193 int bflb_i2s_feature_control(struct bflb_device_s *dev, int cmd, size_t arg); 194 195 #ifdef __cplusplus 196 } 197 #endif 198 199 /** 200 * @} 201 */ 202 203 /** 204 * @} 205 */ 206 207 #endif 208