Browse Source

🎨 Prefer DELAY_NS over DELAY_CYCLES (#22382)

Katelyn Schiesser 3 years ago
parent
commit
e55427aaa2
No account linked to committer's email address
1 changed files with 4 additions and 4 deletions
  1. 4
    4
      Marlin/src/HAL/DUE/HAL_SPI.cpp

+ 4
- 4
Marlin/src/HAL/DUE/HAL_SPI.cpp View File

240
   }
240
   }
241
 
241
 
242
   // all the others
242
   // all the others
243
-  static uint32_t spiDelayCyclesX4 = 4 * (F_CPU) / 1000000; // 4µs => 125khz
243
+  static uint16_t spiDelayNS = 4000; // 4000ns => 125khz
244
 
244
 
245
   static uint8_t spiTransferX(uint8_t b) { // using Mode 0
245
   static uint8_t spiTransferX(uint8_t b) { // using Mode 0
246
     int bits = 8;
246
     int bits = 8;
249
       b <<= 1; // little setup time
249
       b <<= 1; // little setup time
250
 
250
 
251
       WRITE(SD_SCK_PIN, HIGH);
251
       WRITE(SD_SCK_PIN, HIGH);
252
-      DELAY_CYCLES(spiDelayCyclesX4);
252
+      DELAY_NS(spiDelayNS);
253
 
253
 
254
       b |= (READ(SD_MISO_PIN) != 0);
254
       b |= (READ(SD_MISO_PIN) != 0);
255
 
255
 
256
       WRITE(SD_SCK_PIN, LOW);
256
       WRITE(SD_SCK_PIN, LOW);
257
-      DELAY_CYCLES(spiDelayCyclesX4);
257
+      DELAY_NS(spiDelayNS);
258
     } while (--bits);
258
     } while (--bits);
259
     return b;
259
     return b;
260
   }
260
   }
510
         spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
510
         spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
511
         break;
511
         break;
512
       default:
512
       default:
513
-        spiDelayCyclesX4 = ((F_CPU) / 1000000) >> (6 - spiRate) << 2; // spiRate of 2 gives the maximum error with current CPU
513
+        spiDelayNS = 4000 >> (6 - spiRate); // spiRate of 2 gives the maximum error with current CPU
514
         spiTransferTx = (pfnSpiTransfer)spiTransferX;
514
         spiTransferTx = (pfnSpiTransfer)spiTransferX;
515
         spiTransferRx = (pfnSpiTransfer)spiTransferX;
515
         spiTransferRx = (pfnSpiTransfer)spiTransferX;
516
         spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;
516
         spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;

Loading…
Cancel
Save