Commit f4fc76dc authored by 张金硕's avatar 张金硕

Merge branch 'dev' of http://tyw-server.synology.me:12345/shihao/haojin750tft into jinshuo

parents e0f90aa6 ebcb1966
......@@ -393,6 +393,11 @@
<FileType>5</FileType>
<FilePath>..\..\..\..\Source\System\main.h</FilePath>
</File>
<File>
<FileName>Sys_Scheduler_Lib.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\Source\System\Sys_Scheduler_Lib.c</FilePath>
</File>
<File>
<FileName>Sys_Scheduler.c</FileName>
<FileType>1</FileType>
......@@ -403,11 +408,6 @@
<FileType>5</FileType>
<FilePath>..\..\..\..\Source\System\Sys_Scheduler.h</FilePath>
</File>
<File>
<FileName>Sys_Scheduler_Lib.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\Source\System\Sys_Scheduler_Lib.c</FilePath>
</File>
<File>
<FileName>Sys_Scheduler_Lib.h</FileName>
<FileType>5</FileType>
......
#include "Backlight.h"
#include "BackLight.h"
#include "Components.h"
typedef void (*SetPwm)(Light_uint16_t Pwm);
typedef Light_uint8_t (*SetPwmEnable)(void);
typedef Light_uint8_t (*SetPwmLevel)(void);
typedef Light_uint16_t (*NtcRes)(void);
typedef struct
{
SetPwm SetPwmCbk; /* 设置PWM回调函数 */
SetPwmEnable SetPwmEnCbk; /* 设置PWM使能回调函数 */
SetPwmLevel SetPwmLevelCbk; /* 背光等级回调函数 */
NtcRes NtcResCbk; /* 获取电阻值回调函数 */
} BackLightExtPara;
typedef struct
{
SetPwm SetPwmCbk; /* 设置PWM回调函数 */
SetPwmEnable SetPwmEnCbk; /* 设置PWM使能回调函数 */
SetPwmLevel SetPwmLevelCbk; /* 背光等级回调函数 */
NtcRes NtcResCbk;
Light_uint8_t BacklightEn; /* 背光使能 */
Light_uint16_t BacklightPwm; /* 背光PWM */
Light_uint16_t BacklightLevel; /* 背光等级 */
} _Backlight_Op;
_Backlight_Op Backlight_Operate;
#define BACK_LIGHT_Val_1 (( 100 * Backlight_Operate.BacklightPwm ) / 100 )
#define BACK_LIGHT_Val_2 (( 200 * Backlight_Operate.BacklightPwm ) / 100 )
#define BACK_LIGHT_Val_3 (( 400 * Backlight_Operate.BacklightPwm ) / 100 )
#define BACK_LIGHT_Val_4 (( 600 * Backlight_Operate.BacklightPwm ) / 100 )
#define BACK_LIGHT_Val_5 (( 800 * Backlight_Operate.BacklightPwm ) / 100 )
#define LIGHT_DATA_TIME 10u /*这里填写多长时间采集一个数据,单位ms*/
#define LIGHT_DATA_NUM 20u /*燃油电阻采集数据总数 最大255*/
#define LIGHT_CAL_START 5u /*数据排序后取中间部分计算平均:起始*/
......@@ -45,532 +12,579 @@ Light_uint16_t NtcDataCount;
Light_uint16_t NtcData[LIGHT_DATA_NUM] = {0};
typedef struct
{
Light_uint16_t Temperature; /* 温度 */
Light_uint16_t Resistance; /* 阻值 */
} _st_Backlight;
uint8_t u8Lvl;
uint8_t Pos_Lamp_Sts;
typedef struct
uint16_t u16DialcurDuty;
uint16_t u16DialdestDuty;
uint16_t u16DialDampingTimer;
uint16_t u16TftcurDuty;
uint16_t u16TftdestDuty;
uint16_t u16TftDampingTimer;
uint8_t destFactor;
uint8_t curFactor;
uint16_t Ntc_Timer;
} _Back_Light_Struct;
_Back_Light_Struct g_stBL;
typedef enum
{
Light_uint16_t BacklightLevel; /* 背光等级 */
Light_uint16_t BacklightDuty; /* 背光占空比 */
} _st_BacklightLevel;
#define Backlight_Max 10
#define BacklightLevel_Max 5
_st_Backlight BacklightTable[Backlight_Max] =
{
/*温度 阻值 */
{550, 2708},
{600, 2602},
{650, 2500},
{700, 2043},
{750, 2310},
{800, 2221},
{850, 2136},
{900, 2055},
{950, 1977},
{1000, 1902},
};
_st_BacklightLevel BacklightLevelTable[BacklightLevel_Max] =
{
/*背光等级 背光占空比 */
{1, 100},
{2, 200},
{3, 400},
{4, 600},
{5, 800},
Light_Lvl_0 = 0,
Light_Lvl_1,
Light_Lvl_2,
Light_Lvl_3,
Light_Lvl_4,
Light_Lvl_5,
Light_Lvl_6,
Light_Lvl_Max,
}_BL_LVL_Enum;
void BackLight_Back_PWM_Init(void);
void BackLight_30_Init(void)
{
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
BackLight_Set_Lvl(Light_Lvl_4);
g_stBL.curFactor = 100;
}
void BackLight_15_Init(void)
{
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
g_stBL.curFactor = 100;
}
void BackLight_WakeUp_Init(void)
{
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
g_stBL.curFactor = 100;
}
void BackLight_Sleep_Init(void)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 0);
}
void BackLight_Back_PWM_Init(void)
{
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
}
uint16_t NTCDegreesBoard[] =
{
550,
600,
650,
700,
750,
800,
850,
900,
950,
1000,
};
void Data_Light_Res_service(Light_uint8_t deltaTime)//获取光感阻值,并做平均
uint16_t NTCResBoard[] =
{
uint16_t LightRes = 0;
uint8_t i, j;
uint32_t temp32;
static uint16_t timeCount = 0;
if (timeCount >= LIGHT_DATA_TIME)
27091,
22224,
18323,
15184,
12635,
10566,
8873,
7481,
6337,
5384,
};
/**
* @brief 实现数据的渐变效果
* 该函数用于更新当前值,使其逐渐接近目标值,渐变的步长由step参数控制。同时,通过timer参数来实现一定的延迟效果,
* 仅当计时器达到或超过预设的timedelay时,才会进行一次渐变操作。这有助于平滑数据的变化,避免突变。
* @param cur 当前值的指针,函数将更新这个值
* @param dest 目标值,当前值将逐渐变化到这个值
* @param step 每次变化的步长
* @param timer 计时器的指针,用于实现变化的延迟
* @param timedelay 延迟的时间阈值,当计时器达到或超过这个值时,才会进行变化
*/
void U16_Data_Gradient(Light_uint16_t *cur, Light_uint16_t dest, Light_uint16_t step, Light_uint16_t *timer, const Light_uint16_t timedelay)
{
if (*cur > dest)
{
timeCount = 0;
if (NtcDataCount < LIGHT_DATA_NUM)
if ((*cur - dest) > step)
{
/*获取光敏电阻*/
LightRes = ADC_Read_Signal(ADC_CH_LIGHT_SENSITIVE); // ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if (LightRes < 32000)
if (*timer >= timedelay)
{
if (LightRes % 10 >= 5)
(*cur) -= step;
(*timer) = 0;
}
else
{
LightRes += 5;
(*timer)++;
}
}
else
{
LightRes = 32000;
*cur = dest;
*timer = 0;
}
/*由小到大插入数据*/
for (i = 0; i < NtcDataCount; i++)
}
else
{
if (LightRes < NtcData[i])
if ((dest - *cur) > step)
{
break;
}
if (*timer >= timedelay)
{
(*cur) += step;
(*timer) = 0;
}
for (j = NtcDataCount; j > i; j--)
else
{
NtcData[j] = NtcData[j - 1];
(*timer)++;
}
NtcData[i] = LightRes;
NtcDataCount++;
}
else
{
/*一组数据采集完毕,取中间部分计算平均值*/
temp32 = 0;
for (i = LIGHT_CAL_START; i < LIGHT_CAL_END; i++)
{
temp32 += NtcData[i];
}
LightR = (uint16_t) (temp32 / (LIGHT_CAL_END - LIGHT_CAL_START));
NtcDataCount = 0;
LightADCompleteFlg = 1;
*cur = dest;
*timer = 0;
}
}
timeCount += deltaTime;
if(SYS_OPR_STAT_IGN_ON)
}
uint16_t NTC_Get_Degrees(uint16_t *ResBoard, uint16_t *DegreesBoard, uint8_t size, uint16_t input)
{
uint8_t i = 0;
uint16_t ret = 0;
uint32_t temp = 0;
if(input >= ResBoard[0])
{
if(Menu_Item_Select_Get(MENU_ITEM_SELECT_AUTO))
ret = DegreesBoard[0];
}
else if(input <= ResBoard[size-1])
{
if(LightADCompleteFlg)
ret = DegreesBoard[size-1];
}
else
{
if(LightR <= 800)
for(i=0; i<size-1; i++)
{
LightR_Status_Count++;
if(LightR_Status_Count>=150)
if((input < ResBoard[i] )&&(input >= ResBoard[i+1]))
{
LightR_Status_Count = 0;
LightR_Status = 0;
temp = DegreesBoard[i+1] - DegreesBoard[i];
temp *= (ResBoard[i] - input);
temp /= (ResBoard[i] - ResBoard[i+1]);
temp += DegreesBoard[i];
ret = (uint16_t)temp;
break;
}
}
else if(LightR > 800)
{
LightR_Status_Count++;
if(LightR_Status_Count>=150)
{
LightR_Status_Count = 0;
LightR_Status = 1;
}
return ret;
}
void BackLight_Get_curDuty(void)
{
uint16_t tftBL = 0;
uint16_t dialBL = 0;
uint16_t NTCDegrees = 0;
uint16_t NTCresistance = 0;
uint32_t wtemp = 0;
/* 获取NTC阻值 */
NTCresistance = ADC_Read_Signal(ADC_CH_NTC_TEMP);
/* 计算温度值 */
NTCDegrees = NTC_Get_Degrees(NTCResBoard ,NTCDegreesBoard, sizeof(NTCResBoard)/sizeof(uint16_t), NTCresistance);
if ( NTCDegrees < 650 )
{
g_stBL.destFactor = 100;
}
else if ( NTCDegrees <= 850 )
{
wtemp = (850 - NTCDegrees);
wtemp *= 3;
wtemp += 400;
wtemp /= 10;
g_stBL.destFactor = wtemp;
/* 85°为40%占空比,65°为100%占空比, 1°大概为3% */
}
if(LightR_Status == 0)
else
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_2);
g_stBL.destFactor = 40;
}
if ( (g_stBL.curFactor < g_stBL.destFactor) && (NTCDegrees < 750) )
{
if ( g_stBL.Ntc_Timer <= 400 )
g_stBL.Ntc_Timer++;
else
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_5);
g_stBL.Ntc_Timer = 0;
g_stBL.curFactor++;
}
if ( g_stBL.curFactor >= g_stBL.destFactor )
g_stBL.curFactor = g_stBL.destFactor;
}
else if ( g_stBL.curFactor > g_stBL.destFactor )
{
if ( g_stBL.Ntc_Timer <= 200 )
g_stBL.Ntc_Timer++;
else
{
g_stBL.Ntc_Timer = 0;
g_stBL.curFactor--;
}
else if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_AUTO))
if ( g_stBL.curFactor <= g_stBL.destFactor )
g_stBL.curFactor = g_stBL.destFactor;
}
/* 背光等级 */
switch (g_stBL.u8Lvl)
{
if(Backlight_SetPwmLevel() == 1U)
case Light_Lvl_0:
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_1);
tftBL = 100;
break;
}
else if(Backlight_SetPwmLevel() == 2U)
case Light_Lvl_1:
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_2);
tftBL = 200;
break;
}
else if(Backlight_SetPwmLevel() == 3U)
case Light_Lvl_2:
default:
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_3);
tftBL = 400;
break;
}
else if(Backlight_SetPwmLevel() == 4U)
case Light_Lvl_3:
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_4);
tftBL = 600;
break;
}
else if(Backlight_SetPwmLevel() == 5U)
case Light_Lvl_4:
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_5);
tftBL = 800;
break;
}
}
else
/* 两路PWM的时候再启用 */
#if 0
g_stBL.u16DialdestDuty = ( uint32_t )(( uint32_t )dialBL * ( uint32_t )g_stBL.curFactor / ( uint32_t )100);
if(g_stBL.u16DialdestDuty < 100)
{
BackLight_Process();
g_stBL.u16DialdestDuty = 100;
}
if(g_stBL.u16DialcurDuty < 100)
{
g_stBL.u16DialcurDuty = g_stBL.u16DialdestDuty;
}
else
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 0);
U16_Data_Gradient((uint16_t *)&g_stBL.u16DialcurDuty, g_stBL.u16DialdestDuty, 1u, (uint16_t *)&g_stBL.u16DialDampingTimer, 1u);
}
}
#endif
/* 计算具体应该多少占空比 */
g_stBL.u16TftdestDuty = ( uint32_t )(( uint32_t )tftBL * ( uint32_t )g_stBL.curFactor / ( uint32_t )100);
Light_uint16_t GetBacklightDutyByLevel(Light_uint16_t level)
{
for (Light_uint8_t i = 0; i < BacklightLevel_Max; ++i)
/* 确保目标占空比不小于100 */
if(g_stBL.u16TftdestDuty < 100)
{
if (BacklightLevelTable[i].BacklightLevel == level)
g_stBL.u16TftdestDuty = 100;
}
/* 如果当前占空比小于100,那还是按照上次结果显示 */
if(g_stBL.u16TftcurDuty < 100)
{
return BacklightLevelTable[i].BacklightDuty;
g_stBL.u16TftcurDuty = g_stBL.u16TftdestDuty;
}
/* 逐步逼近目标占空比 */
else
{
U16_Data_Gradient((uint16_t *)&g_stBL.u16TftcurDuty, g_stBL.u16TftdestDuty, 1u, (uint16_t *)&g_stBL.u16DialDampingTimer, 1u);
}
return 0;
}
/* 设置PWM回调函数 */
void Backlight_SetPwm(Light_uint16_t Pwm)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, Pwm);
}
/* 设置PWM使能回调函数 */
Light_uint8_t Backlight_SetPwmEn(void)
#if 0
/* 此项目用不上 */
//10MS
void BackLight_Control(void)
{
uint16_t wtemp = 0;
return 1;
}
/* 背光等级回调函数 */
Light_uint8_t Backlight_SetPwmLevel(void)
{
Light_uint8_t Backlight_PwmLevel;
if(LightR > 0 && LightR <= 400)
{
Backlight_PwmLevel = 1U;
}
else if(LightR > 400 && LightR <= 800)
if(SYS_OPR_STAT_HALT)
{
Backlight_PwmLevel = 2U;
PWM_Channel_Set_Duty(5, 0);
PWM_Channel_Set_Duty(3, 0);
return;
}
else if(LightR > 800 && LightR <= 1400)
if(Get_Core_StartStatus() == Soc_Startup)
{
Backlight_PwmLevel = 3U;
PWM_Channel_Set_Duty(5, 0);
PWM_Channel_Set_Duty(3, 0);
return;
}
else if(LightR > 1400 && LightR <= 2000)
BackLight_Get_curDuty();
if(Common_Get_IG_Sts() == COMMON_POWER_ON)
{
Backlight_PwmLevel = 4U;
PWM_Channel_Set_Duty(5, g_stBL.u16DialcurDuty);
PWM_Channel_Set_Duty(3, g_stBL.u16TftcurDuty);
}
else if(LightR > 2000 && LightR <= 2600)
else
{
Backlight_PwmLevel = 5U;
PWM_Channel_Set_Duty(5, 0);
PWM_Channel_Set_Duty(3, 0);
}
return Backlight_PwmLevel;
}
/* 获取电阻值回调函数 */
Light_uint16_t Backlight_NtcRes(void)
{
Light_uint16_t u8NtcRes = ADC_Read_Signal(ADC_CH_NTC_TEMP);
return u8NtcRes;
}
void Backlight_Init(BackLightExtPara *backlightInit)
#endif
/* 获取当前背光等级 */
uint8_t BackLight_Get_Lvl(void )
{
Backlight_Operate.SetPwmCbk = backlightInit->SetPwmCbk;
Backlight_Operate.SetPwmEnCbk = backlightInit->SetPwmEnCbk;
Backlight_Operate.SetPwmLevelCbk = backlightInit->SetPwmLevelCbk;
Backlight_Operate.NtcResCbk = backlightInit->NtcResCbk;
return g_stBL.u8Lvl;
}
void Backlight_KL30_Wakeup_Init(void)
/* 设置当前背光等级 */
void BackLight_Set_Lvl(Light_uint8_t lvl)
{
BackLightExtPara pFunc;
pFunc.SetPwmCbk = Backlight_SetPwm;
pFunc.SetPwmEnCbk = Backlight_SetPwmEn;
pFunc.SetPwmLevelCbk = Backlight_SetPwmLevel;
pFunc.NtcResCbk = Backlight_NtcRes;
Backlight_Init(&pFunc);
g_stBL.u8Lvl = lvl;
}
/**
* 根据给定的背光表和输入电阻值,获取对应的温度值。
* 这个函数通过线性插值方法在背光表中查找与输入电阻最接近的温度值。
* @param backlightTable 背光表,包含电阻和对应温度的数组。
* @param size 背光表的大小,即数组的元素个数。
* @param input 输入的电阻值。
* @return 返回对应的温度值。
*/
Light_uint16_t Get_Ntc_Temp(_st_Backlight *backlightTable, Light_uint8_t size, Light_uint16_t input)
void Data_Light_Res_service(Light_uint8_t deltaTime)//获取光感阻值,并做平均
{
Light_uint16_t result = 0;
Light_uint32_t temp = 0;
Light_uint8_t i = 0;
if (input >= backlightTable[0].Resistance)
{
result = backlightTable[0].Temperature;
}
else if (input <= backlightTable[size - 1].Resistance)
uint16_t LightRes = 0U;
uint8_t i, j;
uint32_t temp32;
static uint16_t timeCount = 0;
if (timeCount >= LIGHT_DATA_TIME)
{
result = backlightTable[size - 1].Temperature;
}
else
timeCount = 0;
if (NtcDataCount < LIGHT_DATA_NUM)
{
for (i = 0; i < size - 1; i++)
/*获取光敏电阻*/
LightRes = ADC_Read_Signal(ADC_CH_LIGHT_SENSITIVE); // ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if (LightRes < 32000)
{
if ((input < backlightTable[i].Resistance) && (input >= backlightTable[i + 1].Resistance))
if (LightRes % 10 >= 5)
{
temp = backlightTable[i + 1].Temperature - backlightTable[i].Temperature;
temp *= (backlightTable[i].Resistance - input);
temp /= (backlightTable[i].Resistance - backlightTable[i + 1].Resistance);
temp += backlightTable[i].Temperature;
result = (Light_uint16_t)temp;
break;
LightRes += 5;
}
}
else
{
LightRes = 32000;
}
return result;
}
Light_uint16_t Get_Pwm_Factor_Optimized(Light_uint16_t CurrentTemp)
{
if (CurrentTemp >= 900)
/*由小到大插入数据*/
for (i = 0; i < NtcDataCount; i++)
{
return 10;
}
if (CurrentTemp >= 880 && CurrentTemp <= 890)
if (LightRes < NtcData[i])
{
return 20;
break;
}
if (CurrentTemp >= 850 && CurrentTemp <= 860)
{
return 70;
}
if (CurrentTemp >= 800 && CurrentTemp <= 830)
for (j = NtcDataCount; j > i; j--)
{
return 75;
NtcData[j] = NtcData[j - 1];
}
if (CurrentTemp >= 750 && CurrentTemp <= 780)
{
return 80;
NtcData[i] = LightRes;
NtcDataCount++;
}
if (CurrentTemp >= 700 && CurrentTemp <= 730)
else
{
return 85;
}
if (CurrentTemp >= 650 && CurrentTemp <= 680)
/*一组数据采集完毕,取中间部分计算平均值*/
temp32 = 0;
for (i = LIGHT_CAL_START; i < LIGHT_CAL_END; i++)
{
return 90;
temp32 += NtcData[i];
}
if (CurrentTemp >= 600 && CurrentTemp <= 630)
{
return 95;
LightR = (uint16_t) (temp32 / (LIGHT_CAL_END - LIGHT_CAL_START));
NtcDataCount = 0;
LightADCompleteFlg = 1;
}
if (CurrentTemp < 580)
{
return 100;
}
return 100;
timeCount += deltaTime;
}
typedef struct
/* 背光等级回调函数 */
Light_uint8_t Backlight_GetPwmLevel(void)
{
Light_uint8_t destFactor;
Light_uint8_t curFactor;
Light_uint16_t NtcDelayTimer;
Light_uint16_t u16DialcurDuty;
Light_uint16_t u16DialdestDuty;
Light_uint16_t u16DialDampingTimer;
} _st_BacklightFactor_Ctrl;
_st_BacklightFactor_Ctrl BacklightFactorCtrl;
Light_uint8_t Backlight_PwmLevel;
/**
* @brief 实现数据的渐变效果
* 该函数用于更新当前值,使其逐渐接近目标值,渐变的步长由step参数控制。同时,通过timer参数来实现一定的延迟效果,
* 仅当计时器达到或超过预设的timedelay时,才会进行一次渐变操作。这有助于平滑数据的变化,避免突变。
* @param cur 当前值的指针,函数将更新这个值
* @param dest 目标值,当前值将逐渐变化到这个值
* @param step 每次变化的步长
* @param timer 计时器的指针,用于实现变化的延迟
* @param timedelay 延迟的时间阈值,当计时器达到或超过这个值时,才会进行变化
*/
void U16_Data_Gradient(Light_uint16_t *cur, Light_uint16_t dest, Light_uint16_t step, Light_uint16_t *timer, const Light_uint16_t timedelay)
{
if (*cur > dest)
{
if ((*cur - dest) > step)
{
if (*timer >= timedelay)
{
(*cur) -= step;
(*timer) = 0;
}
else
if(LightR > 0 && LightR <= 400)
{
(*timer)++;
}
Backlight_PwmLevel = 1U;
}
else
else if(LightR > 400 && LightR <= 800)
{
*cur = dest;
*timer = 0;
}
Backlight_PwmLevel = 2U;
}
else
{
if ((dest - *cur) > step)
{
if (*timer >= timedelay)
else if(LightR > 800 && LightR <= 1400)
{
(*cur) += step;
(*timer) = 0;
Backlight_PwmLevel = 3U;
}
else
else if(LightR > 1400 && LightR <= 2000)
{
(*timer)++;
}
Backlight_PwmLevel = 4U;
}
else
else if(LightR > 2000 && LightR <= 2600)
{
*cur = dest;
*timer = 0;
}
Backlight_PwmLevel = 5U;
}
return Backlight_PwmLevel;
}
void BackLight_Service(void)
/* 背光服务,10ms调用 */
void BackLight_Process(void)
{
Light_uint16_t CurrentTemp = 0;
Light_uint16_t Factor = 0;
if (Backlight_Operate.NtcResCbk != Backlight_NULL)
if(SYS_OPR_STAT_IGN_ON)
{
CurrentTemp = Get_Ntc_Temp(BacklightTable, sizeof(BacklightTable) / sizeof(Light_uint16_t), Backlight_Operate.NtcResCbk());
}
else
/* 自动模式,判断白天还是黑夜 */
if(Menu_Item_Select_Get(MENU_ITEM_SELECT_AUTO))
{
CurrentTemp = 0XFFFF; /* 无效不执行NTC策略 */
}
/* 根据外部传入背光等级获取对应占空比 */
if (Backlight_Operate.SetPwmLevelCbk != Backlight_NULL)
if(LightADCompleteFlg)
{
if(g_u8Display_Mode == ModeNIGHT)
{
Backlight_Operate.BacklightPwm = GetBacklightDutyByLevel(Backlight_Operate.SetPwmLevelCbk());
LightR_Status = 0U;
}
if (Backlight_Operate.SetPwmEnCbk != Backlight_NULL)
else if(g_u8Display_Mode == ModeDAY)
{
Backlight_Operate.BacklightEn = Backlight_Operate.SetPwmEnCbk();
LightR_Status = 1U;
}
if (Backlight_Operate.BacklightEn == 1)
if(LightR <= 200)
{
if (CurrentTemp != 0XFFFF)
LightR_Status_Count++;
if(LightR_Status_Count>=150)
{
BacklightFactorCtrl.destFactor = Get_Pwm_Factor_Optimized(CurrentTemp);
if ((BacklightFactorCtrl.curFactor < BacklightFactorCtrl.destFactor) && (CurrentTemp <= BacklightTable[0].Temperature))
LightR_Status_Count = 0;
LightR_Status = 0;
}
}
else if(LightR > 200)
{
if (BacklightFactorCtrl.NtcDelayTimer <= 400)
BacklightFactorCtrl.NtcDelayTimer++;
else
LightR_Status_Count++;
if(LightR_Status_Count>=150)
{
BacklightFactorCtrl.NtcDelayTimer = 0;
BacklightFactorCtrl.curFactor++;
LightR_Status_Count = 0;
LightR_Status = 1;
}
if (BacklightFactorCtrl.curFactor >= BacklightFactorCtrl.destFactor)
BacklightFactorCtrl.curFactor = BacklightFactorCtrl.destFactor;
}
else if (BacklightFactorCtrl.curFactor > BacklightFactorCtrl.destFactor)
/* 系统的意思是要当前背光等级基础上的80%和20%,不是直接设置背光 */
/*if(LightR_Status == 0)
{
if (BacklightFactorCtrl.NtcDelayTimer <= 200)
BacklightFactorCtrl.NtcDelayTimer++;
BackLight_Set_Lvl(Light_Lvl_1);
}
else
{
BacklightFactorCtrl.NtcDelayTimer = 0;
BacklightFactorCtrl.curFactor--;
}
if (BacklightFactorCtrl.curFactor <= BacklightFactorCtrl.destFactor)
BacklightFactorCtrl.curFactor = BacklightFactorCtrl.destFactor;
}
BacklightFactorCtrl.u16DialdestDuty = Backlight_Operate.BacklightPwm * BacklightFactorCtrl.curFactor / 100;
if (BacklightFactorCtrl.u16DialdestDuty < 50)
BackLight_Set_Lvl(Light_Lvl_4);
}*/
if(LightR_Status == 0)
{
BacklightFactorCtrl.u16DialdestDuty = 50;
g_u8Display_Mode = ModeNIGHT;
}
if (CurrentTemp <= BacklightTable[0].Temperature)
else if(LightR_Status == 1)
{
BacklightFactorCtrl.u16DialcurDuty = BacklightFactorCtrl.u16DialdestDuty;
g_u8Display_Mode = ModeDAY;
}
else
}
}
/* 根据感光判断当前应该设置什么背光等级 */
else if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_AUTO))
{
if (BacklightFactorCtrl.u16DialcurDuty < 100)
if(Backlight_GetPwmLevel() == 1U)
{
BacklightFactorCtrl.u16DialcurDuty = BacklightFactorCtrl.u16DialdestDuty;
BackLight_Set_Lvl(Light_Lvl_0);
}
else
else if(Backlight_GetPwmLevel() == 2U)
{
U16_Data_Gradient((Light_uint16_t *)&BacklightFactorCtrl.u16DialcurDuty, BacklightFactorCtrl.u16DialdestDuty, 1u, (Light_uint16_t *)&BacklightFactorCtrl.u16DialDampingTimer, 1u);
BackLight_Set_Lvl(Light_Lvl_1);
}
else if(Backlight_GetPwmLevel() == 3U)
{
BackLight_Set_Lvl(Light_Lvl_2);
}
Backlight_Operate.BacklightPwm = BacklightFactorCtrl.u16DialcurDuty;
// Backlight_Operate.SetPwmCbk(Backlight_Operate.BacklightPwm);
else if(Backlight_GetPwmLevel() == 4U)
{
BackLight_Set_Lvl(Light_Lvl_3);
}
else
else if(Backlight_GetPwmLevel() == 5U)
{
/* 无NTC策略 直接根据当前背光等级调整PWM */
Backlight_Operate.BacklightPwm = 100U;
// Backlight_Operate.SetPwmCbk(Backlight_Operate.BacklightPwm);
BackLight_Set_Lvl(Light_Lvl_4);
}
}
/* 菜单设置 */
else
{
Backlight_Operate.BacklightPwm = 100U;
// Backlight_Operate.SetPwmCbk(0);
}
}
void BackLight_Process(void)
{
if(SYS_OPR_STAT_IGN_ON)
{
if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_5) == 1)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, (BACK_LIGHT_Val_5));
BackLight_Set_Lvl(Light_Lvl_4);
}
else if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_4) == 1)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_4);
BackLight_Set_Lvl(Light_Lvl_3);
}
else if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_3) == 1)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_3);
BackLight_Set_Lvl(Light_Lvl_2);
}
else if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_2) == 1)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_2);
BackLight_Set_Lvl(Light_Lvl_1);
}
else if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_1) == 1)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_1);
BackLight_Set_Lvl(Light_Lvl_0);
}
else
{
BackLight_Set_Lvl(Light_Lvl_3);
}
}
/* 数据处理,包括NTC功能 */
BackLight_Get_curDuty();
if(Menu_Item_Select_Get(MENU_ITEM_SELECT_AUTO))
{
uint16_t u16TftPwmBackShow = g_stBL.u16TftcurDuty ;
if(LightR_Status == 0)
{
u16TftPwmBackShow *= 20U;
u16TftPwmBackShow /= 100U;
}
else
{
u16TftPwmBackShow *= 80U;
u16TftPwmBackShow /= 100U;
}
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, u16TftPwmBackShow);
}
else
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_4);
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, g_stBL.u16TftcurDuty);
}
}
else
......
......@@ -22,10 +22,22 @@
#endif /* NULL */
extern Light_uint16_t LightR_Status ;
void Backlight_KL30_Wakeup_Init(void);
void BackLight_Process(void);
Light_uint8_t Backlight_SetPwmLevel(void);
extern void BackLight_Service(void);
extern void BackLight_30_Init(void);
extern void BackLight_15_Init(void);
extern void BackLight_WakeUp_Init(void);
extern void BackLight_Sleep_Init(void);
extern void BackLight_Back_PWM_Init(void);
extern void BackLight_Set_Lvl(Light_uint8_t lvl);
extern void BackLight_Process(void);
extern Light_uint8_t Backlight_GetPwmLevel(void);
......
......@@ -1729,14 +1729,14 @@ void AMT630H_GUI_Display_Mode_Setting(Menu_Item_en_t display_mode) /*图 显示
if(Menu_Item_Select_Get(MENU_ITEM_SELECT_AUTO) == 1)
{
g_u8Display_Mode_select = ModeATUO;
if(LightR_Status == 0)
{
g_u8Display_Mode = ModeNIGHT;
}
else if(LightR_Status == 1)
{
g_u8Display_Mode = ModeDAY;
}
// if(LightR_Status == 0)
// {
// g_u8Display_Mode = ModeNIGHT;
// }
// else if(LightR_Status == 1)
// {
// g_u8Display_Mode = ModeDAY;
// }
}
else
{
......@@ -1887,23 +1887,23 @@ void AMT630H_GUI_Backlight_Setting(Menu_Item_en_t back_mode) /*图 背光*/
if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_AUTO))
{
g_u8Backlight_select = Backlight_ATUO ;
if(Backlight_SetPwmLevel() == 5)
if(Backlight_GetPwmLevel() == 5)
{
g_u8Backlight = Backlight_5;
}
else if(Backlight_SetPwmLevel() == 4)
else if(Backlight_GetPwmLevel() == 4)
{
g_u8Backlight = Backlight_4;
}
else if(Backlight_SetPwmLevel() == 3)
else if(Backlight_GetPwmLevel() == 3)
{
g_u8Backlight = Backlight_3;
}
else if(Backlight_SetPwmLevel() == 2)
else if(Backlight_GetPwmLevel() == 2)
{
g_u8Backlight = Backlight_2;
}
else if(Backlight_SetPwmLevel() == 1)
else if(Backlight_GetPwmLevel() == 1)
{
g_u8Backlight = Backlight_1;
}
......@@ -2048,23 +2048,23 @@ void AMT630H_GUI_Backlight_Setting(Menu_Item_en_t back_mode) /*图 背光*/
if(Menu_Item_Select_Get(MENU_ITEM_BACKLIGHT_AUTO))
{
g_u8Backlight_select = Backlight_ATUO ;
if(Backlight_SetPwmLevel() == 5)
if(Backlight_GetPwmLevel() == 5)
{
g_u8Backlight = Backlight_5;
}
else if(Backlight_SetPwmLevel() == 4)
else if(Backlight_GetPwmLevel() == 4)
{
g_u8Backlight = Backlight_4;
}
else if(Backlight_SetPwmLevel() == 3)
else if(Backlight_GetPwmLevel() == 3)
{
g_u8Backlight = Backlight_3;
}
else if(Backlight_SetPwmLevel() == 2)
else if(Backlight_GetPwmLevel() == 2)
{
g_u8Backlight = Backlight_2;
}
else if(Backlight_SetPwmLevel() == 1)
else if(Backlight_GetPwmLevel() == 1)
{
g_u8Backlight = Backlight_1;
}
......
......@@ -55,11 +55,9 @@ static void Power_KL30_Init(void)
Key_KL30_Init_EXample();
Data_User_Mileage_KL30Init();
Fuel_KL30_Init();
Backlight_KL30_Wakeup_Init();
BackLight_30_Init();
Amt630hInit();
Telltales_Init();
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
g_stRTCInformation.u8RTCSecond = 0;
g_stRTCInformation.u8RTCMinute = 0;
g_stRTCInformation.u8RTCHour = 0;
......@@ -71,7 +69,7 @@ static void Power_KL30_Init(void)
UDS_Startup_Init();
Can_Init();
Protocol_KL30_Wakeup_Init();
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 500);
RTE_DEEPSLEEP_GPIO_Interrupt_Enable(KL15_AD_IN, Trigger_Rising);
FaultCode_Init();
}
......@@ -92,7 +90,7 @@ static void Power_Wakeup_Init(void)
Key_Wakeup_Init_EXample();
Line_In_KL15_ON_Init();
Fuel_KL30_Init();
Backlight_KL30_Wakeup_Init();
BackLight_WakeUp_Init();
RTE_UART_Sleep_Init(UART_CH2);
loc_config.u32UARTChEn = 1U;
loc_config.u32UARTbps = 115200U;
......@@ -101,8 +99,6 @@ static void Power_Wakeup_Init(void)
UART_DeInit(UART2);
RTE_UART_Init(UART_CH2, &loc_config); /* 配置串口,630H上电发送0x0D,但是底板没回复 */
Amt630hInit();
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
Telltales_Init();
Key_KL30_Init_EXample();
Menu_User_WAKEUP();
......@@ -124,7 +120,7 @@ static void Power_OVP_Init(void)
static void Power_IG_OFF_Init(void)
{
Line_In_KL15_OFF_Init();
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 0);
BackLight_15_Init();
}
static void Power_IG_ON_Init(void)
......
......@@ -42,6 +42,7 @@ void Sys_10ms_Tasks(void)
Fuel_R_Cal(10u);
Coolant_R_Cal(10u);
Data_Light_Res_service(10);
BackLight_Process();
}
void Sys_20ms_Tasks(void)
......@@ -52,7 +53,6 @@ void Sys_20ms_Tasks(void)
void Sys_50ms_Tasks(void)
{
BackLight_Service();
Telltales_Management();
UDS_Read_Preconditions();
g_u8Cursor_Posittion = Menu_Get_Current_Cursor_Information();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment