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

Remove HAL_GetPort #7754

Merged
merged 2 commits into from
Jan 31, 2025
Merged
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
8 changes: 4 additions & 4 deletions hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public interface AnalogTriggerType {
/**
* Initializes the analog input port using the given port object.
*
* @param halPortHandle Handle to the port to initialize.
* @param channel The smartio channel.
* @return the created analog input handle
* @see "HAL_InitializeAnalogInputPort"
*/
public static native int initializeAnalogInputPort(int halPortHandle);
public static native int initializeAnalogInputPort(int channel);

/**
* Frees an analog input port.
*
* @param portHandle Handle to the analog port.
* @param analogPortHandle Handle to the analog port.
* @see "HAL_FreeAnalogInputPort"
*/
public static native void freeAnalogInputPort(int portHandle);
public static native void freeAnalogInputPort(int analogPortHandle);

/**
* Checks that the analog module number is valid.
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/java/edu/wpi/first/hal/DIOJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class DIOJNI extends JNIWrapper {
/**
* Creates a new instance of a digital port.
*
* @param halPortHandle the port handle to create from
* @param channel the smartio channel
* @param input true for input, false for output
* @return the created digital handle
* @see "HAL_InitializeDIOPort"
*/
public static native int initializeDIOPort(int halPortHandle, boolean input);
public static native int initializeDIOPort(int channel, boolean input);

/**
* Checks if a DIO channel is valid.
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class DutyCycleJNI extends JNIWrapper {
/**
* Initialize a DutyCycle input.
*
* @param halPortHandle the port handle to create from
* @param channel the smartio channel
* @return the created duty cycle handle
* @see "HAL_InitializeDutyCycle"
*/
public static native int initialize(int halPortHandle);
public static native int initialize(int channel);

/**
* Free a DutyCycle.
Expand Down
25 changes: 0 additions & 25 deletions hal/src/main/java/edu/wpi/first/hal/HAL.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,31 +211,6 @@ public static void simPeriodicAfter() {
*/
public static native boolean getSystemTimeValid();

/**
* Gets a port handle for a specific channel and module.
*
* <p>This is expected to be used for PCMs, as the roboRIO does not work with modules anymore.
*
* <p>The created handle does not need to be freed.
*
* @param module the module number
* @param channel the channel number
* @return the created port
* @see "HAL_GetPortWithModule"
*/
public static native int getPortWithModule(byte module, byte channel);

/**
* Gets a port handle for a specific channel.
*
* <p>The created handle does not need to be freed.
*
* @param channel the channel number
* @return the created port
* @see "HAL_GetPort"
*/
public static native int getPort(byte channel);

/**
* Report the usage of a resource of interest.
*
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/java/edu/wpi/first/hal/PWMJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class PWMJNI extends DIOJNI {
/**
* Initializes a PWM port.
*
* @param halPortHandle the port to initialize
* @param channel the smartio channel
* @return the created pwm handle
*/
public static native int initializePWMPort(int halPortHandle);
public static native int initializePWMPort(int channel);

/**
* Checks if a pwm channel is valid.
Expand Down
12 changes: 0 additions & 12 deletions hal/src/main/native/cpp/handles/HandlesInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ void HandleBase::ResetGlobalHandles() {
}
}
}
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
// set last 8 bits, then shift to first 8 bits
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
handle = handle << 24;
// shift module and add to 3rd set of 8 bits
int32_t temp = module;
temp = (temp << 8) & 0xff00;
handle += temp;
// add channel to last 8 bits
handle += channel;
return handle;
}
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
int16_t version) {
if (index < 0) {
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/cpp/jni/AnalogJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogInputPort
(JNIEnv* env, jclass, jint id)
(JNIEnv* env, jclass, jint channel)
{
int32_t status = 0;
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
auto analog =
HAL_InitializeAnalogInputPort((HAL_PortHandle)id, stack.c_str(), &status);
auto analog = HAL_InitializeAnalogInputPort(channel, stack.c_str(), &status);
CheckStatusForceThrow(env, status);
return (jint)analog;
}
Expand Down
6 changes: 3 additions & 3 deletions hal/src/main/native/cpp/jni/DIOJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DIOJNI_initializeDIOPort
(JNIEnv* env, jclass, jint id, jboolean input)
(JNIEnv* env, jclass, jint channel, jboolean input)
{
int32_t status = 0;
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
auto dio = HAL_InitializeDIOPort(
(HAL_PortHandle)id, static_cast<uint8_t>(input), stack.c_str(), &status);
auto dio = HAL_InitializeDIOPort(channel, static_cast<uint8_t>(input),
stack.c_str(), &status);
CheckStatusForceThrow(env, status);
return (jint)dio;
}
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/cpp/jni/DutyCycleJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_initialize
(JNIEnv* env, jclass, jint portHandle)
(JNIEnv* env, jclass, jint channel)
{
int32_t status = 0;
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
auto handle = HAL_InitializeDutyCycle(static_cast<HAL_Handle>(portHandle),
stack.c_str(), &status);
auto handle = HAL_InitializeDutyCycle(channel, stack.c_str(), &status);
CheckStatus(env, status);
return handle;
}
Expand Down
26 changes: 0 additions & 26 deletions hal/src/main/native/cpp/jni/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,4 @@ Java_edu_wpi_first_hal_HAL_getSystemTimeValid
return val;
}

/*
* Class: edu_wpi_first_hal_HAL
* Method: getPortWithModule
* Signature: (BB)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_HAL_getPortWithModule
(JNIEnv* env, jclass, jbyte module, jbyte channel)
{
HAL_PortHandle port = HAL_GetPortWithModule(module, channel);
return (jint)port;
}

/*
* Class: edu_wpi_first_hal_HAL
* Method: getPort
* Signature: (B)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_HAL_getPort
(JNIEnv* env, jclass, jbyte channel)
{
HAL_PortHandle port = HAL_GetPort(channel);
return (jint)port;
}

} // extern "C"
4 changes: 2 additions & 2 deletions hal/src/main/native/cpp/jni/PWMJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_PWMJNI_initializePWMPort
(JNIEnv* env, jclass, jint id)
(JNIEnv* env, jclass, jint channel)
{
int32_t status = 0;
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, stack.c_str(), &status);
auto pwm = HAL_InitializePWMPort(channel, stack.c_str(), &status);
CheckStatusForceThrow(env, status);
return (jint)pwm;
}
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/native/include/hal/AnalogInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ extern "C" {
/**
* Initializes the analog input port using the given port object.
*
* @param[in] portHandle Handle to the port to initialize.
* @param[in] channel the smartio channel.
* @param[in] allocationLocation the location where the allocation is occurring
* (can be null)
* @param[out] status the error code, or 0 for success
* @return the created analog input handle
*/
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
HAL_PortHandle portHandle, const char* allocationLocation, int32_t* status);
int32_t channel, const char* allocationLocation, int32_t* status);

/**
* Frees an analog input port.
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/include/hal/DIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ extern "C" {
/**
* Creates a new instance of a digital port.
*
* @param[in] portHandle the port handle to create from
* @param[in] channel the smartio channel
* @param[in] input true for input, false for output
* @param[in] allocationLocation the location where the allocation is occurring
* (can be null)
* @param[out] status Error status variable. 0 on success.
* @return the created digital handle
*/
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input,
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
const char* allocationLocation,
int32_t* status);

Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/native/include/hal/DutyCycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ extern "C" {
/**
* Initialize a DutyCycle input.
*
* @param[in] portHandle the port handle to create from
* @param[in] channel the smartio channel
* @param[in] allocationLocation the location where the allocation is occurring
* (can be null)
* @param[out] status Error status variable. 0 on success.
* @return the created duty cycle handle
*/
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
const char* allocationLocation,
int32_t* status);

Expand Down
24 changes: 0 additions & 24 deletions hal/src/main/native/include/hal/HALBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,6 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status);
*/
int32_t HAL_GetCommsDisableCount(int32_t* status);

/**
* Gets a port handle for a specific channel.
*
* The created handle does not need to be freed.
*
* @param channel the channel number
* @return the created port
*/
HAL_PortHandle HAL_GetPort(int32_t channel);

/**
* Gets a port handle for a specific channel and module.
*
* This is expected to be used for PCMs, as the roboRIO does not work with
* modules anymore.
*
* The created handle does not need to be freed.
*
* @param module the module number
* @param channel the channel number
* @return the created port
*/
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);

/**
* Reads the microsecond-resolution timer on the FPGA.
*
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/native/include/hal/PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ extern "C" {
/**
* Initializes a PWM port.
*
* @param[in] portHandle the port to initialize
* @param[in] channel the smartio channel
* @param[in] allocationLocation the location where the allocation is occurring
* (can be null)
* @param[out] status Error status variable. 0 on success.
* @return the created pwm handle
*/
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
const char* allocationLocation,
int32_t* status);

Expand Down
2 changes: 0 additions & 2 deletions hal/src/main/native/include/hal/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

typedef int32_t HAL_Handle;

typedef HAL_Handle HAL_PortHandle;

typedef HAL_Handle HAL_AnalogInputHandle;

typedef HAL_Handle HAL_AnalogOutputHandle;
Expand Down
37 changes: 0 additions & 37 deletions hal/src/main/native/include/hal/handles/HandlesInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,43 +153,6 @@ inline int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType,
* Bit 31: 1 if handle error, 0 if no error
*/

// using a 16 bit value so we can store 0-255 and still report error
/**
* Gets the port channel of a port handle.
*
* @param handle the port handle
* @return the port channel
*/
inline int16_t getPortHandleChannel(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
return InvalidHandleIndex;
}
return static_cast<uint8_t>(handle & 0xff);
}

// using a 16 bit value so we can store 0-255 and still report error
/**
* Gets the port module of a port handle.
*
* @param handle the port handle
* @return the port module
*/
inline int16_t getPortHandleModule(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
return InvalidHandleIndex;
}
return static_cast<uint8_t>((handle >> 8) & 0xff);
}

/**
* Create a port handle.
*
* @param channel the channel
* @param module the module
* @return port handle for the module and channel
*/
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module);

/**
* Create a handle for a specific index, type and version.
*
Expand Down
6 changes: 2 additions & 4 deletions hal/src/main/native/sim/AnalogInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ void InitializeAnalogInput() {}

extern "C" {
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
HAL_PortHandle portHandle, const char* allocationLocation,
int32_t* status) {
int32_t channel, const char* allocationLocation, int32_t* status) {
hal::init::CheckInit();
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex || channel >= kNumAnalogInputs) {
if (channel < 0 || channel >= kNumAnalogInputs) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input",
0, kNumAnalogInputs, channel);
Expand Down
6 changes: 2 additions & 4 deletions hal/src/main/native/sim/DIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ void InitializeDIO() {

extern "C" {

HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input,
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();

int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
if (channel < 0 || channel >= kNumDigitalChannels) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
kNumDigitalChannels, channel);
Expand Down
Loading
Loading