stm32l1xx_hal_lcd.c 21 KB

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