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