File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -644,6 +644,7 @@ static void i2c_write_comms_callback(uint8_t* pData, uint8_t size) {
644
644
}
645
645
break ;
646
646
case gPowerState_c :
647
+ power_source = pwr_mon_get_power_source ();
647
648
i2cResponse .cmdData .readRspCmd .dataSize = sizeof (power_source );
648
649
memcpy (& i2cResponse .cmdData .readRspCmd .data , & power_source , sizeof (power_source ));
649
650
break ;
Original file line number Diff line number Diff line change @@ -40,22 +40,29 @@ void pwr_mon_init(void)
40
40
power_source_t pwr_mon_get_power_source (void ) {
41
41
power_source_t power_source = PWR_SOURCE_NONE ;
42
42
uint32_t bat_voltage_mv = 0 ;
43
+ uint32_t vin_voltage_mv = 0 ;
43
44
44
45
// Read WAKE_ON_EDGE pin for detecting if board is USB powered
45
46
bool usb_on = (((PIN_WAKE_ON_EDGE_GPIO -> PDIR ) >> PIN_WAKE_ON_EDGE_BIT ) & 0x01U ) ? false : true;
46
47
47
48
// Read battery voltage
48
49
bat_voltage_mv = pwr_mon_get_vbat_mv ();
49
50
51
+ // Read Vin voltage
52
+ vin_voltage_mv = pwr_mon_get_vin_mv ();
53
+
50
54
// Get power source based on battery and USB
51
55
if (usb_on == true && bat_voltage_mv < (BATT_MIN_VOLTAGE )) {
52
56
power_source = PWR_USB_ONLY ;
53
57
} else if (usb_on == true && bat_voltage_mv >= (BATT_MIN_VOLTAGE )) {
54
58
power_source = PWR_USB_AND_BATT ;
55
59
} else if (usb_on == false && bat_voltage_mv >= (BATT_MIN_VOLTAGE )) {
56
- power_source = PWR_BATT_ONLY ;
57
- } else if (usb_on == false && bat_voltage_mv < (BATT_MIN_VOLTAGE )) {
58
- power_source = PWR_SOURCE_NONE ;
60
+ // If battery voltage is greater than Vin, it means the battery is used
61
+ if ( bat_voltage_mv + 200 > vin_voltage_mv ) {
62
+ power_source = PWR_BATT_ONLY ;
63
+ } else {
64
+ power_source = PWR_SOURCE_NONE ;
65
+ }
59
66
}
60
67
61
68
return power_source ;
You can’t perform that action at this time.
0 commit comments