Skip to content

Commit ad29d45

Browse files
authored
[hal] Remove HAL_GetPort (#7754)
1 parent 6e70437 commit ad29d45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+84
-272
lines changed

hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ public class AnalogJNI extends JNIWrapper {
1313
/**
1414
* Initializes the analog input port using the given port object.
1515
*
16-
* @param halPortHandle Handle to the port to initialize.
16+
* @param channel The smartio channel.
1717
* @return the created analog input handle
1818
* @see "HAL_InitializeAnalogInputPort"
1919
*/
20-
public static native int initializeAnalogInputPort(int halPortHandle);
20+
public static native int initializeAnalogInputPort(int channel);
2121

2222
/**
2323
* Frees an analog input port.
2424
*
25-
* @param portHandle Handle to the analog port.
25+
* @param analogPortHandle Handle to the analog port.
2626
* @see "HAL_FreeAnalogInputPort"
2727
*/
28-
public static native void freeAnalogInputPort(int portHandle);
28+
public static native void freeAnalogInputPort(int analogPortHandle);
2929

3030
/**
3131
* Checks that the analog module number is valid.

hal/src/main/java/edu/wpi/first/hal/DIOJNI.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class DIOJNI extends JNIWrapper {
1313
/**
1414
* Creates a new instance of a digital port.
1515
*
16-
* @param halPortHandle the port handle to create from
16+
* @param channel the smartio channel
1717
* @param input true for input, false for output
1818
* @return the created digital handle
1919
* @see "HAL_InitializeDIOPort"
2020
*/
21-
public static native int initializeDIOPort(int halPortHandle, boolean input);
21+
public static native int initializeDIOPort(int channel, boolean input);
2222

2323
/**
2424
* Checks if a DIO channel is valid.

hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class DutyCycleJNI extends JNIWrapper {
1313
/**
1414
* Initialize a DutyCycle input.
1515
*
16-
* @param halPortHandle the port handle to create from
16+
* @param channel the smartio channel
1717
* @return the created duty cycle handle
1818
* @see "HAL_InitializeDutyCycle"
1919
*/
20-
public static native int initialize(int halPortHandle);
20+
public static native int initialize(int channel);
2121

2222
/**
2323
* Free a DutyCycle.

hal/src/main/java/edu/wpi/first/hal/HAL.java

-25
Original file line numberDiff line numberDiff line change
@@ -211,31 +211,6 @@ public static void simPeriodicAfter() {
211211
*/
212212
public static native boolean getSystemTimeValid();
213213

214-
/**
215-
* Gets a port handle for a specific channel and module.
216-
*
217-
* <p>This is expected to be used for PCMs, as the roboRIO does not work with modules anymore.
218-
*
219-
* <p>The created handle does not need to be freed.
220-
*
221-
* @param module the module number
222-
* @param channel the channel number
223-
* @return the created port
224-
* @see "HAL_GetPortWithModule"
225-
*/
226-
public static native int getPortWithModule(byte module, byte channel);
227-
228-
/**
229-
* Gets a port handle for a specific channel.
230-
*
231-
* <p>The created handle does not need to be freed.
232-
*
233-
* @param channel the channel number
234-
* @return the created port
235-
* @see "HAL_GetPort"
236-
*/
237-
public static native int getPort(byte channel);
238-
239214
/**
240215
* Report the usage of a resource of interest.
241216
*

hal/src/main/java/edu/wpi/first/hal/PWMJNI.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public class PWMJNI extends DIOJNI {
1313
/**
1414
* Initializes a PWM port.
1515
*
16-
* @param halPortHandle the port to initialize
16+
* @param channel the smartio channel
1717
* @return the created pwm handle
1818
*/
19-
public static native int initializePWMPort(int halPortHandle);
19+
public static native int initializePWMPort(int channel);
2020

2121
/**
2222
* Checks if a pwm channel is valid.

hal/src/main/native/cpp/handles/HandlesInternal.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ void HandleBase::ResetGlobalHandles() {
4949
}
5050
}
5151
}
52-
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
53-
// set last 8 bits, then shift to first 8 bits
54-
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
55-
handle = handle << 24;
56-
// shift module and add to 3rd set of 8 bits
57-
int32_t temp = module;
58-
temp = (temp << 8) & 0xff00;
59-
handle += temp;
60-
// add channel to last 8 bits
61-
handle += channel;
62-
return handle;
63-
}
6452
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
6553
int16_t version) {
6654
if (index < 0) {

hal/src/main/native/cpp/jni/AnalogJNI.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ extern "C" {
2525
*/
2626
JNIEXPORT jint JNICALL
2727
Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogInputPort
28-
(JNIEnv* env, jclass, jint id)
28+
(JNIEnv* env, jclass, jint channel)
2929
{
3030
int32_t status = 0;
3131
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
32-
auto analog =
33-
HAL_InitializeAnalogInputPort((HAL_PortHandle)id, stack.c_str(), &status);
32+
auto analog = HAL_InitializeAnalogInputPort(channel, stack.c_str(), &status);
3433
CheckStatusForceThrow(env, status);
3534
return (jint)analog;
3635
}

hal/src/main/native/cpp/jni/DIOJNI.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ extern "C" {
2626
*/
2727
JNIEXPORT jint JNICALL
2828
Java_edu_wpi_first_hal_DIOJNI_initializeDIOPort
29-
(JNIEnv* env, jclass, jint id, jboolean input)
29+
(JNIEnv* env, jclass, jint channel, jboolean input)
3030
{
3131
int32_t status = 0;
3232
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
33-
auto dio = HAL_InitializeDIOPort(
34-
(HAL_PortHandle)id, static_cast<uint8_t>(input), stack.c_str(), &status);
33+
auto dio = HAL_InitializeDIOPort(channel, static_cast<uint8_t>(input),
34+
stack.c_str(), &status);
3535
CheckStatusForceThrow(env, status);
3636
return (jint)dio;
3737
}

hal/src/main/native/cpp/jni/DutyCycleJNI.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ extern "C" {
2020
*/
2121
JNIEXPORT jint JNICALL
2222
Java_edu_wpi_first_hal_DutyCycleJNI_initialize
23-
(JNIEnv* env, jclass, jint portHandle)
23+
(JNIEnv* env, jclass, jint channel)
2424
{
2525
int32_t status = 0;
2626
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
27-
auto handle = HAL_InitializeDutyCycle(static_cast<HAL_Handle>(portHandle),
28-
stack.c_str(), &status);
27+
auto handle = HAL_InitializeDutyCycle(channel, stack.c_str(), &status);
2928
CheckStatus(env, status);
3029
return handle;
3130
}

hal/src/main/native/cpp/jni/HAL.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -199,30 +199,4 @@ Java_edu_wpi_first_hal_HAL_getSystemTimeValid
199199
return val;
200200
}
201201

202-
/*
203-
* Class: edu_wpi_first_hal_HAL
204-
* Method: getPortWithModule
205-
* Signature: (BB)I
206-
*/
207-
JNIEXPORT jint JNICALL
208-
Java_edu_wpi_first_hal_HAL_getPortWithModule
209-
(JNIEnv* env, jclass, jbyte module, jbyte channel)
210-
{
211-
HAL_PortHandle port = HAL_GetPortWithModule(module, channel);
212-
return (jint)port;
213-
}
214-
215-
/*
216-
* Class: edu_wpi_first_hal_HAL
217-
* Method: getPort
218-
* Signature: (B)I
219-
*/
220-
JNIEXPORT jint JNICALL
221-
Java_edu_wpi_first_hal_HAL_getPort
222-
(JNIEnv* env, jclass, jbyte channel)
223-
{
224-
HAL_PortHandle port = HAL_GetPort(channel);
225-
return (jint)port;
226-
}
227-
228202
} // extern "C"

hal/src/main/native/cpp/jni/PWMJNI.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ extern "C" {
2626
*/
2727
JNIEXPORT jint JNICALL
2828
Java_edu_wpi_first_hal_PWMJNI_initializePWMPort
29-
(JNIEnv* env, jclass, jint id)
29+
(JNIEnv* env, jclass, jint channel)
3030
{
3131
int32_t status = 0;
3232
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
33-
auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, stack.c_str(), &status);
33+
auto pwm = HAL_InitializePWMPort(channel, stack.c_str(), &status);
3434
CheckStatusForceThrow(env, status);
3535
return (jint)pwm;
3636
}

hal/src/main/native/include/hal/AnalogInput.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ extern "C" {
2121
/**
2222
* Initializes the analog input port using the given port object.
2323
*
24-
* @param[in] portHandle Handle to the port to initialize.
24+
* @param[in] channel the smartio channel.
2525
* @param[in] allocationLocation the location where the allocation is occurring
2626
* (can be null)
2727
* @param[out] status the error code, or 0 for success
2828
* @return the created analog input handle
2929
*/
3030
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
31-
HAL_PortHandle portHandle, const char* allocationLocation, int32_t* status);
31+
int32_t channel, const char* allocationLocation, int32_t* status);
3232

3333
/**
3434
* Frees an analog input port.

hal/src/main/native/include/hal/DIO.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ extern "C" {
2121
/**
2222
* Creates a new instance of a digital port.
2323
*
24-
* @param[in] portHandle the port handle to create from
24+
* @param[in] channel the smartio channel
2525
* @param[in] input true for input, false for output
2626
* @param[in] allocationLocation the location where the allocation is occurring
2727
* (can be null)
2828
* @param[out] status Error status variable. 0 on success.
2929
* @return the created digital handle
3030
*/
31-
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
32-
HAL_Bool input,
31+
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
3332
const char* allocationLocation,
3433
int32_t* status);
3534

hal/src/main/native/include/hal/DutyCycle.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ extern "C" {
1919
/**
2020
* Initialize a DutyCycle input.
2121
*
22-
* @param[in] portHandle the port handle to create from
22+
* @param[in] channel the smartio channel
2323
* @param[in] allocationLocation the location where the allocation is occurring
2424
* (can be null)
2525
* @param[out] status Error status variable. 0 on success.
2626
* @return the created duty cycle handle
2727
*/
28-
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
28+
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
2929
const char* allocationLocation,
3030
int32_t* status);
3131

hal/src/main/native/include/hal/HALBase.h

-24
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,6 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status);
148148
*/
149149
int32_t HAL_GetCommsDisableCount(int32_t* status);
150150

151-
/**
152-
* Gets a port handle for a specific channel.
153-
*
154-
* The created handle does not need to be freed.
155-
*
156-
* @param channel the channel number
157-
* @return the created port
158-
*/
159-
HAL_PortHandle HAL_GetPort(int32_t channel);
160-
161-
/**
162-
* Gets a port handle for a specific channel and module.
163-
*
164-
* This is expected to be used for PCMs, as the roboRIO does not work with
165-
* modules anymore.
166-
*
167-
* The created handle does not need to be freed.
168-
*
169-
* @param module the module number
170-
* @param channel the channel number
171-
* @return the created port
172-
*/
173-
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
174-
175151
/**
176152
* Reads the microsecond-resolution timer on the FPGA.
177153
*

hal/src/main/native/include/hal/PWM.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ extern "C" {
2121
/**
2222
* Initializes a PWM port.
2323
*
24-
* @param[in] portHandle the port to initialize
24+
* @param[in] channel the smartio channel
2525
* @param[in] allocationLocation the location where the allocation is occurring
2626
* (can be null)
2727
* @param[out] status Error status variable. 0 on success.
2828
* @return the created pwm handle
2929
*/
30-
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
30+
HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
3131
const char* allocationLocation,
3232
int32_t* status);
3333

hal/src/main/native/include/hal/Types.h

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
typedef int32_t HAL_Handle;
1818

19-
typedef HAL_Handle HAL_PortHandle;
20-
2119
typedef HAL_Handle HAL_AnalogInputHandle;
2220

2321
typedef HAL_Handle HAL_AnalogOutputHandle;

hal/src/main/native/include/hal/handles/HandlesInternal.h

-37
Original file line numberDiff line numberDiff line change
@@ -153,43 +153,6 @@ inline int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType,
153153
* Bit 31: 1 if handle error, 0 if no error
154154
*/
155155

156-
// using a 16 bit value so we can store 0-255 and still report error
157-
/**
158-
* Gets the port channel of a port handle.
159-
*
160-
* @param handle the port handle
161-
* @return the port channel
162-
*/
163-
inline int16_t getPortHandleChannel(HAL_PortHandle handle) {
164-
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
165-
return InvalidHandleIndex;
166-
}
167-
return static_cast<uint8_t>(handle & 0xff);
168-
}
169-
170-
// using a 16 bit value so we can store 0-255 and still report error
171-
/**
172-
* Gets the port module of a port handle.
173-
*
174-
* @param handle the port handle
175-
* @return the port module
176-
*/
177-
inline int16_t getPortHandleModule(HAL_PortHandle handle) {
178-
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
179-
return InvalidHandleIndex;
180-
}
181-
return static_cast<uint8_t>((handle >> 8) & 0xff);
182-
}
183-
184-
/**
185-
* Create a port handle.
186-
*
187-
* @param channel the channel
188-
* @param module the module
189-
* @return port handle for the module and channel
190-
*/
191-
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module);
192-
193156
/**
194157
* Create a handle for a specific index, type and version.
195158
*

hal/src/main/native/sim/AnalogInput.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ void InitializeAnalogInput() {}
1919

2020
extern "C" {
2121
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
22-
HAL_PortHandle portHandle, const char* allocationLocation,
23-
int32_t* status) {
22+
int32_t channel, const char* allocationLocation, int32_t* status) {
2423
hal::init::CheckInit();
25-
int16_t channel = getPortHandleChannel(portHandle);
26-
if (channel == InvalidHandleIndex || channel >= kNumAnalogInputs) {
24+
if (channel < 0 || channel >= kNumAnalogInputs) {
2725
*status = RESOURCE_OUT_OF_RANGE;
2826
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input",
2927
0, kNumAnalogInputs, channel);

hal/src/main/native/sim/DIO.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ void InitializeDIO() {
3131

3232
extern "C" {
3333

34-
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
35-
HAL_Bool input,
34+
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
3635
const char* allocationLocation,
3736
int32_t* status) {
3837
hal::init::CheckInit();
3938

40-
int16_t channel = getPortHandleChannel(portHandle);
41-
if (channel == InvalidHandleIndex) {
39+
if (channel < 0 || channel >= kNumDigitalChannels) {
4240
*status = RESOURCE_OUT_OF_RANGE;
4341
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
4442
kNumDigitalChannels, channel);

0 commit comments

Comments
 (0)