STM32F479xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_dsi.c 00004 * @author MCD Application Team 00005 * @brief DSI HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the DSI peripheral: 00008 * + Initialization and de-initialization functions 00009 * + IO operation functions 00010 * + Peripheral Control functions 00011 * + Peripheral State and Errors functions 00012 @verbatim 00013 ============================================================================== 00014 ##### How to use this driver ##### 00015 ============================================================================== 00016 [..] 00017 The DSI HAL driver can be used as follows: 00018 00019 (#) Declare a DSI_HandleTypeDef handle structure, for example: DSI_HandleTypeDef hdsi; 00020 00021 (#) Initialize the DSI low level resources by implementing the HAL_DSI_MspInit() API: 00022 (##) Enable the DSI interface clock 00023 (##) NVIC configuration if you need to use interrupt process 00024 (+++) Configure the DSI interrupt priority 00025 (+++) Enable the NVIC DSI IRQ Channel 00026 00027 (#) Initialize the DSI Host peripheral, the required PLL parameters, number of lances and 00028 TX Escape clock divider by calling the HAL_DSI_Init() API which calls HAL_DSI_MspInit(). 00029 00030 *** Configuration *** 00031 ========================= 00032 [..] 00033 (#) Use HAL_DSI_ConfigAdaptedCommandMode() function to configure the DSI host in adapted 00034 command mode. 00035 00036 (#) When operating in video mode , use HAL_DSI_ConfigVideoMode() to configure the DSI host. 00037 00038 (#) Function HAL_DSI_ConfigCommand() is used to configure the DSI commands behavior in low power mode. 00039 00040 (#) To configure the DSI PHY timings parameters, use function HAL_DSI_ConfigPhyTimer(). 00041 00042 (#) The DSI Host can be started/stopped using respectively functions HAL_DSI_Start() and HAL_DSI_Stop(). 00043 Functions HAL_DSI_ShortWrite(), HAL_DSI_LongWrite() and HAL_DSI_Read() allows respectively 00044 to write DSI short packets, long packets and to read DSI packets. 00045 00046 (#) The DSI Host Offers two Low power modes : 00047 (++) Low Power Mode on data lanes only: Only DSI data lanes are shut down. 00048 It is possible to enter/exit from this mode using respectively functions HAL_DSI_EnterULPMData() 00049 and HAL_DSI_ExitULPMData() 00050 00051 (++) Low Power Mode on data and clock lanes : All DSI lanes are shut down including data and clock lanes. 00052 It is possible to enter/exit from this mode using respectively functions HAL_DSI_EnterULPM() 00053 and HAL_DSI_ExitULPM() 00054 00055 (#) To control DSI state you can use the following function: HAL_DSI_GetState() 00056 00057 *** Error management *** 00058 ======================== 00059 [..] 00060 (#) User can select the DSI errors to be reported/monitored using function HAL_DSI_ConfigErrorMonitor() 00061 When an error occurs, the callback HAL_DSI_ErrorCallback() is asserted and then user can retrieve 00062 the error code by calling function HAL_DSI_GetError() 00063 00064 *** DSI HAL driver macros list *** 00065 ============================================= 00066 [..] 00067 Below the list of most used macros in DSI HAL driver. 00068 00069 (+) __HAL_DSI_ENABLE: Enable the DSI Host. 00070 (+) __HAL_DSI_DISABLE: Disable the DSI Host. 00071 (+) __HAL_DSI_WRAPPER_ENABLE: Enables the DSI wrapper. 00072 (+) __HAL_DSI_WRAPPER_DISABLE: Disable the DSI wrapper. 00073 (+) __HAL_DSI_PLL_ENABLE: Enables the DSI PLL. 00074 (+) __HAL_DSI_PLL_DISABLE: Disables the DSI PLL. 00075 (+) __HAL_DSI_REG_ENABLE: Enables the DSI regulator. 00076 (+) __HAL_DSI_REG_DISABLE: Disables the DSI regulator. 00077 (+) __HAL_DSI_GET_FLAG: Get the DSI pending flags. 00078 (+) __HAL_DSI_CLEAR_FLAG: Clears the DSI pending flags. 00079 (+) __HAL_DSI_ENABLE_IT: Enables the specified DSI interrupts. 00080 (+) __HAL_DSI_DISABLE_IT: Disables the specified DSI interrupts. 00081 (+) __HAL_DSI_GET_IT_SOURCE: Checks whether the specified DSI interrupt source is enabled or not. 00082 00083 [..] 00084 (@) You can refer to the DSI HAL driver header file for more useful macros 00085 00086 *** Callback registration *** 00087 ============================================= 00088 [..] 00089 The compilation define USE_HAL_DSI_REGISTER_CALLBACKS when set to 1 00090 allows the user to configure dynamically the driver callbacks. 00091 Use Function HAL_DSI_RegisterCallback() to register a callback. 00092 00093 [..] 00094 Function HAL_DSI_RegisterCallback() allows to register following callbacks: 00095 (+) TearingEffectCallback : DSI Tearing Effect Callback. 00096 (+) EndOfRefreshCallback : DSI End Of Refresh Callback. 00097 (+) ErrorCallback : DSI Error Callback 00098 (+) MspInitCallback : DSI MspInit. 00099 (+) MspDeInitCallback : DSI MspDeInit. 00100 [..] 00101 This function takes as parameters the HAL peripheral handle, the callback ID 00102 and a pointer to the user callback function. 00103 00104 [..] 00105 Use function HAL_DSI_UnRegisterCallback() to reset a callback to the default 00106 weak function. 00107 HAL_DSI_UnRegisterCallback takes as parameters the HAL peripheral handle, 00108 and the callback ID. 00109 [..] 00110 This function allows to reset following callbacks: 00111 (+) TearingEffectCallback : DSI Tearing Effect Callback. 00112 (+) EndOfRefreshCallback : DSI End Of Refresh Callback. 00113 (+) ErrorCallback : DSI Error Callback 00114 (+) MspInitCallback : DSI MspInit. 00115 (+) MspDeInitCallback : DSI MspDeInit. 00116 00117 [..] 00118 By default, after the HAL_DSI_Init and when the state is HAL_DSI_STATE_RESET 00119 all callbacks are set to the corresponding weak functions: 00120 examples HAL_DSI_TearingEffectCallback(), HAL_DSI_EndOfRefreshCallback(). 00121 Exception done for MspInit and MspDeInit functions that are respectively 00122 reset to the legacy weak (surcharged) functions in the HAL_DSI_Init() 00123 and HAL_DSI_DeInit() only when these callbacks are null (not registered beforehand). 00124 If not, MspInit or MspDeInit are not null, the HAL_DSI_Init() and HAL_DSI_DeInit() 00125 keep and use the user MspInit/MspDeInit callbacks (registered beforehand). 00126 00127 [..] 00128 Callbacks can be registered/unregistered in HAL_DSI_STATE_READY state only. 00129 Exception done MspInit/MspDeInit that can be registered/unregistered 00130 in HAL_DSI_STATE_READY or HAL_DSI_STATE_RESET state, 00131 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. 00132 In that case first register the MspInit/MspDeInit user callbacks 00133 using HAL_DSI_RegisterCallback() before calling HAL_DSI_DeInit() 00134 or HAL_DSI_Init() function. 00135 00136 [..] 00137 When The compilation define USE_HAL_DSI_REGISTER_CALLBACKS is set to 0 or 00138 not defined, the callback registration feature is not available and all callbacks 00139 are set to the corresponding weak functions. 00140 00141 @endverbatim 00142 ****************************************************************************** 00143 * @attention 00144 * 00145 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00146 * All rights reserved.</center></h2> 00147 * 00148 * This software component is licensed by ST under BSD 3-Clause license, 00149 * the "License"; You may not use this file except in compliance with the 00150 * License. You may obtain a copy of the License at: 00151 * opensource.org/licenses/BSD-3-Clause 00152 * 00153 ****************************************************************************** 00154 */ 00155 00156 /* Includes ------------------------------------------------------------------*/ 00157 #include "stm32f4xx_hal.h" 00158 00159 /** @addtogroup STM32F4xx_HAL_Driver 00160 * @{ 00161 */ 00162 00163 #ifdef HAL_DSI_MODULE_ENABLED 00164 00165 #if defined(DSI) 00166 00167 /** @addtogroup DSI 00168 * @{ 00169 */ 00170 00171 /* Private types -------------------------------------------------------------*/ 00172 /* Private defines -----------------------------------------------------------*/ 00173 /** @addtogroup DSI_Private_Constants 00174 * @{ 00175 */ 00176 #define DSI_TIMEOUT_VALUE ((uint32_t)1000U) /* 1s */ 00177 00178 #define DSI_ERROR_ACK_MASK (DSI_ISR0_AE0 | DSI_ISR0_AE1 | DSI_ISR0_AE2 | DSI_ISR0_AE3 | \ 00179 DSI_ISR0_AE4 | DSI_ISR0_AE5 | DSI_ISR0_AE6 | DSI_ISR0_AE7 | \ 00180 DSI_ISR0_AE8 | DSI_ISR0_AE9 | DSI_ISR0_AE10 | DSI_ISR0_AE11 | \ 00181 DSI_ISR0_AE12 | DSI_ISR0_AE13 | DSI_ISR0_AE14 | DSI_ISR0_AE15) 00182 #define DSI_ERROR_PHY_MASK (DSI_ISR0_PE0 | DSI_ISR0_PE1 | DSI_ISR0_PE2 | DSI_ISR0_PE3 | DSI_ISR0_PE4) 00183 #define DSI_ERROR_TX_MASK DSI_ISR1_TOHSTX 00184 #define DSI_ERROR_RX_MASK DSI_ISR1_TOLPRX 00185 #define DSI_ERROR_ECC_MASK (DSI_ISR1_ECCSE | DSI_ISR1_ECCME) 00186 #define DSI_ERROR_CRC_MASK DSI_ISR1_CRCE 00187 #define DSI_ERROR_PSE_MASK DSI_ISR1_PSE 00188 #define DSI_ERROR_EOT_MASK DSI_ISR1_EOTPE 00189 #define DSI_ERROR_OVF_MASK DSI_ISR1_LPWRE 00190 #define DSI_ERROR_GEN_MASK (DSI_ISR1_GCWRE | DSI_ISR1_GPWRE | DSI_ISR1_GPTXE | DSI_ISR1_GPRDE | DSI_ISR1_GPRXE) 00191 /** 00192 * @} 00193 */ 00194 00195 /* Private variables ---------------------------------------------------------*/ 00196 /* Private constants ---------------------------------------------------------*/ 00197 /* Private macros ------------------------------------------------------------*/ 00198 /* Private function prototypes -----------------------------------------------*/ 00199 static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx, uint32_t ChannelID, uint32_t DataType, uint32_t Data0, 00200 uint32_t Data1); 00201 00202 static HAL_StatusTypeDef DSI_ShortWrite(DSI_HandleTypeDef *hdsi, 00203 uint32_t ChannelID, 00204 uint32_t Mode, 00205 uint32_t Param1, 00206 uint32_t Param2); 00207 00208 /* Private functions ---------------------------------------------------------*/ 00209 /** 00210 * @brief Generic DSI packet header configuration 00211 * @param DSIx Pointer to DSI register base 00212 * @param ChannelID Virtual channel ID of the header packet 00213 * @param DataType Packet data type of the header packet 00214 * This parameter can be any value of : 00215 * @arg DSI_SHORT_WRITE_PKT_Data_Type 00216 * @arg DSI_LONG_WRITE_PKT_Data_Type 00217 * @arg DSI_SHORT_READ_PKT_Data_Type 00218 * @arg DSI_MAX_RETURN_PKT_SIZE 00219 * @param Data0 Word count LSB 00220 * @param Data1 Word count MSB 00221 * @retval None 00222 */ 00223 static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx, 00224 uint32_t ChannelID, 00225 uint32_t DataType, 00226 uint32_t Data0, 00227 uint32_t Data1) 00228 { 00229 /* Update the DSI packet header with new information */ 00230 DSIx->GHCR = (DataType | (ChannelID << 6U) | (Data0 << 8U) | (Data1 << 16U)); 00231 } 00232 00233 /** 00234 * @brief write short DCS or short Generic command 00235 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00236 * the configuration information for the DSI. 00237 * @param ChannelID Virtual channel ID. 00238 * @param Mode DSI short packet data type. 00239 * This parameter can be any value of @arg DSI_SHORT_WRITE_PKT_Data_Type. 00240 * @param Param1 DSC command or first generic parameter. 00241 * This parameter can be any value of @arg DSI_DCS_Command or a 00242 * generic command code. 00243 * @param Param2 DSC parameter or second generic parameter. 00244 * @retval HAL status 00245 */ 00246 static HAL_StatusTypeDef DSI_ShortWrite(DSI_HandleTypeDef *hdsi, 00247 uint32_t ChannelID, 00248 uint32_t Mode, 00249 uint32_t Param1, 00250 uint32_t Param2) 00251 { 00252 uint32_t tickstart; 00253 00254 /* Get tick */ 00255 tickstart = HAL_GetTick(); 00256 00257 /* Wait for Command FIFO Empty */ 00258 while((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == 0U) 00259 { 00260 /* Check for the Timeout */ 00261 if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE) 00262 { 00263 return HAL_TIMEOUT; 00264 } 00265 } 00266 00267 /* Configure the packet to send a short DCS command with 0 or 1 parameter */ 00268 /* Update the DSI packet header with new information */ 00269 hdsi->Instance->GHCR = (Mode | (ChannelID << 6U) | (Param1 << 8U) | (Param2 << 16U)); 00270 00271 return HAL_OK; 00272 } 00273 00274 /* Exported functions --------------------------------------------------------*/ 00275 /** @addtogroup DSI_Exported_Functions 00276 * @{ 00277 */ 00278 00279 /** @defgroup DSI_Group1 Initialization and Configuration functions 00280 * @brief Initialization and Configuration functions 00281 * 00282 @verbatim 00283 =============================================================================== 00284 ##### Initialization and Configuration functions ##### 00285 =============================================================================== 00286 [..] This section provides functions allowing to: 00287 (+) Initialize and configure the DSI 00288 (+) De-initialize the DSI 00289 00290 @endverbatim 00291 * @{ 00292 */ 00293 00294 /** 00295 * @brief Initializes the DSI according to the specified 00296 * parameters in the DSI_InitTypeDef and create the associated handle. 00297 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00298 * the configuration information for the DSI. 00299 * @param PLLInit pointer to a DSI_PLLInitTypeDef structure that contains 00300 * the PLL Clock structure definition for the DSI. 00301 * @retval HAL status 00302 */ 00303 HAL_StatusTypeDef HAL_DSI_Init(DSI_HandleTypeDef *hdsi, DSI_PLLInitTypeDef *PLLInit) 00304 { 00305 uint32_t tickstart; 00306 uint32_t unitIntervalx4; 00307 uint32_t tempIDF; 00308 00309 /* Check the DSI handle allocation */ 00310 if (hdsi == NULL) 00311 { 00312 return HAL_ERROR; 00313 } 00314 00315 /* Check function parameters */ 00316 assert_param(IS_DSI_PLL_NDIV(PLLInit->PLLNDIV)); 00317 assert_param(IS_DSI_PLL_IDF(PLLInit->PLLIDF)); 00318 assert_param(IS_DSI_PLL_ODF(PLLInit->PLLODF)); 00319 assert_param(IS_DSI_AUTO_CLKLANE_CONTROL(hdsi->Init.AutomaticClockLaneControl)); 00320 assert_param(IS_DSI_NUMBER_OF_LANES(hdsi->Init.NumberOfLanes)); 00321 00322 #if (USE_HAL_DSI_REGISTER_CALLBACKS == 1) 00323 if (hdsi->State == HAL_DSI_STATE_RESET) 00324 { 00325 /* Reset the DSI callback to the legacy weak callbacks */ 00326 hdsi->TearingEffectCallback = HAL_DSI_TearingEffectCallback; /* Legacy weak TearingEffectCallback */ 00327 hdsi->EndOfRefreshCallback = HAL_DSI_EndOfRefreshCallback; /* Legacy weak EndOfRefreshCallback */ 00328 hdsi->ErrorCallback = HAL_DSI_ErrorCallback; /* Legacy weak ErrorCallback */ 00329 00330 if (hdsi->MspInitCallback == NULL) 00331 { 00332 hdsi->MspInitCallback = HAL_DSI_MspInit; 00333 } 00334 /* Initialize the low level hardware */ 00335 hdsi->MspInitCallback(hdsi); 00336 } 00337 #else 00338 if (hdsi->State == HAL_DSI_STATE_RESET) 00339 { 00340 /* Initialize the low level hardware */ 00341 HAL_DSI_MspInit(hdsi); 00342 } 00343 #endif /* USE_HAL_DSI_REGISTER_CALLBACKS */ 00344 00345 /* Change DSI peripheral state */ 00346 hdsi->State = HAL_DSI_STATE_BUSY; 00347 00348 /**************** Turn on the regulator and enable the DSI PLL ****************/ 00349 00350 /* Enable the regulator */ 00351 __HAL_DSI_REG_ENABLE(hdsi); 00352 00353 /* Get tick */ 00354 tickstart = HAL_GetTick(); 00355 00356 /* Wait until the regulator is ready */ 00357 while (__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_RRS) == 0U) 00358 { 00359 /* Check for the Timeout */ 00360 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 00361 { 00362 return HAL_TIMEOUT; 00363 } 00364 } 00365 00366 /* Set the PLL division factors */ 00367 hdsi->Instance->WRPCR &= ~(DSI_WRPCR_PLL_NDIV | DSI_WRPCR_PLL_IDF | DSI_WRPCR_PLL_ODF); 00368 hdsi->Instance->WRPCR |= (((PLLInit->PLLNDIV) << 2U) | ((PLLInit->PLLIDF) << 11U) | ((PLLInit->PLLODF) << 16U)); 00369 00370 /* Enable the DSI PLL */ 00371 __HAL_DSI_PLL_ENABLE(hdsi); 00372 00373 /* Get tick */ 00374 tickstart = HAL_GetTick(); 00375 00376 /* Wait for the lock of the PLL */ 00377 while (__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_PLLLS) == 0U) 00378 { 00379 /* Check for the Timeout */ 00380 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 00381 { 00382 return HAL_TIMEOUT; 00383 } 00384 } 00385 00386 /*************************** Set the PHY parameters ***************************/ 00387 00388 /* D-PHY clock and digital enable*/ 00389 hdsi->Instance->PCTLR |= (DSI_PCTLR_CKE | DSI_PCTLR_DEN); 00390 00391 /* Clock lane configuration */ 00392 hdsi->Instance->CLCR &= ~(DSI_CLCR_DPCC | DSI_CLCR_ACR); 00393 hdsi->Instance->CLCR |= (DSI_CLCR_DPCC | hdsi->Init.AutomaticClockLaneControl); 00394 00395 /* Configure the number of active data lanes */ 00396 hdsi->Instance->PCONFR &= ~DSI_PCONFR_NL; 00397 hdsi->Instance->PCONFR |= hdsi->Init.NumberOfLanes; 00398 00399 /************************ Set the DSI clock parameters ************************/ 00400 00401 /* Set the TX escape clock division factor */ 00402 hdsi->Instance->CCR &= ~DSI_CCR_TXECKDIV; 00403 hdsi->Instance->CCR |= hdsi->Init.TXEscapeCkdiv; 00404 00405 /* Calculate the bit period in high-speed mode in unit of 0.25 ns (UIX4) */ 00406 /* The equation is : UIX4 = IntegerPart( (1000/F_PHY_Mhz) * 4 ) */ 00407 /* Where : F_PHY_Mhz = (NDIV * HSE_Mhz) / (IDF * ODF) */ 00408 tempIDF = (PLLInit->PLLIDF > 0U) ? PLLInit->PLLIDF : 1U; 00409 unitIntervalx4 = (4000000U * tempIDF * ((1UL << (0x3U & PLLInit->PLLODF)))) / ((HSE_VALUE / 1000U) * PLLInit->PLLNDIV); 00410 00411 /* Set the bit period in high-speed mode */ 00412 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_UIX4; 00413 hdsi->Instance->WPCR[0U] |= unitIntervalx4; 00414 00415 /****************************** Error management *****************************/ 00416 00417 /* Disable all error interrupts and reset the Error Mask */ 00418 hdsi->Instance->IER[0U] = 0U; 00419 hdsi->Instance->IER[1U] = 0U; 00420 hdsi->ErrorMsk = 0U; 00421 00422 /* Initialise the error code */ 00423 hdsi->ErrorCode = HAL_DSI_ERROR_NONE; 00424 00425 /* Initialize the DSI state*/ 00426 hdsi->State = HAL_DSI_STATE_READY; 00427 00428 return HAL_OK; 00429 } 00430 00431 /** 00432 * @brief De-initializes the DSI peripheral registers to their default reset 00433 * values. 00434 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00435 * the configuration information for the DSI. 00436 * @retval HAL status 00437 */ 00438 HAL_StatusTypeDef HAL_DSI_DeInit(DSI_HandleTypeDef *hdsi) 00439 { 00440 /* Check the DSI handle allocation */ 00441 if (hdsi == NULL) 00442 { 00443 return HAL_ERROR; 00444 } 00445 00446 /* Change DSI peripheral state */ 00447 hdsi->State = HAL_DSI_STATE_BUSY; 00448 00449 /* Disable the DSI wrapper */ 00450 __HAL_DSI_WRAPPER_DISABLE(hdsi); 00451 00452 /* Disable the DSI host */ 00453 __HAL_DSI_DISABLE(hdsi); 00454 00455 /* D-PHY clock and digital disable */ 00456 hdsi->Instance->PCTLR &= ~(DSI_PCTLR_CKE | DSI_PCTLR_DEN); 00457 00458 /* Turn off the DSI PLL */ 00459 __HAL_DSI_PLL_DISABLE(hdsi); 00460 00461 /* Disable the regulator */ 00462 __HAL_DSI_REG_DISABLE(hdsi); 00463 00464 #if (USE_HAL_DSI_REGISTER_CALLBACKS == 1) 00465 if (hdsi->MspDeInitCallback == NULL) 00466 { 00467 hdsi->MspDeInitCallback = HAL_DSI_MspDeInit; 00468 } 00469 /* DeInit the low level hardware */ 00470 hdsi->MspDeInitCallback(hdsi); 00471 #else 00472 /* DeInit the low level hardware */ 00473 HAL_DSI_MspDeInit(hdsi); 00474 #endif /* USE_HAL_DSI_REGISTER_CALLBACKS */ 00475 00476 /* Initialise the error code */ 00477 hdsi->ErrorCode = HAL_DSI_ERROR_NONE; 00478 00479 /* Initialize the DSI state*/ 00480 hdsi->State = HAL_DSI_STATE_RESET; 00481 00482 /* Release Lock */ 00483 __HAL_UNLOCK(hdsi); 00484 00485 return HAL_OK; 00486 } 00487 00488 /** 00489 * @brief Enable the error monitor flags 00490 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00491 * the configuration information for the DSI. 00492 * @param ActiveErrors indicates which error interrupts will be enabled. 00493 * This parameter can be any combination of @arg DSI_Error_Data_Type. 00494 * @retval HAL status 00495 */ 00496 HAL_StatusTypeDef HAL_DSI_ConfigErrorMonitor(DSI_HandleTypeDef *hdsi, uint32_t ActiveErrors) 00497 { 00498 /* Process locked */ 00499 __HAL_LOCK(hdsi); 00500 00501 hdsi->Instance->IER[0U] = 0U; 00502 hdsi->Instance->IER[1U] = 0U; 00503 00504 /* Store active errors to the handle */ 00505 hdsi->ErrorMsk = ActiveErrors; 00506 00507 if ((ActiveErrors & HAL_DSI_ERROR_ACK) != 0U) 00508 { 00509 /* Enable the interrupt generation on selected errors */ 00510 hdsi->Instance->IER[0U] |= DSI_ERROR_ACK_MASK; 00511 } 00512 00513 if ((ActiveErrors & HAL_DSI_ERROR_PHY) != 0U) 00514 { 00515 /* Enable the interrupt generation on selected errors */ 00516 hdsi->Instance->IER[0U] |= DSI_ERROR_PHY_MASK; 00517 } 00518 00519 if ((ActiveErrors & HAL_DSI_ERROR_TX) != 0U) 00520 { 00521 /* Enable the interrupt generation on selected errors */ 00522 hdsi->Instance->IER[1U] |= DSI_ERROR_TX_MASK; 00523 } 00524 00525 if ((ActiveErrors & HAL_DSI_ERROR_RX) != 0U) 00526 { 00527 /* Enable the interrupt generation on selected errors */ 00528 hdsi->Instance->IER[1U] |= DSI_ERROR_RX_MASK; 00529 } 00530 00531 if ((ActiveErrors & HAL_DSI_ERROR_ECC) != 0U) 00532 { 00533 /* Enable the interrupt generation on selected errors */ 00534 hdsi->Instance->IER[1U] |= DSI_ERROR_ECC_MASK; 00535 } 00536 00537 if ((ActiveErrors & HAL_DSI_ERROR_CRC) != 0U) 00538 { 00539 /* Enable the interrupt generation on selected errors */ 00540 hdsi->Instance->IER[1U] |= DSI_ERROR_CRC_MASK; 00541 } 00542 00543 if ((ActiveErrors & HAL_DSI_ERROR_PSE) != 0U) 00544 { 00545 /* Enable the interrupt generation on selected errors */ 00546 hdsi->Instance->IER[1U] |= DSI_ERROR_PSE_MASK; 00547 } 00548 00549 if ((ActiveErrors & HAL_DSI_ERROR_EOT) != 0U) 00550 { 00551 /* Enable the interrupt generation on selected errors */ 00552 hdsi->Instance->IER[1U] |= DSI_ERROR_EOT_MASK; 00553 } 00554 00555 if ((ActiveErrors & HAL_DSI_ERROR_OVF) != 0U) 00556 { 00557 /* Enable the interrupt generation on selected errors */ 00558 hdsi->Instance->IER[1U] |= DSI_ERROR_OVF_MASK; 00559 } 00560 00561 if ((ActiveErrors & HAL_DSI_ERROR_GEN) != 0U) 00562 { 00563 /* Enable the interrupt generation on selected errors */ 00564 hdsi->Instance->IER[1U] |= DSI_ERROR_GEN_MASK; 00565 } 00566 00567 /* Process Unlocked */ 00568 __HAL_UNLOCK(hdsi); 00569 00570 return HAL_OK; 00571 } 00572 00573 /** 00574 * @brief Initializes the DSI MSP. 00575 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00576 * the configuration information for the DSI. 00577 * @retval None 00578 */ 00579 __weak void HAL_DSI_MspInit(DSI_HandleTypeDef *hdsi) 00580 { 00581 /* Prevent unused argument(s) compilation warning */ 00582 UNUSED(hdsi); 00583 /* NOTE : This function Should not be modified, when the callback is needed, 00584 the HAL_DSI_MspInit could be implemented in the user file 00585 */ 00586 } 00587 00588 /** 00589 * @brief De-initializes the DSI MSP. 00590 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00591 * the configuration information for the DSI. 00592 * @retval None 00593 */ 00594 __weak void HAL_DSI_MspDeInit(DSI_HandleTypeDef *hdsi) 00595 { 00596 /* Prevent unused argument(s) compilation warning */ 00597 UNUSED(hdsi); 00598 /* NOTE : This function Should not be modified, when the callback is needed, 00599 the HAL_DSI_MspDeInit could be implemented in the user file 00600 */ 00601 } 00602 00603 #if (USE_HAL_DSI_REGISTER_CALLBACKS == 1) 00604 /** 00605 * @brief Register a User DSI Callback 00606 * To be used instead of the weak predefined callback 00607 * @param hdsi dsi handle 00608 * @param CallbackID ID of the callback to be registered 00609 * This parameter can be one of the following values: 00610 * @arg HAL_DSI_TEARING_EFFECT_CB_ID Tearing Effect Callback ID 00611 * @arg HAL_DSI_ENDOF_REFRESH_CB_ID End Of Refresh Callback ID 00612 * @arg HAL_DSI_ERROR_CB_ID Error Callback ID 00613 * @arg HAL_DSI_MSPINIT_CB_ID MspInit callback ID 00614 * @arg HAL_DSI_MSPDEINIT_CB_ID MspDeInit callback ID 00615 * @param pCallback pointer to the Callback function 00616 * @retval status 00617 */ 00618 HAL_StatusTypeDef HAL_DSI_RegisterCallback(DSI_HandleTypeDef *hdsi, HAL_DSI_CallbackIDTypeDef CallbackID, 00619 pDSI_CallbackTypeDef pCallback) 00620 { 00621 HAL_StatusTypeDef status = HAL_OK; 00622 00623 if (pCallback == NULL) 00624 { 00625 /* Update the error code */ 00626 hdsi->ErrorCode |= HAL_DSI_ERROR_INVALID_CALLBACK; 00627 00628 return HAL_ERROR; 00629 } 00630 /* Process locked */ 00631 __HAL_LOCK(hdsi); 00632 00633 if (hdsi->State == HAL_DSI_STATE_READY) 00634 { 00635 switch (CallbackID) 00636 { 00637 case HAL_DSI_TEARING_EFFECT_CB_ID : 00638 hdsi->TearingEffectCallback = pCallback; 00639 break; 00640 00641 case HAL_DSI_ENDOF_REFRESH_CB_ID : 00642 hdsi->EndOfRefreshCallback = pCallback; 00643 break; 00644 00645 case HAL_DSI_ERROR_CB_ID : 00646 hdsi->ErrorCallback = pCallback; 00647 break; 00648 00649 case HAL_DSI_MSPINIT_CB_ID : 00650 hdsi->MspInitCallback = pCallback; 00651 break; 00652 00653 case HAL_DSI_MSPDEINIT_CB_ID : 00654 hdsi->MspDeInitCallback = pCallback; 00655 break; 00656 00657 default : 00658 /* Update the error code */ 00659 hdsi->ErrorCode |= HAL_DSI_ERROR_INVALID_CALLBACK; 00660 /* Return error status */ 00661 status = HAL_ERROR; 00662 break; 00663 } 00664 } 00665 else if (hdsi->State == HAL_DSI_STATE_RESET) 00666 { 00667 switch (CallbackID) 00668 { 00669 case HAL_DSI_MSPINIT_CB_ID : 00670 hdsi->MspInitCallback = pCallback; 00671 break; 00672 00673 case HAL_DSI_MSPDEINIT_CB_ID : 00674 hdsi->MspDeInitCallback = pCallback; 00675 break; 00676 00677 default : 00678 /* Update the error code */ 00679 hdsi->ErrorCode |= HAL_DSI_ERROR_INVALID_CALLBACK; 00680 /* Return error status */ 00681 status = HAL_ERROR; 00682 break; 00683 } 00684 } 00685 else 00686 { 00687 /* Update the error code */ 00688 hdsi->ErrorCode |= HAL_DSI_ERROR_INVALID_CALLBACK; 00689 /* Return error status */ 00690 status = HAL_ERROR; 00691 } 00692 00693 /* Release Lock */ 00694 __HAL_UNLOCK(hdsi); 00695 00696 return status; 00697 } 00698 00699 /** 00700 * @brief Unregister a DSI Callback 00701 * DSI callabck is redirected to the weak predefined callback 00702 * @param hdsi dsi handle 00703 * @param CallbackID ID of the callback to be unregistered 00704 * This parameter can be one of the following values: 00705 * @arg HAL_DSI_TEARING_EFFECT_CB_ID Tearing Effect Callback ID 00706 * @arg HAL_DSI_ENDOF_REFRESH_CB_ID End Of Refresh Callback ID 00707 * @arg HAL_DSI_ERROR_CB_ID Error Callback ID 00708 * @arg HAL_DSI_MSPINIT_CB_ID MspInit callback ID 00709 * @arg HAL_DSI_MSPDEINIT_CB_ID MspDeInit callback ID 00710 * @retval status 00711 */ 00712 HAL_StatusTypeDef HAL_DSI_UnRegisterCallback(DSI_HandleTypeDef *hdsi, HAL_DSI_CallbackIDTypeDef CallbackID) 00713 { 00714 HAL_StatusTypeDef status = HAL_OK; 00715 00716 /* Process locked */ 00717 __HAL_LOCK(hdsi); 00718 00719 if (hdsi->State == HAL_DSI_STATE_READY) 00720 { 00721 switch (CallbackID) 00722 { 00723 case HAL_DSI_TEARING_EFFECT_CB_ID : 00724 hdsi->TearingEffectCallback = HAL_DSI_TearingEffectCallback; /* Legacy weak TearingEffectCallback */ 00725 break; 00726 00727 case HAL_DSI_ENDOF_REFRESH_CB_ID : 00728 hdsi->EndOfRefreshCallback = HAL_DSI_EndOfRefreshCallback; /* Legacy weak EndOfRefreshCallback */ 00729 break; 00730 00731 case HAL_DSI_ERROR_CB_ID : 00732 hdsi->ErrorCallback = HAL_DSI_ErrorCallback; /* Legacy weak ErrorCallback */ 00733 break; 00734 00735 case HAL_DSI_MSPINIT_CB_ID : 00736 hdsi->MspInitCallback = HAL_DSI_MspInit; /* Legcay weak MspInit Callback */ 00737 break; 00738 00739 case HAL_DSI_MSPDEINIT_CB_ID : 00740 hdsi->MspDeInitCallback = HAL_DSI_MspDeInit; /* Legcay weak MspDeInit Callback */ 00741 break; 00742 00743 default : 00744 /* Update the error code */ 00745 hdsi->ErrorCode |= HAL_DSI_ERROR_INVALID_CALLBACK; 00746 /* Return error status */ 00747 status = HAL_ERROR; 00748 break; 00749 } 00750 } 00751 else if (hdsi->State == HAL_DSI_STATE_RESET) 00752 { 00753 switch (CallbackID) 00754 { 00755 case HAL_DSI_MSPINIT_CB_ID : 00756 hdsi->MspInitCallback = HAL_DSI_MspInit; /* Legcay weak MspInit Callback */ 00757 break; 00758 00759 case HAL_DSI_MSPDEINIT_CB_ID : 00760 hdsi->MspDeInitCallback = HAL_DSI_MspDeInit; /* Legcay weak MspDeInit Callback */ 00761 break; 00762 00763 default : 00764 /* Update the error code */ 00765 hdsi->ErrorCode |= HAL_DSI_ERROR_INVALID_CALLBACK; 00766 /* Return error status */ 00767 status = HAL_ERROR; 00768 break; 00769 } 00770 } 00771 else 00772 { 00773 /* Update the error code */ 00774 hdsi->ErrorCode |= HAL_DSI_ERROR_INVALID_CALLBACK; 00775 /* Return error status */ 00776 status = HAL_ERROR; 00777 } 00778 00779 /* Release Lock */ 00780 __HAL_UNLOCK(hdsi); 00781 00782 return status; 00783 } 00784 #endif /* USE_HAL_DSI_REGISTER_CALLBACKS */ 00785 00786 /** 00787 * @} 00788 */ 00789 00790 /** @defgroup DSI_Group2 IO operation functions 00791 * @brief IO operation functions 00792 * 00793 @verbatim 00794 =============================================================================== 00795 ##### IO operation functions ##### 00796 =============================================================================== 00797 [..] This section provides function allowing to: 00798 (+) Handle DSI interrupt request 00799 00800 @endverbatim 00801 * @{ 00802 */ 00803 /** 00804 * @brief Handles DSI interrupt request. 00805 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00806 * the configuration information for the DSI. 00807 * @retval HAL status 00808 */ 00809 void HAL_DSI_IRQHandler(DSI_HandleTypeDef *hdsi) 00810 { 00811 uint32_t ErrorStatus0, ErrorStatus1; 00812 00813 /* Tearing Effect Interrupt management ***************************************/ 00814 if (__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_TE) != 0U) 00815 { 00816 if (__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_TE) != 0U) 00817 { 00818 /* Clear the Tearing Effect Interrupt Flag */ 00819 __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_TE); 00820 00821 /* Tearing Effect Callback */ 00822 #if (USE_HAL_DSI_REGISTER_CALLBACKS == 1) 00823 /*Call registered Tearing Effect callback */ 00824 hdsi->TearingEffectCallback(hdsi); 00825 #else 00826 /*Call legacy Tearing Effect callback*/ 00827 HAL_DSI_TearingEffectCallback(hdsi); 00828 #endif /* USE_HAL_DSI_REGISTER_CALLBACKS */ 00829 } 00830 } 00831 00832 /* End of Refresh Interrupt management ***************************************/ 00833 if (__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_ER) != 0U) 00834 { 00835 if (__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_ER) != 0U) 00836 { 00837 /* Clear the End of Refresh Interrupt Flag */ 00838 __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_ER); 00839 00840 /* End of Refresh Callback */ 00841 #if (USE_HAL_DSI_REGISTER_CALLBACKS == 1) 00842 /*Call registered End of refresh callback */ 00843 hdsi->EndOfRefreshCallback(hdsi); 00844 #else 00845 /*Call Legacy End of refresh callback */ 00846 HAL_DSI_EndOfRefreshCallback(hdsi); 00847 #endif /* USE_HAL_DSI_REGISTER_CALLBACKS */ 00848 } 00849 } 00850 00851 /* Error Interrupts management ***********************************************/ 00852 if (hdsi->ErrorMsk != 0U) 00853 { 00854 ErrorStatus0 = hdsi->Instance->ISR[0U]; 00855 ErrorStatus0 &= hdsi->Instance->IER[0U]; 00856 ErrorStatus1 = hdsi->Instance->ISR[1U]; 00857 ErrorStatus1 &= hdsi->Instance->IER[1U]; 00858 00859 if ((ErrorStatus0 & DSI_ERROR_ACK_MASK) != 0U) 00860 { 00861 hdsi->ErrorCode |= HAL_DSI_ERROR_ACK; 00862 } 00863 00864 if ((ErrorStatus0 & DSI_ERROR_PHY_MASK) != 0U) 00865 { 00866 hdsi->ErrorCode |= HAL_DSI_ERROR_PHY; 00867 } 00868 00869 if ((ErrorStatus1 & DSI_ERROR_TX_MASK) != 0U) 00870 { 00871 hdsi->ErrorCode |= HAL_DSI_ERROR_TX; 00872 } 00873 00874 if ((ErrorStatus1 & DSI_ERROR_RX_MASK) != 0U) 00875 { 00876 hdsi->ErrorCode |= HAL_DSI_ERROR_RX; 00877 } 00878 00879 if ((ErrorStatus1 & DSI_ERROR_ECC_MASK) != 0U) 00880 { 00881 hdsi->ErrorCode |= HAL_DSI_ERROR_ECC; 00882 } 00883 00884 if ((ErrorStatus1 & DSI_ERROR_CRC_MASK) != 0U) 00885 { 00886 hdsi->ErrorCode |= HAL_DSI_ERROR_CRC; 00887 } 00888 00889 if ((ErrorStatus1 & DSI_ERROR_PSE_MASK) != 0U) 00890 { 00891 hdsi->ErrorCode |= HAL_DSI_ERROR_PSE; 00892 } 00893 00894 if ((ErrorStatus1 & DSI_ERROR_EOT_MASK) != 0U) 00895 { 00896 hdsi->ErrorCode |= HAL_DSI_ERROR_EOT; 00897 } 00898 00899 if ((ErrorStatus1 & DSI_ERROR_OVF_MASK) != 0U) 00900 { 00901 hdsi->ErrorCode |= HAL_DSI_ERROR_OVF; 00902 } 00903 00904 if ((ErrorStatus1 & DSI_ERROR_GEN_MASK) != 0U) 00905 { 00906 hdsi->ErrorCode |= HAL_DSI_ERROR_GEN; 00907 } 00908 00909 /* Check only selected errors */ 00910 if (hdsi->ErrorCode != HAL_DSI_ERROR_NONE) 00911 { 00912 /* DSI error interrupt callback */ 00913 #if (USE_HAL_DSI_REGISTER_CALLBACKS == 1) 00914 /*Call registered Error callback */ 00915 hdsi->ErrorCallback(hdsi); 00916 #else 00917 /*Call Legacy Error callback */ 00918 HAL_DSI_ErrorCallback(hdsi); 00919 #endif /* USE_HAL_DSI_REGISTER_CALLBACKS */ 00920 } 00921 } 00922 } 00923 00924 /** 00925 * @brief Tearing Effect DSI callback. 00926 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00927 * the configuration information for the DSI. 00928 * @retval None 00929 */ 00930 __weak void HAL_DSI_TearingEffectCallback(DSI_HandleTypeDef *hdsi) 00931 { 00932 /* Prevent unused argument(s) compilation warning */ 00933 UNUSED(hdsi); 00934 /* NOTE : This function Should not be modified, when the callback is needed, 00935 the HAL_DSI_TearingEffectCallback could be implemented in the user file 00936 */ 00937 } 00938 00939 /** 00940 * @brief End of Refresh DSI callback. 00941 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00942 * the configuration information for the DSI. 00943 * @retval None 00944 */ 00945 __weak void HAL_DSI_EndOfRefreshCallback(DSI_HandleTypeDef *hdsi) 00946 { 00947 /* Prevent unused argument(s) compilation warning */ 00948 UNUSED(hdsi); 00949 /* NOTE : This function Should not be modified, when the callback is needed, 00950 the HAL_DSI_EndOfRefreshCallback could be implemented in the user file 00951 */ 00952 } 00953 00954 /** 00955 * @brief Operation Error DSI callback. 00956 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 00957 * the configuration information for the DSI. 00958 * @retval None 00959 */ 00960 __weak void HAL_DSI_ErrorCallback(DSI_HandleTypeDef *hdsi) 00961 { 00962 /* Prevent unused argument(s) compilation warning */ 00963 UNUSED(hdsi); 00964 /* NOTE : This function Should not be modified, when the callback is needed, 00965 the HAL_DSI_ErrorCallback could be implemented in the user file 00966 */ 00967 } 00968 00969 /** 00970 * @} 00971 */ 00972 00973 /** @defgroup DSI_Group3 Peripheral Control functions 00974 * @brief Peripheral Control functions 00975 * 00976 @verbatim 00977 =============================================================================== 00978 ##### Peripheral Control functions ##### 00979 =============================================================================== 00980 [..] This section provides functions allowing to: 00981 (+) Configure the Generic interface read-back Virtual Channel ID 00982 (+) Select video mode and configure the corresponding parameters 00983 (+) Configure command transmission mode: High-speed or Low-power 00984 (+) Configure the flow control 00985 (+) Configure the DSI PHY timer 00986 (+) Configure the DSI HOST timeout 00987 (+) Configure the DSI HOST timeout 00988 (+) Start/Stop the DSI module 00989 (+) Refresh the display in command mode 00990 (+) Controls the display color mode in Video mode 00991 (+) Control the display shutdown in Video mode 00992 (+) write short DCS or short Generic command 00993 (+) write long DCS or long Generic command 00994 (+) Read command (DCS or generic) 00995 (+) Enter/Exit the Ultra Low Power Mode on data only (D-PHY PLL running) 00996 (+) Enter/Exit the Ultra Low Power Mode on data only and clock (D-PHY PLL turned off) 00997 (+) Start/Stop test pattern generation 00998 (+) Slew-Rate And Delay Tuning 00999 (+) Low-Power Reception Filter Tuning 01000 (+) Activate an additional current path on all lanes to meet the SDDTx parameter 01001 (+) Custom lane pins configuration 01002 (+) Set custom timing for the PHY 01003 (+) Force the Clock/Data Lane in TX Stop Mode 01004 (+) Force LP Receiver in Low-Power Mode 01005 (+) Force Data Lanes in RX Mode after a BTA 01006 (+) Enable a pull-down on the lanes to prevent from floating states when unused 01007 (+) Switch off the contention detection on data lanes 01008 01009 @endverbatim 01010 * @{ 01011 */ 01012 01013 /** 01014 * @brief Configure the Generic interface read-back Virtual Channel ID. 01015 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01016 * the configuration information for the DSI. 01017 * @param VirtualChannelID Virtual channel ID 01018 * @retval HAL status 01019 */ 01020 HAL_StatusTypeDef HAL_DSI_SetGenericVCID(DSI_HandleTypeDef *hdsi, uint32_t VirtualChannelID) 01021 { 01022 /* Process locked */ 01023 __HAL_LOCK(hdsi); 01024 01025 /* Update the GVCID register */ 01026 hdsi->Instance->GVCIDR &= ~DSI_GVCIDR_VCID; 01027 hdsi->Instance->GVCIDR |= VirtualChannelID; 01028 01029 /* Process unlocked */ 01030 __HAL_UNLOCK(hdsi); 01031 01032 return HAL_OK; 01033 } 01034 01035 /** 01036 * @brief Select video mode and configure the corresponding parameters 01037 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01038 * the configuration information for the DSI. 01039 * @param VidCfg pointer to a DSI_VidCfgTypeDef structure that contains 01040 * the DSI video mode configuration parameters 01041 * @retval HAL status 01042 */ 01043 HAL_StatusTypeDef HAL_DSI_ConfigVideoMode(DSI_HandleTypeDef *hdsi, DSI_VidCfgTypeDef *VidCfg) 01044 { 01045 /* Process locked */ 01046 __HAL_LOCK(hdsi); 01047 01048 /* Check the parameters */ 01049 assert_param(IS_DSI_COLOR_CODING(VidCfg->ColorCoding)); 01050 assert_param(IS_DSI_VIDEO_MODE_TYPE(VidCfg->Mode)); 01051 assert_param(IS_DSI_LP_COMMAND(VidCfg->LPCommandEnable)); 01052 assert_param(IS_DSI_LP_HFP(VidCfg->LPHorizontalFrontPorchEnable)); 01053 assert_param(IS_DSI_LP_HBP(VidCfg->LPHorizontalBackPorchEnable)); 01054 assert_param(IS_DSI_LP_VACTIVE(VidCfg->LPVerticalActiveEnable)); 01055 assert_param(IS_DSI_LP_VFP(VidCfg->LPVerticalFrontPorchEnable)); 01056 assert_param(IS_DSI_LP_VBP(VidCfg->LPVerticalBackPorchEnable)); 01057 assert_param(IS_DSI_LP_VSYNC(VidCfg->LPVerticalSyncActiveEnable)); 01058 assert_param(IS_DSI_FBTAA(VidCfg->FrameBTAAcknowledgeEnable)); 01059 assert_param(IS_DSI_DE_POLARITY(VidCfg->DEPolarity)); 01060 assert_param(IS_DSI_VSYNC_POLARITY(VidCfg->VSPolarity)); 01061 assert_param(IS_DSI_HSYNC_POLARITY(VidCfg->HSPolarity)); 01062 /* Check the LooselyPacked variant only in 18-bit mode */ 01063 if (VidCfg->ColorCoding == DSI_RGB666) 01064 { 01065 assert_param(IS_DSI_LOOSELY_PACKED(VidCfg->LooselyPacked)); 01066 } 01067 01068 /* Select video mode by resetting CMDM and DSIM bits */ 01069 hdsi->Instance->MCR &= ~DSI_MCR_CMDM; 01070 hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM; 01071 01072 /* Configure the video mode transmission type */ 01073 hdsi->Instance->VMCR &= ~DSI_VMCR_VMT; 01074 hdsi->Instance->VMCR |= VidCfg->Mode; 01075 01076 /* Configure the video packet size */ 01077 hdsi->Instance->VPCR &= ~DSI_VPCR_VPSIZE; 01078 hdsi->Instance->VPCR |= VidCfg->PacketSize; 01079 01080 /* Set the chunks number to be transmitted through the DSI link */ 01081 hdsi->Instance->VCCR &= ~DSI_VCCR_NUMC; 01082 hdsi->Instance->VCCR |= VidCfg->NumberOfChunks; 01083 01084 /* Set the size of the null packet */ 01085 hdsi->Instance->VNPCR &= ~DSI_VNPCR_NPSIZE; 01086 hdsi->Instance->VNPCR |= VidCfg->NullPacketSize; 01087 01088 /* Select the virtual channel for the LTDC interface traffic */ 01089 hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID; 01090 hdsi->Instance->LVCIDR |= VidCfg->VirtualChannelID; 01091 01092 /* Configure the polarity of control signals */ 01093 hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP); 01094 hdsi->Instance->LPCR |= (VidCfg->DEPolarity | VidCfg->VSPolarity | VidCfg->HSPolarity); 01095 01096 /* Select the color coding for the host */ 01097 hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC; 01098 hdsi->Instance->LCOLCR |= VidCfg->ColorCoding; 01099 01100 /* Select the color coding for the wrapper */ 01101 hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX; 01102 hdsi->Instance->WCFGR |= ((VidCfg->ColorCoding) << 1U); 01103 01104 /* Enable/disable the loosely packed variant to 18-bit configuration */ 01105 if (VidCfg->ColorCoding == DSI_RGB666) 01106 { 01107 hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_LPE; 01108 hdsi->Instance->LCOLCR |= VidCfg->LooselyPacked; 01109 } 01110 01111 /* Set the Horizontal Synchronization Active (HSA) in lane byte clock cycles */ 01112 hdsi->Instance->VHSACR &= ~DSI_VHSACR_HSA; 01113 hdsi->Instance->VHSACR |= VidCfg->HorizontalSyncActive; 01114 01115 /* Set the Horizontal Back Porch (HBP) in lane byte clock cycles */ 01116 hdsi->Instance->VHBPCR &= ~DSI_VHBPCR_HBP; 01117 hdsi->Instance->VHBPCR |= VidCfg->HorizontalBackPorch; 01118 01119 /* Set the total line time (HLINE=HSA+HBP+HACT+HFP) in lane byte clock cycles */ 01120 hdsi->Instance->VLCR &= ~DSI_VLCR_HLINE; 01121 hdsi->Instance->VLCR |= VidCfg->HorizontalLine; 01122 01123 /* Set the Vertical Synchronization Active (VSA) */ 01124 hdsi->Instance->VVSACR &= ~DSI_VVSACR_VSA; 01125 hdsi->Instance->VVSACR |= VidCfg->VerticalSyncActive; 01126 01127 /* Set the Vertical Back Porch (VBP)*/ 01128 hdsi->Instance->VVBPCR &= ~DSI_VVBPCR_VBP; 01129 hdsi->Instance->VVBPCR |= VidCfg->VerticalBackPorch; 01130 01131 /* Set the Vertical Front Porch (VFP)*/ 01132 hdsi->Instance->VVFPCR &= ~DSI_VVFPCR_VFP; 01133 hdsi->Instance->VVFPCR |= VidCfg->VerticalFrontPorch; 01134 01135 /* Set the Vertical Active period*/ 01136 hdsi->Instance->VVACR &= ~DSI_VVACR_VA; 01137 hdsi->Instance->VVACR |= VidCfg->VerticalActive; 01138 01139 /* Configure the command transmission mode */ 01140 hdsi->Instance->VMCR &= ~DSI_VMCR_LPCE; 01141 hdsi->Instance->VMCR |= VidCfg->LPCommandEnable; 01142 01143 /* Low power largest packet size */ 01144 hdsi->Instance->LPMCR &= ~DSI_LPMCR_LPSIZE; 01145 hdsi->Instance->LPMCR |= ((VidCfg->LPLargestPacketSize) << 16U); 01146 01147 /* Low power VACT largest packet size */ 01148 hdsi->Instance->LPMCR &= ~DSI_LPMCR_VLPSIZE; 01149 hdsi->Instance->LPMCR |= VidCfg->LPVACTLargestPacketSize; 01150 01151 /* Enable LP transition in HFP period */ 01152 hdsi->Instance->VMCR &= ~DSI_VMCR_LPHFPE; 01153 hdsi->Instance->VMCR |= VidCfg->LPHorizontalFrontPorchEnable; 01154 01155 /* Enable LP transition in HBP period */ 01156 hdsi->Instance->VMCR &= ~DSI_VMCR_LPHBPE; 01157 hdsi->Instance->VMCR |= VidCfg->LPHorizontalBackPorchEnable; 01158 01159 /* Enable LP transition in VACT period */ 01160 hdsi->Instance->VMCR &= ~DSI_VMCR_LPVAE; 01161 hdsi->Instance->VMCR |= VidCfg->LPVerticalActiveEnable; 01162 01163 /* Enable LP transition in VFP period */ 01164 hdsi->Instance->VMCR &= ~DSI_VMCR_LPVFPE; 01165 hdsi->Instance->VMCR |= VidCfg->LPVerticalFrontPorchEnable; 01166 01167 /* Enable LP transition in VBP period */ 01168 hdsi->Instance->VMCR &= ~DSI_VMCR_LPVBPE; 01169 hdsi->Instance->VMCR |= VidCfg->LPVerticalBackPorchEnable; 01170 01171 /* Enable LP transition in vertical sync period */ 01172 hdsi->Instance->VMCR &= ~DSI_VMCR_LPVSAE; 01173 hdsi->Instance->VMCR |= VidCfg->LPVerticalSyncActiveEnable; 01174 01175 /* Enable the request for an acknowledge response at the end of a frame */ 01176 hdsi->Instance->VMCR &= ~DSI_VMCR_FBTAAE; 01177 hdsi->Instance->VMCR |= VidCfg->FrameBTAAcknowledgeEnable; 01178 01179 /* Process unlocked */ 01180 __HAL_UNLOCK(hdsi); 01181 01182 return HAL_OK; 01183 } 01184 01185 /** 01186 * @brief Select adapted command mode and configure the corresponding parameters 01187 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01188 * the configuration information for the DSI. 01189 * @param CmdCfg pointer to a DSI_CmdCfgTypeDef structure that contains 01190 * the DSI command mode configuration parameters 01191 * @retval HAL status 01192 */ 01193 HAL_StatusTypeDef HAL_DSI_ConfigAdaptedCommandMode(DSI_HandleTypeDef *hdsi, DSI_CmdCfgTypeDef *CmdCfg) 01194 { 01195 /* Process locked */ 01196 __HAL_LOCK(hdsi); 01197 01198 /* Check the parameters */ 01199 assert_param(IS_DSI_COLOR_CODING(CmdCfg->ColorCoding)); 01200 assert_param(IS_DSI_TE_SOURCE(CmdCfg->TearingEffectSource)); 01201 assert_param(IS_DSI_TE_POLARITY(CmdCfg->TearingEffectPolarity)); 01202 assert_param(IS_DSI_AUTOMATIC_REFRESH(CmdCfg->AutomaticRefresh)); 01203 assert_param(IS_DSI_VS_POLARITY(CmdCfg->VSyncPol)); 01204 assert_param(IS_DSI_TE_ACK_REQUEST(CmdCfg->TEAcknowledgeRequest)); 01205 assert_param(IS_DSI_DE_POLARITY(CmdCfg->DEPolarity)); 01206 assert_param(IS_DSI_VSYNC_POLARITY(CmdCfg->VSPolarity)); 01207 assert_param(IS_DSI_HSYNC_POLARITY(CmdCfg->HSPolarity)); 01208 01209 /* Select command mode by setting CMDM and DSIM bits */ 01210 hdsi->Instance->MCR |= DSI_MCR_CMDM; 01211 hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM; 01212 hdsi->Instance->WCFGR |= DSI_WCFGR_DSIM; 01213 01214 /* Select the virtual channel for the LTDC interface traffic */ 01215 hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID; 01216 hdsi->Instance->LVCIDR |= CmdCfg->VirtualChannelID; 01217 01218 /* Configure the polarity of control signals */ 01219 hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP); 01220 hdsi->Instance->LPCR |= (CmdCfg->DEPolarity | CmdCfg->VSPolarity | CmdCfg->HSPolarity); 01221 01222 /* Select the color coding for the host */ 01223 hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC; 01224 hdsi->Instance->LCOLCR |= CmdCfg->ColorCoding; 01225 01226 /* Select the color coding for the wrapper */ 01227 hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX; 01228 hdsi->Instance->WCFGR |= ((CmdCfg->ColorCoding) << 1U); 01229 01230 /* Configure the maximum allowed size for write memory command */ 01231 hdsi->Instance->LCCR &= ~DSI_LCCR_CMDSIZE; 01232 hdsi->Instance->LCCR |= CmdCfg->CommandSize; 01233 01234 /* Configure the tearing effect source and polarity and select the refresh mode */ 01235 hdsi->Instance->WCFGR &= ~(DSI_WCFGR_TESRC | DSI_WCFGR_TEPOL | DSI_WCFGR_AR | DSI_WCFGR_VSPOL); 01236 hdsi->Instance->WCFGR |= (CmdCfg->TearingEffectSource | CmdCfg->TearingEffectPolarity | CmdCfg->AutomaticRefresh | 01237 CmdCfg->VSyncPol); 01238 01239 /* Configure the tearing effect acknowledge request */ 01240 hdsi->Instance->CMCR &= ~DSI_CMCR_TEARE; 01241 hdsi->Instance->CMCR |= CmdCfg->TEAcknowledgeRequest; 01242 01243 /* Enable the Tearing Effect interrupt */ 01244 __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_TE); 01245 01246 /* Enable the End of Refresh interrupt */ 01247 __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_ER); 01248 01249 /* Process unlocked */ 01250 __HAL_UNLOCK(hdsi); 01251 01252 return HAL_OK; 01253 } 01254 01255 /** 01256 * @brief Configure command transmission mode: High-speed or Low-power 01257 * and enable/disable acknowledge request after packet transmission 01258 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01259 * the configuration information for the DSI. 01260 * @param LPCmd pointer to a DSI_LPCmdTypeDef structure that contains 01261 * the DSI command transmission mode configuration parameters 01262 * @retval HAL status 01263 */ 01264 HAL_StatusTypeDef HAL_DSI_ConfigCommand(DSI_HandleTypeDef *hdsi, DSI_LPCmdTypeDef *LPCmd) 01265 { 01266 /* Process locked */ 01267 __HAL_LOCK(hdsi); 01268 01269 assert_param(IS_DSI_LP_GSW0P(LPCmd->LPGenShortWriteNoP)); 01270 assert_param(IS_DSI_LP_GSW1P(LPCmd->LPGenShortWriteOneP)); 01271 assert_param(IS_DSI_LP_GSW2P(LPCmd->LPGenShortWriteTwoP)); 01272 assert_param(IS_DSI_LP_GSR0P(LPCmd->LPGenShortReadNoP)); 01273 assert_param(IS_DSI_LP_GSR1P(LPCmd->LPGenShortReadOneP)); 01274 assert_param(IS_DSI_LP_GSR2P(LPCmd->LPGenShortReadTwoP)); 01275 assert_param(IS_DSI_LP_GLW(LPCmd->LPGenLongWrite)); 01276 assert_param(IS_DSI_LP_DSW0P(LPCmd->LPDcsShortWriteNoP)); 01277 assert_param(IS_DSI_LP_DSW1P(LPCmd->LPDcsShortWriteOneP)); 01278 assert_param(IS_DSI_LP_DSR0P(LPCmd->LPDcsShortReadNoP)); 01279 assert_param(IS_DSI_LP_DLW(LPCmd->LPDcsLongWrite)); 01280 assert_param(IS_DSI_LP_MRDP(LPCmd->LPMaxReadPacket)); 01281 assert_param(IS_DSI_ACK_REQUEST(LPCmd->AcknowledgeRequest)); 01282 01283 /* Select High-speed or Low-power for command transmission */ 01284 hdsi->Instance->CMCR &= ~(DSI_CMCR_GSW0TX | \ 01285 DSI_CMCR_GSW1TX | \ 01286 DSI_CMCR_GSW2TX | \ 01287 DSI_CMCR_GSR0TX | \ 01288 DSI_CMCR_GSR1TX | \ 01289 DSI_CMCR_GSR2TX | \ 01290 DSI_CMCR_GLWTX | \ 01291 DSI_CMCR_DSW0TX | \ 01292 DSI_CMCR_DSW1TX | \ 01293 DSI_CMCR_DSR0TX | \ 01294 DSI_CMCR_DLWTX | \ 01295 DSI_CMCR_MRDPS); 01296 hdsi->Instance->CMCR |= (LPCmd->LPGenShortWriteNoP | \ 01297 LPCmd->LPGenShortWriteOneP | \ 01298 LPCmd->LPGenShortWriteTwoP | \ 01299 LPCmd->LPGenShortReadNoP | \ 01300 LPCmd->LPGenShortReadOneP | \ 01301 LPCmd->LPGenShortReadTwoP | \ 01302 LPCmd->LPGenLongWrite | \ 01303 LPCmd->LPDcsShortWriteNoP | \ 01304 LPCmd->LPDcsShortWriteOneP | \ 01305 LPCmd->LPDcsShortReadNoP | \ 01306 LPCmd->LPDcsLongWrite | \ 01307 LPCmd->LPMaxReadPacket); 01308 01309 /* Configure the acknowledge request after each packet transmission */ 01310 hdsi->Instance->CMCR &= ~DSI_CMCR_ARE; 01311 hdsi->Instance->CMCR |= LPCmd->AcknowledgeRequest; 01312 01313 /* Process unlocked */ 01314 __HAL_UNLOCK(hdsi); 01315 01316 return HAL_OK; 01317 } 01318 01319 /** 01320 * @brief Configure the flow control parameters 01321 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01322 * the configuration information for the DSI. 01323 * @param FlowControl flow control feature(s) to be enabled. 01324 * This parameter can be any combination of @arg DSI_FlowControl. 01325 * @retval HAL status 01326 */ 01327 HAL_StatusTypeDef HAL_DSI_ConfigFlowControl(DSI_HandleTypeDef *hdsi, uint32_t FlowControl) 01328 { 01329 /* Process locked */ 01330 __HAL_LOCK(hdsi); 01331 01332 /* Check the parameters */ 01333 assert_param(IS_DSI_FLOW_CONTROL(FlowControl)); 01334 01335 /* Set the DSI Host Protocol Configuration Register */ 01336 hdsi->Instance->PCR &= ~DSI_FLOW_CONTROL_ALL; 01337 hdsi->Instance->PCR |= FlowControl; 01338 01339 /* Process unlocked */ 01340 __HAL_UNLOCK(hdsi); 01341 01342 return HAL_OK; 01343 } 01344 01345 /** 01346 * @brief Configure the DSI PHY timer parameters 01347 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01348 * the configuration information for the DSI. 01349 * @param PhyTimers DSI_PHY_TimerTypeDef structure that contains 01350 * the DSI PHY timing parameters 01351 * @retval HAL status 01352 */ 01353 HAL_StatusTypeDef HAL_DSI_ConfigPhyTimer(DSI_HandleTypeDef *hdsi, DSI_PHY_TimerTypeDef *PhyTimers) 01354 { 01355 uint32_t maxTime; 01356 /* Process locked */ 01357 __HAL_LOCK(hdsi); 01358 01359 maxTime = (PhyTimers->ClockLaneLP2HSTime > PhyTimers->ClockLaneHS2LPTime) ? PhyTimers->ClockLaneLP2HSTime : 01360 PhyTimers->ClockLaneHS2LPTime; 01361 01362 /* Clock lane timer configuration */ 01363 01364 /* In Automatic Clock Lane control mode, the DSI Host can turn off the clock lane between two 01365 High-Speed transmission. 01366 To do so, the DSI Host calculates the time required for the clock lane to change from HighSpeed 01367 to Low-Power and from Low-Power to High-Speed. 01368 This timings are configured by the HS2LP_TIME and LP2HS_TIME in the DSI Host Clock Lane Timer Configuration Register (DSI_CLTCR). 01369 But the DSI Host is not calculating LP2HS_TIME + HS2LP_TIME but 2 x HS2LP_TIME. 01370 01371 Workaround : Configure HS2LP_TIME and LP2HS_TIME with the same value being the max of HS2LP_TIME or LP2HS_TIME. 01372 */ 01373 hdsi->Instance->CLTCR &= ~(DSI_CLTCR_LP2HS_TIME | DSI_CLTCR_HS2LP_TIME); 01374 hdsi->Instance->CLTCR |= (maxTime | ((maxTime) << 16U)); 01375 01376 /* Data lane timer configuration */ 01377 hdsi->Instance->DLTCR &= ~(DSI_DLTCR_MRD_TIME | DSI_DLTCR_LP2HS_TIME | DSI_DLTCR_HS2LP_TIME); 01378 hdsi->Instance->DLTCR |= (PhyTimers->DataLaneMaxReadTime | ((PhyTimers->DataLaneLP2HSTime) << 16U) | (( 01379 PhyTimers->DataLaneHS2LPTime) << 24U)); 01380 01381 /* Configure the wait period to request HS transmission after a stop state */ 01382 hdsi->Instance->PCONFR &= ~DSI_PCONFR_SW_TIME; 01383 hdsi->Instance->PCONFR |= ((PhyTimers->StopWaitTime) << 8U); 01384 01385 /* Process unlocked */ 01386 __HAL_UNLOCK(hdsi); 01387 01388 return HAL_OK; 01389 } 01390 01391 /** 01392 * @brief Configure the DSI HOST timeout parameters 01393 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01394 * the configuration information for the DSI. 01395 * @param HostTimeouts DSI_HOST_TimeoutTypeDef structure that contains 01396 * the DSI host timeout parameters 01397 * @retval HAL status 01398 */ 01399 HAL_StatusTypeDef HAL_DSI_ConfigHostTimeouts(DSI_HandleTypeDef *hdsi, DSI_HOST_TimeoutTypeDef *HostTimeouts) 01400 { 01401 /* Process locked */ 01402 __HAL_LOCK(hdsi); 01403 01404 /* Set the timeout clock division factor */ 01405 hdsi->Instance->CCR &= ~DSI_CCR_TOCKDIV; 01406 hdsi->Instance->CCR |= ((HostTimeouts->TimeoutCkdiv) << 8U); 01407 01408 /* High-speed transmission timeout */ 01409 hdsi->Instance->TCCR[0U] &= ~DSI_TCCR0_HSTX_TOCNT; 01410 hdsi->Instance->TCCR[0U] |= ((HostTimeouts->HighSpeedTransmissionTimeout) << 16U); 01411 01412 /* Low-power reception timeout */ 01413 hdsi->Instance->TCCR[0U] &= ~DSI_TCCR0_LPRX_TOCNT; 01414 hdsi->Instance->TCCR[0U] |= HostTimeouts->LowPowerReceptionTimeout; 01415 01416 /* High-speed read timeout */ 01417 hdsi->Instance->TCCR[1U] &= ~DSI_TCCR1_HSRD_TOCNT; 01418 hdsi->Instance->TCCR[1U] |= HostTimeouts->HighSpeedReadTimeout; 01419 01420 /* Low-power read timeout */ 01421 hdsi->Instance->TCCR[2U] &= ~DSI_TCCR2_LPRD_TOCNT; 01422 hdsi->Instance->TCCR[2U] |= HostTimeouts->LowPowerReadTimeout; 01423 01424 /* High-speed write timeout */ 01425 hdsi->Instance->TCCR[3U] &= ~DSI_TCCR3_HSWR_TOCNT; 01426 hdsi->Instance->TCCR[3U] |= HostTimeouts->HighSpeedWriteTimeout; 01427 01428 /* High-speed write presp mode */ 01429 hdsi->Instance->TCCR[3U] &= ~DSI_TCCR3_PM; 01430 hdsi->Instance->TCCR[3U] |= HostTimeouts->HighSpeedWritePrespMode; 01431 01432 /* Low-speed write timeout */ 01433 hdsi->Instance->TCCR[4U] &= ~DSI_TCCR4_LPWR_TOCNT; 01434 hdsi->Instance->TCCR[4U] |= HostTimeouts->LowPowerWriteTimeout; 01435 01436 /* BTA timeout */ 01437 hdsi->Instance->TCCR[5U] &= ~DSI_TCCR5_BTA_TOCNT; 01438 hdsi->Instance->TCCR[5U] |= HostTimeouts->BTATimeout; 01439 01440 /* Process unlocked */ 01441 __HAL_UNLOCK(hdsi); 01442 01443 return HAL_OK; 01444 } 01445 01446 /** 01447 * @brief Start the DSI module 01448 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01449 * the configuration information for the DSI. 01450 * @retval HAL status 01451 */ 01452 HAL_StatusTypeDef HAL_DSI_Start(DSI_HandleTypeDef *hdsi) 01453 { 01454 /* Process locked */ 01455 __HAL_LOCK(hdsi); 01456 01457 /* Enable the DSI host */ 01458 __HAL_DSI_ENABLE(hdsi); 01459 01460 /* Enable the DSI wrapper */ 01461 __HAL_DSI_WRAPPER_ENABLE(hdsi); 01462 01463 /* Process unlocked */ 01464 __HAL_UNLOCK(hdsi); 01465 01466 return HAL_OK; 01467 } 01468 01469 /** 01470 * @brief Stop the DSI module 01471 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01472 * the configuration information for the DSI. 01473 * @retval HAL status 01474 */ 01475 HAL_StatusTypeDef HAL_DSI_Stop(DSI_HandleTypeDef *hdsi) 01476 { 01477 /* Process locked */ 01478 __HAL_LOCK(hdsi); 01479 01480 /* Disable the DSI host */ 01481 __HAL_DSI_DISABLE(hdsi); 01482 01483 /* Disable the DSI wrapper */ 01484 __HAL_DSI_WRAPPER_DISABLE(hdsi); 01485 01486 /* Process unlocked */ 01487 __HAL_UNLOCK(hdsi); 01488 01489 return HAL_OK; 01490 } 01491 01492 /** 01493 * @brief Refresh the display in command mode 01494 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01495 * the configuration information for the DSI. 01496 * @retval HAL status 01497 */ 01498 HAL_StatusTypeDef HAL_DSI_Refresh(DSI_HandleTypeDef *hdsi) 01499 { 01500 /* Process locked */ 01501 __HAL_LOCK(hdsi); 01502 01503 /* Update the display */ 01504 hdsi->Instance->WCR |= DSI_WCR_LTDCEN; 01505 01506 /* Process unlocked */ 01507 __HAL_UNLOCK(hdsi); 01508 01509 return HAL_OK; 01510 } 01511 01512 /** 01513 * @brief Controls the display color mode in Video mode 01514 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01515 * the configuration information for the DSI. 01516 * @param ColorMode Color mode (full or 8-colors). 01517 * This parameter can be any value of @arg DSI_Color_Mode 01518 * @retval HAL status 01519 */ 01520 HAL_StatusTypeDef HAL_DSI_ColorMode(DSI_HandleTypeDef *hdsi, uint32_t ColorMode) 01521 { 01522 /* Process locked */ 01523 __HAL_LOCK(hdsi); 01524 01525 /* Check the parameters */ 01526 assert_param(IS_DSI_COLOR_MODE(ColorMode)); 01527 01528 /* Update the display color mode */ 01529 hdsi->Instance->WCR &= ~DSI_WCR_COLM; 01530 hdsi->Instance->WCR |= ColorMode; 01531 01532 /* Process unlocked */ 01533 __HAL_UNLOCK(hdsi); 01534 01535 return HAL_OK; 01536 } 01537 01538 /** 01539 * @brief Control the display shutdown in Video mode 01540 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01541 * the configuration information for the DSI. 01542 * @param Shutdown Shut-down (Display-ON or Display-OFF). 01543 * This parameter can be any value of @arg DSI_ShutDown 01544 * @retval HAL status 01545 */ 01546 HAL_StatusTypeDef HAL_DSI_Shutdown(DSI_HandleTypeDef *hdsi, uint32_t Shutdown) 01547 { 01548 /* Process locked */ 01549 __HAL_LOCK(hdsi); 01550 01551 /* Check the parameters */ 01552 assert_param(IS_DSI_SHUT_DOWN(Shutdown)); 01553 01554 /* Update the display Shutdown */ 01555 hdsi->Instance->WCR &= ~DSI_WCR_SHTDN; 01556 hdsi->Instance->WCR |= Shutdown; 01557 01558 /* Process unlocked */ 01559 __HAL_UNLOCK(hdsi); 01560 01561 return HAL_OK; 01562 } 01563 01564 /** 01565 * @brief write short DCS or short Generic command 01566 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01567 * the configuration information for the DSI. 01568 * @param ChannelID Virtual channel ID. 01569 * @param Mode DSI short packet data type. 01570 * This parameter can be any value of @arg DSI_SHORT_WRITE_PKT_Data_Type. 01571 * @param Param1 DSC command or first generic parameter. 01572 * This parameter can be any value of @arg DSI_DCS_Command or a 01573 * generic command code. 01574 * @param Param2 DSC parameter or second generic parameter. 01575 * @retval HAL status 01576 */ 01577 HAL_StatusTypeDef HAL_DSI_ShortWrite(DSI_HandleTypeDef *hdsi, 01578 uint32_t ChannelID, 01579 uint32_t Mode, 01580 uint32_t Param1, 01581 uint32_t Param2) 01582 { 01583 HAL_StatusTypeDef status; 01584 /* Check the parameters */ 01585 assert_param(IS_DSI_SHORT_WRITE_PACKET_TYPE(Mode)); 01586 01587 /* Process locked */ 01588 __HAL_LOCK(hdsi); 01589 01590 status = DSI_ShortWrite(hdsi, ChannelID, Mode, Param1, Param2); 01591 01592 /* Process unlocked */ 01593 __HAL_UNLOCK(hdsi); 01594 01595 return status; 01596 } 01597 01598 /** 01599 * @brief write long DCS or long Generic command 01600 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01601 * the configuration information for the DSI. 01602 * @param ChannelID Virtual channel ID. 01603 * @param Mode DSI long packet data type. 01604 * This parameter can be any value of @arg DSI_LONG_WRITE_PKT_Data_Type. 01605 * @param NbParams Number of parameters. 01606 * @param Param1 DSC command or first generic parameter. 01607 * This parameter can be any value of @arg DSI_DCS_Command or a 01608 * generic command code 01609 * @param ParametersTable Pointer to parameter values table. 01610 * @retval HAL status 01611 */ 01612 HAL_StatusTypeDef HAL_DSI_LongWrite(DSI_HandleTypeDef *hdsi, 01613 uint32_t ChannelID, 01614 uint32_t Mode, 01615 uint32_t NbParams, 01616 uint32_t Param1, 01617 uint8_t *ParametersTable) 01618 { 01619 uint32_t uicounter, nbBytes, count; 01620 uint32_t tickstart; 01621 uint32_t fifoword; 01622 uint8_t *pparams = ParametersTable; 01623 01624 /* Process locked */ 01625 __HAL_LOCK(hdsi); 01626 01627 /* Check the parameters */ 01628 assert_param(IS_DSI_LONG_WRITE_PACKET_TYPE(Mode)); 01629 01630 /* Get tick */ 01631 tickstart = HAL_GetTick(); 01632 01633 /* Wait for Command FIFO Empty */ 01634 while ((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == 0U) 01635 { 01636 /* Check for the Timeout */ 01637 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01638 { 01639 /* Process Unlocked */ 01640 __HAL_UNLOCK(hdsi); 01641 01642 return HAL_TIMEOUT; 01643 } 01644 } 01645 01646 /* Set the DCS code on payload byte 1, and the other parameters on the write FIFO command*/ 01647 fifoword = Param1; 01648 nbBytes = (NbParams < 3U) ? NbParams : 3U; 01649 01650 for (count = 0U; count < nbBytes; count++) 01651 { 01652 fifoword |= (((uint32_t)(*(pparams + count))) << (8U + (8U * count))); 01653 } 01654 hdsi->Instance->GPDR = fifoword; 01655 01656 uicounter = NbParams - nbBytes; 01657 pparams += nbBytes; 01658 /* Set the Next parameters on the write FIFO command*/ 01659 while (uicounter != 0U) 01660 { 01661 nbBytes = (uicounter < 4U) ? uicounter : 4U; 01662 fifoword = 0U; 01663 for (count = 0U; count < nbBytes; count++) 01664 { 01665 fifoword |= (((uint32_t)(*(pparams + count))) << (8U * count)); 01666 } 01667 hdsi->Instance->GPDR = fifoword; 01668 01669 uicounter -= nbBytes; 01670 pparams += nbBytes; 01671 } 01672 01673 /* Configure the packet to send a long DCS command */ 01674 DSI_ConfigPacketHeader(hdsi->Instance, 01675 ChannelID, 01676 Mode, 01677 ((NbParams + 1U) & 0x00FFU), 01678 (((NbParams + 1U) & 0xFF00U) >> 8U)); 01679 01680 /* Process unlocked */ 01681 __HAL_UNLOCK(hdsi); 01682 01683 return HAL_OK; 01684 } 01685 01686 /** 01687 * @brief Read command (DCS or generic) 01688 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01689 * the configuration information for the DSI. 01690 * @param ChannelNbr Virtual channel ID 01691 * @param Array pointer to a buffer to store the payload of a read back operation. 01692 * @param Size Data size to be read (in byte). 01693 * @param Mode DSI read packet data type. 01694 * This parameter can be any value of @arg DSI_SHORT_READ_PKT_Data_Type. 01695 * @param DCSCmd DCS get/read command. 01696 * @param ParametersTable Pointer to parameter values table. 01697 * @retval HAL status 01698 */ 01699 HAL_StatusTypeDef HAL_DSI_Read(DSI_HandleTypeDef *hdsi, 01700 uint32_t ChannelNbr, 01701 uint8_t *Array, 01702 uint32_t Size, 01703 uint32_t Mode, 01704 uint32_t DCSCmd, 01705 uint8_t *ParametersTable) 01706 { 01707 uint32_t tickstart; 01708 uint8_t *pdata = Array; 01709 uint32_t datasize = Size; 01710 uint32_t fifoword; 01711 uint32_t nbbytes; 01712 uint32_t count; 01713 01714 /* Process locked */ 01715 __HAL_LOCK(hdsi); 01716 01717 /* Check the parameters */ 01718 assert_param(IS_DSI_READ_PACKET_TYPE(Mode)); 01719 01720 if (datasize > 2U) 01721 { 01722 /* set max return packet size */ 01723 if (DSI_ShortWrite(hdsi, ChannelNbr, DSI_MAX_RETURN_PKT_SIZE, ((datasize) & 0xFFU), 01724 (((datasize) >> 8U) & 0xFFU)) != HAL_OK) 01725 { 01726 /* Process Unlocked */ 01727 __HAL_UNLOCK(hdsi); 01728 01729 return HAL_ERROR; 01730 } 01731 } 01732 01733 /* Configure the packet to read command */ 01734 if (Mode == DSI_DCS_SHORT_PKT_READ) 01735 { 01736 DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, DCSCmd, 0U); 01737 } 01738 else if (Mode == DSI_GEN_SHORT_PKT_READ_P0) 01739 { 01740 DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, 0U, 0U); 01741 } 01742 else if (Mode == DSI_GEN_SHORT_PKT_READ_P1) 01743 { 01744 DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0U], 0U); 01745 } 01746 else if (Mode == DSI_GEN_SHORT_PKT_READ_P2) 01747 { 01748 DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0U], ParametersTable[1U]); 01749 } 01750 else 01751 { 01752 /* Process Unlocked */ 01753 __HAL_UNLOCK(hdsi); 01754 01755 return HAL_ERROR; 01756 } 01757 01758 /* Get tick */ 01759 tickstart = HAL_GetTick(); 01760 01761 /* If DSI fifo is not empty, read requested bytes */ 01762 while (((int32_t)(datasize)) > 0) 01763 { 01764 if ((hdsi->Instance->GPSR & DSI_GPSR_PRDFE) == 0U) 01765 { 01766 fifoword = hdsi->Instance->GPDR; 01767 nbbytes = (datasize < 4U) ? datasize : 4U; 01768 01769 for (count = 0U; count < nbbytes; count++) 01770 { 01771 *pdata = (uint8_t)(fifoword >> (8U * count)); 01772 pdata++; 01773 datasize--; 01774 } 01775 } 01776 01777 /* Check for the Timeout */ 01778 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01779 { 01780 /* Process Unlocked */ 01781 __HAL_UNLOCK(hdsi); 01782 01783 return HAL_TIMEOUT; 01784 } 01785 } 01786 01787 /* Process unlocked */ 01788 __HAL_UNLOCK(hdsi); 01789 01790 return HAL_OK; 01791 } 01792 01793 /** 01794 * @brief Enter the ULPM (Ultra Low Power Mode) with the D-PHY PLL running 01795 * (only data lanes are in ULPM) 01796 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01797 * the configuration information for the DSI. 01798 * @retval HAL status 01799 */ 01800 HAL_StatusTypeDef HAL_DSI_EnterULPMData(DSI_HandleTypeDef *hdsi) 01801 { 01802 uint32_t tickstart; 01803 01804 /* Process locked */ 01805 __HAL_LOCK(hdsi); 01806 01807 /* ULPS Request on Data Lanes */ 01808 hdsi->Instance->PUCR |= DSI_PUCR_URDL; 01809 01810 /* Get tick */ 01811 tickstart = HAL_GetTick(); 01812 01813 /* Wait until the D-PHY active lanes enter into ULPM */ 01814 if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE) 01815 { 01816 while ((hdsi->Instance->PSR & DSI_PSR_UAN0) != 0U) 01817 { 01818 /* Check for the Timeout */ 01819 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01820 { 01821 /* Process Unlocked */ 01822 __HAL_UNLOCK(hdsi); 01823 01824 return HAL_TIMEOUT; 01825 } 01826 } 01827 } 01828 else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES) 01829 { 01830 while ((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1)) != 0U) 01831 { 01832 /* Check for the Timeout */ 01833 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01834 { 01835 /* Process Unlocked */ 01836 __HAL_UNLOCK(hdsi); 01837 01838 return HAL_TIMEOUT; 01839 } 01840 } 01841 } 01842 else 01843 { 01844 /* Process unlocked */ 01845 __HAL_UNLOCK(hdsi); 01846 01847 return HAL_ERROR; 01848 } 01849 01850 /* Process unlocked */ 01851 __HAL_UNLOCK(hdsi); 01852 01853 return HAL_OK; 01854 } 01855 01856 /** 01857 * @brief Exit the ULPM (Ultra Low Power Mode) with the D-PHY PLL running 01858 * (only data lanes are in ULPM) 01859 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01860 * the configuration information for the DSI. 01861 * @retval HAL status 01862 */ 01863 HAL_StatusTypeDef HAL_DSI_ExitULPMData(DSI_HandleTypeDef *hdsi) 01864 { 01865 uint32_t tickstart; 01866 01867 /* Process locked */ 01868 __HAL_LOCK(hdsi); 01869 01870 /* Exit ULPS on Data Lanes */ 01871 hdsi->Instance->PUCR |= DSI_PUCR_UEDL; 01872 01873 /* Get tick */ 01874 tickstart = HAL_GetTick(); 01875 01876 /* Wait until all active lanes exit ULPM */ 01877 if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE) 01878 { 01879 while ((hdsi->Instance->PSR & DSI_PSR_UAN0) != DSI_PSR_UAN0) 01880 { 01881 /* Check for the Timeout */ 01882 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01883 { 01884 /* Process Unlocked */ 01885 __HAL_UNLOCK(hdsi); 01886 01887 return HAL_TIMEOUT; 01888 } 01889 } 01890 } 01891 else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES) 01892 { 01893 while ((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1)) != (DSI_PSR_UAN0 | DSI_PSR_UAN1)) 01894 { 01895 /* Check for the Timeout */ 01896 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01897 { 01898 /* Process Unlocked */ 01899 __HAL_UNLOCK(hdsi); 01900 01901 return HAL_TIMEOUT; 01902 } 01903 } 01904 } 01905 else 01906 { 01907 /* Process unlocked */ 01908 __HAL_UNLOCK(hdsi); 01909 01910 return HAL_ERROR; 01911 } 01912 01913 /* wait for 1 ms*/ 01914 HAL_Delay(1U); 01915 01916 /* De-assert the ULPM requests and the ULPM exit bits */ 01917 hdsi->Instance->PUCR = 0U; 01918 01919 /* Process unlocked */ 01920 __HAL_UNLOCK(hdsi); 01921 01922 return HAL_OK; 01923 } 01924 01925 /** 01926 * @brief Enter the ULPM (Ultra Low Power Mode) with the D-PHY PLL turned off 01927 * (both data and clock lanes are in ULPM) 01928 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 01929 * the configuration information for the DSI. 01930 * @retval HAL status 01931 */ 01932 HAL_StatusTypeDef HAL_DSI_EnterULPM(DSI_HandleTypeDef *hdsi) 01933 { 01934 uint32_t tickstart; 01935 01936 /* Process locked */ 01937 __HAL_LOCK(hdsi); 01938 01939 /* Clock lane configuration: no more HS request */ 01940 hdsi->Instance->CLCR &= ~DSI_CLCR_DPCC; 01941 01942 /* Use system PLL as byte lane clock source before stopping DSIPHY clock source */ 01943 __HAL_RCC_DSI_CONFIG(RCC_DSICLKSOURCE_PLLR); 01944 01945 /* ULPS Request on Clock and Data Lanes */ 01946 hdsi->Instance->PUCR |= (DSI_PUCR_URCL | DSI_PUCR_URDL); 01947 01948 /* Get tick */ 01949 tickstart = HAL_GetTick(); 01950 01951 /* Wait until all active lanes exit ULPM */ 01952 if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE) 01953 { 01954 while ((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UANC)) != 0U) 01955 { 01956 /* Check for the Timeout */ 01957 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01958 { 01959 /* Process Unlocked */ 01960 __HAL_UNLOCK(hdsi); 01961 01962 return HAL_TIMEOUT; 01963 } 01964 } 01965 } 01966 else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES) 01967 { 01968 while ((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC)) != 0U) 01969 { 01970 /* Check for the Timeout */ 01971 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 01972 { 01973 /* Process Unlocked */ 01974 __HAL_UNLOCK(hdsi); 01975 01976 return HAL_TIMEOUT; 01977 } 01978 } 01979 } 01980 else 01981 { 01982 /* Process unlocked */ 01983 __HAL_UNLOCK(hdsi); 01984 01985 return HAL_ERROR; 01986 } 01987 01988 /* Turn off the DSI PLL */ 01989 __HAL_DSI_PLL_DISABLE(hdsi); 01990 01991 /* Process unlocked */ 01992 __HAL_UNLOCK(hdsi); 01993 01994 return HAL_OK; 01995 } 01996 01997 /** 01998 * @brief Exit the ULPM (Ultra Low Power Mode) with the D-PHY PLL turned off 01999 * (both data and clock lanes are in ULPM) 02000 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02001 * the configuration information for the DSI. 02002 * @retval HAL status 02003 */ 02004 HAL_StatusTypeDef HAL_DSI_ExitULPM(DSI_HandleTypeDef *hdsi) 02005 { 02006 uint32_t tickstart; 02007 02008 /* Process locked */ 02009 __HAL_LOCK(hdsi); 02010 02011 /* Turn on the DSI PLL */ 02012 __HAL_DSI_PLL_ENABLE(hdsi); 02013 02014 /* Get tick */ 02015 tickstart = HAL_GetTick(); 02016 02017 /* Wait for the lock of the PLL */ 02018 while (__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_PLLLS) == 0U) 02019 { 02020 /* Check for the Timeout */ 02021 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 02022 { 02023 /* Process Unlocked */ 02024 __HAL_UNLOCK(hdsi); 02025 02026 return HAL_TIMEOUT; 02027 } 02028 } 02029 02030 /* Exit ULPS on Clock and Data Lanes */ 02031 hdsi->Instance->PUCR |= (DSI_PUCR_UECL | DSI_PUCR_UEDL); 02032 02033 /* Get tick */ 02034 tickstart = HAL_GetTick(); 02035 02036 /* Wait until all active lanes exit ULPM */ 02037 if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE) 02038 { 02039 while ((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UANC)) != (DSI_PSR_UAN0 | DSI_PSR_UANC)) 02040 { 02041 /* Check for the Timeout */ 02042 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 02043 { 02044 /* Process Unlocked */ 02045 __HAL_UNLOCK(hdsi); 02046 02047 return HAL_TIMEOUT; 02048 } 02049 } 02050 } 02051 else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES) 02052 { 02053 while ((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC)) != (DSI_PSR_UAN0 | DSI_PSR_UAN1 | 02054 DSI_PSR_UANC)) 02055 { 02056 /* Check for the Timeout */ 02057 if ((HAL_GetTick() - tickstart) > DSI_TIMEOUT_VALUE) 02058 { 02059 /* Process Unlocked */ 02060 __HAL_UNLOCK(hdsi); 02061 02062 return HAL_TIMEOUT; 02063 } 02064 } 02065 } 02066 else 02067 { 02068 /* Process unlocked */ 02069 __HAL_UNLOCK(hdsi); 02070 02071 return HAL_ERROR; 02072 } 02073 02074 /* wait for 1 ms */ 02075 HAL_Delay(1U); 02076 02077 /* De-assert the ULPM requests and the ULPM exit bits */ 02078 hdsi->Instance->PUCR = 0U; 02079 02080 /* Switch the lanbyteclock source in the RCC from system PLL to D-PHY */ 02081 __HAL_RCC_DSI_CONFIG(RCC_DSICLKSOURCE_DSIPHY); 02082 02083 /* Restore clock lane configuration to HS */ 02084 hdsi->Instance->CLCR |= DSI_CLCR_DPCC; 02085 02086 /* Process unlocked */ 02087 __HAL_UNLOCK(hdsi); 02088 02089 return HAL_OK; 02090 } 02091 02092 /** 02093 * @brief Start test pattern generation 02094 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02095 * the configuration information for the DSI. 02096 * @param Mode Pattern generator mode 02097 * This parameter can be one of the following values: 02098 * 0 : Color bars (horizontal or vertical) 02099 * 1 : BER pattern (vertical only) 02100 * @param Orientation Pattern generator orientation 02101 * This parameter can be one of the following values: 02102 * 0 : Vertical color bars 02103 * 1 : Horizontal color bars 02104 * @retval HAL status 02105 */ 02106 HAL_StatusTypeDef HAL_DSI_PatternGeneratorStart(DSI_HandleTypeDef *hdsi, uint32_t Mode, uint32_t Orientation) 02107 { 02108 /* Process locked */ 02109 __HAL_LOCK(hdsi); 02110 02111 /* Configure pattern generator mode and orientation */ 02112 hdsi->Instance->VMCR &= ~(DSI_VMCR_PGM | DSI_VMCR_PGO); 02113 hdsi->Instance->VMCR |= ((Mode << 20U) | (Orientation << 24U)); 02114 02115 /* Enable pattern generator by setting PGE bit */ 02116 hdsi->Instance->VMCR |= DSI_VMCR_PGE; 02117 02118 /* Process unlocked */ 02119 __HAL_UNLOCK(hdsi); 02120 02121 return HAL_OK; 02122 } 02123 02124 /** 02125 * @brief Stop test pattern generation 02126 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02127 * the configuration information for the DSI. 02128 * @retval HAL status 02129 */ 02130 HAL_StatusTypeDef HAL_DSI_PatternGeneratorStop(DSI_HandleTypeDef *hdsi) 02131 { 02132 /* Process locked */ 02133 __HAL_LOCK(hdsi); 02134 02135 /* Disable pattern generator by clearing PGE bit */ 02136 hdsi->Instance->VMCR &= ~DSI_VMCR_PGE; 02137 02138 /* Process unlocked */ 02139 __HAL_UNLOCK(hdsi); 02140 02141 return HAL_OK; 02142 } 02143 02144 /** 02145 * @brief Set Slew-Rate And Delay Tuning 02146 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02147 * the configuration information for the DSI. 02148 * @param CommDelay Communication delay to be adjusted. 02149 * This parameter can be any value of @arg DSI_Communication_Delay 02150 * @param Lane select between clock or data lanes. 02151 * This parameter can be any value of @arg DSI_Lane_Group 02152 * @param Value Custom value of the slew-rate or delay 02153 * @retval HAL status 02154 */ 02155 HAL_StatusTypeDef HAL_DSI_SetSlewRateAndDelayTuning(DSI_HandleTypeDef *hdsi, uint32_t CommDelay, uint32_t Lane, 02156 uint32_t Value) 02157 { 02158 /* Process locked */ 02159 __HAL_LOCK(hdsi); 02160 02161 /* Check function parameters */ 02162 assert_param(IS_DSI_COMMUNICATION_DELAY(CommDelay)); 02163 assert_param(IS_DSI_LANE_GROUP(Lane)); 02164 02165 switch (CommDelay) 02166 { 02167 case DSI_SLEW_RATE_HSTX: 02168 if (Lane == DSI_CLOCK_LANE) 02169 { 02170 /* High-Speed Transmission Slew Rate Control on Clock Lane */ 02171 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXSRCCL; 02172 hdsi->Instance->WPCR[1U] |= Value << 16U; 02173 } 02174 else if (Lane == DSI_DATA_LANES) 02175 { 02176 /* High-Speed Transmission Slew Rate Control on Data Lanes */ 02177 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXSRCDL; 02178 hdsi->Instance->WPCR[1U] |= Value << 18U; 02179 } 02180 else 02181 { 02182 /* Process unlocked */ 02183 __HAL_UNLOCK(hdsi); 02184 02185 return HAL_ERROR; 02186 } 02187 break; 02188 case DSI_SLEW_RATE_LPTX: 02189 if (Lane == DSI_CLOCK_LANE) 02190 { 02191 /* Low-Power transmission Slew Rate Compensation on Clock Lane */ 02192 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPSRCCL; 02193 hdsi->Instance->WPCR[1U] |= Value << 6U; 02194 } 02195 else if (Lane == DSI_DATA_LANES) 02196 { 02197 /* Low-Power transmission Slew Rate Compensation on Data Lanes */ 02198 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPSRCDL; 02199 hdsi->Instance->WPCR[1U] |= Value << 8U; 02200 } 02201 else 02202 { 02203 /* Process unlocked */ 02204 __HAL_UNLOCK(hdsi); 02205 02206 return HAL_ERROR; 02207 } 02208 break; 02209 case DSI_HS_DELAY: 02210 if (Lane == DSI_CLOCK_LANE) 02211 { 02212 /* High-Speed Transmission Delay on Clock Lane */ 02213 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXDCL; 02214 hdsi->Instance->WPCR[1U] |= Value; 02215 } 02216 else if (Lane == DSI_DATA_LANES) 02217 { 02218 /* High-Speed Transmission Delay on Data Lanes */ 02219 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXDDL; 02220 hdsi->Instance->WPCR[1U] |= Value << 2U; 02221 } 02222 else 02223 { 02224 /* Process unlocked */ 02225 __HAL_UNLOCK(hdsi); 02226 02227 return HAL_ERROR; 02228 } 02229 break; 02230 default: 02231 break; 02232 } 02233 02234 /* Process unlocked */ 02235 __HAL_UNLOCK(hdsi); 02236 02237 return HAL_OK; 02238 } 02239 02240 /** 02241 * @brief Low-Power Reception Filter Tuning 02242 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02243 * the configuration information for the DSI. 02244 * @param Frequency cutoff frequency of low-pass filter at the input of LPRX 02245 * @retval HAL status 02246 */ 02247 HAL_StatusTypeDef HAL_DSI_SetLowPowerRXFilter(DSI_HandleTypeDef *hdsi, uint32_t Frequency) 02248 { 02249 /* Process locked */ 02250 __HAL_LOCK(hdsi); 02251 02252 /* Low-Power RX low-pass Filtering Tuning */ 02253 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPRXFT; 02254 hdsi->Instance->WPCR[1U] |= Frequency << 25U; 02255 02256 /* Process unlocked */ 02257 __HAL_UNLOCK(hdsi); 02258 02259 return HAL_OK; 02260 } 02261 02262 /** 02263 * @brief Activate an additional current path on all lanes to meet the SDDTx parameter 02264 * defined in the MIPI D-PHY specification 02265 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02266 * the configuration information for the DSI. 02267 * @param State ENABLE or DISABLE 02268 * @retval HAL status 02269 */ 02270 HAL_StatusTypeDef HAL_DSI_SetSDD(DSI_HandleTypeDef *hdsi, FunctionalState State) 02271 { 02272 /* Process locked */ 02273 __HAL_LOCK(hdsi); 02274 02275 /* Check function parameters */ 02276 assert_param(IS_FUNCTIONAL_STATE(State)); 02277 02278 /* Activate/Disactivate additional current path on all lanes */ 02279 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_SDDC; 02280 hdsi->Instance->WPCR[1U] |= ((uint32_t)State << 12U); 02281 02282 /* Process unlocked */ 02283 __HAL_UNLOCK(hdsi); 02284 02285 return HAL_OK; 02286 } 02287 02288 /** 02289 * @brief Custom lane pins configuration 02290 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02291 * the configuration information for the DSI. 02292 * @param CustomLane Function to be applied on selected lane. 02293 * This parameter can be any value of @arg DSI_CustomLane 02294 * @param Lane select between clock or data lane 0 or data lane 1. 02295 * This parameter can be any value of @arg DSI_Lane_Select 02296 * @param State ENABLE or DISABLE 02297 * @retval HAL status 02298 */ 02299 HAL_StatusTypeDef HAL_DSI_SetLanePinsConfiguration(DSI_HandleTypeDef *hdsi, uint32_t CustomLane, uint32_t Lane, 02300 FunctionalState State) 02301 { 02302 /* Process locked */ 02303 __HAL_LOCK(hdsi); 02304 02305 /* Check function parameters */ 02306 assert_param(IS_DSI_CUSTOM_LANE(CustomLane)); 02307 assert_param(IS_DSI_LANE(Lane)); 02308 assert_param(IS_FUNCTIONAL_STATE(State)); 02309 02310 switch (CustomLane) 02311 { 02312 case DSI_SWAP_LANE_PINS: 02313 if (Lane == DSI_CLK_LANE) 02314 { 02315 /* Swap pins on clock lane */ 02316 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWCL; 02317 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 6U); 02318 } 02319 else if (Lane == DSI_DATA_LANE0) 02320 { 02321 /* Swap pins on data lane 0 */ 02322 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWDL0; 02323 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 7U); 02324 } 02325 else if (Lane == DSI_DATA_LANE1) 02326 { 02327 /* Swap pins on data lane 1 */ 02328 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWDL1; 02329 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 8U); 02330 } 02331 else 02332 { 02333 /* Process unlocked */ 02334 __HAL_UNLOCK(hdsi); 02335 02336 return HAL_ERROR; 02337 } 02338 break; 02339 case DSI_INVERT_HS_SIGNAL: 02340 if (Lane == DSI_CLK_LANE) 02341 { 02342 /* Invert HS signal on clock lane */ 02343 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSICL; 02344 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 9U); 02345 } 02346 else if (Lane == DSI_DATA_LANE0) 02347 { 02348 /* Invert HS signal on data lane 0 */ 02349 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSIDL0; 02350 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 10U); 02351 } 02352 else if (Lane == DSI_DATA_LANE1) 02353 { 02354 /* Invert HS signal on data lane 1 */ 02355 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSIDL1; 02356 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 11U); 02357 } 02358 else 02359 { 02360 /* Process unlocked */ 02361 __HAL_UNLOCK(hdsi); 02362 02363 return HAL_ERROR; 02364 } 02365 break; 02366 default: 02367 break; 02368 } 02369 02370 /* Process unlocked */ 02371 __HAL_UNLOCK(hdsi); 02372 02373 return HAL_OK; 02374 } 02375 02376 /** 02377 * @brief Set custom timing for the PHY 02378 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02379 * the configuration information for the DSI. 02380 * @param Timing PHY timing to be adjusted. 02381 * This parameter can be any value of @arg DSI_PHY_Timing 02382 * @param State ENABLE or DISABLE 02383 * @param Value Custom value of the timing 02384 * @retval HAL status 02385 */ 02386 HAL_StatusTypeDef HAL_DSI_SetPHYTimings(DSI_HandleTypeDef *hdsi, uint32_t Timing, FunctionalState State, uint32_t Value) 02387 { 02388 /* Process locked */ 02389 __HAL_LOCK(hdsi); 02390 02391 /* Check function parameters */ 02392 assert_param(IS_DSI_PHY_TIMING(Timing)); 02393 assert_param(IS_FUNCTIONAL_STATE(State)); 02394 02395 switch (Timing) 02396 { 02397 case DSI_TCLK_POST: 02398 /* Enable/Disable custom timing setting */ 02399 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKPOSTEN; 02400 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 27U); 02401 02402 if (State != DISABLE) 02403 { 02404 /* Set custom value */ 02405 hdsi->Instance->WPCR[4U] &= ~DSI_WPCR4_TCLKPOST; 02406 hdsi->Instance->WPCR[4U] |= Value & DSI_WPCR4_TCLKPOST; 02407 } 02408 02409 break; 02410 case DSI_TLPX_CLK: 02411 /* Enable/Disable custom timing setting */ 02412 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TLPXCEN; 02413 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 26U); 02414 02415 if (State != DISABLE) 02416 { 02417 /* Set custom value */ 02418 hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_TLPXC; 02419 hdsi->Instance->WPCR[3U] |= (Value << 24U) & DSI_WPCR3_TLPXC; 02420 } 02421 02422 break; 02423 case DSI_THS_EXIT: 02424 /* Enable/Disable custom timing setting */ 02425 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSEXITEN; 02426 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 25U); 02427 02428 if (State != DISABLE) 02429 { 02430 /* Set custom value */ 02431 hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_THSEXIT; 02432 hdsi->Instance->WPCR[3U] |= (Value << 16U) & DSI_WPCR3_THSEXIT; 02433 } 02434 02435 break; 02436 case DSI_TLPX_DATA: 02437 /* Enable/Disable custom timing setting */ 02438 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TLPXDEN; 02439 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 24U); 02440 02441 if (State != DISABLE) 02442 { 02443 /* Set custom value */ 02444 hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_TLPXD; 02445 hdsi->Instance->WPCR[3U] |= (Value << 8U) & DSI_WPCR3_TLPXD; 02446 } 02447 02448 break; 02449 case DSI_THS_ZERO: 02450 /* Enable/Disable custom timing setting */ 02451 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSZEROEN; 02452 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 23U); 02453 02454 if (State != DISABLE) 02455 { 02456 /* Set custom value */ 02457 hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_THSZERO; 02458 hdsi->Instance->WPCR[3U] |= Value & DSI_WPCR3_THSZERO; 02459 } 02460 02461 break; 02462 case DSI_THS_TRAIL: 02463 /* Enable/Disable custom timing setting */ 02464 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSTRAILEN; 02465 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 22U); 02466 02467 if (State != DISABLE) 02468 { 02469 /* Set custom value */ 02470 hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_THSTRAIL; 02471 hdsi->Instance->WPCR[2U] |= (Value << 24U) & DSI_WPCR2_THSTRAIL; 02472 } 02473 02474 break; 02475 case DSI_THS_PREPARE: 02476 /* Enable/Disable custom timing setting */ 02477 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSPREPEN; 02478 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 21U); 02479 02480 if (State != DISABLE) 02481 { 02482 /* Set custom value */ 02483 hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_THSPREP; 02484 hdsi->Instance->WPCR[2U] |= (Value << 16U) & DSI_WPCR2_THSPREP; 02485 } 02486 02487 break; 02488 case DSI_TCLK_ZERO: 02489 /* Enable/Disable custom timing setting */ 02490 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKZEROEN; 02491 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 20U); 02492 02493 if (State != DISABLE) 02494 { 02495 /* Set custom value */ 02496 hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_TCLKZERO; 02497 hdsi->Instance->WPCR[2U] |= (Value << 8U) & DSI_WPCR2_TCLKZERO; 02498 } 02499 02500 break; 02501 case DSI_TCLK_PREPARE: 02502 /* Enable/Disable custom timing setting */ 02503 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKPREPEN; 02504 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 19U); 02505 02506 if (State != DISABLE) 02507 { 02508 /* Set custom value */ 02509 hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_TCLKPREP; 02510 hdsi->Instance->WPCR[2U] |= Value & DSI_WPCR2_TCLKPREP; 02511 } 02512 02513 break; 02514 default: 02515 break; 02516 } 02517 02518 /* Process unlocked */ 02519 __HAL_UNLOCK(hdsi); 02520 02521 return HAL_OK; 02522 } 02523 02524 /** 02525 * @brief Force the Clock/Data Lane in TX Stop Mode 02526 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02527 * the configuration information for the DSI. 02528 * @param Lane select between clock or data lanes. 02529 * This parameter can be any value of @arg DSI_Lane_Group 02530 * @param State ENABLE or DISABLE 02531 * @retval HAL status 02532 */ 02533 HAL_StatusTypeDef HAL_DSI_ForceTXStopMode(DSI_HandleTypeDef *hdsi, uint32_t Lane, FunctionalState State) 02534 { 02535 /* Process locked */ 02536 __HAL_LOCK(hdsi); 02537 02538 /* Check function parameters */ 02539 assert_param(IS_DSI_LANE_GROUP(Lane)); 02540 assert_param(IS_FUNCTIONAL_STATE(State)); 02541 02542 if (Lane == DSI_CLOCK_LANE) 02543 { 02544 /* Force/Unforce the Clock Lane in TX Stop Mode */ 02545 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_FTXSMCL; 02546 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 12U); 02547 } 02548 else if (Lane == DSI_DATA_LANES) 02549 { 02550 /* Force/Unforce the Data Lanes in TX Stop Mode */ 02551 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_FTXSMDL; 02552 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 13U); 02553 } 02554 else 02555 { 02556 /* Process unlocked */ 02557 __HAL_UNLOCK(hdsi); 02558 02559 return HAL_ERROR; 02560 } 02561 02562 /* Process unlocked */ 02563 __HAL_UNLOCK(hdsi); 02564 02565 return HAL_OK; 02566 } 02567 02568 /** 02569 * @brief Force LP Receiver in Low-Power Mode 02570 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02571 * the configuration information for the DSI. 02572 * @param State ENABLE or DISABLE 02573 * @retval HAL status 02574 */ 02575 HAL_StatusTypeDef HAL_DSI_ForceRXLowPower(DSI_HandleTypeDef *hdsi, FunctionalState State) 02576 { 02577 /* Process locked */ 02578 __HAL_LOCK(hdsi); 02579 02580 /* Check function parameters */ 02581 assert_param(IS_FUNCTIONAL_STATE(State)); 02582 02583 /* Force/Unforce LP Receiver in Low-Power Mode */ 02584 hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_FLPRXLPM; 02585 hdsi->Instance->WPCR[1U] |= ((uint32_t)State << 22U); 02586 02587 /* Process unlocked */ 02588 __HAL_UNLOCK(hdsi); 02589 02590 return HAL_OK; 02591 } 02592 02593 /** 02594 * @brief Force Data Lanes in RX Mode after a BTA 02595 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02596 * the configuration information for the DSI. 02597 * @param State ENABLE or DISABLE 02598 * @retval HAL status 02599 */ 02600 HAL_StatusTypeDef HAL_DSI_ForceDataLanesInRX(DSI_HandleTypeDef *hdsi, FunctionalState State) 02601 { 02602 /* Process locked */ 02603 __HAL_LOCK(hdsi); 02604 02605 /* Check function parameters */ 02606 assert_param(IS_FUNCTIONAL_STATE(State)); 02607 02608 /* Force Data Lanes in RX Mode */ 02609 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TDDL; 02610 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 16U); 02611 02612 /* Process unlocked */ 02613 __HAL_UNLOCK(hdsi); 02614 02615 return HAL_OK; 02616 } 02617 02618 /** 02619 * @brief Enable a pull-down on the lanes to prevent from floating states when unused 02620 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02621 * the configuration information for the DSI. 02622 * @param State ENABLE or DISABLE 02623 * @retval HAL status 02624 */ 02625 HAL_StatusTypeDef HAL_DSI_SetPullDown(DSI_HandleTypeDef *hdsi, FunctionalState State) 02626 { 02627 /* Process locked */ 02628 __HAL_LOCK(hdsi); 02629 02630 /* Check function parameters */ 02631 assert_param(IS_FUNCTIONAL_STATE(State)); 02632 02633 /* Enable/Disable pull-down on lanes */ 02634 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_PDEN; 02635 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 18U); 02636 02637 /* Process unlocked */ 02638 __HAL_UNLOCK(hdsi); 02639 02640 return HAL_OK; 02641 } 02642 02643 /** 02644 * @brief Switch off the contention detection on data lanes 02645 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02646 * the configuration information for the DSI. 02647 * @param State ENABLE or DISABLE 02648 * @retval HAL status 02649 */ 02650 HAL_StatusTypeDef HAL_DSI_SetContentionDetectionOff(DSI_HandleTypeDef *hdsi, FunctionalState State) 02651 { 02652 /* Process locked */ 02653 __HAL_LOCK(hdsi); 02654 02655 /* Check function parameters */ 02656 assert_param(IS_FUNCTIONAL_STATE(State)); 02657 02658 /* Contention Detection on Data Lanes OFF */ 02659 hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_CDOFFDL; 02660 hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 14U); 02661 02662 /* Process unlocked */ 02663 __HAL_UNLOCK(hdsi); 02664 02665 return HAL_OK; 02666 } 02667 02668 /** 02669 * @} 02670 */ 02671 02672 /** @defgroup DSI_Group4 Peripheral State and Errors functions 02673 * @brief Peripheral State and Errors functions 02674 * 02675 @verbatim 02676 =============================================================================== 02677 ##### Peripheral State and Errors functions ##### 02678 =============================================================================== 02679 [..] 02680 This subsection provides functions allowing to 02681 (+) Check the DSI state. 02682 (+) Get error code. 02683 02684 @endverbatim 02685 * @{ 02686 */ 02687 02688 /** 02689 * @brief Return the DSI state 02690 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02691 * the configuration information for the DSI. 02692 * @retval HAL state 02693 */ 02694 HAL_DSI_StateTypeDef HAL_DSI_GetState(DSI_HandleTypeDef *hdsi) 02695 { 02696 return hdsi->State; 02697 } 02698 02699 /** 02700 * @brief Return the DSI error code 02701 * @param hdsi pointer to a DSI_HandleTypeDef structure that contains 02702 * the configuration information for the DSI. 02703 * @retval DSI Error Code 02704 */ 02705 uint32_t HAL_DSI_GetError(DSI_HandleTypeDef *hdsi) 02706 { 02707 /* Get the error code */ 02708 return hdsi->ErrorCode; 02709 } 02710 02711 /** 02712 * @} 02713 */ 02714 02715 /** 02716 * @} 02717 */ 02718 02719 /** 02720 * @} 02721 */ 02722 02723 #endif /* DSI */ 02724 02725 #endif /* HAL_DSI_MODULE_ENABLED */ 02726 02727 /** 02728 * @} 02729 */ 02730 02731 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/