Browse Source

⏪️ Revert MAX31865 recent changes (#22660)

ellensp 3 years ago
parent
commit
66ded801b7
No account linked to committer's email address

+ 3
- 3
Marlin/src/inc/Conditionals_post.h View File

@@ -755,13 +755,13 @@
755 755
   // to select a USER library for MAX6675, MAX31855, MAX31865
756 756
   //
757 757
   #if BOTH(HAS_MAX6675, LIB_MAX6675)
758
-    #define LIB_USR_MAX6675 1
758
+    #define USE_LIB_MAX6675 1
759 759
   #endif
760 760
   #if BOTH(HAS_MAX31855, LIB_MAX31855)
761
-    #define LIB_USR_MAX31855 1
761
+    #define USE_ADAFRUIT_MAX31855 1
762 762
   #endif
763 763
   #if BOTH(HAS_MAX31865, LIB_MAX31865)
764
-    #define LIB_USR_MAX31865 1
764
+    #define USE_ADAFRUIT_MAX31865 1
765 765
   #elif HAS_MAX31865
766 766
     #define LIB_INTERNAL_MAX31865 1
767 767
   #endif

+ 23
- 15
Marlin/src/libs/MAX31865.cpp View File

@@ -44,12 +44,11 @@
44 44
 //#define MAX31865_DEBUG
45 45
 //#define MAX31865_DEBUG_SPI
46 46
 
47
-#include <SoftwareSPI.h>
48
-
49 47
 #include "../inc/MarlinConfig.h"
50 48
 
51
-#if HAS_MAX31865 && !LIB_USR_MAX31865
49
+#if HAS_MAX31865 && !USE_ADAFRUIT_MAX31865
52 50
 
51
+//#include <SoftwareSPI.h> // TODO: switch to SPIclass/SoftSPI
53 52
 #include "MAX31865.h"
54 53
 
55 54
 // The maximum speed the MAX31865 can do is 5 MHz
@@ -62,7 +61,7 @@ SPISettings MAX31865::spiConfig = SPISettings(
62 61
     500000
63 62
   #endif
64 63
   , MSBFIRST
65
-  , SPI_MODE1 // CPOL0 CPHA1
64
+  , SPI_MODE_1 // CPOL0 CPHA1
66 65
 );
67 66
 
68 67
 #ifndef LARGE_PINMAP
@@ -153,15 +152,17 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
153 152
   OUT_WRITE(_cs, HIGH);
154 153
 
155 154
   if (_sclk != TERN(LARGE_PINMAP, -1UL, -1)) {
156
-    // define pin modes for Software SPI
155
+    // Define pin modes for Software SPI
157 156
     #ifdef MAX31865_DEBUG
158 157
       SERIAL_ECHOLN("Initializing MAX31865 Software SPI");
159 158
     #endif
160
-    
161
-    swSpiBegin(_sclk, _miso, _mosi);
162
-    
163
-  } else {
164
-    // start and configure hardware SPI
159
+
160
+    OUT_WRITE(_sclk, LOW);
161
+    SET_OUTPUT(_mosi);
162
+    SET_INPUT(_miso);
163
+  }
164
+  else {
165
+    // Start and configure hardware SPI
165 166
     #ifdef MAX31865_DEBUG
166 167
       SERIAL_ECHOLN("Initializing MAX31865 Hardware SPI");
167 168
     #endif
@@ -169,9 +170,6 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
169 170
     SPI.begin();
170 171
   }
171 172
 
172
-  // SPI Begin must be called first, then init
173
-  _spi_speed = swSpiInit(SPI_QUARTER_SPEED, _sclk, _mosi);
174
-
175 173
   setWires(wires);
176 174
   enableBias(false);
177 175
   autoConvert(false);
@@ -486,7 +484,17 @@ uint8_t MAX31865::spixfer(uint8_t x) {
486 484
   if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
487 485
     return SPI.transfer(x);
488 486
 
489
-  return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi);
487
+  uint8_t reply = 0;
488
+  for (int i = 7; i >= 0; i--) {
489
+    reply <<= 1;
490
+    WRITE(_sclk, HIGH);
491
+    WRITE(_mosi, x & (1 << i));
492
+    WRITE(_sclk, LOW);
493
+    if (READ(_miso))
494
+      reply |= 1;
495
+  }
496
+
497
+  return reply;
490 498
 }
491 499
 
492
-#endif // HAS_MAX31865 && !LIB_USR_MAX31865
500
+#endif // HAS_MAX31865 && !USE_ADAFRUIT_MAX31865

+ 0
- 1
Marlin/src/libs/MAX31865.h View File

@@ -90,7 +90,6 @@ private:
90 90
   static SPISettings spiConfig;
91 91
 
92 92
   TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs;
93
-  uint8_t _spi_speed;
94 93
   float Rzero, Rref;
95 94
 
96 95
   void setConfig(uint8_t config, bool enable);

+ 3
- 3
Marlin/src/module/temperature.cpp View File

@@ -63,21 +63,21 @@
63 63
 
64 64
 // LIB_MAX6675 can be added to the build_flags in platformio.ini to use a user-defined library
65 65
 // If LIB_MAX6675 is not on the build_flags then raw SPI reads will be used.
66
-#if HAS_MAX6675 && LIB_USR_MAX6675
66
+#if HAS_MAX6675 && USE_LIB_MAX6675
67 67
   #include <max6675.h>
68 68
   #define HAS_MAX6675_LIBRARY 1
69 69
 #endif
70 70
 
71 71
 // LIB_MAX31855 can be added to the build_flags in platformio.ini to use a user-defined library.
72 72
 // If LIB_MAX31855 is not on the build_flags then raw SPI reads will be used.
73
-#if HAS_MAX31855 && LIB_USR_MAX31855
73
+#if HAS_MAX31855 && USE_ADAFRUIT_MAX31855
74 74
   #include <Adafruit_MAX31855.h>
75 75
   #define HAS_MAX31855_LIBRARY 1
76 76
   typedef Adafruit_MAX31855 MAX31855;
77 77
 #endif
78 78
 
79 79
 #if HAS_MAX31865
80
-  #if LIB_USR_MAX31865
80
+  #if USE_ADAFRUIT_MAX31865
81 81
     #include <Adafruit_MAX31865.h>
82 82
     typedef Adafruit_MAX31865 MAX31865;
83 83
   #else

Loading…
Cancel
Save