i2s.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * @file i2s.h
  3. * @brief I2S (Inter-Integrated Sound) driver function prototypes and data types.
  4. */
  5. /* ****************************************************************************
  6. * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  22. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Except as contained in this notice, the name of Maxim Integrated
  27. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  28. * Products, Inc. Branding Policy.
  29. *
  30. * The mere transfer of this software does not imply any licenses
  31. * of trade secrets, proprietary technology, copyrights, patents,
  32. * trademarks, maskwork rights, or any other form of intellectual
  33. * property whatsoever. Maxim Integrated Products, Inc. retains all
  34. * ownership rights.
  35. *
  36. * $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
  37. * $Revision: 40072 $
  38. *
  39. *************************************************************************** */
  40. #ifndef _I2S_H_
  41. #define _I2S_H_
  42. /* **** Includes **** */
  43. #include "mxc_config.h"
  44. #include "dma.h"
  45. #include "spimss_regs.h"
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /**
  50. * @defgroup i2s Inter-Integrated Sound (I2S)
  51. * @ingroup spi
  52. * @{
  53. */
  54. /* **** Definitions **** */
  55. /** @brief I2S audio directions */
  56. typedef enum {
  57. AUDIO_OUT = 1,
  58. AUDIO_IN = 2,
  59. } i2s_direction_t;
  60. /** @brief I2S Configuration Struct */
  61. typedef struct {
  62. uint8_t left_justify;
  63. uint8_t mono_audio;
  64. i2s_direction_t audio_direction;
  65. unsigned int sample_rate;
  66. unsigned int start_immediately;
  67. void *dma_src_addr;
  68. void *dma_dst_addr;
  69. unsigned int dma_cnt;
  70. unsigned int dma_reload_en;
  71. } i2s_cfg_t;
  72. /* **** Function Prototypes **** */
  73. /**
  74. * @brief Initialize I2S resources
  75. * @param cfg I2S Configuration Struct
  76. * @param dma_ctz_cb Optional function to be called when the DMA completes
  77. a transfer. Set to NULL if unused.
  78. * @param sys_cfg_i2s System configuration object
  79. * @details This initialization is required before using the I2S driver functions.
  80. * @return \c #E_NO_ERROR if successful
  81. */
  82. int I2S_Init(const i2s_cfg_t *cfg, void (*dma_ctz_cb)(int, int), const sys_cfg_i2s_t* sys_cfg_i2s);
  83. /**
  84. * @brief Release I2S
  85. * @details De-configures the I2S protocol and stops DMA request
  86. * @return \c #E_BAD_PARAM if DMA cannot be stopped, #E_NO_ERROR otherwise
  87. */
  88. int I2S_Shutdown(void);
  89. /**
  90. * @brief Mute I2S Output
  91. * @details Sets I2S data to zero, continues sending clock and accessing DMA
  92. * @return \c #E_NO_ERROR
  93. */
  94. int I2S_Mute(void);
  95. /**
  96. * @brief Unmute I2S Output
  97. * @details Restores I2S data
  98. * @return \c #E_NO_ERROR
  99. */
  100. int I2S_Unmute(void);
  101. /**
  102. * @brief Pause I2S Output
  103. * @details Similar to mute, but stops FIFO and DMA access, clocks continue
  104. * @return \c #E_NO_ERROR
  105. */
  106. int I2S_Pause(void);
  107. /**
  108. * @brief Unpause I2S Output
  109. * @details Similar to mute, but restarts FIFO and DMA access
  110. * @return \c #E_NO_ERROR
  111. */
  112. int I2S_Unpause(void);
  113. /**
  114. * @brief Stops I2S Output
  115. * @details Similar to pause, but also halts clock
  116. * @return \c #E_NO_ERROR
  117. */
  118. int I2S_Stop(void);
  119. /**
  120. * @brief Starts I2S Output
  121. * @details Starts I2S Output, automatically called by configure if requested
  122. * @return \c #E_NO_ERROR
  123. */
  124. int I2S_Start(void);
  125. /**
  126. * @brief Clears DMA Interrupt Flags
  127. * @details Clears the DMA Interrupt flags, should be called at the end of a dma_ctz_cb
  128. * @return \c #E_NO_ERROR
  129. */
  130. int I2S_DMA_ClearFlags(void);
  131. /**
  132. * @brief Set DMA Addr (Source or Dest) and bytes to transfer
  133. * @param src_addr The address to read data from (Audio Out)
  134. * @param dst_addr The address to write data to (Audio In)
  135. * @param count The length of the transfer in bytes
  136. * @details Sets the address to read/write data in memory and the length of
  137. * the transfer. The unused addr parameter is ignored.
  138. * @return \c #E_NO_ERROR
  139. */
  140. int I2S_DMA_SetAddrCnt(void *src_addr, void *dst_addr, unsigned int count);
  141. /**
  142. * @brief Sets the DMA reload address and count
  143. * @param src_addr The address to read data from (Audio Out)
  144. * @param dst_addr The address to write data to (Audio In)
  145. * @param count The length of the transfer in bytes
  146. * @details If DMA reload is enabled, when the DMA has transfered $count bytes
  147. * (a CTZ event occurs) the src, dst, and count registers will be
  148. * set to these. The DMA reload flag clears after a reload occurs.
  149. * @return \c #E_NO_ERROR
  150. */
  151. int I2S_DMA_SetReload(void *src_addr, void *dst_addr, unsigned int count);
  152. /**@} end of group i2s */
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156. #endif /* _I2S_H_ */