cs43l22.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. ******************************************************************************
  3. * @file cs43l22.h
  4. * @author MCD Application Team
  5. * @version V2.0.2
  6. * @date 06-October-2015
  7. * @brief This file contains all the functions prototypes for the cs43l22.c driver.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __CS43L22_H
  39. #define __CS43L22_H
  40. /* Includes ------------------------------------------------------------------*/
  41. #include "../Common/audio.h"
  42. /** @addtogroup BSP
  43. * @{
  44. */
  45. /** @addtogroup Component
  46. * @{
  47. */
  48. /** @addtogroup CS43L22
  49. * @{
  50. */
  51. /** @defgroup CS43L22_Exported_Types
  52. * @{
  53. */
  54. /**
  55. * @}
  56. */
  57. /** @defgroup CS43L22_Exported_Constants
  58. * @{
  59. */
  60. /******************************************************************************/
  61. /*************************** Codec User defines ******************************/
  62. /******************************************************************************/
  63. /* Codec output DEVICE */
  64. #define OUTPUT_DEVICE_SPEAKER 1
  65. #define OUTPUT_DEVICE_HEADPHONE 2
  66. #define OUTPUT_DEVICE_BOTH 3
  67. #define OUTPUT_DEVICE_AUTO 4
  68. /* Volume Levels values */
  69. #define DEFAULT_VOLMIN 0x00
  70. #define DEFAULT_VOLMAX 0xFF
  71. #define DEFAULT_VOLSTEP 0x04
  72. #define AUDIO_PAUSE 0
  73. #define AUDIO_RESUME 1
  74. /* Codec POWER DOWN modes */
  75. #define CODEC_PDWN_HW 1
  76. #define CODEC_PDWN_SW 2
  77. /* MUTE commands */
  78. #define AUDIO_MUTE_ON 1
  79. #define AUDIO_MUTE_OFF 0
  80. /* AUDIO FREQUENCY */
  81. #define AUDIO_FREQUENCY_192K ((uint32_t)192000)
  82. #define AUDIO_FREQUENCY_96K ((uint32_t)96000)
  83. #define AUDIO_FREQUENCY_48K ((uint32_t)48000)
  84. #define AUDIO_FREQUENCY_44K ((uint32_t)44100)
  85. #define AUDIO_FREQUENCY_32K ((uint32_t)32000)
  86. #define AUDIO_FREQUENCY_22K ((uint32_t)22050)
  87. #define AUDIO_FREQUENCY_16K ((uint32_t)16000)
  88. #define AUDIO_FREQUENCY_11K ((uint32_t)11025)
  89. #define AUDIO_FREQUENCY_8K ((uint32_t)8000)
  90. /** CS43l22 Registers ***/
  91. #define CS43L22_REG_ID 0x01
  92. #define CS43L22_REG_POWER_CTL1 0x02
  93. #define CS43L22_REG_POWER_CTL2 0x04
  94. #define CS43L22_REG_CLOCKING_CTL 0x05
  95. #define CS43L22_REG_INTERFACE_CTL1 0x06
  96. #define CS43L22_REG_INTERFACE_CTL2 0x07
  97. #define CS43L22_REG_PASSTHR_A_SELECT 0x08
  98. #define CS43L22_REG_PASSTHR_B_SELECT 0x09
  99. #define CS43L22_REG_ANALOG_ZC_SR_SETT 0x0A
  100. #define CS43L22_REG_PASSTHR_GANG_CTL 0x0C
  101. #define CS43L22_REG_PLAYBACK_CTL1 0x0D
  102. #define CS43L22_REG_MISC_CTL 0x0E
  103. #define CS43L22_REG_PLAYBACK_CTL2 0x0F
  104. #define CS43L22_REG_PASSTHR_A_VOL 0x14
  105. #define CS43L22_REG_PASSTHR_B_VOL 0x15
  106. #define CS43L22_REG_PCMA_VOL 0x1A
  107. #define CS43L22_REG_PCMB_VOL 0x1B
  108. #define CS43L22_REG_BEEP_FREQ_ON_TIME 0x1C
  109. #define CS43L22_REG_BEEP_VOL_OFF_TIME 0x1D
  110. #define CS43L22_REG_BEEP_TONE_CFG 0x1E
  111. #define CS43L22_REG_TONE_CTL 0x1F
  112. #define CS43L22_REG_MASTER_A_VOL 0x20
  113. #define CS43L22_REG_MASTER_B_VOL 0x21
  114. #define CS43L22_REG_HEADPHONE_A_VOL 0x22
  115. #define CS43L22_REG_HEADPHONE_B_VOL 0x23
  116. #define CS43L22_REG_SPEAKER_A_VOL 0x24
  117. #define CS43L22_REG_SPEAKER_B_VOL 0x25
  118. #define CS43L22_REG_CH_MIXER_SWAP 0x26
  119. #define CS43L22_REG_LIMIT_CTL1 0x27
  120. #define CS43L22_REG_LIMIT_CTL2 0x28
  121. #define CS43L22_REG_LIMIT_ATTACK_RATE 0x29
  122. #define CS43L22_REG_OVF_CLK_STATUS 0x2E
  123. #define CS43L22_REG_BATT_COMPENSATION 0x2F
  124. #define CS43L22_REG_VP_BATTERY_LEVEL 0x30
  125. #define CS43L22_REG_SPEAKER_STATUS 0x31
  126. #define CS43L22_REG_TEMPMONITOR_CTL 0x32
  127. #define CS43L22_REG_THERMAL_FOLDBACK 0x33
  128. #define CS43L22_REG_CHARGE_PUMP_FREQ 0x34
  129. /******************************************************************************/
  130. /****************************** REGISTER MAPPING ******************************/
  131. /******************************************************************************/
  132. /**
  133. * @brief CS43L22 ID
  134. */
  135. #define CS43L22_ID 0xE0
  136. #define CS43L22_ID_MASK 0xF8
  137. /**
  138. * @brief Chip ID Register: Chip I.D. and Revision Register
  139. * Read only register
  140. * Default value: 0x01
  141. * [7:3] CHIPID[4:0]: I.D. code for the CS43L22.
  142. * Default value: 11100b
  143. * [2:0] REVID[2:0]: CS43L22 revision level.
  144. * Default value:
  145. * 000 - Rev A0
  146. * 001 - Rev A1
  147. * 010 - Rev B0
  148. * 011 - Rev B1
  149. */
  150. #define CS43L22_CHIPID_ADDR 0x01
  151. /**
  152. * @}
  153. */
  154. /** @defgroup CS43L22_Exported_Macros
  155. * @{
  156. */
  157. /**
  158. * @}
  159. */
  160. /** @defgroup CS43L22_Exported_Functions
  161. * @{
  162. */
  163. /*------------------------------------------------------------------------------
  164. Audio Codec functions
  165. ------------------------------------------------------------------------------*/
  166. /* High Layer codec functions */
  167. uint32_t cs43l22_Init(uint16_t DeviceAddr, uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
  168. void cs43l22_DeInit(void);
  169. uint32_t cs43l22_ReadID(uint16_t DeviceAddr);
  170. uint32_t cs43l22_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size);
  171. uint32_t cs43l22_Pause(uint16_t DeviceAddr);
  172. uint32_t cs43l22_Resume(uint16_t DeviceAddr);
  173. uint32_t cs43l22_Stop(uint16_t DeviceAddr, uint32_t Cmd);
  174. uint32_t cs43l22_SetVolume(uint16_t DeviceAddr, uint8_t Volume);
  175. uint32_t cs43l22_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq);
  176. uint32_t cs43l22_SetMute(uint16_t DeviceAddr, uint32_t Cmd);
  177. uint32_t cs43l22_SetOutputMode(uint16_t DeviceAddr, uint8_t Output);
  178. uint32_t cs43l22_Reset(uint16_t DeviceAddr);
  179. /* AUDIO IO functions */
  180. void AUDIO_IO_Init(void);
  181. void AUDIO_IO_DeInit(void);
  182. void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
  183. uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
  184. /* Audio driver structure */
  185. extern AUDIO_DrvTypeDef cs43l22_drv;
  186. #endif /* __CS43L22_H */
  187. /**
  188. * @}
  189. */
  190. /**
  191. * @}
  192. */
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @}
  198. */
  199. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/