mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[hal] Error if attempting to set DIO output on an input port (#3436)
This commit is contained in:
@@ -272,6 +272,29 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
|
||||
}
|
||||
{
|
||||
std::scoped_lock lock(digitalDIOMutex);
|
||||
|
||||
tDIO::tOutputEnable currentOutputEnable =
|
||||
digitalSystem->readOutputEnable(status);
|
||||
|
||||
HAL_Bool isInput = false;
|
||||
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
isInput =
|
||||
((currentOutputEnable.SPIPort >> remapSPIChannel(port->channel)) &
|
||||
1) != 0;
|
||||
} else if (port->channel < kNumDigitalHeaders) {
|
||||
isInput = ((currentOutputEnable.Headers >> port->channel) & 1) != 0;
|
||||
} else {
|
||||
isInput = ((currentOutputEnable.MXP >> remapMXPChannel(port->channel)) &
|
||||
1) != 0;
|
||||
}
|
||||
|
||||
if (isInput) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status, "Cannot set output of an input channel");
|
||||
return;
|
||||
}
|
||||
|
||||
tDIO::tDO currentDIO = digitalSystem->readDO(status);
|
||||
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
|
||||
@@ -40,6 +40,11 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
||||
*/
|
||||
HAL_Bool HAL_CheckDIOChannel(int32_t channel);
|
||||
|
||||
/**
|
||||
* Frees a DIO port.
|
||||
*
|
||||
* @param handle the DIO channel handle
|
||||
*/
|
||||
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle);
|
||||
|
||||
/**
|
||||
|
||||
@@ -174,6 +174,11 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
|
||||
value = 1;
|
||||
}
|
||||
}
|
||||
if (SimDIOData[port->channel].isInput) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status, "Cannot set output of an input channel");
|
||||
return;
|
||||
}
|
||||
SimDIOData[port->channel].value = value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user