Power improvements (#114)

This commit is contained in:
Ken Van Hoeylandt
2024-12-09 21:58:30 +01:00
committed by GitHub
parent e4206e8637
commit da81256622
16 changed files with 370 additions and 96 deletions
+2 -1
View File
@@ -16,6 +16,7 @@ class Display;
class Keyboard;
typedef Display* (*CreateDisplay)();
typedef Keyboard* (*CreateKeyboard)();
typedef std::shared_ptr<Power> (*CreatePower)();
struct Configuration {
/**
@@ -53,7 +54,7 @@ struct Configuration {
/**
* An optional power interface for battery or other power delivery.
*/
const Power* _Nullable power = nullptr;
const CreatePower _Nullable power = nullptr;
/**
* A list of i2c devices (can be empty, but preferably accurately represents the device capabilities)
+32 -12
View File
@@ -4,18 +4,38 @@
namespace tt::hal {
typedef bool (*PowerIsCharging)();
typedef bool (*PowerIsChargingEnabled)();
typedef void (*PowerSetChargingEnabled)(bool enabled);
typedef uint8_t (*PowerGetBatteryCharge)(); // Power value [0, 255] which maps to 0-100% charge
typedef int32_t (*PowerGetCurrent)(); // Consumption or charge current in mAh
class Power{
typedef struct {
PowerIsCharging isCharging;
PowerIsChargingEnabled isChargingEnabled;
PowerSetChargingEnabled setChargingEnabled;
PowerGetBatteryCharge getChargeLevel;
PowerGetCurrent getCurrent;
} Power;
public:
Power() = default;
virtual ~Power() = default;
enum MetricType {
IS_CHARGING, // bool
CURRENT, // int32_t, mAh
BATTERY_VOLTAGE, // uint32_t, mV
CHARGE_LEVEL, // uint8_t [0, 100]
};
union MetricData {
int32_t valueAsInt32 = 0;
uint32_t valueAsUint32;
uint8_t valueAsUint8;
float valueAsFloat;
bool valueAsBool;
};
virtual bool supportsMetric(MetricType type) const = 0;
/**
* @return false when metric is not supported or (temporarily) not available.
*/
virtual bool getMetric(Power::MetricType type, MetricData& data) = 0;
virtual bool supportsChargeControl() const { return false; }
virtual bool isAllowedToCharge() const { return false; }
virtual void setAllowedToCharge(bool canCharge) { /* NO-OP*/ }
};
} // namespace tt