/** * @brief Configures the LCD Blink mode and Blink frequency. * @param LCD_BlinkMode: specifies the LCD blink mode. * This parameter can be one of the following values: * @arg LCD_BlinkMode_Off: Blink disabled * @arg LCD_BlinkMode_SEG0_COM0: Blink enabled on SEG[0], COM[0] (1 pixel) * @arg LCD_BlinkMode_SEG0_AllCOM: Blink enabled on SEG[0], all COM (up to 8 * pixels according to the programmed duty) * @arg LCD_BlinkMode_AllSEG_AllCOM: Blink enabled on all SEG and all COM * (all pixels) * @param LCD_BlinkFrequency: specifies the LCD blink frequency. * This parameter can be one of the following values: * @arg LCD_BlinkFrequency_Div8: The Blink frequency = fLcd/8 * @arg LCD_BlinkFrequency_Div16: The Blink frequency = fLcd/16 * @arg LCD_BlinkFrequency_Div32: The Blink frequency = fLcd/32 * @arg LCD_BlinkFrequency_Div64: The Blink frequency = fLcd/64 * @arg LCD_BlinkFrequency_Div128: The Blink frequency = fLcd/128 * @arg LCD_BlinkFrequency_Div256: The Blink frequency = fLcd/256 * @arg LCD_BlinkFrequency_Div512: The Blink frequency = fLcd/512 * @arg LCD_BlinkFrequency_Div1024: The Blink frequency = fLcd/1024 * @retval None */ void LCD_BlinkConfig(uint32_t LCD_BlinkMode, uint32_t LCD_BlinkFrequency) { /* Check the parameters */ assert_param(IS_LCD_BLINK_MODE(LCD_BlinkMode)); assert_param(IS_LCD_BLINK_FREQUENCY(LCD_BlinkFrequency)); LCD->FCR &= (uint32_t)BLINK_MASK; LCD->FCR |= (uint32_t)(LCD_BlinkMode | LCD_BlinkFrequency); }
/** * @brief Configures the LCD Blink mode. * @param LCD_BlinkMode: Specifies the LCD blink mode. * This parameter can be any of the @ref LCD_BlinkMode_TypeDef enumeration. * @param LCD_BlinkFrequency: Specifies the LCD blink frequency. * This parameter can be any of the @ref LCD_BlinkFrequency_TypeDef enumeration. * @retval None */ void LCD_BlinkConfig(LCD_BlinkMode_TypeDef LCD_BlinkMode, LCD_BlinkFrequency_TypeDef LCD_BlinkFrequency) { /* Check function parameters */ assert_param(IS_LCD_BLINK_MODE(LCD_BlinkMode)); assert_param(IS_LCD_BLINK_FREQUENCY(LCD_BlinkFrequency)); LCD->CR1 &= (uint8_t)(~LCD_CR1_BLINK); /* Clear the blink mode bits */ LCD->CR1 |= (uint8_t)LCD_BlinkMode; /* Config the LCD Blink Mode */ LCD->CR1 &= (uint8_t)(~LCD_CR1_BLINKF); /* Clear the blink frequency bits */ LCD->CR1 |= (uint8_t)LCD_BlinkFrequency; /* Config the LCD Blink Frequency */ }
/** * @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. * The LCD HighDrive can be enabled/disabled using related macros up to user. * @param hlcd: LCD handle * @retval None */ HAL_StatusTypeDef HAL_LCD_Init(LCD_HandleTypeDef *hlcd) { uint32_t tickstart = 0x00; uint8_t counter = 0; /* Check the LCD handle allocation */ if(hlcd == NULL) { return HAL_ERROR; } /* Check function parameters */ assert_param(IS_LCD_ALL_INSTANCE(hlcd->Instance)); assert_param(IS_LCD_PRESCALER(hlcd->Init.Prescaler)); assert_param(IS_LCD_DIVIDER(hlcd->Init.Divider)); assert_param(IS_LCD_DUTY(hlcd->Init.Duty)); 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)); assert_param(IS_LCD_MUXSEGMENT(hlcd->Init.MuxSegment)); if(hlcd->State == HAL_LCD_STATE_RESET) { /* Allocate lock resource and initialize it */ hlcd->Lock = HAL_UNLOCKED; /* Initialize the low level hardware (MSP) */ HAL_LCD_MspInit(hlcd); } hlcd->State = HAL_LCD_STATE_BUSY; /* Disable the peripheral */ __HAL_LCD_DISABLE(hlcd); /* Clear the LCD_RAM registers and enable the display request by setting the UDR bit in the LCD_SR register */ for(counter = LCD_RAM_REGISTER0; counter <= LCD_RAM_REGISTER15; counter++) { hlcd->Instance->RAM[counter] = 0; } /* Enable the display request */ 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 Set DIV[3:0] bits according to hlcd->Init.Divider value Set BLINK[1:0] bits according to hlcd->Init.BlinkMode value 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 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: Set DUTY[2:0] bits according to hlcd->Init.Duty value Set BIAS[1:0] bits according to hlcd->Init.Bias value Set VSEL bit according to hlcd->Init.VoltageSource value Set MUX_SEG bit according to hlcd->Init.MuxSegment value */ MODIFY_REG(hlcd->Instance->CR, \ (LCD_CR_DUTY | LCD_CR_BIAS | LCD_CR_VSEL | LCD_CR_MUX_SEG), \ (hlcd->Init.Duty | hlcd->Init.Bias | hlcd->Init.VoltageSource | hlcd->Init.MuxSegment)); /* Enable the peripheral */ __HAL_LCD_ENABLE(hlcd); /* Get timeout */ tickstart = HAL_GetTick(); /* Wait Until the LCD is enabled */ while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_ENS) == RESET) { if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE) { hlcd->ErrorCode = HAL_LCD_ERROR_ENS; return HAL_TIMEOUT; } } /* Get timeout */ tickstart = HAL_GetTick(); /*!< Wait Until the LCD Booster is ready */ while(__HAL_LCD_GET_FLAG(hlcd, LCD_FLAG_RDY) == RESET) { if((HAL_GetTick() - tickstart ) > LCD_TIMEOUT_VALUE) { hlcd->ErrorCode = HAL_LCD_ERROR_RDY; return HAL_TIMEOUT; } } /* Initialize the LCD state */ hlcd->ErrorCode = HAL_LCD_ERROR_NONE; hlcd->State= HAL_LCD_STATE_READY; return HAL_OK; }