STM32Cube BSP FW for STM32F769I-Discovery
Dependents: mbed-os-example-blinky-5 DISCO-F769NI_TOUCHSCREEN_demo_custom_1 Datarecorder2 DISCO-F769NI_TOUCHSCREEN_demo ... more
adv7533.c
00001 /** 00002 ****************************************************************************** 00003 * @file adv7533.c 00004 * @author MCD Application Team 00005 * @brief This file provides the ADV7533 DSI to HDMI bridge driver 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Includes ------------------------------------------------------------------*/ 00037 #include "adv7533.h" 00038 00039 /** @addtogroup BSP 00040 * @{ 00041 */ 00042 00043 /** @addtogroup Components 00044 * @{ 00045 */ 00046 00047 /** @defgroup ADV7533 ADV7533 00048 * @brief This file provides a set of functions needed to drive the 00049 * adv7533 DSI-HDMI bridge. 00050 * @{ 00051 */ 00052 00053 /* Private types -------------------------------------------------------------*/ 00054 /* Private variables ---------------------------------------------------------*/ 00055 /* Private constants ---------------------------------------------------------*/ 00056 /** @defgroup ADV7533_Private_Constants ADV7533 Private Constants 00057 * @{ 00058 */ 00059 00060 /** 00061 * @} 00062 */ 00063 00064 /* Private macros ------------------------------------------------------------*/ 00065 /* Private functions ---------------------------------------------------------*/ 00066 /** @defgroup ADV7533_Exported_Variables 00067 * @{ 00068 */ 00069 00070 AUDIO_DrvTypeDef adv7533_drv = 00071 { 00072 adv7533_AudioInit, 00073 adv7533_DeInit, 00074 adv7533_ReadID, 00075 adv7533_Play, 00076 adv7533_Pause, 00077 adv7533_Resume, 00078 adv7533_Stop, 00079 adv7533_SetFrequency, 00080 adv7533_SetVolume, /* Not supported, added for compatibility */ 00081 adv7533_SetMute, 00082 adv7533_SetOutputMode, /* Not supported, added for compatibility */ 00083 adv7533_Reset /* Not supported, added for compatibility */ 00084 }; 00085 00086 /** 00087 * @} 00088 */ 00089 00090 /* Exported functions --------------------------------------------------------*/ 00091 /** @defgroup ADV7533_Exported_Functions ADV7533 Exported Functions 00092 * @{ 00093 */ 00094 00095 /** 00096 * @brief Initializes the ADV7533 bridge. 00097 * @param None 00098 * @retval Status 00099 */ 00100 uint8_t ADV7533_Init(void) 00101 { 00102 HDMI_IO_Init(); 00103 00104 /* Configure the IC2 address for CEC_DSI interface */ 00105 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0xE1, ADV7533_CEC_DSI_I2C_ADDR); 00106 00107 return 0; 00108 } 00109 00110 /** 00111 * @brief Power on the ADV7533 bridge. 00112 * @param None 00113 * @retval None 00114 */ 00115 void ADV7533_PowerOn(void) 00116 { 00117 uint8_t tmp; 00118 00119 /* Power on */ 00120 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0x41); 00121 tmp &= ~0x40; 00122 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x41, tmp); 00123 } 00124 00125 /** 00126 * @brief Power off the ADV7533 bridge. 00127 * @param None 00128 * @retval None 00129 */ 00130 void ADV7533_PowerDown(void) 00131 { 00132 uint8_t tmp; 00133 00134 /* Power down */ 00135 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0x41); 00136 tmp |= 0x40; 00137 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x41, tmp); 00138 } 00139 00140 /** 00141 * @brief Configure the DSI-HDMI ADV7533 bridge for video. 00142 * @param config : pointer to adv7533ConfigTypeDef that contains the 00143 * video configuration parameters 00144 * @retval None 00145 */ 00146 void ADV7533_Configure(adv7533ConfigTypeDef * config) 00147 { 00148 uint8_t tmp; 00149 00150 /* Sequence from Section 3 - Quick Start Guide */ 00151 00152 /* ADV7533 Power Settings */ 00153 /* Power down */ 00154 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0x41); 00155 tmp &= ~0x40; 00156 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x41, tmp); 00157 /* HPD Override */ 00158 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0xD6); 00159 tmp |= 0x40; 00160 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0xD6, tmp); 00161 /* Gate DSI LP Oscillator and DSI Bias Clock Powerdown */ 00162 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x03); 00163 tmp &= ~0x02; 00164 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x03, tmp); 00165 00166 /* Fixed registers that must be set on power-up */ 00167 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0x16); 00168 tmp &= ~0x3E; 00169 tmp |= 0x20; 00170 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x16, tmp); 00171 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x9A, 0xE0); 00172 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0xBA); 00173 tmp &= ~0xF8; 00174 tmp |= 0x70; 00175 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0xBA, tmp); 00176 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0xDE, 0x82); 00177 00178 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0xE4); 00179 tmp |= 0x40; 00180 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0xE4, tmp); 00181 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0xE5, 0x80); 00182 00183 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x15); 00184 tmp &= ~0x30; 00185 tmp |= 0x10; 00186 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x17); 00187 tmp &= ~0xF0; 00188 tmp |= 0xD0; 00189 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x17, tmp); 00190 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x24); 00191 tmp &= ~0x10; 00192 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x24, tmp); 00193 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x57); 00194 tmp |= 0x01; 00195 tmp |= 0x10; 00196 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x57, tmp); 00197 00198 /* Configure the number of DSI lanes */ 00199 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x1C, (config->DSI_LANES << 4)); 00200 00201 /* Setup video output mode */ 00202 /* Select HDMI mode */ 00203 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0xAF); 00204 tmp |= 0x02; 00205 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0xAF, tmp); 00206 /* HDMI Output Enable */ 00207 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x03); 00208 tmp |= 0x80; 00209 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x03, tmp); 00210 00211 /* GC packet enable */ 00212 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0x40); 00213 tmp |= 0x80; 00214 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x40, tmp); 00215 /* Input color depth 24-bit per pixel */ 00216 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0x4C); 00217 tmp &= ~0x0F; 00218 tmp |= 0x03; 00219 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x4C, tmp); 00220 /* Down dither output color depth */ 00221 HDMI_IO_Write(ADV7533_MAIN_I2C_ADDR, 0x49, 0xfc); 00222 00223 /* Internal timing disabled */ 00224 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x27); 00225 tmp &= ~0x80; 00226 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x27, tmp); 00227 } 00228 00229 /** 00230 * @brief Enable video pattern generation. 00231 * @param None 00232 * @retval None 00233 */ 00234 void ADV7533_PatternEnable(void) 00235 { 00236 /* Timing generator enable */ 00237 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x55, 0x80); /* Color bar */ 00238 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x55, 0xA0); /* Color ramp */ 00239 00240 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x03, 0x89); 00241 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0xAF, 0x16); 00242 } 00243 00244 /** 00245 * @brief Disable video pattern generation. 00246 * @param none 00247 * @retval none 00248 */ 00249 void ADV7533_PatternDisable(void) 00250 { 00251 /* Timing generator enable */ 00252 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x55, 0x00); 00253 } 00254 00255 /** 00256 * @brief Initializes the ADV7533 audio interface. 00257 * @param DeviceAddr: Device address on communication Bus. 00258 * @param OutputDevice: Not used (for compatiblity only). 00259 * @param Volume: Not used (for compatiblity only). 00260 * @param AudioFreq: Audio Frequency 00261 * @retval 0 if correct communication, else wrong communication 00262 */ 00263 uint32_t adv7533_AudioInit(uint16_t DeviceAddr, uint16_t OutputDevice, uint8_t Volume,uint32_t AudioFreq) 00264 { 00265 uint32_t val = 4096; 00266 uint8_t tmp = 0; 00267 00268 /* Audio data enable*/ 00269 tmp = HDMI_IO_Read(ADV7533_CEC_DSI_I2C_ADDR, 0x05); 00270 tmp &= ~0x20; 00271 HDMI_IO_Write(ADV7533_CEC_DSI_I2C_ADDR, 0x05, tmp); 00272 00273 /* HDMI statup */ 00274 tmp= (uint8_t)((val & 0xF0000)>>16); 00275 HDMI_IO_Write(DeviceAddr, 0x01, tmp); 00276 00277 tmp= (uint8_t)((val & 0xFF00)>>8); 00278 HDMI_IO_Write(DeviceAddr, 0x02, tmp); 00279 00280 tmp= (uint8_t)((val & 0xFF)); 00281 HDMI_IO_Write(DeviceAddr, 0x03, tmp); 00282 00283 /* Enable spdif */ 00284 tmp = HDMI_IO_Read(DeviceAddr, 0x0B); 00285 tmp |= 0x80; 00286 HDMI_IO_Write(DeviceAddr, 0x0B, tmp); 00287 00288 /* Enable I2S */ 00289 tmp = HDMI_IO_Read(DeviceAddr, 0x0C); 00290 tmp |=0x04; 00291 HDMI_IO_Write(DeviceAddr, 0x0C, tmp); 00292 00293 /* Set audio sampling frequency */ 00294 adv7533_SetFrequency(DeviceAddr, AudioFreq); 00295 00296 /* Select SPDIF is 0x10 , I2S=0x00 */ 00297 tmp = HDMI_IO_Read(ADV7533_MAIN_I2C_ADDR, 0x0A); 00298 tmp &=~ 0x10; 00299 HDMI_IO_Write(DeviceAddr, 0x0A, tmp); 00300 00301 /* Set v1P2 enable */ 00302 tmp = HDMI_IO_Read(DeviceAddr, 0xE4); 00303 tmp |= 0x80; 00304 HDMI_IO_Write(DeviceAddr, 0xE4, tmp); 00305 00306 return 0; 00307 } 00308 00309 /** 00310 * @brief Deinitializes the adv7533 00311 * @param None 00312 * @retval None 00313 */ 00314 void adv7533_DeInit(void) 00315 { 00316 /* Deinitialize Audio adv7533 interface */ 00317 AUDIO_IO_DeInit(); 00318 } 00319 00320 /** 00321 * @brief Get the adv7533 ID. 00322 * @param DeviceAddr: Device address on communication Bus. 00323 * @retval The adv7533 ID 00324 */ 00325 uint32_t adv7533_ReadID(uint16_t DeviceAddr) 00326 { 00327 uint32_t tmp = 0; 00328 00329 tmp = HDMI_IO_Read(DeviceAddr, ADV7533_CHIPID_ADDR0); 00330 tmp = (tmp<<8); 00331 tmp |= HDMI_IO_Read(DeviceAddr, ADV7533_CHIPID_ADDR1); 00332 00333 return(tmp); 00334 } 00335 00336 /** 00337 * @brief Pauses playing on the audio hdmi 00338 * @param DeviceAddr: Device address on communication Bus. 00339 * @retval 0 if correct communication, else wrong communication 00340 */ 00341 uint32_t adv7533_Pause(uint16_t DeviceAddr) 00342 { 00343 return(adv7533_SetMute(DeviceAddr,AUDIO_MUTE_ON)); 00344 } 00345 00346 /** 00347 * @brief Resumes playing on the audio hdmi. 00348 * @param DeviceAddr: Device address on communication Bus. 00349 * @retval 0 if correct communication, else wrong communication 00350 */ 00351 uint32_t adv7533_Resume(uint16_t DeviceAddr) 00352 { 00353 return(adv7533_SetMute(DeviceAddr,AUDIO_MUTE_OFF)); 00354 } 00355 00356 /** 00357 * @brief Start the audio hdmi play feature. 00358 * @note For this codec no Play options are required. 00359 * @param DeviceAddr: Device address on communication Bus. 00360 * @retval 0 if correct communication, else wrong communication 00361 */ 00362 uint32_t adv7533_Play(uint16_t DeviceAddr ,uint16_t* pBuffer ,uint16_t Size) 00363 { 00364 return(adv7533_SetMute(DeviceAddr,AUDIO_MUTE_OFF)); 00365 } 00366 00367 /** 00368 * @brief Stop playing on the audio hdmi 00369 * @param DeviceAddr: Device address on communication Bus. 00370 * @retval 0 if correct communication, else wrong communication 00371 */ 00372 uint32_t adv7533_Stop(uint16_t DeviceAddr,uint32_t cmd) 00373 { 00374 return(adv7533_SetMute(DeviceAddr,AUDIO_MUTE_ON)); 00375 } 00376 00377 /** 00378 * @brief Enables or disables the mute feature on the audio hdmi. 00379 * @param DeviceAddr: Device address on communication Bus. 00380 * @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the 00381 * mute mode. 00382 * @retval 0 if correct communication, else wrong communication 00383 */ 00384 uint32_t adv7533_SetMute(uint16_t DeviceAddr, uint32_t Cmd) 00385 { 00386 uint8_t tmp = 0; 00387 00388 tmp = HDMI_IO_Read(DeviceAddr, 0x0D); 00389 if (Cmd == AUDIO_MUTE_ON) 00390 { 00391 /* enable audio mute*/ 00392 tmp |= 0x40; 00393 HDMI_IO_Write(DeviceAddr, 0x0D, tmp); 00394 } 00395 else 00396 { 00397 /*audio mute off disable the mute */ 00398 tmp &= ~0x40; 00399 HDMI_IO_Write(DeviceAddr, 0x0D, tmp); 00400 } 00401 return 0; 00402 } 00403 00404 /** 00405 * @brief Sets output mode. 00406 * @param DeviceAddr: Device address on communication Bus. 00407 * @param Output : hdmi output. 00408 * @retval 0 if correct communication, else wrong communication 00409 */ 00410 uint32_t adv7533_SetOutputMode(uint16_t DeviceAddr, uint8_t Output) 00411 { 00412 return 0; 00413 } 00414 00415 /** 00416 * @brief Sets volumee. 00417 * @param DeviceAddr: Device address on communication Bus. 00418 * @param Volume : volume value. 00419 * @retval 0 if correct communication, else wrong communication 00420 */ 00421 uint32_t adv7533_SetVolume(uint16_t DeviceAddr, uint8_t Volume) 00422 { 00423 return 0; 00424 } 00425 00426 /** 00427 * @brief Resets adv7533 registers. 00428 * @param DeviceAddr: Device address on communication Bus. 00429 * @retval 0 if correct communication, else wrong communication 00430 */ 00431 uint32_t adv7533_Reset(uint16_t DeviceAddr) 00432 { 00433 return 0; 00434 } 00435 00436 /** 00437 * @brief Sets new frequency. 00438 * @param DeviceAddr: Device address on communication Bus. 00439 * @param AudioFreq: Audio frequency used to play the audio stream. 00440 * @retval 0 if correct communication, else wrong communication 00441 */ 00442 uint32_t adv7533_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq) 00443 { 00444 uint8_t tmp = 0; 00445 00446 tmp = HDMI_IO_Read(DeviceAddr, 0x15); 00447 tmp &= (~0xF0); 00448 /* Clock Configurations */ 00449 switch (AudioFreq) 00450 { 00451 case AUDIO_FREQUENCY_32K: 00452 /* Sampling Frequency =32 KHZ*/ 00453 tmp |= 0x30; 00454 HDMI_IO_Write(DeviceAddr, 0x15, tmp); 00455 break; 00456 case AUDIO_FREQUENCY_44K: 00457 /* Sampling Frequency =44,1 KHZ*/ 00458 tmp |= 0x00; 00459 HDMI_IO_Write(DeviceAddr, 0x15, tmp); 00460 break; 00461 00462 case AUDIO_FREQUENCY_48K: 00463 /* Sampling Frequency =48KHZ*/ 00464 tmp |= 0x20; 00465 HDMI_IO_Write(DeviceAddr, 0x15, tmp); 00466 break; 00467 00468 case AUDIO_FREQUENCY_96K: 00469 /* Sampling Frequency =96 KHZ*/ 00470 tmp |= 0xA0; 00471 HDMI_IO_Write(DeviceAddr, 0x15, tmp); 00472 break; 00473 00474 case AUDIO_FREQUENCY_88K: 00475 /* Sampling Frequency =88,2 KHZ*/ 00476 tmp |= 0x80; 00477 HDMI_IO_Write(DeviceAddr, 0x15, tmp); 00478 break; 00479 00480 case AUDIO_FREQUENCY_176K: 00481 /* Sampling Frequency =176,4 KHZ*/ 00482 tmp |= 0xC0; 00483 HDMI_IO_Write(DeviceAddr, 0x15, tmp); 00484 break; 00485 00486 case AUDIO_FREQUENCY_192K: 00487 /* Sampling Frequency =192KHZ*/ 00488 tmp |= 0xE0; 00489 HDMI_IO_Write(DeviceAddr, 0x15, tmp); 00490 break; 00491 } 00492 return 0; 00493 } 00494 00495 /** 00496 * @} 00497 */ 00498 00499 /** 00500 * @} 00501 */ 00502 00503 /** 00504 * @} 00505 */ 00506 00507 /** 00508 * @} 00509 */ 00510 00511 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:55:03 by 1.7.2