Ken Van Hoeylandt cff0605b0a
Implement device management (#199)
- Added `tt::hal::Device` and functions (de)register devices and search for them.
- Refactored apps: `Power` and `Display` settings apps now use the device API to find devices.
- Implemented the new API for all existing drivers for all devices, including the simulator.
- Updated HAL Configuration to return `std::shared_ptr` instead of raw pointers.
- Added test project for headless tests and implemented tests for the new code.
2025-02-02 15:16:51 +01:00

44 lines
1.3 KiB
C++

#include "Tactility/hal/Device.h"
#include "Tactility/hal/Hal_i.h"
#include "Tactility/hal/i2c/I2c.h"
#include <Tactility/kernel/SystemEvents.h>
#define TAG "hal"
namespace tt::hal {
void init(const Configuration& configuration) {
kernel::systemEventPublish(kernel::SystemEvent::BootInitHalBegin);
kernel::systemEventPublish(kernel::SystemEvent::BootInitI2cBegin);
tt_check(i2c::init(configuration.i2c), "I2C init failed");
if (configuration.initHardware != nullptr) {
TT_LOG_I(TAG, "Init hardware");
tt_check(configuration.initHardware(), "Hardware init failed");
}
kernel::systemEventPublish(kernel::SystemEvent::BootInitI2cEnd);
if (configuration.initBoot != nullptr) {
TT_LOG_I(TAG, "Init power");
tt_check(configuration.initBoot(), "Init power failed");
}
if (configuration.sdcard != nullptr) {
TT_LOG_I(TAG, "Mounting sdcard");
if (!configuration.sdcard->mount(TT_SDCARD_MOUNT_POINT)) {
TT_LOG_W(TAG, "SD card mount failed (init can continue)");
}
hal::registerDevice(configuration.sdcard);
}
if (configuration.power != nullptr) {
std::shared_ptr<tt::hal::Power> power = configuration.power();
hal::registerDevice(power);
}
kernel::systemEventPublish(kernel::SystemEvent::BootInitHalEnd);
}
} // namespace