Browse Source

🎨 Rename MAX31865 elements

Scott Lahteine 3 years ago
parent
commit
0a64209305
2 changed files with 64 additions and 64 deletions
  1. 58
    58
      Marlin/src/libs/MAX31865.cpp
  2. 6
    6
      Marlin/src/libs/MAX31865.h

+ 58
- 58
Marlin/src/libs/MAX31865.cpp View File

73
    * @param spi_clk   the SPI clock pin to use
73
    * @param spi_clk   the SPI clock pin to use
74
   */
74
   */
75
   MAX31865::MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk) {
75
   MAX31865::MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk) {
76
-    _cs = spi_cs;
77
-    _mosi = spi_mosi;
78
-    _miso = spi_miso;
79
-    _sclk = spi_clk;
76
+    cselPin = spi_cs;
77
+    mosiPin = spi_mosi;
78
+    misoPin = spi_miso;
79
+    sclkPin = spi_clk;
80
   }
80
   }
81
 
81
 
82
   /**
82
   /**
86
    * @param spi_cs  the SPI CS pin to use along with the default SPI device
86
    * @param spi_cs  the SPI CS pin to use along with the default SPI device
87
    */
87
    */
88
   MAX31865::MAX31865(int8_t spi_cs) {
88
   MAX31865::MAX31865(int8_t spi_cs) {
89
-    _cs = spi_cs;
90
-    _sclk = _miso = _mosi = -1;
89
+    cselPin = spi_cs;
90
+    sclkPin = misoPin = mosiPin = -1;
91
   }
91
   }
92
 
92
 
93
 #else // LARGE_PINMAP
93
 #else // LARGE_PINMAP
104
    * @param pin_mapping  set to 1 for positive pin values
104
    * @param pin_mapping  set to 1 for positive pin values
105
    */
105
    */
106
   MAX31865::MAX31865(uint32_t spi_cs, uint32_t spi_mosi, uint32_t spi_miso, uint32_t spi_clk, uint8_t pin_mapping) {
106
   MAX31865::MAX31865(uint32_t spi_cs, uint32_t spi_mosi, uint32_t spi_miso, uint32_t spi_clk, uint8_t pin_mapping) {
107
-    _cs = spi_cs;
108
-    _mosi = spi_mosi;
109
-    _miso = spi_miso;
110
-    _sclk = spi_clk;
107
+    cselPin = spi_cs;
108
+    mosiPin = spi_mosi;
109
+    misoPin = spi_miso;
110
+    sclkPin = spi_clk;
111
   }
111
   }
112
 
112
 
113
   /**
113
   /**
119
    * @param pin_mapping  set to 1 for positive pin values
119
    * @param pin_mapping  set to 1 for positive pin values
120
    */
120
    */
121
   MAX31865::MAX31865(uint32_t spi_cs, uint8_t pin_mapping) {
121
   MAX31865::MAX31865(uint32_t spi_cs, uint8_t pin_mapping) {
122
-    _cs = spi_cs;
123
-    _sclk = _miso = _mosi = -1UL;  //-1UL or 0xFFFFFFFF or 4294967295
122
+    cselPin = spi_cs;
123
+    sclkPin = misoPin = mosiPin = -1UL;  //-1UL or 0xFFFFFFFF or 4294967295
124
   }
124
   }
125
 
125
 
126
 #endif // LARGE_PINMAP
126
 #endif // LARGE_PINMAP
139
  * @param ref    The resistance of the reference resistor, in ohms.
139
  * @param ref    The resistance of the reference resistor, in ohms.
140
  */
140
  */
141
 void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
141
 void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
142
-  Rzero = zero;
143
-  Rref = ref;
142
+  zeroRes = zero;
143
+  refRes = ref;
144
 
144
 
145
-  OUT_WRITE(_cs, HIGH);
145
+  OUT_WRITE(cselPin, HIGH);
146
 
146
 
147
-  if (_sclk != TERN(LARGE_PINMAP, -1UL, -1)) {
147
+  if (sclkPin != TERN(LARGE_PINMAP, -1UL, -1)) {
148
     softSpiBegin(SPI_QUARTER_SPEED); // Define pin modes for Software SPI
148
     softSpiBegin(SPI_QUARTER_SPEED); // Define pin modes for Software SPI
149
   }
149
   }
150
   else {
150
   else {
162
   #ifdef MAX31865_DEBUG_SPI
162
   #ifdef MAX31865_DEBUG_SPI
163
     SERIAL_ECHOLNPGM(
163
     SERIAL_ECHOLNPGM(
164
       TERN(LARGE_PINMAP, "LARGE_PINMAP", "Regular")
164
       TERN(LARGE_PINMAP, "LARGE_PINMAP", "Regular")
165
-      " begin call with _cs: ", _cs,
166
-      " _miso: ", _miso,
167
-      " _sclk: ", _sclk,
168
-      " _mosi: ", _mosi,
165
+      " begin call with cselPin: ", cselPin,
166
+      " misoPin: ", misoPin,
167
+      " sclkPin: ", sclkPin,
168
+      " mosiPin: ", mosiPin,
169
       " config: ", readRegister8(MAX31865_CONFIG_REG)
169
       " config: ", readRegister8(MAX31865_CONFIG_REG)
170
     );
170
     );
171
   #endif
171
   #endif
282
  */
282
  */
283
 float MAX31865::readResistance() {
283
 float MAX31865::readResistance() {
284
   // Strip the error bit (D0) and convert to a float ratio.
284
   // Strip the error bit (D0) and convert to a float ratio.
285
-  // less precise method: (readRaw() * Rref) >> 16
286
-  return (((readRaw() >> 1) / 32768.0f) * Rref);
285
+  // less precise method: (readRaw() * refRes) >> 16
286
+  return (((readRaw() >> 1) / 32768.0f) * refRes);
287
 }
287
 }
288
 
288
 
289
 /**
289
 /**
300
  *
300
  *
301
  * @return  Temperature in C
301
  * @return  Temperature in C
302
  */
302
  */
303
-float MAX31865::temperature(uint16_t adcVal) {
304
-  return temperature(((adcVal) / 32768.0f) * Rref);
303
+float MAX31865::temperature(uint16_t adc_val) {
304
+  return temperature(((adc_val) / 32768.0f) * refRes);
305
 }
305
 }
306
 
306
 
307
 /**
307
 /**
309
  * Uses the technique outlined in this PDF:
309
  * Uses the technique outlined in this PDF:
310
  * http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
310
  * http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
311
  *
311
  *
312
- * @param    Rrtd  the resistance value in ohms
313
- * @return         the temperature in degC
312
+ * @param    rtd_res  the resistance value in ohms
313
+ * @return            the temperature in degC
314
  */
314
  */
315
-float MAX31865::temperature(float Rrtd) {
316
-  float temp = (RTD_Z1 + sqrt(RTD_Z2 + (RTD_Z3 * Rrtd))) / RTD_Z4;
315
+float MAX31865::temperature(float rtd_res) {
316
+  float temp = (RTD_Z1 + sqrt(RTD_Z2 + (RTD_Z3 * rtd_res))) * RECIPROCAL(RTD_Z4);
317
 
317
 
318
   // From the PDF...
318
   // From the PDF...
319
   //
319
   //
324
   // of resistance.
324
   // of resistance.
325
   //
325
   //
326
   if (temp < 0) {
326
   if (temp < 0) {
327
-    Rrtd = (Rrtd / Rzero) * 100; // normalize to 100 ohm
328
-    float rpoly = Rrtd;
327
+    rtd_res = (rtd_res / zeroRes) * 100; // normalize to 100 ohm
328
+    float rpoly = rtd_res;
329
 
329
 
330
     temp = -242.02 + (2.2228 * rpoly);
330
     temp = -242.02 + (2.2228 * rpoly);
331
-    rpoly *= Rrtd; // square
331
+    rpoly *= rtd_res; // square
332
     temp += 2.5859e-3 * rpoly;
332
     temp += 2.5859e-3 * rpoly;
333
-    rpoly *= Rrtd; // ^3
333
+    rpoly *= rtd_res; // ^3
334
     temp -= 4.8260e-6 * rpoly;
334
     temp -= 4.8260e-6 * rpoly;
335
-    rpoly *= Rrtd; // ^4
335
+    rpoly *= rtd_res; // ^4
336
     temp -= 2.8183e-8 * rpoly;
336
     temp -= 2.8183e-8 * rpoly;
337
-    rpoly *= Rrtd; // ^5
337
+    rpoly *= rtd_res; // ^5
338
     temp += 1.5243e-10 * rpoly;
338
     temp += 1.5243e-10 * rpoly;
339
   }
339
   }
340
 
340
 
399
  */
399
  */
400
 void MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
400
 void MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
401
   addr &= 0x7F; // make sure top bit is not set
401
   addr &= 0x7F; // make sure top bit is not set
402
-  if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
402
+  if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
403
     SPI.beginTransaction(spiConfig);
403
     SPI.beginTransaction(spiConfig);
404
   else
404
   else
405
-    WRITE(_sclk, LOW);
405
+    WRITE(sclkPin, LOW);
406
 
406
 
407
-  WRITE(_cs, LOW);
407
+  WRITE(cselPin, LOW);
408
 
408
 
409
   #ifdef TARGET_LPC1768
409
   #ifdef TARGET_LPC1768
410
-    DELAY_CYCLES(_spi_speed);
410
+    DELAY_CYCLES(spiSpeed);
411
   #endif
411
   #endif
412
 
412
 
413
   spiTransfer(addr);
413
   spiTransfer(addr);
420
     buffer++;
420
     buffer++;
421
   }
421
   }
422
 
422
 
423
-  if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
423
+  if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
424
     SPI.endTransaction();
424
     SPI.endTransaction();
425
 
425
 
426
-  WRITE(_cs, HIGH);
426
+  WRITE(cselPin, HIGH);
427
 }
427
 }
428
 
428
 
429
 /**
429
 /**
433
  * @param data  the data to write
433
  * @param data  the data to write
434
  */
434
  */
435
 void MAX31865::writeRegister8(uint8_t addr, uint8_t data) {
435
 void MAX31865::writeRegister8(uint8_t addr, uint8_t data) {
436
-  if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
436
+  if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
437
     SPI.beginTransaction(spiConfig);
437
     SPI.beginTransaction(spiConfig);
438
   else
438
   else
439
-    WRITE(_sclk, LOW);
439
+    WRITE(sclkPin, LOW);
440
 
440
 
441
-  WRITE(_cs, LOW);
441
+  WRITE(cselPin, LOW);
442
 
442
 
443
   #ifdef TARGET_LPC1768
443
   #ifdef TARGET_LPC1768
444
-    DELAY_CYCLES(_spi_speed);
444
+    DELAY_CYCLES(spiSpeed);
445
   #endif
445
   #endif
446
 
446
 
447
   spiTransfer(addr | 0x80); // make sure top bit is set
447
   spiTransfer(addr | 0x80); // make sure top bit is set
448
   spiTransfer(data);
448
   spiTransfer(data);
449
 
449
 
450
-  if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
450
+  if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
451
     SPI.endTransaction();
451
     SPI.endTransaction();
452
 
452
 
453
-  WRITE(_cs, HIGH);
453
+  WRITE(cselPin, HIGH);
454
 }
454
 }
455
 
455
 
456
 /**
456
 /**
463
  * @return    the 8-bit response
463
  * @return    the 8-bit response
464
  */
464
  */
465
 uint8_t MAX31865::spiTransfer(uint8_t x) {
465
 uint8_t MAX31865::spiTransfer(uint8_t x) {
466
-  if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
466
+  if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
467
     return SPI.transfer(x);
467
     return SPI.transfer(x);
468
 
468
 
469
   #ifdef TARGET_LPC1768
469
   #ifdef TARGET_LPC1768
470
-    return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi);
470
+    return swSpiTransfer(x, spiSpeed, sclkPin, misoPin, mosiPin);
471
   #else
471
   #else
472
     uint8_t reply = 0;
472
     uint8_t reply = 0;
473
     for (int i = 7; i >= 0; i--) {
473
     for (int i = 7; i >= 0; i--) {
474
-      WRITE(_sclk, HIGH);           DELAY_NS_VAR(_spi_delay);
474
+      WRITE(sclkPin, HIGH);         DELAY_NS_VAR(spiDelay);
475
       reply <<= 1;
475
       reply <<= 1;
476
-      WRITE(_mosi, x & _BV(i));     DELAY_NS_VAR(_spi_delay);
477
-      if (READ(_miso)) reply |= 1;
478
-      WRITE(_sclk, LOW);            DELAY_NS_VAR(_spi_delay);
476
+      WRITE(mosiPin, x & _BV(i));   DELAY_NS_VAR(spiDelay);
477
+      if (READ(misoPin)) reply |= 1;
478
+      WRITE(sclkPin, LOW);          DELAY_NS_VAR(spiDelay);
479
     }
479
     }
480
     return reply;
480
     return reply;
481
   #endif
481
   #endif
486
     SERIAL_ECHOLNPGM("Initializing MAX31865 Software SPI");
486
     SERIAL_ECHOLNPGM("Initializing MAX31865 Software SPI");
487
   #endif
487
   #endif
488
   #ifdef TARGET_LPC1768
488
   #ifdef TARGET_LPC1768
489
-    swSpiBegin(_sclk, _miso, _mosi);
490
-    _spi_speed = swSpiInit(spi_speed, _sclk, _mosi);
489
+    swSpiBegin(sclkPin, misoPin, mosiPin);
490
+    spiSpeed = swSpiInit(spi_speed, sclkPin, mosiPin);
491
   #else
491
   #else
492
-    _spi_delay = (100UL << spi_speed) / 3; // Calculate delay in ns. Top speed is ~10MHz, or 100ns delay between bits.
493
-    OUT_WRITE(_sclk, LOW);
494
-    SET_OUTPUT(_mosi);
495
-    SET_INPUT(_miso);
492
+    spiDelay = (100UL << spi_speed) / 3; // Calculate delay in ns. Top speed is ~10MHz, or 100ns delay between bits.
493
+    OUT_WRITE(sclkPin, LOW);
494
+    SET_OUTPUT(mosiPin);
495
+    SET_INPUT(misoPin);
496
   #endif
496
   #endif
497
 }
497
 }
498
 
498
 

+ 6
- 6
Marlin/src/libs/MAX31865.h View File

89
 private:
89
 private:
90
   static SPISettings spiConfig;
90
   static SPISettings spiConfig;
91
 
91
 
92
-  TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs;
92
+  TERN(LARGE_PINMAP, uint32_t, uint8_t) sclkPin, misoPin, mosiPin, cselPin;
93
 
93
 
94
   #ifdef TARGET_LPC1768
94
   #ifdef TARGET_LPC1768
95
-    uint8_t _spi_speed;
95
+    uint8_t spiSpeed;
96
   #else
96
   #else
97
-    uint16_t _spi_delay;
97
+    uint16_t spiDelay;
98
   #endif
98
   #endif
99
 
99
 
100
-  float Rzero, Rref;
100
+  float zeroRes, refRes;
101
 
101
 
102
   void setConfig(uint8_t config, bool enable);
102
   void setConfig(uint8_t config, bool enable);
103
 
103
 
135
   uint16_t readRaw();
135
   uint16_t readRaw();
136
   float readResistance();
136
   float readResistance();
137
   float temperature();
137
   float temperature();
138
-  float temperature(uint16_t adcVal);
139
-  float temperature(float Rrtd);
138
+  float temperature(uint16_t adc_val);
139
+  float temperature(float rtd_res);
140
 };
140
 };

Loading…
Cancel
Save