Hal refactored (#99)

This commit is contained in:
Ken Van Hoeylandt
2024-12-02 00:32:39 +01:00
committed by GitHub
parent 0188ce721c
commit 33bb742dfb
103 changed files with 1222 additions and 1228 deletions
+19 -13
View File
@@ -6,22 +6,23 @@
namespace tt::hal {
typedef bool (*InitPower)();
typedef bool (*InitBoot)();
typedef bool (*InitHardware)();
typedef bool (*InitLvgl)();
typedef void (*SetBacklightDuty)(uint8_t);
typedef struct {
/** Set backlight duty */
_Nullable SetBacklightDuty setBacklightDuty;
} Display;
typedef struct {
class Display;
class Keyboard;
typedef Display* (*CreateDisplay)();
typedef Keyboard* (*CreateKeyboard)();
struct Configuration {
/**
* Called before I2C/SPI/etc is initialized.
* Used for powering on the peripherals manually.
*/
const InitPower _Nullable initPower = nullptr;
const InitBoot _Nullable initBoot = nullptr;
/**
* Called after I2C/SPI/etc is initialized.
@@ -32,27 +33,32 @@ typedef struct {
/**
* Create and initialize all LVGL devices. (e.g. display, touch, keyboard)
*/
const InitLvgl _Nullable initLvgl;
const InitLvgl _Nullable initLvgl = nullptr;
/**
* Display HAL functionality.
*/
const Display display;
const CreateDisplay _Nullable createDisplay = nullptr;
/**
* Display HAL functionality.
*/
const CreateKeyboard _Nullable createKeyboard = nullptr;
/**
* An optional SD card interface.
*/
const sdcard::SdCard* _Nullable sdcard;
const sdcard::SdCard* _Nullable sdcard = nullptr;
/**
* An optional power interface for battery or other power delivery.
*/
const Power* _Nullable power;
const Power* _Nullable power = nullptr;
/**
* A list of i2c devices (can be empty, but preferably accurately represents the device capabilities)
*/
const std::vector<i2c::Configuration> i2c;
} Configuration;
const std::vector<i2c::Configuration> i2c = {};
};
} // namespace
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Touch;
class Display {
public:
[[nodiscard]] virtual bool start() = 0;
[[nodiscard]] virtual bool stop() = 0;
[[nodiscard]] virtual void setPowerOn(bool turnOn) = 0;
[[nodiscard]] virtual bool isPoweredOn() const = 0;
[[nodiscard]] virtual bool supportsPowerControl() const = 0;
[[nodiscard]] virtual Touch* _Nullable createTouch() = 0;
/** Set a value in the range [0, 255] */
virtual void setBacklightDuty(uint8_t backlightDuty) = 0;
[[nodiscard]] virtual uint8_t getBacklightDuty() const = 0;
[[nodiscard]] virtual bool supportsBacklightDuty() const = 0;
/** After start() returns true, this should return a valid pointer until stop() is called and returns true */
[[nodiscard]] virtual lv_display_t* _Nullable getLvglDisplay() const = 0;
};
}
+2 -7
View File
@@ -6,9 +6,9 @@
namespace tt::hal {
void init(const Configuration& configuration) {
if (configuration.initPower != nullptr) {
if (configuration.initBoot != nullptr) {
TT_LOG_I(TAG, "Init power");
tt_check(configuration.initPower(), "Init power failed");
tt_check(configuration.initBoot(), "Init power failed");
}
tt_check(i2c::init(configuration.i2c), "I2C init failed");
@@ -23,11 +23,6 @@ void init(const Configuration& configuration) {
TT_LOG_W(TAG, "SD card mount failed (init can continue)");
}
}
if (configuration.initLvgl != nullptr) {
TT_LOG_I(TAG, "Init LVGL");
tt_check(configuration.initLvgl(), "LVGL init failed");
}
}
} // namespace
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Display;
class Keyboard {
public:
[[nodiscard]] virtual bool start(lv_display_t* display) = 0;
[[nodiscard]] virtual bool stop() = 0;
[[nodiscard]] virtual bool isAttached() const = 0;
[[nodiscard]] virtual lv_indev_t* _Nullable getLvglIndev() = 0;
};
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Display;
class Touch {
public:
[[nodiscard]] virtual bool start(lv_display_t* display) = 0;
[[nodiscard]] virtual bool stop() = 0;
[[nodiscard]] virtual lv_indev_t* _Nullable getLvglIndev() = 0;
};
}