mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal, wpilib] PWM Rewrite (#7845)
The HAL will only contain the output period and the raw microseconds. Higher level things such as SimDevice can handle everything else.
This commit is contained in:
@@ -17,11 +17,9 @@ void InitializePWMData() {
|
||||
PWMData* hal::SimPWMData;
|
||||
void PWMData::ResetData() {
|
||||
initialized.Reset(false);
|
||||
simDevice = 0;
|
||||
pulseMicrosecond.Reset(0);
|
||||
speed.Reset(0);
|
||||
position.Reset(0);
|
||||
periodScale.Reset(0);
|
||||
zeroLatch.Reset(false);
|
||||
outputPeriod.Reset(0);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@@ -29,16 +27,17 @@ void HALSIM_ResetPWMData(int32_t index) {
|
||||
SimPWMData[index].ResetData();
|
||||
}
|
||||
|
||||
HAL_SimDeviceHandle HALSIM_GetPWMSimDevice(int32_t index) {
|
||||
return SimPWMData[index].simDevice;
|
||||
}
|
||||
|
||||
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
||||
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PWM##CAPINAME, SimPWMData, \
|
||||
LOWERNAME)
|
||||
|
||||
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
|
||||
DEFINE_CAPI(int32_t, PulseMicrosecond, pulseMicrosecond)
|
||||
DEFINE_CAPI(double, Speed, speed)
|
||||
DEFINE_CAPI(double, Position, position)
|
||||
DEFINE_CAPI(int32_t, PeriodScale, periodScale)
|
||||
DEFINE_CAPI(HAL_Bool, ZeroLatch, zeroLatch)
|
||||
DEFINE_CAPI(int32_t, OutputPeriod, outputPeriod)
|
||||
|
||||
#define REGISTER(NAME) \
|
||||
SimPWMData[index].NAME.RegisterCallback(callback, param, initialNotify)
|
||||
@@ -47,9 +46,6 @@ void HALSIM_RegisterPWMAllCallbacks(int32_t index, HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {
|
||||
REGISTER(initialized);
|
||||
REGISTER(pulseMicrosecond);
|
||||
REGISTER(speed);
|
||||
REGISTER(position);
|
||||
REGISTER(periodScale);
|
||||
REGISTER(zeroLatch);
|
||||
REGISTER(outputPeriod);
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -11,20 +11,15 @@ namespace hal {
|
||||
class PWMData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(PulseMicrosecond)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Speed)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Position)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(PeriodScale)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(ZeroLatch)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(OutputPeriod)
|
||||
|
||||
public:
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
|
||||
false};
|
||||
std::atomic<HAL_SimDeviceHandle> simDevice;
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetPulseMicrosecondName> pulseMicrosecond{
|
||||
0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetSpeedName> speed{0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetPositionName> position{0};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetPeriodScaleName> periodScale{0};
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetZeroLatchName> zeroLatch{false};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetOutputPeriodName> outputPeriod{0};
|
||||
|
||||
virtual void ResetData();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user