Radio: Start working on TactilityC
... it begins ...
This commit is contained in:
parent
d876d70cd4
commit
320a756799
@ -13,7 +13,8 @@ enum DeviceType {
|
||||
DEVICE_TYPE_SDCARD,
|
||||
DEVICE_TYPE_KEYBOARD,
|
||||
DEVICE_TYPE_POWER,
|
||||
DEVICE_TYPE_GPS
|
||||
DEVICE_TYPE_GPS,
|
||||
DEVICE_TYPE_RADIO
|
||||
};
|
||||
|
||||
typedef uint32_t DeviceId;
|
||||
|
||||
44
TactilityC/Include/tt_hal_radio.h
Normal file
44
TactilityC/Include/tt_hal_radio.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* RadioHandle;
|
||||
|
||||
enum Modulation {
|
||||
MODULATION_LORA,
|
||||
MODULATION_FSK,
|
||||
MODULATION_LRFHSS
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocate a radio driver object for the specified radioId.
|
||||
* @param[in] radioId the identifier of the radio device
|
||||
* @return the radio handle
|
||||
*/
|
||||
RadioHandle tt_hal_radio_alloc(DeviceId radioId);
|
||||
|
||||
/**
|
||||
* Free the memory for the radio driver object.
|
||||
* @param[in] handle the radio driver handle
|
||||
*/
|
||||
void tt_hal_radio_free(RadioHandle handle);
|
||||
|
||||
/**
|
||||
* Set the modulation for the radio driver object.
|
||||
* @param[in] modulation the modulation type
|
||||
* @param[in] handle the radio driver handle
|
||||
*/
|
||||
void tt_hal_radio_set_modulation(RadioHandle handle, Modulation modulation);
|
||||
|
||||
/**
|
||||
* Get the modulation for the radio driver object.
|
||||
* @param[in] handle the radio driver handle
|
||||
* @return the modulation type
|
||||
*/
|
||||
Modulation tt_hal_radio_get_modulation(RadioHandle handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -20,6 +20,8 @@ static tt::hal::Device::Type toTactilityDeviceType(DeviceType type) {
|
||||
return tt::hal::Device::Type::Power;
|
||||
case DEVICE_TYPE_GPS:
|
||||
return tt::hal::Device::Type::Gps;
|
||||
case DEVICE_TYPE_RADIO:
|
||||
return tt::hal::Device::Type::Radio;
|
||||
default:
|
||||
tt_crash("Device::Type not supported");
|
||||
}
|
||||
|
||||
68
TactilityC/Source/tt_hal_radio.cpp
Normal file
68
TactilityC/Source/tt_hal_radio.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#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<tt::hal::radio::RadioDevice> device;
|
||||
DeviceWrapper(std::shared_ptr<tt::hal::radio::RadioDevice> device) : device(device) {}
|
||||
};
|
||||
|
||||
static std::shared_ptr<tt::hal::radio::RadioDevice> 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<tt::hal::radio::RadioDevice>(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<DeviceWrapper*>(handle);
|
||||
delete wrapper;
|
||||
}
|
||||
|
||||
void tt_hal_radio_set_modulation(RadioHandle handle, Modulation modulation) {
|
||||
auto wrapper = static_cast<DeviceWrapper*>(handle);
|
||||
wrapper->device->setModulation(toCpp(modulation));
|
||||
}
|
||||
|
||||
Modulation tt_hal_radio_get_modulation(RadioHandle handle) {
|
||||
auto wrapper = static_cast<DeviceWrapper*>(handle);
|
||||
return fromCpp(wrapper->device->getModulation());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user