mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] SPI: Remove byte limit on size in Java API (#7774)
The underlying Linux spidev supports up to page size length.
This commit is contained in:
@@ -61,12 +61,12 @@ public class SPIJNI extends JNIWrapper {
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
* @param dataToSend Buffer of data to send as part of the transaction.
|
||||
* @param dataReceived Buffer to read data into.
|
||||
* @param size Number of bytes to transfer. [0..7]
|
||||
* @param size Number of bytes to transfer.
|
||||
* @return Number of bytes transferred, -1 for error
|
||||
* @see "HAL_TransactionSPI"
|
||||
*/
|
||||
public static native int spiTransaction(
|
||||
int port, ByteBuffer dataToSend, ByteBuffer dataReceived, byte size);
|
||||
int port, ByteBuffer dataToSend, ByteBuffer dataReceived, int size);
|
||||
|
||||
/**
|
||||
* Performs an SPI send/receive transaction.
|
||||
@@ -77,12 +77,12 @@ public class SPIJNI extends JNIWrapper {
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
* @param dataToSend Buffer of data to send as part of the transaction.
|
||||
* @param dataReceived Buffer to read data into.
|
||||
* @param size Number of bytes to transfer. [0..7]
|
||||
* @param size Number of bytes to transfer.
|
||||
* @return Number of bytes transferred, -1 for error
|
||||
* @see "HAL_TransactionSPI"
|
||||
*/
|
||||
public static native int spiTransactionB(
|
||||
int port, byte[] dataToSend, byte[] dataReceived, byte size);
|
||||
int port, byte[] dataToSend, byte[] dataReceived, int size);
|
||||
|
||||
/**
|
||||
* Executes a write transaction with the device.
|
||||
@@ -95,7 +95,7 @@ public class SPIJNI extends JNIWrapper {
|
||||
* @return The number of bytes written. -1 for an error
|
||||
* @see "HAL_WriteSPI"
|
||||
*/
|
||||
public static native int spiWrite(int port, ByteBuffer dataToSend, byte sendSize);
|
||||
public static native int spiWrite(int port, ByteBuffer dataToSend, int sendSize);
|
||||
|
||||
/**
|
||||
* Executes a write transaction with the device.
|
||||
@@ -108,7 +108,7 @@ public class SPIJNI extends JNIWrapper {
|
||||
* @return The number of bytes written. -1 for an error
|
||||
* @see "HAL_WriteSPI"
|
||||
*/
|
||||
public static native int spiWriteB(int port, byte[] dataToSend, byte sendSize);
|
||||
public static native int spiWriteB(int port, byte[] dataToSend, int sendSize);
|
||||
|
||||
/**
|
||||
* Executes a read from the device.
|
||||
@@ -121,11 +121,11 @@ public class SPIJNI extends JNIWrapper {
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
* @param initiate initiates a transaction when true. Just reads when false.
|
||||
* @param dataReceived A pointer to the array of bytes to store the data read from the device.
|
||||
* @param size The number of bytes to read in the transaction. [1..7]
|
||||
* @param size The number of bytes to read in the transaction.
|
||||
* @return Number of bytes read. -1 for error.
|
||||
* @see "HAL_ReadSPI"
|
||||
*/
|
||||
public static native int spiRead(int port, boolean initiate, ByteBuffer dataReceived, byte size);
|
||||
public static native int spiRead(int port, boolean initiate, ByteBuffer dataReceived, int size);
|
||||
|
||||
/**
|
||||
* Executes a read from the device.
|
||||
@@ -138,11 +138,11 @@ public class SPIJNI extends JNIWrapper {
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
* @param initiate initiates a transaction when true. Just reads when false.
|
||||
* @param dataReceived A pointer to the array of bytes to store the data read from the device.
|
||||
* @param size The number of bytes to read in the transaction. [1..7]
|
||||
* @param size The number of bytes to read in the transaction.
|
||||
* @return Number of bytes read. -1 for error.
|
||||
* @see "HAL_ReadSPI"
|
||||
*/
|
||||
public static native int spiReadB(int port, boolean initiate, byte[] dataReceived, byte size);
|
||||
public static native int spiReadB(int port, boolean initiate, byte[] dataReceived, int size);
|
||||
|
||||
/**
|
||||
* Closes the SPI port.
|
||||
|
||||
@@ -55,12 +55,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiInitialize
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiTransaction
|
||||
* Signature: (ILjava/lang/Object;Ljava/lang/Object;B)I
|
||||
* Signature: (ILjava/lang/Object;Ljava/lang/Object;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiTransaction
|
||||
(JNIEnv* env, jclass, jint port, jobject dataToSend, jobject dataReceived,
|
||||
jbyte size)
|
||||
jint size)
|
||||
{
|
||||
uint8_t* dataToSendPtr = nullptr;
|
||||
if (dataToSend != nullptr) {
|
||||
@@ -77,12 +77,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiTransaction
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiTransactionB
|
||||
* Signature: (I[B[BB)I
|
||||
* Signature: (I[B[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiTransactionB
|
||||
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend,
|
||||
jbyteArray dataReceived, jbyte size)
|
||||
jbyteArray dataReceived, jint size)
|
||||
{
|
||||
if (size < 0) {
|
||||
ThrowIllegalArgumentException(env, "SPIJNI.spiTransactionB() size < 0");
|
||||
@@ -104,11 +104,11 @@ Java_edu_wpi_first_hal_SPIJNI_spiTransactionB
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiWrite
|
||||
* Signature: (ILjava/lang/Object;B)I
|
||||
* Signature: (ILjava/lang/Object;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiWrite
|
||||
(JNIEnv* env, jclass, jint port, jobject dataToSend, jbyte size)
|
||||
(JNIEnv* env, jclass, jint port, jobject dataToSend, jint size)
|
||||
{
|
||||
uint8_t* dataToSendPtr = nullptr;
|
||||
if (dataToSend != nullptr) {
|
||||
@@ -123,11 +123,11 @@ Java_edu_wpi_first_hal_SPIJNI_spiWrite
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiWriteB
|
||||
* Signature: (I[BB)I
|
||||
* Signature: (I[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiWriteB
|
||||
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jbyte size)
|
||||
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jint size)
|
||||
{
|
||||
jint retVal = HAL_WriteSPI(static_cast<HAL_SPIPort>(port),
|
||||
reinterpret_cast<const uint8_t*>(
|
||||
@@ -139,12 +139,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiWriteB
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiRead
|
||||
* Signature: (IZLjava/lang/Object;B)I
|
||||
* Signature: (IZLjava/lang/Object;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiRead
|
||||
(JNIEnv* env, jclass, jint port, jboolean initiate, jobject dataReceived,
|
||||
jbyte size)
|
||||
jint size)
|
||||
{
|
||||
if (size < 0) {
|
||||
ThrowIllegalArgumentException(env, "SPIJNI.spiRead() size < 0");
|
||||
@@ -169,12 +169,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiRead
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiReadB
|
||||
* Signature: (IZ[BB)I
|
||||
* Signature: (IZ[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiReadB
|
||||
(JNIEnv* env, jclass, jint port, jboolean initiate, jbyteArray dataReceived,
|
||||
jbyte size)
|
||||
jint size)
|
||||
{
|
||||
if (size < 0) {
|
||||
ThrowIllegalArgumentException(env, "SPIJNI.spiReadB() size < 0");
|
||||
|
||||
@@ -140,7 +140,7 @@ public class SPI implements AutoCloseable {
|
||||
if (dataToSend.length < size) {
|
||||
throw new IllegalArgumentException("buffer is too small, must be at least " + size);
|
||||
}
|
||||
return SPIJNI.spiWriteB(m_port, dataToSend, (byte) size);
|
||||
return SPIJNI.spiWriteB(m_port, dataToSend, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +163,7 @@ public class SPI implements AutoCloseable {
|
||||
if (dataToSend.capacity() < size) {
|
||||
throw new IllegalArgumentException("buffer is too small, must be at least " + size);
|
||||
}
|
||||
return SPIJNI.spiWrite(m_port, dataToSend, (byte) size);
|
||||
return SPIJNI.spiWrite(m_port, dataToSend, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +184,7 @@ public class SPI implements AutoCloseable {
|
||||
if (dataReceived.length < size) {
|
||||
throw new IllegalArgumentException("buffer is too small, must be at least " + size);
|
||||
}
|
||||
return SPIJNI.spiReadB(m_port, initiate, dataReceived, (byte) size);
|
||||
return SPIJNI.spiReadB(m_port, initiate, dataReceived, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +211,7 @@ public class SPI implements AutoCloseable {
|
||||
if (dataReceived.capacity() < size) {
|
||||
throw new IllegalArgumentException("buffer is too small, must be at least " + size);
|
||||
}
|
||||
return SPIJNI.spiRead(m_port, initiate, dataReceived, (byte) size);
|
||||
return SPIJNI.spiRead(m_port, initiate, dataReceived, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,7 +229,7 @@ public class SPI implements AutoCloseable {
|
||||
if (dataReceived.length < size) {
|
||||
throw new IllegalArgumentException("dataReceived is too small, must be at least " + size);
|
||||
}
|
||||
return SPIJNI.spiTransactionB(m_port, dataToSend, dataReceived, (byte) size);
|
||||
return SPIJNI.spiTransactionB(m_port, dataToSend, dataReceived, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +256,7 @@ public class SPI implements AutoCloseable {
|
||||
if (dataReceived.capacity() < size) {
|
||||
throw new IllegalArgumentException("dataReceived is too small, must be at least " + size);
|
||||
}
|
||||
return SPIJNI.spiTransaction(m_port, dataToSend, dataReceived, (byte) size);
|
||||
return SPIJNI.spiTransaction(m_port, dataToSend, dataReceived, size);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user