STM32L486xx HAL User Manual
stm32l4xx_hal_lcd.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_lcd.c
00004   * @author  MCD Application Team
00005   * @brief   LCD Controller HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the LCD Controller (LCD) peripheral:
00008   *           + Initialization/de-initialization methods
00009   *           + I/O operation methods
00010   *           + Peripheral State methods
00011   *
00012   @verbatim
00013   ==============================================================================
00014                         ##### How to use this driver #####
00015   ==============================================================================
00016       [..] The LCD HAL driver can be used as follows:
00017 
00018       (#) Declare a LCD_HandleTypeDef handle structure.
00019       
00020       -@- The frequency generator allows you to achieve various LCD frame rates
00021           starting from an LCD input clock frequency (LCDCLK) which can vary
00022           from 32 kHz up to 1 MHz.      
00023       
00024       (#) Initialize the LCD low level resources by implementing the HAL_LCD_MspInit() API:
00025                   
00026           (++) Enable the LCDCLK (same as RTCCLK): to configure the RTCCLK/LCDCLK, proceed as follows:
00027                (+++) Use RCC function HAL_RCCEx_PeriphCLKConfig in indicating RCC_PERIPHCLK_LCD and
00028                   selected clock source (HSE, LSI or LSE)
00029 
00030           (++) LCD pins configuration:
00031               (+++) Enable the clock for the LCD GPIOs.
00032               (+++) Configure these LCD pins as alternate function no-pull.
00033           (++) Enable the LCD interface clock.
00034 
00035       
00036       (#) Program the Prescaler, Divider, Blink mode, Blink Frequency Duty, Bias,
00037           Voltage Source, Dead Time, Pulse On Duration, Contrast, High drive and Multiplexer
00038           Segment in the Init structure of the LCD handle.
00039 
00040       (#) Initialize the LCD registers by calling the HAL_LCD_Init() API.
00041 
00042       -@- The HAL_LCD_Init() API configures also the low level Hardware GPIO, CLOCK, ...etc)
00043           by calling the customized HAL_LCD_MspInit() API.
00044       -@- After calling the HAL_LCD_Init() the LCD RAM memory is cleared
00045 
00046       (#) Optionally you can update the LCD configuration using these macros:
00047               (++) LCD High Drive using the __HAL_LCD_HIGHDRIVER_ENABLE() and __HAL_LCD_HIGHDRIVER_DISABLE() macros
00048               (++) Voltage output buffer using __HAL_LCD_VOLTAGE_BUFFER_ENABLE() and __HAL_LCD_VOLTAGE_BUFFER_DISABLE() macros
00049               (++) LCD Pulse ON Duration using the __HAL_LCD_PULSEONDURATION_CONFIG() macro
00050               (++) LCD Dead Time using the __HAL_LCD_DEADTIME_CONFIG() macro
00051               (++) The LCD Blink mode and frequency using the __HAL_LCD_BLINK_CONFIG() macro
00052               (++) The LCD Contrast using the __HAL_LCD_CONTRAST_CONFIG() macro
00053 
00054       (#) Write to the LCD RAM memory using the HAL_LCD_Write() API, this API can be called
00055           more time to update the different LCD RAM registers before calling
00056           HAL_LCD_UpdateDisplayRequest() API.
00057 
00058       (#) The HAL_LCD_Clear() API can be used to clear the LCD RAM memory.
00059 
00060       (#) When LCD RAM memory is updated enable the update display request using
00061           the HAL_LCD_UpdateDisplayRequest() API.
00062 
00063       [..] LCD and low power modes:
00064            (#) The LCD remain active during Sleep, Low Power run, Low Power Sleep and
00065                STOP modes.
00066 
00067   @endverbatim
00068   ******************************************************************************
00069   * @attention
00070   *
00071   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00072   *
00073   * Redistribution and use in source and binary forms, with or without modification,
00074   * are permitted provided that the following conditions are met:
00075   *   1. Redistributions of source code must retain the above copyright notice,
00076   *      this list of conditions and the following disclaimer.
00077   *   2. Redistributions in binary form must reproduce the above copyright notice,
00078   *      this list of conditions and the following disclaimer in the documentation
00079   *      and/or other materials provided with the distribution.
00080   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00081   *      may be used to endorse or promote products derived from this software
00082   *      without specific prior written permission.
00083   *
00084   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00085   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00086   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00087   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00088   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00089   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00090   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00091   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00092   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00093   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00094   *
00095   ******************************************************************************
00096   */
00097 
00098 /* Includes ------------------------------------------------------------------*/
00099 #include "stm32l4xx_hal.h"
00100 
00101 #if defined(STM32L433xx) || defined(STM32L443xx) || defined(STM32L476xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
00102 
00103 /** @addtogroup STM32L4xx_HAL_Driver
00104   * @{
00105   */
00106 
00107 #ifdef HAL_LCD_MODULE_ENABLED
00108 
00109 /** @defgroup LCD LCD
00110   * @brief LCD HAL module driver
00111   * @{
00112   */
00113 
00114 /* Private typedef -----------------------------------------------------------*/
00115 /* Private define ------------------------------------------------------------*/
00116 /** @defgroup LCD_Private_Defines LCD Private Defines
00117   * @{
00118   */
00119 
00120 #define LCD_TIMEOUT_VALUE             1000
00121 
00122 /**
00123   * @}
00124   */
00125 
00126 /* Private macro -------------------------------------------------------------*/
00127 /* Private variables ---------------------------------------------------------*/
00128 /* Private function prototypes -----------------------------------------------*/
00129 /* Exported functions --------------------------------------------------------*/
00130 
00131 /** @defgroup LCD_Exported_Functions LCD Exported Functions
00132   * @{
00133   */
00134 
00135 /** @defgroup LCD_Exported_Functions_Group1 Initialization/de-initialization methods
00136   *  @brief    Initialization and Configuration functions
00137   *
00138 @verbatim
00139 ===============================================================================
00140             ##### Initialization and Configuration functions #####
00141  ===============================================================================
00142     [..]
00143 
00144 @endverbatim
00145   * @{
00146   */
00147 
00148 /**
00149   * @brief  Initialize the LCD peripheral according to the specified parameters
00150   *         in the LCD_InitStruct and initialize the associated handle.
00151   * @note   This function can be used only when the LCD is disabled.
00152   * @param  hlcd: LCD handle
00153   * @retval None
00154   */
00155 HAL_StatusTypeDef HAL_LCD_Init(LCD_HandleTypeDef *hlcd)
00156 {
00157   uint32_t tickstart = 0x00;
00158   uint32_t counter = 0;
00159 
00160   /* Check the LCD handle allocation */
00161   if(hlcd == NULL)
00162   {
00163     return HAL_ERROR;
00164   }
00165 
00166   /* Check function parameters */
00167   assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance));
00168   assert_param(IS_LCD_PRESCALER(hlcd->Init.Prescaler));
00169   assert_param(IS_LCD_DIVIDER(hlcd->Init.Divider));
00170   assert_param(IS_LCD_DUTY(hlcd->Init.Duty));
00171   assert_param(IS_LCD_BIAS(hlcd->Init.Bias));
00172   assert_param(IS_LCD_VOLTAGE_SOURCE(hlcd->Init.VoltageSource));
00173   assert_param(IS_LCD_PULSE_ON_DURATION(hlcd->Init.PulseOnDuration));
00174   assert_param(IS_LCD_HIGH_DRIVE(hlcd->Init.HighDrive));
00175   assert_param(IS_LCD_DEAD_TIME(hlcd->Init.DeadTime));
00176   assert_param(IS_LCD_CONTRAST(hlcd->Init.Contrast));
00177   assert_param(IS_LCD_BLINK_FREQUENCY(hlcd->Init.BlinkFrequency));
00178   assert_param(IS_LCD_BLINK_MODE(hlcd->Init.BlinkMode));
00179   assert_param(IS_LCD_MUX_SEGMENT(hlcd->Init.MuxSegment));
00180 
00181   if(hlcd->State == HAL_LCD_STATE_RESET)
00182   {
00183     /* Allocate lock resource and initialize it */
00184     hlcd->Lock = HAL_UNLOCKED;
00185 
00186     /* Initialize the low level hardware (MSP) */
00187     HAL_LCD_MspInit(hlcd);
00188   }
00189 
00190   hlcd->State = HAL_LCD_STATE_BUSY;
00191 
00192   /* Disable the peripheral */
00193   __HAL_LCD_DISABLE(hlcd);
00194 
00195   /* Clear the LCD_RAM registers and enable the display request by setting the UDR bit
00196      in the LCD_SR register */
00197   for(counter = LCD_RAM_REGISTER0; counter <= LCD_RAM_REGISTER15; counter++)
00198   {
00199     hlcd->Instance->RAM[counter] = 0;
00200   }
00201   /* Enable the display request */
00202   hlcd->Instance->SR |= LCD_SR_UDR;
00203 
00204   /* Configure the LCD Prescaler, Divider, Blink mode and Blink Frequency:
00205      Set PS[3:0] bits according to hlcd->Init.Prescaler value
00206      Set DIV[3:0] bits according to hlcd->Init.Divider value
00207      Set BLINK[1:0] bits according to hlcd->Init.BlinkMode value
00208      Set BLINKF[2:0] bits according to hlcd->Init.BlinkFrequency value
00209      Set DEAD[2:0] bits according to hlcd->Init.DeadTime value
00210      Set PON[2:0] bits according to hlcd->Init.PulseOnDuration value
00211      Set CC[2:0] bits according to hlcd->Init.Contrast value
00212      Set HD bit according to hlcd->Init.HighDrive value */
00213    MODIFY_REG(hlcd->Instance->FCR, \
00214       (LCD_FCR_PS | LCD_FCR_DIV | LCD_FCR_BLINK| LCD_FCR_BLINKF | \
00215        LCD_FCR_DEAD | LCD_FCR_PON | LCD_FCR_CC | LCD_FCR_HD), \
00216       (hlcd->Init.Prescaler | hlcd->Init.Divider | hlcd->Init.BlinkMode | hlcd->Init.BlinkFrequency | \
00217        hlcd->Init.DeadTime | hlcd->Init.PulseOnDuration | hlcd->Init.Contrast | hlcd->Init.HighDrive));
00218 
00219   /* Wait until LCD Frame Control Register Synchronization flag (FCRSF) is set in the LCD_SR register
00220      This bit is set by hardware each time the LCD_FCR register is updated in the LCDCLK
00221      domain. It is cleared by hardware when writing to the LCD_FCR register.*/
00222   LCD_WaitForSynchro(hlcd);
00223 
00224   /* Configure the LCD Duty, Bias, Voltage Source, Dead Time, Pulse On Duration and Contrast:
00225      Set DUTY[2:0] bits according to hlcd->Init.Duty value
00226      Set BIAS[1:0] bits according to hlcd->Init.Bias value
00227      Set VSEL bit according to hlcd->Init.VoltageSource value
00228      Set MUX_SEG bit according to hlcd->Init.MuxSegment value */
00229   MODIFY_REG(hlcd->Instance->CR, \
00230     (LCD_CR_DUTY | LCD_CR_BIAS | LCD_CR_VSEL | LCD_CR_MUX_SEG), \
00231     (hlcd->Init.Duty | hlcd->Init.Bias | hlcd->Init.VoltageSource | hlcd->Init.MuxSegment));
00232 
00233   /* Enable the peripheral */
00234   __HAL_LCD_ENABLE(hlcd);
00235 
00236   /* Get timeout */
00237   tickstart = HAL_GetTick();
00238 
00239   /* Wait Until the LCD is enabled */
00240   while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_ENS) == RESET)
00241   {
00242     if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
00243     {
00244       hlcd->ErrorCode = HAL_LCD_ERROR_ENS;
00245       return HAL_TIMEOUT;
00246     }
00247   }
00248 
00249   /* Get timeout */
00250   tickstart = HAL_GetTick();
00251 
00252   /*!< Wait Until the LCD Booster is ready */
00253   while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_RDY) == RESET)
00254   {
00255     if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
00256     {
00257       hlcd->ErrorCode = HAL_LCD_ERROR_RDY;
00258       return HAL_TIMEOUT;
00259     }
00260   }
00261 
00262   /* Initialize the LCD state */
00263   hlcd->ErrorCode = HAL_LCD_ERROR_NONE;
00264   hlcd->State= HAL_LCD_STATE_READY;
00265 
00266   return HAL_OK;
00267 }
00268 
00269 /**
00270   * @brief  DeInitialize the LCD peripheral.
00271   * @param  hlcd: LCD handle
00272   * @retval HAL status
00273   */
00274 HAL_StatusTypeDef HAL_LCD_DeInit(LCD_HandleTypeDef *hlcd)
00275 {
00276   /* Check the LCD handle allocation */
00277   if(hlcd == NULL)
00278   {
00279     return HAL_ERROR;
00280   }
00281 
00282   /* Check the parameters */
00283   assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance));
00284 
00285   hlcd->State = HAL_LCD_STATE_BUSY;
00286 
00287   /* DeInit the low level hardware */
00288   HAL_LCD_MspDeInit(hlcd);
00289 
00290   hlcd->ErrorCode = HAL_LCD_ERROR_NONE;
00291   hlcd->State = HAL_LCD_STATE_RESET;
00292 
00293   /* Release Lock */
00294   __HAL_UNLOCK(hlcd);
00295 
00296   return HAL_OK;
00297 }
00298 
00299 /**
00300   * @brief  DeInitialize the LCD MSP.
00301   * @param  hlcd: LCD handle
00302   * @retval None
00303   */
00304 __weak void HAL_LCD_MspDeInit(LCD_HandleTypeDef *hlcd)
00305 {
00306   /* Prevent unused argument(s) compilation warning */
00307   UNUSED(hlcd);
00308 
00309   /* NOTE: This function should not be modified, when the callback is needed,
00310            the HAL_LCD_MspDeInit it to be implemented in the user file
00311    */
00312 }
00313 
00314 /**
00315   * @brief  Initialize the LCD MSP.
00316   * @param  hlcd: LCD handle
00317   * @retval None
00318   */
00319 __weak void HAL_LCD_MspInit(LCD_HandleTypeDef *hlcd)
00320 {
00321   /* Prevent unused argument(s) compilation warning */
00322   UNUSED(hlcd);
00323 
00324   /* NOTE: This function should not be modified, when the callback is needed,
00325            the HAL_LCD_MspInit is to be implemented in the user file
00326    */
00327 }
00328 
00329 /**
00330   * @}
00331   */
00332 
00333 /** @defgroup LCD_Exported_Functions_Group2 IO operation methods
00334   *  @brief LCD RAM functions
00335   *
00336 @verbatim
00337  ===============================================================================
00338                       ##### IO operation functions #####
00339  ===============================================================================
00340  [..] Using its double buffer memory the LCD controller ensures the coherency of the
00341  displayed information without having to use interrupts to control LCD_RAM
00342  modification.
00343  The application software can access the first buffer level (LCD_RAM) through
00344  the APB interface. Once it has modified the LCD_RAM using the HAL_LCD_Write() API,
00345  it sets the UDR flag in the LCD_SR register using the HAL_LCD_UpdateDisplayRequest() API.
00346  This UDR flag (update display request) requests the updated information to be
00347  moved into the second buffer level (LCD_DISPLAY).
00348  This operation is done synchronously with the frame (at the beginning of the
00349  next frame), until the update is completed, the LCD_RAM is write protected and
00350  the UDR flag stays high.
00351  Once the update is completed another flag (UDD - Update Display Done) is set and
00352  generates an interrupt if the UDDIE bit in the LCD_FCR register is set.
00353  The time it takes to update LCD_DISPLAY is, in the worst case, one odd and one
00354  even frame.
00355  The update will not occur (UDR = 1 and UDD = 0) until the display is
00356  enabled (LCDEN = 1).
00357 
00358 @endverbatim
00359   * @{
00360   */
00361 
00362 /**
00363   * @brief  Write a word in the specific LCD RAM.
00364   * @param  hlcd: LCD handle
00365   * @param  RAMRegisterIndex: specifies the LCD RAM Register.
00366   *   This parameter can be one of the following values:
00367   *     @arg LCD_RAM_REGISTER0: LCD RAM Register 0
00368   *     @arg LCD_RAM_REGISTER1: LCD RAM Register 1
00369   *     @arg LCD_RAM_REGISTER2: LCD RAM Register 2
00370   *     @arg LCD_RAM_REGISTER3: LCD RAM Register 3
00371   *     @arg LCD_RAM_REGISTER4: LCD RAM Register 4
00372   *     @arg LCD_RAM_REGISTER5: LCD RAM Register 5
00373   *     @arg LCD_RAM_REGISTER6: LCD RAM Register 6
00374   *     @arg LCD_RAM_REGISTER7: LCD RAM Register 7
00375   *     @arg LCD_RAM_REGISTER8: LCD RAM Register 8
00376   *     @arg LCD_RAM_REGISTER9: LCD RAM Register 9
00377   *     @arg LCD_RAM_REGISTER10: LCD RAM Register 10
00378   *     @arg LCD_RAM_REGISTER11: LCD RAM Register 11
00379   *     @arg LCD_RAM_REGISTER12: LCD RAM Register 12
00380   *     @arg LCD_RAM_REGISTER13: LCD RAM Register 13
00381   *     @arg LCD_RAM_REGISTER14: LCD RAM Register 14
00382   *     @arg LCD_RAM_REGISTER15: LCD RAM Register 15
00383   * @param  RAMRegisterMask: specifies the LCD RAM Register Data Mask.
00384   * @param  Data: specifies LCD Data Value to be written.
00385   * @retval None
00386   */
00387 HAL_StatusTypeDef HAL_LCD_Write(LCD_HandleTypeDef *hlcd, uint32_t RAMRegisterIndex, uint32_t RAMRegisterMask, uint32_t Data)
00388 {
00389   uint32_t tickstart = 0x00;
00390 
00391   if((hlcd->State == HAL_LCD_STATE_READY) || (hlcd->State == HAL_LCD_STATE_BUSY))
00392   {
00393     /* Check the parameters */
00394     assert_param(IS_LCD_RAM_REGISTER(RAMRegisterIndex));
00395 
00396     if(hlcd->State == HAL_LCD_STATE_READY)
00397     {
00398       /* Process Locked */
00399       __HAL_LOCK(hlcd);
00400       hlcd->State = HAL_LCD_STATE_BUSY;
00401 
00402       /* Get timeout */
00403       tickstart = HAL_GetTick();
00404 
00405       /*!< Wait Until the LCD is ready */
00406       while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDR) != RESET)
00407       {
00408         if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
00409         {
00410           hlcd->ErrorCode = HAL_LCD_ERROR_UDR;
00411 
00412           /* Process Unlocked */
00413           __HAL_UNLOCK(hlcd);
00414 
00415           return HAL_TIMEOUT;
00416         }
00417       }
00418     }
00419 
00420     /* Copy the new Data bytes to LCD RAM register */
00421     MODIFY_REG(hlcd->Instance->RAM[RAMRegisterIndex], ~(RAMRegisterMask), Data);
00422 
00423     return HAL_OK;
00424   }
00425   else
00426   {
00427     return HAL_ERROR;
00428   }
00429 }
00430 
00431 /**
00432   * @brief Clear the LCD RAM registers.
00433   * @param hlcd: LCD handle
00434   * @retval None
00435   */
00436 HAL_StatusTypeDef HAL_LCD_Clear(LCD_HandleTypeDef *hlcd)
00437 {
00438   uint32_t tickstart = 0x00;
00439   uint32_t counter = 0;
00440 
00441   if((hlcd->State == HAL_LCD_STATE_READY) || (hlcd->State == HAL_LCD_STATE_BUSY))
00442   {
00443     /* Process Locked */
00444     __HAL_LOCK(hlcd);
00445 
00446     hlcd->State = HAL_LCD_STATE_BUSY;
00447 
00448     /* Get timeout */
00449     tickstart = HAL_GetTick();
00450 
00451     /*!< Wait Until the LCD is ready */
00452     while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDR) != RESET)
00453     {
00454       if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
00455       {
00456         hlcd->ErrorCode = HAL_LCD_ERROR_UDR;
00457 
00458         /* Process Unlocked */
00459         __HAL_UNLOCK(hlcd);
00460 
00461         return HAL_TIMEOUT;
00462       }
00463     }
00464     /* Clear the LCD_RAM registers */
00465     for(counter = LCD_RAM_REGISTER0; counter <= LCD_RAM_REGISTER15; counter++)
00466     {
00467       hlcd->Instance->RAM[counter] = 0;
00468     }
00469 
00470     /* Update the LCD display */
00471     HAL_LCD_UpdateDisplayRequest(hlcd);
00472 
00473     return HAL_OK;
00474   }
00475   else
00476   {
00477     return HAL_ERROR;
00478   }
00479 }
00480 
00481 /**
00482   * @brief  Enable the Update Display Request.
00483   * @param  hlcd: LCD handle
00484   * @note   Each time software modifies the LCD_RAM it must set the UDR bit to
00485   *         transfer the updated data to the second level buffer.
00486   *         The UDR bit stays set until the end of the update and during this
00487   *         time the LCD_RAM is write protected.
00488   * @note   When the display is disabled, the update is performed for all
00489   *         LCD_DISPLAY locations.
00490   *         When the display is enabled, the update is performed only for locations
00491   *         for which commons are active (depending on DUTY). For example if
00492   *         DUTY = 1/2, only the LCD_DISPLAY of COM0 and COM1 will be updated.
00493   * @retval None
00494   */
00495 HAL_StatusTypeDef HAL_LCD_UpdateDisplayRequest(LCD_HandleTypeDef *hlcd)
00496 {
00497   uint32_t tickstart = 0x00;
00498 
00499   /* Clear the Update Display Done flag before starting the update display request */
00500   __HAL_LCD_CLEAR_FLAG(hlcd, LCD_FLAG_UDD);
00501 
00502   /* Enable the display request */
00503   hlcd->Instance->SR |= LCD_SR_UDR;
00504 
00505   /* Get timeout */
00506   tickstart = HAL_GetTick();
00507 
00508   /*!< Wait Until the LCD display is done */
00509   while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDD) == RESET)
00510   {
00511     if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
00512     {
00513       hlcd->ErrorCode = HAL_LCD_ERROR_UDD;
00514 
00515       /* Process Unlocked */
00516       __HAL_UNLOCK(hlcd);
00517 
00518       return HAL_TIMEOUT;
00519     }
00520   }
00521 
00522   hlcd->State = HAL_LCD_STATE_READY;
00523 
00524   /* Process Unlocked */
00525   __HAL_UNLOCK(hlcd);
00526 
00527   return HAL_OK;
00528 }
00529 
00530 /**
00531   * @}
00532   */
00533 
00534 /** @defgroup LCD_Exported_Functions_Group3 Peripheral State methods
00535   *  @brief   LCD State functions
00536   *
00537 @verbatim
00538  ===============================================================================
00539                       ##### Peripheral State functions #####
00540  ===============================================================================
00541     [..]
00542      This subsection provides a set of functions allowing to control the LCD:
00543       (+) HAL_LCD_GetState() API can be helpful to check in run-time the state of the LCD peripheral State.
00544       (+) HAL_LCD_GetError() API to return the LCD error code.
00545 @endverbatim
00546   * @{
00547   */
00548 
00549 /**
00550   * @brief Return the LCD handle state.
00551   * @param hlcd: LCD handle
00552   * @retval HAL state
00553   */
00554 HAL_LCD_StateTypeDef HAL_LCD_GetState(LCD_HandleTypeDef *hlcd)
00555 {
00556   /* Return LCD handle state */
00557   return hlcd->State;
00558 }
00559 
00560 /**
00561   * @brief Return the LCD error code.
00562   * @param hlcd: LCD handle
00563   * @retval LCD Error Code
00564   */
00565 uint32_t HAL_LCD_GetError(LCD_HandleTypeDef *hlcd)
00566 {
00567   return hlcd->ErrorCode;
00568 }
00569 
00570 /**
00571   * @}
00572   */
00573 
00574 /**
00575   * @}
00576   */
00577 
00578 /** @defgroup LCD_Private_Functions LCD Private Functions
00579   * @{
00580   */
00581 
00582 /**
00583   * @brief  Wait until the LCD FCR register is synchronized in the LCDCLK domain.
00584   *   This function must be called after any write operation to LCD_FCR register.
00585   * @retval None
00586   */
00587 HAL_StatusTypeDef LCD_WaitForSynchro(LCD_HandleTypeDef *hlcd)
00588 {
00589   uint32_t tickstart = 0x00;
00590 
00591   /* Get timeout */
00592   tickstart = HAL_GetTick();
00593 
00594   /* Loop until FCRSF flag is set */
00595   while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_FCRSF) == RESET)
00596   {
00597     if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE)
00598     {
00599       hlcd->ErrorCode = HAL_LCD_ERROR_FCRSF;
00600       return HAL_TIMEOUT;
00601     }
00602   }
00603 
00604   return HAL_OK;
00605 }
00606 
00607 /**
00608   * @}
00609   */
00610 
00611 /**
00612   * @}
00613   */
00614 
00615 #endif /* HAL_LCD_MODULE_ENABLED */
00616 
00617 /**
00618   * @}
00619   */
00620 
00621 #endif /* STM32L433xx || STM32L443xx || STM32L476xx || STM32L486xx || STM32L496xx || STM32L4A6xx */
00622 
00623 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00624