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