Project restructuring (fixes macOS builds) (#198)

- Create `Include/` folder for all main projects
- Fix some issues here and there (found while moving things)
- All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
This commit is contained in:
Ken Van Hoeylandt
2025-02-01 18:13:20 +01:00
committed by GitHub
parent 7856827ecf
commit c87200a80d
350 changed files with 967 additions and 870 deletions
@@ -1,63 +0,0 @@
#pragma once
#include "Power.h"
#include "hal/i2c/I2c.h"
#include "SdCard.h"
namespace tt::hal {
typedef bool (*InitBoot)();
typedef bool (*InitHardware)();
typedef bool (*InitLvgl)();
class Display;
class Keyboard;
typedef Display* (*CreateDisplay)();
typedef Keyboard* (*CreateKeyboard)();
typedef std::shared_ptr<Power> (*CreatePower)();
struct Configuration {
/**
* Called before I2C/SPI/etc is initialized.
* Used for powering on the peripherals manually.
*/
const InitBoot _Nullable initBoot = nullptr;
/**
* Called after I2C/SPI/etc is initialized.
* This can be used to communicate with built-in peripherals such as an I2C keyboard.
*/
const InitHardware _Nullable initHardware = nullptr;
/**
* Create and initialize all LVGL devices. (e.g. display, touch, keyboard)
*/
const InitLvgl _Nullable initLvgl = nullptr;
/**
* Display HAL functionality.
*/
const CreateDisplay _Nullable createDisplay = nullptr;
/**
* Display HAL functionality.
*/
const CreateKeyboard _Nullable createKeyboard = nullptr;
/**
* An optional SD card interface.
*/
const std::shared_ptr<SdCard> _Nullable sdcard = nullptr;
/**
* An optional power interface for battery or other power delivery.
*/
const CreatePower _Nullable power = nullptr;
/**
* A list of i2c interfaces
*/
const std::vector<i2c::Configuration> i2c = {};
};
} // namespace
-32
View File
@@ -1,32 +0,0 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Touch;
class Display {
public:
virtual bool start() = 0;
virtual bool stop() = 0;
virtual void setPowerOn(bool turnOn) {}
virtual bool isPoweredOn() const { return true; }
virtual bool supportsPowerControl() const { return false; }
virtual Touch* _Nullable createTouch() = 0;
/** Set a value in the range [0, 255] */
virtual void setBacklightDuty(uint8_t backlightDuty) { /* NO-OP */ }
virtual bool supportsBacklightDuty() const { return false; }
/** Set a value in the range [0, 255] */
virtual void setGammaCurve(uint8_t index) { /* NO-OP */ }
virtual uint8_t getGammaCurveCount() const { return 0; };
/** After start() returns true, this should return a valid pointer until stop() is called and returns true */
virtual lv_display_t* _Nullable getLvglDisplay() const = 0;
};
}
+4 -3
View File
@@ -1,6 +1,7 @@
#include "hal/Hal_i.h"
#include "hal/i2c/I2c.h"
#include "kernel/SystemEvents.h"
#include "Tactility/hal/Hal_i.h"
#include "Tactility/hal/i2c/I2c.h"
#include <Tactility/kernel/SystemEvents.h>
#define TAG "hal"
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Display;
class Keyboard {
public:
virtual bool start(lv_display_t* display) = 0;
virtual bool stop() = 0;
virtual bool isAttached() const = 0;
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
};
}
-41
View File
@@ -1,41 +0,0 @@
#pragma once
#include <cstdint>
namespace tt::hal {
class Power{
public:
Power() = default;
virtual ~Power() = default;
enum class MetricType {
IsCharging, // bool
Current, // int32_t, mAh - battery current: either during charging (positive value) or discharging (negative value)
BatteryVoltage, // uint32_t, mV
ChargeLevel, // 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
-39
View File
@@ -1,39 +0,0 @@
#pragma once
#include "TactilityCore.h"
namespace tt::hal {
#define TT_SDCARD_MOUNT_NAME "sdcard"
#define TT_SDCARD_MOUNT_POINT "/sdcard"
class SdCard {
public:
enum class State {
Mounted,
Unmounted,
Error,
Unknown
};
enum class MountBehaviour {
AtBoot, /** Only mount at boot */
Anytime /** Mount/dismount any time */
};
private:
MountBehaviour mountBehaviour;
public:
explicit SdCard(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
virtual ~SdCard() = default;
virtual bool mount(const char* mountPath) = 0;
virtual bool unmount() = 0;
virtual State getState() const = 0;
virtual MountBehaviour getMountBehaviour() const { return mountBehaviour; }
bool isMounted() const { return getState() == State::Mounted; }
};
} // namespace
+2 -3
View File
@@ -1,9 +1,8 @@
#ifdef ESP_PLATFORM
#include "SpiSdCard.h"
#include "Tactility/hal/SpiSdCard.h"
#include "Check.h"
#include "Log.h"
#include <Tactility/Log.h>
#include <driver/gpio.h>
#include <esp_vfs_fat.h>
-82
View File
@@ -1,82 +0,0 @@
#ifdef ESP_PLATFORM
#pragma once
#include "hal/SdCard.h"
#include <sd_protocol_types.h>
#include <utility>
#include <vector>
#include <hal/spi_types.h>
#include <soc/gpio_num.h>
namespace tt::hal {
/**
* SD card interface at the default SPI interface
*/
class SpiSdCard : public tt::hal::SdCard {
public:
struct Config {
Config(
gpio_num_t spiPinCs,
gpio_num_t spiPinCd,
gpio_num_t spiPinWp,
gpio_num_t spiPinInt,
MountBehaviour mountBehaviourAtBoot,
std::shared_ptr<Lockable> lockable = nullptr,
std::vector<gpio_num_t> csPinWorkAround = std::vector<gpio_num_t>(),
spi_host_device_t spiHost = SPI2_HOST,
int spiFrequencyKhz = SDMMC_FREQ_DEFAULT
) : spiFrequencyKhz(spiFrequencyKhz),
spiPinCs(spiPinCs),
spiPinCd(spiPinCd),
spiPinWp(spiPinWp),
spiPinInt(spiPinInt),
mountBehaviourAtBoot(mountBehaviourAtBoot),
lockable(std::move(lockable)),
csPinWorkAround(std::move(csPinWorkAround)),
spiHost(spiHost)
{}
int spiFrequencyKhz;
gpio_num_t spiPinCs; // Clock
gpio_num_t spiPinCd; // Card detect
gpio_num_t spiPinWp; // Write-protect
gpio_num_t spiPinInt; // Interrupt
SdCard::MountBehaviour mountBehaviourAtBoot;
std::shared_ptr<Lockable> _Nullable lockable;
std::vector<gpio_num_t> csPinWorkAround;
spi_host_device_t spiHost;
bool formatOnMountFailed = false;
uint16_t maxOpenFiles = 4;
uint16_t allocUnitSize = 16 * 1024;
bool statusCheckEnabled = false;
};
private:
std::string mountPoint;
sdmmc_card_t* card = nullptr;
std::shared_ptr<Config> config;
bool applyGpioWorkAround();
bool mountInternal(const char* mount_point);
public:
explicit SpiSdCard(std::unique_ptr<Config> config) :
SdCard(config->mountBehaviourAtBoot),
config(std::move(config))
{}
bool mount(const char* mountPath) override;
bool unmount() override;
State getState() const override;
sdmmc_card_t* _Nullable getCard() { return card; }
};
}
#endif
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Display;
class Touch {
public:
virtual bool start(lv_display_t* display) = 0;
virtual bool stop() = 0;
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
};
}
+4 -3
View File
@@ -1,8 +1,9 @@
#ifdef ESP_PLATFORM
#include "I2c.h"
#include "Log.h"
#include "Mutex.h"
#include "Tactility/hal/i2c/I2c.h"
#include <Tactility/Log.h>
#include <Tactility/Mutex.h>
#include <esp_check.h>
-54
View File
@@ -1,54 +0,0 @@
#pragma once
#include "I2cCompat.h"
#include "RtosCompat.h"
#include <climits>
#include <string>
#include <vector>
namespace tt::hal::i2c {
enum class InitMode {
ByTactility, // Tactility will initialize it in the correct bootup phase
ByExternal, // The device is already initialized and Tactility should assume it works
Disabled // Not initialized by default
};
struct Configuration {
std::string name;
/** The port to operate on */
i2c_port_t port;
/** Whether this bus should be initialized when device starts up */
InitMode initMode;
/** Whether this bus can stopped and re-started. */
bool canReinit;
/** Whether configuration can be changed. */
bool hasMutableConfiguration;
/** Configuration that must be valid when initAtBoot is set to true. */
i2c_config_t config;
};
enum class Status {
Started,
Stopped,
Unknown
};
bool init(const std::vector<i2c::Configuration>& configurations);
bool start(i2c_port_t port);
bool stop(i2c_port_t port);
bool isStarted(i2c_port_t port);
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout);
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout);
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout);
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout);
bool lock(i2c_port_t port, TickType_t timeout = 10 / portTICK_PERIOD_MS);
bool unlock(i2c_port_t port);
} // namespace
@@ -1,39 +0,0 @@
#pragma once
#ifdef ESP_PLATFORM
#include <hal/i2c_types.h>
#include <driver/i2c.h>
#else
#include <cstdint>
typedef int esp_err_t;
typedef enum {
I2C_NUM_0 = 0,
I2C_NUM_1,
LP_I2C_NUM_0,
I2C_NUM_MAX,
} i2c_port_t;
typedef enum{
I2C_MODE_MASTER,
I2C_MODE_MAX,
} i2c_mode_t;
typedef struct {
i2c_mode_t mode;
int sda_io_num;
int scl_io_num;
bool sda_pullup_en;
bool scl_pullup_en;
union {
struct {
uint32_t clk_speed;
} master;
};
uint32_t clk_flags;
} i2c_config_t;
#endif
@@ -1,4 +1,5 @@
#include "I2cDevice.h"
#include "Tactility/hal/i2c/I2cDevice.h"
#include <cstdint>
bool I2cDevice::readRegister12(uint8_t reg, float& out) const {
@@ -1,32 +0,0 @@
#pragma once
#include "./I2c.h"
/**
* Represents an I2C peripheral at a specific port and address.
* It helps to read and write registers.
*
* All read and write calls are thread-safe.
*/
class I2cDevice {
protected:
i2c_port_t port;
uint8_t address;
static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS;
bool readRegister8(uint8_t reg, uint8_t& result) const;
bool writeRegister8(uint8_t reg, uint8_t value) const;
bool readRegister12(uint8_t reg, float& out) const;
bool readRegister14(uint8_t reg, float& out) const;
bool readRegister16(uint8_t reg, uint16_t& out) const;
bool bitOn(uint8_t reg, uint8_t bitmask) const;
bool bitOff(uint8_t reg, uint8_t bitmask) const;
bool bitOnByIndex(uint8_t reg, uint8_t index) const { return bitOn(reg, 1 << index); }
bool bitOffByIndex(uint8_t reg, uint8_t index) const { return bitOff(reg, 1 << index); }
public:
explicit I2cDevice(i2c_port_t port, uint32_t address) : port(port), address(address) {}
};
+2 -2
View File
@@ -3,8 +3,8 @@
/**
* This code is based on i2c_manager from https://github.com/ropg/i2c_manager/blob/master/i2c_manager/i2c_manager.c (original has MIT license)
*/
#include "TactilityCore.h"
#include "I2c.h"
#include "Tactility/TactilityCore.h"
#include "Tactility/hal/i2c/I2c.h"
namespace tt::hal::i2c {
+6 -5
View File
@@ -1,10 +1,11 @@
#ifdef ESP_PLATFORM
#include <Log.h>
#include "Usb.h"
#include "UsbTusb.h"
#include "TactilityHeadless.h"
#include "hal/SpiSdCard.h"
#include "Tactility/hal/usb/Usb.h"
#include "Tactility/hal/usb/UsbTusb.h"
#include "Tactility/hal/SpiSdCard.h"
#include "Tactility/TactilityHeadless.h"
#include <Tactility/Log.h>
namespace tt::hal::usb {
-21
View File
@@ -1,21 +0,0 @@
#pragma once
namespace tt::hal::usb {
enum class Mode {
Default, // Default state of USB stack
None, // State after TinyUSB was used and (partially) deinitialized
MassStorageSdmmc
};
bool startMassStorageWithSdmmc();
void stop();
Mode getMode();
bool isSupported();
bool canRebootIntoMassStorageSdmmc();
void rebootIntoMassStorageSdmmc();
bool isUsbBootMode();
void resetUsbBootMode();
}
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef ESP_PLATFORM
#include "Usb.h"
#include "Tactility/hal/usb/Usb.h"
#define TAG "usb"
+6 -5
View File
@@ -1,13 +1,14 @@
#ifdef ESP_PLATFORM
#include "UsbTusb.h"
#include "sdkconfig.h"
#include "Tactility/hal/usb/UsbTusb.h"
#include <sdkconfig.h>
#if CONFIG_TINYUSB_MSC_ENABLED == 1
#include "Log.h"
#include "tinyusb.h"
#include "tusb_msc_storage.h"
#include <Tactility/Log.h>
#include <tinyusb.h>
#include <tusb_msc_storage.h>
#define TAG "usb"
#define EPNUM_MSC 1
@@ -1,5 +0,0 @@
#pragma once
bool tusbIsSupported();
bool tusbStartMassStorageWithSdmmc();
void tusbStop();