Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
haoJin750TFT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时昊
haoJin750TFT
Commits
f4fc76dc
Commit
f4fc76dc
authored
Sep 21, 2024
by
张金硕
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://tyw-server.synology.me:12345/shihao/haojin750tft
into jinshuo
parents
e0f90aa6
ebcb1966
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
487 additions
and
465 deletions
+487
-465
HaoJin750TFT.uvprojx
.../Project/Cmsemicon/BAT32A279/MDK_ARM/HaoJin750TFT.uvprojx
+5
-5
BackLight.c
Firmware/Source/Application/BackLight.c
+443
-429
BackLight.h
Firmware/Source/Application/BackLight.h
+16
-4
AMT630H_Datas.c
Firmware/Source/Component/AMT630H/AMT630H_Datas.c
+18
-18
PowerManag_user.c
Firmware/Source/Component/PowerManagement/PowerManag_user.c
+4
-8
Sys_Task_List.c
Firmware/Source/System/Sys_Task_List.c
+1
-1
No files found.
Firmware/Project/Cmsemicon/BAT32A279/MDK_ARM/HaoJin750TFT.uvprojx
View file @
f4fc76dc
...
...
@@ -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>
...
...
Firmware/Source/Application/BackLight.c
View file @
f4fc76dc
#include "Back
l
ight.h"
#include "Back
L
ight.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,349 +12,101 @@ Light_uint16_t NtcDataCount;
Light_uint16_t
NtcData
[
LIGHT_DATA_NUM
]
=
{
0
};
typedef
struct
{
Light_uint16_t
Temperature
;
/* 温度 */
Light_uint16_t
Resistance
;
/* 阻值 */
}
_st_Backlight
;
typedef
struct
{
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
},
};
void
Data_Light_Res_service
(
Light_uint8_t
deltaTime
)
//获取光感阻值,并做平均
{
uint16_t
LightRes
=
0
;
uint8_t
i
,
j
;
uint32_t
temp32
;
static
uint16_t
timeCount
=
0
;
if
(
timeCount
>=
LIGHT_DATA_TIME
)
{
timeCount
=
0
;
if
(
NtcDataCount
<
LIGHT_DATA_NUM
)
{
/*获取光敏电阻*/
LightRes
=
ADC_Read_Signal
(
ADC_CH_LIGHT_SENSITIVE
);
// ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if
(
LightRes
<
32000
)
{
if
(
LightRes
%
10
>=
5
)
{
LightRes
+=
5
;
}
}
else
{
LightRes
=
32000
;
}
/*由小到大插入数据*/
for
(
i
=
0
;
i
<
NtcDataCount
;
i
++
)
{
if
(
LightRes
<
NtcData
[
i
])
{
break
;
}
}
for
(
j
=
NtcDataCount
;
j
>
i
;
j
--
)
{
NtcData
[
j
]
=
NtcData
[
j
-
1
];
}
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
;
}
}
timeCount
+=
deltaTime
;
if
(
SYS_OPR_STAT_IGN_ON
)
{
if
(
Menu_Item_Select_Get
(
MENU_ITEM_SELECT_AUTO
))
{
if
(
LightADCompleteFlg
)
{
if
(
LightR
<=
800
)
{
LightR_Status_Count
++
;
if
(
LightR_Status_Count
>=
150
)
{
LightR_Status_Count
=
0
;
LightR_Status
=
0
;
}
}
else
if
(
LightR
>
800
)
{
LightR_Status_Count
++
;
if
(
LightR_Status_Count
>=
150
)
{
LightR_Status_Count
=
0
;
LightR_Status
=
1
;
}
}
if
(
LightR_Status
==
0
)
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_2
);
}
else
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_5
);
}
}
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_AUTO
))
{
if
(
Backlight_SetPwmLevel
()
==
1U
)
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_1
);
}
else
if
(
Backlight_SetPwmLevel
()
==
2U
)
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_2
);
}
else
if
(
Backlight_SetPwmLevel
()
==
3U
)
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_3
);
}
else
if
(
Backlight_SetPwmLevel
()
==
4U
)
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_4
);
}
else
if
(
Backlight_SetPwmLevel
()
==
5U
)
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_5
);
}
}
else
{
BackLight_Process
();
}
}
else
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
0
);
}
}
uint8_t
u8Lvl
;
uint8_t
Pos_Lamp_Sts
;
uint16_t
u16DialcurDuty
;
uint16_t
u16DialdestDuty
;
uint16_t
u16DialDampingTimer
;
uint16_t
u16TftcurDuty
;
uint16_t
u16TftdestDuty
;
uint16_t
u16TftDampingTimer
;
Light_uint16_t
GetBacklightDutyByLevel
(
Light_uint16_t
level
)
{
for
(
Light_uint8_t
i
=
0
;
i
<
BacklightLevel_Max
;
++
i
)
{
if
(
BacklightLevelTable
[
i
].
BacklightLevel
==
level
)
{
return
BacklightLevelTable
[
i
].
BacklightDuty
;
}
}
return
0
;
}
uint8_t
destFactor
;
uint8_t
curFactor
;
uint16_t
Ntc_Timer
;
}
_Back_Light_Struct
;
_Back_Light_Struct
g_stBL
;
/* 设置PWM回调函数 */
void
Backlight_SetPwm
(
Light_uint16_t
Pwm
)
typedef
enum
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
Pwm
);
}
/* 设置PWM使能回调函数 */
Light_uint8_t
Backlight_SetPwmEn
(
void
)
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
)
{
return
1
;
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
;
}
/* 背光等级回调函数 */
Light_uint8_t
Backlight_SetPwmLevel
(
void
)
void
BackLight_15_Init
(
void
)
{
Light_uint8_t
Backlight_PwmLevel
;
if
(
LightR
>
0
&&
LightR
<=
400
)
{
Backlight_PwmLevel
=
1U
;
}
else
if
(
LightR
>
400
&&
LightR
<=
800
)
{
Backlight_PwmLevel
=
2U
;
}
else
if
(
LightR
>
800
&&
LightR
<=
1400
)
{
Backlight_PwmLevel
=
3U
;
}
else
if
(
LightR
>
1400
&&
LightR
<=
2000
)
{
Backlight_PwmLevel
=
4U
;
}
else
if
(
LightR
>
2000
&&
LightR
<=
2600
)
{
Backlight_PwmLevel
=
5U
;
}
return
Backlight_PwmLevel
;
TimerM_PWM_counter_Output_Init
(
TIMERM_COUNTER1
,
20000
,
64000000
);
TimerM_PWM_CH_Output_init
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
ActiveLevel_High
);
g_stBL
.
curFactor
=
100
;
}
/* 获取电阻值回调函数 */
Light_uint16_t
Backlight_NtcRes
(
void
)
void
BackLight_WakeUp_Init
(
void
)
{
Light_uint16_t
u8NtcRes
=
ADC_Read_Signal
(
ADC_CH_NTC_TEMP
);
return
u8NtcRes
;
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
Back
light_Init
(
BackLightExtPara
*
backlightInit
)
void
Back
Light_Sleep_Init
(
void
)
{
Backlight_Operate
.
SetPwmCbk
=
backlightInit
->
SetPwmCbk
;
Backlight_Operate
.
SetPwmEnCbk
=
backlightInit
->
SetPwmEnCbk
;
Backlight_Operate
.
SetPwmLevelCbk
=
backlightInit
->
SetPwmLevelCbk
;
Backlight_Operate
.
NtcResCbk
=
backlightInit
->
NtcResCbk
;
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
0
);
}
void
Backlight_KL30_Wakeup_Init
(
void
)
{
BackLightExtPara
pFunc
;
pFunc
.
SetPwmCbk
=
Backlight_SetPwm
;
pFunc
.
SetPwmEnCbk
=
Backlight_SetPwmEn
;
pFunc
.
SetPwmLevelCbk
=
Backlight_SetPwmLevel
;
pFunc
.
NtcResCbk
=
Backlight_NtcRes
;
Backlight_Init
(
&
pFunc
);
}
/**
* 根据给定的背光表和输入电阻值,获取对应的温度值。
* 这个函数通过线性插值方法在背光表中查找与输入电阻最接近的温度值。
* @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
BackLight_Back_PWM_Init
(
void
)
{
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
)
{
result
=
backlightTable
[
size
-
1
].
Temperature
;
}
else
{
for
(
i
=
0
;
i
<
size
-
1
;
i
++
)
{
if
((
input
<
backlightTable
[
i
].
Resistance
)
&&
(
input
>=
backlightTable
[
i
+
1
].
Resistance
))
{
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
;
}
}
}
return
result
;
TimerM_PWM_counter_Output_Init
(
TIMERM_COUNTER1
,
20000
,
64000000
);
TimerM_PWM_CH_Output_init
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
ActiveLevel_High
);
}
Light_uint16_t
Get_Pwm_Factor_Optimized
(
Light_uint16_t
CurrentTemp
)
uint16_t
NTCDegreesBoard
[]
=
{
if
(
CurrentTemp
>=
900
)
{
return
10
;
}
if
(
CurrentTemp
>=
880
&&
CurrentTemp
<=
890
)
{
return
20
;
}
if
(
CurrentTemp
>=
850
&&
CurrentTemp
<=
860
)
{
return
70
;
}
if
(
CurrentTemp
>=
800
&&
CurrentTemp
<=
830
)
{
return
75
;
}
if
(
CurrentTemp
>=
750
&&
CurrentTemp
<=
780
)
{
return
80
;
}
if
(
CurrentTemp
>=
700
&&
CurrentTemp
<=
730
)
{
return
85
;
}
if
(
CurrentTemp
>=
650
&&
CurrentTemp
<=
680
)
{
return
90
;
}
if
(
CurrentTemp
>=
600
&&
CurrentTemp
<=
630
)
{
return
95
;
}
if
(
CurrentTemp
<
580
)
{
return
100
;
}
return
100
;
}
550
,
600
,
650
,
700
,
750
,
800
,
850
,
900
,
950
,
1000
,
};
typedef
struct
uint16_t
NTCResBoard
[]
=
{
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
;
27091
,
22224
,
18323
,
15184
,
12635
,
10566
,
8873
,
7481
,
6337
,
5384
,
};
/**
* @brief 实现数据的渐变效果
...
...
@@ -443,136 +162,431 @@ void U16_Data_Gradient(Light_uint16_t *cur, Light_uint16_t dest, Light_uint16_t
}
}
void
BackLight_Service
(
void
)
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
])
{
ret
=
DegreesBoard
[
0
];
}
else
if
(
input
<=
ResBoard
[
size
-
1
])
{
ret
=
DegreesBoard
[
size
-
1
];
}
else
{
for
(
i
=
0
;
i
<
size
-
1
;
i
++
)
{
if
((
input
<
ResBoard
[
i
]
)
&&
(
input
>=
ResBoard
[
i
+
1
]))
{
temp
=
DegreesBoard
[
i
+
1
]
-
DegreesBoard
[
i
];
temp
*=
(
ResBoard
[
i
]
-
input
);
temp
/=
(
ResBoard
[
i
]
-
ResBoard
[
i
+
1
]);
temp
+=
DegreesBoard
[
i
];
ret
=
(
uint16_t
)
temp
;
break
;
}
}
}
return
ret
;
}
Light_uint16_t
CurrentTemp
=
0
;
Light_uint16_t
Factor
=
0
;
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% */
}
else
{
g_stBL
.
destFactor
=
40
;
}
if
(
(
g_stBL
.
curFactor
<
g_stBL
.
destFactor
)
&&
(
NTCDegrees
<
750
)
)
{
if
(
g_stBL
.
Ntc_Timer
<=
400
)
g_stBL
.
Ntc_Timer
++
;
else
{
g_stBL
.
Ntc_Timer
=
0
;
g_stBL
.
curFactor
++
;
}
if
(
Backlight_Operate
.
NtcResCbk
!=
Backlight_NULL
)
if
(
g_stBL
.
curFactor
>=
g_stBL
.
destFactor
)
g_stBL
.
curFactor
=
g_stBL
.
destFactor
;
}
else
if
(
g_stBL
.
curFactor
>
g_stBL
.
destFactor
)
{
CurrentTemp
=
Get_Ntc_Temp
(
BacklightTable
,
sizeof
(
BacklightTable
)
/
sizeof
(
Light_uint16_t
),
Backlight_Operate
.
NtcResCbk
());
if
(
g_stBL
.
Ntc_Timer
<=
200
)
g_stBL
.
Ntc_Timer
++
;
else
{
g_stBL
.
Ntc_Timer
=
0
;
g_stBL
.
curFactor
--
;
}
if
(
g_stBL
.
curFactor
<=
g_stBL
.
destFactor
)
g_stBL
.
curFactor
=
g_stBL
.
destFactor
;
}
/* 背光等级 */
switch
(
g_stBL
.
u8Lvl
)
{
case
Light_Lvl_0
:
{
tftBL
=
100
;
break
;
}
case
Light_Lvl_1
:
{
tftBL
=
200
;
break
;
}
case
Light_Lvl_2
:
default:
{
tftBL
=
400
;
break
;
}
case
Light_Lvl_3
:
{
tftBL
=
600
;
break
;
}
case
Light_Lvl_4
:
{
tftBL
=
800
;
break
;
}
}
/* 两路PWM的时候再启用 */
#if 0
g_stBL.u16DialdestDuty = ( uint32_t )(( uint32_t )dialBL * ( uint32_t )g_stBL.curFactor / ( uint32_t )100);
if(g_stBL.u16DialdestDuty < 100)
{
g_stBL.u16DialdestDuty = 100;
}
if(g_stBL.u16DialcurDuty < 100)
{
g_stBL.u16DialcurDuty = g_stBL.u16DialdestDuty;
}
else
{
CurrentTemp
=
0XFFFF
;
/* 无效不执行NTC策略 */
U16_Data_Gradient((uint16_t *)&g_stBL.u16DialcurDuty, g_stBL.u16DialdestDuty, 1u, (uint16_t *)&g_stBL.u16DialDampingTimer, 1u);
}
/* 根据外部传入背光等级获取对应占空比 */
if
(
Backlight_Operate
.
SetPwmLevelCbk
!=
Backlight_NULL
)
#endif
/* 计算具体应该多少占空比 */
g_stBL
.
u16TftdestDuty
=
(
uint32_t
)((
uint32_t
)
tftBL
*
(
uint32_t
)
g_stBL
.
curFactor
/
(
uint32_t
)
100
);
/* 确保目标占空比不小于100 */
if
(
g_stBL
.
u16TftdestDuty
<
100
)
{
g_stBL
.
u16TftdestDuty
=
100
;
}
/* 如果当前占空比小于100,那还是按照上次结果显示 */
if
(
g_stBL
.
u16TftcurDuty
<
100
)
{
Backlight_Operate
.
BacklightPwm
=
GetBacklightDutyByLevel
(
Backlight_Operate
.
SetPwmLevelCbk
())
;
g_stBL
.
u16TftcurDuty
=
g_stBL
.
u16TftdestDuty
;
}
if
(
Backlight_Operate
.
SetPwmEnCbk
!=
Backlight_NULL
)
/* 逐步逼近目标占空比 */
else
{
Backlight_Operate
.
BacklightEn
=
Backlight_Operate
.
SetPwmEnCbk
(
);
U16_Data_Gradient
((
uint16_t
*
)
&
g_stBL
.
u16TftcurDuty
,
g_stBL
.
u16TftdestDuty
,
1u
,
(
uint16_t
*
)
&
g_stBL
.
u16DialDampingTimer
,
1u
);
}
if
(
Backlight_Operate
.
BacklightEn
==
1
)
{
}
if
(
CurrentTemp
!=
0XFFFF
)
{
#if 0
/* 此项目用不上 */
//10MS
void BackLight_Control(void)
{
uint16_t wtemp = 0;
BacklightFactorCtrl
.
destFactor
=
Get_Pwm_Factor_Optimized
(
CurrentTemp
);
if(SYS_OPR_STAT_HALT)
{
PWM_Channel_Set_Duty(5, 0);
PWM_Channel_Set_Duty(3, 0);
return;
}
if
((
BacklightFactorCtrl
.
curFactor
<
BacklightFactorCtrl
.
destFactor
)
&&
(
CurrentTemp
<=
BacklightTable
[
0
].
Temperature
))
{
if
(
BacklightFactorCtrl
.
NtcDelayTimer
<=
400
)
BacklightFactorCtrl
.
NtcDelayTimer
++
;
else
{
BacklightFactorCtrl
.
NtcDelayTimer
=
0
;
BacklightFactorCtrl
.
curFactor
++
;
}
if(Get_Core_StartStatus() == Soc_Startup)
{
PWM_Channel_Set_Duty(5, 0);
PWM_Channel_Set_Duty(3, 0);
return;
}
if
(
BacklightFactorCtrl
.
curFactor
>=
BacklightFactorCtrl
.
destFactor
)
BacklightFactorCtrl
.
curFactor
=
BacklightFactorCtrl
.
destFactor
;
}
else
if
(
BacklightFactorCtrl
.
curFactor
>
BacklightFactorCtrl
.
destFactor
)
{
if
(
BacklightFactorCtrl
.
NtcDelayTimer
<=
200
)
BacklightFactorCtrl
.
NtcDelayTimer
++
;
else
{
BacklightFactorCtrl
.
NtcDelayTimer
=
0
;
BacklightFactorCtrl
.
curFactor
--
;
}
if
(
BacklightFactorCtrl
.
curFactor
<=
BacklightFactorCtrl
.
destFactor
)
BacklightFactorCtrl
.
curFactor
=
BacklightFactorCtrl
.
destFactor
;
}
BackLight_Get_curDuty();
if(Common_Get_IG_Sts() == COMMON_POWER_ON)
{
PWM_Channel_Set_Duty(5, g_stBL.u16DialcurDuty);
PWM_Channel_Set_Duty(3, g_stBL.u16TftcurDuty);
}
else
{
PWM_Channel_Set_Duty(5, 0);
PWM_Channel_Set_Duty(3, 0);
}
}
#endif
/* 获取当前背光等级 */
uint8_t
BackLight_Get_Lvl
(
void
)
{
return
g_stBL
.
u8Lvl
;
}
/* 设置当前背光等级 */
void
BackLight_Set_Lvl
(
Light_uint8_t
lvl
)
{
g_stBL
.
u8Lvl
=
lvl
;
}
BacklightFactorCtrl
.
u16DialdestDuty
=
Backlight_Operate
.
BacklightPwm
*
BacklightFactorCtrl
.
curFactor
/
100
;
if
(
BacklightFactorCtrl
.
u16DialdestDuty
<
50
)
{
BacklightFactorCtrl
.
u16DialdestDuty
=
50
;
}
if
(
CurrentTemp
<=
BacklightTable
[
0
].
Temperature
)
void
Data_Light_Res_service
(
Light_uint8_t
deltaTime
)
//获取光感阻值,并做平均
{
uint16_t
LightRes
=
0U
;
uint8_t
i
,
j
;
uint32_t
temp32
;
static
uint16_t
timeCount
=
0
;
if
(
timeCount
>=
LIGHT_DATA_TIME
)
{
timeCount
=
0
;
if
(
NtcDataCount
<
LIGHT_DATA_NUM
)
{
/*获取光敏电阻*/
LightRes
=
ADC_Read_Signal
(
ADC_CH_LIGHT_SENSITIVE
);
// ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if
(
LightRes
<
32000
)
{
BacklightFactorCtrl
.
u16DialcurDuty
=
BacklightFactorCtrl
.
u16DialdestDuty
;
if
(
LightRes
%
10
>=
5
)
{
LightRes
+=
5
;
}
}
else
{
if
(
BacklightFactorCtrl
.
u16DialcurDuty
<
100
)
{
BacklightFactorCtrl
.
u16DialcurDuty
=
BacklightFactorCtrl
.
u16DialdestDuty
;
}
else
LightRes
=
32000
;
}
/*由小到大插入数据*/
for
(
i
=
0
;
i
<
NtcDataCount
;
i
++
)
{
if
(
LightRes
<
NtcData
[
i
])
{
U16_Data_Gradient
((
Light_uint16_t
*
)
&
BacklightFactorCtrl
.
u16DialcurDuty
,
BacklightFactorCtrl
.
u16DialdestDuty
,
1u
,
(
Light_uint16_t
*
)
&
BacklightFactorCtrl
.
u16DialDampingTimer
,
1u
)
;
break
;
}
}
Backlight_Operate
.
BacklightPwm
=
BacklightFactorCtrl
.
u16DialcurDuty
;
// Backlight_Operate.SetPwmCbk(Backlight_Operate.BacklightPwm);
for
(
j
=
NtcDataCount
;
j
>
i
;
j
--
)
{
NtcData
[
j
]
=
NtcData
[
j
-
1
];
}
NtcData
[
i
]
=
LightRes
;
NtcDataCount
++
;
}
else
{
/* 无NTC策略 直接根据当前背光等级调整PWM */
Backlight_Operate
.
BacklightPwm
=
100U
;
// Backlight_Operate.SetPwmCbk(Backlight_Operate.BacklightPwm);
/*一组数据采集完毕,取中间部分计算平均值*/
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
;
}
}
else
timeCount
+=
deltaTime
;
}
/* 背光等级回调函数 */
Light_uint8_t
Backlight_GetPwmLevel
(
void
)
{
Light_uint8_t
Backlight_PwmLevel
;
if
(
LightR
>
0
&&
LightR
<=
400
)
{
Backlight_Operate
.
BacklightPwm
=
100U
;
// Backlight_Operate.SetPwmCbk(0);
Backlight_PwmLevel
=
1U
;
}
else
if
(
LightR
>
400
&&
LightR
<=
800
)
{
Backlight_PwmLevel
=
2U
;
}
else
if
(
LightR
>
800
&&
LightR
<=
1400
)
{
Backlight_PwmLevel
=
3U
;
}
else
if
(
LightR
>
1400
&&
LightR
<=
2000
)
{
Backlight_PwmLevel
=
4U
;
}
else
if
(
LightR
>
2000
&&
LightR
<=
2600
)
{
Backlight_PwmLevel
=
5U
;
}
return
Backlight_PwmLevel
;
}
/* 背光服务,10ms调用 */
void
BackLight_Process
(
void
)
{
if
(
SYS_OPR_STAT_IGN_ON
)
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
));
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_4
)
==
1
)
/* 自动模式,判断白天还是黑夜 */
if
(
Menu_Item_Select_Get
(
MENU_ITEM_SELECT_AUTO
))
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_4
);
if
(
LightADCompleteFlg
)
{
if
(
g_u8Display_Mode
==
ModeNIGHT
)
{
LightR_Status
=
0U
;
}
else
if
(
g_u8Display_Mode
==
ModeDAY
)
{
LightR_Status
=
1U
;
}
if
(
LightR
<=
200
)
{
LightR_Status_Count
++
;
if
(
LightR_Status_Count
>=
150
)
{
LightR_Status_Count
=
0
;
LightR_Status
=
0
;
}
}
else
if
(
LightR
>
200
)
{
LightR_Status_Count
++
;
if
(
LightR_Status_Count
>=
150
)
{
LightR_Status_Count
=
0
;
LightR_Status
=
1
;
}
}
/* 系统的意思是要当前背光等级基础上的80%和20%,不是直接设置背光 */
/*if(LightR_Status == 0)
{
BackLight_Set_Lvl(Light_Lvl_1);
}
else
{
BackLight_Set_Lvl(Light_Lvl_4);
}*/
if
(
LightR_Status
==
0
)
{
g_u8Display_Mode
=
ModeNIGHT
;
}
else
if
(
LightR_Status
==
1
)
{
g_u8Display_Mode
=
ModeDAY
;
}
}
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_3
)
==
1
)
/* 根据感光判断当前应该设置什么背光等级 */
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_AUTO
))
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_3
);
if
(
Backlight_GetPwmLevel
()
==
1U
)
{
BackLight_Set_Lvl
(
Light_Lvl_0
);
}
else
if
(
Backlight_GetPwmLevel
()
==
2U
)
{
BackLight_Set_Lvl
(
Light_Lvl_1
);
}
else
if
(
Backlight_GetPwmLevel
()
==
3U
)
{
BackLight_Set_Lvl
(
Light_Lvl_2
);
}
else
if
(
Backlight_GetPwmLevel
()
==
4U
)
{
BackLight_Set_Lvl
(
Light_Lvl_3
);
}
else
if
(
Backlight_GetPwmLevel
()
==
5U
)
{
BackLight_Set_Lvl
(
Light_Lvl_4
);
}
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_2
)
==
1
)
/* 菜单设置 */
else
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_2
);
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_1
)
==
1
)
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_5
)
==
1
)
{
BackLight_Set_Lvl
(
Light_Lvl_4
);
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_4
)
==
1
)
{
BackLight_Set_Lvl
(
Light_Lvl_3
);
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_3
)
==
1
)
{
BackLight_Set_Lvl
(
Light_Lvl_2
);
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_2
)
==
1
)
{
BackLight_Set_Lvl
(
Light_Lvl_1
);
}
else
if
(
Menu_Item_Select_Get
(
MENU_ITEM_BACKLIGHT_1
)
==
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
))
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
BACK_LIGHT_Val_1
);
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
{
TimerM_PWM_set_duty
(
TIMERM_COUNTER1
,
TIMERM_CHB
,
0
);
...
...
Firmware/Source/Application/BackLight.h
View file @
f4fc76dc
...
...
@@ -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
);
...
...
Firmware/Source/Component/AMT630H/AMT630H_Datas.c
View file @
f4fc76dc
...
...
@@ -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_
S
etPwmLevel
()
==
5
)
if
(
Backlight_
G
etPwmLevel
()
==
5
)
{
g_u8Backlight
=
Backlight_5
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
4
)
else
if
(
Backlight_
G
etPwmLevel
()
==
4
)
{
g_u8Backlight
=
Backlight_4
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
3
)
else
if
(
Backlight_
G
etPwmLevel
()
==
3
)
{
g_u8Backlight
=
Backlight_3
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
2
)
else
if
(
Backlight_
G
etPwmLevel
()
==
2
)
{
g_u8Backlight
=
Backlight_2
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
1
)
else
if
(
Backlight_
G
etPwmLevel
()
==
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_
S
etPwmLevel
()
==
5
)
if
(
Backlight_
G
etPwmLevel
()
==
5
)
{
g_u8Backlight
=
Backlight_5
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
4
)
else
if
(
Backlight_
G
etPwmLevel
()
==
4
)
{
g_u8Backlight
=
Backlight_4
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
3
)
else
if
(
Backlight_
G
etPwmLevel
()
==
3
)
{
g_u8Backlight
=
Backlight_3
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
2
)
else
if
(
Backlight_
G
etPwmLevel
()
==
2
)
{
g_u8Backlight
=
Backlight_2
;
}
else
if
(
Backlight_
S
etPwmLevel
()
==
1
)
else
if
(
Backlight_
G
etPwmLevel
()
==
1
)
{
g_u8Backlight
=
Backlight_1
;
}
...
...
Firmware/Source/Component/PowerManagement/PowerManag_user.c
View file @
f4fc76dc
...
...
@@ -55,11 +55,9 @@ static void Power_KL30_Init(void)
Key_KL30_Init_EXample
();
Data_User_Mileage_KL30Init
();
Fuel_KL30_Init
();
Back
light_KL30_Wakeup
_Init
();
Back
Light_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
();
Back
light_KL30_Wakeu
p_Init
();
Back
Light_WakeU
p_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
)
...
...
Firmware/Source/System/Sys_Task_List.c
View file @
f4fc76dc
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment