🩹 Use <SoftwareSPI.h> in MAX31865 lib (#22618)
This commit is contained in:
parent
125c5bc345
commit
a0ebe7c8ff
@ -44,7 +44,7 @@
|
|||||||
//#define MAX31865_DEBUG
|
//#define MAX31865_DEBUG
|
||||||
//#define MAX31865_DEBUG_SPI
|
//#define MAX31865_DEBUG_SPI
|
||||||
|
|
||||||
//TODO: switch to SPIclass/SoftSPI
|
#include <SoftwareSPI.h>
|
||||||
|
|
||||||
#include "../inc/MarlinConfig.h"
|
#include "../inc/MarlinConfig.h"
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
|||||||
500000
|
500000
|
||||||
#endif
|
#endif
|
||||||
, MSBFIRST
|
, MSBFIRST
|
||||||
, SPI_MODE_1 // CPOL0 CPHA1
|
, SPI_MODE1 // CPOL0 CPHA1
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifndef LARGE_PINMAP
|
#ifndef LARGE_PINMAP
|
||||||
@ -158,9 +158,8 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
|||||||
SERIAL_ECHOLN("Initializing MAX31865 Software SPI");
|
SERIAL_ECHOLN("Initializing MAX31865 Software SPI");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OUT_WRITE(_sclk, LOW);
|
swSpiBegin(_sclk, _miso, _mosi);
|
||||||
SET_OUTPUT(_mosi);
|
|
||||||
SET_INPUT(_miso);
|
|
||||||
} else {
|
} else {
|
||||||
// start and configure hardware SPI
|
// start and configure hardware SPI
|
||||||
#ifdef MAX31865_DEBUG
|
#ifdef MAX31865_DEBUG
|
||||||
@ -170,6 +169,9 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
|||||||
SPI.begin();
|
SPI.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPI Begin must be called first, then init
|
||||||
|
_spi_speed = swSpiInit(SPI_QUARTER_SPEED, _sclk, _mosi);
|
||||||
|
|
||||||
setWires(wires);
|
setWires(wires);
|
||||||
enableBias(false);
|
enableBias(false);
|
||||||
autoConvert(false);
|
autoConvert(false);
|
||||||
@ -484,17 +486,7 @@ uint8_t MAX31865::spixfer(uint8_t x) {
|
|||||||
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
||||||
return SPI.transfer(x);
|
return SPI.transfer(x);
|
||||||
|
|
||||||
uint8_t reply = 0;
|
return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi);
|
||||||
for (int i = 7; i >= 0; i--) {
|
|
||||||
reply <<= 1;
|
|
||||||
WRITE(_sclk, HIGH);
|
|
||||||
WRITE(_mosi, x & (1 << i));
|
|
||||||
WRITE(_sclk, LOW);
|
|
||||||
if (READ(_miso))
|
|
||||||
reply |= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAS_MAX31865 && !LIB_USR_MAX31865
|
#endif // HAS_MAX31865 && !LIB_USR_MAX31865
|
||||||
|
@ -90,6 +90,7 @@ private:
|
|||||||
static SPISettings spiConfig;
|
static SPISettings spiConfig;
|
||||||
|
|
||||||
TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs;
|
TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs;
|
||||||
|
uint8_t _spi_speed;
|
||||||
float Rzero, Rref;
|
float Rzero, Rref;
|
||||||
|
|
||||||
void setConfig(uint8_t config, bool enable);
|
void setConfig(uint8_t config, bool enable);
|
||||||
|
Loading…
Reference in New Issue
Block a user