You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.1 KiB
87 lines
2.1 KiB
#include "ntc.h"
|
|
#include "comp_adc.h"
|
|
#include "drv_analog.h"
|
|
#include "comp_gp_mux_pucur.h"
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include "comp_protection.h"
|
|
#include "comp_powerout.h"
|
|
#include "comp_pd_manager.h"
|
|
#include "comm_event.h"
|
|
#include "comp_protocol_manager.h"
|
|
#include "app_porta.h"
|
|
#include "dpdm_run.h"
|
|
|
|
#if NTC_ENABLE
|
|
|
|
|
|
void ntc_init(void)
|
|
{
|
|
drv_clkctrl_pin_mul_cfg(RT1, 0);
|
|
rt1_pucur_cfg(RT_20UA);
|
|
}
|
|
|
|
|
|
// 当前是 1ms 进一次
|
|
void ntc_run(void)
|
|
{
|
|
uint16_t ntc_val = 0;
|
|
static uint8_t ntc_derat_cnt = 0, ntc_recove_cnt = 0;
|
|
|
|
ntc_val = COMP_ADC_GET_RT1_VOL();
|
|
|
|
// 消抖时间的话, 是还需要/5, 比如给200ms, 实际是40ms
|
|
if(trigger_check(ntc_val, NTC_100,
|
|
true,
|
|
&ntc_derat_cnt,
|
|
DELAY_100MS)
|
|
)
|
|
{
|
|
user_app.ntc_triggered_dera = true;
|
|
}
|
|
|
|
if(trigger_check(ntc_val, NTC_50,
|
|
false,
|
|
&ntc_recove_cnt,
|
|
DELAY_100MS)
|
|
)
|
|
{
|
|
user_app.ntc_triggered_dera = false;
|
|
}
|
|
|
|
if(user_app.last_ntc_triggered_dera == user_app.ntc_triggered_dera)
|
|
{
|
|
return;
|
|
}
|
|
|
|
user_app.last_ntc_triggered_dera = user_app.ntc_triggered_dera;
|
|
|
|
// 触发NTC时, 双口都要回到5V, 并且DPDN要短接起来
|
|
if(user_app.ntc_triggered_dera)
|
|
{
|
|
dpdm_reset();
|
|
drv_dpdn_short_set(true);
|
|
drv_dpdn1_short_set(true);
|
|
|
|
// 走PD时让 设备自己降。 走其他协议时, 主动降。
|
|
// 如果没走PD,还需要考虑纯typeC状态,要把CC设到 1.5A 的电流广播值
|
|
if(dpdm_power_get_next_protocol() == PROTOCOL_PD_FIX
|
|
|| dpdm_power_get_next_protocol() == PROTOCOL_PD_PPS)
|
|
{
|
|
// 复位协议,屏蔽PD协议, DPDN恢复短接, 电压要降回5V
|
|
pd_restart_send_src_cap(&g_pd_port, SRC_CAP_7W);
|
|
}
|
|
else
|
|
{
|
|
comp_powerout_prl_set_viout(VOLTAGE_5V, CURRENT_3A);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 温度恢复后, 重启下, 不然手机不会重新走协议
|
|
NVIC_SystemReset();
|
|
}
|
|
}
|
|
|
|
|
|
#endif
|
|
|