BGLInterface.c 7.61 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

/*#include "bt_pwm_driver.h"*/
#include "TimerB.h"

#include "BackgroundLight.h"
/*#include "DriverPWM.h"*/

#include "BGLInterface.h"
BL_STATE_PARA BLStatePara;
uint16_t CurLcdBackLightCycle;
/*Comfort 指针仪表
 类型 白天 傍晚 夜晚
 背光等级 不同仪表配置不同
*/

const uint16_t BackLightValue_TFT_Default[BL_TYPE_TOTAL][BL_LV_TOTAL] =
hu's avatar
hu committed
17
    {
hu's avatar
hu committed
18

hu's avatar
hu committed
19 20 21
        {50, 113, 177, 240, 303, 368, 430, 493, 557, 620, 683, 747, 810, 873, 937, 1000},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {3, 8, 15, 23, 43, 68, 98, 130, 170, 212, 267, 323, 385, 450, 523, 600},
hu's avatar
hu committed
22 23 24 25 26

};

/*¡°BackLightValue_DIAL¡± corresponds to ¡°Pointer¡±*/
const uint16_t BackLightValue_DIAL_Default[BL_TYPE_TOTAL][BL_LV_TOTAL] =
hu's avatar
hu committed
27 28 29 30
    {
        {50, 113, 177, 240, 303, 368, 430, 493, 557, 620, 683, 747, 810, 873, 937, 1000},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {3, 8, 15, 23, 43, 68, 98, 130, 170, 212, 267, 323, 385, 450, 523, 600},
hu's avatar
hu committed
31 32 33 34 35 36 37 38 39

};

/*Comfort 断码仪表
 主题 不同仪表配置不同
 类型 白天 傍晚 夜晚
 背光等级 不同仪表配置不同
*/
const uint16_t BackLightValue_R_Default[BL_THEME_TOTAL][BL_TYPE_TOTAL][BL_LV_TOTAL] =
hu's avatar
hu committed
40 41 42 43 44 45 46 47 48 49
    {
        {{20, 70, 140, 210, 280, 350, 400, 470, 540, 610, 680, 680},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
        {{10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 100},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
        {{5, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 50},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}};
hu's avatar
hu committed
50 51

const uint8_t PwmChannel[BACKLIGHT_TOTAL] =
hu's avatar
hu committed
52 53
    /*  TFT             表盘 */
    {TIMERB_2_CH1, TIMERB_0_CH15};
hu's avatar
hu committed
54
/**@brief Back Ground  Light Config function
hu's avatar
hu committed
55 56 57 58 59 60
 * @author TYW
 * @param[in] BGLType  背光类型
 * @param[in] DutyVal  占空比
 * @since 1.0.0.0
 */
void BGLPwm_Config(uint8_t BGLType, uint16_t DutyVal)
hu's avatar
hu committed
61 62 63 64
{
    /*Pwm_Config(2, CurLcdBackLightCycle, DutyVal);*/
    if (PwmChannel[BGLType] != 255u)
    {
hu's avatar
hu committed
65
        TimerB_PWM_Channel_Duty_Set(PwmChannel[BGLType], DutyVal);
hu's avatar
hu committed
66 67 68 69 70 71 72
    }
    else
    {
        ;
    }
}
/**@brief Back Ground  Light Stop function
hu's avatar
hu committed
73 74 75 76
 * @author TYW
 * @param[in] BGLType 背光类型
 * @since 1.0.0.0
 */
hu's avatar
hu committed
77

hu's avatar
hu committed
78
void BGLPwm_Stop(uint8_t BGLType)
hu's avatar
hu committed
79
{
hu's avatar
hu committed
80

hu's avatar
hu committed
81 82 83 84 85 86 87 88 89 90
    if (PwmChannel[BGLType] != 255u)
    {
        TimerB_PWM_Channel_Stop(PwmChannel[BGLType]);
    }
    else
    {
        ;
    }
}
/**@brief Back Ground  Light Start function
hu's avatar
hu committed
91 92 93 94 95
 * @author TYW
 * @param[in] BGLType 背光类型
 * @since 1.0.0.0
 */
void BGLPwm_Start(uint8_t BGLType)
hu's avatar
hu committed
96
{
hu's avatar
hu committed
97

hu's avatar
hu committed
98 99 100 101 102 103 104 105 106 107
    if (PwmChannel[BGLType] != 255u)
    {
        TimerB_PWM_Channel_Start(PwmChannel[BGLType]);
    }
    else
    {
        ;
    }
}
/**@brief Back Ground  Light Schedu function
hu's avatar
hu committed
108 109 110 111 112 113
 * @author TYW
 * @param[in] BGLTheme 背光主题
 * @param[in] BGLType  背光类型
 * @param[in] BGLLvl   背光等级
 * @since 1.0.0.0
 */
hu's avatar
hu committed
114 115
BL_USER_PARA BL_Tmp_PARA;
uint8_t testBL;
hu's avatar
hu committed
116
void BackLightSchedu(uint8_t BGLPowerSt, uint8_t WakeFlag)
hu's avatar
hu committed
117 118 119 120 121
{

    CurLcdBackLightCycle = BACKLIGHTCYCLE;
    BL_Tmp_PARA.BL_User_PowerSt = BGLPowerSt;
    BL_Tmp_PARA.BL_User_WakeFlag = WakeFlag;
hu's avatar
hu committed
122 123 124
    BLStatePara.BL_User_Lvl_Total = BL_LV_TOTAL;
    BLStatePara.BL_User_NTC_AD_MAX = NTC_AD_MAX;
    BLStatePara.BL_User_effect = testBL;
hu's avatar
hu committed
125 126 127 128
    if (BLStatePara.BL_User_Lvl < BL_LV_TOTAL)
    {
        BL_Tmp_PARA.BL_User_TFTDuty = BackLightValue_TFT_Default[BLStatePara.BL_User_Type][BLStatePara.BL_User_Lvl];
        BL_Tmp_PARA.BL_User_GaugesDuty = BackLightValue_DIAL_Default[BLStatePara.BL_User_Type][BLStatePara.BL_User_Lvl];
hu's avatar
hu committed
129 130 131
        // BL_Tmp_PARA.BL_User_RDuty = BackLightValue_R_Default[BLStatePara.BL_User_Theme][BLStatePara.BL_User_Type][BLStatePara.BL_User_Lvl];
        // BL_Tmp_PARA.BL_User_GDuty = BackLightValue_G_Default[BLStatePara.BL_User_Theme][BLStatePara.BL_User_Type][BLStatePara.BL_User_Lvl];
        // BL_Tmp_PARA.BL_User_BDuty = BackLightValue_B_Default[BLStatePara.BL_User_Theme][BLStatePara.BL_User_Type][BLStatePara.BL_User_Lvl];
hu's avatar
hu committed
132 133 134

        BL_Tmp_PARA.BL_User_TFTDuty_MIN = BackLightValue_TFT_Default[BLStatePara.BL_User_Type][BL_LV_MIN];
        BL_Tmp_PARA.BL_User_GaugesDuty_MIN = BackLightValue_DIAL_Default[BLStatePara.BL_User_Type][BL_LV_MIN];
hu's avatar
hu committed
135 136 137
        // BL_Tmp_PARA.BL_User_RDuty_MIN = BackLightValue_R_Default[BLStatePara.BL_User_Theme][BLStatePara.BL_User_Type][BL_LV_MIN];
        // BL_Tmp_PARA.BL_User_GDuty_MIN = BackLightValue_G_Default[BLStatePara.BL_User_Theme][BLStatePara.BL_User_Type][BL_LV_MIN];
        // BL_Tmp_PARA.BL_User_BDuty_MIN = BackLightValue_B_Default[BLStatePara.BL_User_Theme][BLStatePara.BL_User_Type][BL_LV_MIN];
hu's avatar
hu committed
138 139 140 141 142 143 144
    }
    else
    {
        ;
    }
#if COLOR_LED_DEBUG
    DebugBGLPara();
hu's avatar
hu committed
145
#endif
hu's avatar
hu committed
146 147 148 149
    BackLightDeal(BL_Tmp_PARA, BLStatePara);
}

/**@brief Get Ground  Light Theme function
hu's avatar
hu committed
150 151 152 153 154
 * @author TYW
 * @param[in] BGLTheme 背光主题
 * @since 1.0.0.0
 */
void GetBGLTheme(uint8_t BGLTheme)
hu's avatar
hu committed
155 156 157 158 159
{
    BLStatePara.BL_User_Theme = BGLTheme;
}

/**@brief Get Ground  Light Type function
hu's avatar
hu committed
160 161 162 163 164
 * @author TYW
 * @param[in] BGLType 背光类型 白天 傍晚 晚上
 * @since 1.0.0.0
 */
void GetBGLType(uint8_t BGLType)
hu's avatar
hu committed
165 166 167 168 169
{
    BLStatePara.BL_User_Type = BGLType;
}

/**@brief Get Ground  Light Level function
hu's avatar
hu committed
170 171 172 173 174 175
 * @author TYW
 * @param[in] BGLTheme 背光等级
 * @param[in] PositionLight 小灯触发 1是小灯触发 0是关闭
 * @since 1.0.0.0
 */
void GetBGLLvl(uint8_t BGLLvl, uint8_t FunPositionLight)
hu's avatar
hu committed
176 177 178 179 180 181 182 183 184 185 186
{
    uint8_t tmpLvl;
    tmpLvl = 0u;
    if (FunPositionLight)
    {
        tmpLvl = ProcessLittleLight(BGLLvl);
    }
    else
    {
        tmpLvl = BGLLvl;
    }
hu's avatar
hu committed
187
    BLStatePara.BL_User_Lvl = tmpLvl;
hu's avatar
hu committed
188 189
}
/**@brief Get Ground  Light Little Light function
hu's avatar
hu committed
190 191 192 193 194
 * @author TYW
 * @param[in] BGLTheme 背光等级
 * @since 1.0.0.0
 */
uint8_t ProcessLittleLight(uint8_t BGLLvl)
hu's avatar
hu committed
195 196
{
    uint16_t tmpLvl;
hu's avatar
hu committed
197
    tmpLvl = BGLLvl;
hu's avatar
hu committed
198 199 200 201 202 203 204 205 206 207 208 209
    tmpLvl = tmpLvl * POSITION_LIGHT_PERCENT / 100u;
    if ((uint8_t)tmpLvl < BL_LV_2)
    {
        tmpLvl = BL_LV_2;
    }
    else
    {
        ;
    }
    return (uint8_t)tmpLvl;
}
/**@brief Get Ground  Light NTCval function
hu's avatar
hu committed
210 211 212 213 214
 * @author TYW
 * @param[in] BGLNTCADVal 热敏电阻电压值
 * @since 1.0.0.0
 */
void GetBGLNTCVol(uint16_t BGLNTCVol)
hu's avatar
hu committed
215
{
hu's avatar
hu committed
216
    BLStatePara.BL_User_NTC_AD = BGLNTCVol;
hu's avatar
hu committed
217 218
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
219 220 221 222
 * @author TYW
 * @调试背光用传递占空比参数用于调整背后亮度和颜色
 * @since 1.0.0.0
 */
hu's avatar
hu committed
223 224 225 226 227 228
#if COLOR_LED_DEBUG
uint16_t DebugTFTDuty;
uint16_t DebugGaugesDuty;
uint16_t DebugRDuty;
uint16_t DebugGDuty;
uint16_t DebugBDuty;
hu's avatar
hu committed
229
void DebugBGLPara(void)
hu's avatar
hu committed
230 231
{

hu's avatar
hu committed
232
    BL_Tmp_PARA.BL_User_TFTDuty = DebugTFTDuty;
hu's avatar
hu committed
233 234 235 236 237 238
    BL_Tmp_PARA.BL_User_GaugesDuty = DebugGaugesDuty;
    BL_Tmp_PARA.BL_User_RDuty = DebugRDuty;
    BL_Tmp_PARA.BL_User_GDuty = DebugGDuty;
    BL_Tmp_PARA.BL_User_BDuty = DebugBDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
239 240 241 242 243
 * @author TYW
 * @param[in] TestTFTDuty TFT占空比
 * @since 1.0.0.0
 */
void SetTFTDebugPara(uint16_t TestTFTDuty)
hu's avatar
hu committed
244 245 246 247
{
    DebugTFTDuty = TestTFTDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
248 249 250 251 252
 * @author TYW
 * @param[in] TestGaugesDuty Gauges占空比
 * @since 1.0.0.0
 */
void SetGaugesDebugPara(uint16_t TestGaugesDuty)
hu's avatar
hu committed
253 254 255 256
{
    DebugGaugesDuty = TestGaugesDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
257 258 259 260 261
 * @author TYW
 * @param[in] TestRDuty RED占空比
 * @since 1.0.0.0
 */
void SetRDebugPara(uint16_t TestRDuty)
hu's avatar
hu committed
262 263 264 265
{
    DebugRDuty = TestRDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
266 267 268 269 270
 * @author TYW
 * @param[in] TestGDuty Green占空比
 * @since 1.0.0.0
 */
void SetGDebugPara(uint16_t TestGDuty)
hu's avatar
hu committed
271 272 273 274
{
    DebugGDuty = TestGDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
275 276 277 278 279
 * @author TYW
 * @param[in] TestBDuty Blue占空比
 * @since 1.0.0.0
 */
void SetGDebugPara(uint16_t TestBDuty)
hu's avatar
hu committed
280 281 282
{
    DebugBDuty = TestBDuty;
}
hu's avatar
hu committed
283
#endif