1 /**************************************************************************//** 2 * 3 * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 * 7 * Change Logs: 8 * Date Author Notes 9 * 2020-2-7 Wayne First version 10 * 11 ******************************************************************************/ 12 13 #ifndef __DRV_I2S_H__ 14 #define __DRV_I2S_H__ 15 16 #include <rtdevice.h> 17 #include "NuMicro.h" 18 #include <drv_pdma.h> 19 20 #if !defined(NU_I2S_DMA_FIFO_SIZE) 21 #define NU_I2S_DMA_FIFO_SIZE (2048) 22 #endif 23 24 #if !defined(NU_I2S_DMA_BUF_BLOCK_NUMBER) 25 #define NU_I2S_DMA_BUF_BLOCK_NUMBER (2) 26 #endif 27 28 #if ( (NU_I2S_DMA_FIFO_SIZE % NU_I2S_DMA_BUF_BLOCK_NUMBER) != 0 ) 29 #error "Please give an aligned definition" 30 #endif 31 #if ( NU_I2S_DMA_FIFO_SIZE < 2048 ) 32 #warning "DMA FIFO too small, miss voice?" 33 #endif 34 35 #define NU_I2S_DMA_BUF_BLOCK_SIZE (NU_I2S_DMA_FIFO_SIZE/NU_I2S_DMA_BUF_BLOCK_NUMBER) 36 37 typedef enum 38 { 39 NU_I2S_DAI_PLAYBACK, 40 NU_I2S_DAI_CAPTURE, 41 NU_I2S_DAI_CNT 42 } E_NU_I2S_DAI; 43 44 typedef enum 45 { 46 NU_ACODEC_ROLE_MASTER, 47 NU_ACODEC_ROLE_SLAVE, 48 } E_NU_ACODEC_ROLE; 49 50 typedef struct 51 { 52 char *name; 53 54 E_NU_ACODEC_ROLE role; 55 56 struct rt_audio_configure config; 57 58 rt_err_t (*nu_acodec_init)(void); 59 60 rt_err_t (*nu_acodec_reset)(void); 61 62 rt_err_t (*nu_acodec_dsp_control)(struct rt_audio_configure *config); 63 64 rt_err_t (*nu_acodec_mixer_control)(rt_uint32_t ui32Item, rt_uint32_t ui32Value); 65 66 rt_err_t (*nu_acodec_mixer_query)(rt_uint32_t ui32Item, rt_uint32_t *ui32Value); 67 68 } nu_acodec_ops; 69 70 typedef nu_acodec_ops *nu_acodec_ops_t; 71 72 struct nu_i2s_dai 73 { 74 int16_t pdma_perp; 75 int8_t pdma_chanid; 76 rt_uint8_t *fifo; 77 int16_t fifo_block_idx; 78 nu_pdma_desc_t pdma_descs[NU_I2S_DMA_BUF_BLOCK_NUMBER]; 79 }; 80 typedef struct nu_i2s_dai *nu_i2s_dai_t; 81 82 struct nu_i2s 83 { 84 struct rt_audio_device audio; 85 struct rt_audio_configure config; 86 87 char *name; 88 I2S_T *i2s_base; 89 uint32_t i2s_rst; 90 91 struct nu_i2s_dai i2s_dais[NU_I2S_DAI_CNT]; 92 nu_acodec_ops_t AcodecOps; 93 }; 94 typedef struct nu_i2s *nu_i2s_t; 95 96 #endif // __DRV_I2S_H___ 97