drv_i2s.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #ifndef __DRV_I2S_H__
  13. #define __DRV_I2S_H__
  14. #include <rtdevice.h>
  15. #include "NuMicro.h"
  16. #include <drv_pdma.h>
  17. #if !defined(NU_I2S_DMA_FIFO_SIZE)
  18. #define NU_I2S_DMA_FIFO_SIZE (2048)
  19. #endif
  20. #if !defined(NU_I2S_DMA_BUF_BLOCK_NUMBER)
  21. #define NU_I2S_DMA_BUF_BLOCK_NUMBER (2)
  22. #endif
  23. #if ( (NU_I2S_DMA_FIFO_SIZE % NU_I2S_DMA_BUF_BLOCK_NUMBER) != 0 )
  24. #error "Please give an aligned definition"
  25. #endif
  26. #if ( NU_I2S_DMA_FIFO_SIZE < 2048 )
  27. #warning "DMA FIFO too small, miss voice?"
  28. #endif
  29. #define NU_I2S_DMA_BUF_BLOCK_SIZE (NU_I2S_DMA_FIFO_SIZE/NU_I2S_DMA_BUF_BLOCK_NUMBER)
  30. typedef enum
  31. {
  32. NU_I2S_DAI_PLAYBACK,
  33. NU_I2S_DAI_CAPTURE,
  34. NU_I2S_DAI_CNT
  35. } E_NU_I2S_DAI;
  36. typedef enum
  37. {
  38. NU_ACODEC_ROLE_MASTER,
  39. NU_ACODEC_ROLE_SLAVE,
  40. } E_NU_ACODEC_ROLE;
  41. typedef struct
  42. {
  43. char *name;
  44. E_NU_ACODEC_ROLE role;
  45. struct rt_audio_configure config;
  46. rt_err_t (*nu_acodec_init)(void);
  47. rt_err_t (*nu_acodec_reset)(void);
  48. rt_err_t (*nu_acodec_dsp_control)(struct rt_audio_configure *config);
  49. rt_err_t (*nu_acodec_mixer_control)(rt_uint32_t ui32Item, rt_uint32_t ui32Value);
  50. rt_err_t (*nu_acodec_mixer_query)(rt_uint32_t ui32Item, rt_uint32_t *ui32Value);
  51. } nu_acodec_ops;
  52. typedef nu_acodec_ops *nu_acodec_ops_t;
  53. struct nu_i2s_dai
  54. {
  55. int16_t pdma_perp;
  56. int8_t pdma_chanid;
  57. rt_uint8_t *fifo;
  58. int16_t fifo_block_idx;
  59. nu_pdma_desc_t pdma_descs[NU_I2S_DMA_BUF_BLOCK_NUMBER];
  60. };
  61. typedef struct nu_i2s_dai *nu_i2s_dai_t;
  62. struct nu_i2s
  63. {
  64. struct rt_audio_device audio;
  65. struct rt_audio_configure config;
  66. char *name;
  67. I2S_T *i2s_base;
  68. uint32_t i2s_rst;
  69. struct nu_i2s_dai i2s_dais[NU_I2S_DAI_CNT];
  70. nu_acodec_ops_t AcodecOps;
  71. };
  72. typedef struct nu_i2s *nu_i2s_t;
  73. #endif // __DRV_I2S_H___