1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-31 10:01:48 +02:00

Added synchronousWrite() for Pins

Needed for the SPI CS pin.
This commit is contained in:
Mitch Bradley
2021-07-01 22:16:00 -10:00
parent 4201c178db
commit 96b0f93872
7 changed files with 25 additions and 13 deletions

View File

@@ -54,10 +54,10 @@ void TMC2130Stepper::switchCSpin(bool state) {
// We use the _pinCS to figure out which derived class we have
switch (this->_pinCS) {
case 2130:
static_cast<Motors::Details::MyTMC2130Stepper*>(this)->_cspin.write(state);
static_cast<Motors::Details::MyTMC2130Stepper*>(this)->_cspin.synchronousWrite(state);
break;
case 5160:
static_cast<Motors::Details::MyTMC5160Stepper*>(this)->_cspin.write(state);
static_cast<Motors::Details::MyTMC5160Stepper*>(this)->_cspin.synchronousWrite(state);
break;
}
}

View File

@@ -125,6 +125,7 @@ public:
}
inline void write(bool value) const { _detail->write(value); }
inline void synchronousWrite(bool value) const { _detail->synchronousWrite(value); }
inline bool read() const { return _detail->read() != 0; }

View File

@@ -4,9 +4,9 @@
#include <Arduino.h>
// Pin mapping. Pretty straight forward, it's just a thing that stores pins in an array.
//
// The default behavior of a mapped pin is _undefined pin_, so it does nothing.
// Pin mapping. Pretty straight forward, it's just a thing that stores pins in an array.
//
// The default behavior of a mapped pin is _undefined pin_, so it does nothing.
namespace {
class Mapping {
public:
@@ -44,7 +44,7 @@ PinMapper::PinMapper() : _mappedId(0) {}
PinMapper::PinMapper(Pin& pin) {
_mappedId = Mapping::instance().Claim(&pin);
// If you reach this assertion, you haven't been using the Pin class like you're supposed to.
Assert(_mappedId != 0, "Cannot claim pin. We've reached the limit of 255 mapped pins.");
}
@@ -77,7 +77,7 @@ PinMapper::~PinMapper() {
void IRAM_ATTR digitalWrite(uint8_t pin, uint8_t val) {
auto thePin = Mapping::instance()._mapping[pin];
if (thePin) {
thePin->write(val);
thePin->synchronousWrite(val);
}
}

View File

@@ -50,11 +50,19 @@ namespace Pins {
PinCapabilities I2SOPinDetail::capabilities() const { return PinCapabilities::Output | PinCapabilities::I2S; }
void I2SOPinDetail::write(int high) {
// The write will not happen immediately; the data is queued for
// delivery to the serial shift register chain via DMA and a FIFO
void IRAM_ATTR I2SOPinDetail::write(int high) {
int value = _readWriteMask ^ high;
i2s_out_write(_index, value);
}
// Write and wait for completion. Not suitable for use from an ISR
void I2SOPinDetail::synchronousWrite(int high) {
write(high);
i2s_out_delay();
}
int I2SOPinDetail::read() {
auto raw = i2s_out_read(_index);
return raw ^ _readWriteMask;

View File

@@ -37,6 +37,7 @@ namespace Pins {
// I/O:
void write(int high) override;
void synchronousWrite(int high) override;
int read() override;
void setAttr(PinAttributes value) override;
PinAttributes getAttr() const override;

View File

@@ -44,7 +44,8 @@ namespace Pins {
virtual PinCapabilities capabilities() const = 0;
// I/O:
virtual void write(int high) = 0;
virtual void write(int high) = 0;
virtual void synchronousWrite(int high) { write(high); }
virtual int read() = 0;
virtual void setAttr(PinAttributes value) = 0;
virtual PinAttributes getAttr() const = 0;

View File

@@ -16,6 +16,7 @@
along with Grbl_ESP32. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Arduino.h> // IRAM_ATTR
#include "VoidPinDetail.h"
namespace Pins {
@@ -27,10 +28,10 @@ namespace Pins {
return PinCapabilities::Output | PinCapabilities::Input | PinCapabilities::ISR | PinCapabilities::Void;
}
void VoidPinDetail::write(int high) {}
int VoidPinDetail::read() { return 0; }
void VoidPinDetail::setAttr(PinAttributes value) {}
PinAttributes VoidPinDetail::getAttr() const { return PinAttributes::None; }
void IRAM_ATTR VoidPinDetail::write(int high) {}
int VoidPinDetail::read() { return 0; }
void VoidPinDetail::setAttr(PinAttributes value) {}
PinAttributes VoidPinDetail::getAttr() const { return PinAttributes::None; }
String VoidPinDetail::toString() { return "NO_PIN"; }