Implement device management (#199)
- Added `tt::hal::Device` and functions (de)register devices and search for them. - Refactored apps: `Power` and `Display` settings apps now use the device API to find devices. - Implemented the new API for all existing drivers for all devices, including the simulator. - Updated HAL Configuration to return `std::shared_ptr` instead of raw pointers. - Added test project for headless tests and implemented tests for the new code.
This commit is contained in:
committed by
GitHub
parent
c87200a80d
commit
cff0605b0a
@@ -4,7 +4,7 @@
|
||||
|
||||
#define BQ24295_ADDRESS 0x6BU
|
||||
|
||||
class Bq24295 : I2cDevice {
|
||||
class Bq24295 final : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
private:
|
||||
|
||||
@@ -12,6 +12,10 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const final { return "BQ24295"; }
|
||||
|
||||
std::string getDescription() const final { return "I2C-controlled single cell USB charger"; }
|
||||
|
||||
enum class WatchDogTimer {
|
||||
Disabled = 0b000000,
|
||||
Enabled40s = 0b010000,
|
||||
|
||||
@@ -30,8 +30,8 @@ bool UnPhoneDisplay::start() {
|
||||
lv_display_set_color_format(displayHandle, LV_COLOR_FORMAT_NATIVE);
|
||||
|
||||
// TODO malloc to use SPIRAM
|
||||
static auto* buffer1 = (uint8_t*)heap_caps_malloc(BUFFER_SIZE, MALLOC_CAP_SPIRAM);
|
||||
static auto* buffer2 = (uint8_t*)heap_caps_malloc(BUFFER_SIZE, MALLOC_CAP_SPIRAM);
|
||||
buffer1 = (uint8_t*)heap_caps_malloc(BUFFER_SIZE, MALLOC_CAP_SPIRAM);
|
||||
buffer2 = (uint8_t*)heap_caps_malloc(BUFFER_SIZE, MALLOC_CAP_SPIRAM);
|
||||
assert(buffer1 != nullptr);
|
||||
assert(buffer2 != nullptr);
|
||||
|
||||
@@ -61,13 +61,18 @@ bool UnPhoneDisplay::stop() {
|
||||
lv_display_delete(displayHandle);
|
||||
displayHandle = nullptr;
|
||||
|
||||
heap_caps_free(buffer1);
|
||||
heap_caps_free(buffer2);
|
||||
buffer1 = nullptr;
|
||||
buffer2 = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
tt::hal::Touch* _Nullable UnPhoneDisplay::createTouch() {
|
||||
return static_cast<tt::hal::Touch*>(new UnPhoneTouch());
|
||||
std::shared_ptr<tt::hal::Touch> _Nullable UnPhoneDisplay::createTouch() {
|
||||
return std::make_shared<UnPhoneTouch>();
|
||||
}
|
||||
|
||||
tt::hal::Display* createDisplay() {
|
||||
return static_cast<tt::hal::Display*>(new UnPhoneDisplay());
|
||||
std::shared_ptr<tt::hal::Display> createDisplay() {
|
||||
return std::make_shared<UnPhoneDisplay>();
|
||||
}
|
||||
|
||||
@@ -11,16 +11,21 @@ class UnPhoneDisplay : public tt::hal::Display {
|
||||
private:
|
||||
|
||||
lv_display_t* displayHandle = nullptr;
|
||||
uint8_t* buffer1 = nullptr;
|
||||
uint8_t* buffer2 = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const final { return "HX8357"; }
|
||||
std::string getDescription() const final { return "SPI display"; }
|
||||
|
||||
bool start() override;
|
||||
|
||||
bool stop() override;
|
||||
|
||||
tt::hal::Touch* _Nullable createTouch() override;
|
||||
std::shared_ptr<tt::hal::Touch> _Nullable createTouch() override;
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
};
|
||||
|
||||
tt::hal::Display* createDisplay();
|
||||
std::shared_ptr<tt::hal::Display> createDisplay();
|
||||
|
||||
@@ -12,6 +12,9 @@ public:
|
||||
UnPhonePower() = default;
|
||||
~UnPhonePower() = default;
|
||||
|
||||
std::string getName() const final { return "XPT2046 Power Measurement"; }
|
||||
std::string getDescription() const final { return "Power interface via XPT2046 voltage measurement"; }
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(Power::MetricType type, Power::MetricData& data) override;
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const final { return "XPT2046"; }
|
||||
std::string getDescription() const final { return "I2C touch driver"; }
|
||||
|
||||
bool start(lv_display_t* display) override;
|
||||
bool stop() override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
|
||||
|
||||
Reference in New Issue
Block a user