HAL_LCD.c 11.1 KB
Newer Older
Z
ze9hyr 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
/*
  ******************************************************************************
  * @file    HAL_LCD.c
  * @version V1.0.0
  * @date    2020
  * @brief   LCD HAL module driver.
  *          This file provides firmware functions to manage the following
  *          functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (LCD).
  *           @ Initialization and de-initialization functions
  *           @ IO operation functions
  *           @ Peripheral Control functions
  ******************************************************************************
*/
#include "ACM32Fxx_HAL.h"

/*********************************************************************************
* Function    : HAL_LCD_MspInit
* Description : Initialize the LCD MSP.
* Input       : hcan : pointer to a LCD structure that contains
*                      the configuration information for LCD module
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
__weak void HAL_LCD_MspInit(LCD_HandleTypeDef *hlcd)
{

    /* NOTE : This function only enable lcd clk and config NVIC
    Because lcd's SEG and COM is different,so the gpio of lcd need user config self.*/

    /* Enable LCD clock */
    System_Module_Enable(EN_LCD);
    /* Enable the LCD  Frame interrupt */
    hlcd->Instance->CR1 |= LCD_CR1_IE;
    NVIC_ClearPendingIRQ(LCD_IRQn);
    NVIC_SetPriority(LCD_IRQn, 5);
    NVIC_EnableIRQ(LCD_IRQn);
}

/*********************************************************************************
* Function    : HAL_LCD_MspDeInit
* Description : DeInitialize the LCD MSP.
* Input       : hcan : pointer to a LCD structure that contains
*                      the configuration information for LCD module
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
void HAL_LCD_MspDeInit(LCD_HandleTypeDef *hlcd)
{
    /* Disable LCD clock */
    System_Module_Disable(EN_LCD);
}
/*********************************************************************************
* Function    : HAL_LCD_Init
* Description : Initialize the LCD.
* Input       : hcan : pointer to a LCD structure that contains
*                      the configuration information for LCD module
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_Init(LCD_HandleTypeDef *hlcd)
{
    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
    if(!IS_LCD_DUTY(hlcd->Init.Duty)) return HAL_ERROR;
    if(!IS_LCD_BIAS(hlcd->Init.Bias)) return HAL_ERROR;
    if(!IS_LCD_Driving_Waveform(hlcd->Init.Driving_Waveform)) return HAL_ERROR;
    if(!IS_LCD_BiasSrc(hlcd->Init.BiasSrc)) return HAL_ERROR;
    if(!IS_LCD_DisplayMode(hlcd->Init.DisplayMode)) return HAL_ERROR;

    if(!IS_LCD_LCDFrequency(hlcd->Init.LCDFrequency)) return HAL_ERROR;
    if(!IS_LCD_BlinkEN(hlcd->Init.BlinkEN)) return HAL_ERROR;
    if(!IS_LCD_BlinkFrequency(hlcd->Init.BlinkFrequency)) return HAL_ERROR;

    /* Reset the RST_LCD */
    System_Module_Reset(RST_LCD);
    HAL_LCD_MspInit(hlcd);
    hlcd->Instance->CR0|=(LCD_CR0_LCDEN|hlcd->Init.LCDFrequency|hlcd->Init.Bias|hlcd->Init.Duty|hlcd->Init.BiasSrc|hlcd->Init.Driving_Waveform);
    hlcd->Instance->CR1|=(hlcd->Init.BlinkEN|hlcd->Init.BlinkFrequency|hlcd->Init.DisplayMode);
    if(hlcd->Init.Driving_Waveform==LCD_Driving_Waveform_A)
    {
        hlcd->Instance->CR0&=~(LCD_CR0_WSEL);
    }

    if(hlcd->Init.Duty==LCD_DUTY_STATIC)
    {
        if(!IS_LCD_StaticPower(hlcd->Init.StaticPower)) return HAL_ERROR;
        hlcd->Instance->CR0|=hlcd->Init.StaticPower;
    }
    else
    {
        hlcd->Instance->CR0&=~(LCD_CR0_STATIC);//当DUTY选择非静态时,该位必须设置为0
    }
    return HAL_OK;
}

/*********************************************************************************
* Function    : HAL_LCD_DeInit
* Description : DeInitialize the LCD.
* Input       : hcan : pointer to a LCD structure that contains
*                      the configuration information for LCD module
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_DeInit(LCD_HandleTypeDef *hlcd)
{
    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
    /* Reset the CAN peripheral */
    CLEAR_BIT(hlcd->Instance->CR0, LCD_CR0_LCDEN);

    HAL_LCD_MspDeInit(hlcd);
    /* Return function status */
    return HAL_OK;
}
/*********************************************************************************
* Function    : HAL_LCD_InResConfig
* Description : Initialize the LCD When LCD BiasSrc is LCD_BiasSrc_InRes_Seg31_35_Normal or LCD_BiasSrc_InRes_Seg31_35_Cap.
* Input       : hlcd : pointer to a LCD structure that contains
*                      the configuration information for LCD module
*               LCD_InResInitStruct:LCD_InResInitTypeDef
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_InResConfig(LCD_HandleTypeDef *hlcd,LCD_InResInitTypeDef* LCD_InResInitStruct)
{
    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
    /* Config when BiasSrc is Inside Resistance Mod  */
    if(hlcd->Init.BiasSrc!=LCD_BiasSrc_ExRes_Seg31_35_Cap)
    {
    /* Check the parameters */
    if(!IS_LCD_BiasRes(LCD_InResInitStruct->BiasRes)) return HAL_ERROR;
    if(!IS_LCD_DriveMod(LCD_InResInitStruct->DriveMod)) return HAL_ERROR;
    if(!IS_LCD_FastCharge(LCD_InResInitStruct->FastCharge)) return HAL_ERROR;
    if(!IS_LCD_Contrast(LCD_InResInitStruct->Contrast)) return HAL_ERROR;
    /* Config LCD Contrast and Bias Resistance and DriveMod */
    hlcd->Instance->CR0|=(LCD_InResInitStruct->Contrast);
    hlcd->Instance->CR1|=(LCD_InResInitStruct->BiasRes|LCD_InResInitStruct->DriveMod);

    /* Config LCD PONTime when DriveMod is Fast Charge and Fast Charge(FCC) is Enable. */
    if(LCD_InResInitStruct->FastCharge==LCD_FastCharge_Enable && LCD_InResInitStruct->DriveMod==LCD_DriveMod_FC)
    {
        if(!IS_LCD_PONTime(LCD_InResInitStruct->PONTime)) return HAL_ERROR;
        hlcd->Instance->CR1|=(LCD_InResInitStruct->PONTime<<18);
    }
    }
    return HAL_OK;
}

/*********************************************************************************
* Function    : HAL_LCD_SegComConfig
* Description : Config the LCD SEG and COM enable/disable.
* Input       : hlcd : pointer to a LCD structure that contains
*                      the configuration information for LCD module
*               SegCom:LCD_SegComInitTypeDef
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_SegComConfig(LCD_HandleTypeDef *hlcd,LCD_SegComInitTypeDef *SegCom)
{
    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
    hlcd->Instance->LCD_POEN0=SegCom->SEG0_31;
    hlcd->Instance->LCD_POEN1=SegCom->Stc_SEG32_39_COM0_8.SEG32_39_COM0_8;
    return HAL_OK;
}

/*********************************************************************************
* Function    : HAL_LCD_Write
* Description : Write LCD RAMx.
* Input       : hlcd : pointer to a LCD structure that contains
*                      the configuration information for LCD module
*               LCDRAMIndex:LCD RAM index
*               Data:The data you want to write
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_Write(LCD_HandleTypeDef *hlcd, uint32_t LCDRAMIndex, uint32_t Data)
{
    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
    if(LCDRAMIndex>15) return HAL_ERROR;
    /* Wrete Data bytes to LCD RAM register */
    hlcd->Instance->LCD_RAM[LCDRAMIndex]=Data;
    return HAL_OK;
}

/*********************************************************************************
* Function    : HAL_LCD_Clear
* Description : Clear LCD RAMx.
* Input       : hlcd : pointer to a LCD structure that contains
*                      the configuration information for LCD module
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_Clear(LCD_HandleTypeDef *hlcd)
{
    uint8_t LCDRAMIndex=0;
    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;
    /* Clear the LCD_RAM registers */
    for(LCDRAMIndex = 0; LCDRAMIndex <= 15; LCDRAMIndex++)
    {
        hlcd->Instance->LCD_RAM[LCDRAMIndex] = 0U;
    }
    return HAL_OK;
}

/*********************************************************************************
* Function    : HAL_LCD_Start_DMA
* Description : Start lcd dma transfer
* Input       : hlcd : pointer to a LCD structure that contains
*                      the configuration information for LCD module
*               pData:The data want to transfer
*               Length:transfer Size
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_Start_DMA(LCD_HandleTypeDef *hlcd, uint32_t *pData, uint32_t Length)
{

    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;

    hlcd->Instance->CR1 |= LCD_CR1_DMAEN;

    if (HAL_DMA_Start_IT(hlcd->DMA_Handle,(uint32_t)pData,(uint32_t)(&hlcd->Instance->LCD_RAM[0]), Length))
    {
        return HAL_ERROR;
    }

    return HAL_OK;
}

/*********************************************************************************
* Function    : HAL_LCD_Stop_DMA
* Description : Stop lcd dma transfer
* Input       : hlcd : pointer to a LCD structure that contains
*                      the configuration information for LCD module
*               pData:The data want to transfer
*               Length:transfer Size
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
HAL_StatusTypeDef HAL_LCD_Stop_DMA(LCD_HandleTypeDef *hlcd)
{
    HAL_StatusTypeDef status = HAL_OK;
    /* Check the parameters */
    if(!IS_LCD_PERIPH(hlcd->Instance)) return HAL_ERROR;

    hlcd->Instance->CR1 &=~ LCD_CR1_DMAEN;

    status = HAL_DMA_Abort(hlcd->DMA_Handle);

    return status;
}

/*********************************************************************************
* Function    : HAL_LCD_IRQHandler
* Description : HAL_LCD_IRQHandler
* Input       : hlcd : pointer to a LCD structure that contains
*                      the configuration information for LCD module
* Output      :
* Author      : CWT                         Data : 2020年
**********************************************************************************/
void HAL_LCD_IRQHandler(LCD_HandleTypeDef *hlcd)
{
    hlcd->Instance->INTCLR &=~ (LCD_INTCLR_INTFT);
}