Driver improvements (#535)
- New drivers: - SD SPI - spi_peripheral - touch_placeholder - display_placeholder - Devicetree compiler: - Implement phandle-arrays - Implement device addresses - Add placeholder drivers to all devices with a SPI display - SPI driver: add `cs-pins` and set them to high on driver start - FileSystem: add `file_system_set_owner()` and `file_system_get_owner()` - File locking is now checking if the related `FileSystem` is part of a shared SPI bus - Add `device_get_child_count()` - SDMMC driver: Remove default of `slot` value - Fix for Crowpanel Basic 3.5" display (add delay to booting) - Fix for LilyGO T-HMI SD card mounting (delayed mounting by disabling it initially in the dts)
This commit is contained in:
committed by
GitHub
parent
e50659a3fb
commit
599fa46766
@@ -1,26 +1,50 @@
|
||||
#include <tactility/hal/Device.h>
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/drivers/sdcard.h>
|
||||
#include <tactility/filesystem/file_system.h>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
std::shared_ptr<SdCardDevice> find(const std::string& path) {
|
||||
auto sdcards = findDevices<SdCardDevice>(Device::Type::SdCard);
|
||||
for (auto& sdcard : sdcards) {
|
||||
if (sdcard->isMounted() && path.starts_with(sdcard->getMountPath())) {
|
||||
return sdcard;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Lock> findSdCardLock(const std::string& path) {
|
||||
auto sdcard = find(path);
|
||||
if (sdcard != nullptr) {
|
||||
return sdcard->getLock();
|
||||
}
|
||||
struct Ctx {
|
||||
const std::string& path;
|
||||
std::shared_ptr<Lock> result;
|
||||
};
|
||||
Ctx ctx = { path, nullptr };
|
||||
|
||||
return nullptr;
|
||||
file_system_for_each(&ctx, [](FileSystem* fs, void* context) {
|
||||
auto* c = static_cast<Ctx*>(context);
|
||||
char mount_path[64];
|
||||
if (file_system_get_path(fs, mount_path, sizeof(mount_path)) != ERROR_NONE) return true;
|
||||
if (!c->path.starts_with(mount_path)) return true;
|
||||
|
||||
auto* owner = file_system_get_owner(fs);
|
||||
if (owner != nullptr) {
|
||||
// Check for I2C controller: if it has more than 2 children, assume it's the display
|
||||
// TODO: Improve this
|
||||
auto* parent = device_get_parent(owner);
|
||||
if (parent != nullptr && device_get_child_count(parent) >= 2) {
|
||||
c->result = lvgl::getSyncLock();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return ctx.result;
|
||||
}
|
||||
|
||||
void mountAll() {
|
||||
device_for_each_of_type(&SDCARD_TYPE, nullptr, [](::Device* device, void*) -> bool {
|
||||
if (!device_is_ready(device)) {
|
||||
if (device_start(device) != ERROR_NONE) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user