I2C Implementation (#84)
This commit is contained in:
committed by
GitHub
parent
881c8517bf
commit
d8731eaa17
@@ -0,0 +1,38 @@
|
||||
#include "Hal/Power.h"
|
||||
#include "M5Unified.hpp"
|
||||
|
||||
/**
|
||||
* M5.Power by default doesn't have a check to see if charging is enabled.
|
||||
* However, it's always enabled by default after boot, so we cover that here:
|
||||
*/
|
||||
static bool charging_enabled = true;
|
||||
|
||||
static bool is_charging() {
|
||||
return M5.Power.isCharging() == m5::Power_Class::is_charging;
|
||||
}
|
||||
|
||||
static bool is_charging_enabled() {
|
||||
return charging_enabled;
|
||||
}
|
||||
|
||||
static void set_charging_enabled(bool enabled) {
|
||||
charging_enabled = enabled; // Local shadow copy because M5 API doesn't provide a function for it
|
||||
M5.Power.setBatteryCharge(enabled);
|
||||
}
|
||||
|
||||
static uint8_t get_charge_level() {
|
||||
uint16_t scaled = (uint16_t)M5.Power.getBatteryLevel() * 255 / 100;
|
||||
return (uint8_t)scaled;
|
||||
}
|
||||
|
||||
static int32_t get_current() {
|
||||
return M5.Power.getBatteryCurrent();
|
||||
}
|
||||
|
||||
extern const tt::hal::Power m5stack_power = {
|
||||
.is_charging = &is_charging,
|
||||
.is_charging_enabled = &is_charging_enabled,
|
||||
.set_charging_enabled = &set_charging_enabled,
|
||||
.get_charge_level = &get_charge_level,
|
||||
.get_current = &get_current
|
||||
};
|
||||
Reference in New Issue
Block a user