#include "tt_hal_radio.h" #include "Tactility/Check.h" #include "Tactility/hal/Device.h" #include "Tactility/hal/display/DisplayDevice.h" #include "Tactility/hal/display/DisplayDriver.h" static Modulation fromCpp(tt::hal::radio::RadioDevice::Modulation modulation) { switch (modulation) { case tt::hal::radio::RadioDevice::Modulation::LoRa: return MODULATION_LORA; case tt::hal::radio::RadioDevice::Modulation::Fsk: return MODULATION_FSK; case tt::hal::radio::RadioDevice::Modulation::LrFhss: return MODULATION_LRFHSS; default: tt_crash("Modulation not supported"); } } static tt::hal::radio::RadioDevice::Modulation modulation toCpp(Modulation modulation) { switch (modulation) { case MODULATION_LORA: return tt::hal::radio::RadioDevice::Modulation::LoRa; case MODULATION_FSK: return tt::hal::radio::RadioDevice::Modulation::Fsk; case MODULATION_LRFHSS: return tt::hal::radio::RadioDevice::Modulation::LrFhss; default: tt_crash("Modulation not supported"); } } struct DeviceWrapper { std::shared_ptr device; DeviceWrapper(std::shared_ptr device) : device(device) {} }; static std::shared_ptr findValidRadioDevice(tt::hal::Device::Id id) { auto device = tt::hal::findDevice(id); if (device == nullptr || device->getType() != tt::hal::Device::Type::Radio) { return nullptr; } return std::reinterpret_pointer_cast(device); } extern "C" { RadioHandle tt_hal_radio_alloc(DeviceId radioId) { auto radio = findValidRadioDevice(id); return new DeviceWrapper(radio); } void tt_hal_radio_free(RadioHandle handle) { auto wrapper = static_cast(handle); delete wrapper; } void tt_hal_radio_set_modulation(RadioHandle handle, Modulation modulation) { auto wrapper = static_cast(handle); wrapper->device->setModulation(toCpp(modulation)); } Modulation tt_hal_radio_get_modulation(RadioHandle handle) { auto wrapper = static_cast(handle); return fromCpp(wrapper->device->getModulation()); } }