74127a5f6c
- Add kernel support for SPI driver - Add kernel support for UART driver - Implemented ESP32 UART kernel driver - Update existing UART-related code in Tactility to use new kernel driver - Remove UART from tt::hal::Configuration - Remove tt_hal_uart functionality but keep functions for now - Update devicetrees for UART changes - Kernel mutex and recursive mutex: improved locking API design - Other kernel improvements - Added device_exists_of_type() and device_find_by_name()
87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
#include <Tactility/Logger.h>
|
|
#include <Tactility/Tactility.h>
|
|
#include <tactility/check.h>
|
|
#include <Tactility/hal/Configuration.h>
|
|
#include <tactility/hal/Device.h>
|
|
#include <Tactility/hal/spi/SpiInit.h>
|
|
|
|
#include <Tactility/hal/display/DisplayDevice.h>
|
|
#include <Tactility/hal/sdcard/SdCardMounting.h>
|
|
#include <Tactility/hal/touch/TouchDevice.h>
|
|
#include <Tactility/kernel/SystemEvents.h>
|
|
|
|
namespace tt::hal {
|
|
|
|
static const auto LOGGER = Logger("Hal");
|
|
|
|
void registerDevices(const Configuration& configuration) {
|
|
LOGGER.info("Registering devices");
|
|
|
|
auto devices = configuration.createDevices();
|
|
for (auto& device : devices) {
|
|
registerDevice(device);
|
|
|
|
// Register attached devices
|
|
if (device->getType() == Device::Type::Display) {
|
|
const auto display = std::static_pointer_cast<display::DisplayDevice>(device);
|
|
assert(display != nullptr);
|
|
const std::shared_ptr<Device> touch = display->getTouchDevice();
|
|
if (touch != nullptr) {
|
|
registerDevice(touch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void startDisplays() {
|
|
LOGGER.info("Starting displays & touch");
|
|
auto displays = hal::findDevices<display::DisplayDevice>(Device::Type::Display);
|
|
for (auto& display : displays) {
|
|
LOGGER.info("{} starting", display->getName());
|
|
if (!display->start()) {
|
|
LOGGER.error("{} start failed", display->getName());
|
|
} else {
|
|
LOGGER.info("{} started", display->getName());
|
|
|
|
if (display->supportsBacklightDuty()) {
|
|
LOGGER.info("Setting backlight");
|
|
display->setBacklightDuty(0);
|
|
}
|
|
|
|
auto touch = display->getTouchDevice();
|
|
if (touch != nullptr) {
|
|
LOGGER.info("{} starting", touch->getName());
|
|
if (!touch->start()) {
|
|
LOGGER.error("{} start failed", touch->getName());
|
|
} else {
|
|
LOGGER.info("{} started", touch->getName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void init(const Configuration& configuration) {
|
|
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin);
|
|
|
|
check(spi::init(configuration.spi), "SPI init failed");
|
|
|
|
if (configuration.initBoot != nullptr) {
|
|
check(configuration.initBoot(), "Init boot failed");
|
|
}
|
|
|
|
registerDevices(configuration);
|
|
|
|
sdcard::mountAll(); // Warning: This needs to happen BEFORE displays are initialized on the SPI bus
|
|
|
|
startDisplays(); // Warning: SPI displays need to start after SPI SD cards are mounted
|
|
|
|
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalEnd);
|
|
}
|
|
|
|
const Configuration* getConfiguration() {
|
|
return tt::getConfiguration()->hardware;
|
|
}
|
|
|
|
} // namespace
|