mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
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:
committed by
Peter Johnson
parent
1894219ef6
commit
6f6c6da9f5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,8 @@ const char* HAL_GetErrorMessage(int32_t code) {
|
||||
return ERR_FRCSystem_NoDSConnection_MESSAGE;
|
||||
case HAL_CAN_BUFFER_OVERRUN:
|
||||
return HAL_CAN_BUFFER_OVERRUN_MESSAGE;
|
||||
case HAL_LED_CHANNEL_ERROR:
|
||||
return HAL_LED_CHANNEL_ERROR_MESSAGE;
|
||||
default:
|
||||
return "Unknown error status";
|
||||
}
|
||||
|
||||
@@ -94,6 +94,10 @@
|
||||
#define HAL_HANDLE_ERROR_MESSAGE \
|
||||
"HAL: A handle parameter was passed incorrectly"
|
||||
|
||||
#define HAL_LED_CHANNEL_ERROR -1099
|
||||
#define HAL_LED_CHANNEL_ERROR_MESSAGE \
|
||||
"HAL: Addressable LEDs only supported on PWM Headers, not MXP or DIO"
|
||||
|
||||
#define HAL_INVALID_DMA_ADDITION -1102
|
||||
#define HAL_INVALID_DMA_ADDITION_MESSAGE \
|
||||
"HAL_AddDMA() only works before HAL_StartDMA()"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -207,6 +207,8 @@ const char* HAL_GetErrorMessage(int32_t code) {
|
||||
return HAL_SIM_NOT_SUPPORTED_MESSAGE;
|
||||
case HAL_CAN_BUFFER_OVERRUN:
|
||||
return HAL_CAN_BUFFER_OVERRUN_MESSAGE;
|
||||
case HAL_LED_CHANNEL_ERROR:
|
||||
return HAL_LED_CHANNEL_ERROR_MESSAGE;
|
||||
default:
|
||||
return "Unknown error status";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user