Browse Source

Bring SPI_SENSORLESS code up to date (#15560)

Markus Towara 5 years ago
parent
commit
437978d349
2 changed files with 11 additions and 29 deletions
  1. 5
    23
      Marlin/src/feature/tmc_util.h
  2. 6
    6
      Marlin/src/module/endstops.cpp

+ 5
- 23
Marlin/src/feature/tmc_util.h View File

393
 
393
 
394
     template<class TMC, char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
394
     template<class TMC, char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
395
     bool TMCMarlin<TMC, AXIS_LETTER, DRIVER_ID, AXIS_ID>::test_stall_status() {
395
     bool TMCMarlin<TMC, AXIS_LETTER, DRIVER_ID, AXIS_ID>::test_stall_status() {
396
-      uint16_t sg_result = 0;
397
-
398
       this->switchCSpin(LOW);
396
       this->switchCSpin(LOW);
399
 
397
 
400
-      if (this->TMC_SW_SPI != nullptr) {
401
-        this->TMC_SW_SPI->transfer(TMC2130_n::DRV_STATUS_t::address);
402
-        this->TMC_SW_SPI->transfer16(0);
403
-        // We only care about the last 10 bits
404
-        sg_result = this->TMC_SW_SPI->transfer(0);
405
-        sg_result <<= 8;
406
-        sg_result |= this->TMC_SW_SPI->transfer(0);
407
-      }
408
-      else {
409
-        SPI.beginTransaction(SPISettings(16000000/8, MSBFIRST, SPI_MODE3));
410
-        // Read DRV_STATUS
411
-        SPI.transfer(TMC2130_n::DRV_STATUS_t::address);
412
-        SPI.transfer16(0);
413
-        // We only care about the last 10 bits
414
-        sg_result = SPI.transfer(0);
415
-        sg_result <<= 8;
416
-        sg_result |= SPI.transfer(0);
417
-        SPI.endTransaction();
418
-      }
398
+      // read stallGuard flag from TMC library, will handle HW and SW SPI
399
+      TMC2130_n::DRV_STATUS_t drv_status{0};
400
+      drv_status.sr = this->DRV_STATUS();
401
+
419
       this->switchCSpin(HIGH);
402
       this->switchCSpin(HIGH);
420
 
403
 
421
-      return (sg_result & 0x3FF) == 0;
404
+      return drv_status.stallGuard;
422
     }
405
     }
423
-
424
   #endif // SPI_ENDSTOPS
406
   #endif // SPI_ENDSTOPS
425
 
407
 
426
 #endif // USE_SENSORLESS
408
 #endif // USE_SENSORLESS

+ 6
- 6
Marlin/src/module/endstops.cpp View File

537
   /**
537
   /**
538
    * Check and update endstops
538
    * Check and update endstops
539
    */
539
    */
540
-  #if HAS_X_MIN
540
+  #if HAS_X_MIN && !X_SPI_SENSORLESS
541
     #if ENABLED(X_DUAL_ENDSTOPS)
541
     #if ENABLED(X_DUAL_ENDSTOPS)
542
       UPDATE_ENDSTOP_BIT(X, MIN);
542
       UPDATE_ENDSTOP_BIT(X, MIN);
543
       #if HAS_X2_MIN
543
       #if HAS_X2_MIN
550
     #endif
550
     #endif
551
   #endif
551
   #endif
552
 
552
 
553
-  #if HAS_X_MAX
553
+  #if HAS_X_MAX && !X_SPI_SENSORLESS
554
     #if ENABLED(X_DUAL_ENDSTOPS)
554
     #if ENABLED(X_DUAL_ENDSTOPS)
555
       UPDATE_ENDSTOP_BIT(X, MAX);
555
       UPDATE_ENDSTOP_BIT(X, MAX);
556
       #if HAS_X2_MAX
556
       #if HAS_X2_MAX
563
     #endif
563
     #endif
564
   #endif
564
   #endif
565
 
565
 
566
-  #if HAS_Y_MIN
566
+  #if HAS_Y_MIN && !Y_SPI_SENSORLESS
567
     #if ENABLED(Y_DUAL_ENDSTOPS)
567
     #if ENABLED(Y_DUAL_ENDSTOPS)
568
       UPDATE_ENDSTOP_BIT(Y, MIN);
568
       UPDATE_ENDSTOP_BIT(Y, MIN);
569
       #if HAS_Y2_MIN
569
       #if HAS_Y2_MIN
576
     #endif
576
     #endif
577
   #endif
577
   #endif
578
 
578
 
579
-  #if HAS_Y_MAX
579
+  #if HAS_Y_MAX && !Y_SPI_SENSORLESS
580
     #if ENABLED(Y_DUAL_ENDSTOPS)
580
     #if ENABLED(Y_DUAL_ENDSTOPS)
581
       UPDATE_ENDSTOP_BIT(Y, MAX);
581
       UPDATE_ENDSTOP_BIT(Y, MAX);
582
       #if HAS_Y2_MAX
582
       #if HAS_Y2_MAX
589
     #endif
589
     #endif
590
   #endif
590
   #endif
591
 
591
 
592
-  #if HAS_Z_MIN
592
+  #if HAS_Z_MIN && !Z_SPI_SENSORLESS
593
     #if Z_MULTI_ENDSTOPS
593
     #if Z_MULTI_ENDSTOPS
594
       UPDATE_ENDSTOP_BIT(Z, MIN);
594
       UPDATE_ENDSTOP_BIT(Z, MIN);
595
       #if HAS_Z2_MIN
595
       #if HAS_Z2_MIN
616
     UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
616
     UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
617
   #endif
617
   #endif
618
 
618
 
619
-  #if HAS_Z_MAX
619
+  #if HAS_Z_MAX && !Z_SPI_SENSORLESS
620
     // Check both Z dual endstops
620
     // Check both Z dual endstops
621
     #if Z_MULTI_ENDSTOPS
621
     #if Z_MULTI_ENDSTOPS
622
       UPDATE_ENDSTOP_BIT(Z, MAX);
622
       UPDATE_ENDSTOP_BIT(Z, MAX);

Loading…
Cancel
Save