You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

2271 lines
69 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_dsi.c
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 14-April-2017
  7. * @brief DSI HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the DSI peripheral:
  10. * + Initialization and de-initialization functions
  11. * + IO operation functions
  12. * + Peripheral Control functions
  13. * + Peripheral State and Errors functions
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  18. *
  19. * Redistribution and use in source and binary forms, with or without modification,
  20. * are permitted provided that the following conditions are met:
  21. * 1. Redistributions of source code must retain the above copyright notice,
  22. * this list of conditions and the following disclaimer.
  23. * 2. Redistributions in binary form must reproduce the above copyright notice,
  24. * this list of conditions and the following disclaimer in the documentation
  25. * and/or other materials provided with the distribution.
  26. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  27. * may be used to endorse or promote products derived from this software
  28. * without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  34. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  36. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  37. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  38. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ******************************************************************************
  42. */
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal.h"
  45. /** @addtogroup STM32F4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup DSI
  49. * @{
  50. */
  51. #ifdef HAL_DSI_MODULE_ENABLED
  52. #if defined(STM32F469xx) || defined(STM32F479xx)
  53. /* Private types -------------------------------------------------------------*/
  54. /* Private defines -----------------------------------------------------------*/
  55. /** @addtogroup DSI_Private_Constants
  56. * @{
  57. */
  58. #define DSI_TIMEOUT_VALUE ((uint32_t)1000U) /* 1s */
  59. #define DSI_ERROR_ACK_MASK (DSI_ISR0_AE0 | DSI_ISR0_AE1 | DSI_ISR0_AE2 | DSI_ISR0_AE3 | \
  60. DSI_ISR0_AE4 | DSI_ISR0_AE5 | DSI_ISR0_AE6 | DSI_ISR0_AE7 | \
  61. DSI_ISR0_AE8 | DSI_ISR0_AE9 | DSI_ISR0_AE10 | DSI_ISR0_AE11 | \
  62. DSI_ISR0_AE12 | DSI_ISR0_AE13 | DSI_ISR0_AE14 | DSI_ISR0_AE15)
  63. #define DSI_ERROR_PHY_MASK (DSI_ISR0_PE0 | DSI_ISR0_PE1 | DSI_ISR0_PE2 | DSI_ISR0_PE3 | DSI_ISR0_PE4)
  64. #define DSI_ERROR_TX_MASK DSI_ISR1_TOHSTX
  65. #define DSI_ERROR_RX_MASK DSI_ISR1_TOLPRX
  66. #define DSI_ERROR_ECC_MASK (DSI_ISR1_ECCSE | DSI_ISR1_ECCME)
  67. #define DSI_ERROR_CRC_MASK DSI_ISR1_CRCE
  68. #define DSI_ERROR_PSE_MASK DSI_ISR1_PSE
  69. #define DSI_ERROR_EOT_MASK DSI_ISR1_EOTPE
  70. #define DSI_ERROR_OVF_MASK DSI_ISR1_LPWRE
  71. #define DSI_ERROR_GEN_MASK (DSI_ISR1_GCWRE | DSI_ISR1_GPWRE | DSI_ISR1_GPTXE | DSI_ISR1_GPRDE | DSI_ISR1_GPRXE)
  72. /**
  73. * @}
  74. */
  75. /* Private variables ---------------------------------------------------------*/
  76. /* Private constants ---------------------------------------------------------*/
  77. /* Private macros ------------------------------------------------------------*/
  78. /* Private function prototypes -----------------------------------------------*/
  79. static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx, uint32_t ChannelID, uint32_t DataType, uint32_t Data0, uint32_t Data1);
  80. /* Private functions ---------------------------------------------------------*/
  81. /**
  82. * @brief Generic DSI packet header configuration
  83. * @param DSIx: Pointer to DSI register base
  84. * @param ChannelID: Virtual channel ID of the header packet
  85. * @param DataType: Packet data type of the header packet
  86. * This parameter can be any value of :
  87. * @ref DSI_SHORT_WRITE_PKT_Data_Type
  88. * or @ref DSI_LONG_WRITE_PKT_Data_Type
  89. * or @ref DSI_SHORT_READ_PKT_Data_Type
  90. * or DSI_MAX_RETURN_PKT_SIZE
  91. * @param Data0: Word count LSB
  92. * @param Data1: Word count MSB
  93. * @retval None
  94. */
  95. static void DSI_ConfigPacketHeader(DSI_TypeDef *DSIx,
  96. uint32_t ChannelID,
  97. uint32_t DataType,
  98. uint32_t Data0,
  99. uint32_t Data1)
  100. {
  101. /* Update the DSI packet header with new information */
  102. DSIx->GHCR = (DataType | (ChannelID<<6U) | (Data0<<8U) | (Data1<<16U));
  103. }
  104. /* Exported functions --------------------------------------------------------*/
  105. /** @addtogroup DSI_Exported_Functions
  106. * @{
  107. */
  108. /** @defgroup DSI_Group1 Initialization and Configuration functions
  109. * @brief Initialization and Configuration functions
  110. *
  111. @verbatim
  112. ===============================================================================
  113. ##### Initialization and Configuration functions #####
  114. ===============================================================================
  115. [..] This section provides functions allowing to:
  116. (+) Initialize and configure the DSI
  117. (+) De-initialize the DSI
  118. @endverbatim
  119. * @{
  120. */
  121. /**
  122. * @brief Initializes the DSI according to the specified
  123. * parameters in the DSI_InitTypeDef and create the associated handle.
  124. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  125. * the configuration information for the DSI.
  126. * @param PLLInit: pointer to a DSI_PLLInitTypeDef structure that contains
  127. * the PLL Clock structure definition for the DSI.
  128. * @retval HAL status
  129. */
  130. HAL_StatusTypeDef HAL_DSI_Init(DSI_HandleTypeDef *hdsi, DSI_PLLInitTypeDef *PLLInit)
  131. {
  132. uint32_t tickstart = 0U;
  133. uint32_t unitIntervalx4 = 0U;
  134. uint32_t tempIDF = 0U;
  135. /* Check the DSI handle allocation */
  136. if(hdsi == NULL)
  137. {
  138. return HAL_ERROR;
  139. }
  140. /* Check function parameters */
  141. assert_param(IS_DSI_PLL_NDIV(PLLInit->PLLNDIV));
  142. assert_param(IS_DSI_PLL_IDF(PLLInit->PLLIDF));
  143. assert_param(IS_DSI_PLL_ODF(PLLInit->PLLODF));
  144. assert_param(IS_DSI_AUTO_CLKLANE_CONTROL(hdsi->Init.AutomaticClockLaneControl));
  145. assert_param(IS_DSI_NUMBER_OF_LANES(hdsi->Init.NumberOfLanes));
  146. if(hdsi->State == HAL_DSI_STATE_RESET)
  147. {
  148. /* Initialize the low level hardware */
  149. HAL_DSI_MspInit(hdsi);
  150. }
  151. /* Change DSI peripheral state */
  152. hdsi->State = HAL_DSI_STATE_BUSY;
  153. /**************** Turn on the regulator and enable the DSI PLL ****************/
  154. /* Enable the regulator */
  155. __HAL_DSI_REG_ENABLE(hdsi);
  156. /* Get tick */
  157. tickstart = HAL_GetTick();
  158. /* Wait until the regulator is ready */
  159. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_RRS) == RESET)
  160. {
  161. /* Check for the Timeout */
  162. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  163. {
  164. return HAL_TIMEOUT;
  165. }
  166. }
  167. /* Set the PLL division factors */
  168. hdsi->Instance->WRPCR &= ~(DSI_WRPCR_PLL_NDIV | DSI_WRPCR_PLL_IDF | DSI_WRPCR_PLL_ODF);
  169. hdsi->Instance->WRPCR |= (((PLLInit->PLLNDIV)<<2U) | ((PLLInit->PLLIDF)<<11U) | ((PLLInit->PLLODF)<<16U));
  170. /* Enable the DSI PLL */
  171. __HAL_DSI_PLL_ENABLE(hdsi);
  172. /* Get tick */
  173. tickstart = HAL_GetTick();
  174. /* Wait for the lock of the PLL */
  175. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_PLLLS) == RESET)
  176. {
  177. /* Check for the Timeout */
  178. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  179. {
  180. return HAL_TIMEOUT;
  181. }
  182. }
  183. /*************************** Set the PHY parameters ***************************/
  184. /* D-PHY clock and digital enable*/
  185. hdsi->Instance->PCTLR |= (DSI_PCTLR_CKE | DSI_PCTLR_DEN);
  186. /* Clock lane configuration */
  187. hdsi->Instance->CLCR &= ~(DSI_CLCR_DPCC | DSI_CLCR_ACR);
  188. hdsi->Instance->CLCR |= (DSI_CLCR_DPCC | hdsi->Init.AutomaticClockLaneControl);
  189. /* Configure the number of active data lanes */
  190. hdsi->Instance->PCONFR &= ~DSI_PCONFR_NL;
  191. hdsi->Instance->PCONFR |= hdsi->Init.NumberOfLanes;
  192. /************************ Set the DSI clock parameters ************************/
  193. /* Set the TX escape clock division factor */
  194. hdsi->Instance->CCR &= ~DSI_CCR_TXECKDIV;
  195. hdsi->Instance->CCR |= hdsi->Init.TXEscapeCkdiv;
  196. /* Calculate the bit period in high-speed mode in unit of 0.25 ns (UIX4) */
  197. /* The equation is : UIX4 = IntegerPart( (1000/F_PHY_Mhz) * 4 ) */
  198. /* Where : F_PHY_Mhz = (NDIV * HSE_Mhz) / (IDF * ODF) */
  199. tempIDF = (PLLInit->PLLIDF > 0U) ? PLLInit->PLLIDF : 1U;
  200. unitIntervalx4 = (4000000U * tempIDF * (1U << PLLInit->PLLODF)) / ((HSE_VALUE/1000U) * PLLInit->PLLNDIV);
  201. /* Set the bit period in high-speed mode */
  202. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_UIX4;
  203. hdsi->Instance->WPCR[0U] |= unitIntervalx4;
  204. /****************************** Error management *****************************/
  205. /* Disable all error interrupts and reset the Error Mask */
  206. hdsi->Instance->IER[0U] = 0U;
  207. hdsi->Instance->IER[1U] = 0U;
  208. hdsi->ErrorMsk = 0U;
  209. /* Initialise the error code */
  210. hdsi->ErrorCode = HAL_DSI_ERROR_NONE;
  211. /* Initialize the DSI state*/
  212. hdsi->State = HAL_DSI_STATE_READY;
  213. return HAL_OK;
  214. }
  215. /**
  216. * @brief De-initializes the DSI peripheral registers to their default reset
  217. * values.
  218. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  219. * the configuration information for the DSI.
  220. * @retval HAL status
  221. */
  222. HAL_StatusTypeDef HAL_DSI_DeInit(DSI_HandleTypeDef *hdsi)
  223. {
  224. /* Check the DSI handle allocation */
  225. if(hdsi == NULL)
  226. {
  227. return HAL_ERROR;
  228. }
  229. /* Change DSI peripheral state */
  230. hdsi->State = HAL_DSI_STATE_BUSY;
  231. /* Disable the DSI wrapper */
  232. __HAL_DSI_WRAPPER_DISABLE(hdsi);
  233. /* Disable the DSI host */
  234. __HAL_DSI_DISABLE(hdsi);
  235. /* D-PHY clock and digital disable */
  236. hdsi->Instance->PCTLR &= ~(DSI_PCTLR_CKE | DSI_PCTLR_DEN);
  237. /* Turn off the DSI PLL */
  238. __HAL_DSI_PLL_DISABLE(hdsi);
  239. /* Disable the regulator */
  240. __HAL_DSI_REG_DISABLE(hdsi);
  241. /* DeInit the low level hardware */
  242. HAL_DSI_MspDeInit(hdsi);
  243. /* Initialise the error code */
  244. hdsi->ErrorCode = HAL_DSI_ERROR_NONE;
  245. /* Initialize the DSI state*/
  246. hdsi->State = HAL_DSI_STATE_RESET;
  247. /* Release Lock */
  248. __HAL_UNLOCK(hdsi);
  249. return HAL_OK;
  250. }
  251. /**
  252. * @brief Return the DSI error code
  253. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  254. * the configuration information for the DSI.
  255. * @retval DSI Error Code
  256. */
  257. uint32_t HAL_DSI_GetError(DSI_HandleTypeDef *hdsi)
  258. {
  259. /* Get the error code */
  260. return hdsi->ErrorCode;
  261. }
  262. /**
  263. * @brief Enable the error monitor flags
  264. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  265. * the configuration information for the DSI.
  266. * @param ActiveErrors: indicates which error interrupts will be enabled.
  267. * This parameter can be any combination of @ref DSI_Error_Data_Type.
  268. * @retval HAL status
  269. */
  270. HAL_StatusTypeDef HAL_DSI_ConfigErrorMonitor(DSI_HandleTypeDef *hdsi, uint32_t ActiveErrors)
  271. {
  272. /* Process locked */
  273. __HAL_LOCK(hdsi);
  274. hdsi->Instance->IER[0U] = 0U;
  275. hdsi->Instance->IER[1U] = 0U;
  276. /* Store active errors to the handle */
  277. hdsi->ErrorMsk = ActiveErrors;
  278. if((ActiveErrors & HAL_DSI_ERROR_ACK) != RESET)
  279. {
  280. /* Enable the interrupt generation on selected errors */
  281. hdsi->Instance->IER[0U] |= DSI_ERROR_ACK_MASK;
  282. }
  283. if((ActiveErrors & HAL_DSI_ERROR_PHY) != RESET)
  284. {
  285. /* Enable the interrupt generation on selected errors */
  286. hdsi->Instance->IER[0U] |= DSI_ERROR_PHY_MASK;
  287. }
  288. if((ActiveErrors & HAL_DSI_ERROR_TX) != RESET)
  289. {
  290. /* Enable the interrupt generation on selected errors */
  291. hdsi->Instance->IER[1U] |= DSI_ERROR_TX_MASK;
  292. }
  293. if((ActiveErrors & HAL_DSI_ERROR_RX) != RESET)
  294. {
  295. /* Enable the interrupt generation on selected errors */
  296. hdsi->Instance->IER[1U] |= DSI_ERROR_RX_MASK;
  297. }
  298. if((ActiveErrors & HAL_DSI_ERROR_ECC) != RESET)
  299. {
  300. /* Enable the interrupt generation on selected errors */
  301. hdsi->Instance->IER[1U] |= DSI_ERROR_ECC_MASK;
  302. }
  303. if((ActiveErrors & HAL_DSI_ERROR_CRC) != RESET)
  304. {
  305. /* Enable the interrupt generation on selected errors */
  306. hdsi->Instance->IER[1U] |= DSI_ERROR_CRC_MASK;
  307. }
  308. if((ActiveErrors & HAL_DSI_ERROR_PSE) != RESET)
  309. {
  310. /* Enable the interrupt generation on selected errors */
  311. hdsi->Instance->IER[1U] |= DSI_ERROR_PSE_MASK;
  312. }
  313. if((ActiveErrors & HAL_DSI_ERROR_EOT) != RESET)
  314. {
  315. /* Enable the interrupt generation on selected errors */
  316. hdsi->Instance->IER[1U] |= DSI_ERROR_EOT_MASK;
  317. }
  318. if((ActiveErrors & HAL_DSI_ERROR_OVF) != RESET)
  319. {
  320. /* Enable the interrupt generation on selected errors */
  321. hdsi->Instance->IER[1U] |= DSI_ERROR_OVF_MASK;
  322. }
  323. if((ActiveErrors & HAL_DSI_ERROR_GEN) != RESET)
  324. {
  325. /* Enable the interrupt generation on selected errors */
  326. hdsi->Instance->IER[1U] |= DSI_ERROR_GEN_MASK;
  327. }
  328. /* Process Unlocked */
  329. __HAL_UNLOCK(hdsi);
  330. return HAL_OK;
  331. }
  332. /**
  333. * @brief Initializes the DSI MSP.
  334. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  335. * the configuration information for the DSI.
  336. * @retval None
  337. */
  338. __weak void HAL_DSI_MspInit(DSI_HandleTypeDef* hdsi)
  339. {
  340. /* Prevent unused argument(s) compilation warning */
  341. UNUSED(hdsi);
  342. /* NOTE : This function Should not be modified, when the callback is needed,
  343. the HAL_DSI_MspInit could be implemented in the user file
  344. */
  345. }
  346. /**
  347. * @brief De-initializes the DSI MSP.
  348. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  349. * the configuration information for the DSI.
  350. * @retval None
  351. */
  352. __weak void HAL_DSI_MspDeInit(DSI_HandleTypeDef* hdsi)
  353. {
  354. /* Prevent unused argument(s) compilation warning */
  355. UNUSED(hdsi);
  356. /* NOTE : This function Should not be modified, when the callback is needed,
  357. the HAL_DSI_MspDeInit could be implemented in the user file
  358. */
  359. }
  360. /**
  361. * @}
  362. */
  363. /** @defgroup DSI_Group2 IO operation functions
  364. * @brief IO operation functions
  365. *
  366. @verbatim
  367. ===============================================================================
  368. ##### IO operation functions #####
  369. ===============================================================================
  370. [..] This section provides function allowing to:
  371. (+) Handle DSI interrupt request
  372. @endverbatim
  373. * @{
  374. */
  375. /**
  376. * @brief Handles DSI interrupt request.
  377. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  378. * the configuration information for the DSI.
  379. * @retval HAL status
  380. */
  381. void HAL_DSI_IRQHandler(DSI_HandleTypeDef *hdsi)
  382. {
  383. uint32_t ErrorStatus0, ErrorStatus1;
  384. /* Tearing Effect Interrupt management ***************************************/
  385. if(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_TE) != RESET)
  386. {
  387. if(__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_TE) != RESET)
  388. {
  389. /* Clear the Tearing Effect Interrupt Flag */
  390. __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_TE);
  391. /* Tearing Effect Callback */
  392. HAL_DSI_TearingEffectCallback(hdsi);
  393. }
  394. }
  395. /* End of Refresh Interrupt management ***************************************/
  396. if(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_ER) != RESET)
  397. {
  398. if(__HAL_DSI_GET_IT_SOURCE(hdsi, DSI_IT_ER) != RESET)
  399. {
  400. /* Clear the End of Refresh Interrupt Flag */
  401. __HAL_DSI_CLEAR_FLAG(hdsi, DSI_FLAG_ER);
  402. /* End of Refresh Callback */
  403. HAL_DSI_EndOfRefreshCallback(hdsi);
  404. }
  405. }
  406. /* Error Interrupts management ***********************************************/
  407. if(hdsi->ErrorMsk != 0U)
  408. {
  409. ErrorStatus0 = hdsi->Instance->ISR[0U];
  410. ErrorStatus0 &= hdsi->Instance->IER[0U];
  411. ErrorStatus1 = hdsi->Instance->ISR[1U];
  412. ErrorStatus1 &= hdsi->Instance->IER[1U];
  413. if((ErrorStatus0 & DSI_ERROR_ACK_MASK) != RESET)
  414. {
  415. hdsi->ErrorCode |= HAL_DSI_ERROR_ACK;
  416. }
  417. if((ErrorStatus0 & DSI_ERROR_PHY_MASK) != RESET)
  418. {
  419. hdsi->ErrorCode |= HAL_DSI_ERROR_PHY;
  420. }
  421. if((ErrorStatus1 & DSI_ERROR_TX_MASK) != RESET)
  422. {
  423. hdsi->ErrorCode |= HAL_DSI_ERROR_TX;
  424. }
  425. if((ErrorStatus1 & DSI_ERROR_RX_MASK) != RESET)
  426. {
  427. hdsi->ErrorCode |= HAL_DSI_ERROR_RX;
  428. }
  429. if((ErrorStatus1 & DSI_ERROR_ECC_MASK) != RESET)
  430. {
  431. hdsi->ErrorCode |= HAL_DSI_ERROR_ECC;
  432. }
  433. if((ErrorStatus1 & DSI_ERROR_CRC_MASK) != RESET)
  434. {
  435. hdsi->ErrorCode |= HAL_DSI_ERROR_CRC;
  436. }
  437. if((ErrorStatus1 & DSI_ERROR_PSE_MASK) != RESET)
  438. {
  439. hdsi->ErrorCode |= HAL_DSI_ERROR_PSE;
  440. }
  441. if((ErrorStatus1 & DSI_ERROR_EOT_MASK) != RESET)
  442. {
  443. hdsi->ErrorCode |= HAL_DSI_ERROR_EOT;
  444. }
  445. if((ErrorStatus1 & DSI_ERROR_OVF_MASK) != RESET)
  446. {
  447. hdsi->ErrorCode |= HAL_DSI_ERROR_OVF;
  448. }
  449. if((ErrorStatus1 & DSI_ERROR_GEN_MASK) != RESET)
  450. {
  451. hdsi->ErrorCode |= HAL_DSI_ERROR_GEN;
  452. }
  453. /* Check only selected errors */
  454. if(hdsi->ErrorCode != HAL_DSI_ERROR_NONE)
  455. {
  456. /* DSI error interrupt user callback */
  457. HAL_DSI_ErrorCallback(hdsi);
  458. }
  459. }
  460. }
  461. /**
  462. * @brief Tearing Effect DSI callback.
  463. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  464. * the configuration information for the DSI.
  465. * @retval None
  466. */
  467. __weak void HAL_DSI_TearingEffectCallback(DSI_HandleTypeDef *hdsi)
  468. {
  469. /* Prevent unused argument(s) compilation warning */
  470. UNUSED(hdsi);
  471. /* NOTE : This function Should not be modified, when the callback is needed,
  472. the HAL_DSI_TearingEffectCallback could be implemented in the user file
  473. */
  474. }
  475. /**
  476. * @brief End of Refresh DSI callback.
  477. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  478. * the configuration information for the DSI.
  479. * @retval None
  480. */
  481. __weak void HAL_DSI_EndOfRefreshCallback(DSI_HandleTypeDef *hdsi)
  482. {
  483. /* Prevent unused argument(s) compilation warning */
  484. UNUSED(hdsi);
  485. /* NOTE : This function Should not be modified, when the callback is needed,
  486. the HAL_DSI_EndOfRefreshCallback could be implemented in the user file
  487. */
  488. }
  489. /**
  490. * @brief Operation Error DSI callback.
  491. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  492. * the configuration information for the DSI.
  493. * @retval None
  494. */
  495. __weak void HAL_DSI_ErrorCallback(DSI_HandleTypeDef *hdsi)
  496. {
  497. /* Prevent unused argument(s) compilation warning */
  498. UNUSED(hdsi);
  499. /* NOTE : This function Should not be modified, when the callback is needed,
  500. the HAL_DSI_ErrorCallback could be implemented in the user file
  501. */
  502. }
  503. /**
  504. * @}
  505. */
  506. /** @defgroup DSI_Group3 Peripheral Control functions
  507. * @brief Peripheral Control functions
  508. *
  509. @verbatim
  510. ===============================================================================
  511. ##### Peripheral Control functions #####
  512. ===============================================================================
  513. @endverbatim
  514. * @{
  515. */
  516. /**
  517. * @brief Configure the Generic interface read-back Virtual Channel ID.
  518. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  519. * the configuration information for the DSI.
  520. * @param VirtualChannelID: Virtual channel ID
  521. * @retval HAL status
  522. */
  523. HAL_StatusTypeDef HAL_DSI_SetGenericVCID(DSI_HandleTypeDef *hdsi, uint32_t VirtualChannelID)
  524. {
  525. /* Process locked */
  526. __HAL_LOCK(hdsi);
  527. /* Update the GVCID register */
  528. hdsi->Instance->GVCIDR &= ~DSI_GVCIDR_VCID;
  529. hdsi->Instance->GVCIDR |= VirtualChannelID;
  530. /* Process unlocked */
  531. __HAL_UNLOCK(hdsi);
  532. return HAL_OK;
  533. }
  534. /**
  535. * @brief Select video mode and configure the corresponding parameters
  536. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  537. * the configuration information for the DSI.
  538. * @param VidCfg: pointer to a DSI_VidCfgTypeDef structure that contains
  539. * the DSI video mode configuration parameters
  540. * @retval HAL status
  541. */
  542. HAL_StatusTypeDef HAL_DSI_ConfigVideoMode(DSI_HandleTypeDef *hdsi, DSI_VidCfgTypeDef *VidCfg)
  543. {
  544. /* Process locked */
  545. __HAL_LOCK(hdsi);
  546. /* Check the parameters */
  547. assert_param(IS_DSI_COLOR_CODING(VidCfg->ColorCoding));
  548. assert_param(IS_DSI_VIDEO_MODE_TYPE(VidCfg->Mode));
  549. assert_param(IS_DSI_LP_COMMAND(VidCfg->LPCommandEnable));
  550. assert_param(IS_DSI_LP_HFP(VidCfg->LPHorizontalFrontPorchEnable));
  551. assert_param(IS_DSI_LP_HBP(VidCfg->LPHorizontalBackPorchEnable));
  552. assert_param(IS_DSI_LP_VACTIVE(VidCfg->LPVerticalActiveEnable));
  553. assert_param(IS_DSI_LP_VFP(VidCfg->LPVerticalFrontPorchEnable));
  554. assert_param(IS_DSI_LP_VBP(VidCfg->LPVerticalBackPorchEnable));
  555. assert_param(IS_DSI_LP_VSYNC(VidCfg->LPVerticalSyncActiveEnable));
  556. assert_param(IS_DSI_FBTAA(VidCfg->FrameBTAAcknowledgeEnable));
  557. assert_param(IS_DSI_DE_POLARITY(VidCfg->DEPolarity));
  558. assert_param(IS_DSI_VSYNC_POLARITY(VidCfg->VSPolarity));
  559. assert_param(IS_DSI_HSYNC_POLARITY(VidCfg->HSPolarity));
  560. /* Check the LooselyPacked variant only in 18-bit mode */
  561. if(VidCfg->ColorCoding == DSI_RGB666)
  562. {
  563. assert_param(IS_DSI_LOOSELY_PACKED(VidCfg->LooselyPacked));
  564. }
  565. /* Select video mode by resetting CMDM and DSIM bits */
  566. hdsi->Instance->MCR &= ~DSI_MCR_CMDM;
  567. hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM;
  568. /* Configure the video mode transmission type */
  569. hdsi->Instance->VMCR &= ~DSI_VMCR_VMT;
  570. hdsi->Instance->VMCR |= VidCfg->Mode;
  571. /* Configure the video packet size */
  572. hdsi->Instance->VPCR &= ~DSI_VPCR_VPSIZE;
  573. hdsi->Instance->VPCR |= VidCfg->PacketSize;
  574. /* Set the chunks number to be transmitted through the DSI link */
  575. hdsi->Instance->VCCR &= ~DSI_VCCR_NUMC;
  576. hdsi->Instance->VCCR |= VidCfg->NumberOfChunks;
  577. /* Set the size of the null packet */
  578. hdsi->Instance->VNPCR &= ~DSI_VNPCR_NPSIZE;
  579. hdsi->Instance->VNPCR |= VidCfg->NullPacketSize;
  580. /* Select the virtual channel for the LTDC interface traffic */
  581. hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID;
  582. hdsi->Instance->LVCIDR |= VidCfg->VirtualChannelID;
  583. /* Configure the polarity of control signals */
  584. hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP);
  585. hdsi->Instance->LPCR |= (VidCfg->DEPolarity | VidCfg->VSPolarity | VidCfg->HSPolarity);
  586. /* Select the color coding for the host */
  587. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC;
  588. hdsi->Instance->LCOLCR |= VidCfg->ColorCoding;
  589. /* Select the color coding for the wrapper */
  590. hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX;
  591. hdsi->Instance->WCFGR |= ((VidCfg->ColorCoding)<<1U);
  592. /* Enable/disable the loosely packed variant to 18-bit configuration */
  593. if(VidCfg->ColorCoding == DSI_RGB666)
  594. {
  595. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_LPE;
  596. hdsi->Instance->LCOLCR |= VidCfg->LooselyPacked;
  597. }
  598. /* Set the Horizontal Synchronization Active (HSA) in lane byte clock cycles */
  599. hdsi->Instance->VHSACR &= ~DSI_VHSACR_HSA;
  600. hdsi->Instance->VHSACR |= VidCfg->HorizontalSyncActive;
  601. /* Set the Horizontal Back Porch (HBP) in lane byte clock cycles */
  602. hdsi->Instance->VHBPCR &= ~DSI_VHBPCR_HBP;
  603. hdsi->Instance->VHBPCR |= VidCfg->HorizontalBackPorch;
  604. /* Set the total line time (HLINE=HSA+HBP+HACT+HFP) in lane byte clock cycles */
  605. hdsi->Instance->VLCR &= ~DSI_VLCR_HLINE;
  606. hdsi->Instance->VLCR |= VidCfg->HorizontalLine;
  607. /* Set the Vertical Synchronization Active (VSA) */
  608. hdsi->Instance->VVSACR &= ~DSI_VVSACR_VSA;
  609. hdsi->Instance->VVSACR |= VidCfg->VerticalSyncActive;
  610. /* Set the Vertical Back Porch (VBP)*/
  611. hdsi->Instance->VVBPCR &= ~DSI_VVBPCR_VBP;
  612. hdsi->Instance->VVBPCR |= VidCfg->VerticalBackPorch;
  613. /* Set the Vertical Front Porch (VFP)*/
  614. hdsi->Instance->VVFPCR &= ~DSI_VVFPCR_VFP;
  615. hdsi->Instance->VVFPCR |= VidCfg->VerticalFrontPorch;
  616. /* Set the Vertical Active period*/
  617. hdsi->Instance->VVACR &= ~DSI_VVACR_VA;
  618. hdsi->Instance->VVACR |= VidCfg->VerticalActive;
  619. /* Configure the command transmission mode */
  620. hdsi->Instance->VMCR &= ~DSI_VMCR_LPCE;
  621. hdsi->Instance->VMCR |= VidCfg->LPCommandEnable;
  622. /* Low power largest packet size */
  623. hdsi->Instance->LPMCR &= ~DSI_LPMCR_LPSIZE;
  624. hdsi->Instance->LPMCR |= ((VidCfg->LPLargestPacketSize)<<16U);
  625. /* Low power VACT largest packet size */
  626. hdsi->Instance->LPMCR &= ~DSI_LPMCR_VLPSIZE;
  627. hdsi->Instance->LPMCR |= VidCfg->LPVACTLargestPacketSize;
  628. /* Enable LP transition in HFP period */
  629. hdsi->Instance->VMCR &= ~DSI_VMCR_LPHFPE;
  630. hdsi->Instance->VMCR |= VidCfg->LPHorizontalFrontPorchEnable;
  631. /* Enable LP transition in HBP period */
  632. hdsi->Instance->VMCR &= ~DSI_VMCR_LPHBPE;
  633. hdsi->Instance->VMCR |= VidCfg->LPHorizontalBackPorchEnable;
  634. /* Enable LP transition in VACT period */
  635. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVAE;
  636. hdsi->Instance->VMCR |= VidCfg->LPVerticalActiveEnable;
  637. /* Enable LP transition in VFP period */
  638. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVFPE;
  639. hdsi->Instance->VMCR |= VidCfg->LPVerticalFrontPorchEnable;
  640. /* Enable LP transition in VBP period */
  641. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVBPE;
  642. hdsi->Instance->VMCR |= VidCfg->LPVerticalBackPorchEnable;
  643. /* Enable LP transition in vertical sync period */
  644. hdsi->Instance->VMCR &= ~DSI_VMCR_LPVSAE;
  645. hdsi->Instance->VMCR |= VidCfg->LPVerticalSyncActiveEnable;
  646. /* Enable the request for an acknowledge response at the end of a frame */
  647. hdsi->Instance->VMCR &= ~DSI_VMCR_FBTAAE;
  648. hdsi->Instance->VMCR |= VidCfg->FrameBTAAcknowledgeEnable;
  649. /* Process unlocked */
  650. __HAL_UNLOCK(hdsi);
  651. return HAL_OK;
  652. }
  653. /**
  654. * @brief Select adapted command mode and configure the corresponding parameters
  655. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  656. * the configuration information for the DSI.
  657. * @param CmdCfg: pointer to a DSI_CmdCfgTypeDef structure that contains
  658. * the DSI command mode configuration parameters
  659. * @retval HAL status
  660. */
  661. HAL_StatusTypeDef HAL_DSI_ConfigAdaptedCommandMode(DSI_HandleTypeDef *hdsi, DSI_CmdCfgTypeDef *CmdCfg)
  662. {
  663. /* Process locked */
  664. __HAL_LOCK(hdsi);
  665. /* Check the parameters */
  666. assert_param(IS_DSI_COLOR_CODING(CmdCfg->ColorCoding));
  667. assert_param(IS_DSI_TE_SOURCE(CmdCfg->TearingEffectSource));
  668. assert_param(IS_DSI_TE_POLARITY(CmdCfg->TearingEffectPolarity));
  669. assert_param(IS_DSI_AUTOMATIC_REFRESH(CmdCfg->AutomaticRefresh));
  670. assert_param(IS_DSI_VS_POLARITY(CmdCfg->VSyncPol));
  671. assert_param(IS_DSI_TE_ACK_REQUEST(CmdCfg->TEAcknowledgeRequest));
  672. assert_param(IS_DSI_DE_POLARITY(CmdCfg->DEPolarity));
  673. assert_param(IS_DSI_VSYNC_POLARITY(CmdCfg->VSPolarity));
  674. assert_param(IS_DSI_HSYNC_POLARITY(CmdCfg->HSPolarity));
  675. /* Select command mode by setting CMDM and DSIM bits */
  676. hdsi->Instance->MCR |= DSI_MCR_CMDM;
  677. hdsi->Instance->WCFGR &= ~DSI_WCFGR_DSIM;
  678. hdsi->Instance->WCFGR |= DSI_WCFGR_DSIM;
  679. /* Select the virtual channel for the LTDC interface traffic */
  680. hdsi->Instance->LVCIDR &= ~DSI_LVCIDR_VCID;
  681. hdsi->Instance->LVCIDR |= CmdCfg->VirtualChannelID;
  682. /* Configure the polarity of control signals */
  683. hdsi->Instance->LPCR &= ~(DSI_LPCR_DEP | DSI_LPCR_VSP | DSI_LPCR_HSP);
  684. hdsi->Instance->LPCR |= (CmdCfg->DEPolarity | CmdCfg->VSPolarity | CmdCfg->HSPolarity);
  685. /* Select the color coding for the host */
  686. hdsi->Instance->LCOLCR &= ~DSI_LCOLCR_COLC;
  687. hdsi->Instance->LCOLCR |= CmdCfg->ColorCoding;
  688. /* Select the color coding for the wrapper */
  689. hdsi->Instance->WCFGR &= ~DSI_WCFGR_COLMUX;
  690. hdsi->Instance->WCFGR |= ((CmdCfg->ColorCoding)<<1U);
  691. /* Configure the maximum allowed size for write memory command */
  692. hdsi->Instance->LCCR &= ~DSI_LCCR_CMDSIZE;
  693. hdsi->Instance->LCCR |= CmdCfg->CommandSize;
  694. /* Configure the tearing effect source and polarity and select the refresh mode */
  695. hdsi->Instance->WCFGR &= ~(DSI_WCFGR_TESRC | DSI_WCFGR_TEPOL | DSI_WCFGR_AR | DSI_WCFGR_VSPOL);
  696. hdsi->Instance->WCFGR |= (CmdCfg->TearingEffectSource | CmdCfg->TearingEffectPolarity | CmdCfg->AutomaticRefresh | CmdCfg->VSyncPol);
  697. /* Configure the tearing effect acknowledge request */
  698. hdsi->Instance->CMCR &= ~DSI_CMCR_TEARE;
  699. hdsi->Instance->CMCR |= CmdCfg->TEAcknowledgeRequest;
  700. /* Enable the Tearing Effect interrupt */
  701. __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_TE);
  702. /* Enable the End of Refresh interrupt */
  703. __HAL_DSI_ENABLE_IT(hdsi, DSI_IT_ER);
  704. /* Process unlocked */
  705. __HAL_UNLOCK(hdsi);
  706. return HAL_OK;
  707. }
  708. /**
  709. * @brief Configure command transmission mode: High-speed or Low-power
  710. * and enable/disable acknowledge request after packet transmission
  711. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  712. * the configuration information for the DSI.
  713. * @param LPCmd: pointer to a DSI_LPCmdTypeDef structure that contains
  714. * the DSI command transmission mode configuration parameters
  715. * @retval HAL status
  716. */
  717. HAL_StatusTypeDef HAL_DSI_ConfigCommand(DSI_HandleTypeDef *hdsi, DSI_LPCmdTypeDef *LPCmd)
  718. {
  719. /* Process locked */
  720. __HAL_LOCK(hdsi);
  721. assert_param(IS_DSI_LP_GSW0P(LPCmd->LPGenShortWriteNoP));
  722. assert_param(IS_DSI_LP_GSW1P(LPCmd->LPGenShortWriteOneP));
  723. assert_param(IS_DSI_LP_GSW2P(LPCmd->LPGenShortWriteTwoP));
  724. assert_param(IS_DSI_LP_GSR0P(LPCmd->LPGenShortReadNoP));
  725. assert_param(IS_DSI_LP_GSR1P(LPCmd->LPGenShortReadOneP));
  726. assert_param(IS_DSI_LP_GSR2P(LPCmd->LPGenShortReadTwoP));
  727. assert_param(IS_DSI_LP_GLW(LPCmd->LPGenLongWrite));
  728. assert_param(IS_DSI_LP_DSW0P(LPCmd->LPDcsShortWriteNoP));
  729. assert_param(IS_DSI_LP_DSW1P(LPCmd->LPDcsShortWriteOneP));
  730. assert_param(IS_DSI_LP_DSR0P(LPCmd->LPDcsShortReadNoP));
  731. assert_param(IS_DSI_LP_DLW(LPCmd->LPDcsLongWrite));
  732. assert_param(IS_DSI_LP_MRDP(LPCmd->LPMaxReadPacket));
  733. assert_param(IS_DSI_ACK_REQUEST(LPCmd->AcknowledgeRequest));
  734. /* Select High-speed or Low-power for command transmission */
  735. hdsi->Instance->CMCR &= ~(DSI_CMCR_GSW0TX |\
  736. DSI_CMCR_GSW1TX |\
  737. DSI_CMCR_GSW2TX |\
  738. DSI_CMCR_GSR0TX |\
  739. DSI_CMCR_GSR1TX |\
  740. DSI_CMCR_GSR2TX |\
  741. DSI_CMCR_GLWTX |\
  742. DSI_CMCR_DSW0TX |\
  743. DSI_CMCR_DSW1TX |\
  744. DSI_CMCR_DSR0TX |\
  745. DSI_CMCR_DLWTX |\
  746. DSI_CMCR_MRDPS);
  747. hdsi->Instance->CMCR |= (LPCmd->LPGenShortWriteNoP |\
  748. LPCmd->LPGenShortWriteOneP |\
  749. LPCmd->LPGenShortWriteTwoP |\
  750. LPCmd->LPGenShortReadNoP |\
  751. LPCmd->LPGenShortReadOneP |\
  752. LPCmd->LPGenShortReadTwoP |\
  753. LPCmd->LPGenLongWrite |\
  754. LPCmd->LPDcsShortWriteNoP |\
  755. LPCmd->LPDcsShortWriteOneP |\
  756. LPCmd->LPDcsShortReadNoP |\
  757. LPCmd->LPDcsLongWrite |\
  758. LPCmd->LPMaxReadPacket);
  759. /* Configure the acknowledge request after each packet transmission */
  760. hdsi->Instance->CMCR &= ~DSI_CMCR_ARE;
  761. hdsi->Instance->CMCR |= LPCmd->AcknowledgeRequest;
  762. /* Process unlocked */
  763. __HAL_UNLOCK(hdsi);
  764. return HAL_OK;
  765. }
  766. /**
  767. * @brief Configure the flow control parameters
  768. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  769. * the configuration information for the DSI.
  770. * @param FlowControl: flow control feature(s) to be enabled.
  771. * This parameter can be any combination of @ref DSI_FlowControl.
  772. * @retval HAL status
  773. */
  774. HAL_StatusTypeDef HAL_DSI_ConfigFlowControl(DSI_HandleTypeDef *hdsi, uint32_t FlowControl)
  775. {
  776. /* Process locked */
  777. __HAL_LOCK(hdsi);
  778. /* Check the parameters */
  779. assert_param(IS_DSI_FLOW_CONTROL(FlowControl));
  780. /* Set the DSI Host Protocol Configuration Register */
  781. hdsi->Instance->PCR &= ~DSI_FLOW_CONTROL_ALL;
  782. hdsi->Instance->PCR |= FlowControl;
  783. /* Process unlocked */
  784. __HAL_UNLOCK(hdsi);
  785. return HAL_OK;
  786. }
  787. /**
  788. * @brief Configure the DSI PHY timer parameters
  789. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  790. * the configuration information for the DSI.
  791. * @param PhyTimers: DSI_PHY_TimerTypeDef structure that contains
  792. * the DSI PHY timing parameters
  793. * @retval HAL status
  794. */
  795. HAL_StatusTypeDef HAL_DSI_ConfigPhyTimer(DSI_HandleTypeDef *hdsi, DSI_PHY_TimerTypeDef *PhyTimers)
  796. {
  797. uint32_t maxTime;
  798. /* Process locked */
  799. __HAL_LOCK(hdsi);
  800. maxTime = (PhyTimers->ClockLaneLP2HSTime > PhyTimers->ClockLaneHS2LPTime)? PhyTimers->ClockLaneLP2HSTime: PhyTimers->ClockLaneHS2LPTime;
  801. /* Clock lane timer configuration */
  802. /* In Automatic Clock Lane control mode, the DSI Host can turn off the clock lane between two
  803. High-Speed transmission.
  804. To do so, the DSI Host calculates the time required for the clock lane to change from HighSpeed
  805. to Low-Power and from Low-Power to High-Speed.
  806. This timings are configured by the HS2LP_TIME and LP2HS_TIME in the DSI Host Clock Lane Timer Configuration Register (DSI_CLTCR).
  807. But the DSI Host is not calculating LP2HS_TIME + HS2LP_TIME but 2 x HS2LP_TIME.
  808. Workaround : Configure HS2LP_TIME and LP2HS_TIME with the same value being the max of HS2LP_TIME or LP2HS_TIME.
  809. */
  810. hdsi->Instance->CLTCR &= ~(DSI_CLTCR_LP2HS_TIME | DSI_CLTCR_HS2LP_TIME);
  811. hdsi->Instance->CLTCR |= (maxTime | ((maxTime)<<16U));
  812. /* Data lane timer configuration */
  813. hdsi->Instance->DLTCR &= ~(DSI_DLTCR_MRD_TIME | DSI_DLTCR_LP2HS_TIME | DSI_DLTCR_HS2LP_TIME);
  814. hdsi->Instance->DLTCR |= (PhyTimers->DataLaneMaxReadTime | ((PhyTimers->DataLaneLP2HSTime)<<16U) | ((PhyTimers->DataLaneHS2LPTime)<<24U));
  815. /* Configure the wait period to request HS transmission after a stop state */
  816. hdsi->Instance->PCONFR &= ~DSI_PCONFR_SW_TIME;
  817. hdsi->Instance->PCONFR |= ((PhyTimers->StopWaitTime)<<8U);
  818. /* Process unlocked */
  819. __HAL_UNLOCK(hdsi);
  820. return HAL_OK;
  821. }
  822. /**
  823. * @brief Configure the DSI HOST timeout parameters
  824. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  825. * the configuration information for the DSI.
  826. * @param HostTimeouts: DSI_HOST_TimeoutTypeDef structure that contains
  827. * the DSI host timeout parameters
  828. * @retval HAL status
  829. */
  830. HAL_StatusTypeDef HAL_DSI_ConfigHostTimeouts(DSI_HandleTypeDef *hdsi, DSI_HOST_TimeoutTypeDef *HostTimeouts)
  831. {
  832. /* Process locked */
  833. __HAL_LOCK(hdsi);
  834. /* Set the timeout clock division factor */
  835. hdsi->Instance->CCR &= ~DSI_CCR_TOCKDIV;
  836. hdsi->Instance->CCR |= ((HostTimeouts->TimeoutCkdiv)<<8U);
  837. /* High-speed transmission timeout */
  838. hdsi->Instance->TCCR[0U] &= ~DSI_TCCR0_HSTX_TOCNT;
  839. hdsi->Instance->TCCR[0U] |= ((HostTimeouts->HighSpeedTransmissionTimeout)<<16U);
  840. /* Low-power reception timeout */
  841. hdsi->Instance->TCCR[0U] &= ~DSI_TCCR0_LPRX_TOCNT;
  842. hdsi->Instance->TCCR[0U] |= HostTimeouts->LowPowerReceptionTimeout;
  843. /* High-speed read timeout */
  844. hdsi->Instance->TCCR[1U] &= ~DSI_TCCR1_HSRD_TOCNT;
  845. hdsi->Instance->TCCR[1U] |= HostTimeouts->HighSpeedReadTimeout;
  846. /* Low-power read timeout */
  847. hdsi->Instance->TCCR[2U] &= ~DSI_TCCR2_LPRD_TOCNT;
  848. hdsi->Instance->TCCR[2U] |= HostTimeouts->LowPowerReadTimeout;
  849. /* High-speed write timeout */
  850. hdsi->Instance->TCCR[3U] &= ~DSI_TCCR3_HSWR_TOCNT;
  851. hdsi->Instance->TCCR[3U] |= HostTimeouts->HighSpeedWriteTimeout;
  852. /* High-speed write presp mode */
  853. hdsi->Instance->TCCR[3U] &= ~DSI_TCCR3_PM;
  854. hdsi->Instance->TCCR[3U] |= HostTimeouts->HighSpeedWritePrespMode;
  855. /* Low-speed write timeout */
  856. hdsi->Instance->TCCR[4U] &= ~DSI_TCCR4_LPWR_TOCNT;
  857. hdsi->Instance->TCCR[4U] |= HostTimeouts->LowPowerWriteTimeout;
  858. /* BTA timeout */
  859. hdsi->Instance->TCCR[5U] &= ~DSI_TCCR5_BTA_TOCNT;
  860. hdsi->Instance->TCCR[5U] |= HostTimeouts->BTATimeout;
  861. /* Process unlocked */
  862. __HAL_UNLOCK(hdsi);
  863. return HAL_OK;
  864. }
  865. /**
  866. * @brief Start the DSI module
  867. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  868. * the configuration information for the DSI.
  869. * @retval HAL status
  870. */
  871. HAL_StatusTypeDef HAL_DSI_Start(DSI_HandleTypeDef *hdsi)
  872. {
  873. /* Process locked */
  874. __HAL_LOCK(hdsi);
  875. /* Enable the DSI host */
  876. __HAL_DSI_ENABLE(hdsi);
  877. /* Enable the DSI wrapper */
  878. __HAL_DSI_WRAPPER_ENABLE(hdsi);
  879. /* Process unlocked */
  880. __HAL_UNLOCK(hdsi);
  881. return HAL_OK;
  882. }
  883. /**
  884. * @brief Stop the DSI module
  885. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  886. * the configuration information for the DSI.
  887. * @retval HAL status
  888. */
  889. HAL_StatusTypeDef HAL_DSI_Stop(DSI_HandleTypeDef *hdsi)
  890. {
  891. /* Process locked */
  892. __HAL_LOCK(hdsi);
  893. /* Disable the DSI host */
  894. __HAL_DSI_DISABLE(hdsi);
  895. /* Disable the DSI wrapper */
  896. __HAL_DSI_WRAPPER_DISABLE(hdsi);
  897. /* Process unlocked */
  898. __HAL_UNLOCK(hdsi);
  899. return HAL_OK;
  900. }
  901. /**
  902. * @brief Refresh the display in command mode
  903. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  904. * the configuration information for the DSI.
  905. * @retval HAL status
  906. */
  907. HAL_StatusTypeDef HAL_DSI_Refresh(DSI_HandleTypeDef *hdsi)
  908. {
  909. /* Process locked */
  910. __HAL_LOCK(hdsi);
  911. /* Update the display */
  912. hdsi->Instance->WCR |= DSI_WCR_LTDCEN;
  913. /* Process unlocked */
  914. __HAL_UNLOCK(hdsi);
  915. return HAL_OK;
  916. }
  917. /**
  918. * @brief Controls the display color mode in Video mode
  919. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  920. * the configuration information for the DSI.
  921. * @param ColorMode: Color mode (full or 8-colors).
  922. * This parameter can be any value of @ref DSI_Color_Mode
  923. * @retval HAL status
  924. */
  925. HAL_StatusTypeDef HAL_DSI_ColorMode(DSI_HandleTypeDef *hdsi, uint32_t ColorMode)
  926. {
  927. /* Process locked */
  928. __HAL_LOCK(hdsi);
  929. /* Check the parameters */
  930. assert_param(IS_DSI_COLOR_MODE(ColorMode));
  931. /* Update the display color mode */
  932. hdsi->Instance->WCR &= ~DSI_WCR_COLM;
  933. hdsi->Instance->WCR |= ColorMode;
  934. /* Process unlocked */
  935. __HAL_UNLOCK(hdsi);
  936. return HAL_OK;
  937. }
  938. /**
  939. * @brief Control the display shutdown in Video mode
  940. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  941. * the configuration information for the DSI.
  942. * @param Shutdown: Shut-down (Display-ON or Display-OFF).
  943. * This parameter can be any value of @ref DSI_ShutDown
  944. * @retval HAL status
  945. */
  946. HAL_StatusTypeDef HAL_DSI_Shutdown(DSI_HandleTypeDef *hdsi, uint32_t Shutdown)
  947. {
  948. /* Process locked */
  949. __HAL_LOCK(hdsi);
  950. /* Check the parameters */
  951. assert_param(IS_DSI_SHUT_DOWN(Shutdown));
  952. /* Update the display Shutdown */
  953. hdsi->Instance->WCR &= ~DSI_WCR_SHTDN;
  954. hdsi->Instance->WCR |= Shutdown;
  955. /* Process unlocked */
  956. __HAL_UNLOCK(hdsi);
  957. return HAL_OK;
  958. }
  959. /**
  960. * @brief DCS or Generic short write command
  961. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  962. * the configuration information for the DSI.
  963. * @param ChannelID: Virtual channel ID.
  964. * @param Mode: DSI short packet data type.
  965. * This parameter can be any value of @ref DSI_SHORT_WRITE_PKT_Data_Type.
  966. * @param Param1: DSC command or first generic parameter.
  967. * This parameter can be any value of @ref DSI_DCS_Command or a
  968. * generic command code.
  969. * @param Param2: DSC parameter or second generic parameter.
  970. * @retval HAL status
  971. */
  972. HAL_StatusTypeDef HAL_DSI_ShortWrite(DSI_HandleTypeDef *hdsi,
  973. uint32_t ChannelID,
  974. uint32_t Mode,
  975. uint32_t Param1,
  976. uint32_t Param2)
  977. {
  978. uint32_t tickstart = 0U;
  979. /* Process locked */
  980. __HAL_LOCK(hdsi);
  981. /* Check the parameters */
  982. assert_param(IS_DSI_SHORT_WRITE_PACKET_TYPE(Mode));
  983. /* Get tick */
  984. tickstart = HAL_GetTick();
  985. /* Wait for Command FIFO Empty */
  986. while((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == 0U)
  987. {
  988. /* Check for the Timeout */
  989. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  990. {
  991. /* Process Unlocked */
  992. __HAL_UNLOCK(hdsi);
  993. return HAL_TIMEOUT;
  994. }
  995. }
  996. /* Configure the packet to send a short DCS command with 0 or 1 parameter */
  997. DSI_ConfigPacketHeader(hdsi->Instance,
  998. ChannelID,
  999. Mode,
  1000. Param1,
  1001. Param2);
  1002. /* Process unlocked */
  1003. __HAL_UNLOCK(hdsi);
  1004. return HAL_OK;
  1005. }
  1006. /**
  1007. * @brief DCS or Generic long write command
  1008. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1009. * the configuration information for the DSI.
  1010. * @param ChannelID: Virtual channel ID.
  1011. * @param Mode: DSI long packet data type.
  1012. * This parameter can be any value of @ref DSI_LONG_WRITE_PKT_Data_Type.
  1013. * @param NbParams: Number of parameters.
  1014. * @param Param1: DSC command or first generic parameter.
  1015. * This parameter can be any value of @ref DSI_DCS_Command or a
  1016. * generic command code
  1017. * @param ParametersTable: Pointer to parameter values table.
  1018. * @retval HAL status
  1019. */
  1020. HAL_StatusTypeDef HAL_DSI_LongWrite(DSI_HandleTypeDef *hdsi,
  1021. uint32_t ChannelID,
  1022. uint32_t Mode,
  1023. uint32_t NbParams,
  1024. uint32_t Param1,
  1025. uint8_t* ParametersTable)
  1026. {
  1027. uint32_t uicounter = 0U, nbBytes = 0U, count = 0U;
  1028. uint32_t tickstart = 0U;
  1029. uint32_t fifoword = 0U;
  1030. /* Process locked */
  1031. __HAL_LOCK(hdsi);
  1032. /* Check the parameters */
  1033. assert_param(IS_DSI_LONG_WRITE_PACKET_TYPE(Mode));
  1034. /* Get tick */
  1035. tickstart = HAL_GetTick();
  1036. /* Wait for Command FIFO Empty */
  1037. while((hdsi->Instance->GPSR & DSI_GPSR_CMDFE) == RESET)
  1038. {
  1039. /* Check for the Timeout */
  1040. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1041. {
  1042. /* Process Unlocked */
  1043. __HAL_UNLOCK(hdsi);
  1044. return HAL_TIMEOUT;
  1045. }
  1046. }
  1047. /* Set the DCS code on payload byte 1, and the other parameters on the write FIFO command*/
  1048. fifoword = Param1;
  1049. nbBytes = (NbParams < 3U) ? NbParams : 3U;
  1050. for(count = 0U; count < nbBytes; count++)
  1051. {
  1052. fifoword |= (((uint32_t)(*(ParametersTable + count))) << (8U + (8U*count)));
  1053. }
  1054. hdsi->Instance->GPDR = fifoword;
  1055. uicounter = NbParams - nbBytes;
  1056. ParametersTable += nbBytes;
  1057. /* Set the Next parameters on the write FIFO command*/
  1058. while(uicounter != 0U)
  1059. {
  1060. nbBytes = (uicounter < 4U) ? uicounter : 4U;
  1061. fifoword = 0U;
  1062. for(count = 0U; count < nbBytes; count++)
  1063. {
  1064. fifoword |= (((uint32_t)(*(ParametersTable + count))) << (8U*count));
  1065. }
  1066. hdsi->Instance->GPDR = fifoword;
  1067. uicounter -= nbBytes;
  1068. ParametersTable += nbBytes;
  1069. }
  1070. /* Configure the packet to send a long DCS command */
  1071. DSI_ConfigPacketHeader(hdsi->Instance,
  1072. ChannelID,
  1073. Mode,
  1074. ((NbParams+1U)&0x00FFU),
  1075. (((NbParams+1U)&0xFF00U)>>8U));
  1076. /* Process unlocked */
  1077. __HAL_UNLOCK(hdsi);
  1078. return HAL_OK;
  1079. }
  1080. /**
  1081. * @brief Read command (DCS or generic)
  1082. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1083. * the configuration information for the DSI.
  1084. * @param ChannelNbr: Virtual channel ID
  1085. * @param Array: pointer to a buffer to store the payload of a read back operation.
  1086. * @param Size: Data size to be read (in byte).
  1087. * @param Mode: DSI read packet data type.
  1088. * This parameter can be any value of @ref DSI_SHORT_READ_PKT_Data_Type.
  1089. * @param DCSCmd: DCS get/read command.
  1090. * @param ParametersTable: Pointer to parameter values table.
  1091. * @retval HAL status
  1092. */
  1093. HAL_StatusTypeDef HAL_DSI_Read(DSI_HandleTypeDef *hdsi,
  1094. uint32_t ChannelNbr,
  1095. uint8_t* Array,
  1096. uint32_t Size,
  1097. uint32_t Mode,
  1098. uint32_t DCSCmd,
  1099. uint8_t* ParametersTable)
  1100. {
  1101. uint32_t tickstart = 0U;
  1102. /* Process locked */
  1103. __HAL_LOCK(hdsi);
  1104. /* Check the parameters */
  1105. assert_param(IS_DSI_READ_PACKET_TYPE(Mode));
  1106. if(Size > 2U)
  1107. {
  1108. /* set max return packet size */
  1109. HAL_DSI_ShortWrite(hdsi, ChannelNbr, DSI_MAX_RETURN_PKT_SIZE, ((Size)&0xFFU), (((Size)>>8U)&0xFFU));
  1110. }
  1111. /* Configure the packet to read command */
  1112. if (Mode == DSI_DCS_SHORT_PKT_READ)
  1113. {
  1114. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, DCSCmd, 0U);
  1115. }
  1116. else if (Mode == DSI_GEN_SHORT_PKT_READ_P0)
  1117. {
  1118. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, 0U, 0U);
  1119. }
  1120. else if (Mode == DSI_GEN_SHORT_PKT_READ_P1)
  1121. {
  1122. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0U], 0U);
  1123. }
  1124. else if (Mode == DSI_GEN_SHORT_PKT_READ_P2)
  1125. {
  1126. DSI_ConfigPacketHeader(hdsi->Instance, ChannelNbr, Mode, ParametersTable[0U], ParametersTable[1U]);
  1127. }
  1128. else
  1129. {
  1130. /* Process Unlocked */
  1131. __HAL_UNLOCK(hdsi);
  1132. return HAL_ERROR;
  1133. }
  1134. /* Get tick */
  1135. tickstart = HAL_GetTick();
  1136. /* Check that the payload read FIFO is not empty */
  1137. while((hdsi->Instance->GPSR & DSI_GPSR_PRDFE) == DSI_GPSR_PRDFE)
  1138. {
  1139. /* Check for the Timeout */
  1140. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1141. {
  1142. /* Process Unlocked */
  1143. __HAL_UNLOCK(hdsi);
  1144. return HAL_TIMEOUT;
  1145. }
  1146. }
  1147. /* Get the first byte */
  1148. *((uint32_t *)Array) = (hdsi->Instance->GPDR);
  1149. if (Size > 4U)
  1150. {
  1151. Size -= 4U;
  1152. Array += 4U;
  1153. }
  1154. else
  1155. {
  1156. /* Process unlocked */
  1157. __HAL_UNLOCK(hdsi);
  1158. return HAL_OK;
  1159. }
  1160. /* Get tick */
  1161. tickstart = HAL_GetTick();
  1162. /* Get the remaining bytes if any */
  1163. while(((int)(Size)) > 0U)
  1164. {
  1165. if((hdsi->Instance->GPSR & DSI_GPSR_PRDFE) == 0U)
  1166. {
  1167. *((uint32_t *)Array) = (hdsi->Instance->GPDR);
  1168. Size -= 4U;
  1169. Array += 4U;
  1170. }
  1171. /* Check for the Timeout */
  1172. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1173. {
  1174. /* Process Unlocked */
  1175. __HAL_UNLOCK(hdsi);
  1176. return HAL_TIMEOUT;
  1177. }
  1178. }
  1179. /* Process unlocked */
  1180. __HAL_UNLOCK(hdsi);
  1181. return HAL_OK;
  1182. }
  1183. /**
  1184. * @brief Enter the ULPM (Ultra Low Power Mode) with the D-PHY PLL running
  1185. * (only data lanes are in ULPM)
  1186. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1187. * the configuration information for the DSI.
  1188. * @retval HAL status
  1189. */
  1190. HAL_StatusTypeDef HAL_DSI_EnterULPMData(DSI_HandleTypeDef *hdsi)
  1191. {
  1192. uint32_t tickstart = 0U;
  1193. /* Process locked */
  1194. __HAL_LOCK(hdsi);
  1195. /* ULPS Request on Data Lanes */
  1196. hdsi->Instance->PUCR |= DSI_PUCR_URDL;
  1197. /* Get tick */
  1198. tickstart = HAL_GetTick();
  1199. /* Wait until the D-PHY active lanes enter into ULPM */
  1200. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1201. {
  1202. while((hdsi->Instance->PSR & DSI_PSR_UAN0) != RESET)
  1203. {
  1204. /* Check for the Timeout */
  1205. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1206. {
  1207. /* Process Unlocked */
  1208. __HAL_UNLOCK(hdsi);
  1209. return HAL_TIMEOUT;
  1210. }
  1211. }
  1212. }
  1213. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1214. {
  1215. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1)) != RESET)
  1216. {
  1217. /* Check for the Timeout */
  1218. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1219. {
  1220. /* Process Unlocked */
  1221. __HAL_UNLOCK(hdsi);
  1222. return HAL_TIMEOUT;
  1223. }
  1224. }
  1225. }
  1226. /* Process unlocked */
  1227. __HAL_UNLOCK(hdsi);
  1228. return HAL_OK;
  1229. }
  1230. /**
  1231. * @brief Exit the ULPM (Ultra Low Power Mode) with the D-PHY PLL running
  1232. * (only data lanes are in ULPM)
  1233. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1234. * the configuration information for the DSI.
  1235. * @retval HAL status
  1236. */
  1237. HAL_StatusTypeDef HAL_DSI_ExitULPMData(DSI_HandleTypeDef *hdsi)
  1238. {
  1239. uint32_t tickstart = 0U;
  1240. /* Process locked */
  1241. __HAL_LOCK(hdsi);
  1242. /* Exit ULPS on Data Lanes */
  1243. hdsi->Instance->PUCR |= DSI_PUCR_UEDL;
  1244. /* Get tick */
  1245. tickstart = HAL_GetTick();
  1246. /* Wait until all active lanes exit ULPM */
  1247. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1248. {
  1249. while((hdsi->Instance->PSR & DSI_PSR_UAN0) != DSI_PSR_UAN0)
  1250. {
  1251. /* Check for the Timeout */
  1252. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1253. {
  1254. /* Process Unlocked */
  1255. __HAL_UNLOCK(hdsi);
  1256. return HAL_TIMEOUT;
  1257. }
  1258. }
  1259. }
  1260. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1261. {
  1262. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1)) != (DSI_PSR_UAN0 | DSI_PSR_UAN1))
  1263. {
  1264. /* Check for the Timeout */
  1265. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1266. {
  1267. /* Process Unlocked */
  1268. __HAL_UNLOCK(hdsi);
  1269. return HAL_TIMEOUT;
  1270. }
  1271. }
  1272. }
  1273. /* wait for 1 ms*/
  1274. HAL_Delay(1U);
  1275. /* De-assert the ULPM requests and the ULPM exit bits */
  1276. hdsi->Instance->PUCR = 0U;
  1277. /* Process unlocked */
  1278. __HAL_UNLOCK(hdsi);
  1279. return HAL_OK;
  1280. }
  1281. /**
  1282. * @brief Enter the ULPM (Ultra Low Power Mode) with the D-PHY PLL turned off
  1283. * (both data and clock lanes are in ULPM)
  1284. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1285. * the configuration information for the DSI.
  1286. * @retval HAL status
  1287. */
  1288. HAL_StatusTypeDef HAL_DSI_EnterULPM(DSI_HandleTypeDef *hdsi)
  1289. {
  1290. uint32_t tickstart = 0U;
  1291. /* Process locked */
  1292. __HAL_LOCK(hdsi);
  1293. /* Clock lane configuration: no more HS request */
  1294. hdsi->Instance->CLCR &= ~DSI_CLCR_DPCC;
  1295. /* Use system PLL as byte lane clock source before stopping DSIPHY clock source */
  1296. __HAL_RCC_DSI_CONFIG(RCC_DSICLKSOURCE_PLLR);
  1297. /* ULPS Request on Clock and Data Lanes */
  1298. hdsi->Instance->PUCR |= (DSI_PUCR_URCL | DSI_PUCR_URDL);
  1299. /* Get tick */
  1300. tickstart = HAL_GetTick();
  1301. /* Wait until all active lanes exit ULPM */
  1302. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1303. {
  1304. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UANC)) != RESET)
  1305. {
  1306. /* Check for the Timeout */
  1307. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1308. {
  1309. /* Process Unlocked */
  1310. __HAL_UNLOCK(hdsi);
  1311. return HAL_TIMEOUT;
  1312. }
  1313. }
  1314. }
  1315. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1316. {
  1317. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC)) != RESET)
  1318. {
  1319. /* Check for the Timeout */
  1320. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1321. {
  1322. /* Process Unlocked */
  1323. __HAL_UNLOCK(hdsi);
  1324. return HAL_TIMEOUT;
  1325. }
  1326. }
  1327. }
  1328. /* Turn off the DSI PLL */
  1329. __HAL_DSI_PLL_DISABLE(hdsi);
  1330. /* Process unlocked */
  1331. __HAL_UNLOCK(hdsi);
  1332. return HAL_OK;
  1333. }
  1334. /**
  1335. * @brief Exit the ULPM (Ultra Low Power Mode) with the D-PHY PLL turned off
  1336. * (both data and clock lanes are in ULPM)
  1337. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1338. * the configuration information for the DSI.
  1339. * @retval HAL status
  1340. */
  1341. HAL_StatusTypeDef HAL_DSI_ExitULPM(DSI_HandleTypeDef *hdsi)
  1342. {
  1343. uint32_t tickstart = 0U;
  1344. /* Process locked */
  1345. __HAL_LOCK(hdsi);
  1346. /* Turn on the DSI PLL */
  1347. __HAL_DSI_PLL_ENABLE(hdsi);
  1348. /* Get tick */
  1349. tickstart = HAL_GetTick();
  1350. /* Wait for the lock of the PLL */
  1351. while(__HAL_DSI_GET_FLAG(hdsi, DSI_FLAG_PLLLS) == RESET)
  1352. {
  1353. /* Check for the Timeout */
  1354. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1355. {
  1356. /* Process Unlocked */
  1357. __HAL_UNLOCK(hdsi);
  1358. return HAL_TIMEOUT;
  1359. }
  1360. }
  1361. /* Exit ULPS on Clock and Data Lanes */
  1362. hdsi->Instance->PUCR |= (DSI_PUCR_UECL | DSI_PUCR_UEDL);
  1363. /* Get tick */
  1364. tickstart = HAL_GetTick();
  1365. /* Wait until all active lanes exit ULPM */
  1366. if((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_ONE_DATA_LANE)
  1367. {
  1368. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UANC)) != (DSI_PSR_UAN0 | DSI_PSR_UANC))
  1369. {
  1370. /* Check for the Timeout */
  1371. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1372. {
  1373. /* Process Unlocked */
  1374. __HAL_UNLOCK(hdsi);
  1375. return HAL_TIMEOUT;
  1376. }
  1377. }
  1378. }
  1379. else if ((hdsi->Instance->PCONFR & DSI_PCONFR_NL) == DSI_TWO_DATA_LANES)
  1380. {
  1381. while((hdsi->Instance->PSR & (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC)) != (DSI_PSR_UAN0 | DSI_PSR_UAN1 | DSI_PSR_UANC))
  1382. {
  1383. /* Check for the Timeout */
  1384. if((HAL_GetTick() - tickstart ) > DSI_TIMEOUT_VALUE)
  1385. {
  1386. /* Process Unlocked */
  1387. __HAL_UNLOCK(hdsi);
  1388. return HAL_TIMEOUT;
  1389. }
  1390. }
  1391. }
  1392. /* wait for 1 ms*/
  1393. HAL_Delay(1U);
  1394. /* De-assert the ULPM requests and the ULPM exit bits */
  1395. hdsi->Instance->PUCR = 0U;
  1396. /* Switch the lanbyteclock source in the RCC from system PLL to D-PHY */
  1397. __HAL_RCC_DSI_CONFIG(RCC_DSICLKSOURCE_DSIPHY);
  1398. /* Restore clock lane configuration to HS */
  1399. hdsi->Instance->CLCR |= DSI_CLCR_DPCC;
  1400. /* Process unlocked */
  1401. __HAL_UNLOCK(hdsi);
  1402. return HAL_OK;
  1403. }
  1404. /**
  1405. * @brief Start test pattern generation
  1406. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1407. * the configuration information for the DSI.
  1408. * @param Mode: Pattern generator mode
  1409. * This parameter can be one of the following values:
  1410. * 0 : Color bars (horizontal or vertical)
  1411. * 1 : BER pattern (vertical only)
  1412. * @param Orientation: Pattern generator orientation
  1413. * This parameter can be one of the following values:
  1414. * 0 : Vertical color bars
  1415. * 1 : Horizontal color bars
  1416. * @retval HAL status
  1417. */
  1418. HAL_StatusTypeDef HAL_DSI_PatternGeneratorStart(DSI_HandleTypeDef *hdsi, uint32_t Mode, uint32_t Orientation)
  1419. {
  1420. /* Process locked */
  1421. __HAL_LOCK(hdsi);
  1422. /* Configure pattern generator mode and orientation */
  1423. hdsi->Instance->VMCR &= ~(DSI_VMCR_PGM | DSI_VMCR_PGO);
  1424. hdsi->Instance->VMCR |= ((Mode<<20U) | (Orientation<<24U));
  1425. /* Enable pattern generator by setting PGE bit */
  1426. hdsi->Instance->VMCR |= DSI_VMCR_PGE;
  1427. /* Process unlocked */
  1428. __HAL_UNLOCK(hdsi);
  1429. return HAL_OK;
  1430. }
  1431. /**
  1432. * @brief Stop test pattern generation
  1433. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1434. * the configuration information for the DSI.
  1435. * @retval HAL status
  1436. */
  1437. HAL_StatusTypeDef HAL_DSI_PatternGeneratorStop(DSI_HandleTypeDef *hdsi)
  1438. {
  1439. /* Process locked */
  1440. __HAL_LOCK(hdsi);
  1441. /* Disable pattern generator by clearing PGE bit */
  1442. hdsi->Instance->VMCR &= ~DSI_VMCR_PGE;
  1443. /* Process unlocked */
  1444. __HAL_UNLOCK(hdsi);
  1445. return HAL_OK;
  1446. }
  1447. /**
  1448. * @brief Set Slew-Rate And Delay Tuning
  1449. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1450. * the configuration information for the DSI.
  1451. * @param CommDelay: Communication delay to be adjusted.
  1452. * This parameter can be any value of @ref DSI_Communication_Delay
  1453. * @param Lane: select between clock or data lanes.
  1454. * This parameter can be any value of @ref DSI_Lane_Group
  1455. * @param Value: Custom value of the slew-rate or delay
  1456. * @retval HAL status
  1457. */
  1458. HAL_StatusTypeDef HAL_DSI_SetSlewRateAndDelayTuning(DSI_HandleTypeDef *hdsi, uint32_t CommDelay, uint32_t Lane, uint32_t Value)
  1459. {
  1460. /* Process locked */
  1461. __HAL_LOCK(hdsi);
  1462. /* Check function parameters */
  1463. assert_param(IS_DSI_COMMUNICATION_DELAY(CommDelay));
  1464. assert_param(IS_DSI_LANE_GROUP(Lane));
  1465. switch(CommDelay)
  1466. {
  1467. case DSI_SLEW_RATE_HSTX:
  1468. if(Lane == DSI_CLOCK_LANE)
  1469. {
  1470. /* High-Speed Transmission Slew Rate Control on Clock Lane */
  1471. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXSRCCL;
  1472. hdsi->Instance->WPCR[1U] |= Value<<16U;
  1473. }
  1474. else if(Lane == DSI_DATA_LANES)
  1475. {
  1476. /* High-Speed Transmission Slew Rate Control on Data Lanes */
  1477. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXSRCDL;
  1478. hdsi->Instance->WPCR[1U] |= Value<<18U;
  1479. }
  1480. break;
  1481. case DSI_SLEW_RATE_LPTX:
  1482. if(Lane == DSI_CLOCK_LANE)
  1483. {
  1484. /* Low-Power transmission Slew Rate Compensation on Clock Lane */
  1485. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPSRCCL;
  1486. hdsi->Instance->WPCR[1U] |= Value<<6U;
  1487. }
  1488. else if(Lane == DSI_DATA_LANES)
  1489. {
  1490. /* Low-Power transmission Slew Rate Compensation on Data Lanes */
  1491. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPSRCDL;
  1492. hdsi->Instance->WPCR[1U] |= Value<<8U;
  1493. }
  1494. break;
  1495. case DSI_HS_DELAY:
  1496. if(Lane == DSI_CLOCK_LANE)
  1497. {
  1498. /* High-Speed Transmission Delay on Clock Lane */
  1499. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXDCL;
  1500. hdsi->Instance->WPCR[1U] |= Value;
  1501. }
  1502. else if(Lane == DSI_DATA_LANES)
  1503. {
  1504. /* High-Speed Transmission Delay on Data Lanes */
  1505. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_HSTXDDL;
  1506. hdsi->Instance->WPCR[1U] |= Value<<2U;
  1507. }
  1508. break;
  1509. default:
  1510. break;
  1511. }
  1512. /* Process unlocked */
  1513. __HAL_UNLOCK(hdsi);
  1514. return HAL_OK;
  1515. }
  1516. /**
  1517. * @brief Low-Power Reception Filter Tuning
  1518. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1519. * the configuration information for the DSI.
  1520. * @param Frequency: cutoff frequency of low-pass filter at the input of LPRX
  1521. * @retval HAL status
  1522. */
  1523. HAL_StatusTypeDef HAL_DSI_SetLowPowerRXFilter(DSI_HandleTypeDef *hdsi, uint32_t Frequency)
  1524. {
  1525. /* Process locked */
  1526. __HAL_LOCK(hdsi);
  1527. /* Low-Power RX low-pass Filtering Tuning */
  1528. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_LPRXFT;
  1529. hdsi->Instance->WPCR[1U] |= Frequency<<25U;
  1530. /* Process unlocked */
  1531. __HAL_UNLOCK(hdsi);
  1532. return HAL_OK;
  1533. }
  1534. /**
  1535. * @brief Activate an additional current path on all lanes to meet the SDDTx parameter
  1536. * defined in the MIPI D-PHY specification
  1537. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1538. * the configuration information for the DSI.
  1539. * @param State: ENABLE or DISABLE
  1540. * @retval HAL status
  1541. */
  1542. HAL_StatusTypeDef HAL_DSI_SetSDD(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1543. {
  1544. /* Process locked */
  1545. __HAL_LOCK(hdsi);
  1546. /* Check function parameters */
  1547. assert_param(IS_FUNCTIONAL_STATE(State));
  1548. /* Activate/Disactivate additional current path on all lanes */
  1549. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_SDDC;
  1550. hdsi->Instance->WPCR[1U] |= ((uint32_t)State << 12U);
  1551. /* Process unlocked */
  1552. __HAL_UNLOCK(hdsi);
  1553. return HAL_OK;
  1554. }
  1555. /**
  1556. * @brief Custom lane pins configuration
  1557. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1558. * the configuration information for the DSI.
  1559. * @param CustomLane: Function to be applyed on selected lane.
  1560. * This parameter can be any value of @ref DSI_CustomLane
  1561. * @param Lane: select between clock or data lane 0 or data lane 1.
  1562. * This parameter can be any value of @ref DSI_Lane_Select
  1563. * @param State: ENABLE or DISABLE
  1564. * @retval HAL status
  1565. */
  1566. HAL_StatusTypeDef HAL_DSI_SetLanePinsConfiguration(DSI_HandleTypeDef *hdsi, uint32_t CustomLane, uint32_t Lane, FunctionalState State)
  1567. {
  1568. /* Process locked */
  1569. __HAL_LOCK(hdsi);
  1570. /* Check function parameters */
  1571. assert_param(IS_DSI_CUSTOM_LANE(CustomLane));
  1572. assert_param(IS_DSI_LANE(Lane));
  1573. assert_param(IS_FUNCTIONAL_STATE(State));
  1574. switch(CustomLane)
  1575. {
  1576. case DSI_SWAP_LANE_PINS:
  1577. if(Lane == DSI_CLOCK_LANE)
  1578. {
  1579. /* Swap pins on clock lane */
  1580. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWCL;
  1581. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 6U);
  1582. }
  1583. else if(Lane == DSI_DATA_LANE0)
  1584. {
  1585. /* Swap pins on data lane 0 */
  1586. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWDL0;
  1587. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 7U);
  1588. }
  1589. else if(Lane == DSI_DATA_LANE1)
  1590. {
  1591. /* Swap pins on data lane 1 */
  1592. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_SWDL1;
  1593. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 8U);
  1594. }
  1595. break;
  1596. case DSI_INVERT_HS_SIGNAL:
  1597. if(Lane == DSI_CLOCK_LANE)
  1598. {
  1599. /* Invert HS signal on clock lane */
  1600. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSICL;
  1601. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 9U);
  1602. }
  1603. else if(Lane == DSI_DATA_LANE0)
  1604. {
  1605. /* Invert HS signal on data lane 0 */
  1606. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSIDL0;
  1607. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 10U);
  1608. }
  1609. else if(Lane == DSI_DATA_LANE1)
  1610. {
  1611. /* Invert HS signal on data lane 1 */
  1612. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_HSIDL1;
  1613. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 11U);
  1614. }
  1615. break;
  1616. default:
  1617. break;
  1618. }
  1619. /* Process unlocked */
  1620. __HAL_UNLOCK(hdsi);
  1621. return HAL_OK;
  1622. }
  1623. /**
  1624. * @brief Set custom timing for the PHY
  1625. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1626. * the configuration information for the DSI.
  1627. * @param Timing: PHY timing to be adjusted.
  1628. * This parameter can be any value of @ref DSI_PHY_Timing
  1629. * @param State: ENABLE or DISABLE
  1630. * @param Value: Custom value of the timing
  1631. * @retval HAL status
  1632. */
  1633. HAL_StatusTypeDef HAL_DSI_SetPHYTimings(DSI_HandleTypeDef *hdsi, uint32_t Timing, FunctionalState State, uint32_t Value)
  1634. {
  1635. /* Process locked */
  1636. __HAL_LOCK(hdsi);
  1637. /* Check function parameters */
  1638. assert_param(IS_DSI_PHY_TIMING(Timing));
  1639. assert_param(IS_FUNCTIONAL_STATE(State));
  1640. switch(Timing)
  1641. {
  1642. case DSI_TCLK_POST:
  1643. /* Enable/Disable custom timing setting */
  1644. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKPOSTEN;
  1645. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 27U);
  1646. if(State)
  1647. {
  1648. /* Set custom value */
  1649. hdsi->Instance->WPCR[4U] &= ~DSI_WPCR4_TCLKPOST;
  1650. hdsi->Instance->WPCR[4U] |= Value & DSI_WPCR4_TCLKPOST;
  1651. }
  1652. break;
  1653. case DSI_TLPX_CLK:
  1654. /* Enable/Disable custom timing setting */
  1655. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TLPXCEN;
  1656. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 26U);
  1657. if(State)
  1658. {
  1659. /* Set custom value */
  1660. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_TLPXC;
  1661. hdsi->Instance->WPCR[3U] |= (Value << 24U) & DSI_WPCR3_TLPXC;
  1662. }
  1663. break;
  1664. case DSI_THS_EXIT:
  1665. /* Enable/Disable custom timing setting */
  1666. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSEXITEN;
  1667. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 25U);
  1668. if(State)
  1669. {
  1670. /* Set custom value */
  1671. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_THSEXIT;
  1672. hdsi->Instance->WPCR[3U] |= (Value << 16U) & DSI_WPCR3_THSEXIT;
  1673. }
  1674. break;
  1675. case DSI_TLPX_DATA:
  1676. /* Enable/Disable custom timing setting */
  1677. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TLPXDEN;
  1678. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 24U);
  1679. if(State)
  1680. {
  1681. /* Set custom value */
  1682. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_TLPXD;
  1683. hdsi->Instance->WPCR[3U] |= (Value << 8U) & DSI_WPCR3_TLPXD;
  1684. }
  1685. break;
  1686. case DSI_THS_ZERO:
  1687. /* Enable/Disable custom timing setting */
  1688. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSZEROEN;
  1689. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 23U);
  1690. if(State)
  1691. {
  1692. /* Set custom value */
  1693. hdsi->Instance->WPCR[3U] &= ~DSI_WPCR3_THSZERO;
  1694. hdsi->Instance->WPCR[3U] |= Value & DSI_WPCR3_THSZERO;
  1695. }
  1696. break;
  1697. case DSI_THS_TRAIL:
  1698. /* Enable/Disable custom timing setting */
  1699. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSTRAILEN;
  1700. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 22U);
  1701. if(State)
  1702. {
  1703. /* Set custom value */
  1704. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_THSTRAIL;
  1705. hdsi->Instance->WPCR[2U] |= (Value << 24U) & DSI_WPCR2_THSTRAIL;
  1706. }
  1707. break;
  1708. case DSI_THS_PREPARE:
  1709. /* Enable/Disable custom timing setting */
  1710. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_THSPREPEN;
  1711. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 21U);
  1712. if(State)
  1713. {
  1714. /* Set custom value */
  1715. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_THSPREP;
  1716. hdsi->Instance->WPCR[2U] |= (Value << 16U) & DSI_WPCR2_THSPREP;
  1717. }
  1718. break;
  1719. case DSI_TCLK_ZERO:
  1720. /* Enable/Disable custom timing setting */
  1721. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKZEROEN;
  1722. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 20U);
  1723. if(State)
  1724. {
  1725. /* Set custom value */
  1726. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_TCLKZERO;
  1727. hdsi->Instance->WPCR[2U] |= (Value << 8U) & DSI_WPCR2_TCLKZERO;
  1728. }
  1729. break;
  1730. case DSI_TCLK_PREPARE:
  1731. /* Enable/Disable custom timing setting */
  1732. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TCLKPREPEN;
  1733. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 19U);
  1734. if(State)
  1735. {
  1736. /* Set custom value */
  1737. hdsi->Instance->WPCR[2U] &= ~DSI_WPCR2_TCLKPREP;
  1738. hdsi->Instance->WPCR[2U] |= Value & DSI_WPCR2_TCLKPREP;
  1739. }
  1740. break;
  1741. default:
  1742. break;
  1743. }
  1744. /* Process unlocked */
  1745. __HAL_UNLOCK(hdsi);
  1746. return HAL_OK;
  1747. }
  1748. /**
  1749. * @brief Force the Clock/Data Lane in TX Stop Mode
  1750. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1751. * the configuration information for the DSI.
  1752. * @param Lane: select between clock or data lanes.
  1753. * This parameter can be any value of @ref DSI_Lane_Group
  1754. * @param State: ENABLE or DISABLE
  1755. * @retval HAL status
  1756. */
  1757. HAL_StatusTypeDef HAL_DSI_ForceTXStopMode(DSI_HandleTypeDef *hdsi, uint32_t Lane, FunctionalState State)
  1758. {
  1759. /* Process locked */
  1760. __HAL_LOCK(hdsi);
  1761. /* Check function parameters */
  1762. assert_param(IS_DSI_LANE_GROUP(Lane));
  1763. assert_param(IS_FUNCTIONAL_STATE(State));
  1764. if(Lane == DSI_CLOCK_LANE)
  1765. {
  1766. /* Force/Unforce the Clock Lane in TX Stop Mode */
  1767. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_FTXSMCL;
  1768. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 12U);
  1769. }
  1770. else if(Lane == DSI_DATA_LANES)
  1771. {
  1772. /* Force/Unforce the Data Lanes in TX Stop Mode */
  1773. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_FTXSMDL;
  1774. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 13U);
  1775. }
  1776. /* Process unlocked */
  1777. __HAL_UNLOCK(hdsi);
  1778. return HAL_OK;
  1779. }
  1780. /**
  1781. * @brief Forces LP Receiver in Low-Power Mode
  1782. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1783. * the configuration information for the DSI.
  1784. * @param State: ENABLE or DISABLE
  1785. * @retval HAL status
  1786. */
  1787. HAL_StatusTypeDef HAL_DSI_ForceRXLowPower(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1788. {
  1789. /* Process locked */
  1790. __HAL_LOCK(hdsi);
  1791. /* Check function parameters */
  1792. assert_param(IS_FUNCTIONAL_STATE(State));
  1793. /* Force/Unforce LP Receiver in Low-Power Mode */
  1794. hdsi->Instance->WPCR[1U] &= ~DSI_WPCR1_FLPRXLPM;
  1795. hdsi->Instance->WPCR[1U] |= ((uint32_t)State << 22U);
  1796. /* Process unlocked */
  1797. __HAL_UNLOCK(hdsi);
  1798. return HAL_OK;
  1799. }
  1800. /**
  1801. * @brief Force Data Lanes in RX Mode after a BTA
  1802. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1803. * the configuration information for the DSI.
  1804. * @param State: ENABLE or DISABLE
  1805. * @retval HAL status
  1806. */
  1807. HAL_StatusTypeDef HAL_DSI_ForceDataLanesInRX(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1808. {
  1809. /* Process locked */
  1810. __HAL_LOCK(hdsi);
  1811. /* Check function parameters */
  1812. assert_param(IS_FUNCTIONAL_STATE(State));
  1813. /* Force Data Lanes in RX Mode */
  1814. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_TDDL;
  1815. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 16U);
  1816. /* Process unlocked */
  1817. __HAL_UNLOCK(hdsi);
  1818. return HAL_OK;
  1819. }
  1820. /**
  1821. * @brief Enable a pull-down on the lanes to prevent from floating states when unused
  1822. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1823. * the configuration information for the DSI.
  1824. * @param State: ENABLE or DISABLE
  1825. * @retval HAL status
  1826. */
  1827. HAL_StatusTypeDef HAL_DSI_SetPullDown(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1828. {
  1829. /* Process locked */
  1830. __HAL_LOCK(hdsi);
  1831. /* Check function parameters */
  1832. assert_param(IS_FUNCTIONAL_STATE(State));
  1833. /* Enable/Disable pull-down on lanes */
  1834. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_PDEN;
  1835. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 18U);
  1836. /* Process unlocked */
  1837. __HAL_UNLOCK(hdsi);
  1838. return HAL_OK;
  1839. }
  1840. /**
  1841. * @brief Switch off the contention detection on data lanes
  1842. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1843. * the configuration information for the DSI.
  1844. * @param State: ENABLE or DISABLE
  1845. * @retval HAL status
  1846. */
  1847. HAL_StatusTypeDef HAL_DSI_SetContentionDetectionOff(DSI_HandleTypeDef *hdsi, FunctionalState State)
  1848. {
  1849. /* Process locked */
  1850. __HAL_LOCK(hdsi);
  1851. /* Check function parameters */
  1852. assert_param(IS_FUNCTIONAL_STATE(State));
  1853. /* Contention Detection on Data Lanes OFF */
  1854. hdsi->Instance->WPCR[0U] &= ~DSI_WPCR0_CDOFFDL;
  1855. hdsi->Instance->WPCR[0U] |= ((uint32_t)State << 14U);
  1856. /* Process unlocked */
  1857. __HAL_UNLOCK(hdsi);
  1858. return HAL_OK;
  1859. }
  1860. /**
  1861. * @}
  1862. */
  1863. /** @defgroup DSI_Group4 Peripheral State and Errors functions
  1864. * @brief Peripheral State and Errors functions
  1865. *
  1866. @verbatim
  1867. ===============================================================================
  1868. ##### Peripheral State and Errors functions #####
  1869. ===============================================================================
  1870. [..]
  1871. This subsection provides functions allowing to
  1872. (+) Check the DSI state.
  1873. (+) Get error code.
  1874. @endverbatim
  1875. * @{
  1876. */
  1877. /**
  1878. * @brief Return the DSI state
  1879. * @param hdsi: pointer to a DSI_HandleTypeDef structure that contains
  1880. * the configuration information for the DSI.
  1881. * @retval HAL state
  1882. */
  1883. HAL_DSI_StateTypeDef HAL_DSI_GetState(DSI_HandleTypeDef *hdsi)
  1884. {
  1885. return hdsi->State;
  1886. }
  1887. /**
  1888. * @}
  1889. */
  1890. /**
  1891. * @}
  1892. */
  1893. #endif /* STM32F469xx || STM32F479xx */
  1894. #endif /* HAL_DSI_MODULE_ENABLED */
  1895. /**
  1896. * @}
  1897. */
  1898. /**
  1899. * @}
  1900. */
  1901. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/