bsp_wm8960.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-12-05 zylx The first version for STM32F4xx
  9. * 2019-4-25 misonyo port to IMXRT
  10. */
  11. #ifndef __DRV_WM8960_H__
  12. #define __DRV_WM8960_H__
  13. #include <rtthread.h>
  14. #include <rtdevice.h>
  15. #include "fsl_common.h"
  16. /*!
  17. * @addtogroup wm8960
  18. * @{
  19. */
  20. /*******************************************************************************
  21. * Definitions
  22. ******************************************************************************/
  23. /*! @name Driver version */
  24. /*@{*/
  25. /*! @brief CLOCK driver version 2.1.0 */
  26. #define FSL_WM8960_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
  27. /*@}*/
  28. /*! @brief wm8960 handle size */
  29. #ifndef WM8960_HANDLE_SIZE
  30. #define WM8960_HANDLE_SIZE (100U)
  31. #endif
  32. /*! @brief Define the register address of WM8960. */
  33. #define WM8960_LINVOL 0x0
  34. #define WM8960_RINVOL 0x1
  35. #define WM8960_LOUT1 0x2
  36. #define WM8960_ROUT1 0x3
  37. #define WM8960_CLOCK1 0x4
  38. #define WM8960_DACCTL1 0x5
  39. #define WM8960_DACCTL2 0x6
  40. #define WM8960_IFACE1 0x7
  41. #define WM8960_CLOCK2 0x8
  42. #define WM8960_IFACE2 0x9
  43. #define WM8960_LDAC 0xa
  44. #define WM8960_RDAC 0xb
  45. #define WM8960_RESET 0xf
  46. #define WM8960_3D 0x10
  47. #define WM8960_ALC1 0x11
  48. #define WM8960_ALC2 0x12
  49. #define WM8960_ALC3 0x13
  50. #define WM8960_NOISEG 0x14
  51. #define WM8960_LADC 0x15
  52. #define WM8960_RADC 0x16
  53. #define WM8960_ADDCTL1 0x17
  54. #define WM8960_ADDCTL2 0x18
  55. #define WM8960_POWER1 0x19
  56. #define WM8960_POWER2 0x1a
  57. #define WM8960_ADDCTL3 0x1b
  58. #define WM8960_APOP1 0x1c
  59. #define WM8960_APOP2 0x1d
  60. #define WM8960_LINPATH 0x20
  61. #define WM8960_RINPATH 0x21
  62. #define WM8960_LOUTMIX 0x22
  63. #define WM8960_ROUTMIX 0x25
  64. #define WM8960_MONOMIX1 0x26
  65. #define WM8960_MONOMIX2 0x27
  66. #define WM8960_LOUT2 0x28
  67. #define WM8960_ROUT2 0x29
  68. #define WM8960_MONO 0x2a
  69. #define WM8960_INBMIX1 0x2b
  70. #define WM8960_INBMIX2 0x2c
  71. #define WM8960_BYPASS1 0x2d
  72. #define WM8960_BYPASS2 0x2e
  73. #define WM8960_POWER3 0x2f
  74. #define WM8960_ADDCTL4 0x30
  75. #define WM8960_CLASSD1 0x31
  76. #define WM8960_CLASSD3 0x33
  77. #define WM8960_PLL1 0x34
  78. #define WM8960_PLL2 0x35
  79. #define WM8960_PLL3 0x36
  80. #define WM8960_PLL4 0x37
  81. /*! @brief Cache register number */
  82. #define WM8960_CACHEREGNUM 56
  83. /*! @brief WM8960_IFACE1 FORMAT bits */
  84. #define WM8960_IFACE1_FORMAT_MASK 0x03
  85. #define WM8960_IFACE1_FORMAT_SHIFT 0x00
  86. #define WM8960_IFACE1_FORMAT_RJ 0x00
  87. #define WM8960_IFACE1_FORMAT_LJ 0x01
  88. #define WM8960_IFACE1_FORMAT_I2S 0x02
  89. #define WM8960_IFACE1_FORMAT_DSP 0x03
  90. #define WM8960_IFACE1_FORMAT(x) ((x << WM8960_IFACE1_FORMAT_SHIFT) & WM8960_IFACE1_FORMAT_MASK)
  91. /*! @brief WM8960_IFACE1 WL bits */
  92. #define WM8960_IFACE1_WL_MASK 0x0C
  93. #define WM8960_IFACE1_WL_SHIFT 0x02
  94. #define WM8960_IFACE1_WL_16BITS 0x00
  95. #define WM8960_IFACE1_WL_20BITS 0x01
  96. #define WM8960_IFACE1_WL_24BITS 0x02
  97. #define WM8960_IFACE1_WL_32BITS 0x03
  98. #define WM8960_IFACE1_WL(x) ((x << WM8960_IFACE1_WL_SHIFT) & WM8960_IFACE1_WL_MASK)
  99. /*! @brief WM8960_IFACE1 LRP bit */
  100. #define WM8960_IFACE1_LRP_MASK 0x10
  101. #define WM8960_IFACE1_LRP_SHIFT 0x04
  102. #define WM8960_IFACE1_LRCLK_NORMAL_POL 0x00
  103. #define WM8960_IFACE1_LRCLK_INVERT_POL 0x01
  104. #define WM8960_IFACE1_DSP_MODEA 0x00
  105. #define WM8960_IFACE1_DSP_MODEB 0x01
  106. #define WM8960_IFACE1_LRP(x) ((x << WM8960_IFACE1_LRP_SHIFT) & WM8960_IFACE1_LRP_MASK)
  107. /*! @brief WM8960_IFACE1 DLRSWAP bit */
  108. #define WM8960_IFACE1_DLRSWAP_MASK 0x20
  109. #define WM8960_IFACE1_DLRSWAP_SHIFT 0x05
  110. #define WM8960_IFACE1_DACCH_NORMAL 0x00
  111. #define WM8960_IFACE1_DACCH_SWAP 0x01
  112. #define WM8960_IFACE1_DLRSWAP(x) ((x << WM8960_IFACE1_DLRSWAP_SHIFT) & WM8960_IFACE1_DLRSWAP_MASK)
  113. /*! @brief WM8960_IFACE1 MS bit */
  114. #define WM8960_IFACE1_MS_MASK 0x40
  115. #define WM8960_IFACE1_MS_SHIFT 0x06
  116. #define WM8960_IFACE1_SLAVE 0x00
  117. #define WM8960_IFACE1_MASTER 0x01
  118. #define WM8960_IFACE1_MS(x) ((x << WM8960_IFACE1_MS_SHIFT) & WM8960_IFACE1_MS_MASK)
  119. /*! @brief WM8960_IFACE1 BCLKINV bit */
  120. #define WM8960_IFACE1_BCLKINV_MASK 0x80
  121. #define WM8960_IFACE1_BCLKINV_SHIFT 0x07
  122. #define WM8960_IFACE1_BCLK_NONINVERT 0x00
  123. #define WM8960_IFACE1_BCLK_INVERT 0x01
  124. #define WM8960_IFACE1_BCLKINV(x) ((x << WM8960_IFACE1_BCLKINV_SHIFT) & WM8960_IFACE1_BCLKINV_MASK)
  125. /*! @brief WM8960_IFACE1 ALRSWAP bit */
  126. #define WM8960_IFACE1_ALRSWAP_MASK 0x100
  127. #define WM8960_IFACE1_ALRSWAP_SHIFT 0x08
  128. #define WM8960_IFACE1_ADCCH_NORMAL 0x00
  129. #define WM8960_IFACE1_ADCCH_SWAP 0x01
  130. #define WM8960_IFACE1_ALRSWAP(x) ((x << WM8960_IFACE1_ALRSWAP_SHIFT) & WM8960_IFACE1_ALRSWAP_MASK)
  131. /*! @brief WM8960_POWER1 */
  132. #define WM8960_POWER1_VREF_MASK 0x40
  133. #define WM8960_POWER1_VREF_SHIFT 0x06
  134. #define WM8960_POWER1_AINL_MASK 0x20
  135. #define WM8960_POWER1_AINL_SHIFT 0x05
  136. #define WM8960_POWER1_AINR_MASK 0x10
  137. #define WM8960_POWER1_AINR_SHIFT 0x04
  138. #define WM8960_POWER1_ADCL_MASK 0x08
  139. #define WM8960_POWER1_ADCL_SHIFT 0x03
  140. #define WM8960_POWER1_ADCR_MASK 0x0
  141. #define WM8960_POWER1_ADCR_SHIFT 0x02
  142. #define WM8960_POWER1_MICB_MASK 0x02
  143. #define WM8960_POWER1_MICB_SHIFT 0x01
  144. #define WM8960_POWER1_DIGENB_MASK 0x01
  145. #define WM8960_POWER1_DIGENB_SHIFT 0x00
  146. /*! @brief WM8960_POWER2 */
  147. #define WM8960_POWER2_DACL_MASK 0x100
  148. #define WM8960_POWER2_DACL_SHIFT 0x08
  149. #define WM8960_POWER2_DACR_MASK 0x80
  150. #define WM8960_POWER2_DACR_SHIFT 0x07
  151. #define WM8960_POWER2_LOUT1_MASK 0x40
  152. #define WM8960_POWER2_LOUT1_SHIFT 0x06
  153. #define WM8960_POWER2_ROUT1_MASK 0x20
  154. #define WM8960_POWER2_ROUT1_SHIFT 0x05
  155. #define WM8960_POWER2_SPKL_MASK 0x10
  156. #define WM8960_POWER2_SPKL_SHIFT 0x04
  157. #define WM8960_POWER2_SPKR_MASK 0x08
  158. #define WM8960_POWER2_SPKR_SHIFT 0x03
  159. #define WM8960_POWER3_LMIC_MASK 0x20
  160. #define WM8960_POWER3_LMIC_SHIFT 0x05
  161. #define WM8960_POWER3_RMIC_MASK 0x10
  162. #define WM8960_POWER3_RMIC_SHIFT 0x04
  163. #define WM8960_POWER3_LOMIX_MASK 0x08
  164. #define WM8960_POWER3_LOMIX_SHIFT 0x03
  165. #define WM8960_POWER3_ROMIX_MASK 0x04
  166. #define WM8960_POWER3_ROMIX_SHIFT 0x02
  167. /*! @brief WM8960 I2C address. */
  168. #define WM8960_I2C_ADDR 0x1A
  169. /*! @brief WM8960 I2C baudrate */
  170. #define WM8960_I2C_BAUDRATE (100000U)
  171. /*! @brief Modules in WM8960 board. */
  172. typedef enum _wm8960_module
  173. {
  174. kWM8960_ModuleADC = 0, /*!< ADC module in WM8960 */
  175. kWM8960_ModuleDAC = 1, /*!< DAC module in WM8960 */
  176. kWM8960_ModuleVREF = 2, /*!< VREF module */
  177. kWM8960_ModuleHP = 3, /*!< Headphone */
  178. kWM8960_ModuleMICB = 4, /*!< Mic bias */
  179. kWM8960_ModuleMIC = 5, /*!< Input Mic */
  180. kWM8960_ModuleLineIn = 6, /*!< Analog in PGA */
  181. kWM8960_ModuleLineOut = 7, /*!< Line out module */
  182. kWM8960_ModuleSpeaker = 8, /*!< Speaker module */
  183. kWM8960_ModuleOMIX = 9, /*!< Output mixer */
  184. } wm8960_module_t;
  185. /*! @brief wm8960 play channel */
  186. enum _wm8960_play_channel
  187. {
  188. kWM8960_HeadphoneLeft = 1, /*!< wm8960 headphone left channel */
  189. kWM8960_HeadphoneRight = 2, /*!< wm8960 headphone right channel */
  190. kWM8960_SpeakerLeft = 4, /*!< wm8960 speaker left channel */
  191. kWM8960_SpeakerRight = 8, /*!< wm8960 speaker right channel */
  192. };
  193. /*! @brief wm8960 play source */
  194. typedef enum _wm8960_play_source
  195. {
  196. kWM8960_PlaySourcePGA = 1, /*!< wm8960 play source PGA */
  197. kWM8960_PlaySourceInput = 2, /*!< wm8960 play source Input */
  198. kWM8960_PlaySourceDAC = 4, /*!< wm8960 play source DAC */
  199. } wm8960_play_source_t;
  200. /*!
  201. * @brief WM8960 data route.
  202. * Only provide some typical data route, not all route listed.
  203. * Note: Users cannot combine any routes, once a new route is set, the previous one would be replaced.
  204. */
  205. typedef enum _wm8960_route
  206. {
  207. kWM8960_RouteBypass = 0, /*!< LINEIN->Headphone. */
  208. kWM8960_RoutePlayback = 1, /*!< I2SIN->DAC->Headphone. */
  209. kWM8960_RoutePlaybackandRecord = 2, /*!< I2SIN->DAC->Headphone, LINEIN->ADC->I2SOUT. */
  210. kWM8960_RouteRecord = 5 /*!< LINEIN->ADC->I2SOUT. */
  211. } wm8960_route_t;
  212. /*!
  213. * @brief The audio data transfer protocol choice.
  214. * WM8960 only supports I2S format and PCM format.
  215. */
  216. typedef enum _wm8960_protocol
  217. {
  218. kWM8960_BusI2S = 2, /*!< I2S type */
  219. kWM8960_BusLeftJustified = 1, /*!< Left justified mode */
  220. kWM8960_BusRightJustified = 0, /*!< Right justified mode */
  221. kWM8960_BusPCMA = 3, /*!< PCM A mode */
  222. kWM8960_BusPCMB = 3 | (1 << 4) /*!< PCM B mode */
  223. } wm8960_protocol_t;
  224. /*! @brief wm8960 input source */
  225. typedef enum _wm8960_input
  226. {
  227. kWM8960_InputClosed = 0, /*!< Input device is closed */
  228. kWM8960_InputSingleEndedMic = 1, /*!< Input as single ended mic, only use L/RINPUT1 */
  229. kWM8960_InputDifferentialMicInput2 = 2, /*!< Input as differential mic, use L/RINPUT1 and L/RINPUT2 */
  230. kWM8960_InputDifferentialMicInput3 = 3, /*!< Input as differential mic, use L/RINPUT1 and L/RINPUT3*/
  231. kWM8960_InputLineINPUT2 = 4, /*!< Input as line input, only use L/RINPUT2 */
  232. kWM8960_InputLineINPUT3 = 5 /*!< Input as line input, only use L/RINPUT3 */
  233. } wm8960_input_t;
  234. /*! @brief audio sample rate definition */
  235. enum _wm8960_sample_rate
  236. {
  237. kWM8960_AudioSampleRate8KHz = 8000U, /*!< Sample rate 8000 Hz */
  238. kWM8960_AudioSampleRate11025Hz = 11025U, /*!< Sample rate 11025 Hz */
  239. kWM8960_AudioSampleRate12KHz = 12000U, /*!< Sample rate 12000 Hz */
  240. kWM8960_AudioSampleRate16KHz = 16000U, /*!< Sample rate 16000 Hz */
  241. kWM8960_AudioSampleRate22050Hz = 22050U, /*!< Sample rate 22050 Hz */
  242. kWM8960_AudioSampleRate24KHz = 24000U, /*!< Sample rate 24000 Hz */
  243. kWM8960_AudioSampleRate32KHz = 32000U, /*!< Sample rate 32000 Hz */
  244. kWM8960_AudioSampleRate44100Hz = 44100U, /*!< Sample rate 44100 Hz */
  245. kWM8960_AudioSampleRate48KHz = 48000U, /*!< Sample rate 48000 Hz */
  246. kWM8960_AudioSampleRate96KHz = 96000U, /*!< Sample rate 96000 Hz */
  247. kWM8960_AudioSampleRate192KHz = 192000U, /*!< Sample rate 192000 Hz */
  248. kWM8960_AudioSampleRate384KHz = 384000U, /*!< Sample rate 384000 Hz */
  249. };
  250. /*! @brief audio bit width */
  251. enum _wm8960_audio_bit_width
  252. {
  253. kWM8960_AudioBitWidth16bit = 16U, /*!< audio bit width 16 */
  254. kWM8960_AudioBitWidth20bit = 20U, /*!< audio bit width 20 */
  255. kWM8960_AudioBitWidth24bit = 24U, /*!< audio bit width 24 */
  256. kWM8960_AudioBitWidth32bit = 32U, /*!< audio bit width 32 */
  257. };
  258. /*! @brief wm8960 audio format */
  259. typedef struct _wm8960_audio_format
  260. {
  261. uint32_t mclk_HZ; /*!< master clock frequency */
  262. uint32_t sampleRate; /*!< sample rate */
  263. uint32_t bitWidth; /*!< bit width */
  264. } wm8960_audio_format_t;
  265. /*! @brief Initialize structure of WM8960 */
  266. typedef struct wm8960_config
  267. {
  268. wm8960_route_t route; /*!< Audio data route.*/
  269. wm8960_protocol_t bus; /*!< Audio transfer protocol */
  270. wm8960_audio_format_t format; /*!< Audio format */
  271. rt_bool_t master_slave; /*!< Master or slave. */
  272. rt_bool_t enableSpeaker; /*!< True means enable class D speaker as output, false means no */
  273. wm8960_input_t leftInputSource; /*!< Left input source for WM8960 */
  274. wm8960_input_t rightInputSource; /*!< Right input source for wm8960 */
  275. wm8960_play_source_t playSource; /*!< play source */
  276. uint8_t slaveAddress; /*!< wm8960 device address */
  277. //codec_i2c_config_t i2cConfig; /*!< i2c configuration */
  278. } wm8960_config_t;
  279. /*! @brief wm8960 codec handler
  280. * Applicationi should allocate a buffer with WM8960_HANDLE_SIZE for handle definition, such as
  281. * uint8_t wm8960HandleBuffer[WM8960_HANDLE_SIZE];
  282. * wm8904_handle_t *wm8904Handle = wm8960HandleBuffer;
  283. */
  284. typedef struct _wm8960_handle
  285. {
  286. const wm8960_config_t *config; /*!< wm8904 config pointer */
  287. void *i2cHandle; /*!< i2c handle */
  288. } wm8960_handle_t;
  289. /*******************************************************************************
  290. * API
  291. ******************************************************************************/
  292. #if defined(__cplusplus)
  293. extern "C" {
  294. #endif
  295. /*!
  296. * @brief WM8960 initialize function.
  297. *
  298. * The second parameter is NULL to WM8960 in this version. If users want
  299. * to change the settings, they have to use wm8960_write_reg() or wm8960_modify_reg()
  300. * to set the register value of WM8960.
  301. * Note: If the codec_config is NULL, it would initialize WM8960 using default settings.
  302. * The default setting:
  303. * codec_config->route = kWM8960_RoutePlaybackandRecord
  304. * codec_config->bus = kWM8960_BusI2S
  305. * codec_config->master = slave
  306. *
  307. * @param handle WM8960 handle structure.
  308. * @param wm8960Config WM8960 configuration structure.
  309. */
  310. void WM8960_init(struct rt_i2c_bus_device *dev, wm8960_config_t *wm8960Config);
  311. /*!
  312. * @brief Deinit the WM8960 codec.
  313. *
  314. * This function close all modules in WM8960 to save power.
  315. *
  316. * @param handle WM8960 handle structure pointer.
  317. */
  318. void WM8960_Deinit(struct rt_i2c_bus_device *dev);
  319. /*!
  320. * @brief Set audio data route in WM8960.
  321. *
  322. * This function would set the data route according to route. The route cannot be combined,
  323. * as all route would enable different modules.
  324. * Note: If a new route is set, the previous route would not work.
  325. *
  326. * @param handle WM8960 handle structure.
  327. * @param route Audio data route in WM8960.
  328. */
  329. void WM8960_SetDataRoute(struct rt_i2c_bus_device *dev, wm8960_route_t route);
  330. /*!
  331. * @brief Set left audio input source in WM8960.
  332. *
  333. * @param handle WM8960 handle structure.
  334. * @param input Audio input source.
  335. */
  336. void WM8960_SetLeftInput(struct rt_i2c_bus_device *dev, wm8960_input_t input);
  337. /*!
  338. * @brief Set right audio input source in WM8960.
  339. *
  340. * @param handle WM8960 handle structure.
  341. * @param input Audio input source.
  342. */
  343. void WM8960_SetRightInput(struct rt_i2c_bus_device *dev, wm8960_input_t input);
  344. /*!
  345. * @brief Set the audio transfer protocol.
  346. *
  347. * WM8960 only supports I2S, left justified, right justified, PCM A, PCM B format.
  348. *
  349. * @param handle WM8960 handle structure.
  350. * @param bus Audio data transfer protocol.
  351. */
  352. void WM8960_SetProtocol(struct rt_i2c_bus_device *dev, wm8960_protocol_t protocol);
  353. /*!
  354. * @brief Set WM8960 as master or slave.
  355. *
  356. * @param handle WM8960 handle structure.
  357. * @param master 1 represent master, 0 represent slave.
  358. */
  359. void WM8960_SetMasterSlave(struct rt_i2c_bus_device *dev, rt_bool_t master);
  360. /*!
  361. * @brief Set the volume of different modules in WM8960.
  362. *
  363. * This function would set the volume of WM8960 modules. Uses need to appoint the module.
  364. * The function assume that left channel and right channel has the same volume.
  365. *
  366. * @param handle WM8960 handle structure.
  367. * @param module Module to set volume, it can be ADC, DAC, Headphone and so on.
  368. * @param volume Volume value need to be set.
  369. */
  370. void WM8960_SetVolume(struct rt_i2c_bus_device *dev, wm8960_module_t module, rt_uint32_t volume);
  371. /*!
  372. * @brief Get the volume of different modules in WM8960.
  373. *
  374. * This function gets the volume of WM8960 modules. Uses need to appoint the module.
  375. * The function assume that left channel and right channel has the same volume.
  376. *
  377. * @param handle WM8960 handle structure.
  378. * @param module Module to set volume, it can be ADC, DAC, Headphone and so on.
  379. * @return Volume value of the module.
  380. */
  381. rt_uint32_t WM8960_GetVolume(struct rt_i2c_bus_device *dev, wm8960_module_t module);
  382. /*!
  383. * @brief Mute modules in WM8960.
  384. *
  385. * @param handle WM8960 handle structure.
  386. * @param module Modules need to be mute.
  387. * @param isEnabled Mute or unmute, 1 represent mute.
  388. */
  389. void WM8960_SetMute(struct rt_i2c_bus_device *dev, wm8960_module_t module, rt_bool_t isEnabled);
  390. /*!
  391. * @brief Enable/disable expected devices.
  392. *
  393. * @param handle WM8960 handle structure.
  394. * @param module Module expected to enable.
  395. * @param isEnabled Enable or disable moudles.
  396. */
  397. void WM8960_SetModule(struct rt_i2c_bus_device *dev, wm8960_module_t module, rt_bool_t isEnabled);
  398. /*!
  399. * @brief SET the WM8960 play source.
  400. *
  401. * @param handle WM8960 handle structure.
  402. * @param playSource play source , can be a value combine of kWM8960_ModuleHeadphoneSourcePGA,
  403. * kWM8960_ModuleHeadphoneSourceDAC, kWM8960_ModulePlaySourceInput, kWM8960_ModulePlayMonoRight,
  404. * kWM8960_ModulePlayMonoLeft.
  405. *
  406. * @return kStatus_WM8904_Success if successful, different code otherwise..
  407. */
  408. void WM8960_SetPlay(struct rt_i2c_bus_device *dev, uint32_t playSource);
  409. /*!
  410. * @brief Configure the data format of audio data.
  411. *
  412. * This function would configure the registers about the sample rate, bit depths.
  413. *
  414. * @param handle WM8960 handle structure pointer.
  415. * @param sysclk system clock of the codec which can be generated by MCLK or PLL output.
  416. * @param sample_rate Sample rate of audio file running in WM8960. WM8960 now
  417. * supports 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, 44.1k, 48k and 96k sample rate.
  418. * @param bits Bit depth of audio file (WM8960 only supports 16bit, 20bit, 24bit
  419. * and 32 bit in HW).
  420. */
  421. void WM8960_ConfigDataFormat(struct rt_i2c_bus_device *dev, uint32_t sysclk, rt_uint32_t sample_rate, rt_uint32_t bits);
  422. /*!
  423. * @brief Enable/disable jack detect feature.
  424. *
  425. * @param handle WM8960 handle structure.
  426. * @param isEnabled Enable or disable moudles.
  427. */
  428. void WM8960_SetJackDetect(struct rt_i2c_bus_device *dev, rt_bool_t isEnabled);
  429. /*!
  430. * @brief Write register to WM8960 using I2C.
  431. *
  432. * @param handle WM8960 handle structure.
  433. * @param reg The register address in WM8960.
  434. * @param val Value needs to write into the register.
  435. */
  436. void wm8960_write_reg(struct rt_i2c_bus_device *dev, rt_uint8_t reg, rt_uint16_t val);
  437. /*!
  438. * @brief Read register from WM8960 using I2C.
  439. * @param handle WM8960 handle structure.
  440. * @param reg The register address in WM8960.
  441. * @param val Value written to.
  442. */
  443. void wm8960_read_reg(struct rt_i2c_bus_device *dev, rt_uint8_t reg, rt_uint16_t *val);
  444. /*!
  445. * @brief Modify some bits in the register using I2C.
  446. * @param handle WM8960 handle structure.
  447. * @param reg The register address in WM8960.
  448. * @param mask The mask code for the bits want to write. The bit you want to write should be 0.
  449. * @param val Value needs to write into the register.
  450. */
  451. void wm8960_modify_reg(struct rt_i2c_bus_device *dev, rt_uint8_t reg, rt_uint16_t mask, rt_uint16_t val);
  452. #if defined(__cplusplus)
  453. }
  454. #endif
  455. /*! @} */
  456. #endif /* _FSL_WM8960_H_ */
  457. /*******************************************************************************
  458. * API
  459. ******************************************************************************/