stm32l1xx_hal_lcd.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_lcd.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 5-September-2014
  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. (#) Initialize the LCD low level resources by implement the HAL_LCD_MspInit() API:
  21. (##) Enable the LCDCLK (same as RTCCLK): to configure the RTCCLK/LCDCLK, proceed as follows:
  22. (+) Use RCC function HAL_RCCEx_PeriphCLKConfig in indicating RCC_PERIPHCLK_LCD and
  23. selected clock source (HSE, LSI or LSE)
  24. -@- The frequency generator allows you to achieve various LCD frame rates
  25. starting from an LCD input clock frequency (LCDCLK) which can vary
  26. from 32 kHz up to 1 MHz.
  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 and Contrast in the hlcd Init structure.
  33. (#) Initialize the LCD registers by calling the HAL_LCD_Init() API.
  34. -@- The HAL_LCD_Init() API configures also the low level Hardware GPIO, CLOCK, ...etc)
  35. by calling the custumed HAL_LCD_MspInit() API.
  36. -@- After calling the HAL_LCD_Init() the LCD RAM memory is cleared
  37. (#) Optionally you can update the LCD configuration using these macros:
  38. (+) LCD High Drive using the __HAL_LCD_HIGHDRIVER_ENABLE() and __HAL_LCD_HIGHDRIVER_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 STOP mode.
  51. @endverbatim
  52. ******************************************************************************
  53. * @attention
  54. *
  55. * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  56. *
  57. * Redistribution and use in source and binary forms, with or without modification,
  58. * are permitted provided that the following conditions are met:
  59. * 1. Redistributions of source code must retain the above copyright notice,
  60. * this list of conditions and the following disclaimer.
  61. * 2. Redistributions in binary form must reproduce the above copyright notice,
  62. * this list of conditions and the following disclaimer in the documentation
  63. * and/or other materials provided with the distribution.
  64. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  65. * may be used to endorse or promote products derived from this software
  66. * without specific prior written permission.
  67. *
  68. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  69. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  71. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  72. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  73. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  75. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  76. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  77. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  78. *
  79. ******************************************************************************
  80. */
  81. /* Includes ------------------------------------------------------------------*/
  82. #include "stm32l1xx_hal.h"
  83. /** @addtogroup STM32L1xx_HAL_Driver
  84. * @{
  85. */
  86. #ifdef HAL_LCD_MODULE_ENABLED
  87. #if defined (STM32L100xB) || defined (STM32L100xBA) || defined (STM32L100xC) ||\
  88. defined (STM32L152xB) || defined (STM32L152xBA) || defined (STM32L152xC) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L152xE) ||\
  89. defined (STM32L162xC) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L162xE)
  90. /** @defgroup LCD LCD
  91. * @brief LCD HAL module driver
  92. * @{
  93. */
  94. /* Private typedef -----------------------------------------------------------*/
  95. /* Private define ------------------------------------------------------------*/
  96. /** @defgroup LCD_Private_Defines LCD Private Defines
  97. * @{
  98. */
  99. #define LCD_TIMEOUT_VALUE 1000
  100. /**
  101. * @}
  102. */
  103. /* Private macro -------------------------------------------------------------*/
  104. /* Private variables ---------------------------------------------------------*/
  105. /* Private function prototypes -----------------------------------------------*/
  106. /* Private functions ---------------------------------------------------------*/
  107. /** @defgroup LCD_Exported_Functions LCD Exported Functions
  108. * @{
  109. */
  110. /** @defgroup LCD_Exported_Functions_Group1 Initialization/de-initialization methods
  111. * @brief Initialization and Configuration functions
  112. *
  113. @verbatim
  114. ===============================================================================
  115. ##### Initialization and Configuration functions #####
  116. ===============================================================================
  117. [..]
  118. @endverbatim
  119. * @{
  120. */
  121. /**
  122. * @brief DeInitializes the LCD peripheral.
  123. * @param hlcd: LCD handle
  124. * @retval HAL status
  125. */
  126. HAL_StatusTypeDef HAL_LCD_DeInit(LCD_HandleTypeDef *hlcd)
  127. {
  128. /* Check the LCD handle allocation */
  129. if(hlcd == NULL)
  130. {
  131. return HAL_ERROR;
  132. }
  133. /* Check the parameters */
  134. assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance));
  135. hlcd->State = HAL_LCD_STATE_BUSY;
  136. /* DeInit the low level hardware */
  137. HAL_LCD_MspDeInit(hlcd);
  138. hlcd->ErrorCode = HAL_LCD_ERROR_NONE;
  139. hlcd->State = HAL_LCD_STATE_RESET;
  140. /* Release Lock */
  141. __HAL_UNLOCK(hlcd);
  142. return HAL_OK;
  143. }
  144. /**
  145. * @brief Initializes the LCD peripheral according to the specified parameters
  146. * in the LCD_InitStruct.
  147. * @note This function can be used only when the LCD is disabled.
  148. * @param hlcd: LCD handle
  149. * @retval None
  150. */
  151. HAL_StatusTypeDef HAL_LCD_Init(LCD_HandleTypeDef *hlcd)
  152. {
  153. uint32_t tickstart = 0x00;
  154. uint8_t counter = 0;
  155. /* Check the LCD handle allocation */
  156. if(hlcd == NULL)
  157. {
  158. return HAL_ERROR;
  159. }
  160. /* Check function parameters */
  161. assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance));
  162. assert_param(IS_LCD_PRESCALER(hlcd->Init.Prescaler));
  163. assert_param(IS_LCD_DIVIDER(hlcd->Init.Divider));
  164. assert_param(IS_LCD_DUTY(hlcd->Init.Duty));
  165. assert_param(IS_LCD_BIAS(hlcd->Init.Bias));
  166. assert_param(IS_LCD_VOLTAGE_SOURCE(hlcd->Init.VoltageSource));
  167. assert_param(IS_LCD_PULSE_ON_DURATION(hlcd->Init.PulseOnDuration));
  168. assert_param(IS_LCD_DEAD_TIME(hlcd->Init.DeadTime));
  169. assert_param(IS_LCD_CONTRAST(hlcd->Init.Contrast));
  170. assert_param(IS_LCD_BLINK_FREQUENCY(hlcd->Init.BlinkFrequency));
  171. assert_param(IS_LCD_BLINK_MODE(hlcd->Init.BlinkMode));
  172. assert_param(IS_LCD_MUXSEGMENT(hlcd->Init.MuxSegment));
  173. if(hlcd->State == HAL_LCD_STATE_RESET)
  174. {
  175. /* Initialize the low level hardware (MSP) */
  176. HAL_LCD_MspInit(hlcd);
  177. }
  178. hlcd->State = HAL_LCD_STATE_BUSY;
  179. /* Disable the peripheral */
  180. __HAL_LCD_DISABLE(hlcd);
  181. /* Clear the LCD_RAM registers and enable the display request by setting the UDR bit
  182. in the LCD_SR register */
  183. for(counter = LCD_RAM_REGISTER0; counter <= LCD_RAM_REGISTER15; counter++)
  184. {
  185. hlcd->Instance->RAM[counter] = 0;
  186. }
  187. /* Enable the display request */
  188. hlcd->Instance->SR |= LCD_SR_UDR;
  189. /* Configure the LCD Prescaler, Divider, Blink mode and Blink Frequency:
  190. Set PS[3:0] bits according to hlcd->Init.Prescaler value
  191. Set DIV[3:0] bits according to hlcd->Init.Divider value
  192. Set BLINK[1:0] bits according to hlcd->Init.BlinkMode value
  193. Set BLINKF[2:0] bits according to hlcd->Init.BlinkFrequency value
  194. Set DEAD[2:0] bits according to hlcd->Init.DeadTime value
  195. Set PON[2:0] bits according to hlcd->Init.PulseOnDuration value
  196. Set CC[2:0] bits according to hlcd->Init.Contrast value */
  197. MODIFY_REG(hlcd->Instance->FCR, \
  198. (LCD_FCR_PS | LCD_FCR_DIV | LCD_FCR_BLINK| LCD_FCR_BLINKF | \
  199. LCD_FCR_DEAD | LCD_FCR_PON | LCD_FCR_CC), \
  200. (hlcd->Init.Prescaler | hlcd->Init.Divider | hlcd->Init.BlinkMode | hlcd->Init.BlinkFrequency | \
  201. hlcd->Init.DeadTime | hlcd->Init.PulseOnDuration | hlcd->Init.Contrast));
  202. /* Wait until LCD Frame Control Register Synchronization flag (FCRSF) is set in the LCD_SR register
  203. This bit is set by hardware each time the LCD_FCR register is updated in the LCDCLK
  204. domain. It is cleared by hardware when writing to the LCD_FCR register.*/
  205. LCD_WaitForSynchro(hlcd);
  206. /* Configure the LCD Duty, Bias, Voltage Source, Dead Time, Pulse On Duration and Contrast:
  207. Set DUTY[2:0] bits according to hlcd->Init.Duty value
  208. Set BIAS[1:0] bits according to hlcd->Init.Bias value
  209. Set VSEL bit according to hlcd->Init.VoltageSource value
  210. Set MUX_SEG bit according to hlcd->Init.MuxSegment value */
  211. MODIFY_REG(hlcd->Instance->CR, \
  212. (LCD_CR_DUTY | LCD_CR_BIAS | LCD_CR_VSEL | LCD_CR_MUX_SEG), \
  213. (hlcd->Init.Duty | hlcd->Init.Bias | hlcd->Init.VoltageSource | hlcd->Init.MuxSegment));
  214. /* Enable the peripheral */
  215. __HAL_LCD_ENABLE(hlcd);
  216. /* Get timeout */
  217. tickstart = HAL_GetTick();
  218. /* Wait Until the LCD is enabled */
  219. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_ENS) == RESET)
  220. {
  221. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  222. {
  223. hlcd->ErrorCode = HAL_LCD_ERROR_ENS;
  224. return HAL_TIMEOUT;
  225. }
  226. }
  227. /* Get timeout */
  228. tickstart = HAL_GetTick();
  229. /*!< Wait Until the LCD Booster is ready */
  230. while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_RDY) == RESET)
  231. {
  232. if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
  233. {
  234. hlcd->ErrorCode = HAL_LCD_ERROR_RDY;
  235. return HAL_TIMEOUT;
  236. }
  237. }
  238. /* Initialize the LCD state */
  239. hlcd->ErrorCode = HAL_LCD_ERROR_NONE;
  240. hlcd->State= HAL_LCD_STATE_READY;
  241. return HAL_OK;
  242. }
  243. /**
  244. * @brief LCD MSP DeInit.
  245. * @param hlcd: LCD handle
  246. * @retval None
  247. */
  248. __weak void HAL_LCD_MspDeInit(LCD_HandleTypeDef *hlcd)
  249. {
  250. /* NOTE: This function Should not be modified, when the callback is needed,
  251. the HAL_LCD_MspDeInit could be implemented in the user file
  252. */
  253. }
  254. /**
  255. * @brief LCD MSP Init.
  256. * @param hlcd: LCD handle
  257. * @retval None
  258. */
  259. __weak void HAL_LCD_MspInit(LCD_HandleTypeDef *hlcd)
  260. {
  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 */
  507. #endif /* HAL_LCD_MODULE_ENABLED */
  508. /**
  509. * @}
  510. */
  511. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/