Makes SPI edge changes more obvious (#1056)

Rising and Falling mean the opposite when active is set high vs low. Leading and trailing makes much more sense.

Closes #925
This commit is contained in:
Thad House
2018-05-14 18:16:36 -07:00
committed by Peter Johnson
parent 560123ab7d
commit ab70220ecf
9 changed files with 57 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ ADXL345_SPI::ADXL345_SPI(SPI::Port port, ADXL345_SPI::Range range)
: m_spi(port) {
m_spi.SetClockRate(500000);
m_spi.SetMSBFirst();
m_spi.SetSampleDataOnFalling();
m_spi.SetSampleDataOnTrailingEdge();
m_spi.SetClockActiveLow();
m_spi.SetChipSelectActiveHigh();

View File

@@ -47,7 +47,7 @@ ADXL362::ADXL362(Range range) : ADXL362(SPI::Port::kOnboardCS1, range) {}
ADXL362::ADXL362(SPI::Port port, Range range) : m_spi(port) {
m_spi.SetClockRate(3000000);
m_spi.SetMSBFirst();
m_spi.SetSampleDataOnFalling();
m_spi.SetSampleDataOnTrailingEdge();
m_spi.SetClockActiveLow();
m_spi.SetChipSelectActiveLow();

View File

@@ -64,7 +64,7 @@ ADXRS450_Gyro::ADXRS450_Gyro() : ADXRS450_Gyro(SPI::kOnboardCS0) {}
ADXRS450_Gyro::ADXRS450_Gyro(SPI::Port port) : m_spi(port) {
m_spi.SetClockRate(3000000);
m_spi.SetMSBFirst();
m_spi.SetSampleDataOnRising();
m_spi.SetSampleDataOnLeadingEdge();
m_spi.SetClockActiveHigh();
m_spi.SetChipSelectActiveLow();

View File

@@ -174,6 +174,24 @@ void SPI::SetLSBFirst() {
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
}
/**
* Configure that the data is stable on the leading edge and the data
* changes on the trailing edge.
*/
void SPI::SetSampleDataOnLeadingEdge() {
m_sampleOnTrailing = false;
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
}
/**
* Configure that the data is stable on the trailing edge and the data
* changes on the leading edge.
*/
void SPI::SetSampleDataOnTrailingEdge() {
m_sampleOnTrailing = true;
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
}
/**
* Configure that the data is stable on the falling edge and the data
* changes on the rising edge.

View File

@@ -12,6 +12,7 @@
#include <memory>
#include <wpi/ArrayRef.h>
#include <wpi/deprecated.h>
#include "ErrorBase.h"
@@ -43,7 +44,12 @@ class SPI : public ErrorBase {
void SetMSBFirst();
void SetLSBFirst();
void SetSampleDataOnLeadingEdge();
void SetSampleDataOnTrailingEdge();
WPI_DEPRECATED("Use SetSampleDataOnTrailingEdge in most cases.")
void SetSampleDataOnFalling();
WPI_DEPRECATED("Use SetSampleDataOnLeadingEdge in most cases")
void SetSampleDataOnRising();
void SetClockActiveLow();

View File

@@ -92,7 +92,7 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer, Sendable {
private void init(Range range) {
m_spi.setClockRate(500000);
m_spi.setMSBFirst();
m_spi.setSampleDataOnFalling();
m_spi.setSampleDataOnTrailingEdge();
m_spi.setClockActiveLow();
m_spi.setChipSelectActiveHigh();

View File

@@ -83,7 +83,7 @@ public class ADXL362 extends SensorBase implements Accelerometer, Sendable {
m_spi.setClockRate(3000000);
m_spi.setMSBFirst();
m_spi.setSampleDataOnFalling();
m_spi.setSampleDataOnTrailingEdge();
m_spi.setClockActiveLow();
m_spi.setChipSelectActiveLow();

View File

@@ -58,7 +58,7 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, Sendable
m_spi.setClockRate(3000000);
m_spi.setMSBFirst();
m_spi.setSampleDataOnRising();
m_spi.setSampleDataOnLeadingEdge();
m_spi.setClockActiveHigh();
m_spi.setChipSelectActiveLow();

View File

@@ -107,8 +107,29 @@ public class SPI {
}
/**
* Configure that the data is stable on the falling edge and the data changes on the rising edge.
* Configure that the data is stable on the leading edge and the data changes on the trailing
* edge.
*/
public final void setSampleDataOnLeadingEdge() {
m_dataOnTrailing = 0;
SPIJNI.spiSetOpts(m_port, m_bitOrder, m_dataOnTrailing, m_clockPolarity);
}
/**
* Configure that the data is stable on the trailing edge and the data changes on the leading
* edge.
*/
public final void setSampleDataOnTrailingEdge() {
m_dataOnTrailing = 1;
SPIJNI.spiSetOpts(m_port, m_bitOrder, m_dataOnTrailing, m_clockPolarity);
}
/**
* Configure that the data is stable on the falling edge and the data changes on the rising edge.
* Note this gets reversed is setClockActiveLow is set.
* @deprecated use {@link #setSampleDataOnTrailingEdge()} in most cases.
*/
@Deprecated
public final void setSampleDataOnFalling() {
m_dataOnTrailing = 1;
SPIJNI.spiSetOpts(m_port, m_bitOrder, m_dataOnTrailing, m_clockPolarity);
@@ -116,12 +137,17 @@ public class SPI {
/**
* Configure that the data is stable on the rising edge and the data changes on the falling edge.
* Note this gets reversed is setClockActiveLow is set.
* @deprecated use {@link #setSampleDataOnLeadingEdge()} in most cases.
*/
@Deprecated
public final void setSampleDataOnRising() {
m_dataOnTrailing = 0;
SPIJNI.spiSetOpts(m_port, m_bitOrder, m_dataOnTrailing, m_clockPolarity);
}
/**
* Configure the chip select line to be active high.
*/