drv_i2s.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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-12-12 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #ifndef __DRV_I2S_H__
  13. #define __DRV_I2S_H__
  14. #include <rtthread.h>
  15. #include <drv_sys.h>
  16. #include "NuMicro.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. #if ( NU_I2S_DMA_BUF_BLOCK_SIZE > RT_AUDIO_RECORD_PIPE_SIZE )
  31. #error "Specified I2S DMA buffer size is small than PIPE size in RT driver."
  32. #error "You should enlarge RT_AUDIO_RECORD_PIPE_SIZE. "
  33. #endif
  34. typedef enum
  35. {
  36. NU_I2S_DAI_PLAYBACK,
  37. NU_I2S_DAI_CAPTURE,
  38. NU_I2S_DAI_CNT
  39. } E_NU_I2S_DAI;
  40. typedef enum
  41. {
  42. NU_ACODEC_ROLE_MASTER,
  43. NU_ACODEC_ROLE_SLAVE,
  44. } E_NU_ACODEC_ROLE;
  45. typedef struct
  46. {
  47. char *name;
  48. E_NU_ACODEC_ROLE role;
  49. struct rt_audio_configure config;
  50. rt_err_t (*nu_acodec_init)(void);
  51. rt_err_t (*nu_acodec_reset)(void);
  52. rt_err_t (*nu_acodec_dsp_control)(struct rt_audio_configure *config);
  53. rt_err_t (*nu_acodec_mixer_control)(rt_uint32_t ui32Item, rt_uint32_t ui32Value);
  54. rt_err_t (*nu_acodec_mixer_query)(rt_uint32_t ui32Item, rt_uint32_t *ui32Value);
  55. } nu_acodec_ops;
  56. typedef nu_acodec_ops *nu_acodec_ops_t;
  57. struct nu_i2s_dai
  58. {
  59. rt_uint8_t *fifo;
  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. IRQn_Type irqn;
  68. E_SYS_IPRST rstidx;
  69. E_SYS_IPCLK clkidx;
  70. struct nu_i2s_dai i2s_dais[NU_I2S_DAI_CNT];
  71. nu_acodec_ops_t AcodecOps;
  72. };
  73. typedef struct nu_i2s *nu_i2s_t;
  74. #endif // __DRV_I2S_H___