Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 491_AXP2021_pl23+_Addons.diff
- - Modified Battery Status Logic
- - CV_Volage selection at Compile Time (only 4.0, 4.1, 4.2 Volt)
- - ADC Voltage Readings >0x1fff make no sense, Display as 'Floating' in Debug Menu
- - Found a Formula for ADC TDie calculation, implemented Display in Debug Menu
- (https://github.com/lewisxhe/XPowersLib src/REG/AXP2101Constants.h, modified to integer only)
- - Show the AXP2101_REG_BATT_PERCENTAGE Value for Reference in the Battery Status Debug Menu
- Mini-Credit ZappBranigan2972 on forums / F. Jacobsen on the Theme Site
- ---
- --- a/firmware/drivers/axp-2101.c.orig 2024-11-12 10:10:52.680404703 +0100
- +++ b/firmware/drivers/axp-2101.c 2024-11-12 10:22:13.304513117 +0100
- @@ -266,7 +266,7 @@
- .en_bit = 0,
- .min_mV = 500,
- .max_mV = 1400,
- - .step_mV = 560,
- + .step_mV = 50, // 560 must be a typo...
- .step2_min_mV = 0,
- .step2_mV = 0,
- .step2_max_mV = 0,
- --- a/firmware/drivers/axp-2101.c.orig 2024-11-12 10:10:52.680404703 +0100
- +++ b/firmware/drivers/axp-2101.c 2024-11-12 10:22:13.304513117 +0100
- @@ -398,10 +398,10 @@
- /* TODO: can we trust the battery current direction? */
- int axp2101_battery_status(void)
- {
- - int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP2101_REG_PMU_STATUS2);
- - if((r >> 5) & 0x03 == 0) {
- + int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP2101_REG_PMU_STATUS2) & 0x07;
- + if(r == 4) {
- return AXP2101_BATT_FULL;
- - } else if((r >> 5) & 0x03 == 01) {
- + } else if(r < 4) {
- return AXP2101_BATT_CHARGING;
- } else {
- return AXP2101_BATT_DISCHARGING;
- @@ -499,6 +499,12 @@
- 300, 400, 500, 600, 700, 800, 900, 1000,
- };
- +enum CV_Voltage {
- + CV4_00V = 1,
- + CV4_10V = 2,
- + CV4_20V = 3,
- +};
- +
- // constant current charge current limits
- void axp2101_set_charge_current(int current_mA)
- {
- @@ -508,6 +514,9 @@
- chargecurrent_tbl[index+1] <= current_mA)
- ++index;
- + // Limit Charger Voltage
- + i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
- + AXP2101_REG_CV_SETTING, 0x07, CV4_20V, NULL);
- i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
- AXP2101_REG_ICC_SETTING, 0x0f, index, NULL);
- }
- @@ -555,11 +564,11 @@
- (void)data;
- static const char* const adc_names[] = {
- - "V_bat", "V_bus", "V_sys", "V_ts", "V_die",
- + "V_bat", "V_bus", "V_sys", "V_ts", "T_die",
- };
- static const char* const adc_units[] = {
- - "mV", "mV", "mV", "mV", "C*100",
- + "mV", "mV", "mV", "mV", "°C",
- };
- static const char* const supply_names[] = {
- @@ -574,12 +583,24 @@
- if(raw_value == INT_MIN) {
- snprintf(buf, buflen, "%s: [Disabled]", adc_names[adc]);
- return buf;
- + } else if(raw_value > 0x1fff) { // Values greater makes no sense
- + snprintf(buf, buflen, "%s: [Floating]", adc_names[adc]);
- + return buf;
- }
- int value = axp2101_adc_conv_raw(adc, raw_value);
- - snprintf(buf, buflen, "%s: %d %s", adc_names[adc],
- + if(adc == AXP2101_ADC_DIE_TEMPERATURE) {
- + /* From https://github.com/lewisxhe/XPowersLib src/REG/AXP2101Constants.h, integer only ver. */
- + #define XPOWERS_AXP2101_TEMP_CONVERSION(raw) (220 + ( (7274 - raw) / 2) )
- + int die_temp = XPOWERS_AXP2101_TEMP_CONVERSION(value);
- + int die_temp_abs = die_temp<0 ? -die_temp : die_temp;
- + snprintf(buf, buflen, "%s: %s%d.%1d %s", adc_names[adc],
- + die_temp<0 ? "-":"+", die_temp_abs/10, die_temp_abs%10,
- + adc_units[adc]);
- + } else {
- + snprintf(buf, buflen, "%s: %d %s", adc_names[adc],
- value, adc_units[adc]);
- -
- + }
- return buf;
- }
- @@ -598,13 +619,16 @@
- switch(item) {
- case AXP_DEBUG_BATTERY_STATUS: {
- + int batreg = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP2101_REG_BATT_PERCENTAGE);
- switch(axp2101_battery_status()) {
- case AXP2101_BATT_FULL:
- return "Battery: Full";
- case AXP2101_BATT_CHARGING:
- - return "Battery: Charging";
- + snprintf(buf, buflen,"Battery: Charging [%2d%%]", batreg);
- + return buf;
- case AXP2101_BATT_DISCHARGING:
- - return "Battery: Discharging";
- + snprintf(buf, buflen, "Battery: Discharging [%2d%%]", batreg);
- + return buf;
- default:
- return "Battery: Unknown";
- }
Advertisement
Add Comment
Please, Sign In to add comment