Skip to content

Commit 597217d

Browse files
authored
Project Creation
1 parent 401532f commit 597217d

20 files changed

+3358
-0
lines changed

examples/Power/ETA4662/main.cpp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* @Description(CN):
3+
* 基于Arduino_DriveBus库的ETA4662充电芯片例程
4+
* 以下是使用该款芯片需要注意的几个点:
5+
* 1. ETA4662默认状态下为关闭充电功能的状态,需要手动开启充电
6+
* 2. 在使用Arduino_DriveBus库时,初始化阶段会对芯片进行一次初始化的写入数据,具体
7+
* 初始化内容可以前往芯片文件下的XXX_Initialization_Operations[]这个数组查看
8+
* 3. Arduino_DriveBus库使用枚举的方式寄存操作芯片的命令和值,具体的可执行命令已经在
9+
* 芯片文件的@Description有说明
10+
*
11+
* @Description(EN):
12+
* ETA4662 charging chip routine based on Arduino_DriveBus library
13+
* Here are a few points to note when using this chip:
14+
* 1. The ETA4662 is in a default state of disabling charging, which needs to be manually enabled.
15+
* 2. When using the Arduino_DriveBus library, the chip is initialized during the initialization phase
16+
* by writing data to it. The specific initialization content can be viewed in the XXX_Initialization_Operations[]
17+
* array under the chip file.
18+
* 3. The Arduino_DriveBus library uses enumerations to register commands and values for operating the chip.
19+
* The specific executable commands are explained in the chip file under @Description.
20+
*
21+
* @version: V1.0.0
22+
* @Author: Xk_w
23+
* @Date: 2023-11-27 10:08:51
24+
* @LastEditors: Xk_w
25+
* @LastEditTime: 2023-11-27 17:54:02
26+
* @License: GPL 3.0
27+
*/
28+
#include "Arduino_DriveBus_Library.h"
29+
#include "pin_config.h"
30+
31+
std::shared_ptr<Arduino_IIC_DriveBus> IIC_Bus =
32+
std::make_shared<Arduino_HWIIC>(IIC_SDA, IIC_SCL, &Wire);
33+
34+
std::unique_ptr<Arduino_IIC> ETA4662(new Arduino_ETA4662(IIC_Bus, ETA4662_DEVICE_ADDRESS,
35+
DRIVEBUS_DEFAULT_VALUE, DRIVEBUS_DEFAULT_VALUE));
36+
37+
void setup()
38+
{
39+
Serial.begin(115200);
40+
Serial.println("Ciallo");
41+
42+
while (ETA4662->begin() == false)
43+
{
44+
Serial.println("ETA4662 initialization fail");
45+
delay(2000);
46+
}
47+
Serial.println("ETA4662 initialization successfully");
48+
49+
ETA4662->IIC_Write_Device_State(ETA4662->Arduino_IIC_Power::Device::POWER_DEVICE_CHARGING_MODE,
50+
ETA4662->Arduino_IIC_Power::Device_State::POWER_DEVICE_ON); // 充电
51+
// ETA4662->IIC_Write_Device_State(ETA4662->Arduino_IIC_Power::Device::POWER_DEVICE_WATCHDOG_MODE,
52+
// ETA4662->Arduino_IIC_Power::Device_State::POWER_DEVICE_ON); // 看门狗(当启动ETA4662的看门狗时,看门狗的定时器到达指定值后将断开电源重新连接,与ETA4662通信的MCU将重启)
53+
// ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_WATCHDOG_TIMER, 80); // 看门狗定时器值
54+
55+
// 热调节阈值设置为60度
56+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_THERMAL_REGULATION_THRESHOLD, 60);
57+
// 最小输入电压设置为4760mV
58+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_MINIMUM_INPUT_VOLTAGE_LIMIT, 4760);
59+
// 充电目标电压电压设置为4215mV
60+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_CHARGING_TARGET_VOLTAGE_LIMIT, 4215);
61+
// 系统电压设置为4950mV(输出电压)
62+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_SYSTEM_VOLTAGE_LIMIT, 4950);
63+
// 输入电流限制设置为470mA
64+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_INPUT_CURRENT_LIMIT, 470);
65+
// 快速充电电流限制设置为136mA
66+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_FAST_CHARGING_CURRENT_LIMIT, 136);
67+
// 终端充电和预充电电流限制设置为5mA
68+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_TERMINATION_PRECHARGE_CHARGING_CURRENT_LIMIT, 5);
69+
// BAT到SYS的放电电流限制设置为2200mA
70+
ETA4662->IIC_Write_Device_Value(ETA4662->Arduino_IIC_Power::Device_Value::POWER_DEVICE_BAT_TO_SYS_DISCHARGE_CURRENT_LIMIT, 2200);
71+
}
72+
void loop()
73+
{
74+
Serial.printf("--------------------ETA4662--------------------\n");
75+
Serial.printf("System running time: %d\n\n", (uint32_t)millis() / 1000);
76+
Serial.printf("IIC_Bus.use_count(): %d\n\n", (int32_t)IIC_Bus.use_count());
77+
78+
Serial.printf("ID: %#X \n", (int32_t)ETA4662->IIC_Read_Device_ID());
79+
80+
Serial.printf("\nCharging Status: %s \n",
81+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_CHARGING_STATUS)).c_str());
82+
Serial.printf("Input Source Status: %s \n",
83+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_INPUT_SOURCE_STATUS)).c_str());
84+
Serial.printf("System Voltage Status: %s \n",
85+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_SYSTEM_VOLTAGE_STATUS)).c_str());
86+
Serial.printf("Thermal Regulation Status: %s \n",
87+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_THERMAL_REGULATION_STATUS)).c_str());
88+
89+
Serial.printf("\nWatchdog Fault Status: %s \n",
90+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_WATCHDOG_FAULT_STATUS)).c_str());
91+
Serial.printf("Input Fault Status: %s \n",
92+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_INPUT_FAULT_STATUS)).c_str());
93+
Serial.printf("Thermal Shutdown Fault Status: %s \n",
94+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_THERMAL_SHUTDOWN_FAULT_STATUS)).c_str());
95+
Serial.printf("Battery Fault Status: %s \n",
96+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_BATTERY_FAULT_STATUS)).c_str());
97+
Serial.printf("Safety Timer Fault Status: %s \n",
98+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_SAFETY_TIMER_STATUS_FAULT_STATUS)).c_str());
99+
Serial.printf("NTC Fault Status: %s \n",
100+
(ETA4662->IIC_Read_Device_State(ETA4662->Arduino_IIC_Power::Status_Information::POWER_NTC_FAULT_STATUS)).c_str());
101+
102+
Serial.printf("\nThermal Regulation Threshold: %d ^C \n",
103+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_THERMAL_REGULATION_THRESHOLD));
104+
105+
Serial.printf("\nInput Minimum Voltage Limit: %d mV \n",
106+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_MINIMUM_INPUT_VOLTAGE_LIMIT));
107+
Serial.printf("Charging Voltage Limit: %d mV \n",
108+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_CHARGING_TARGET_VOLTAGE_LIMIT));
109+
Serial.printf("System Voltage Limit: %d mV \n",
110+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_SYSTEM_VOLTAGE_LIMIT));
111+
Serial.printf("Input Current Limit: %d mA \n",
112+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_INPUT_CURRENT_LIMIT));
113+
Serial.printf("Fast Charge Current Limit: %d mA \n",
114+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_FAST_CHARGING_CURRENT_LIMIT));
115+
Serial.printf("Termination And Precondition Charge Current Limit: %d mA \n",
116+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_TERMINATION_PRECHARGE_CHARGING_CURRENT_LIMIT));
117+
Serial.printf("BAT To SYS Discharge Current Limit: %d mA \n",
118+
ETA4662->IIC_Read_Device_Value(ETA4662->Arduino_IIC_Power::Value_Information::POWER_BAT_TO_SYS_DISCHARGE_CURRENT_LIMIT));
119+
120+
Serial.printf("--------------------ETA4662--------------------\n");
121+
122+
delay(1000);
123+
}

examples/Power/SY6970/main.cpp

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* @Description(CN):
3+
* 基于Arduino_DriveBus库的SY6970充电芯片例程
4+
* 以下是使用该款芯片需要注意的几个点:
5+
* 1. SY6970在获取芯片电压电流的时候需要开启ADC测量功能才能正常检测到电压电流等数据
6+
* 如果未开启则获得的是错误信息
7+
* 2. 在使用Arduino_DriveBus库时,初始化阶段会对芯片进行一次初始化的写入数据,具体
8+
* 初始化内容可以前往芯片文件下的XXX_Initialization_Operations[]这个数组查看
9+
* 3. Arduino_DriveBus库使用枚举的方式寄存操作芯片的命令和值,具体的可执行命令已经在
10+
* 芯片文件的@Description有说明
11+
*
12+
* @Description(EN):
13+
* SY6970 Charging Chip Routine based on Arduino_DriveBus Library
14+
* Here are a few points to note when using this chip:
15+
* 1. When obtaining voltage and current data from the SY6970 chip, the ADC measurement
16+
* function must be enabled to correctly detect the voltage, current, and other data. If not enabled,
17+
* error messages will be obtained.
18+
* 2. When using the Arduino_DriveBus library, the chip is initialized with data during the initialization
19+
* phase. The specific initialization content can be viewed in the XXX_Initialization_Operations[] array in
20+
* the chip file.
21+
* 3. The Arduino_DriveBus library uses enumerations to register commands and values for operating
22+
* the chip. The specific executable commands are explained in the chip file under @Description.
23+
*
24+
* @version: V1.0.0
25+
* @Author: Xk_w
26+
* @Date: 2023-11-17 13:34:38
27+
* @LastEditors: Xk_w
28+
* @LastEditTime: 2023-11-27 17:33:55
29+
* @License: GPL 3.0
30+
*/
31+
#include "Arduino_DriveBus_Library.h"
32+
#include "pin_config.h"
33+
34+
std::shared_ptr<Arduino_IIC_DriveBus> IIC_Bus =
35+
std::make_shared<Arduino_HWIIC>(IIC_SDA, IIC_SCL, &Wire);
36+
37+
std::unique_ptr<Arduino_IIC> SY6970(new Arduino_SY6970(IIC_Bus, SY6970_DEVICE_ADDRESS,
38+
DRIVEBUS_DEFAULT_VALUE, DRIVEBUS_DEFAULT_VALUE));
39+
40+
static bool Temp1 = 0;
41+
42+
void setup()
43+
{
44+
Serial.begin(115200);
45+
Serial.println("Ciallo");
46+
47+
while (SY6970->begin() == false)
48+
{
49+
Serial.println("SY6970 initialization fail");
50+
delay(2000);
51+
}
52+
Serial.println("SY6970 initialization successfully");
53+
54+
// 开启ADC测量功能
55+
while (SY6970->IIC_Write_Device_State(SY6970->Device::POWER_DEVICE_ADC_MEASURE,
56+
SY6970->Device_State::POWER_DEVICE_ON) == false)
57+
{
58+
Serial.println("SY6970 ADC Measure ON fail");
59+
delay(2000);
60+
}
61+
Serial.println("SY6970 ADC Measure ON successfully");
62+
63+
// 禁用看门狗定时器喂狗功能
64+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_WATCHDOG_TIMER, 0);
65+
// 热调节阈值设置为60度
66+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_THERMAL_REGULATION_THRESHOLD, 60);
67+
// 充电目标电压电压设置为4224mV
68+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_CHARGING_TARGET_VOLTAGE_LIMIT, 4224);
69+
// 最小系统电压限制为3600mA
70+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_MINIMUM_SYSTEM_VOLTAGE_LIMIT, 3600);
71+
// 设置OTG电压为5062mV
72+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_OTG_VOLTAGE_LIMIT, 5062);
73+
// 输入电流限制设置为600mA
74+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_INPUT_CURRENT_LIMIT, 600);
75+
// 快速充电电流限制设置为2112mA
76+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_FAST_CHARGING_CURRENT_LIMIT, 2112);
77+
// 预充电电流限制设置为192mA
78+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_PRECHARGE_CHARGING_CURRENT_LIMIT, 192);
79+
// 终端充电电流限制设置为320mA
80+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_TERMINATION_CHARGING_CURRENT_LIMIT, 320);
81+
// OTG电流限制设置为500mA
82+
SY6970->IIC_Write_Device_Value(SY6970->Arduino_IIC_Power::Device_Value::POWER_DEVICE_OTG_CHARGING_LIMIT, 500);
83+
}
84+
85+
void loop()
86+
{
87+
Serial.printf("--------------------SY6970--------------------\n");
88+
Serial.printf("System running time: %d\n\n", (uint32_t)millis() / 1000);
89+
Serial.printf("IIC_Bus.use_count(): %d\n\n", (int32_t)IIC_Bus.use_count());
90+
91+
Serial.printf("IIC device ID: %#X \n", (int32_t)SY6970->IIC_Read_Device_ID());
92+
93+
Serial.printf("\nBUS Status: %s \n",
94+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_BUS_STATUS)).c_str());
95+
Serial.printf("BUS Connection Status: %s \n",
96+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_BUS_CONNECTION_STATUS)).c_str());
97+
Serial.printf("Charging Status: %s \n",
98+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_CHARGING_STATUS)).c_str());
99+
Serial.printf("Input Source Status: %s \n",
100+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_INPUT_SOURCE_STATUS)).c_str());
101+
Serial.printf("Input USB Status: %s \n",
102+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_INPUT_USB_STATUS)).c_str());
103+
Serial.printf("System Voltage Status: %s \n",
104+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_SYSTEM_VOLTAGE_STATUS)).c_str());
105+
Serial.printf("Thermal Regulation Status: %s \n",
106+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_THERMAL_REGULATION_STATUS)).c_str());
107+
108+
Serial.printf("\nWatchdog Fault Status: %s \n",
109+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_WATCHDOG_FAULT_STATUS)).c_str());
110+
Serial.printf("OTG Fault Status: %s \n",
111+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_OTG_FAULT_STATUS)).c_str());
112+
Serial.printf("Charging Fault Status: %s \n",
113+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_CHARGING_FAULT_STATUS)).c_str());
114+
Serial.printf("Battery Fault Status: %s \n",
115+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_BATTERY_FAULT_STATUS)).c_str());
116+
Serial.printf("NTC Fault Status: %s \n",
117+
(SY6970->IIC_Read_Device_State(SY6970->Arduino_IIC_Power::Status_Information::POWER_NTC_FAULT_STATUS)).c_str());
118+
119+
Serial.printf("\nInput Voltage: %d mV \n",
120+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_INPUT_VOLTAGE));
121+
Serial.printf("Battery Voltage: %d mV \n",
122+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_BATTERY_VOLTAGE));
123+
Serial.printf("System Voltage: %d mV \n",
124+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_SYSTEM_VOLTAGE));
125+
Serial.printf("NTC Voltage Percentage: %.03f %% \n",
126+
(float)SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_NTC_VOLTAGE_PERCENTAGE) / 1000.0);
127+
Serial.printf("Charging Current: %d mA \n",
128+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_CHARGING_CURRENT));
129+
Serial.printf("Thermal Regulation Threshold: %d ^C \n",
130+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_THERMAL_REGULATION_THRESHOLD));
131+
132+
Serial.printf("\nCharging Voltage Limit: %d mV \n",
133+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_CHARGING_TARGET_VOLTAGE_LIMIT));
134+
Serial.printf("Minimum System Voltage Limit: %d mV \n",
135+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_MINIMUM_SYSTEM_VOLTAGE_LIMIT));
136+
Serial.printf("OTG Voltage Limit: %d mV \n",
137+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_OTG_VOLTAGE_LIMIT));
138+
Serial.printf("Input Current Limit: %d mA \n",
139+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_INPUT_CURRENT_LIMIT));
140+
Serial.printf("Fast Charge Current Limit: %d mA \n",
141+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_FAST_CHARGING_CURRENT_LIMIT));
142+
Serial.printf("Precharge Charge Current Limit: %d mA \n",
143+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_PRECHARGE_CHARGING_CURRENT_LIMIT));
144+
Serial.printf("Termination Charge Current Limit: %d mA \n",
145+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_TERMINATION_CHARGING_CURRENT_LIMIT));
146+
Serial.printf("OTG Current Limit: %d mA \n",
147+
SY6970->IIC_Read_Device_Value(SY6970->Arduino_IIC_Power::Value_Information::POWER_OTG_CURRENT_LIMIT));
148+
149+
Serial.printf("--------------------SY6970--------------------\n\n");
150+
151+
delay(1000);
152+
153+
Temp1 = !Temp1;
154+
if (Temp1 == 0)
155+
{
156+
}
157+
else
158+
{
159+
}
160+
}

0 commit comments

Comments
 (0)