stm32l4xx_hal_lcd.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_lcd.c
  4. * @author MCD Application Team
  5. * @brief LCD Controller HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the LCD Controller (LCD) peripheral:
  8. * + Initialization/de-initialization methods
  9. * + I/O operation methods
  10. * + Peripheral State methods
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### How to use this driver #####
  15. ==============================================================================
  16. [..] The LCD HAL driver can be used as follows:
  17. (#) Declare a LCD_HandleTypeDef handle structure.
  18. -@- The frequency generator allows you to achieve various LCD frame rates
  19. starting from an LCD input clock frequency (LCDCLK) which can vary
  20. from 32 kHz up to 1 MHz.
  21. (#) Initialize the LCD low level resources by implementing the HAL_LCD_MspInit() API:
  22. (++) Enable the LCDCLK (same as RTCCLK): to configure the RTCCLK/LCDCLK, proceed as follows:
  23. (+++) Use RCC function HAL_RCCEx_PeriphCLKConfig in indicating RCC_PERIPHCLK_LCD and
  24. selected clock source (HSE, LSI or LSE)
  25. (++) LCD pins configuration:
  26. (+++) Enable the clock for the LCD GPIOs.
  27. (+++) Configure these LCD pins as alternate function no-pull.
  28. (++) Enable the LCD interface clock.
  29. (#) Program the Prescaler, Divider, Blink mode, Blink Frequency Duty, Bias,
  30. Voltage Source, Dead Time, Pulse On Duration, Contrast, High drive and Multiplexer
  31. Segment in the Init structure of the LCD handle.
  32. (#) Initialize the LCD registers by calling the HAL_LCD_Init() API.
  33. -@- The HAL_LCD_Init() API configures also the low level Hardware GPIO, CLOCK, ...etc)
  34. by calling the customized HAL_LCD_MspInit() API.
  35. -@- After calling the HAL_LCD_Init() the LCD RAM memory is cleared
  36. (#) Optionally you can update the LCD configuration using these macros:
  37. (++) LCD High Drive using the __HAL_LCD_HIGHDRIVER_ENABLE() and __HAL_LCD_HIGHDRIVER_DISABLE() macros
  38. (++) Voltage output buffer using __HAL_LCD_VOLTAGE_BUFFER_ENABLE() and __HAL_LCD_VOLTAGE_BUFFER_DISABLE() macros
  39. (++) LCD Pulse ON Duration using the __HAL_LCD_PULSEONDURATION_CONFIG() macro
  40. (++) LCD Dead Time using the __HAL_LCD_DEADTIME_CONFIG() macro
  41. (++) The LCD Blink mode and frequency using the __HAL_LCD_BLINK_CONFIG() macro
  42. (++) The LCD Contrast using the __HAL_LCD_CONTRAST_CONFIG() macro
  43. (#) Write to the LCD RAM memory using the HAL_LCD_Write() API, this API can be called
  44. more time to update the different LCD RAM registers before calling
  45. HAL_LCD_UpdateDisplayRequest() API.
  46. (#) The HAL_LCD_Clear() API can be used to clear the LCD RAM memory.
  47. (#) When LCD RAM memory is updated enable the update display request using
  48. the HAL_LCD_UpdateDisplayRequest() API.
  49. [..] LCD and low power modes:
  50. (#) The LCD remain active during Sleep, Low Power run, Low Power Sleep and
  51. STOP modes.
  52. @endverbatim
  53. ******************************************************************************
  54. * @attention
  55. *
  56. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  57. *
  58. * Redistribution and use in source and binary forms, with or without modification,
  59. * are permitted provided that the following conditions are met:
  60. * 1. Redistributions of source code must retain the above copyright notice,
  61. * this list of conditions and the following disclaimer.
  62. * 2. Redistributions in binary form must reproduce the above copyright notice,
  63. * this list of conditions and the following disclaimer in the documentation
  64. * and/or other materials provided with the distribution.
  65. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  66. * may be used to endorse or promote products derived from this software
  67. * without specific prior written permission.
  68. *
  69. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  70. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  71. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  72. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  73. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  74. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  75. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  77. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  78. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  79. *
  80. ******************************************************************************
  81. */
  82. /* Includes ------------------------------------------------------------------*/
  83. #include "stm32l4xx_hal.h"
  84. #if defined(STM32L433xx) || defined(STM32L443xx) || defined(STM32L476xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
  85. /** @addtogroup STM32L4xx_HAL_Driver
  86. * @{
  87. */
  88. #ifdef HAL_LCD_MODULE_ENABLED
  89. /** @defgroup LCD LCD
  90. * @brief LCD HAL module driver
  91. * @{
  92. */
  93. /* Private typedef -----------------------------------------------------------*/
  94. /* Private define ------------------------------------------------------------*/
  95. /** @defgroup LCD_Private_Defines LCD Private Defines
  96. * @{
  97. */
  98. #define LCD_TIMEOUT_VALUE 1000
  99. /**
  100. * @}
  101. */
  102. /* Private macro -------------------------------------------------------------*/
  103. /* Private variables ---------------------------------------------------------*/
  104. /* Private function prototypes -----------------------------------------------*/
  105. /* Exported functions --------------------------------------------------------*/
  106. /** @defgroup LCD_Exported_Functions LCD Exported Functions
  107. * @{
  108. */
  109. /** @defgroup LCD_Exported_Functions_Group1 Initialization/de-initialization methods
  110. * @brief Initialization and Configuration functions
  111. *
  112. @verbatim
  113. ===============================================================================
  114. ##### Initialization and Configuration functions #####
  115. ===============================================================================
  116. [..]
  117. @endverbatim
  118. * @{
  119. */
  120. /**
  121. * @brief Initialize the LCD peripheral according to the specified parameters
  122. * in the LCD_InitStruct and initialize the associated handle.
  123. * @note This function can be used only when the LCD is disabled.
  124. * @param hlcd: LCD handle
  125. * @retval None
  126. */
  127. HAL_StatusTypeDef HAL_LCD_Init(LCD_HandleTypeDef *hlcd)
  128. {
  129. uint32_t tickstart = 0x00;
  130. uint32_t counter = 0;
  131. /* Check the LCD handle allocation */
  132. if(hlcd == NULL)
  133. {
  134. return HAL_ERROR;
  135. }
  136. /* Check function parameters */
  137. assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance));
  138. assert_param(IS_LCD_PRESCALER(hlcd->Init.Prescaler));
  139. assert_param(IS_LCD_DIVIDER(hlcd->Init.Divider));
  140. assert_param(IS_LCD_DUTY(hlcd->Init.Duty));
  141. assert_param(IS_LCD_BIAS(hlcd->Init.Bias));
  142. assert_param(IS_LCD_VOLTAGE_SOURCE(hlcd->Init.VoltageSource));
  143. assert_param(IS_LCD_PULSE_ON_DURATION(hlcd->Init.PulseOnDuration));
  144. assert_param(IS_LCD_HIGH_DRIVE(hlcd->Init.HighDrive));
  145. assert_param(IS_LCD_DEAD_TIME(hlcd->Init.DeadTime));
  146. assert_param(IS_LCD_CONTRAST(hlcd->Init.Contrast));
  147. assert_param(IS_LCD_BLINK_FREQUENCY(hlcd->Init.BlinkFrequency));
  148. assert_param(IS_LCD_BLINK_MODE(hlcd->Init.BlinkMode));
  149. assert_param(IS_LCD_MUX_SEGMENT(hlcd->Init.MuxSegment));
  150. if(hlcd->State == HAL_LCD_STATE_RESET)
  151. {
  152. /* Allocate lock resource and initialize it */
  153. hlcd->Lock = HAL_UNLOCKED;
  154. /* Initialize the low level hardware (MSP) */
  155. HAL_LCD_MspInit(hlcd);
  156. }
  157. hlcd->State = HAL_LCD_STATE_BUSY;
  158. /* Disable the peripheral */
  159. __HAL_LCD_DISABLE(hlcd);
  160. /* Clear the LCD_RAM registers and enable the display request by setting the UDR bit
  161. in the LCD_SR register */
  162. for(counter = LCD_RAM_REGISTER0; counter <= LCD_RAM_REGISTER15; counter++)
  163. {
  164. hlcd->Instance->RAM[counter] = 0;
  165. }
  166. /* Enable the display request */
  167. hlcd->Instance->SR |= LCD_SR_UDR;
  168. /* Configure the LCD Prescaler, Divider, Blink mode and Blink Frequency:
  169. Set PS[3:0] bits according to hlcd->Init.Prescaler value
  170. Set DIV[3:0] bits according to hlcd->Init.Divider value
  171. Set BLINK[1:0] bits according to hlcd->Init.BlinkMode value
  172. Set BLINKF[2:0] bits according to hlcd->Init.BlinkFrequency value
  173. Set DEAD[2:0] bits according to hlcd->Init.DeadTime value
  174. Set PON[2:0] bits according to hlcd->Init.PulseOnDuration value
  175. Set CC[2:0] bits according to hlcd->Init.Contrast value
  176. Set HD bit according to hlcd->Init.HighDrive value */
  177. MODIFY_REG(hlcd->Instance->FCR, \
  178. (LCD_FCR_PS | LCD_FCR_DIV | LCD_FCR_BLINK| LCD_FCR_BLINKF | \
  179. LCD_FCR_DEAD | LCD_FCR_PON | LCD_FCR_CC | LCD_FCR_HD), \
  180. (hlcd->Init.Prescaler | hlcd->Init.Divider | hlcd->Init.BlinkMode | hlcd->Init.BlinkFrequency | \
  181. hlcd->Init.DeadTime | hlcd->Init.PulseOnDuration | hlcd->Init.Contrast | hlcd->Init.HighDrive));
  182. /* Wait until LCD Frame Control Register Synchronization flag (FCRSF) is set in the LCD_SR register
  183. This bit is set by hardware each time the LCD_FCR register is updated in the LCDCLK
  184. domain. It is cleared by hardware when writing to the LCD_FCR register.*/
  185. LCD_WaitForSynchro(hlcd);
  186. /* Configure the LCD Duty, Bias, Voltage Source, Dead Time, Pulse On Duration and Contrast:
  187. Set DUTY[2:0] bits according to hlcd->Init.Duty value
  188. Set BIAS[1:0] bits according to hlcd->Init.Bias value
  189. Set VSEL bit according to hlcd->Init.VoltageSource value
  190. Set MUX_SEG bit according to hlcd->Init.MuxSegment value */
  191. MODIFY_REG(hlcd->Instance->CR, \
  192. (LCD_CR_DUTY | LCD_CR_BIAS | LCD_CR_VSEL | LCD_CR_MUX_SEG), \
  193. (hlcd->Init.Duty | hlcd->Init.Bias | hlcd->Init.VoltageSource | hlcd->Init.MuxSegment));
  194. /* Enable the peripheral */
  195. __HAL_LCD_ENABLE(hlcd);
  196. /* Get timeout */
  197. tickstart = HAL_GetTick();
  198. /* Wait Until the LCD is enabled */
  199. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_ENS) == RESET)
  200. {
  201. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  202. {
  203. hlcd->ErrorCode = HAL_LCD_ERROR_ENS;
  204. return HAL_TIMEOUT;
  205. }
  206. }
  207. /* Get timeout */
  208. tickstart = HAL_GetTick();
  209. /*!< Wait Until the LCD Booster is ready */
  210. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_RDY) == RESET)
  211. {
  212. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  213. {
  214. hlcd->ErrorCode = HAL_LCD_ERROR_RDY;
  215. return HAL_TIMEOUT;
  216. }
  217. }
  218. /* Initialize the LCD state */
  219. hlcd->ErrorCode = HAL_LCD_ERROR_NONE;
  220. hlcd->State= HAL_LCD_STATE_READY;
  221. return HAL_OK;
  222. }
  223. /**
  224. * @brief DeInitialize the LCD peripheral.
  225. * @param hlcd: LCD handle
  226. * @retval HAL status
  227. */
  228. HAL_StatusTypeDef HAL_LCD_DeInit(LCD_HandleTypeDef *hlcd)
  229. {
  230. /* Check the LCD handle allocation */
  231. if(hlcd == NULL)
  232. {
  233. return HAL_ERROR;
  234. }
  235. /* Check the parameters */
  236. assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance));
  237. hlcd->State = HAL_LCD_STATE_BUSY;
  238. /* DeInit the low level hardware */
  239. HAL_LCD_MspDeInit(hlcd);
  240. hlcd->ErrorCode = HAL_LCD_ERROR_NONE;
  241. hlcd->State = HAL_LCD_STATE_RESET;
  242. /* Release Lock */
  243. __HAL_UNLOCK(hlcd);
  244. return HAL_OK;
  245. }
  246. /**
  247. * @brief DeInitialize the LCD MSP.
  248. * @param hlcd: LCD handle
  249. * @retval None
  250. */
  251. __weak void HAL_LCD_MspDeInit(LCD_HandleTypeDef *hlcd)
  252. {
  253. /* Prevent unused argument(s) compilation warning */
  254. UNUSED(hlcd);
  255. /* NOTE: This function should not be modified, when the callback is needed,
  256. the HAL_LCD_MspDeInit it to be implemented in the user file
  257. */
  258. }
  259. /**
  260. * @brief Initialize the LCD MSP.
  261. * @param hlcd: LCD handle
  262. * @retval None
  263. */
  264. __weak void HAL_LCD_MspInit(LCD_HandleTypeDef *hlcd)
  265. {
  266. /* Prevent unused argument(s) compilation warning */
  267. UNUSED(hlcd);
  268. /* NOTE: This function should not be modified, when the callback is needed,
  269. the HAL_LCD_MspInit is to be implemented in the user file
  270. */
  271. }
  272. /**
  273. * @}
  274. */
  275. /** @defgroup LCD_Exported_Functions_Group2 IO operation methods
  276. * @brief LCD RAM functions
  277. *
  278. @verbatim
  279. ===============================================================================
  280. ##### IO operation functions #####
  281. ===============================================================================
  282. [..] Using its double buffer memory the LCD controller ensures the coherency of the
  283. displayed information without having to use interrupts to control LCD_RAM
  284. modification.
  285. The application software can access the first buffer level (LCD_RAM) through
  286. the APB interface. Once it has modified the LCD_RAM using the HAL_LCD_Write() API,
  287. it sets the UDR flag in the LCD_SR register using the HAL_LCD_UpdateDisplayRequest() API.
  288. This UDR flag (update display request) requests the updated information to be
  289. moved into the second buffer level (LCD_DISPLAY).
  290. This operation is done synchronously with the frame (at the beginning of the
  291. next frame), until the update is completed, the LCD_RAM is write protected and
  292. the UDR flag stays high.
  293. Once the update is completed another flag (UDD - Update Display Done) is set and
  294. generates an interrupt if the UDDIE bit in the LCD_FCR register is set.
  295. The time it takes to update LCD_DISPLAY is, in the worst case, one odd and one
  296. even frame.
  297. The update will not occur (UDR = 1 and UDD = 0) until the display is
  298. enabled (LCDEN = 1).
  299. @endverbatim
  300. * @{
  301. */
  302. /**
  303. * @brief Write a word in the specific LCD RAM.
  304. * @param hlcd: LCD handle
  305. * @param RAMRegisterIndex: specifies the LCD RAM Register.
  306. * This parameter can be one of the following values:
  307. * @arg LCD_RAM_REGISTER0: LCD RAM Register 0
  308. * @arg LCD_RAM_REGISTER1: LCD RAM Register 1
  309. * @arg LCD_RAM_REGISTER2: LCD RAM Register 2
  310. * @arg LCD_RAM_REGISTER3: LCD RAM Register 3
  311. * @arg LCD_RAM_REGISTER4: LCD RAM Register 4
  312. * @arg LCD_RAM_REGISTER5: LCD RAM Register 5
  313. * @arg LCD_RAM_REGISTER6: LCD RAM Register 6
  314. * @arg LCD_RAM_REGISTER7: LCD RAM Register 7
  315. * @arg LCD_RAM_REGISTER8: LCD RAM Register 8
  316. * @arg LCD_RAM_REGISTER9: LCD RAM Register 9
  317. * @arg LCD_RAM_REGISTER10: LCD RAM Register 10
  318. * @arg LCD_RAM_REGISTER11: LCD RAM Register 11
  319. * @arg LCD_RAM_REGISTER12: LCD RAM Register 12
  320. * @arg LCD_RAM_REGISTER13: LCD RAM Register 13
  321. * @arg LCD_RAM_REGISTER14: LCD RAM Register 14
  322. * @arg LCD_RAM_REGISTER15: LCD RAM Register 15
  323. * @param RAMRegisterMask: specifies the LCD RAM Register Data Mask.
  324. * @param Data: specifies LCD Data Value to be written.
  325. * @retval None
  326. */
  327. HAL_StatusTypeDef HAL_LCD_Write(LCD_HandleTypeDef *hlcd, uint32_t RAMRegisterIndex, uint32_t RAMRegisterMask, uint32_t Data)
  328. {
  329. uint32_t tickstart = 0x00;
  330. if((hlcd->State == HAL_LCD_STATE_READY) || (hlcd->State == HAL_LCD_STATE_BUSY))
  331. {
  332. /* Check the parameters */
  333. assert_param(IS_LCD_RAM_REGISTER(RAMRegisterIndex));
  334. if(hlcd->State == HAL_LCD_STATE_READY)
  335. {
  336. /* Process Locked */
  337. __HAL_LOCK(hlcd);
  338. hlcd->State = HAL_LCD_STATE_BUSY;
  339. /* Get timeout */
  340. tickstart = HAL_GetTick();
  341. /*!< Wait Until the LCD is ready */
  342. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDR) != RESET)
  343. {
  344. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  345. {
  346. hlcd->ErrorCode = HAL_LCD_ERROR_UDR;
  347. /* Process Unlocked */
  348. __HAL_UNLOCK(hlcd);
  349. return HAL_TIMEOUT;
  350. }
  351. }
  352. }
  353. /* Copy the new Data bytes to LCD RAM register */
  354. MODIFY_REG(hlcd->Instance->RAM[RAMRegisterIndex], ~(RAMRegisterMask), Data);
  355. return HAL_OK;
  356. }
  357. else
  358. {
  359. return HAL_ERROR;
  360. }
  361. }
  362. /**
  363. * @brief Clear the LCD RAM registers.
  364. * @param hlcd: LCD handle
  365. * @retval None
  366. */
  367. HAL_StatusTypeDef HAL_LCD_Clear(LCD_HandleTypeDef *hlcd)
  368. {
  369. uint32_t tickstart = 0x00;
  370. uint32_t counter = 0;
  371. if((hlcd->State == HAL_LCD_STATE_READY) || (hlcd->State == HAL_LCD_STATE_BUSY))
  372. {
  373. /* Process Locked */
  374. __HAL_LOCK(hlcd);
  375. hlcd->State = HAL_LCD_STATE_BUSY;
  376. /* Get timeout */
  377. tickstart = HAL_GetTick();
  378. /*!< Wait Until the LCD is ready */
  379. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDR) != RESET)
  380. {
  381. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  382. {
  383. hlcd->ErrorCode = HAL_LCD_ERROR_UDR;
  384. /* Process Unlocked */
  385. __HAL_UNLOCK(hlcd);
  386. return HAL_TIMEOUT;
  387. }
  388. }
  389. /* Clear the LCD_RAM registers */
  390. for(counter = LCD_RAM_REGISTER0; counter <= LCD_RAM_REGISTER15; counter++)
  391. {
  392. hlcd->Instance->RAM[counter] = 0;
  393. }
  394. /* Update the LCD display */
  395. HAL_LCD_UpdateDisplayRequest(hlcd);
  396. return HAL_OK;
  397. }
  398. else
  399. {
  400. return HAL_ERROR;
  401. }
  402. }
  403. /**
  404. * @brief Enable the Update Display Request.
  405. * @param hlcd: LCD handle
  406. * @note Each time software modifies the LCD_RAM it must set the UDR bit to
  407. * transfer the updated data to the second level buffer.
  408. * The UDR bit stays set until the end of the update and during this
  409. * time the LCD_RAM is write protected.
  410. * @note When the display is disabled, the update is performed for all
  411. * LCD_DISPLAY locations.
  412. * When the display is enabled, the update is performed only for locations
  413. * for which commons are active (depending on DUTY). For example if
  414. * DUTY = 1/2, only the LCD_DISPLAY of COM0 and COM1 will be updated.
  415. * @retval None
  416. */
  417. HAL_StatusTypeDef HAL_LCD_UpdateDisplayRequest(LCD_HandleTypeDef *hlcd)
  418. {
  419. uint32_t tickstart = 0x00;
  420. /* Clear the Update Display Done flag before starting the update display request */
  421. __HAL_LCD_CLEAR_FLAG(hlcd, LCD_FLAG_UDD);
  422. /* Enable the display request */
  423. hlcd->Instance->SR |= LCD_SR_UDR;
  424. /* Get timeout */
  425. tickstart = HAL_GetTick();
  426. /*!< Wait Until the LCD display is done */
  427. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDD) == RESET)
  428. {
  429. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  430. {
  431. hlcd->ErrorCode = HAL_LCD_ERROR_UDD;
  432. /* Process Unlocked */
  433. __HAL_UNLOCK(hlcd);
  434. return HAL_TIMEOUT;
  435. }
  436. }
  437. hlcd->State = HAL_LCD_STATE_READY;
  438. /* Process Unlocked */
  439. __HAL_UNLOCK(hlcd);
  440. return HAL_OK;
  441. }
  442. /**
  443. * @}
  444. */
  445. /** @defgroup LCD_Exported_Functions_Group3 Peripheral State methods
  446. * @brief LCD State functions
  447. *
  448. @verbatim
  449. ===============================================================================
  450. ##### Peripheral State functions #####
  451. ===============================================================================
  452. [..]
  453. This subsection provides a set of functions allowing to control the LCD:
  454. (+) HAL_LCD_GetState() API can be helpful to check in run-time the state of the LCD peripheral State.
  455. (+) HAL_LCD_GetError() API to return the LCD error code.
  456. @endverbatim
  457. * @{
  458. */
  459. /**
  460. * @brief Return the LCD handle state.
  461. * @param hlcd: LCD handle
  462. * @retval HAL state
  463. */
  464. HAL_LCD_StateTypeDef HAL_LCD_GetState(LCD_HandleTypeDef *hlcd)
  465. {
  466. /* Return LCD handle state */
  467. return hlcd->State;
  468. }
  469. /**
  470. * @brief Return the LCD error code.
  471. * @param hlcd: LCD handle
  472. * @retval LCD Error Code
  473. */
  474. uint32_t HAL_LCD_GetError(LCD_HandleTypeDef *hlcd)
  475. {
  476. return hlcd->ErrorCode;
  477. }
  478. /**
  479. * @}
  480. */
  481. /**
  482. * @}
  483. */
  484. /** @defgroup LCD_Private_Functions LCD Private Functions
  485. * @{
  486. */
  487. /**
  488. * @brief Wait until the LCD FCR register is synchronized in the LCDCLK domain.
  489. * This function must be called after any write operation to LCD_FCR register.
  490. * @retval None
  491. */
  492. HAL_StatusTypeDef LCD_WaitForSynchro(LCD_HandleTypeDef *hlcd)
  493. {
  494. uint32_t tickstart = 0x00;
  495. /* Get timeout */
  496. tickstart = HAL_GetTick();
  497. /* Loop until FCRSF flag is set */
  498. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_FCRSF) == RESET)
  499. {
  500. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  501. {
  502. hlcd->ErrorCode = HAL_LCD_ERROR_FCRSF;
  503. return HAL_TIMEOUT;
  504. }
  505. }
  506. return HAL_OK;
  507. }
  508. /**
  509. * @}
  510. */
  511. /**
  512. * @}
  513. */
  514. #endif /* HAL_LCD_MODULE_ENABLED */
  515. /**
  516. * @}
  517. */
  518. #endif /* STM32L433xx || STM32L443xx || STM32L476xx || STM32L486xx || STM32L496xx || STM32L4A6xx */
  519. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/