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.

stm32l1xx_hal_lcd.c 20KB

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