Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if (DEFINED ENV{ESP_IDF_VERSION})
"Firmware"
"Devices/${TACTILITY_DEVICE_PROJECT}"
"Drivers"
"Modules"
"Platforms/PlatformEsp32"
"TactilityKernel"
"Tactility"
Expand Down Expand Up @@ -84,6 +85,7 @@ if (NOT DEFINED ENV{ESP_IDF_VERSION})
add_subdirectory(Libraries/QRCode)
add_subdirectory(Libraries/minitar)
add_subdirectory(Libraries/minmea)
add_subdirectory(Modules/hal-device)

# FreeRTOS
set(FREERTOS_CONFIG_FILE_DIRECTORY ${PROJECT_SOURCE_DIR}/Devices/simulator/Source CACHE STRING "")
Expand Down
2 changes: 1 addition & 1 deletion Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static bool initBoot() {

using namespace tt::hal;

static std::vector<std::shared_ptr<Device>> createDevices() {
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
return {
createPower(),
ButtonControl::createOneButtonControl(0),
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tdeck/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bool initBoot();

using namespace tt::hal;

static std::vector<std::shared_ptr<Device>> createDevices() {
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
return {
createPower(),
createDisplay(),
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tdeck/Source/devices/KeyboardBacklight.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <Tactility/hal/Device.h>
#include <tactility/hal/Device.h>
#include <Tactility/TactilityCore.h>

class KeyboardBacklightDevice final : public tt::hal::Device {
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tdeck/Source/devices/TdeckKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Tactility/settings/KeyboardSettings.h>
#include <Tactility/settings/DisplaySettings.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/Device.h>
#include <tactility/hal/Device.h>
#include <Tactility/Logger.h>
#include <KeyboardBacklight/KeyboardBacklight.h>

Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tdeck/Source/devices/TrackballDevice.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <Tactility/hal/Device.h>
#include <tactility/hal/Device.h>
#include <lvgl.h>

class TrackballDevice : public tt::hal::Device {
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tdisplay-s3/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bool initBoot();

using namespace tt::hal;

static std::vector<std::shared_ptr<Device>> createDevices() {
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
return {
createPower(),
createDisplay(),
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tdisplay/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static bool initBoot() {
return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT);
}

static std::vector<std::shared_ptr<Device>> createDevices() {
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
return {
createDisplay(),
ButtonControl::createTwoButtonControl(35, 0)
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tdongle-s3/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool initBoot();

using namespace tt::hal;

static std::vector<std::shared_ptr<Device>> createDevices() {
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
return {
createDisplay(),
createSdCard()
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tlora-pager/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static DeviceVector createDevices() {
auto tca8418 = std::make_shared<Tca8418>(I2C_NUM_0);
auto keyboard = std::make_shared<TpagerKeyboard>(tca8418);

return std::vector<std::shared_ptr<Device>> {
return std::vector<std::shared_ptr<tt::hal::Device>> {
tca8418,
std::make_shared<Bq25896>(I2C_NUM_0),
bq27220,
Expand Down
4 changes: 2 additions & 2 deletions Devices/lilygo-tlora-pager/Source/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ extern Driver tlora_pager_driver;
static error_t start() {
/* We crash when construct fails, because if a single driver fails to construct,
* there is no guarantee that the previously constructed drivers can be destroyed */
check(driver_construct(&tlora_pager_driver) == ERROR_NONE);
check(driver_construct_add(&tlora_pager_driver) == ERROR_NONE);
return ERROR_NONE;
}

static error_t stop() {
/* We crash when destruct fails, because if a single driver fails to destruct,
* there is no guarantee that the previously destroyed drivers can be recovered */
check(driver_destruct(&tlora_pager_driver) == ERROR_NONE);
check(driver_remove_destruct(&tlora_pager_driver) == ERROR_NONE);
return ERROR_NONE;
}

Expand Down
2 changes: 1 addition & 1 deletion Devices/simulator/Source/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void deinitPower() {
#endif
}

static std::vector<std::shared_ptr<Device>> createDevices() {
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
return {
std::make_shared<SdlDisplay>(),
std::make_shared<SdlKeyboard>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool initBoot();

using namespace tt::hal;

static std::vector<std::shared_ptr<Device>> createDevices() {
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
return {
createDisplay(),
createSdCard()
Expand Down
2 changes: 1 addition & 1 deletion Drivers/XPT2046/Source/Xpt2046Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Xpt2046Touch.h"

#include <Tactility/Logger.h>
#include <Tactility/hal/Device.h>
#include <tactility/hal/Device.h>

static const auto LOGGER = tt::Logger("Xpt2046Power");

Expand Down
1 change: 1 addition & 0 deletions Firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ else ()
TactilityCore
TactilityFreeRtos
TactilityKernel
hal-device
Simulator
PlatformPosix
SDL2::SDL2-static SDL2-static
Expand Down
46 changes: 46 additions & 0 deletions Modules/hal-device/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.20)

if (DEFINED ENV{ESP_IDF_VERSION})
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)

list(APPEND REQUIRES_LIST
TactilityKernel
TactilityCore
TactilityFreeRtos
)

idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Include/"
REQUIRES ${REQUIRES_LIST}
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${COMPONENT_LIB} PUBLIC -Wno-unused-variable)
endif ()

else ()

file(GLOB_RECURSE SOURCES "Source/*.c*")

add_library(hal-device OBJECT)

target_sources(hal-device PRIVATE ${SOURCES})

target_include_directories(hal-device
PRIVATE Private/
PUBLIC Include/
)

add_definitions(-D_Nullable=)
add_definitions(-D_Nonnull=)

target_link_libraries(hal-device PUBLIC
TactilityFreeRtos
TactilityCore
TactilityKernel
freertos_kernel
)

endif ()

28 changes: 28 additions & 0 deletions Modules/hal-device/Include/tactility/drivers/hal_device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

enum class HalDeviceType {
HAL_DEVICE_TYPE_I2C,
HAL_DEVICE_TYPE_DISPLAY,
HAL_DEVICE_TYPE_TOUCH,
HAL_DEVICE_TYPE_SDCARD,
HAL_DEVICE_TYPE_KEYBOARD,
HAL_DEVICE_TYPE_ENCODER,
HAL_DEVICE_TYPE_POWER,
HAL_DEVICE_TYPE_GPS,
HAL_DEVICE_TYPE_OTHER
};

HalDeviceType hal_device_get_type(struct Device* device);

void hal_device_for_each_of_type(HalDeviceType type, void* context, bool(*onDevice)(struct Device* device, void* context));

extern const struct DeviceType HAL_DEVICE_TYPE;

#ifdef __cplusplus
}
#endif
21 changes: 21 additions & 0 deletions Modules/hal-device/Include/tactility/drivers/hal_device.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include "hal_device.h"

#include <memory>
#include <tactility/hal/Device.h>

namespace tt::hal {

/**
* @brief Get a tt::hal::Device object from a Kernel device.
* @warning The input device must be of type HAL_DEVICE_TYPE
* @param kernelDevice The kernel device
* @return std::shared_ptr<Device>
*/
std::shared_ptr<Device> hal_device_get_device(::Device* kernelDevice);

void hal_device_set_device(::Device* kernelDevice, std::shared_ptr<Device> halDevice);

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <functional>
Expand All @@ -7,6 +8,10 @@
#include <vector>
#include <cassert>

#include <tactility/device.h>

typedef ::Device KernelDevice;

namespace tt::hal {
/** Base class for HAL-related devices. */
class Device {
Expand All @@ -27,9 +32,19 @@ class Device {

typedef uint32_t Id;

struct KernelDeviceHolder {
const std::string name;
std::shared_ptr<KernelDevice> device = std::make_shared<KernelDevice>();

explicit KernelDeviceHolder(std::string name) : name(name) {
device->name = this->name.c_str();
}
};

private:

Id id;
std::shared_ptr<KernelDeviceHolder> kernelDeviceHolder;

public:

Expand All @@ -49,6 +64,10 @@ class Device {
* e.g. "USB charging controller with I2C interface."
*/
virtual std::string getDescription() const = 0;

void setKernelDeviceHolder(std::shared_ptr<KernelDeviceHolder> kernelDeviceHolder) { this->kernelDeviceHolder = kernelDeviceHolder; }

std::shared_ptr<KernelDeviceHolder> getKernelDeviceHolder() const { return kernelDeviceHolder; }
};

/**
Expand Down Expand Up @@ -92,7 +111,7 @@ std::vector<std::shared_ptr<DeviceType>> findDevices(Device::Type type) {
assert(target_device != nullptr);
result.push_back(target_device);
}
return std::move(result);
return result;
}
}

Expand Down
12 changes: 12 additions & 0 deletions Modules/hal-device/Include/tactility/hal_device_module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

extern struct Module hal_device_module;

#ifdef __cplusplus
}
#endif
Loading