1 /** 2 * @file i2s.h 3 * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited 4 */ 5 6 #ifndef HAL_I2S_H 7 #define HAL_I2S_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /** @addtogroup hal_i2s I2S 14 * i2s hal API. 15 * 16 * @{ 17 */ 18 19 #include <stdint.h> 20 21 /* Define the wait forever timeout macro */ 22 #define HAL_WAIT_FOREVER 0xFFFFFFFFU 23 24 /* 25 * I2S mode 26 */ 27 typedef enum { 28 MODE_SLAVE_TX, 29 MODE_SLAVE_RX, 30 MODE_MASTER_TX, 31 MODE_MASTER_RX 32 } hal_i2s_mode_t; 33 34 /* 35 * I2S standard 36 */ 37 typedef enum { 38 STANDARD_PHILIPS, /**< Philips standard */ 39 STANDARD_MSB, /**< MSB align standard */ 40 STANDARD_LSB, /**< LSB align standard */ 41 STANDARD_PCM_SHORT, /**< PCM short frame standard */ 42 STANDARD_PCM_LONG /**< PCM long frame standard */ 43 } hal_i2s_std_t; 44 45 /* 46 * I2S data format 47 */ 48 typedef enum { 49 DATAFORMAT_16B, /**< 16 bit dataformat */ 50 DATAFORMAT_16B_EXTENDED, /**< 16 bit externded dataformat, 32 bit frame */ 51 DATAFORMAT_24B, /**< 24 bit dataformat */ 52 DATAFORMAT_32B /**< 32 bit dataformat */ 53 } hal_i2s_data_format_t; 54 55 /* 56 * I2S configuration 57 */ 58 typedef struct { 59 uint32_t freq; /**< I2S communication frequency */ 60 hal_i2s_mode_t mode; /**< I2S operating mode */ 61 hal_i2s_std_t standard; /**< I2S communication standard */ 62 hal_i2s_data_format_t data_format; /**< I2S communication data format */ 63 } i2s_config_t; 64 65 /* 66 * I2S device description 67 */ 68 typedef struct { 69 uint8_t port; /* I2S port */ 70 i2s_config_t config; /* I2S config */ 71 void *priv; /* Priv data */ 72 } i2s_dev_t; 73 74 /** 75 * Initialises a I2S dev 76 * 77 * @param[in] i2s the dev which should be initialised 78 * 79 * @return 0 : on success, otherwise is error 80 */ 81 int32_t hal_i2s_init(i2s_dev_t *i2s); 82 83 /** 84 * Transmit data on a I2S dev 85 * 86 * @param[in] i2s the I2S dev 87 * @param[in] data pointer to the start of data 88 * @param[in] size number of bytes to transmit 89 * @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER 90 * if you want to wait forever 91 * 92 * @return 0 : on success, otherwise is error 93 */ 94 int32_t hal_i2s_send(i2s_dev_t *i2s, const void *data, uint32_t size, uint32_t timeout); 95 96 /** 97 * Receive data on a I2S dev 98 * 99 * @param[in] i2s the I2S dev 100 * @param[out] data pointer to the buffer which will store incoming data 101 * @param[in] size number of bytes to receive 102 * @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER 103 * if you want to wait forever 104 * 105 * @return 0 : on success, otherwise is error 106 */ 107 int32_t hal_i2s_recv(i2s_dev_t *i2s, void *data, uint32_t size, uint32_t timeout); 108 109 /** 110 * Pause a I2S dev 111 * 112 * @param[in] i2s the dev which should be paused 113 * 114 * @return 0 : on success, otherwise is error 115 */ 116 int32_t hal_i2s_pause(i2s_dev_t *i2s); 117 118 /** 119 * Resume a I2S dev 120 * 121 * @param[in] i2s the dev which should be resumed 122 * 123 * @return 0 : on success, otherwise is error 124 */ 125 int32_t hal_i2s_resume(i2s_dev_t *i2s); 126 127 /** 128 * Stop a I2S dev 129 * 130 * @param[in] i2s the dev which should be stopped 131 * 132 * @return 0 : on success, otherwise is error 133 */ 134 int32_t hal_i2s_stop(i2s_dev_t *i2s); 135 136 /** 137 * finalize a I2S dev 138 * 139 * @param[in] i2s the dev which should be finalized 140 * 141 * @return 0 : on success, otherwise is error 142 */ 143 int32_t hal_i2s_finalize(i2s_dev_t *i2s); 144 145 /** @} */ 146 147 #ifdef __cplusplus 148 } 149 #endif 150 151 #endif /* HAL_I2S_H */ 152 153