[hal, wpilib] Remove SPI support (#7678)

This commit is contained in:
Thad House
2025-01-17 00:22:29 -08:00
committed by GitHub
parent dc335ddedb
commit 92f0a3c961
84 changed files with 12 additions and 12763 deletions

View File

@@ -61,20 +61,6 @@ HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
handle += channel;
return handle;
}
HAL_PortHandle createPortHandleForSPI(uint8_t channel) {
// set last 8 bits, then shift to first 8 bits
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
handle = handle << 16;
// set second set up bits to 1
int32_t temp = 1;
temp = (temp << 8) & 0xff00;
handle += temp;
// shift to last set of bits
handle = handle << 8;
// 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) {

View File

@@ -1,466 +0,0 @@
// 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.
#include <jni.h>
#include <cassert>
#include <wpi/jni_util.h>
#include "HALUtil.h"
#include "edu_wpi_first_hal_SPIJNI.h"
#include "hal/SPI.h"
using namespace hal;
using namespace wpi::java;
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);
extern "C" {
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiInitialize
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiInitialize
(JNIEnv* env, jclass, jint port)
{
int32_t status = 0;
HAL_InitializeSPI(static_cast<HAL_SPIPort>(port), &status);
CheckStatusForceThrow(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiTransaction
* Signature: (ILjava/lang/Object;Ljava/lang/Object;B)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiTransaction
(JNIEnv* env, jclass, jint port, jobject dataToSend, jobject dataReceived,
jbyte size)
{
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != nullptr) {
dataToSendPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
}
uint8_t* dataReceivedPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataReceived));
jint retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port),
dataToSendPtr, dataReceivedPtr, size);
return retVal;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiTransactionB
* Signature: (I[B[BB)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiTransactionB
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend,
jbyteArray dataReceived, jbyte size)
{
if (size < 0) {
ThrowIllegalArgumentException(env, "SPIJNI.spiTransactionB() size < 0");
return 0;
}
wpi::SmallVector<uint8_t, 128> recvBuf;
recvBuf.resize(size);
jint retVal =
HAL_TransactionSPI(static_cast<HAL_SPIPort>(port),
reinterpret_cast<const uint8_t*>(
JSpan<const jbyte>(env, dataToSend).data()),
recvBuf.data(), size);
env->SetByteArrayRegion(dataReceived, 0, size,
reinterpret_cast<const jbyte*>(recvBuf.data()));
return retVal;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiWrite
* Signature: (ILjava/lang/Object;B)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiWrite
(JNIEnv* env, jclass, jint port, jobject dataToSend, jbyte size)
{
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != nullptr) {
dataToSendPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
}
jint retVal =
HAL_WriteSPI(static_cast<HAL_SPIPort>(port), dataToSendPtr, size);
return retVal;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiWriteB
* Signature: (I[BB)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiWriteB
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jbyte size)
{
jint retVal = HAL_WriteSPI(static_cast<HAL_SPIPort>(port),
reinterpret_cast<const uint8_t*>(
JSpan<const jbyte>(env, dataToSend).data()),
size);
return retVal;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiRead
* Signature: (IZLjava/lang/Object;B)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiRead
(JNIEnv* env, jclass, jint port, jboolean initiate, jobject dataReceived,
jbyte size)
{
if (size < 0) {
ThrowIllegalArgumentException(env, "SPIJNI.spiRead() size < 0");
return 0;
}
uint8_t* dataReceivedPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataReceived));
jint retVal;
if (initiate) {
wpi::SmallVector<uint8_t, 128> sendBuf;
sendBuf.resize(size);
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(),
dataReceivedPtr, size);
} else {
retVal = HAL_ReadSPI(static_cast<HAL_SPIPort>(port),
reinterpret_cast<uint8_t*>(dataReceivedPtr), size);
}
return retVal;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiReadB
* Signature: (IZ[BB)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiReadB
(JNIEnv* env, jclass, jint port, jboolean initiate, jbyteArray dataReceived,
jbyte size)
{
if (size < 0) {
ThrowIllegalArgumentException(env, "SPIJNI.spiReadB() size < 0");
return 0;
}
jint retVal;
wpi::SmallVector<uint8_t, 128> recvBuf;
recvBuf.resize(size);
if (initiate) {
wpi::SmallVector<uint8_t, 128> sendBuf;
sendBuf.resize(size);
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(),
recvBuf.data(), size);
} else {
retVal = HAL_ReadSPI(static_cast<HAL_SPIPort>(port), recvBuf.data(), size);
}
env->SetByteArrayRegion(dataReceived, 0, size,
reinterpret_cast<const jbyte*>(recvBuf.data()));
return retVal;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiClose
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiClose
(JNIEnv*, jclass, jint port)
{
HAL_CloseSPI(static_cast<HAL_SPIPort>(port));
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiSetSpeed
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiSetSpeed
(JNIEnv*, jclass, jint port, jint speed)
{
HAL_SetSPISpeed(static_cast<HAL_SPIPort>(port), speed);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiSetMode
* Signature: (II)V
*/
JNIEXPORT void JNICALL
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)
{
return static_cast<jint>(HAL_GetSPIMode(static_cast<HAL_SPIPort>(port)));
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiSetChipSelectActiveHigh
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiSetChipSelectActiveHigh
(JNIEnv* env, jclass, jint port)
{
int32_t status = 0;
HAL_SetSPIChipSelectActiveHigh(static_cast<HAL_SPIPort>(port), &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiSetChipSelectActiveLow
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiSetChipSelectActiveLow
(JNIEnv* env, jclass, jint port)
{
int32_t status = 0;
HAL_SetSPIChipSelectActiveLow(static_cast<HAL_SPIPort>(port), &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiInitAuto
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiInitAuto
(JNIEnv* env, jclass, jint port, jint bufferSize)
{
int32_t status = 0;
HAL_InitSPIAuto(static_cast<HAL_SPIPort>(port), bufferSize, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiFreeAuto
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiFreeAuto
(JNIEnv* env, jclass, jint port)
{
int32_t status = 0;
if (port != HAL_kInvalidHandle) {
HAL_FreeSPIAuto(static_cast<HAL_SPIPort>(port), &status);
}
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiStartAutoRate
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiStartAutoRate
(JNIEnv* env, jclass, jint port, jdouble period)
{
int32_t status = 0;
HAL_StartSPIAutoRate(static_cast<HAL_SPIPort>(port), period, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiStartAutoTrigger
* Signature: (IIIZZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiStartAutoTrigger
(JNIEnv* env, jclass, jint port, jint digitalSourceHandle,
jint analogTriggerType, jboolean triggerRising, jboolean triggerFalling)
{
int32_t status = 0;
HAL_StartSPIAutoTrigger(static_cast<HAL_SPIPort>(port), digitalSourceHandle,
static_cast<HAL_AnalogTriggerType>(analogTriggerType),
triggerRising, triggerFalling, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiStopAuto
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiStopAuto
(JNIEnv* env, jclass, jint port)
{
int32_t status = 0;
HAL_StopSPIAuto(static_cast<HAL_SPIPort>(port), &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiSetAutoTransmitData
* Signature: (I[BI)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiSetAutoTransmitData
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jint zeroSize)
{
JSpan<const jbyte> jarr(env, dataToSend);
int32_t status = 0;
HAL_SetSPIAutoTransmitData(static_cast<HAL_SPIPort>(port),
reinterpret_cast<const uint8_t*>(jarr.data()),
jarr.size(), zeroSize, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiForceAutoRead
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiForceAutoRead
(JNIEnv* env, jclass, jint port)
{
int32_t status = 0;
HAL_ForceSPIAutoRead(static_cast<HAL_SPIPort>(port), &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiReadAutoReceivedData
* Signature: (ILjava/lang/Object;ID)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiReadAutoReceivedData__ILjava_nio_ByteBuffer_2ID
(JNIEnv* env, jclass, jint port, jobject buffer, jint numToRead,
jdouble timeout)
{
uint32_t* recvBuf =
reinterpret_cast<uint32_t*>(env->GetDirectBufferAddress(buffer));
int32_t status = 0;
jint retval = HAL_ReadSPIAutoReceivedData(
static_cast<HAL_SPIPort>(port), recvBuf, numToRead, timeout, &status);
CheckStatus(env, status);
return retval;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiReadAutoReceivedData
* Signature: (I[IID)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiReadAutoReceivedData__I_3IID
(JNIEnv* env, jclass, jint port, jintArray buffer, jint numToRead,
jdouble timeout)
{
if (numToRead < 0) {
ThrowIllegalArgumentException(
env, "SPIJNI.spiReadAutoReceivedData() numToRead < 0");
return 0;
}
wpi::SmallVector<uint32_t, 128> recvBuf;
recvBuf.resize(numToRead);
int32_t status = 0;
jint retval =
HAL_ReadSPIAutoReceivedData(static_cast<HAL_SPIPort>(port),
recvBuf.data(), numToRead, timeout, &status);
if (!CheckStatus(env, status)) {
return retval;
}
if (numToRead > 0) {
env->SetIntArrayRegion(buffer, 0, numToRead,
reinterpret_cast<const jint*>(recvBuf.data()));
}
return retval;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiGetAutoDroppedCount
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiGetAutoDroppedCount
(JNIEnv* env, jclass, jint port)
{
int32_t status = 0;
auto retval =
HAL_GetSPIAutoDroppedCount(static_cast<HAL_SPIPort>(port), &status);
CheckStatus(env, status);
return retval;
}
/*
* 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);
}
} // extern "C"

View File

@@ -1,277 +0,0 @@
// 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.
#include <jni.h>
#include "CallbackStore.h"
#include "edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI.h"
#include "hal/simulation/SPIAccelerometerData.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: registerActiveCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerActiveCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterSPIAccelerometerActiveCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: cancelActiveCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelActiveCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelSPIAccelerometerActiveCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: getActive
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getActive
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetSPIAccelerometerActive(index);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: setActive
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setActive
(JNIEnv*, jclass, jint index, jboolean value)
{
HALSIM_SetSPIAccelerometerActive(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: registerRangeCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerRangeCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterSPIAccelerometerRangeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: cancelRangeCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelRangeCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelSPIAccelerometerRangeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: getRange
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getRange
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetSPIAccelerometerRange(index);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: setRange
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setRange
(JNIEnv*, jclass, jint index, jint value)
{
HALSIM_SetSPIAccelerometerRange(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: registerXCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerXCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterSPIAccelerometerXCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: cancelXCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelXCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelSPIAccelerometerXCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: getX
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getX
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetSPIAccelerometerX(index);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: setX
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setX
(JNIEnv*, jclass, jint index, jdouble value)
{
HALSIM_SetSPIAccelerometerX(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: registerYCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerYCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterSPIAccelerometerYCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: cancelYCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelYCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelSPIAccelerometerYCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: getY
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getY
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetSPIAccelerometerY(index);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: setY
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setY
(JNIEnv*, jclass, jint index, jdouble value)
{
HALSIM_SetSPIAccelerometerY(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: registerZCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerZCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterSPIAccelerometerZCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: cancelZCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelZCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelSPIAccelerometerZCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: getZ
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getZ
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetSPIAccelerometerZ(index);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: setZ
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setZ
(JNIEnv*, jclass, jint index, jdouble value)
{
HALSIM_SetSPIAccelerometerZ(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
* Method: resetData
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_resetData
(JNIEnv*, jclass, jint index)
{
HALSIM_ResetSPIAccelerometerData(index);
}
} // extern "C"

View File

@@ -1,157 +0,0 @@
// 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.
#include <jni.h>
#include "BufferCallbackStore.h"
#include "CallbackStore.h"
#include "ConstBufferCallbackStore.h"
#include "SpiReadAutoReceiveBufferCallbackStore.h"
#include "edu_wpi_first_hal_simulation_SPIDataJNI.h"
#include "hal/simulation/SPIData.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: registerInitializedCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerInitializedCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterSPIInitializedCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: cancelInitializedCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelInitializedCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelSPIInitializedCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: getInitialized
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_getInitialized
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetSPIInitialized(index);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: setInitialized
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_setInitialized
(JNIEnv*, jclass, jint index, jboolean value)
{
HALSIM_SetSPIInitialized(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: registerReadCallback
* Signature: (ILjava/lang/Object;)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerReadCallback
(JNIEnv* env, jclass, jint index, jobject callback)
{
return sim::AllocateBufferCallback(env, index, callback,
&HALSIM_RegisterSPIReadCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: cancelReadCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelReadCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
sim::FreeBufferCallback(env, handle, index, &HALSIM_CancelSPIReadCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: registerWriteCallback
* Signature: (ILjava/lang/Object;)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerWriteCallback
(JNIEnv* env, jclass, jint index, jobject callback)
{
return sim::AllocateConstBufferCallback(env, index, callback,
&HALSIM_RegisterSPIWriteCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: cancelWriteCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelWriteCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
sim::FreeConstBufferCallback(env, handle, index,
&HALSIM_CancelSPIWriteCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: registerReadAutoReceiveBufferCallback
* Signature: (ILjava/lang/Object;)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerReadAutoReceiveBufferCallback
(JNIEnv* env, jclass, jint index, jobject callback)
{
return sim::AllocateSpiBufferCallback(
env, index, callback, &HALSIM_RegisterSPIReadAutoReceivedDataCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: cancelReadAutoReceiveBufferCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelReadAutoReceiveBufferCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
sim::FreeSpiBufferCallback(env, handle, index,
&HALSIM_CancelSPIReadAutoReceivedDataCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
* Method: resetData
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_SPIDataJNI_resetData
(JNIEnv*, jclass, jint index)
{
HALSIM_ResetSPIData(index);
}
} // extern "C"

View File

@@ -10,7 +10,6 @@
#include "CallbackStore.h"
#include "ConstBufferCallbackStore.h"
#include "SimDeviceDataJNI.h"
#include "SpiReadAutoReceiveBufferCallbackStore.h"
#include "edu_wpi_first_hal_simulation_SimulatorJNI.h"
#include "hal/HAL.h"
#include "hal/handles/HandlesInternal.h"
@@ -22,11 +21,9 @@ static JavaVM* jvm = nullptr;
static JClass notifyCallbackCls;
static JClass bufferCallbackCls;
static JClass constBufferCallbackCls;
static JClass spiReadAutoReceiveBufferCallbackCls;
static jmethodID notifyCallbackCallback;
static jmethodID bufferCallbackCallback;
static jmethodID constBufferCallbackCallback;
static jmethodID spiReadAutoReceiveBufferCallbackCallback;
namespace hal::sim {
jint SimOnLoad(JavaVM* vm, void* reserved) {
@@ -73,23 +70,9 @@ jint SimOnLoad(JavaVM* vm, void* reserved) {
return JNI_ERR;
}
spiReadAutoReceiveBufferCallbackCls = JClass(
env, "edu/wpi/first/hal/simulation/SpiReadAutoReceiveBufferCallback");
if (!spiReadAutoReceiveBufferCallbackCls) {
return JNI_ERR;
}
spiReadAutoReceiveBufferCallbackCallback =
env->GetMethodID(spiReadAutoReceiveBufferCallbackCls, "callback",
"(Ljava/lang/String;[II)I");
if (!spiReadAutoReceiveBufferCallbackCallback) {
return JNI_ERR;
}
InitializeStore();
InitializeBufferStore();
InitializeConstBufferStore();
InitializeSpiBufferStore();
if (!InitializeSimDeviceDataJNI(env)) {
return JNI_ERR;
}
@@ -106,7 +89,6 @@ void SimOnUnload(JavaVM* vm, void* reserved) {
notifyCallbackCls.free(env);
bufferCallbackCls.free(env);
constBufferCallbackCls.free(env);
spiReadAutoReceiveBufferCallbackCls.free(env);
FreeSimDeviceDataJNI(env);
jvm = nullptr;
}
@@ -127,9 +109,6 @@ jmethodID GetConstBufferCallback() {
return constBufferCallbackCallback;
}
jmethodID GetSpiReadAutoReceiveBufferCallback() {
return spiReadAutoReceiveBufferCallbackCallback;
}
} // namespace hal::sim
extern "C" {

View File

@@ -15,5 +15,4 @@ JavaVM* GetJVM();
jmethodID GetNotifyCallback();
jmethodID GetBufferCallback();
jmethodID GetConstBufferCallback();
jmethodID GetSpiReadAutoReceiveBufferCallback();
} // namespace hal::sim

View File

@@ -1,134 +0,0 @@
// 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.
#include "SpiReadAutoReceiveBufferCallbackStore.h"
#include <jni.h>
#include <cstdio>
#include <memory>
#include <wpi/jni_util.h>
#include "SimulatorJNI.h"
#include "hal/Types.h"
#include "hal/handles/UnlimitedHandleResource.h"
using namespace hal;
using namespace hal::sim;
using namespace wpi::java;
static hal::UnlimitedHandleResource<
SIM_JniHandle, SpiReadAutoReceiveBufferCallbackStore,
hal::HAL_HandleEnum::SimulationJni>* callbackHandles;
namespace hal::sim {
void InitializeSpiBufferStore() {
static hal::UnlimitedHandleResource<SIM_JniHandle,
SpiReadAutoReceiveBufferCallbackStore,
hal::HAL_HandleEnum::SimulationJni>
cb;
callbackHandles = &cb;
}
} // namespace hal::sim
void SpiReadAutoReceiveBufferCallbackStore::create(JNIEnv* env, jobject obj) {
m_call = JGlobal<jobject>(env, obj);
}
int32_t SpiReadAutoReceiveBufferCallbackStore::performCallback(
const char* name, uint32_t* buffer, int32_t numToRead) {
JNIEnv* env;
JavaVM* vm = sim::GetJVM();
bool didAttachThread = false;
int tryGetEnv = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
if (tryGetEnv == JNI_EDETACHED) {
// Thread not attached
didAttachThread = true;
if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
// Failed to attach, log and return
std::puts("Failed to attach");
std::fflush(stdout);
return -1;
}
} else if (tryGetEnv == JNI_EVERSION) {
std::puts("Invalid JVM Version requested");
std::fflush(stdout);
}
auto toCallbackArr = MakeJIntArray(
env, std::span<const uint32_t>{buffer, static_cast<size_t>(numToRead)});
jint ret = env->CallIntMethod(m_call, sim::GetBufferCallback(),
MakeJString(env, name), toCallbackArr,
static_cast<jint>(numToRead));
jint* fromCallbackArr = reinterpret_cast<jint*>(
env->GetPrimitiveArrayCritical(toCallbackArr, nullptr));
for (int i = 0; i < ret; i++) {
buffer[i] = fromCallbackArr[i];
}
env->ReleasePrimitiveArrayCritical(toCallbackArr, fromCallbackArr, JNI_ABORT);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
}
if (didAttachThread) {
vm->DetachCurrentThread();
}
return ret;
}
void SpiReadAutoReceiveBufferCallbackStore::free(JNIEnv* env) {
m_call.free(env);
}
SIM_JniHandle sim::AllocateSpiBufferCallback(
JNIEnv* env, jint index, jobject callback,
RegisterSpiBufferCallbackFunc createCallback) {
auto callbackStore =
std::make_shared<SpiReadAutoReceiveBufferCallbackStore>();
auto handle = callbackHandles->Allocate(callbackStore);
if (handle == HAL_kInvalidHandle) {
return -1;
}
uintptr_t handleAsPtr = static_cast<uintptr_t>(handle);
void* handleAsVoidPtr = reinterpret_cast<void*>(handleAsPtr);
callbackStore->create(env, callback);
auto callbackFunc = [](const char* name, void* param, uint32_t* buffer,
int32_t numToRead, int32_t* outputCount) {
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
auto data = callbackHandles->Get(handle);
if (!data) {
return;
}
*outputCount = data->performCallback(name, buffer, numToRead);
};
auto id = createCallback(index, callbackFunc, handleAsVoidPtr);
callbackStore->setCallbackId(id);
return handle;
}
void sim::FreeSpiBufferCallback(JNIEnv* env, SIM_JniHandle handle, jint index,
FreeSpiBufferCallbackFunc freeCallback) {
auto callback = callbackHandles->Free(handle);
if (callback == nullptr) {
return;
}
freeCallback(index, callback->getCallbackId());
callback->free(env);
}

View File

@@ -1,44 +0,0 @@
// 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.
#pragma once
#include <jni.h>
#include <wpi/jni_util.h>
#include "SimulatorJNI.h"
#include "hal/Types.h"
#include "hal/Value.h"
#include "hal/handles/UnlimitedHandleResource.h"
#include "hal/simulation/NotifyListener.h"
#include "hal/simulation/SPIData.h"
namespace hal::sim {
class SpiReadAutoReceiveBufferCallbackStore {
public:
void create(JNIEnv* env, jobject obj);
int32_t performCallback(const char* name, uint32_t* buffer,
int32_t numToRead);
void free(JNIEnv* env);
void setCallbackId(int32_t id) { callbackId = id; }
int32_t getCallbackId() { return callbackId; }
private:
wpi::java::JGlobal<jobject> m_call;
int32_t callbackId;
};
void InitializeSpiBufferStore();
using RegisterSpiBufferCallbackFunc = int32_t (*)(
int32_t index, HAL_SpiReadAutoReceiveBufferCallback callback, void* param);
using FreeSpiBufferCallbackFunc = void (*)(int32_t index, int32_t uid);
SIM_JniHandle AllocateSpiBufferCallback(
JNIEnv* env, jint index, jobject callback,
RegisterSpiBufferCallbackFunc createCallback);
void FreeSpiBufferCallback(JNIEnv* env, SIM_JniHandle handle, jint index,
FreeSpiBufferCallbackFunc freeCallback);
} // namespace hal::sim

View File

@@ -30,7 +30,6 @@
#include "hal/PWM.h"
#include "hal/Ports.h"
#include "hal/Power.h"
#include "hal/SPI.h"
#include "hal/SerialPort.h"
#include "hal/SimDevice.h"
#include "hal/Threads.h"

View File

@@ -1,281 +0,0 @@
// 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.
#pragma once
#include <stdint.h>
#include "hal/AnalogTrigger.h"
#include "hal/SPITypes.h"
#include "hal/Types.h"
/**
* @defgroup hal_spi SPI Functions
* @ingroup hal_capi
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initializes the SPI port. Opens the port if necessary and saves the handle.
*
* If opening the MXP port, also sets up the channel functions appropriately.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS3, 4
* for MXP
* @param[out] status the error code, or 0 for success
*/
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status);
/**
* Performs an SPI send/receive transaction.
*
* This is a lower-level interface to the spi hardware giving you more control
* over each transaction.
*
* @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]
* @return Number of bytes transferred, -1 for error
*/
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size);
/**
* Executes a write transaction with the device.
*
* Writes to a device and wait until the transaction is complete.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4
* for MXP
* @param dataToSend The data to write to the register on the device.
* @param sendSize The number of bytes to be written
* @return The number of bytes written. -1 for an error
*/
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize);
/**
* Executes a read from the device.
*
* This method does not write any data out to the device.
*
* Most spi devices will require a register address to be written before they
* begin returning data.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP
* @param buffer A pointer to the array of bytes to store the data read from the
* device.
* @param count The number of bytes to read in the transaction. [1..7]
* @return Number of bytes read. -1 for error.
*/
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count);
/**
* Closes the SPI port.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_CloseSPI(HAL_SPIPort port);
/**
* Sets the clock speed for the SPI bus.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP
* @param speed The speed in Hz (500KHz-10MHz)
*/
void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed);
/**
* Sets the SPI Mode.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP
* @param mode The SPI mode to use
*/
void HAL_SetSPIMode(HAL_SPIPort port, HAL_SPIMode mode);
/**
* Gets the SPI Mode.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP
* @return The SPI mode currently set
*/
HAL_SPIMode HAL_GetSPIMode(HAL_SPIPort port);
/**
* Sets the CS Active high for a SPI port.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP
* @param[out] status the error code, or 0 for success
*/
void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status);
/**
* Sets the CS Active low for a SPI port.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2, 4
* for MXP
* @param[out] status the error code, or 0 for success
*/
void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status);
/**
* Gets the stored handle for a SPI port.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @return The stored handle for the SPI port. 0 represents no stored
* handle.
*/
int32_t HAL_GetSPIHandle(HAL_SPIPort port);
/**
* Sets the stored handle for a SPI port.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP.
* @param handle The value of the handle for the port.
*/
void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle);
/**
* Initializes the SPI automatic accumulator.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2,
* 4 for MXP.
* @param[in] bufferSize The accumulator buffer size.
* @param[out] status the error code, or 0 for success
*/
void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status);
/**
* Frees an SPI automatic accumulator.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2, 4
* for MXP.
* @param[out] status the error code, or 0 for success
*/
void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status);
/**
* Sets the period for automatic SPI accumulation.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2, 4
* for MXP.
* @param[in] period The accumulation period (seconds).
* @param[out] status the error code, or 0 for success
*/
void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t* status);
/**
* Starts the auto SPI accumulator on a specific trigger.
*
* Note that triggering on both rising and falling edges is a valid
* configuration.
*
* @param[in] port The number of the port to use. 0-3 for Onboard
* CS0-CS2, 4 for MXP.
* @param[in] digitalSourceHandle The trigger source to use (Either
* HAL_AnalogTriggerHandle or HAL_DigitalHandle).
* @param[in] analogTriggerType The analog trigger type, if the source is an
* analog trigger.
* @param[in] triggerRising Trigger on the rising edge if true.
* @param[in] triggerFalling Trigger on the falling edge if true.
* @param[out] status the error code, or 0 for success
*/
void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_Bool triggerRising, HAL_Bool triggerFalling,
int32_t* status);
/**
* Stops an automatic SPI accumulation.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2, 4
* for MXP.
* @param[out] status the error code, or 0 for success
*/
void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status);
/**
* Sets the data to be transmitted to the device to initiate a read.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2,
* 4 for MXP.
* @param[in] dataToSend Pointer to the data to send (Gets copied for continue
* use, so no need to keep alive).
* @param[in] dataSize The length of the data to send.
* @param[in] zeroSize The number of zeros to send after the data.
* @param[out] status the error code, or 0 for success
*/
void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t dataSize, int32_t zeroSize,
int32_t* status);
/**
* Immediately forces an SPI read to happen.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2, 4
* for MXP.
* @param[out] status the error code, or 0 for success
*/
void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status);
/**
* Reads data received by the SPI accumulator. Each received data sequence
* consists of a timestamp followed by the received data bytes, one byte per
* word (in the least significant byte). The length of each received data
* sequence is the same as the combined dataSize + zeroSize set in
* HAL_SetSPIAutoTransmitData.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2,
* 4 for MXP.
* @param[out] buffer The buffer to store the data into.
* @param[in] numToRead The number of words to read.
* @param[in] timeout The read timeout (in seconds).
* @param[out] status the error code, or 0 for success
* @return The number of words actually read.
*/
int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
int32_t numToRead, double timeout,
int32_t* status);
/**
* Gets the count of how many SPI accumulations have been missed.
*
* @param[in] port The number of the port to use. 0-3 for Onboard CS0-CS2, 4
* for MXP.
* @param[out] status the error code, or 0 for success
* @return The number of missed accumulations.
*/
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status);
/**
* Configure the Auto SPI Stall time between reads.
*
* @param[in] port The number of the port to use. 0-3 for Onboard
* CS0-CS2, 4 for MXP.
* @param[in] csToSclkTicks the number of ticks to wait before asserting the
* cs pin
* @param[in] stallTicks the number of ticks to stall for
* @param[in] pow2BytesPerRead the number of bytes to read before stalling
* @param[out] status the error code, or 0 for success
*/
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
int32_t stallTicks, int32_t pow2BytesPerRead,
int32_t* status);
#ifdef __cplusplus
} // extern "C"
#endif
/** @} */

View File

@@ -1,44 +0,0 @@
// 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.
#pragma once
#include <stdint.h>
#include "hal/Types.h"
/**
* @defgroup hal_spi SPI Functions
* @ingroup hal_capi
* @{
*/
/** SPI port. */
HAL_ENUM(HAL_SPIPort) {
/** Invalid port number. */
HAL_SPI_kInvalid = -1,
/** Onboard SPI bus port CS0. */
HAL_SPI_kOnboardCS0,
/** Onboard SPI bus port CS1. */
HAL_SPI_kOnboardCS1,
/** Onboard SPI bus port CS2. */
HAL_SPI_kOnboardCS2,
/** Onboard SPI bus port CS3. */
HAL_SPI_kOnboardCS3,
/** MXP (roboRIO MXP) SPI bus port. */
HAL_SPI_kMXP
};
/** SPI mode. */
HAL_ENUM(HAL_SPIMode) {
/** Clock idle low, data sampled on rising edge. */
HAL_SPI_kMode0 = 0,
/** Clock idle low, data sampled on falling edge. */
HAL_SPI_kMode1 = 1,
/** Clock idle high, data sampled on falling edge. */
HAL_SPI_kMode2 = 2,
/** Clock idle high, data sampled on rising edge. */
HAL_SPI_kMode3 = 3,
};
/** @} */

View File

@@ -181,20 +181,6 @@ inline int16_t getPortHandleModule(HAL_PortHandle handle) {
return static_cast<uint8_t>((handle >> 8) & 0xff);
}
// using a 16 bit value so we can store 0-255 and still report error
/**
* Gets the SPI channel of a port handle.
*
* @param handle the port handle
* @return the port SPI channel
*/
inline int16_t getPortHandleSPIEnable(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
return InvalidHandleIndex;
}
return static_cast<uint8_t>((handle >> 16) & 0xff);
}
/**
* Create a port handle.
*
@@ -204,14 +190,6 @@ inline int16_t getPortHandleSPIEnable(HAL_PortHandle handle) {
*/
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module);
/**
* Create a port handle for SPI.
*
* @param channel the SPI channel
* @return port handle for the channel
*/
HAL_PortHandle createPortHandleForSPI(uint8_t channel);
/**
* Create a handle for a specific index, type and version.
*

View File

@@ -1,60 +0,0 @@
// 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.
#pragma once
#include "hal/Types.h"
#include "hal/simulation/NotifyListener.h"
#ifdef __cplusplus
extern "C" {
#endif
void HALSIM_ResetSPIAccelerometerData(int32_t index);
int32_t HALSIM_RegisterSPIAccelerometerActiveCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void HALSIM_CancelSPIAccelerometerActiveCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetSPIAccelerometerActive(int32_t index);
void HALSIM_SetSPIAccelerometerActive(int32_t index, HAL_Bool active);
int32_t HALSIM_RegisterSPIAccelerometerRangeCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void HALSIM_CancelSPIAccelerometerRangeCallback(int32_t index, int32_t uid);
int32_t HALSIM_GetSPIAccelerometerRange(int32_t index);
void HALSIM_SetSPIAccelerometerRange(int32_t index, int32_t range);
int32_t HALSIM_RegisterSPIAccelerometerXCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void HALSIM_CancelSPIAccelerometerXCallback(int32_t index, int32_t uid);
double HALSIM_GetSPIAccelerometerX(int32_t index);
void HALSIM_SetSPIAccelerometerX(int32_t index, double x);
int32_t HALSIM_RegisterSPIAccelerometerYCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void HALSIM_CancelSPIAccelerometerYCallback(int32_t index, int32_t uid);
double HALSIM_GetSPIAccelerometerY(int32_t index);
void HALSIM_SetSPIAccelerometerY(int32_t index, double y);
int32_t HALSIM_RegisterSPIAccelerometerZCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void HALSIM_CancelSPIAccelerometerZCallback(int32_t index, int32_t uid);
double HALSIM_GetSPIAccelerometerZ(int32_t index);
void HALSIM_SetSPIAccelerometerZ(int32_t index, double z);
void HALSIM_RegisterSPIAccelerometerAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -1,46 +0,0 @@
// 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.
#pragma once
#include "hal/Types.h"
#include "hal/simulation/NotifyListener.h"
typedef void (*HAL_SpiReadAutoReceiveBufferCallback)(const char* name,
void* param,
uint32_t* buffer,
int32_t numToRead,
int32_t* outputCount);
#ifdef __cplusplus
extern "C" {
#endif
void HALSIM_ResetSPIData(int32_t index);
int32_t HALSIM_RegisterSPIInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void HALSIM_CancelSPIInitializedCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetSPIInitialized(int32_t index);
void HALSIM_SetSPIInitialized(int32_t index, HAL_Bool initialized);
int32_t HALSIM_RegisterSPIReadCallback(int32_t index,
HAL_BufferCallback callback,
void* param);
void HALSIM_CancelSPIReadCallback(int32_t index, int32_t uid);
int32_t HALSIM_RegisterSPIWriteCallback(int32_t index,
HAL_ConstBufferCallback callback,
void* param);
void HALSIM_CancelSPIWriteCallback(int32_t index, int32_t uid);
int32_t HALSIM_RegisterSPIReadAutoReceivedDataCallback(
int32_t index, HAL_SpiReadAutoReceiveBufferCallback callback, void* param);
void HALSIM_CancelSPIReadAutoReceivedDataCallback(int32_t index, int32_t uid);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -85,8 +85,6 @@ void InitializeHAL() {
InitializePWMData();
InitializeRoboRioData();
InitializeSimDeviceData();
InitializeSPIAccelerometerData();
InitializeSPIData();
InitializeAccelerometer();
InitializeAddressableLED();
InitializeAnalogAccumulator();
@@ -116,7 +114,6 @@ void InitializeHAL() {
InitializePWM();
InitializeSerialPort();
InitializeSimDevice();
InitializeSPI();
InitializeThreads();
}
} // namespace hal::init

View File

@@ -36,8 +36,6 @@ extern void InitializePowerDistributionData();
extern void InitializePWMData();
extern void InitializeRoboRioData();
extern void InitializeSimDeviceData();
extern void InitializeSPIAccelerometerData();
extern void InitializeSPIData();
extern void InitializeAccelerometer();
extern void InitializeAddressableLED();
extern void InitializeAnalogAccumulator();
@@ -67,7 +65,6 @@ extern void InitializeREVPH();
extern void InitializePWM();
extern void InitializeSerialPort();
extern void InitializeSimDevice();
extern void InitializeSPI();
extern void InitializeThreads();
} // namespace hal::init

View File

@@ -1,74 +0,0 @@
// 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.
#include "hal/SPI.h"
#include "HALInitializer.h"
#include "mockdata/SPIDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeSPI() {}
} // namespace hal::init
extern "C" {
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
hal::init::CheckInit();
SimSPIData[port].initialized = true;
}
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size) {
return SimSPIData[port].Transaction(dataToSend, dataReceived, size);
}
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize) {
return SimSPIData[port].Write(dataToSend, sendSize);
}
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
return SimSPIData[port].Read(buffer, count);
}
void HAL_CloseSPI(HAL_SPIPort port) {
SimSPIData[port].initialized = false;
}
void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {}
void HAL_SetSPIMode(HAL_SPIPort port, HAL_SPIMode mode) {}
HAL_SPIMode HAL_GetSPIMode(HAL_SPIPort port) {
return HAL_SPI_kMode0;
}
void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {}
void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {}
int32_t HAL_GetSPIHandle(HAL_SPIPort port) {
return 0;
}
void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) {}
void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status) {}
void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status) {}
void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t* status) {}
void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_Bool triggerRising, HAL_Bool triggerFalling,
int32_t* status) {}
void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status) {}
void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t dataSize, int32_t zeroSize,
int32_t* status) {}
void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status) {}
int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
int32_t numToRead, double timeout,
int32_t* status) {
return SimSPIData[port].ReadAutoReceivedData(buffer, numToRead, timeout,
status);
}
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
return 0;
}
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
int32_t stallTicks, int32_t pow2BytesPerRead,
int32_t* status) {}
} // extern "C"

View File

@@ -19,8 +19,6 @@
#include <hal/simulation/PowerDistributionData.h>
#include <hal/simulation/REVPHData.h>
#include <hal/simulation/RoboRioData.h>
#include <hal/simulation/SPIAccelerometerData.h>
#include <hal/simulation/SPIData.h>
#include <hal/simulation/SimDeviceData.h>
#include "../PortsInternal.h"
@@ -88,12 +86,4 @@ extern "C" void HALSIM_ResetAllSimData(void) {
HALSIM_ResetRoboRioData();
HALSIM_ResetSimDeviceData();
for (int32_t i = 0; i < hal::kSPIAccelerometers; i++) {
HALSIM_ResetSPIAccelerometerData(i);
}
for (int32_t i = 0; i < hal::kSPIPorts; i++) {
HALSIM_ResetSPIData(i);
}
}

View File

@@ -1,55 +0,0 @@
// 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.
#include "../PortsInternal.h"
#include "SPIAccelerometerDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeSPIAccelerometerData() {
static SPIAccelerometerData ssad[kSPIAccelerometers];
::hal::SimSPIAccelerometerData = ssad;
}
} // namespace hal::init
SPIAccelerometerData* hal::SimSPIAccelerometerData;
void SPIAccelerometerData::ResetData() {
active.Reset(false);
range.Reset(0);
x.Reset(0.0);
y.Reset(0.0);
z.Reset(0.0);
}
extern "C" {
void HALSIM_ResetSPIAccelerometerData(int32_t index) {
SimSPIAccelerometerData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, SPIAccelerometer##CAPINAME, \
SimSPIAccelerometerData, LOWERNAME)
DEFINE_CAPI(HAL_Bool, Active, active)
DEFINE_CAPI(int32_t, Range, range)
DEFINE_CAPI(double, X, x)
DEFINE_CAPI(double, Y, y)
DEFINE_CAPI(double, Z, z)
#define REGISTER(NAME) \
SimSPIAccelerometerData[index].NAME.RegisterCallback(callback, param, \
initialNotify)
void HALSIM_RegisterSPIAccelerometerAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
REGISTER(active);
REGISTER(range);
REGISTER(x);
REGISTER(y);
REGISTER(z);
}
} // extern "C"

View File

@@ -1,28 +0,0 @@
// 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.
#pragma once
#include "hal/simulation/SPIAccelerometerData.h"
#include "hal/simulation/SimDataValue.h"
namespace hal {
class SPIAccelerometerData {
HAL_SIMDATAVALUE_DEFINE_NAME(Active)
HAL_SIMDATAVALUE_DEFINE_NAME(Range)
HAL_SIMDATAVALUE_DEFINE_NAME(X)
HAL_SIMDATAVALUE_DEFINE_NAME(Y)
HAL_SIMDATAVALUE_DEFINE_NAME(Z)
public:
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetActiveName> active{false};
SimDataValue<int32_t, HAL_MakeInt, GetRangeName> range{0};
SimDataValue<double, HAL_MakeDouble, GetXName> x{0.0};
SimDataValue<double, HAL_MakeDouble, GetYName> y{0.0};
SimDataValue<double, HAL_MakeDouble, GetZName> z{0.0};
virtual void ResetData();
};
extern SPIAccelerometerData* SimSPIAccelerometerData;
} // namespace hal

View File

@@ -1,70 +0,0 @@
// 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.
#include "../PortsInternal.h"
#include "SPIDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeSPIData() {
static SPIData ssd[kSPIPorts];
::hal::SimSPIData = ssd;
}
} // namespace hal::init
SPIData* hal::SimSPIData;
void SPIData::ResetData() {
initialized.Reset(false);
read.Reset();
write.Reset();
autoReceivedData.Reset();
}
int32_t SPIData::Read(uint8_t* buffer, int32_t count) {
read(buffer, count);
return count;
}
int32_t SPIData::Write(const uint8_t* dataToSend, int32_t sendSize) {
write(dataToSend, sendSize);
return sendSize;
}
int32_t SPIData::Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
int32_t size) {
write(dataToSend, size);
read(dataReceived, size);
return size;
}
int32_t SPIData::ReadAutoReceivedData(uint32_t* buffer, int32_t numToRead,
double timeout, int32_t* status) {
int32_t outputCount = 0;
autoReceivedData(buffer, numToRead, &outputCount);
return outputCount;
}
extern "C" {
void HALSIM_ResetSPIData(int32_t index) {
SimSPIData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, SPI##CAPINAME, SimSPIData, \
LOWERNAME)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
#undef DEFINE_CAPI
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI(TYPE, HALSIM, SPI##CAPINAME, SimSPIData, \
LOWERNAME)
DEFINE_CAPI(HAL_BufferCallback, Read, read)
DEFINE_CAPI(HAL_ConstBufferCallback, Write, write)
DEFINE_CAPI(HAL_SpiReadAutoReceiveBufferCallback, ReadAutoReceivedData,
autoReceivedData)
} // extern "C"

View File

@@ -1,37 +0,0 @@
// 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.
#pragma once
#include "hal/simulation/SPIData.h"
#include "hal/simulation/SimCallbackRegistry.h"
#include "hal/simulation/SimDataValue.h"
namespace hal {
class SPIData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Read)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Write)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(AutoReceive)
public:
int32_t Read(uint8_t* buffer, int32_t count);
int32_t Write(const uint8_t* dataToSend, int32_t sendSize);
int32_t Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
int32_t size);
int32_t ReadAutoReceivedData(uint32_t* buffer, int32_t numToRead,
double timeout, int32_t* status);
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
false};
SimCallbackRegistry<HAL_BufferCallback, GetReadName> read;
SimCallbackRegistry<HAL_ConstBufferCallback, GetWriteName> write;
SimCallbackRegistry<HAL_SpiReadAutoReceiveBufferCallback, GetAutoReceiveName>
autoReceivedData;
void ResetData();
};
extern SPIData* SimSPIData;
} // namespace hal

View File

@@ -75,7 +75,6 @@ void InitializeHAL() {
InitializePWM();
InitializeSerialPort();
InitializeSmartIo();
InitializeSPI();
InitializeThreads();
}
} // namespace init

View File

@@ -49,6 +49,5 @@ extern void InitializePower();
extern void InitializePWM();
extern void InitializeSerialPort();
extern void InitializeSmartIo();
extern void InitializeSPI();
extern void InitializeThreads();
} // namespace hal::init

View File

@@ -1,141 +0,0 @@
// 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.
#include "hal/SPI.h"
#include <fcntl.h>
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <array>
#include <atomic>
#include <cstdio>
#include <cstring>
#include <memory>
#include <fmt/format.h>
#include <wpi/mutex.h>
#include <wpi/print.h>
#include "HALInitializer.h"
#include "HALInternal.h"
#include "hal/DIO.h"
#include "hal/HAL.h"
#include "hal/handles/HandlesInternal.h"
using namespace hal;
namespace hal::init {
void InitializeSPI() {}
} // namespace hal::init
extern "C" {
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
hal::init::CheckInit();
*status = HAL_HANDLE_ERROR;
return;
}
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size) {
return -1;
}
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize) {
return -1;
}
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
return -1;
}
void HAL_CloseSPI(HAL_SPIPort port) {}
void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {}
void HAL_SetSPIMode(HAL_SPIPort port, HAL_SPIMode mode) {}
HAL_SPIMode HAL_GetSPIMode(HAL_SPIPort port) {
return HAL_SPI_kMode0;
}
void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
int32_t HAL_GetSPIHandle(HAL_SPIPort port) {
return 0;
}
void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) {}
void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_Bool triggerRising, HAL_Bool triggerFalling,
int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t dataSize, int32_t zeroSize,
int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
int32_t numToRead, double timeout,
int32_t* status) {
*status = HAL_HANDLE_ERROR;
return 0;
}
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return 0;
}
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
int32_t stallTicks, int32_t pow2BytesPerRead,
int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
} // extern "C"

View File

@@ -1,25 +0,0 @@
// 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.
#include "hal/simulation/SPIAccelerometerData.h"
#include "hal/simulation/SimDataValue.h"
extern "C" {
void HALSIM_ResetSPIAccelerometerData(int32_t index) {}
#define DEFINE_CAPI(TYPE, CAPINAME, RETURN) \
HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, SPIAccelerometer##CAPINAME, RETURN)
DEFINE_CAPI(HAL_Bool, Active, false)
DEFINE_CAPI(int32_t, Range, 0)
DEFINE_CAPI(double, X, 0)
DEFINE_CAPI(double, Y, 0)
DEFINE_CAPI(double, Z, 0)
void HALSIM_RegisterSPIAccelerometerAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {}
} // extern "C"

View File

@@ -1,25 +0,0 @@
// 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.
#include "hal/simulation/SPIData.h"
#include "hal/simulation/SimDataValue.h"
extern "C" {
void HALSIM_ResetSPIData(int32_t index) {}
#define DEFINE_CAPI(TYPE, CAPINAME, RETURN) \
HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, SPI##CAPINAME, RETURN)
DEFINE_CAPI(HAL_Bool, Initialized, false)
#undef DEFINE_CAPI
#define DEFINE_CAPI(TYPE, CAPINAME) \
HAL_SIMCALLBACKREGISTRY_STUB_CAPI(TYPE, HALSIM, SPI##CAPINAME)
DEFINE_CAPI(HAL_BufferCallback, Read)
DEFINE_CAPI(HAL_ConstBufferCallback, Write)
DEFINE_CAPI(HAL_SpiReadAutoReceiveBufferCallback, ReadAutoReceivedData)
} // extern "C"