Tactility/TactilityC/Source/tt_hal_device.cpp
Ken Van Hoeylandt e6abd496f9
Various improvements (#461)
* **New Features**
  * Time and delay utilities added (ticks, ms, µs); SD card now uses an expansion-header CS pin; HTTP downloads warn when run on the GUI task and yield to avoid blocking.

* **Bug Fixes / Reliability**
  * Many hard-crash paths converted to guarded checks to reduce abrupt termination and improve stability.

* **Tests**
  * Unit tests added to validate time and delay accuracy.

* **Chores**
  * License header and build/macro updates.
2026-01-27 08:04:21 +01:00

49 lines
1.3 KiB
C++

#include "tt_hal_device.h"
#include "Tactility/Check.h"
#include <Tactility/hal/Device.h>
static tt::hal::Device::Type toTactilityDeviceType(DeviceType type) {
switch (type) {
case DEVICE_TYPE_I2C:
return tt::hal::Device::Type::I2c;
case DEVICE_TYPE_DISPLAY:
return tt::hal::Device::Type::Display;
case DEVICE_TYPE_TOUCH:
return tt::hal::Device::Type::Touch;
case DEVICE_TYPE_SDCARD:
return tt::hal::Device::Type::SdCard;
case DEVICE_TYPE_KEYBOARD:
return tt::hal::Device::Type::Keyboard;
case DEVICE_TYPE_POWER:
return tt::hal::Device::Type::Power;
case DEVICE_TYPE_GPS:
return tt::hal::Device::Type::Gps;
default:
check(false, "Device::Type not supported");
}
}
extern "C" {
bool tt_hal_device_find(DeviceType type, DeviceId* deviceIds, uint16_t* count, uint16_t maxCount) {
assert(maxCount > 0);
int16_t currentIndex = -1;
uint16_t maxIndex = maxCount - 1;
findDevices<tt::hal::Device>(toTactilityDeviceType(type), [&](const auto& device) {
currentIndex++;
deviceIds[currentIndex] = device->getId();
// Continue if there is storage capacity left
return currentIndex < maxIndex;
});
*count = currentIndex + 1;
return currentIndex >= 0;
}
}