19 changed files with 358 additions and 151 deletions
@ -0,0 +1,8 @@ |
|||
{ |
|||
"files.associations": { |
|||
"drv_analog.h": "c", |
|||
"iterator": "c", |
|||
"comp_protocol_manager.h": "c", |
|||
"comp_sample_volt_cur_report.h": "c" |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
#ifndef __COMM_EVENT_H__ |
|||
#define __COMM_EVENT_H__ |
|||
|
|||
typedef enum |
|||
{ |
|||
PORT_IS_NULL = 0, |
|||
SINGLE_TYPEC_INSER, |
|||
SINGLE_USBA_INSER, |
|||
TYPEC_USBA_INSER, |
|||
} e_port_status; |
|||
|
|||
typedef enum |
|||
{ |
|||
port_enter_status, |
|||
port_exit_status, |
|||
} e_port_process_status; |
|||
|
|||
void port_status_run(void); |
|||
|
|||
#endif |
@ -0,0 +1,152 @@ |
|||
#include "comm_event.h" |
|||
#include "drv_analog.h" |
|||
#include <stdbool.h> |
|||
#include <stdint.h> |
|||
#include "comp_powerout.h" |
|||
#include "comp_protocol_manager.h" |
|||
#include "comp_sample_volt_cur_report.h" |
|||
|
|||
// 端口状态机
|
|||
void port_status_run(void) |
|||
{ |
|||
// typeC 和 A口 状态
|
|||
uint8_t typec_status = 0, usba_status = 0; |
|||
static e_port_status port_status = PORT_IS_NULL; |
|||
static e_port_status last_port_status = PORT_IS_NULL; |
|||
static e_port_process_status port_process_status = port_enter_status; |
|||
uint16_t set_current = CURRENT_5A; |
|||
|
|||
|
|||
typec_status = typec_is_attched(); |
|||
usba_status = port_a1_is_attached(); |
|||
|
|||
if(typec_status && usba_status) |
|||
{ |
|||
port_status = TYPEC_USBA_INSER; |
|||
} |
|||
else if(typec_status && !usba_status) |
|||
{ |
|||
port_status = SINGLE_TYPEC_INSER; |
|||
} |
|||
else if(!typec_status && usba_status) |
|||
{ |
|||
port_status = SINGLE_USBA_INSER; |
|||
} |
|||
else |
|||
{ |
|||
port_status = PORT_IS_NULL; |
|||
} |
|||
|
|||
if(last_port_status != port_status) |
|||
{ |
|||
port_process_status = port_enter_status; |
|||
} |
|||
|
|||
switch(port_status) |
|||
{ |
|||
case PORT_IS_NULL: |
|||
if(port_process_status == port_enter_status) |
|||
{ |
|||
port_process_status = port_exit_status; |
|||
|
|||
// 什么都没接时, 也是用buck给A口供电来检查A口是否插入
|
|||
buck_control(true); |
|||
dpdm_power_a1_gate_enable(false); |
|||
} |
|||
else |
|||
{ |
|||
|
|||
} |
|||
|
|||
break; |
|||
|
|||
case SINGLE_TYPEC_INSER: |
|||
if(port_process_status == port_enter_status) |
|||
{ |
|||
port_process_status = port_exit_status; |
|||
|
|||
// 单C口时, 常开buck, 关闭gateA, 等A口有拉电流才反过来
|
|||
buck_control(true); |
|||
dpdm_power_a1_gate_enable(false); |
|||
} |
|||
else |
|||
{ |
|||
|
|||
} |
|||
|
|||
break; |
|||
|
|||
case SINGLE_USBA_INSER: |
|||
if(port_process_status == port_enter_status) |
|||
{ |
|||
port_process_status = port_exit_status; |
|||
|
|||
// 单A口
|
|||
dpdm_power_a1_gate_enable(true); |
|||
buck_control(false); |
|||
} |
|||
else |
|||
{ |
|||
|
|||
} |
|||
|
|||
break; |
|||
|
|||
case TYPEC_USBA_INSER: |
|||
if(port_process_status == port_enter_status) |
|||
{ |
|||
port_process_status = port_exit_status; |
|||
|
|||
if(g_powerout_info.set_vol < VOLTAGE_5P5V |
|||
&& (get_adp_curr_sample_volt() < VOLTAGE_5P5V)) |
|||
{ |
|||
// 加大电流--->开gateA--->关buck
|
|||
// comp_powerout_prl_set_cur(CURRENT_5A);
|
|||
comp_set_current(&g_powerout_info, CURRENT_5P5A); // 需要立刻设置
|
|||
|
|||
// 是否有可能电流环设置的没那么快, 一打开gateA就被拉挂了? 需要加个延迟等电流环设置完再开A?
|
|||
// drv_delay_us(500);
|
|||
// drv_delay_ms(5);
|
|||
dpdm_power_a1_gate_enable(true); |
|||
// drv_delay_ms(2);
|
|||
buck_control(false); |
|||
} |
|||
else |
|||
{ |
|||
buck_control(true); |
|||
dpdm_power_a1_gate_enable(false); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
// C口开始升压 且 gateA还开着
|
|||
if(g_powerout_info.set_vol > VOLTAGE_5P5V |
|||
&& REG_ANALOG_GATEA->bf.en) |
|||
{ |
|||
// todo: 看看是否需要延迟个1ms等待buck完全开启再关gateA
|
|||
buck_control(true); |
|||
dpdm_power_a1_gate_enable(false); |
|||
} |
|||
else if(g_powerout_info.set_vol < VOLTAGE_5P5V |
|||
&& (get_adp_curr_sample_volt() < VOLTAGE_5P5V) |
|||
&& !REG_ANALOG_GATEA->bf.en) |
|||
{ |
|||
// set_current = CURRENT_5A + user_app.usba_high_current_vol;
|
|||
// if(set_current > CURRENT_6A)
|
|||
// {
|
|||
// set_current = CURRENT_6A;
|
|||
// }
|
|||
// comp_powerout_prl_set_cur(set_current);
|
|||
|
|||
comp_set_current(&g_powerout_info, CURRENT_5P5A); // 需要立刻设置
|
|||
dpdm_power_a1_gate_enable(true); |
|||
buck_control(false); |
|||
} |
|||
} |
|||
|
|||
break; |
|||
} |
|||
|
|||
last_port_status = port_status; |
|||
} |
|||
|
Loading…
Reference in new issue