mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[hal, wpilib] Fix up DIO pulse API (#4387)
The FPGA API takes microseconds directly, instead of a scaled value. Also add a new HAL level API to trigger multiple DIOs with the same pulse at once.
This commit is contained in:
@@ -408,13 +408,24 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
|
||||
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLengthSeconds,
|
||||
int32_t* status) {
|
||||
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t pulseLengthMicroseconds =
|
||||
static_cast<uint32_t>(pulseLengthSeconds * 1e6);
|
||||
|
||||
if (pulseLengthMicroseconds <= 0 || pulseLengthMicroseconds > 0xFFFF) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status,
|
||||
"Length must be between 1 and 65535 microseconds");
|
||||
return;
|
||||
}
|
||||
|
||||
tDIO::tPulse pulse;
|
||||
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
@@ -426,9 +437,29 @@ void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
|
||||
}
|
||||
|
||||
digitalSystem->writePulseLength(
|
||||
static_cast<uint16_t>(1.0e9 * pulseLength /
|
||||
(pwmSystem->readLoopTiming(status) * 25)),
|
||||
status);
|
||||
static_cast<uint16_t>(pulseLengthMicroseconds), status);
|
||||
digitalSystem->writePulse(pulse, status);
|
||||
}
|
||||
|
||||
void HAL_PulseMultiple(uint32_t channelMask, double pulseLengthSeconds,
|
||||
int32_t* status) {
|
||||
uint32_t pulseLengthMicroseconds =
|
||||
static_cast<uint32_t>(pulseLengthSeconds * 1e6);
|
||||
|
||||
if (pulseLengthMicroseconds <= 0 || pulseLengthMicroseconds > 0xFFFF) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status,
|
||||
"Length must be between 1 and 65535 microseconds");
|
||||
return;
|
||||
}
|
||||
|
||||
tDIO::tPulse pulse;
|
||||
pulse.Headers = channelMask & 0x2FF;
|
||||
pulse.MXP = (channelMask & 0xFFFF) >> 10;
|
||||
pulse.SPIPort = (channelMask & 0x1F) >> 26;
|
||||
|
||||
digitalSystem->writePulseLength(
|
||||
static_cast<uint16_t>(pulseLengthMicroseconds), status);
|
||||
digitalSystem->writePulse(pulse, status);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user