stm32l4xx_hal_lcd.c 20 KB

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