From 66ded801b734fbb597ab1c1497d347544b3aa05c Mon Sep 17 00:00:00 2001 From: ellensp <530024+ellensp@users.noreply.github.com> Date: Tue, 31 Aug 2021 15:40:49 +1200 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=EF=B8=8F=20Revert=20MAX31865=20recent?= =?UTF-8?q?=20changes=20(#22660)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/inc/Conditionals_post.h | 6 ++--- Marlin/src/libs/MAX31865.cpp | 38 ++++++++++++++++++------------ Marlin/src/libs/MAX31865.h | 1 - Marlin/src/module/temperature.cpp | 6 ++--- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index fd49aada6b..a43e57d158 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -755,13 +755,13 @@ // to select a USER library for MAX6675, MAX31855, MAX31865 // #if BOTH(HAS_MAX6675, LIB_MAX6675) - #define LIB_USR_MAX6675 1 + #define USE_LIB_MAX6675 1 #endif #if BOTH(HAS_MAX31855, LIB_MAX31855) - #define LIB_USR_MAX31855 1 + #define USE_ADAFRUIT_MAX31855 1 #endif #if BOTH(HAS_MAX31865, LIB_MAX31865) - #define LIB_USR_MAX31865 1 + #define USE_ADAFRUIT_MAX31865 1 #elif HAS_MAX31865 #define LIB_INTERNAL_MAX31865 1 #endif diff --git a/Marlin/src/libs/MAX31865.cpp b/Marlin/src/libs/MAX31865.cpp index 86c31edee9..1264c6fbe8 100644 --- a/Marlin/src/libs/MAX31865.cpp +++ b/Marlin/src/libs/MAX31865.cpp @@ -44,12 +44,11 @@ //#define MAX31865_DEBUG //#define MAX31865_DEBUG_SPI -#include - #include "../inc/MarlinConfig.h" -#if HAS_MAX31865 && !LIB_USR_MAX31865 +#if HAS_MAX31865 && !USE_ADAFRUIT_MAX31865 +//#include // TODO: switch to SPIclass/SoftSPI #include "MAX31865.h" // The maximum speed the MAX31865 can do is 5 MHz @@ -62,7 +61,7 @@ SPISettings MAX31865::spiConfig = SPISettings( 500000 #endif , MSBFIRST - , SPI_MODE1 // CPOL0 CPHA1 + , SPI_MODE_1 // CPOL0 CPHA1 ); #ifndef LARGE_PINMAP @@ -153,15 +152,17 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) { OUT_WRITE(_cs, HIGH); if (_sclk != TERN(LARGE_PINMAP, -1UL, -1)) { - // define pin modes for Software SPI + // Define pin modes for Software SPI #ifdef MAX31865_DEBUG SERIAL_ECHOLN("Initializing MAX31865 Software SPI"); #endif - - swSpiBegin(_sclk, _miso, _mosi); - - } else { - // start and configure hardware SPI + + OUT_WRITE(_sclk, LOW); + SET_OUTPUT(_mosi); + SET_INPUT(_miso); + } + else { + // Start and configure hardware SPI #ifdef MAX31865_DEBUG SERIAL_ECHOLN("Initializing MAX31865 Hardware SPI"); #endif @@ -169,9 +170,6 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) { SPI.begin(); } - // SPI Begin must be called first, then init - _spi_speed = swSpiInit(SPI_QUARTER_SPEED, _sclk, _mosi); - setWires(wires); enableBias(false); autoConvert(false); @@ -486,7 +484,17 @@ uint8_t MAX31865::spixfer(uint8_t x) { if (_sclk == TERN(LARGE_PINMAP, -1UL, -1)) return SPI.transfer(x); - return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi); + uint8_t reply = 0; + 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 && !USE_ADAFRUIT_MAX31865 diff --git a/Marlin/src/libs/MAX31865.h b/Marlin/src/libs/MAX31865.h index 13a117447d..5d50e870ec 100644 --- a/Marlin/src/libs/MAX31865.h +++ b/Marlin/src/libs/MAX31865.h @@ -90,7 +90,6 @@ private: static SPISettings spiConfig; TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs; - uint8_t _spi_speed; float Rzero, Rref; void setConfig(uint8_t config, bool enable); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 0475db486c..935de772f4 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -63,21 +63,21 @@ // LIB_MAX6675 can be added to the build_flags in platformio.ini to use a user-defined library // If LIB_MAX6675 is not on the build_flags then raw SPI reads will be used. -#if HAS_MAX6675 && LIB_USR_MAX6675 +#if HAS_MAX6675 && USE_LIB_MAX6675 #include #define HAS_MAX6675_LIBRARY 1 #endif // LIB_MAX31855 can be added to the build_flags in platformio.ini to use a user-defined library. // If LIB_MAX31855 is not on the build_flags then raw SPI reads will be used. -#if HAS_MAX31855 && LIB_USR_MAX31855 +#if HAS_MAX31855 && USE_ADAFRUIT_MAX31855 #include #define HAS_MAX31855_LIBRARY 1 typedef Adafruit_MAX31855 MAX31855; #endif #if HAS_MAX31865 - #if LIB_USR_MAX31865 + #if USE_ADAFRUIT_MAX31865 #include typedef Adafruit_MAX31865 MAX31865; #else