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

@@ -13,6 +13,7 @@
#include "ConstantsInternal.h"
#include "DigitalInternal.h"
#include "HALInitializer.h"
#include "PortsInternal.h"
#include "hal/ChipObject.h"
#include "hal/handles/HandlesInternal.h"
@@ -94,11 +95,23 @@ extern "C" {
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) {
*status = HAL_HANDLE_ERROR;
// 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;
}