HAL renaming & relocation (#215)

Implemented more consistent naming:
- Moved all HAL devices into their own namespace (and related folder)
- Post-fixed all HAL device names with "Device"
This commit is contained in:
Ken Van Hoeylandt
2025-02-09 16:48:23 +01:00
committed by GitHub
parent a7a3b17ff6
commit 2345ba6d13
62 changed files with 263 additions and 250 deletions
@@ -1,20 +1,21 @@
#pragma once
#include "./SdCard.h"
#include "./i2c/I2c.h"
#include "Tactility/hal/sdcard/SdCardDevice.h"
#include "Tactility/hal/spi/Spi.h"
#include "Tactility/hal/uart/Uart.h"
#include "i2c/I2c.h"
namespace tt::hal {
typedef bool (*InitBoot)();
class Display;
class Keyboard;
class Power;
typedef std::shared_ptr<Display> (*CreateDisplay)();
typedef std::shared_ptr<Keyboard> (*CreateKeyboard)();
typedef std::shared_ptr<Power> (*CreatePower)();
namespace display { class DisplayDevice; }
namespace keyboard { class KeyboardDevice; }
namespace power { class PowerDevice; }
typedef std::shared_ptr<display::DisplayDevice> (*CreateDisplay)();
typedef std::shared_ptr<keyboard::KeyboardDevice> (*CreateKeyboard)();
typedef std::shared_ptr<power::PowerDevice> (*CreatePower)();
enum class LvglInit {
Default,
@@ -38,7 +39,7 @@ struct Configuration {
const CreateKeyboard _Nullable createKeyboard = nullptr;
/** An optional SD card interface. */
const std::shared_ptr<SdCard> _Nullable sdcard = nullptr;
const std::shared_ptr<sdcard::SdCardDevice> _Nullable sdcard = nullptr;
/** An optional power interface for battery or other power delivery. */
const CreatePower _Nullable power = nullptr;
@@ -1,14 +1,16 @@
#pragma once
#include "Device.h"
#include "../Device.h"
#include <lvgl.h>
namespace tt::hal {
namespace tt::hal::touch {
class TouchDevice;
}
class Touch;
namespace tt::hal::display {
class Display : public Device {
class DisplayDevice : public Device {
public:
@@ -21,7 +23,7 @@ public:
virtual bool isPoweredOn() const { return true; }
virtual bool supportsPowerControl() const { return false; }
virtual std::shared_ptr<Touch> _Nullable createTouch() = 0;
virtual std::shared_ptr<touch::TouchDevice> _Nullable createTouch() = 0;
/** Set a value in the range [0, 255] */
virtual void setBacklightDuty(uint8_t backlightDuty) { /* NO-OP */ }
@@ -35,4 +37,4 @@ public:
virtual lv_display_t* _Nullable getLvglDisplay() const = 0;
};
}
} // namespace tt::hal::display
@@ -1,14 +1,14 @@
#pragma once
#include "Device.h"
#include "../Device.h"
#include <lvgl.h>
namespace tt::hal {
namespace tt::hal::keyboard {
class Display;
class Keyboard : public Device {
class KeyboardDevice : public Device {
public:
@@ -1,16 +1,16 @@
#pragma once
#include "Device.h"
#include "../Device.h"
#include <cstdint>
namespace tt::hal {
namespace tt::hal::power {
class Power : public Device {
class PowerDevice : public Device {
public:
Power() = default;
~Power() override = default;
PowerDevice() = default;
~PowerDevice() override = default;
Type getType() const override { return Type::Power; }
@@ -34,7 +34,7 @@ public:
/**
* @return false when metric is not supported or (temporarily) not available.
*/
virtual bool getMetric(Power::MetricType type, MetricData& data) = 0;
virtual bool getMetric(MetricType type, MetricData& data) = 0;
virtual bool supportsChargeControl() const { return false; }
virtual bool isAllowedToCharge() const { return false; }
@@ -1,12 +1,12 @@
#pragma once
#include "Device.h"
#include "../Device.h"
#include <Tactility/TactilityCore.h>
namespace tt::hal {
namespace tt::hal::sdcard {
class SdCard : public Device {
class SdCardDevice : public Device {
public:
@@ -28,8 +28,8 @@ private:
public:
explicit SdCard(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
virtual ~SdCard() override = default;
explicit SdCardDevice(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
virtual ~SdCardDevice() override = default;
Type getType() const final { return Type::SdCard; };
@@ -46,7 +46,7 @@ public:
};
/** Return the SdCard device if the path is within the SdCard mounted path (path std::string::starts_with() check)*/
std::shared_ptr<SdCard> _Nullable findSdCard(const std::string& path);
std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path);
/**
* Acquires an SD card lock if the path is an SD card path.
@@ -54,7 +54,7 @@ std::shared_ptr<SdCard> _Nullable findSdCard(const std::string& path);
*/
template<typename ReturnType>
inline ReturnType withSdCardLock(const std::string& path, std::function<ReturnType()> fn) {
auto sdcard = hal::findSdCard(path);
auto sdcard = find(path);
std::unique_ptr<ScopedLockableUsage> scoped_lockable;
if (sdcard != nullptr) {
scoped_lockable = sdcard->getLockable()->scoped();
@@ -2,7 +2,7 @@
#pragma once
#include "Tactility/hal/SdCard.h"
#include "SdCardDevice.h"
#include <sd_protocol_types.h>
#include <utility>
@@ -10,13 +10,15 @@
#include <hal/spi_types.h>
#include <soc/gpio_num.h>
namespace tt::hal {
namespace tt::hal::sdcard {
/**
* SD card interface at the default SPI interface
*/
class SpiSdCard final : public tt::hal::SdCard {
class SpiSdCardDevice final : public SdCardDevice {
public:
struct Config {
Config(
gpio_num_t spiPinCs,
@@ -46,7 +48,7 @@ public:
gpio_num_t spiPinCd; // Card detect
gpio_num_t spiPinWp; // Write-protect
gpio_num_t spiPinInt; // Interrupt
SdCard::MountBehaviour mountBehaviourAtBoot;
SdCardDevice::MountBehaviour mountBehaviourAtBoot;
std::shared_ptr<Lockable> _Nullable lockable;
std::vector<gpio_num_t> csPinWorkAround;
spi_host_device_t spiHost;
@@ -67,8 +69,7 @@ private:
public:
explicit SpiSdCard(std::unique_ptr<Config> config) :
SdCard(config->mountBehaviourAtBoot),
explicit SpiSdCardDevice(std::unique_ptr<Config> config) : SdCardDevice(config->mountBehaviourAtBoot),
config(std::move(config))
{}
@@ -1,14 +1,14 @@
#pragma once
#include "Device.h"
#include "../Device.h"
#include <lvgl.h>
namespace tt::hal {
namespace tt::hal::touch {
class Display;
class Touch : public Device {
class TouchDevice : public Device {
public:
+2 -2
View File
@@ -1,9 +1,9 @@
#include "Tactility/hal/Configuration.h"
#include "Tactility/hal/Device.h"
#include "Tactility/hal/i2c/I2c.h"
#include "Tactility/hal/power/PowerDevice.h"
#include "Tactility/hal/spi/Spi.h"
#include "Tactility/hal/uart/Uart.h"
#include "Tactility/hal/Power.h"
#include <Tactility/kernel/SystemEvents.h>
@@ -42,7 +42,7 @@ void init(const Configuration& configuration) {
}
if (configuration.power != nullptr) {
std::shared_ptr<tt::hal::Power> power = configuration.power();
std::shared_ptr<tt::hal::power::PowerDevice> power = configuration.power();
hal::registerDevice(power);
}
@@ -1,10 +1,10 @@
#include "Tactility/hal/SdCard.h"
#include "Tactility/hal/Device.h"
#include "Tactility/hal/sdcard/SdCardDevice.h"
namespace tt::hal {
namespace tt::hal::sdcard {
std::shared_ptr<SdCard> _Nullable findSdCard(const std::string& path) {
auto sdcards = findDevices<SdCard>(Device::Type::SdCard);
std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path) {
auto sdcards = findDevices<SdCardDevice>(Device::Type::SdCard);
for (auto& sdcard : sdcards) {
if (sdcard->isMounted() && path.starts_with(sdcard->getMountPath())) {
return sdcard;
@@ -1,6 +1,6 @@
#ifdef ESP_PLATFORM
#include "Tactility/hal/SpiSdCard.h"
#include "Tactility/hal/sdcard/SpiSdCardDevice.h"
#include <Tactility/Log.h>
@@ -10,7 +10,7 @@
#define TAG "spi_sdcard"
namespace tt::hal {
namespace tt::hal::sdcard {
/**
* Before we can initialize the sdcard's SPI communications, we have to set all
@@ -19,7 +19,7 @@ namespace tt::hal {
* See https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino
* @return success result
*/
bool SpiSdCard::applyGpioWorkAround() {
bool SpiSdCardDevice::applyGpioWorkAround() {
TT_LOG_D(TAG, "init");
uint64_t pin_bit_mask = BIT64(config->spiPinCs);
@@ -50,7 +50,7 @@ bool SpiSdCard::applyGpioWorkAround() {
return true;
}
bool SpiSdCard::mountInternal(const std::string& newMountPath) {
bool SpiSdCardDevice::mountInternal(const std::string& newMountPath) {
TT_LOG_I(TAG, "Mounting %s", newMountPath.c_str());
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
@@ -92,7 +92,7 @@ bool SpiSdCard::mountInternal(const std::string& newMountPath) {
return true;
}
bool SpiSdCard::mount(const std::string& newMountPath) {
bool SpiSdCardDevice::mount(const std::string& newMountPath) {
if (!applyGpioWorkAround()) {
TT_LOG_E(TAG, "Failed to set SPI CS pins high. This is a pre-requisite for mounting.");
return false;
@@ -107,7 +107,7 @@ bool SpiSdCard::mount(const std::string& newMountPath) {
}
}
bool SpiSdCard::unmount() {
bool SpiSdCardDevice::unmount() {
if (card == nullptr) {
TT_LOG_E(TAG, "Can't unmount: not mounted");
return false;
@@ -124,7 +124,7 @@ bool SpiSdCard::unmount() {
}
// TODO: Refactor to "bool getStatus(Status* status)" method so that it can fail when the lvgl lock fails
tt::hal::SdCard::State SpiSdCard::getState() const {
SdCardDevice::State SpiSdCardDevice::getState() const {
if (card == nullptr) {
return State::Unmounted;
}
+3 -3
View File
@@ -1,9 +1,9 @@
#ifdef ESP_PLATFORM
#include "Tactility/hal/usb/Usb.h"
#include "Tactility/hal/usb/UsbTusb.h"
#include "Tactility/hal/SpiSdCard.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/hal/sdcard/SpiSdCardDevice.h"
#include "Tactility/hal/usb/UsbTusb.h"
#include <Tactility/Log.h>
@@ -32,7 +32,7 @@ sdmmc_card_t* _Nullable getCard() {
return nullptr;
}
auto spi_sdcard = std::static_pointer_cast<SpiSdCard>(sdcard);
auto spi_sdcard = std::static_pointer_cast<sdcard::SpiSdCardDevice>(sdcard);
if (spi_sdcard == nullptr) {
TT_LOG_W(TAG, "SD card interface is not supported (must be SpiSdCard)");
return nullptr;
@@ -17,7 +17,7 @@ private:
Mutex mutex;
std::unique_ptr<Timer> updateTimer;
hal::SdCard::State lastState = hal::SdCard::State::Unmounted;
hal::sdcard::SdCardDevice::State lastState = hal::sdcard::SdCardDevice::State::Unmounted;
bool lock(TickType_t timeout) const {
return mutex.lock(timeout);
@@ -34,7 +34,7 @@ private:
if (lock(50)) {
auto new_state = sdcard->getState();
if (new_state == hal::SdCard::State::Error) {
if (new_state == hal::sdcard::SdCardDevice::State::Error) {
TT_LOG_W(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
sdcard->unmount();
}