2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
#include <jni.h>
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
#include <wpi/jni_util.h>
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
#include "HALUtil.h"
|
2018-09-20 21:59:46 -07:00
|
|
|
#include "edu_wpi_first_hal_SPIJNI.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "hal/SPI.h"
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2020-06-26 17:12:55 -07:00
|
|
|
using namespace hal;
|
2017-11-14 00:00:45 -08:00
|
|
|
using namespace wpi::java;
|
2016-10-31 23:04:49 -07:00
|
|
|
|
2022-09-24 00:11:37 -07:00
|
|
|
static_assert(HAL_SPIPort::HAL_SPI_kInvalid ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_INVALID_PORT);
|
|
|
|
|
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS0 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_ONBOARD_CS0_PORT);
|
|
|
|
|
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS1 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_ONBOARD_CS1_PORT);
|
|
|
|
|
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS2 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_ONBOARD_CS2_PORT);
|
|
|
|
|
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS3 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_ONBOARD_CS3_PORT);
|
|
|
|
|
static_assert(HAL_SPIPort::HAL_SPI_kMXP == edu_wpi_first_hal_SPIJNI_MXP_PORT);
|
|
|
|
|
|
|
|
|
|
static_assert(HAL_SPIMode::HAL_SPI_kMode0 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_SPI_MODE0);
|
|
|
|
|
static_assert(HAL_SPIMode::HAL_SPI_kMode1 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_SPI_MODE1);
|
|
|
|
|
static_assert(HAL_SPIMode::HAL_SPI_kMode2 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_SPI_MODE2);
|
|
|
|
|
static_assert(HAL_SPIMode::HAL_SPI_kMode3 ==
|
|
|
|
|
edu_wpi_first_hal_SPIJNI_SPI_MODE3);
|
|
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
extern "C" {
|
|
|
|
|
|
2014-01-06 09:27:51 -05:00
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiInitialize
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiInitialize
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_InitializeSPI(static_cast<HAL_SPIPort>(port), &status);
|
2016-09-29 20:18:40 -07:00
|
|
|
CheckStatusForceThrow(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiTransaction
|
2018-05-13 17:09:56 -07:00
|
|
|
* Signature: (ILjava/lang/Object;Ljava/lang/Object;B)I
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiTransaction
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jobject dataToSend, jobject dataReceived,
|
|
|
|
|
jbyte size)
|
|
|
|
|
{
|
|
|
|
|
uint8_t* dataToSendPtr = nullptr;
|
2020-12-28 10:52:52 -08:00
|
|
|
if (dataToSend != nullptr) {
|
2018-05-13 17:09:56 -07:00
|
|
|
dataToSendPtr =
|
|
|
|
|
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
|
2016-05-20 17:30:37 -07:00
|
|
|
}
|
2018-05-13 17:09:56 -07:00
|
|
|
uint8_t* dataReceivedPtr =
|
|
|
|
|
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataReceived));
|
|
|
|
|
jint retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port),
|
|
|
|
|
dataToSendPtr, dataReceivedPtr, size);
|
2016-05-20 17:30:37 -07:00
|
|
|
return retVal;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
2017-11-14 00:00:45 -08:00
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-11-14 00:00:45 -08:00
|
|
|
* Method: spiTransactionB
|
|
|
|
|
* Signature: (I[B[BB)I
|
|
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiTransactionB
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend,
|
|
|
|
|
jbyteArray dataReceived, jbyte size)
|
|
|
|
|
{
|
2022-06-15 21:20:52 -07:00
|
|
|
if (size < 0) {
|
|
|
|
|
ThrowIllegalArgumentException(env, "SPIJNI.spiTransactionB() size < 0");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::SmallVector<uint8_t, 128> recvBuf;
|
2017-11-14 00:00:45 -08:00
|
|
|
recvBuf.resize(size);
|
|
|
|
|
jint retVal =
|
|
|
|
|
HAL_TransactionSPI(static_cast<HAL_SPIPort>(port),
|
2018-05-13 17:09:56 -07:00
|
|
|
reinterpret_cast<const uint8_t*>(
|
2017-11-14 00:00:45 -08:00
|
|
|
JByteArrayRef(env, dataToSend).array().data()),
|
|
|
|
|
recvBuf.data(), size);
|
|
|
|
|
env->SetByteArrayRegion(dataReceived, 0, size,
|
2018-05-13 17:09:56 -07:00
|
|
|
reinterpret_cast<const jbyte*>(recvBuf.data()));
|
2017-11-14 00:00:45 -08:00
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 09:27:51 -05:00
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiWrite
|
2018-05-13 17:09:56 -07:00
|
|
|
* Signature: (ILjava/lang/Object;B)I
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiWrite
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jobject dataToSend, jbyte size)
|
|
|
|
|
{
|
|
|
|
|
uint8_t* dataToSendPtr = nullptr;
|
2020-12-28 10:52:52 -08:00
|
|
|
if (dataToSend != nullptr) {
|
2018-05-13 17:09:56 -07:00
|
|
|
dataToSendPtr =
|
|
|
|
|
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
|
2016-05-20 17:30:37 -07:00
|
|
|
}
|
2018-05-13 17:09:56 -07:00
|
|
|
jint retVal =
|
|
|
|
|
HAL_WriteSPI(static_cast<HAL_SPIPort>(port), dataToSendPtr, size);
|
2016-05-20 17:30:37 -07:00
|
|
|
return retVal;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
2017-11-14 00:00:45 -08:00
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-11-14 00:00:45 -08:00
|
|
|
* Method: spiWriteB
|
|
|
|
|
* Signature: (I[BB)I
|
|
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiWriteB
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jbyte size)
|
|
|
|
|
{
|
2017-11-14 00:00:45 -08:00
|
|
|
jint retVal = HAL_WriteSPI(static_cast<HAL_SPIPort>(port),
|
2018-05-13 17:09:56 -07:00
|
|
|
reinterpret_cast<const uint8_t*>(
|
2017-11-14 00:00:45 -08:00
|
|
|
JByteArrayRef(env, dataToSend).array().data()),
|
|
|
|
|
size);
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 09:27:51 -05:00
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiRead
|
2018-05-13 17:09:56 -07:00
|
|
|
* Signature: (IZLjava/lang/Object;B)I
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiRead
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jboolean initiate, jobject dataReceived,
|
|
|
|
|
jbyte size)
|
|
|
|
|
{
|
2022-06-15 21:20:52 -07:00
|
|
|
if (size < 0) {
|
|
|
|
|
ThrowIllegalArgumentException(env, "SPIJNI.spiRead() size < 0");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
uint8_t* dataReceivedPtr =
|
|
|
|
|
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataReceived));
|
2017-11-14 00:00:45 -08:00
|
|
|
jint retVal;
|
|
|
|
|
if (initiate) {
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::SmallVector<uint8_t, 128> sendBuf;
|
2017-11-14 00:00:45 -08:00
|
|
|
sendBuf.resize(size);
|
2018-05-13 17:09:56 -07:00
|
|
|
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(),
|
|
|
|
|
dataReceivedPtr, size);
|
2017-11-14 00:00:45 -08:00
|
|
|
} else {
|
2018-05-13 17:09:56 -07:00
|
|
|
retVal = HAL_ReadSPI(static_cast<HAL_SPIPort>(port),
|
|
|
|
|
reinterpret_cast<uint8_t*>(dataReceivedPtr), size);
|
2017-11-14 00:00:45 -08:00
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-11-14 00:00:45 -08:00
|
|
|
* Method: spiReadB
|
|
|
|
|
* Signature: (IZ[BB)I
|
|
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiReadB
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jboolean initiate, jbyteArray dataReceived,
|
|
|
|
|
jbyte size)
|
|
|
|
|
{
|
2022-06-15 21:20:52 -07:00
|
|
|
if (size < 0) {
|
|
|
|
|
ThrowIllegalArgumentException(env, "SPIJNI.spiReadB() size < 0");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 00:00:45 -08:00
|
|
|
jint retVal;
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::SmallVector<uint8_t, 128> recvBuf;
|
2017-11-14 00:00:45 -08:00
|
|
|
recvBuf.resize(size);
|
|
|
|
|
if (initiate) {
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::SmallVector<uint8_t, 128> sendBuf;
|
2017-11-14 00:00:45 -08:00
|
|
|
sendBuf.resize(size);
|
2018-05-13 17:09:56 -07:00
|
|
|
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(),
|
|
|
|
|
recvBuf.data(), size);
|
2017-11-14 00:00:45 -08:00
|
|
|
} else {
|
|
|
|
|
retVal = HAL_ReadSPI(static_cast<HAL_SPIPort>(port), recvBuf.data(), size);
|
|
|
|
|
}
|
|
|
|
|
env->SetByteArrayRegion(dataReceived, 0, size,
|
2018-05-13 17:09:56 -07:00
|
|
|
reinterpret_cast<const jbyte*>(recvBuf.data()));
|
2016-05-20 17:30:37 -07:00
|
|
|
return retVal;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiClose
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiClose
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv*, jclass, jint port)
|
|
|
|
|
{
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_CloseSPI(static_cast<HAL_SPIPort>(port));
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiSetSpeed
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (II)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiSetSpeed
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv*, jclass, jint port, jint speed)
|
|
|
|
|
{
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPISpeed(static_cast<HAL_SPIPort>(port), speed);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2022-09-24 00:11:37 -07:00
|
|
|
* Method: spiSetMode
|
|
|
|
|
* Signature: (II)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2022-09-24 00:11:37 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiSetMode
|
|
|
|
|
(JNIEnv*, jclass, jint port, jint mode)
|
|
|
|
|
{
|
|
|
|
|
HAL_SetSPIMode(static_cast<HAL_SPIPort>(port),
|
|
|
|
|
static_cast<HAL_SPIMode>(mode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
|
|
|
|
* Method: spiGetMode
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiGetMode
|
|
|
|
|
(JNIEnv*, jclass, jint port)
|
2018-05-13 17:09:56 -07:00
|
|
|
{
|
2022-09-24 00:11:37 -07:00
|
|
|
return static_cast<jint>(HAL_GetSPIMode(static_cast<HAL_SPIPort>(port)));
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiSetChipSelectActiveHigh
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiSetChipSelectActiveHigh
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPIChipSelectActiveHigh(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiSetChipSelectActiveLow
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiSetChipSelectActiveLow
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPIChipSelectActiveLow(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-22 11:50:49 -08:00
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiInitAuto
|
|
|
|
|
* Signature: (II)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiInitAuto
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jint bufferSize)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-12-13 23:41:37 -08:00
|
|
|
HAL_InitSPIAuto(static_cast<HAL_SPIPort>(port), bufferSize, &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiFreeAuto
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiFreeAuto
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-12-13 23:41:37 -08:00
|
|
|
HAL_FreeSPIAuto(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiStartAutoRate
|
|
|
|
|
* Signature: (ID)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiStartAutoRate
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jdouble period)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-12-13 23:41:37 -08:00
|
|
|
HAL_StartSPIAutoRate(static_cast<HAL_SPIPort>(port), period, &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiStartAutoTrigger
|
|
|
|
|
* Signature: (IIIZZ)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiStartAutoTrigger
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jint digitalSourceHandle,
|
|
|
|
|
jint analogTriggerType, jboolean triggerRising, jboolean triggerFalling)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-12-13 23:41:37 -08:00
|
|
|
HAL_StartSPIAutoTrigger(static_cast<HAL_SPIPort>(port), digitalSourceHandle,
|
2018-05-13 17:09:56 -07:00
|
|
|
static_cast<HAL_AnalogTriggerType>(analogTriggerType),
|
|
|
|
|
triggerRising, triggerFalling, &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiStopAuto
|
|
|
|
|
* Signature: (I)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiStopAuto
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-12-13 23:41:37 -08:00
|
|
|
HAL_StopSPIAuto(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiSetAutoTransmitData
|
|
|
|
|
* Signature: (I[BI)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiSetAutoTransmitData
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jint zeroSize)
|
|
|
|
|
{
|
2017-12-13 23:41:37 -08:00
|
|
|
JByteArrayRef jarr(env, dataToSend);
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2018-05-13 17:09:56 -07:00
|
|
|
HAL_SetSPIAutoTransmitData(
|
|
|
|
|
static_cast<HAL_SPIPort>(port),
|
2017-12-13 23:41:37 -08:00
|
|
|
reinterpret_cast<const uint8_t*>(jarr.array().data()),
|
|
|
|
|
jarr.array().size(), zeroSize, &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiForceAutoRead
|
|
|
|
|
* Signature: (I)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiForceAutoRead
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2017-12-13 23:41:37 -08:00
|
|
|
HAL_ForceSPIAutoRead(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiReadAutoReceivedData
|
2018-05-13 17:09:56 -07:00
|
|
|
* Signature: (ILjava/lang/Object;ID)I
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiReadAutoReceivedData__ILjava_nio_ByteBuffer_2ID
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jobject buffer, jint numToRead,
|
|
|
|
|
jdouble timeout)
|
|
|
|
|
{
|
2018-12-06 22:29:20 -08:00
|
|
|
uint32_t* recvBuf =
|
|
|
|
|
reinterpret_cast<uint32_t*>(env->GetDirectBufferAddress(buffer));
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2018-05-13 17:09:56 -07:00
|
|
|
jint retval = HAL_ReadSPIAutoReceivedData(
|
|
|
|
|
static_cast<HAL_SPIPort>(port), recvBuf, numToRead, timeout, &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2017-12-13 23:41:37 -08:00
|
|
|
return retval;
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiReadAutoReceivedData
|
2018-12-06 22:29:20 -08:00
|
|
|
* Signature: (I[IID)I
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-12-06 22:29:20 -08:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiReadAutoReceivedData__I_3IID
|
|
|
|
|
(JNIEnv* env, jclass, jint port, jintArray buffer, jint numToRead,
|
2018-05-13 17:09:56 -07:00
|
|
|
jdouble timeout)
|
|
|
|
|
{
|
2022-06-15 21:20:52 -07:00
|
|
|
if (numToRead < 0) {
|
|
|
|
|
ThrowIllegalArgumentException(
|
|
|
|
|
env, "SPIJNI.spiReadAutoReceivedData() numToRead < 0");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 22:29:20 -08:00
|
|
|
wpi::SmallVector<uint32_t, 128> recvBuf;
|
2017-12-13 23:41:37 -08:00
|
|
|
recvBuf.resize(numToRead);
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2018-05-13 17:09:56 -07:00
|
|
|
jint retval =
|
|
|
|
|
HAL_ReadSPIAutoReceivedData(static_cast<HAL_SPIPort>(port),
|
|
|
|
|
recvBuf.data(), numToRead, timeout, &status);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!CheckStatus(env, status)) {
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
2017-12-13 23:41:37 -08:00
|
|
|
if (numToRead > 0) {
|
2018-12-06 22:29:20 -08:00
|
|
|
env->SetIntArrayRegion(buffer, 0, numToRead,
|
|
|
|
|
reinterpret_cast<const jint*>(recvBuf.data()));
|
2017-12-13 23:41:37 -08:00
|
|
|
}
|
|
|
|
|
return retval;
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
2017-12-13 23:41:37 -08:00
|
|
|
* Method: spiGetAutoDroppedCount
|
|
|
|
|
* Signature: (I)I
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2018-05-13 17:09:56 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiGetAutoDroppedCount
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2016-05-20 17:30:37 -07:00
|
|
|
int32_t status = 0;
|
2018-05-13 17:09:56 -07:00
|
|
|
auto retval =
|
|
|
|
|
HAL_GetSPIAutoDroppedCount(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
CheckStatus(env, status);
|
2017-12-13 23:41:37 -08:00
|
|
|
return retval;
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
2019-12-24 10:52:58 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_hal_SPIJNI
|
|
|
|
|
* Method: spiConfigureAutoStall
|
|
|
|
|
* Signature: (IIII)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_hal_SPIJNI_spiConfigureAutoStall
|
|
|
|
|
(JNIEnv* env, jclass, jint port, jint csToSclkTicks, jint stallTicks,
|
|
|
|
|
jint pow2BytesPerRead)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_ConfigureSPIAutoStall(static_cast<HAL_SPIPort>(port), csToSclkTicks,
|
|
|
|
|
stallTicks, pow2BytesPerRead, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
} // extern "C"
|