cs43l22.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /****************************************************************************
  2. * drivers/audio/cs43l22.h
  3. *
  4. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Reference:
  8. * "CS43L22 Ultra Low Power CODEC for Portable Audio Applications, Pre-
  9. * Production", September 2012, Rev 3.3, Wolfson Microelectronics
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. * 3. Neither the name NuttX nor the names of its contributors may be
  22. * used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  28. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  29. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  30. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  32. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  33. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ****************************************************************************/
  39. #ifndef __DRIVERS_AUDIO_CS43L22_H
  40. #define __DRIVERS_AUDIO_CS43L22_H
  41. /****************************************************************************
  42. * Included Files
  43. ****************************************************************************/
  44. #include <nuttx/config.h>
  45. #include <nuttx/compiler.h>
  46. #include <pthread.h>
  47. #include <mqueue.h>
  48. #include <nuttx/wqueue.h>
  49. #include <nuttx/fs/ioctl.h>
  50. #define getreg32(a) (*(volatile uint32_t *)(a))
  51. #define putreg32(v,a) (*(volatile uint32_t *)(a) = (v))
  52. #define getreg16(a) (*(volatile uint16_t *)(a))
  53. #define putreg16(v,a) (*(volatile uint16_t *)(a) = (v))
  54. #ifdef CONFIG_AUDIO
  55. /****************************************************************************
  56. * Pre-Processor Definitions
  57. ****************************************************************************/
  58. /* So far, I have not been able to get FLL lock interrupts. Worse, I have
  59. * been able to get the FLL to claim that it is locked at all even when
  60. * polling. What am I doing wrong?
  61. *
  62. * Hmmm.. seems unnecessary anyway
  63. */
  64. #undef CS43L22_USE_FFLOCK_INT
  65. #undef CS43L22_USE_FFLOCK_POLL
  66. /* Registers Addresses ******************************************************/
  67. #define CS43L22_ID_REV 0x01 /* Chip I.D. and Revision */
  68. #define CS43L22_POWER_CTRL1 0x02 /* Power Control 1 */
  69. #define CS43L22_POWER_CTRL2 0x04 /* Power Control 2 */
  70. #define CS43L22_CLOCK_CTRL 0x05 /* Clocking Control */
  71. #define CS43L22_INTERFACE_CTRL1 0x06 /* Interface Control 1 */
  72. #define CS43L22_INTERFACE_CTRL2 0x07 /* Interface Control 2 */
  73. #define CS43L22_PASS_SEL_A 0x08 /* Passthrough x Select: PassA */
  74. #define CS43L22_PASS_SEL_B 0x09 /* Passthrough x Select: PassB */
  75. #define CS43L22_ANLG_ZC_SR_SEL 0x0A /* Analog ZC and SR Settings */
  76. #define CS43L22_PASS_GANG_CTRL 0x0C /* Passthrough Gang Control */
  77. #define CS43L22_PLAYBACK_CTRL1 0x0D /* Playback Control 1 */
  78. #define CS43L22_MISCLLNS_CTRL 0x0E /* Miscellaneous Controls */
  79. #define CS43L22_PLAYBACK_CTRL2 0x0F /* Playback Control 2 */
  80. #define CS43L22_PASS_VOL_A 0x14 /* Passthrough x Volume: PASSAVOL */
  81. #define CS43L22_PASS_VOL_B 0x15 /* Passthrough x Volume: PASSBVOL */
  82. #define CS43L22_PCM_VOL_A 0x1A /* PCMx Volume: PCMA */
  83. #define CS43L22_PCM_VOL_B 0x1B /* PCMx Volume: PCMB */
  84. #define CS43L22_BP_FREQ_ON_TIME 0x1C /* Beep Frequency & On Time */
  85. #define CS43L22_BP_VOL_OFF_TIME 0x1D /* Beep Volume & Off Time */
  86. #define CS43L22_BP_TONE_CFG 0x1E /* Beep & Tone Configuration */
  87. #define CS43L22_TONE_CTRL 0x1F /* Tone Control */
  88. #define CS43L22_MS_VOL_CTRL_A 0x20 /* Master Volume Control: MSTA */
  89. #define CS43L22_MS_VOL_CTRL_B 0x21 /* Master Volume Control: MSTB */
  90. #define CS43L22_HP_VOL_CTRL_A 0x22 /* Headphone Volume Control: HPA */
  91. #define CS43L22_HP_VOL_CTRL_B 0x23 /* Headphone Volume Control: HPB */
  92. #define CS43L22_SPK_VOL_CTRL_A 0x24 /* Speaker Volume Control: SPKA */
  93. #define CS43L22_SPK_VOL_CTRL_B 0x25 /* Speaker Volume Control: SPKB */
  94. #define CS43L22_PCM_CH_SWAP 0x26 /* PCM Channel Swap */
  95. #define CS43L22_LIM_CTRL1 0x27 /* Limiter Control 1, Min/Max Thresholds */
  96. #define CS43L22_LIM_CTRL2 0x28 /* Limiter Control 2, Release Rate */
  97. #define CS43L22_LIM_ATTACK_RATE 0x29 /* Limiter Attack Rate */
  98. #define CS43L22_STATUS 0x2E /* Status */
  99. #define CS43L22_BAT_COMP 0x2F /* Battery Compensation */
  100. #define CS43L22_VP_BAT_LEVEL 0x30 /* VP Battery Level */
  101. #define CS43L22_SPK_STATUS 0x31 /* Speaker Status */
  102. #define CS43L22_TEMP_MON_CTRL 0x32 /* Temperature Monitor Control */
  103. #define CS43L22_THERMAL_FOLDBACK 0x33 /* Thermal Foldback */
  104. #define CS43L22_CHRG_PUMP_FREQ 0x34 /* Charge Pump Frequency */
  105. #define CS43L22_HPBMUTE (1 << 7)
  106. #define CS43L22_HPAMUTE (1 << 6)
  107. #define CS43L22_SPKBMUTE (1 << 5)
  108. #define CS43L22_SPKAMUTE (1 << 4)
  109. /* Register Default Values **************************************************/
  110. /* Registers have some undocumented bits set on power up. These probably
  111. * should be retained on writes (?).
  112. */
  113. #define CS43L22_ID_REV_DEFAULT 0xe3 /* Chip I.D. and Revision */
  114. #define CS43L22_POWER_CTRL1_DEFAULT 0x01 /* Power Control 1 */
  115. #define CS43L22_POWER_CTRL2_DEFAULT 0x05 /* Power Control 2 */
  116. #define CS43L22_CLOCK_CTRL_DEFAULT 0xa0 /* Clocking Control */
  117. #define CS43L22_INTERFACE_CTRL1_DEFAULT 0x00 /* Interface Control 1 */
  118. #define CS43L22_INTERFACE_CTRL2_DEFAULT 0x00 /* Interface Control 2 */
  119. #define CS43L22_PASS_SEL_A_DEFAULT 0x81 /* Passthrough x Select: PassA */
  120. #define CS43L22_PASS_SEL_B_DEFAULT 0x81 /* Passthrough x Select: PassB */
  121. #define CS43L22_ANLG_ZC_SR_SEL_DEFAULT 0xa5 /* Analog ZC and SR Settings */
  122. #define CS43L22_PASS_GANG_CTRL_DEFAULT 0x00 /* Passthrough Gang Control */
  123. #define CS43L22_PLAYBACK_CTRL1_DEFAULT 0x60 /* Playback Control 1 */
  124. #define CS43L22_MISCLLNS_CTRL_DEFAULT 0x02 /* Miscellaneous Controls */
  125. #define CS43L22_PLAYBACK_CTRL2_DEFAULT 0x00 /* Playback Control 2 */
  126. #define CS43L22_PASS_VOL_A_DEFAULT 0x00 /* Passthrough x Volume: PASSAVOL */
  127. #define CS43L22_PASS_VOL_B_DEFAULT 0x00 /* Passthrough x Volume: PASSBVOL */
  128. #define CS43L22_PCM_VOL_A_DEFAULT 0x00 /* PCMx Volume: PCMA */
  129. #define CS43L22_PCM_VOL_B_DEFAULT 0x00 /* PCMx Volume: PCMB */
  130. #define CS43L22_BP_FREQ_ON_TIME_DEFAULT 0x00 /* Beep Frequency & On Time */
  131. #define CS43L22_BP_VOL_OFF_TIME_DEFAULT 0x00 /* Beep Volume & Off Time */
  132. #define CS43L22_BP_TONE_CFG_DEFAULT 0x00 /* Beep & Tone Configuration */
  133. #define CS43L22_TONE_CTRL_DEFAULT 0x88 /* Tone Control */
  134. #define CS43L22_MS_VOL_CTRL_A_DEFAULT 0x00 /* Master Volume Control: MSTA */
  135. #define CS43L22_MS_VOL_CTRL_B_DEFAULT 0x00 /* Master Volume Control: MSTB */
  136. #define CS43L22_HP_VOL_CTRL_A_DEFAULT 0x00 /* Headphone Volume Control: HPA */
  137. #define CS43L22_HP_VOL_CTRL_B_DEFAULT 0x00 /* Headphone Volume Control: HPB */
  138. #define CS43L22_SPK_VOL_CTRL_A_DEFAULT 0x00 /* Speaker Volume Control: SPKA */
  139. #define CS43L22_SPK_VOL_CTRL_B_DEFAULT 0x00 /* Speaker Volume Control: SPKB */
  140. #define CS43L22_PCM_CH_SWAP_DEFAULT 0x00 /* PCM Channel Swap */
  141. #define CS43L22_LIM_CTRL1_DEFAULT 0x00 /* Limiter Control 1, Min/Max Thresholds */
  142. #define CS43L22_LIM_CTRL2_DEFAULT 0x7f /* Limiter Control 2, Release Rate */
  143. #define CS43L22_LIM_ATTACK_RATE_DEFAULT 0xc0 /* Limiter Attack Rate */
  144. #define CS43L22_STATUS_DEFAULT 0x00 /* Status */
  145. #define CS43L22_BAT_COMP_DEFAULT 0x00 /* Battery Compensation */
  146. #define CS43L22_VP_BAT_LEVEL_DEFAULT 0x00 /* VP Battery Level */
  147. #define CS43L22_SPK_STATUS_DEFAULT 0x00 /* Speaker Status */
  148. #define CS43L22_TEMP_MON_CTRL_DEFAULT 0x3b /* Temperature Monitor Control */
  149. #define CS43L22_THERMAL_FOLDBACK_DEFAULT 0x00 /* Thermal Foldback */
  150. #define CS43L22_CHRG_PUMP_FREQ_DEFAULT 0x5f /* Charge Pump Frequency */
  151. /* Register Bit Definitions *************************************************/
  152. /* 0x01 Chip I.D. and Revision (Read Only) */
  153. #define CS43L22_DEV_ID_REV (0xe3)
  154. #define CS43L22_ID_SHIFT (3)
  155. #define CS43L22_ID_MASK (0x1f << CS43L22_ID_SHIFT)
  156. #define CS43L22_REV_SHIFT (0)
  157. #define CS43L22_REV_MASK (0x07 << CS43L22_REV_SHIFT)
  158. /* 0x02 Power Control 1 */
  159. #define CS43L22_POWER_DOWN (0x01) /* Powered Down */
  160. #define CS43L22_POWER_UP (0x9e) /* Powered Up */
  161. /* 0x04 Power Control 2 */
  162. #define CS43L22_PDN_HPB_SHIFT (6) /* Bits 6-7: Headphone channel B Control */
  163. #define CS43L22_PDN_HPB_ON_HW_PIN_LO (0 << CS43L22_PDN_HPB_SHIFT) /* PDN_HPx[1:0] 00 Headphone channel is ON when the SPK/HP_SW pin, 6, is LO
  164. Headphone channel is OFF when the SPK/HP_SW pin, 6, is HI */
  165. #define CS43L22_PDN_HPB_ON_HW_PIN_HI (1 << CS43L22_PDN_HPB_SHIFT) /* PDN_HPx[1:0] 01 Headphone channel is ON when the SPK/HP_SW pin, 6, is HI
  166. Headphone channel is OFF when the SPK/HP_SW pin, 6, is LO */
  167. #define CS43L22_PDN_HPB_ON (2 << CS43L22_PDN_HPB_SHIFT) /* PDN_HPx[1:0] 10 Headphone channel is always ON */
  168. #define CS43L22_PDN_HPB_OFF (3 << CS43L22_PDN_HPB_SHIFT) /* PDN_HPx[1:0] 11 Headphone channel is always OFF */
  169. #define CS43L22_PDN_HPA_SHIFT (4) /* Bits 4-5: Headphone channel A Control */
  170. #define CS43L22_PDN_HPA_ON_HW_PIN_LO (0 << CS43L22_PDN_HPA_SHIFT) /* PDN_HPx[1:0] 00 Headphone channel is ON when the SPK/HP_SW pin, 6, is LO
  171. Headphone channel is OFF when the SPK/HP_SW pin, 6, is HI */
  172. #define CS43L22_PDN_HPA_ON_HW_PIN_HI (1 << CS43L22_PDN_HPA_SHIFT) /* PDN_HPx[1:0] 01 Headphone channel is ON when the SPK/HP_SW pin, 6, is HI
  173. Headphone channel is OFF when the SPK/HP_SW pin, 6, is LO */
  174. #define CS43L22_PDN_HPA_ON (2 << CS43L22_PDN_HPA_SHIFT) /* PDN_HPx[1:0] 10 Headphone channel is always ON */
  175. #define CS43L22_PDN_HPA_OFF (3 << CS43L22_PDN_HPA_SHIFT) /* PDN_HPx[1:0] 11 Headphone channel is always OFF */
  176. #define CS43L22_PDN_SPKB_SHIFT (2) /* Bits 2-3: Speaker channel B Control */
  177. #define CS43L22_PDN_SPKB_ON_HW_PIN_LO (0 << CS43L22_PDN_SPKB_SHIFT) /* PDN_HPx[1:0] 00 Speaker channel is ON when the SPK/HP_SW pin, 6, is LO
  178. Speaker channel is OFF when the SPK/HP_SW pin, 6, is HI */
  179. #define CS43L22_PDN_SPKB_ON_HW_PIN_HI (1 << CS43L22_PDN_SPKB_SHIFT) /* PDN_HPx[1:0] 01 Speaker channel is ON when the SPK/HP_SW pin, 6, is HI
  180. Speaker channel is OFF when the SPK/HP_SW pin, 6, is LO */
  181. #define CS43L22_PDN_SPKB_ON (2 << CS43L22_PDN_SPKB_SHIFT) /* PDN_HPx[1:0] 10 Speaker channel is always ON */
  182. #define CS43L22_PDN_SPKB_OFF (3 << CS43L22_PDN_SPKB_SHIFT) /* PDN_HPx[1:0] 11 Speaker channel is always OFF */
  183. #define CS43L22_PDN_SPKA_SHIFT (0) /* Bits 0-1: Speaker channel A Control */
  184. #define CS43L22_PDN_SPKA_ON_HW_PIN_LO (0 << CS43L22_PDN_SPKA_SHIFT) /* PDN_HPx[1:0] 00 Speaker channel is ON when the SPK/HP_SW pin, 6, is LO
  185. Speaker channel is OFF when the SPK/HP_SW pin, 6, is HI */
  186. #define CS43L22_PDN_SPKA_ON_HW_PIN_HI (1 << CS43L22_PDN_SPKA_SHIFT) /* PDN_HPx[1:0] 01 Speaker channel is ON when the SPK/HP_SW pin, 6, is HI
  187. Speaker channel is OFF when the SPK/HP_SW pin, 6, is LO */
  188. #define CS43L22_PDN_SPKA_ON (2 << CS43L22_PDN_SPKA_SHIFT) /* PDN_HPx[1:0] 10 Speaker channel is always ON */
  189. #define CS43L22_PDN_SPKA_OFF (3 << CS43L22_PDN_SPKA_SHIFT) /* PDN_HPx[1:0] 11 Speaker channel is always OFF */
  190. /* 0x05 Clocking Control */
  191. #define CS43L22_AUTO_DETECT_ENABLE (1 << 7) /* Auto-detection of speed mode enable */
  192. #define CS43L22_SPEED_SHIFT (5) /* Bits 5-6: Speed mode */
  193. #define CS43L22_SPEED_DOUBLE (0 << CS43L22_SPEED_SHIFT) /* Slave: Double-Speed Mode (DSM - 50 kHz -100 kHz Fs) Master: MCLK=512 SCLK=64*/
  194. #define CS43L22_SPEED_SINGLE (1 << CS43L22_SPEED_SHIFT) /* Slave: Single-Speed Mode (SSM - 4 kHz -50 kHz Fs) Master: MCLK=256 SCLK=64*/
  195. #define CS43L22_SPEED_HALF (2 << CS43L22_SPEED_SHIFT) /* Slave: Half-Speed Mode (HSM - 12.5kHz -25 kHz Fs) Master: MCLK=128 SCLK=64*/
  196. #define CS43L22_SPEED_QUARTER (3 << CS43L22_SPEED_SHIFT) /* Slave: Quarter-Speed Mode (QSM - 4 kHz -12.5 kHz Fs)Master: MCLK=128 SCLK=64*/
  197. #define CS43L22_32k_GROUP_ENABLE (1 << 4) /* Bit 4: Specifies whether or not the input/output sample rate is 8 kHz, 16 kHz or 32 kHz */
  198. #define CS43L22_VIDEOCLK_ENABLE (1 << 3) /* Bit 3: Specifies whether or not the external MCLK frequency is 27 MHz */
  199. #define CS43L22_MCLK_LRCK_RATIO_SHIFT (1) /* Bits 1-2: Internal MCLK/LRCK Ratio */
  200. #define CS43L22_RATIO_128_64 (0 << CS43L22_MCLK_LRCK_RATIO_SHIFT) /* RATIO[1:0] Internal MCLK Cycles per LRCK=128, SCLK/LRCK=64 Ratio in Master Mode */
  201. #define CS43L22_RATIO_125_62 (1 << CS43L22_MCLK_LRCK_RATIO_SHIFT) /* RATIO[1:0] Internal MCLK Cycles per LRCK=125, SCLK/LRCK=62 Ratio in Master Mode */
  202. #define CS43L22_RATIO_132_66 (2 << CS43L22_MCLK_LRCK_RATIO_SHIFT) /* RATIO[1:0] Internal MCLK Cycles per LRCK=132, SCLK/LRCK=66 Ratio in Master Mode */
  203. #define CS43L22_RATIO_136_68 (3 << CS43L22_MCLK_LRCK_RATIO_SHIFT) /* RATIO[1:0] Internal MCLK Cycles per LRCK=136, SCLK/LRCK=68 Ratio in Master Mode */
  204. #define CS43L22_CLKDIV2_ENABLE (1 << 0) /* Bit 0: Divided by 2 */
  205. /* 0x06 Interface Control 1 */
  206. #define CS43L22_MODE_MASTER (1 << 7) /* Configures the serial port I/O clocking */
  207. #define CS43L22_SCLK_POLARITY_INVERT (1 << 6) /* Configures the polarity of the SCLK signal */
  208. #define CS43L22_DSP_MODE_ENABLE (1 << 4) /* Configures a data-packed interface format for the DAC */
  209. #define CS43L22_DAC_IF_FORMAT_SHIFT (2) /* Bits 2-3: Configures the digital interface format for data on SDIN */
  210. #define CS43L22_DAC_IF_LEFT_JUSTIFIED (0 << CS43L22_DAC_IF_FORMAT_SHIFT) /* DACDIF[1:0] Left Justified, up to 24-bit data */
  211. #define CS43L22_DAC_IF_I2S (1 << CS43L22_DAC_IF_FORMAT_SHIFT) /* DACDIF[1:0] I2S, up to 24-bit data */
  212. #define CS43L22_DAC_IF_RIGHT_JUSTIFIED (2 << CS43L22_DAC_IF_FORMAT_SHIFT) /* DACDIF[1:0] Right Justified */
  213. #define CS43L22_DAC_IF_RESERVED (3 << CS43L22_DAC_IF_FORMAT_SHIFT) /* DACDIF[1:0] Reserved */
  214. #define CS43L22_AUDIO_WORD_LENGHT_SHIFT (0) /* Bits 0-1: Configures the audio sample word length used for the data into SDIN */
  215. #define CS43L22_AWL_DSP_32_RJ_24 (0 << CS43L22_AUDIO_WORD_LENGHT_SHIFT)/* AWL[1:0] DSP Mode: 32-bit data, Right Justified: 24-bit data */
  216. #define CS43L22_AWL_DSP_24_RJ_20 (1 << CS43L22_AUDIO_WORD_LENGHT_SHIFT)/* AWL[1:0] DSP Mode: 24-bit data, Right Justified: 20-bit data */
  217. #define CS43L22_AWL_DSP_20_RJ_18 (2 << CS43L22_AUDIO_WORD_LENGHT_SHIFT)/* AWL[1:0] DSP Mode: 20-bit data, Right Justified: 18-bit data */
  218. #define CS43L22_AWL_DSP_16_RJ_16 (3 << CS43L22_AUDIO_WORD_LENGHT_SHIFT)/* AWL[1:0] DSP Mode: 16 bit data, Right Justified: 16-bit data */
  219. /* 0x0E Miscellaneous Controls */
  220. #define CS43L22_FREEZE (1 << 3) /* Configures a hold on all register settings */
  221. #define CS43L22_DEEMPHASIS_ENABLE (1 << 2) /* Configures a 15μs/50μs digital de-emphasis filter response on the headphone/line and speaker outputs */
  222. /* 0x1F Tone Control */
  223. #define CS43L22_TREB_GAIN_SHIFT (4) /* Sets the gain of the treble shelving filter */
  224. #define CS43L22_TREB_GAIN(a) ((a) << CS43L22_TREB_GAIN_SHIFT)
  225. /* TREB[3:0] Gain Setting:*/
  226. /* 0000 +12.0 dB */
  227. /* ··· ··· */
  228. /* 0111 +1.5 dB */
  229. /* 1000 0 dB */
  230. /* 1001 -1.5 dB */
  231. /* 1111 -10.5 dB */
  232. /* Step Size: 1.5 dB */
  233. #define CS43L22_BASS_GAIN_SHIFT (0) /* Sets the gain of the bass shelving filter */
  234. #define CS43L22_BASS_GAIN(a) ((a) << CS43L22_BASS_GAIN_SHIFT)
  235. /* BASS[3:0] Gain Setting:*/
  236. /* 0000 +12.0 dB */
  237. /* ··· ··· */
  238. /* 0111 +1.5 dB */
  239. /* 1000 0 dB */
  240. /* 1001 -1.5 dB */
  241. /* 1111 -10.5 dB */
  242. /* Step Size: 1.5 dB */
  243. /* FLL Configuration *********************************************************/
  244. /* Default FLL configuration */
  245. #define CS43L22_DEFAULT_SAMPRATE 11025 /* Initial sample rate */
  246. #define CS43L22_DEFAULT_NCHANNELS 1 /* Initial number of channels */
  247. #define CS43L22_DEFAULT_BPSAMP 16 /* Initial bits per sample */
  248. #define CS43L22_NFLLRATIO 5 /* Number of FLL_RATIO values */
  249. #define CS43L22_MINOUTDIV 4 /* Minimum FLL_OUTDIV divider */
  250. #define CS43L22_MAXOUTDIV 64 /* Maximum FLL_OUTDIV divider */
  251. #define CS43L22_BCLK_MAXDIV 20 /* Maximum BCLK divider */
  252. #define CS43L22_FRAMELEN8 14 /* Bits per frame for 8-bit data */
  253. #define CS43L22_FRAMELEN16 32 /* Bits per frame for 16-bit data */
  254. /* Commonly defined and redefined macros */
  255. #ifndef MIN
  256. # define MIN(a,b) (((a) < (b)) ? (a) : (b))
  257. #endif
  258. #ifndef MAX
  259. # define MAX(a,b) (((a) > (b)) ? (a) : (b))
  260. #endif
  261. /****************************************************************************
  262. * Public Types
  263. ****************************************************************************/
  264. struct cs43l22_dev_s
  265. {
  266. /* We are an audio lower half driver (We are also the upper "half" of
  267. * the CS43L22 driver with respect to the board lower half driver).
  268. *
  269. * Terminology: Our "lower" half audio instances will be called dev for the
  270. * publicly visible version and "priv" for the version that only this driver
  271. * knows. From the point of view of this driver, it is the board lower
  272. * "half" that is referred to as "lower".
  273. */
  274. struct audio_lowerhalf_s dev; /* CS43L22 audio lower half (this device) */
  275. /* Our specific driver data goes here */
  276. const FAR struct cs43l22_lower_s *lower; /* Pointer to the board lower functions */
  277. FAR struct i2c_master_s *i2c; /* I2C driver to use */
  278. FAR struct i2s_dev_s *i2s; /* I2S driver to use */
  279. struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
  280. struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
  281. mqd_t mq; /* Message queue for receiving messages */
  282. char mqname[16]; /* Our message queue name */
  283. pthread_t threadid; /* ID of our thread */
  284. uint32_t bitrate; /* Actual programmed bit rate */
  285. sem_t pendsem; /* Protect pendq */
  286. #ifdef CS43L22_USE_FFLOCK_INT
  287. struct work_s work; /* Interrupt work */
  288. #endif
  289. uint16_t samprate; /* Configured samprate (samples/sec) */
  290. #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
  291. #ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
  292. uint16_t balance; /* Current balance level (b16) */
  293. #endif /* CONFIG_AUDIO_EXCLUDE_BALANCE */
  294. uint8_t volume; /* Current volume level {0..63} */
  295. #endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */
  296. uint8_t nchannels; /* Number of channels (1 or 2) */
  297. uint8_t bpsamp; /* Bits per sample (8 or 16) */
  298. volatile uint8_t inflight; /* Number of audio buffers in-flight */
  299. #ifdef CS43L22_USE_FFLOCK_INT
  300. volatile bool locked; /* FLL is locked */
  301. #endif
  302. bool running; /* True: Worker thread is running */
  303. bool paused; /* True: Playing is paused */
  304. bool mute; /* True: Output is muted */
  305. #ifndef CONFIG_AUDIO_EXCLUDE_STOP
  306. bool terminating; /* True: Stop requested */
  307. #endif
  308. bool reserved; /* True: Device is reserved */
  309. volatile int result; /* The result of the last transfer */
  310. };
  311. /****************************************************************************
  312. * Public Data
  313. ****************************************************************************/
  314. #ifdef CONFIG_CS43L22_CLKDEBUG
  315. extern const uint8_t g_sysclk_scaleb1[CS43L22_BCLK_MAXDIV+1];
  316. extern const uint8_t g_fllratio[CS43L22_NFLLRATIO];
  317. #endif
  318. /****************************************************************************
  319. * Public Function Prototypes
  320. ****************************************************************************/
  321. /****************************************************************************
  322. * Name: cs43l22_readreg
  323. *
  324. * Description:
  325. * Read the specified 8-bit register from the CS43L22 device.
  326. *
  327. ****************************************************************************/
  328. #if defined(CONFIG_CS43L22_REGDUMP) || defined(CONFIG_CS43L22_CLKDEBUG)
  329. struct cs43l22_dev_s;
  330. uint8_t cs43l22_readreg(FAR struct cs43l22_dev_s *priv, uint8_t regaddr);
  331. #endif
  332. #endif /* CONFIG_AUDIO */
  333. #endif /* __DRIVERS_AUDIO_CS43L22_H */