1 /* 2 * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include <stdint.h> 10 #include <stdlib.h> 11 #include <stdbool.h> 12 #include <stddef.h> 13 #include "esp_bit_defs.h" 14 #include "soc/soc_caps.h" 15 #include "soc/clk_tree_defs.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** 22 * @brief I2S channel slot mode 23 */ 24 typedef enum { 25 I2S_SLOT_MODE_MONO = 1, /*!< I2S channel slot format mono, transmit same data in all slots for tx mode, only receive the data in the first slots for rx mode. */ 26 I2S_SLOT_MODE_STEREO = 2, /*!< I2S channel slot format stereo, transmit different data in different slots for tx mode, receive the data in all slots for rx mode. */ 27 } i2s_slot_mode_t; 28 29 /** 30 * @brief I2S channel direction 31 */ 32 typedef enum { 33 I2S_DIR_RX = BIT(0), /*!< I2S channel direction RX */ 34 I2S_DIR_TX = BIT(1), /*!< I2S channel direction TX */ 35 } i2s_dir_t; 36 37 /** 38 * @brief I2S controller role 39 */ 40 typedef enum { 41 I2S_ROLE_MASTER, /*!< I2S controller master role, bclk and ws signal will be set to output */ 42 I2S_ROLE_SLAVE /*!< I2S controller slave role, bclk and ws signal will be set to input */ 43 } i2s_role_t; 44 45 /** 46 * @brief Available data bit width in one slot 47 */ 48 typedef enum { 49 I2S_DATA_BIT_WIDTH_8BIT = 8, /*!< I2S channel data bit-width: 8 */ 50 I2S_DATA_BIT_WIDTH_16BIT = 16, /*!< I2S channel data bit-width: 16 */ 51 I2S_DATA_BIT_WIDTH_24BIT = 24, /*!< I2S channel data bit-width: 24 */ 52 I2S_DATA_BIT_WIDTH_32BIT = 32, /*!< I2S channel data bit-width: 32 */ 53 } i2s_data_bit_width_t; 54 55 /** 56 * @brief Total slot bit width in one slot 57 * 58 */ 59 typedef enum { 60 I2S_SLOT_BIT_WIDTH_AUTO = (0), /*!< I2S channel slot bit-width equals to data bit-width */ 61 I2S_SLOT_BIT_WIDTH_8BIT = (8), /*!< I2S channel slot bit-width: 8 */ 62 I2S_SLOT_BIT_WIDTH_16BIT = (16), /*!< I2S channel slot bit-width: 16 */ 63 I2S_SLOT_BIT_WIDTH_24BIT = (24), /*!< I2S channel slot bit-width: 24 */ 64 I2S_SLOT_BIT_WIDTH_32BIT = (32), /*!< I2S channel slot bit-width: 32 */ 65 } i2s_slot_bit_width_t; 66 67 #if SOC_I2S_SUPPORTED 68 typedef soc_periph_i2s_clk_src_t i2s_clock_src_t; /*!< I2S clock source */ 69 #else 70 typedef int i2s_clock_src_t; /*!< Define a default type to avoid compiling warnings */ 71 #endif 72 73 74 #if SOC_I2S_SUPPORTS_PCM 75 /** 76 * @brief A/U-law decompress or compress configuration. 77 * 78 */ 79 typedef enum { 80 I2S_PCM_DISABLE = 0, /*!< Disable A/U law decompress or compress*/ 81 I2S_PCM_A_DECOMPRESS, /*!< A-law decompress*/ 82 I2S_PCM_A_COMPRESS, /*!< A-law compress*/ 83 I2S_PCM_U_DECOMPRESS, /*!< U-law decompress*/ 84 I2S_PCM_U_COMPRESS, /*!< U-law compress*/ 85 } i2s_pcm_compress_t; 86 #endif // SOC_I2S_SUPPORTS_PCM 87 88 #if SOC_I2S_SUPPORTS_PDM_RX 89 /** 90 * @brief I2S PDM RX down-sampling mode 91 */ 92 typedef enum { 93 I2S_PDM_DSR_8S = 0, /*!< downsampling number is 8 for PDM RX mode*/ 94 I2S_PDM_DSR_16S, /*!< downsampling number is 16 for PDM RX mode*/ 95 I2S_PDM_DSR_MAX, 96 } i2s_pdm_dsr_t; 97 #endif // SOC_I2S_SUPPORTS_PDM_RX 98 99 #if SOC_I2S_SUPPORTS_PDM_TX 100 /** 101 * @brief pdm tx singnal scaling mode 102 */ 103 typedef enum { 104 I2S_PDM_SIG_SCALING_DIV_2 = 0, /*!< I2S TX PDM signal scaling: /2 */ 105 I2S_PDM_SIG_SCALING_MUL_1 = 1, /*!< I2S TX PDM signal scaling: x1 */ 106 I2S_PDM_SIG_SCALING_MUL_2 = 2, /*!< I2S TX PDM signal scaling: x2 */ 107 I2S_PDM_SIG_SCALING_MUL_4 = 3, /*!< I2S TX PDM signal scaling: x4 */ 108 } i2s_pdm_sig_scale_t; 109 110 #if SOC_I2S_HW_VERSION_2 111 /** 112 * @brief PDM TX line mode 113 * @note For the standard codec mode, PDM pins are connect to a codec which requires both clock signal and data signal 114 * For the DAC output mode, PDM data signal can be connected to a power amplifier directly with a low-pass filter, 115 * normally, DAC output mode doesn't need the clock signal. 116 */ 117 typedef enum { 118 I2S_PDM_TX_ONE_LINE_CODEC, /*!< Standard PDM format output, left and right slot data on a single line */ 119 I2S_PDM_TX_ONE_LINE_DAC, /*!< PDM DAC format output, left or right slot data on a single line */ 120 I2S_PDM_TX_TWO_LINE_DAC, /*!< PDM DAC format output, left and right slot data on separated lines */ 121 } i2s_pdm_tx_line_mode_t; 122 #endif // SOC_I2S_HW_VERSION_2 123 #endif // SOC_I2S_SUPPORTS_PDM_TX 124 125 /** 126 * @brief I2S slot select in standard mode 127 * @note It has different meanings in tx/rx/mono/stereo mode, and it may have differen behaviors on different targets 128 * For the details, please refer to the I2S API reference 129 */ 130 typedef enum { 131 I2S_STD_SLOT_LEFT = BIT(0), /*!< I2S transmits or receives left slot */ 132 I2S_STD_SLOT_RIGHT = BIT(1), /*!< I2S transmits or receives right slot */ 133 I2S_STD_SLOT_BOTH = BIT(0) | BIT(1), /*!< I2S transmits or receives both left and right slot */ 134 } i2s_std_slot_mask_t; 135 136 /** 137 * @brief I2S slot select in PDM mode 138 * 139 */ 140 typedef enum { 141 I2S_PDM_SLOT_RIGHT = BIT(0), /*!< I2S PDM only transmits or receives the PDM device whose 'select' pin is pulled up */ 142 I2S_PDM_SLOT_LEFT = BIT(1), /*!< I2S PDM only transmits or receives the PDM device whose 'select' pin is pulled down */ 143 I2S_PDM_SLOT_BOTH = BIT(0) | BIT(1), /*!< I2S PDM transmits or receives both two slots */ 144 #if SOC_I2S_PDM_MAX_RX_LINES > 1 145 /* The following enumerators are only used in multi-line PDM RX mode */ 146 I2S_PDM_RX_LINE0_SLOT_RIGHT = I2S_PDM_SLOT_RIGHT, /*!< I2S PDM receives the right slot on line 0 */ 147 I2S_PDM_RX_LINE0_SLOT_LEFT = I2S_PDM_SLOT_LEFT, /*!< I2S PDM receives the left slot on line 0 */ 148 I2S_PDM_RX_LINE1_SLOT_RIGHT = BIT(2), /*!< I2S PDM receives the right slot on line 1 */ 149 I2S_PDM_RX_LINE1_SLOT_LEFT = BIT(3), /*!< I2S PDM receives the left slot on line 1 */ 150 I2S_PDM_RX_LINE2_SLOT_RIGHT = BIT(4), /*!< I2S PDM receives the right slot on line 2 */ 151 I2S_PDM_RX_LINE2_SLOT_LEFT = BIT(5), /*!< I2S PDM receives the left slot on line 2 */ 152 I2S_PDM_RX_LINE3_SLOT_RIGHT = BIT(6), /*!< I2S PDM receives the right slot on line 3 */ 153 I2S_PDM_RX_LINE3_SLOT_LEFT = BIT(7), /*!< I2S PDM receives the left slot on line 3 */ 154 I2S_PDM_LINE_SLOT_ALL = 0x00ff, /*!< I2S PDM receives all slots */ 155 #endif 156 } i2s_pdm_slot_mask_t; 157 158 #if SOC_I2S_SUPPORTS_TDM 159 /** 160 * @brief tdm slot number 161 * @note Multiple slots in TDM mode. 162 * For TX module, only the active slot send the audio data, the inactive slot send a constant or will be skipped if 'skip_msk' is set. 163 * For RX module, only receive the audio data in active slots, the data in inactive slots will be ignored. 164 * the bit map of active slot can not exceed (0x1<<total_slot_num). 165 * e.g: slot_mask = (I2S_TDM_SLOT0 | I2S_TDM_SLOT3), here the active slot number is 2 and total_slot is not supposed to be smaller than 4. 166 */ 167 typedef enum { 168 I2S_TDM_SLOT0 = BIT(0), /*!< I2S slot 0 enabled */ 169 I2S_TDM_SLOT1 = BIT(1), /*!< I2S slot 1 enabled */ 170 I2S_TDM_SLOT2 = BIT(2), /*!< I2S slot 2 enabled */ 171 I2S_TDM_SLOT3 = BIT(3), /*!< I2S slot 3 enabled */ 172 I2S_TDM_SLOT4 = BIT(4), /*!< I2S slot 4 enabled */ 173 I2S_TDM_SLOT5 = BIT(5), /*!< I2S slot 5 enabled */ 174 I2S_TDM_SLOT6 = BIT(6), /*!< I2S slot 6 enabled */ 175 I2S_TDM_SLOT7 = BIT(7), /*!< I2S slot 7 enabled */ 176 I2S_TDM_SLOT8 = BIT(8), /*!< I2S slot 8 enabled */ 177 I2S_TDM_SLOT9 = BIT(9), /*!< I2S slot 9 enabled */ 178 I2S_TDM_SLOT10 = BIT(10), /*!< I2S slot 10 enabled */ 179 I2S_TDM_SLOT11 = BIT(11), /*!< I2S slot 11 enabled */ 180 I2S_TDM_SLOT12 = BIT(12), /*!< I2S slot 12 enabled */ 181 I2S_TDM_SLOT13 = BIT(13), /*!< I2S slot 13 enabled */ 182 I2S_TDM_SLOT14 = BIT(14), /*!< I2S slot 14 enabled */ 183 I2S_TDM_SLOT15 = BIT(15), /*!< I2S slot 15 enabled */ 184 } i2s_tdm_slot_mask_t; 185 #endif // SOC_I2S_SUPPORTS_TDM 186 187 188 #ifdef __cplusplus 189 } 190 #endif 191