Updates to addressable LED (#2098)

Only PWM Headers are supported, so enforce that.

Also fixes some init checks and init order checks.
This commit is contained in:
Thad House
2019-11-18 15:25:04 -08:00
committed by Peter Johnson
parent 1894219ef6
commit 6f6c6da9f5
5 changed files with 41 additions and 6 deletions

View File

@@ -44,6 +44,24 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
HAL_DigitalHandle outputPort, int32_t* status) {
hal::init::CheckInit();
auto digitalPort =
hal::digitalChannelHandles->Get(outputPort, hal::HAL_HandleEnum::PWM);
if (!digitalPort) {
// If DIO was passed, channel error, else generic error
if (getHandleType(outputPort) == hal::HAL_HandleEnum::DIO) {
*status = HAL_LED_CHANNEL_ERROR;
} else {
*status = HAL_HANDLE_ERROR;
}
return HAL_kInvalidHandle;
}
if (digitalPort->channel >= kNumPWMHeaders) {
*status = HAL_LED_CHANNEL_ERROR;
return HAL_kInvalidHandle;
}
HAL_AddressableLEDHandle handle = ledHandles->Allocate();
if (handle == HAL_kInvalidHandle) {
*status = NO_AVAILABLE_RESOURCES;
@@ -57,11 +75,7 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
}
int16_t index = getHandleIndex(handle);
if (auto port = digitalChannelHandles->Get(outputPort, HAL_HandleEnum::PWM)) {
SimAddressableLEDData[index].outputPort = port->channel;
} else {
SimAddressableLEDData[index].outputPort = -1;
}
SimAddressableLEDData[index].outputPort = digitalPort->channel;
SimAddressableLEDData[index].length = 1;
SimAddressableLEDData[index].running = false;
SimAddressableLEDData[index].initialized = true;