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: