Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hal, wpilib] PWM Rewrite #7845

Draft
wants to merge 7 commits into
base: 2027
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions hal/src/main/java/edu/wpi/first/hal/DIOJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ public class DIOJNI extends JNIWrapper {
*/
public static native boolean isAnyPulsing();

/**
* Gets the loop timing of the PWM system.
*
* @return the loop time in clock ticks
*/
public static native short getLoopTiming();

/**
* Allocates a DO PWM Generator.
*
Expand Down
32 changes: 0 additions & 32 deletions hal/src/main/java/edu/wpi/first/hal/PWMConfigDataResult.java

This file was deleted.

121 changes: 9 additions & 112 deletions hal/src/main/java/edu/wpi/first/hal/PWMJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,14 @@ public class PWMJNI extends DIOJNI {
*/
public static native void freePWMPort(int pwmPortHandle);

/**
* Sets the configuration settings for the PWM channel.
*
* <p>All values are in microseconds.
*
* @param pwmPortHandle the PWM handle
* @param maxPwm the maximum PWM value
* @param deadbandMaxPwm the high range of the center deadband
* @param centerPwm the center PWM value
* @param deadbandMinPwm the low range of the center deadband
* @param minPwm the minimum PWM value
*/
public static native void setPWMConfigMicroseconds(
int pwmPortHandle,
int maxPwm,
int deadbandMaxPwm,
int centerPwm,
int deadbandMinPwm,
int minPwm);

/**
* Gets the pwm configuration settings for the PWM channel.
*
* <p>Values are in microseconds.
*
* @param pwmPortHandle the PWM handle
* @return the pwm configuration settings
*/
public static native PWMConfigDataResult getPWMConfigMicroseconds(int pwmPortHandle);

/**
* Sets if the FPGA should output the center value if the input value is within the deadband.
*
* @param pwmPortHandle the PWM handle
* @param eliminateDeadband true to eliminate deadband, otherwise false
*/
public static native void setPWMEliminateDeadband(int pwmPortHandle, boolean eliminateDeadband);

/**
* Gets the current eliminate deadband value.
/**
* Indicates the pwm is used by a simulated device.
*
* @param pwmPortHandle the PWM handle
* @return true if set, otherwise false
* @param handle the pwm handle
* @param device simulated device handle
* @see "HAL_SetPWMSimDevice"
*/
public static native boolean getPWMEliminateDeadband(int pwmPortHandle);
public static native void setPWMSimDevice(int handle, int device);

/**
* Sets a PWM channel to the desired pulse width in microseconds.
Expand All @@ -87,28 +50,6 @@ public static native void setPWMConfigMicroseconds(
*/
public static native void setPulseTimeMicroseconds(int pwmPortHandle, int microsecondPulseTime);

/**
* Sets a PWM channel to the desired scaled value.
*
* <p>The values range from -1 to 1 and the period is controlled by the PWM Period and MinHigh
* registers.
*
* @param pwmPortHandle the PWM handle
* @param speed the scaled PWM value to set
*/
public static native void setPWMSpeed(int pwmPortHandle, double speed);

/**
* Sets a PWM channel to the desired position value.
*
* <p>The values range from 0 to 1 and the period is controlled by the PWM Period and MinHigh
* registers.
*
* @param pwmPortHandle the PWM handle
* @param position the positional PWM value to set
*/
public static native void setPWMPosition(int pwmPortHandle, double position);

/**
* Gets the current microsecond pulse time from a PWM channel.
*
Expand All @@ -118,56 +59,12 @@ public static native void setPWMConfigMicroseconds(
public static native int getPulseTimeMicroseconds(int pwmPortHandle);

/**
* Gets a scaled value from a PWM channel.
*
* <p>The values range from -1 to 1.
*
* @param pwmPortHandle the PWM handle
* @return the current speed PWM value
*/
public static native double getPWMSpeed(int pwmPortHandle);

/**
* Gets a position value from a PWM channel.
*
* <p>The values range from 0 to 1.
*
* @param pwmPortHandle the PWM handle
* @return the current positional PWM value
*/
public static native double getPWMPosition(int pwmPortHandle);

/**
* Sets a PWM channel to be disabled.
*
* <p>The channel is disabled until the next time it is set. Note this is different from just
* setting a 0 speed, as this will actively stop all signaling on the channel.
*
* @param pwmPortHandle the PWM handle.
*/
public static native void setPWMDisabled(int pwmPortHandle);

/**
* Forces a PWM signal to go to 0 temporarily.
*
* @param pwmPortHandle the PWM handle.
*/
public static native void latchPWMZero(int pwmPortHandle);

/**
* Sets the PWM output to be a continuous high signal while enabled.
*
* @param pwmPortHandle the PWM handle.
*/
public static native void setAlwaysHighMode(int pwmPortHandle);

/**
* Sets how how often the PWM signal is squelched, thus scaling the period.
* Sets the PWM output period.
*
* @param pwmPortHandle the PWM handle.
* @param squelchMask the 2-bit mask of outputs to squelch
* @param period 0 for 5ms, 1 or 2 for 10ms, 3 for 20ms
*/
public static native void setPWMPeriodScale(int pwmPortHandle, int squelchMask);
public static native void setPWMOutputPeriod(int pwmPortHandle, int period);

/** Utility class. */
private PWMJNI() {}
Expand Down
35 changes: 4 additions & 31 deletions hal/src/main/java/edu/wpi/first/hal/simulation/PWMDataJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,14 @@ public static native int registerPulseMicrosecondCallback(

public static native void setPulseMicrosecond(int index, int microsecondPulseTime);

public static native int registerSpeedCallback(
public static native int registerOutputPeriodCallback(
int index, NotifyCallback callback, boolean initialNotify);

public static native void cancelSpeedCallback(int index, int uid);
public static native void cancelOutputPeriodCallback(int index, int uid);

public static native double getSpeed(int index);
public static native int getOutputPeriod(int index);

public static native void setSpeed(int index, double speed);

public static native int registerPositionCallback(
int index, NotifyCallback callback, boolean initialNotify);

public static native void cancelPositionCallback(int index, int uid);

public static native double getPosition(int index);

public static native void setPosition(int index, double position);

public static native int registerPeriodScaleCallback(
int index, NotifyCallback callback, boolean initialNotify);

public static native void cancelPeriodScaleCallback(int index, int uid);

public static native int getPeriodScale(int index);

public static native void setPeriodScale(int index, int periodScale);

public static native int registerZeroLatchCallback(
int index, NotifyCallback callback, boolean initialNotify);

public static native void cancelZeroLatchCallback(int index, int uid);

public static native boolean getZeroLatch(int index);

public static native void setZeroLatch(int index, boolean zeroLatch);
public static native void setOutputPeriod(int index, int period);

public static native void resetData(int index);

Expand Down
15 changes: 0 additions & 15 deletions hal/src/main/native/cpp/jni/DIOJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,6 @@ Java_edu_wpi_first_hal_DIOJNI_isAnyPulsing
return returnValue;
}

/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: getLoopTiming
* Signature: ()S
*/
JNIEXPORT jshort JNICALL
Java_edu_wpi_first_hal_DIOJNI_getLoopTiming
(JNIEnv* env, jclass)
{
int32_t status = 0;
jshort returnValue = HAL_GetPWMLoopTiming(&status);
CheckStatus(env, status);
return returnValue;
}

/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: allocateDigitalPWM
Expand Down
13 changes: 0 additions & 13 deletions hal/src/main/native/cpp/jni/HALUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static JException halHandleExCls;
static JException uncleanStatusExCls;
static JException nullPointerEx;
static JClass powerDistributionVersionCls;
static JClass pwmConfigDataResultCls;
static JClass canStatusCls;
static JClass matchInfoDataCls;
static JClass canReceiveMessageCls;
Expand All @@ -56,7 +55,6 @@ static JClass canStreamOverflowExCls;
static const JClassInit classes[] = {
{"edu/wpi/first/hal/PowerDistributionVersion",
&powerDistributionVersionCls},
{"edu/wpi/first/hal/PWMConfigDataResult", &pwmConfigDataResultCls},
{"edu/wpi/first/hal/can/CANStatus", &canStatusCls},
{"edu/wpi/first/hal/MatchInfoData", &matchInfoDataCls},
{"edu/wpi/first/hal/can/CANReceiveMessage", &canReceiveMessageCls},
Expand Down Expand Up @@ -180,17 +178,6 @@ void ThrowBoundaryException(JNIEnv* env, double value, double lower,
env->Throw(static_cast<jthrowable>(ex));
}

jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm) {
static jmethodID constructor =
env->GetMethodID(pwmConfigDataResultCls, "<init>", "(IIIII)V");
return env->NewObject(
pwmConfigDataResultCls, constructor, static_cast<jint>(maxPwm),
static_cast<jint>(deadbandMaxPwm), static_cast<jint>(centerPwm),
static_cast<jint>(deadbandMinPwm), static_cast<jint>(minPwm));
}

jobject CreateREVPHVersion(JNIEnv* env, uint32_t firmwareMajor,
uint32_t firmwareMinor, uint32_t firmwareFix,
uint32_t hardwareMinor, uint32_t hardwareMajor,
Expand Down
4 changes: 0 additions & 4 deletions hal/src/main/native/cpp/jni/HALUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg);
void ThrowBoundaryException(JNIEnv* env, double value, double lower,
double upper);

jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm);

jobject CreateREVPHVersion(JNIEnv* env, uint32_t firmwareMajor,
uint32_t firmwareMinor, uint32_t firmwareFix,
uint32_t hardwareMinor, uint32_t hardwareMajor,
Expand Down
Loading
Loading