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

hu's avatar
hu committed
86
void BGLPwm_Stop(uint8_t BGLType)
hu's avatar
hu committed
87
{
hu's avatar
hu committed
88

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

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

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

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

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

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

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

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