nu_i2s.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**************************************************************************//**
  2. * @file i2s.h
  3. * @brief N9H30 I2S driver header file
  4. *
  5. * @note
  6. * SPDX-License-Identifier: Apache-2.0
  7. * Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_I2S_H__
  10. #define __NU_I2S_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup N9H30_Device_Driver N9H30 Device Driver
  16. @{
  17. */
  18. /** @addtogroup N9H30_I2S_Driver I2S Driver
  19. @{
  20. */
  21. /** @addtogroup N9H30_I2S_EXPORTED_CONSTANTS I2S Exported Constants
  22. @{
  23. */
  24. #define I2S_ERR_BUSY -1 /*!< Interface is busy */
  25. #define I2S_ERR_IO -2 /*!< IO contril error */
  26. #define I2S_DISABLE 0 /*!< Enable I2S */
  27. #define I2S_ENABLE 1 /*!< Disable I2S */
  28. #define I2S_PLAY 0 /*!< Play I2S audio */
  29. #define I2S_REC 1 /*!< Reocrd I2S audio */
  30. #define PCM_PLAY 0 /*!< Play PCM audio */
  31. #define PCM_REC 1 /*!< Record PCM audio */
  32. #define I2S_SET_PLAY 0 /*!< Start or stop to play */
  33. #define I2S_START_PLAY 0 /*!< Start to play */
  34. #define I2S_STOP_PLAY 1 /*!< Stop to play */
  35. #define I2S_SET_RECORD 1 /*!< Start or stop to record */
  36. #define I2S_START_REC 0 /*!< Start to record */
  37. #define I2S_STOP_REC 1 /*!< Stop to record */
  38. #define I2S_SELECT_BLOCK 2 /*!< Select block function */
  39. #define I2S_BLOCK_I2S 0 /*!< Select I2S function */
  40. #define I2S_BLOCK_PCM 1 /*!< Select PCM function */
  41. #define I2S_SELECT_BIT 3 /*!< Select data bit width */
  42. #define I2S_BIT_WIDTH_8 0 /*!< 8-bit */
  43. #define I2S_BIT_WIDTH_16 1 /*!< 16-bit */
  44. #define I2S_BIT_WIDTH_24 2 /*!< 24-bit */
  45. #define I2S_SET_PLAY_DMA_INT_SEL 4 /*!< Select play DMA interrupt request */
  46. #define I2S_SET_REC_DMA_INT_SEL 5 /*!< Select record DMA interrupt request */
  47. #define I2S_DMA_INT_END 0 /*!< End of buffer */
  48. #define I2S_DMA_INT_HALF 1 /*!< Half of buffer */
  49. #define I2S_DMA_INT_QUARTER 2 /*!< Quarter of buffer */
  50. #define I2S_DMA_INT_EIGHTH 3 /*!< Eighth of buffer */
  51. #define I2S_SET_ZEROCROSS 6 /*!< Enable or disable zero cross function */
  52. #define I2S_SET_DMACOUNTER 7 /*!< Enable or disable DMA counter function */
  53. #define I2S_SET_CHANNEL 8 /*!< Set channel number */
  54. #define I2S_CHANNEL_P_I2S_ONE 2 /*!< I2S one channel */
  55. #define I2S_CHANNEL_P_I2S_TWO 3 /*!< I2S two channels */
  56. #define I2S_CHANNEL_P_PCM_TWO 3 /*!< PCM two slots */
  57. #define I2S_CHANNEL_P_PCM_TWO_SLOT1 0 /*!< PCM two slots with all slot1 data */
  58. #define I2S_CHANNEL_P_PCM_TWO_SLOT0 1 /*!< PCM two slots with all slot0 data */
  59. #define I2S_CHANNEL_P_PCM_ONE_SLOT0 2 /*!< PCM one slot with all slot0 data */
  60. #define I2S_CHANNEL_R_I2S_LEFT_PCM_SLOT0 1 /*!< I2S left channel or PCM slot0 */
  61. #define I2S_CHANNEL_R_I2S_RIGHT_PCM_SLOT1 2 /*!< I2S right channel or PCM slot1 */
  62. #define I2S_CHANNEL_R_I2S_TWO 3 /*!< I2S two channels */
  63. #define I2S_SET_MODE 9 /*!< Select master or slave mode */
  64. #define I2S_MODE_MASTER 0 /*!< master mode */
  65. #define I2S_MODE_SLAVE 1 /*!< slave mode */
  66. #define I2S_SET_SPLITDATA 10 /*!< Enable or disable split data function */
  67. #define I2S_SET_DMA_ADDRESS 11 /*!< Set DMA address */
  68. #define I2S_SET_DMA_LENGTH 12 /*!< Set DMA length */
  69. #define I2S_GET_DMA_CUR_ADDRESS 13 /*!< Get current DMA address */
  70. #define I2S_SET_I2S_FORMAT 14 /*!< Select I2S format */
  71. #define I2S_FORMAT_I2S 0 /*!< I2S format */
  72. #define I2S_FORMAT_MSB 1 /*!< MSB foramt */
  73. #define I2S_SET_I2S_CALLBACKFUN 15 /*!< Install play or record call-back function */
  74. #define I2S_SET_PCMSLOT 16 /*!< Set PCM interface start position of slot */
  75. #define PCM_SLOT1_IN 0 /*!< Slot-1 in position */
  76. #define PCM_SLOT1_OUT 1 /*!< Slot-1 out position */
  77. #define PCM_SLOT2_IN 2 /*!< Slot-2 in position */
  78. #define PCM_SLOT2_OUT 3 /*!< Slot-2 out position */
  79. #define I2S_SET_PCM_FS_PERIOD 17 /*!< Set PCM FS pulse period */
  80. /*@}*/ /* end of group N9H30_I2S_EXPORTED_CONSTANTS */
  81. /** @addtogroup N9H30_I2S_EXPORTED_FUNCTIONS I2S Exported Functions
  82. @{
  83. */
  84. int32_t i2sOpen(void);
  85. void i2sClose(void);
  86. void i2sInit(void);
  87. int32_t i2sIoctl(uint32_t cmd, uint32_t arg0, uint32_t arg1);
  88. void i2sSetSampleRate(uint32_t u32SourceClockRate, uint32_t u32SampleRate, uint32_t u32DataBit, uint32_t u32Channel);
  89. void i2sSetMCLKFrequency(uint32_t u32SourceClockRate, uint32_t u32SampleRate);
  90. void i2sSetPCMBCLKFrequency(uint32_t u32SourceClockRate, uint32_t u32Rate);
  91. /*@}*/ /* end of group N9H30_I2S_EXPORTED_FUNCTIONS */
  92. /*@}*/ /* end of group N9H30_I2S_Driver */
  93. /*@}*/ /* end of group N9H30_Device_Driver */
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif //__NU_I2S_H__
  98. /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/