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.
Diff: targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_lcd.c
- Revision:
- 489:119543c9f674
- Parent:
- 387:643a59b3dbac
--- a/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_lcd.c Thu Mar 05 13:15:07 2015 +0000 +++ b/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_lcd.c Thu Mar 12 14:30:49 2015 +0000 @@ -2,8 +2,8 @@ ****************************************************************************** * @file stm32l0xx_hal_lcd.c * @author MCD Application Team - * @version V1.1.0 - * @date 18-June-2014 + * @version V1.2.0 + * @date 06-February-2015 * @brief LCD Controller HAL module driver. * This file provides firmware functions to manage the following * functionalities of the LCD Controller (LCD) peripheral: @@ -21,10 +21,8 @@ (#) Initialize the LCD low level resources by implement the HAL_LCD_MspInit() API: (##) Enable the LCDCLK (same as RTCCLK): to configure the RTCCLK/LCDCLK, proceed as follows: - (+) Enable the Power Controller (PWR) APB1 interface clock using the - __PWR_CLK_ENABLE() macro. - (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. - (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function. + (+) Use RCC function HAL_RCCEx_PeriphCLKConfig in indicating RCC_PERIPHCLK_LCD and + selected clock source (HSE, LSI or LSE) -@- The frequency generator allows you to achieve various LCD frame rates starting from an LCD input clock frequency (LCDCLK) which can vary @@ -66,7 +64,7 @@ ****************************************************************************** * @attention * - * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -96,30 +94,38 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32l0xx_hal.h" +#if defined (STM32L053xx) || defined (STM32L063xx) || defined (STM32L073xx) || defined (STM32L083xx) + /** @addtogroup STM32L0xx_HAL_Driver * @{ */ -/** @defgroup LCD +#ifdef HAL_LCD_MODULE_ENABLED + +/** @defgroup LCD LCD * @brief LCD HAL module driver * @{ */ -#ifdef HAL_LCD_MODULE_ENABLED -#if !defined (STM32L051xx) && !defined (STM32L052xx) && !defined (STM32L062xx) && !defined (STM32L061xx) /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ +/** @defgroup LCD_Private_Defines LCD Private Defines + * @{ + */ #define LCD_TIMEOUT_VALUE 1000 +/** + * @} + */ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ -/** @defgroup LCD_Private_Functions +/** @defgroup LCD_Exported_Functions LCD Exported Functions * @{ */ -/** @defgroup LCD_Group1 Initialization/de-initialization methods +/** @defgroup LCD_Exported_Functions_Group1 Initialization/de-initialization methods * @brief Initialization and Configuration functions * @verbatim @@ -140,7 +146,7 @@ HAL_StatusTypeDef HAL_LCD_DeInit(LCD_HandleTypeDef *hlcd) { /* Check the LCD handle allocation */ - if(hlcd == HAL_NULL) + if(hlcd == NULL) { return HAL_ERROR; } @@ -148,8 +154,20 @@ /* Check the parameters */ assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance)); + /* Check the LCD peripheral state */ + if(hlcd->State == HAL_LCD_STATE_BUSY) + { + return HAL_BUSY; + } + hlcd->State = HAL_LCD_STATE_BUSY; + /* Disable the peripheral */ + __HAL_LCD_DISABLE(hlcd); + + /*Disable Highdrive by default*/ + __HAL_LCD_HIGHDRIVER_DISABLE(hlcd); + /* DeInit the low level hardware */ HAL_LCD_MspDeInit(hlcd); @@ -165,7 +183,8 @@ /** * @brief Initializes the LCD peripheral according to the specified parameters * in the LCD_InitStruct. - * @note This function can be used only when the LCD is disabled. + * @note This function can be used only when the LCD is disabled. + * The LCD HighDrive can be enabled/disabled using related macros up to user. * @param hlcd: LCD handle * @retval None */ @@ -175,7 +194,7 @@ uint8_t counter = 0; /* Check the LCD handle allocation */ - if(hlcd == HAL_NULL) + if(hlcd == NULL) { return HAL_ERROR; } @@ -188,12 +207,12 @@ assert_param(IS_LCD_BIAS(hlcd->Init.Bias)); assert_param(IS_LCD_VOLTAGE_SOURCE(hlcd->Init.VoltageSource)); assert_param(IS_LCD_PULSE_ON_DURATION(hlcd->Init.PulseOnDuration)); + assert_param(IS_LCD_HIGHDRIVE(hlcd->Init.HighDrive)); assert_param(IS_LCD_DEAD_TIME(hlcd->Init.DeadTime)); assert_param(IS_LCD_CONTRAST(hlcd->Init.Contrast)); assert_param(IS_LCD_BLINK_FREQUENCY(hlcd->Init.BlinkFrequency)); assert_param(IS_LCD_BLINK_MODE(hlcd->Init.BlinkMode)); - if(hlcd->State == HAL_LCD_STATE_RESET) { /* Initialize the low level hardware (MSP) */ @@ -212,7 +231,7 @@ hlcd->Instance->RAM[counter] = 0; } /* Enable the display request */ - hlcd->Instance->SR |= LCD_SR_UDR; + SET_BIT(hlcd->Instance->SR, LCD_SR_UDR); /* Configure the LCD Prescaler, Divider, Blink mode and Blink Frequency: Set PS[3:0] bits according to hlcd->Init.Prescaler value @@ -221,22 +240,27 @@ Set BLINKF[2:0] bits according to hlcd->Init.BlinkFrequency value Set DEAD[2:0] bits according to hlcd->Init.DeadTime value Set PON[2:0] bits according to hlcd->Init.PulseOnDuration value - Set CC[2:0] bits according to hlcd->Init.Contrast value */ - hlcd->Instance->FCR = (uint32_t)(hlcd->Init.Prescaler | hlcd->Init.Divider | \ - hlcd->Init.BlinkMode | hlcd->Init.BlinkFrequency | \ - hlcd->Init.DeadTime | hlcd->Init.PulseOnDuration | \ - hlcd->Init.Contrast); + Set CC[2:0] bits according to hlcd->Init.Contrast value + Set HD[0] bit according to hlcd->Init.HighDrive value*/ + + MODIFY_REG(hlcd->Instance->FCR, \ + (LCD_FCR_PS | LCD_FCR_DIV | LCD_FCR_BLINK| LCD_FCR_BLINKF | \ + LCD_FCR_DEAD | LCD_FCR_PON | LCD_FCR_CC), \ + (hlcd->Init.Prescaler | hlcd->Init.Divider | hlcd->Init.BlinkMode | hlcd->Init.BlinkFrequency | \ + hlcd->Init.DeadTime | hlcd->Init.PulseOnDuration | hlcd->Init.Contrast | hlcd->Init.HighDrive)); + /* Wait until LCD Frame Control Register Synchronization flag (FCRSF) is set in the LCD_SR register This bit is set by hardware each time the LCD_FCR register is updated in the LCDCLK domain. It is cleared by hardware when writing to the LCD_FCR register.*/ LCD_WaitForSynchro(hlcd); - /* Configure the LCD Duty, Bias, Voltage Source, Dead Time, Pulse On Duration and Contrast: + /* Configure the LCD Duty, Bias, Voltage Source, Dead Time: Set DUTY[2:0] bits according to hlcd->Init.Duty value Set BIAS[1:0] bits according to hlcd->Init.Bias value Set VSEL bits according to hlcd->Init.VoltageSource value */ - hlcd->Instance->CR = (uint32_t)(hlcd->Init.Duty | hlcd->Init.Bias | \ - hlcd->Init.VoltageSource); + MODIFY_REG(hlcd->Instance->CR, \ + (LCD_CR_DUTY | LCD_CR_BIAS | LCD_CR_VSEL), \ + (hlcd->Init.Duty | hlcd->Init.Bias | hlcd->Init.VoltageSource)); /* Enable the peripheral */ __HAL_LCD_ENABLE(hlcd); @@ -245,11 +269,11 @@ tickstart = HAL_GetTick(); /* Wait Until the LCD is enabled */ - while((hlcd->Instance->SR & LCD_FLAG_ENS) == (uint32_t)RESET) + while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_ENS) == RESET) { if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE) { - hlcd->ErrorCode = HAL_LCD_ERROR_ENS; + hlcd->ErrorCode = HAL_LCD_ERROR_ENS; return HAL_TIMEOUT; } } @@ -258,11 +282,11 @@ tickstart = HAL_GetTick(); /*!< Wait Until the LCD Booster is ready */ - while((hlcd->Instance->SR & LCD_FLAG_RDY) == (uint32_t)RESET) + while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_RDY) == RESET) { if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE) { - hlcd->ErrorCode = HAL_LCD_ERROR_RDY; + hlcd->ErrorCode = HAL_LCD_ERROR_RDY; return HAL_TIMEOUT; } } @@ -302,7 +326,7 @@ * @} */ -/** @defgroup LCD_Group2 IO operation methods +/** @defgroup LCD_Exported_Functions_Group2 IO operation methods * @brief LCD RAM functions * @verbatim @@ -354,6 +378,11 @@ * @arg LCD_RAM_REGISTER15: LCD RAM Register 15 * @param RAMRegisterMask: specifies the LCD RAM Register Data Mask. * @param Data: specifies LCD Data Value to be written. + * @note For LCD glass COM*SEG as 8*40 for example, the LCD common terminals COM[0,7] + * are mapped on 32bits LCD_RAM_REGISTER[0,14] according to rules: COM(n) spread + * on LCD_RAM_REGISTER(2*n) and LCD_RAM_REGISTER(2*n+1).The segment terminals + * SEG[0,39] of COM(n) correspond to LSB bits of related LCD_RAM_REGISTER(2*n)[0,31] + * and LCD_RAM_REGISTER(2*n+1)[0,7] * @retval None */ HAL_StatusTypeDef HAL_LCD_Write(LCD_HandleTypeDef *hlcd, uint32_t RAMRegisterIndex, uint32_t RAMRegisterMask, uint32_t Data) @@ -375,21 +404,19 @@ tickstart = HAL_GetTick(); /*!< Wait Until the LCD is ready */ - while((hlcd->Instance->SR & LCD_FLAG_UDR) != (uint32_t)RESET) + while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDR) != RESET) { if((HAL_GetTick() - tickstart) > LCD_TIMEOUT_VALUE) { hlcd->ErrorCode = HAL_LCD_ERROR_UDR; + /* Process Unlocked */ + __HAL_UNLOCK(hlcd); return HAL_TIMEOUT; } } } - - /* Clear the data bytes position into LCD RAM register */ - hlcd->Instance->RAM[RAMRegisterIndex] &= (uint32_t)RAMRegisterMask; - - /* Copy the new Data bytes to LCD RAM register */ - hlcd->Instance->RAM[RAMRegisterIndex] |= (uint32_t)Data; +/* Copy the new Data bytes to LCD RAM register */ + MODIFY_REG(hlcd->Instance->RAM[RAMRegisterIndex], ~(RAMRegisterMask), Data); return HAL_OK; } @@ -420,11 +447,15 @@ tickstart = HAL_GetTick(); /*!< Wait Until the LCD is ready */ - while((hlcd->Instance->SR & LCD_FLAG_UDR) != (uint32_t)RESET) + while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDR) != RESET) { if( (HAL_GetTick() - tickstart) > LCD_TIMEOUT_VALUE) { - hlcd->ErrorCode = HAL_LCD_ERROR_UDR; + hlcd->ErrorCode = HAL_LCD_ERROR_UDR; + + /* Process Unlocked */ + __HAL_UNLOCK(hlcd); + return HAL_TIMEOUT; } } @@ -473,13 +504,17 @@ tickstart = HAL_GetTick(); /*!< Wait Until the LCD display is done */ - while((hlcd->Instance->SR & LCD_FLAG_UDD) == (uint32_t)RESET) + while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_UDD) == RESET) { - if( (HAL_GetTick() - tickstart) > LCD_TIMEOUT_VALUE) + if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE) { - hlcd->ErrorCode = HAL_LCD_ERROR_UDD; + hlcd->ErrorCode = HAL_LCD_ERROR_UDD; + + /* Process Unlocked */ + __HAL_UNLOCK(hlcd); + return HAL_TIMEOUT; - } + } } hlcd->State = HAL_LCD_STATE_READY; @@ -494,7 +529,7 @@ * @} */ -/** @defgroup LCD_Group3 Peripheral State methods +/** @defgroup LCD_Exported_Functions_Group3 Peripheral State methods * @brief LCD State functions * @verbatim @@ -534,9 +569,17 @@ */ /** + * @} + */ + +/** @defgroup LCD_Private_Functions LCD Private Functions + * @{ + */ + +/** * @brief Waits until the LCD FCR register is synchronized in the LCDCLK domain. * This function must be called after any write operation to LCD_FCR register. - * @param None + * @param hlcd: LCD handle * @retval None */ HAL_StatusTypeDef LCD_WaitForSynchro(LCD_HandleTypeDef *hlcd) @@ -547,7 +590,7 @@ tickstart = HAL_GetTick(); /* Loop until FCRSF flag is set */ - while((hlcd->Instance->SR & LCD_FLAG_FCRSF) == (uint32_t)RESET) + while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_FCRSF) == RESET) { if((HAL_GetTick() - tickstart) > LCD_TIMEOUT_VALUE) { @@ -562,16 +605,16 @@ /** * @} */ -#endif /* STM32L051xx && STM32L052xx && STM32L062xx && STM32L061xx*/ -#endif /* HAL_LCD_MODULE_ENABLED */ + /** * @} */ +#endif /* HAL_LCD_MODULE_ENABLED */ /** * @} */ - +#endif /* #if defined (STM32L053xx) || defined (STM32L063xx) || defined (STM32L073xx) || defined (STM32L083xx) */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/