mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[hal,wpilib] Remove a ton of things related to the FPGA (#7846)
Co-authored-by: Gold856 <117957790+Gold856@users.noreply.github.com>
This commit is contained in:
@@ -43,7 +43,6 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
|
||||
}
|
||||
|
||||
analog_port->channel = static_cast<uint8_t>(channel);
|
||||
analog_port->isAccumulator = false;
|
||||
|
||||
SimAnalogInData[channel].initialized = true;
|
||||
SimAnalogInData[channel].simDevice = 0;
|
||||
@@ -80,52 +79,6 @@ void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle,
|
||||
SimAnalogInData[port->channel].simDevice = device;
|
||||
}
|
||||
|
||||
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
|
||||
// No op
|
||||
}
|
||||
double HAL_GetAnalogSampleRate(int32_t* status) {
|
||||
return kDefaultSampleRate;
|
||||
}
|
||||
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t bits, int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
SimAnalogInData[port->channel].averageBits = bits;
|
||||
}
|
||||
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return SimAnalogInData[port->channel].averageBits;
|
||||
}
|
||||
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t bits, int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
SimAnalogInData[port->channel].oversampleBits = bits;
|
||||
}
|
||||
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return SimAnalogInData[port->channel].oversampleBits;
|
||||
}
|
||||
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
@@ -137,27 +90,12 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
double voltage = SimAnalogInData[port->channel].voltage;
|
||||
return HAL_GetAnalogVoltsToValue(analogPortHandle, voltage, status);
|
||||
}
|
||||
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
// No averaging supported
|
||||
return HAL_GetAnalogValue(analogPortHandle, status);
|
||||
}
|
||||
|
||||
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
double voltage, int32_t* status) {
|
||||
if (voltage > 5.0) {
|
||||
voltage = 5.0;
|
||||
*status = VOLTAGE_OUT_OF_RANGE;
|
||||
}
|
||||
if (voltage < 0.0) {
|
||||
voltage = 0.0;
|
||||
*status = VOLTAGE_OUT_OF_RANGE;
|
||||
}
|
||||
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
|
||||
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
|
||||
int32_t value =
|
||||
static_cast<int32_t>((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9));
|
||||
return value;
|
||||
return static_cast<int32_t>(voltage * 4095.0 / 3.3);
|
||||
}
|
||||
|
||||
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
@@ -171,29 +109,6 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
|
||||
double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t rawValue, int32_t* status) {
|
||||
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
|
||||
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
|
||||
double voltage = LSBWeight * 1.0e-9 * rawValue - offset * 1.0e-9;
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// No averaging supported
|
||||
return SimAnalogInData[port->channel].voltage;
|
||||
}
|
||||
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
return 1220703;
|
||||
}
|
||||
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
return rawValue / 4095.0 * 3.3;
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -13,15 +13,9 @@
|
||||
#include "wpi/hal/handles/IndexedHandleResource.hpp"
|
||||
|
||||
namespace wpi::hal {
|
||||
constexpr int32_t kTimebase = 40000000; ///< 40 MHz clock
|
||||
constexpr int32_t kDefaultOversampleBits = 0;
|
||||
constexpr int32_t kDefaultAverageBits = 7;
|
||||
constexpr double kDefaultSampleRate = 50000.0;
|
||||
static constexpr uint32_t kAccumulatorChannels[] = {0, 1};
|
||||
|
||||
struct AnalogPort {
|
||||
uint8_t channel;
|
||||
bool isAccumulator;
|
||||
std::string previousAllocation;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,19 +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 "wpi/hal/Constants.h"
|
||||
|
||||
#include "ConstantsInternal.hpp"
|
||||
|
||||
using namespace wpi::hal;
|
||||
|
||||
namespace wpi::hal::init {
|
||||
void InitializeConstants() {}
|
||||
} // namespace wpi::hal::init
|
||||
|
||||
extern "C" {
|
||||
int32_t HAL_GetSystemClockTicksPerMicrosecond(void) {
|
||||
return kSystemClockTicksPerMicrosecond;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -1,11 +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>
|
||||
|
||||
namespace wpi::hal {
|
||||
constexpr int32_t kSystemClockTicksPerMicrosecond = 40;
|
||||
} // namespace wpi::hal
|
||||
@@ -86,7 +86,6 @@ void InitializeHAL() {
|
||||
InitializeAnalogInput();
|
||||
InitializeAnalogInternal();
|
||||
InitializeCAN();
|
||||
InitializeConstants();
|
||||
InitializeCounter();
|
||||
InitializeDigitalInternal();
|
||||
InitializeDIO();
|
||||
|
||||
@@ -38,7 +38,6 @@ extern void InitializeAlert();
|
||||
extern void InitializeAnalogInput();
|
||||
extern void InitializeAnalogInternal();
|
||||
extern void InitializeCAN();
|
||||
extern void InitializeConstants();
|
||||
extern void InitializeCounter();
|
||||
extern void InitializeDigitalInternal();
|
||||
extern void InitializeDIO();
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
|
||||
#include "MockHooksInternal.hpp"
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "wpi/hal/PWM.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "DigitalInternal.hpp"
|
||||
#include "HALInitializer.hpp"
|
||||
#include "HALInternal.hpp"
|
||||
|
||||
@@ -16,6 +16,9 @@ extern "C" {
|
||||
int32_t HAL_GetNumCanBuses(void) {
|
||||
return kNumCanBuses;
|
||||
}
|
||||
int32_t HAL_GetNumSmartIo(void) {
|
||||
return kNumSmartIo;
|
||||
}
|
||||
int32_t HAL_GetNumAnalogInputs(void) {
|
||||
return kNumAnalogInputs;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace wpi::hal {
|
||||
constexpr int32_t kNumCanBuses = 5;
|
||||
constexpr int32_t kAccelerometers = 1;
|
||||
constexpr int32_t kNumSmartIo = 6;
|
||||
constexpr int32_t kNumAccumulators = 2;
|
||||
constexpr int32_t kNumAnalogInputs = 8;
|
||||
constexpr int32_t kNumAnalogOutputs = 2;
|
||||
|
||||
@@ -18,8 +18,6 @@ AnalogInData* wpi::hal::SimAnalogInData;
|
||||
void AnalogInData::ResetData() {
|
||||
initialized.Reset(false);
|
||||
simDevice = 0;
|
||||
averageBits.Reset(7);
|
||||
oversampleBits.Reset(0);
|
||||
voltage.Reset(0.0);
|
||||
}
|
||||
|
||||
@@ -37,8 +35,6 @@ HAL_SimDeviceHandle HALSIM_GetAnalogInSimDevice(int32_t index) {
|
||||
SimAnalogInData, LOWERNAME)
|
||||
|
||||
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
|
||||
DEFINE_CAPI(int32_t, AverageBits, averageBits)
|
||||
DEFINE_CAPI(int32_t, OversampleBits, oversampleBits)
|
||||
DEFINE_CAPI(double, Voltage, voltage)
|
||||
|
||||
#define REGISTER(NAME) \
|
||||
@@ -48,8 +44,6 @@ void HALSIM_RegisterAnalogInAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {
|
||||
REGISTER(initialized);
|
||||
REGISTER(averageBits);
|
||||
REGISTER(oversampleBits);
|
||||
REGISTER(voltage);
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -11,16 +11,12 @@
|
||||
namespace wpi::hal {
|
||||
class AnalogInData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(AverageBits)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(OversampleBits)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
|
||||
|
||||
public:
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
|
||||
false};
|
||||
std::atomic<HAL_SimDeviceHandle> simDevice;
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetAverageBitsName> averageBits{7};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetOversampleBitsName> oversampleBits{0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetVoltageName> voltage{0.0};
|
||||
|
||||
virtual void ResetData();
|
||||
|
||||
Reference in New Issue
Block a user