BGLInterface.c 8.07 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] =
17 18 19 20 21
{
    /*0    1    2    3    4    5    6    7    8    9   10   11   12   13   14    15*/
    {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] =
27 28 29 30 31
{
    /*0    1    2    3    4    5    6    7    8    9   10   11   12   13   14    15*/
    {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
32 33 34 35 36 37 38 39 40

};

/*Comfort 断码仪表
 主题 不同仪表配置不同
 类型 白天 傍晚 夜晚
 背光等级 不同仪表配置不同
*/
const uint16_t BackLightValue_R_Default[BL_THEME_TOTAL][BL_TYPE_TOTAL][BL_LV_TOTAL] =
41 42 43 44 45 46 47 48 49 50 51
{
    {
        {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}
    },
hu's avatar
hu committed
52
    {
53 54 55 56 57
        {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
58 59

const uint8_t PwmChannel[BACKLIGHT_TOTAL] =
60 61 62 63
    /*  TFT             表盘           燃油          水温         水温背光*/
{TIMERB_2_CH1, TIMERB_0_CH15, TIMERB_1_CH15, TIMERB_1_CH10, TIMERB_2_CH7};
//{255, 255, 255, TIMERB_1_CH10, 255};

hu's avatar
hu committed
64
/**@brief Back Ground  Light Config function
hu's avatar
hu committed
65 66 67 68 69 70
 * @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
71 72 73 74
{
    /*Pwm_Config(2, CurLcdBackLightCycle, DutyVal);*/
    if (PwmChannel[BGLType] != 255u)
    {
hu's avatar
hu committed
75
        TimerB_PWM_Channel_Duty_Set(PwmChannel[BGLType], DutyVal);
hu's avatar
hu committed
76 77 78 79 80 81 82
    }
    else
    {
        ;
    }
}
/**@brief Back Ground  Light Stop function
hu's avatar
hu committed
83 84 85 86
 * @author TYW
 * @param[in] BGLType 背光类型
 * @since 1.0.0.0
 */
hu's avatar
hu committed
87

hu's avatar
hu committed
88
void BGLPwm_Stop(uint8_t BGLType)
hu's avatar
hu committed
89
{
hu's avatar
hu committed
90

hu's avatar
hu committed
91 92 93 94 95 96 97 98 99 100
    if (PwmChannel[BGLType] != 255u)
    {
        TimerB_PWM_Channel_Stop(PwmChannel[BGLType]);
    }
    else
    {
        ;
    }
}
/**@brief Back Ground  Light Start function
hu's avatar
hu committed
101 102 103 104 105
 * @author TYW
 * @param[in] BGLType 背光类型
 * @since 1.0.0.0
 */
void BGLPwm_Start(uint8_t BGLType)
hu's avatar
hu committed
106
{
hu's avatar
hu committed
107

hu's avatar
hu committed
108 109 110 111 112 113 114 115 116 117
    if (PwmChannel[BGLType] != 255u)
    {
        TimerB_PWM_Channel_Start(PwmChannel[BGLType]);
    }
    else
    {
        ;
    }
}
/**@brief Back Ground  Light Schedu function
hu's avatar
hu committed
118 119 120 121 122 123
 * @author TYW
 * @param[in] BGLTheme 背光主题
 * @param[in] BGLType  背光类型
 * @param[in] BGLLvl   背光等级
 * @since 1.0.0.0
 */
hu's avatar
hu committed
124 125
BL_USER_PARA BL_Tmp_PARA;
uint8_t testBL;
hu's avatar
hu committed
126
void BackLightSchedu(uint8_t BGLPowerSt, uint8_t WakeFlag)
hu's avatar
hu committed
127 128 129 130 131
{

    CurLcdBackLightCycle = BACKLIGHTCYCLE;
    BL_Tmp_PARA.BL_User_PowerSt = BGLPowerSt;
    BL_Tmp_PARA.BL_User_WakeFlag = WakeFlag;
hu's avatar
hu committed
132 133 134
    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
135 136 137 138
    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
139 140 141
        // 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
142 143 144

        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
145 146 147
        // 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
148 149 150 151 152 153 154
    }
    else
    {
        ;
    }
#if COLOR_LED_DEBUG
    DebugBGLPara();
hu's avatar
hu committed
155
#endif
hu's avatar
hu committed
156 157 158 159
    BackLightDeal(BL_Tmp_PARA, BLStatePara);
}

/**@brief Get Ground  Light Theme function
hu's avatar
hu committed
160 161 162 163 164
 * @author TYW
 * @param[in] BGLTheme 背光主题
 * @since 1.0.0.0
 */
void GetBGLTheme(uint8_t BGLTheme)
hu's avatar
hu committed
165 166 167 168 169
{
    BLStatePara.BL_User_Theme = BGLTheme;
}

/**@brief Get Ground  Light Type function
hu's avatar
hu committed
170 171 172 173 174
 * @author TYW
 * @param[in] BGLType 背光类型 白天 傍晚 晚上
 * @since 1.0.0.0
 */
void GetBGLType(uint8_t BGLType)
hu's avatar
hu committed
175 176 177 178 179
{
    BLStatePara.BL_User_Type = BGLType;
}

/**@brief Get Ground  Light Level function
hu's avatar
hu committed
180 181 182 183 184 185
 * @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
186 187 188 189 190 191 192 193 194 195 196
{
    uint8_t tmpLvl;
    tmpLvl = 0u;
    if (FunPositionLight)
    {
        tmpLvl = ProcessLittleLight(BGLLvl);
    }
    else
    {
        tmpLvl = BGLLvl;
    }
hu's avatar
hu committed
197
    BLStatePara.BL_User_Lvl = tmpLvl;
hu's avatar
hu committed
198 199
}
/**@brief Get Ground  Light Little Light function
hu's avatar
hu committed
200 201 202 203 204
 * @author TYW
 * @param[in] BGLTheme 背光等级
 * @since 1.0.0.0
 */
uint8_t ProcessLittleLight(uint8_t BGLLvl)
hu's avatar
hu committed
205 206
{
    uint16_t tmpLvl;
hu's avatar
hu committed
207
    tmpLvl = BGLLvl;
hu's avatar
hu committed
208 209 210 211 212 213 214 215 216 217 218 219
    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
220 221 222 223 224
 * @author TYW
 * @param[in] BGLNTCADVal 热敏电阻电压值
 * @since 1.0.0.0
 */
void GetBGLNTCVol(uint16_t BGLNTCVol)
hu's avatar
hu committed
225
{
hu's avatar
hu committed
226
    BLStatePara.BL_User_NTC_AD = BGLNTCVol;
hu's avatar
hu committed
227 228
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
229 230 231 232
 * @author TYW
 * @调试背光用传递占空比参数用于调整背后亮度和颜色
 * @since 1.0.0.0
 */
hu's avatar
hu committed
233 234 235 236 237 238
#if COLOR_LED_DEBUG
uint16_t DebugTFTDuty;
uint16_t DebugGaugesDuty;
uint16_t DebugRDuty;
uint16_t DebugGDuty;
uint16_t DebugBDuty;
hu's avatar
hu committed
239
void DebugBGLPara(void)
hu's avatar
hu committed
240 241
{

hu's avatar
hu committed
242
    BL_Tmp_PARA.BL_User_TFTDuty = DebugTFTDuty;
hu's avatar
hu committed
243 244 245 246 247 248
    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
249 250 251 252 253
 * @author TYW
 * @param[in] TestTFTDuty TFT占空比
 * @since 1.0.0.0
 */
void SetTFTDebugPara(uint16_t TestTFTDuty)
hu's avatar
hu committed
254 255 256 257
{
    DebugTFTDuty = TestTFTDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
258 259 260 261 262
 * @author TYW
 * @param[in] TestGaugesDuty Gauges占空比
 * @since 1.0.0.0
 */
void SetGaugesDebugPara(uint16_t TestGaugesDuty)
hu's avatar
hu committed
263 264 265 266
{
    DebugGaugesDuty = TestGaugesDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
267 268 269 270 271
 * @author TYW
 * @param[in] TestRDuty RED占空比
 * @since 1.0.0.0
 */
void SetRDebugPara(uint16_t TestRDuty)
hu's avatar
hu committed
272 273 274 275
{
    DebugRDuty = TestRDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
276 277 278 279 280
 * @author TYW
 * @param[in] TestGDuty Green占空比
 * @since 1.0.0.0
 */
void SetGDebugPara(uint16_t TestGDuty)
hu's avatar
hu committed
281 282 283 284
{
    DebugGDuty = TestGDuty;
}
/**@brief Debug Ground  Light function
hu's avatar
hu committed
285 286 287 288 289
 * @author TYW
 * @param[in] TestBDuty Blue占空比
 * @since 1.0.0.0
 */
void SetGDebugPara(uint16_t TestBDuty)
hu's avatar
hu committed
290 291 292
{
    DebugBDuty = TestBDuty;
}
hu's avatar
hu committed
293
#endif