mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[hal] Add support for DMA to Java (#3158)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <hal/Types.h>
|
||||
#include <units/time.h>
|
||||
|
||||
namespace frc {
|
||||
class Encoder;
|
||||
@@ -13,6 +14,8 @@ class DigitalSource;
|
||||
class DutyCycle;
|
||||
class AnalogInput;
|
||||
class DMASample;
|
||||
class PWM;
|
||||
class PWMMotorController;
|
||||
|
||||
class DMA {
|
||||
friend class DMASample;
|
||||
@@ -25,7 +28,8 @@ class DMA {
|
||||
DMA(DMA&& other) = default;
|
||||
|
||||
void SetPause(bool pause);
|
||||
void SetRate(int cycles);
|
||||
void SetTimedTrigger(units::second_t seconds);
|
||||
void SetTimedTriggerCycles(int cycles);
|
||||
|
||||
void AddEncoder(const Encoder* encoder);
|
||||
void AddEncoderPeriod(const Encoder* encoder);
|
||||
@@ -41,10 +45,15 @@ class DMA {
|
||||
void AddAveragedAnalogInput(const AnalogInput* analogInput);
|
||||
void AddAnalogAccumulator(const AnalogInput* analogInput);
|
||||
|
||||
void SetExternalTrigger(DigitalSource* source, bool rising, bool falling);
|
||||
int SetExternalTrigger(DigitalSource* source, bool rising, bool falling);
|
||||
int SetPwmEdgeTrigger(PWM* pwm, bool rising, bool falling);
|
||||
int SetPwmEdgeTrigger(PWMMotorController* pwm, bool rising, bool falling);
|
||||
|
||||
void StartDMA(int queueDepth);
|
||||
void StopDMA();
|
||||
void ClearSensors();
|
||||
void ClearExternalTriggers();
|
||||
|
||||
void Start(int queueDepth);
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
hal::Handle<HAL_DMAHandle> dmaHandle;
|
||||
|
||||
@@ -19,11 +19,16 @@
|
||||
namespace frc {
|
||||
class DMASample : public HAL_DMASample {
|
||||
public:
|
||||
HAL_DMAReadStatus Update(const DMA* dma, units::second_t timeout,
|
||||
int32_t* remaining, int32_t* status) {
|
||||
units::millisecond_t ms = timeout;
|
||||
auto timeoutMs = ms.to<int32_t>();
|
||||
return HAL_ReadDMA(dma->dmaHandle, this, timeoutMs, remaining, status);
|
||||
enum class DMAReadStatus {
|
||||
kOk = HAL_DMA_OK,
|
||||
kTimeout = HAL_DMA_TIMEOUT,
|
||||
kError = HAL_DMA_ERROR
|
||||
};
|
||||
|
||||
DMAReadStatus Update(const DMA* dma, units::second_t timeout,
|
||||
int32_t* remaining, int32_t* status) {
|
||||
return static_cast<DMAReadStatus>(HAL_ReadDMA(
|
||||
dma->dmaHandle, this, timeout.to<double>(), remaining, status));
|
||||
}
|
||||
|
||||
uint64_t GetTime() const { return timeStamp; }
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
namespace frc {
|
||||
class AddressableLED;
|
||||
class DMA;
|
||||
|
||||
/**
|
||||
* Class implements the PWM generation in the FPGA.
|
||||
@@ -33,6 +34,7 @@ class AddressableLED;
|
||||
class PWM : public wpi::Sendable, public wpi::SendableHelper<PWM> {
|
||||
public:
|
||||
friend class AddressableLED;
|
||||
friend class DMA;
|
||||
/**
|
||||
* Represents the amount to multiply the minimum servo-pulse pwm period by.
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "frc/motorcontrol/MotorController.h"
|
||||
|
||||
namespace frc {
|
||||
class DMA;
|
||||
|
||||
/**
|
||||
* Common base class for all PWM Motor Controllers.
|
||||
@@ -24,6 +25,8 @@ class PWMMotorController : public MotorController,
|
||||
public wpi::Sendable,
|
||||
public wpi::SendableHelper<PWMMotorController> {
|
||||
public:
|
||||
friend class DMA;
|
||||
|
||||
PWMMotorController(PWMMotorController&&) = default;
|
||||
PWMMotorController& operator=(PWMMotorController&&) = default;
|
||||
|
||||
@@ -74,6 +77,8 @@ class PWMMotorController : public MotorController,
|
||||
|
||||
private:
|
||||
bool m_isInverted = false;
|
||||
|
||||
PWM* GetPwm() { return &m_pwm; }
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user