gd32f30x_audio_codec.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*!
  2. \file gd32f30x_usb_audio_codec.h
  3. \brief This file contains all the functions prototypes for the audio codec
  4. low layer driver.
  5. \version 2023-06-30, V2.1.6, firmware for GD32F30x
  6. */
  7. /*
  8. Copyright (c) 2023, GigaDevice Semiconductor Inc.
  9. Redistribution and use in source and binary forms, with or without modification,
  10. are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice, this
  12. list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. 3. Neither the name of the copyright holder nor the names of its contributors
  17. may be used to endorse or promote products derived from this software without
  18. specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. OF SUCH DAMAGE.
  29. */
  30. #ifndef GD32F30X_AUDIO_CODEC_H
  31. #define GD32F30X_AUDIO_CODEC_H
  32. #include "usbd_conf.h"
  33. /* select the interrupt preemption priority and sub-priority for DMA interrupt */
  34. #define AD_IRQ_PREPRIO 2
  35. #define AD_IRQ_SUBRIO 0
  36. /* uncomment the defines below to select if the master clock mode should be enabled or not */
  37. #define IIS_MCLK_ENABLED
  38. //#define IIS_MCLK_DISABLED
  39. /* hardware configuration defines parameters */
  40. /* I2S peripheral configuration defines (data and control interface of the audio codec) */
  41. #define AD_I2S SPI1
  42. #define AD_I2S_CLK RCU_SPI1
  43. #define AD_I2S_ADDRESS (SPI1+0x0C)
  44. #define AD_I2S_IRQ SPI1_IRQn
  45. #define AD_I2S_WS_PIN GPIO_PIN_12
  46. #define AD_I2S_SCK_PIN GPIO_PIN_13
  47. #define AD_I2S_SD_PIN GPIO_PIN_15
  48. #define AD_I2S_MCK_PIN GPIO_PIN_6
  49. #define AD_I2S_GPIO_CLK RCU_GPIOB
  50. #define AD_I2S_MCK_CLK RCU_GPIOC
  51. #define AD_I2S_GPIO GPIOB
  52. #define AD_I2S_MCK_GPIO GPIOC
  53. /* I2S DMA Stream definitions */
  54. #define AD_DMA_CLOCK RCU_DMA0
  55. #define AD_DMA_CHANNEL DMA_CH4
  56. #define AD_DMA_IRQ DMA0_Channel4_IRQn
  57. #define AD_DMA_FLAG_TC DMA_FLAG_FTF
  58. #define AD_DMA_FLAG_HT DMA_FLAG_HTF
  59. #define AD_DMA_FLAG_TE DMA_FLAG_ERR
  60. #define AD_DMA_FLAG_GL DMA_INT_FLAG_G
  61. #define AD_DMA_FLAG_ALL DMA_INT_FLAG_G
  62. #define AD_DMA DMA0
  63. #define AD_DMA_IRQHandler DMA0_Channel4_IRQHandler
  64. /* mask for the bit en of the i2s cfgr register */
  65. #define I2S_ENABLE_MASK (0x0400)
  66. /* audio state */
  67. typedef enum _audio_status {
  68. AD_OK = 0,
  69. AD_FAIL,
  70. } audio_status;
  71. typedef enum _audio_ctl {
  72. AD_PAUSE = 0,
  73. AD_RESUME,
  74. } audio_ctl;
  75. /* audio machine states */
  76. typedef enum _audio_state {
  77. AD_STATE_INACTIVE = 0,
  78. AD_STATE_ACTIVE,
  79. AD_STATE_PLAYING,
  80. AD_STATE_PAUSED,
  81. AD_STATE_STOPPED,
  82. AD_STATE_ERROR,
  83. } audio_state_enum;
  84. /* audio commands enumeration */
  85. typedef enum
  86. {
  87. AD_CMD_PLAY = 1U,
  88. AD_CMD_PAUSE,
  89. AD_CMD_STOP,
  90. }audio_cmd_enum;
  91. /* function declarations */
  92. /* initializes the audio codec audio interface (i2s) */
  93. void codec_audio_interface_init(uint32_t audio_freq);
  94. /* deinitialize the audio codec audio interface */
  95. void codec_audio_interface_deinit(void);
  96. /* initializes IOs used by the audio codec */
  97. void codec_gpio_init(void);
  98. /* deinitialize IOs used by the audio codec interface */
  99. void codec_gpio_deinit(void);
  100. /* initializes dma to prepare for audio data transfer */
  101. void codec_i2s_dma_init(void);
  102. /* restore default state of the used media */
  103. void codec_i2s_dma_deinit(void);
  104. /* starts playing audio stream from the audio media */
  105. void audio_play(uint32_t addr, uint32_t size);
  106. /* pauses or resumes the audio stream playing from the media */
  107. void audio_pause_resume(uint32_t cmd, uint32_t addr, uint32_t size);
  108. /* stops audio stream playing on the used media */
  109. void audio_stop(void);
  110. #endif /* GD32F10X_AUDIO_CODEC_H */