sama_classd.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SAMA5D2x/sama_classd.h
  15. * @brief SAMA CLASSD support macros and structures.
  16. *
  17. * @addtogroup SAMA5D2x_CLASSD
  18. * @{
  19. */
  20. #ifndef SAMA_CLASSD_LLD_H
  21. #define SAMA_CLASSD_LLD_H
  22. /**
  23. * @brief Using the CLASSD driver.
  24. */
  25. #if !defined(SAMA_USE_CLASSD) || defined(__DOXYGEN__)
  26. #define SAMA_USE_CLASSD FALSE
  27. #endif
  28. #if SAMA_USE_CLASSD || defined(__DOXYGEN__)
  29. /*===========================================================================*/
  30. /* Driver constants. */
  31. /*===========================================================================*/
  32. /*===========================================================================*/
  33. /* Driver pre-compile time settings. */
  34. /*===========================================================================*/
  35. /**
  36. * @name Configuration options
  37. * @{
  38. */
  39. /**
  40. * @brief CLASSD DMA interrupt priority level setting.
  41. */
  42. #if !defined(SAMA_CLASSD_DMA_IRQ_PRIORITY) || defined(__DOXYGEN__)
  43. #define SAMA_CLASSD_DMA_IRQ_PRIORITY 4
  44. #endif
  45. /** @} */
  46. /*===========================================================================*/
  47. /* Derived constants and error checks. */
  48. /*===========================================================================*/
  49. #if !defined(SAMA_DMA_REQUIRED)
  50. #define SAMA_DMA_REQUIRED
  51. #endif
  52. /*===========================================================================*/
  53. /* Driver data structures and types. */
  54. /*===========================================================================*/
  55. /**
  56. * @brief Driver state machine possible states.
  57. */
  58. typedef enum {
  59. CLASSD_UNINIT = 0, /**< Not initialized. */
  60. CLASSD_STOP = 1, /**< Stopped. */
  61. CLASSD_READY = 2, /**< Ready. */
  62. CLASSD_ACTIVE = 3, /**< Exchanging data. */
  63. } classdstate_t;
  64. /**
  65. * @brief Structure representing audio info.
  66. */
  67. static const struct {
  68. /**
  69. * @brief Contains the value of the Sample Rate.
  70. */
  71. uint32_t rate;
  72. /**
  73. * @brief Contains a mask of the Sample Rate.
  74. */
  75. uint32_t sample_rate;
  76. /**
  77. * @brief Contains a mask of the DSP Clock.
  78. */
  79. uint32_t dsp_clk;
  80. } audio_info[] = {
  81. {8000, CLASSD_INTPMR_FRAME_FRAME_8K, CLASSD_INTPMR_DSPCLKFREQ_12M288},
  82. {16000, CLASSD_INTPMR_FRAME_FRAME_16K, CLASSD_INTPMR_DSPCLKFREQ_12M288},
  83. {32000, CLASSD_INTPMR_FRAME_FRAME_32K, CLASSD_INTPMR_DSPCLKFREQ_12M288},
  84. {48000, CLASSD_INTPMR_FRAME_FRAME_48K, CLASSD_INTPMR_DSPCLKFREQ_12M288},
  85. {96000, CLASSD_INTPMR_FRAME_FRAME_96K, CLASSD_INTPMR_DSPCLKFREQ_12M288},
  86. {22050, CLASSD_INTPMR_FRAME_FRAME_22K, CLASSD_INTPMR_DSPCLKFREQ_11M2896},
  87. {44100, CLASSD_INTPMR_FRAME_FRAME_44K, CLASSD_INTPMR_DSPCLKFREQ_11M2896},
  88. {88200, CLASSD_INTPMR_FRAME_FRAME_88K, CLASSD_INTPMR_DSPCLKFREQ_11M2896},
  89. };
  90. /**
  91. * @brief Type of a structure representing Standard WAV file header information.
  92. */
  93. struct wav_header {
  94. /**
  95. * @brief Contains the letters "RIFF" in ASCII form.
  96. */
  97. uint32_t chunk_id;
  98. /**
  99. * @brief Size of the rest of the chunk following this number.
  100. */
  101. uint32_t chunk_size;
  102. /**
  103. * @brief Contains the letters "WAVE".
  104. */
  105. uint32_t format;
  106. /**
  107. * @brief Contains the letters "fmt ".
  108. */
  109. uint32_t subchunk1_id;
  110. /**
  111. * @brief 16 for PCM. This is the size of the rest of the Subchunk which follows this number.
  112. */
  113. uint32_t subchunk1_size;
  114. /**
  115. * @brief PCM = 1 (i.e. Linear quantization). Values other than 1 indicate some form of compression.
  116. */
  117. uint16_t audio_format;
  118. /**
  119. * @brief Mono = 1, Stereo = 2, etc.
  120. */
  121. uint16_t num_channels;
  122. /**
  123. * @brief 8000, 44100, etc.
  124. */
  125. uint32_t sample_rate;
  126. /**
  127. * @brief SampleRate * NumChannels * BitsPerSample/8
  128. */
  129. uint32_t byte_rate;
  130. /**
  131. * @brief NumChannels * BitsPerSample/8
  132. */
  133. uint16_t block_align;
  134. /**
  135. * @brief 8 bits = 8, 16 bits = 16, etc.
  136. */
  137. uint16_t bits_per_sample;
  138. /**
  139. * @brief Contains the letters "data".
  140. */
  141. uint32_t subchunk2_id;
  142. /**
  143. * @brief Number of bytes in the data.
  144. */
  145. uint32_t subchunk2_size;
  146. };
  147. /**
  148. * @brief Type of a structure representing an CLASSD driver.
  149. */
  150. typedef struct CLASSDDriver CLASSDDriver;
  151. /**
  152. * @brief Type of a generic CLASSD callback.
  153. */
  154. typedef void (*classdcb_t)(CLASSDDriver *classdp);
  155. /**
  156. * @brief Driver configuration structure.
  157. * @note It could be empty on some architectures.
  158. */
  159. typedef struct {
  160. /**
  161. * @brief Callback pointer.
  162. */
  163. classdcb_t callback;
  164. /**
  165. * @brief Configuration of the CLASSD left channel.
  166. */
  167. uint32_t left;
  168. /**
  169. * @brief Configuration of the CLASSD right channel.
  170. */
  171. uint32_t right;
  172. /**
  173. * @brief Configuration of the CLASSD left channel mute.
  174. */
  175. uint32_t left_mute;
  176. /**
  177. * @brief Configuration of the CLASSD right channel mute.
  178. */
  179. uint32_t right_mute;
  180. /**
  181. * @brief Configuration of the CLASSD PWM modulation type.
  182. */
  183. uint32_t pwm_mode;
  184. /**
  185. * @brief Configuration of the CLASSD Non-Overlapping.
  186. */
  187. uint32_t non_overlap;
  188. /**
  189. * @brief Configuration of the CLASSD Non-Overlapping value.
  190. */
  191. uint32_t novrval;
  192. /**
  193. * @brief Configuration of the CLASSD left channel attenuation.
  194. */
  195. uint32_t attl;
  196. /**
  197. * @brief Configuration of the CLASSD right channel attenuation.
  198. */
  199. uint32_t attr;
  200. /**
  201. * @brief Configuration of the CLASSD de-emphasis filter.
  202. */
  203. uint32_t deemp;
  204. /**
  205. * @brief Configuration of the CLASSD swap left right channel.
  206. */
  207. uint32_t swap;
  208. /**
  209. * @brief Configuration of the CLASSD sample frequency.
  210. */
  211. uint32_t frame;
  212. /**
  213. * @brief Configuration of the CLASSD EQ config.
  214. */
  215. uint32_t eqcfg;
  216. /**
  217. * @brief Configuration of the CLASSD mono signal.
  218. */
  219. uint32_t mono;
  220. /**
  221. * @brief Configuration of the CLASSD mono mode.
  222. */
  223. uint32_t mono_mode;
  224. } CLASSDConfig;
  225. /**
  226. * @brief Structure representing an CLASSD driver.
  227. */
  228. struct CLASSDDriver {
  229. /**
  230. * @brief Driver state.
  231. */
  232. classdstate_t state;
  233. /**
  234. * @brief Current configuration data.
  235. */
  236. const CLASSDConfig *config;
  237. /**
  238. * @brief Pointer to the WDT registers block.
  239. */
  240. Classd *classd;
  241. /**
  242. * @brief Transmit DMA stream.
  243. */
  244. sama_dma_channel_t *dmatx;
  245. /**
  246. * @brief TX DMA mode bit mask.
  247. */
  248. uint32_t txdmamode;
  249. };
  250. /*===========================================================================*/
  251. /* Driver macros. */
  252. /*===========================================================================*/
  253. /*===========================================================================*/
  254. /* External declarations. */
  255. /*===========================================================================*/
  256. extern CLASSDDriver CLASSDD0;
  257. #ifdef __cplusplus
  258. extern "C" {
  259. #endif
  260. void classdInit(void);
  261. void classdObjectInit(CLASSDDriver *classdp);
  262. void classdStart(CLASSDDriver *classdp, const CLASSDConfig *config);
  263. void classdStop(CLASSDDriver *classdp);
  264. void classdSetSampleFrame(CLASSDConfig *classdconfigp, uint8_t *music_file);
  265. void classdSendAudioI(CLASSDDriver *classdp, const void *txbuf);
  266. void classdSendAudio(CLASSDDriver *classdp, const void *txbuf);
  267. void classdMuteChannel(CLASSDDriver *classdp, bool left, bool right);
  268. #ifdef __cplusplus
  269. }
  270. #endif
  271. #endif /* SAMA_USE_CLASSD */
  272. #endif /* SAMA_CLASSD_LLD_H */
  273. /** @} */