mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Oct 31 11:00:10 2014 +0000
Revision:
376:cb4d9db17537
Synchronized with git revision 07b49da75eac883fc8916d3d6b6962664b8db29e

Full URL: https://github.com/mbedmicro/mbed/commit/07b49da75eac883fc8916d3d6b6962664b8db29e/

Targets: DISCO_L053C8 - new platform - STM32L0 Discovery board

Who changed what in which revision?

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