Parcourir la source

Better handling of DELAY_NS and DELAY_US (#10716)

Co-Authored-By: ejtagle <ejtagle@hotmail.com>
Scott Lahteine il y a 6 ans
Parent
révision
a1062eec5b
Aucun compte lié à l'adresse e-mail de l'auteur

+ 133
- 0
Marlin/src/HAL/Delay.h Voir le fichier

@@ -0,0 +1,133 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+
25
+  Busy wait delay Cycles routines:
26
+
27
+  DELAY_CYCLES(count): Delay execution in cycles
28
+  DELAY_NS(count): Delay execution in nanoseconds
29
+  DELAY_US(count): Delay execution in microseconds
30
+
31
+  */
32
+
33
+#ifndef MARLIN_DELAY_H
34
+#define MARLIN_DELAY_H
35
+
36
+#if defined(__arm__) || defined(__thumb__)
37
+
38
+  /* https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles */
39
+
40
+  #define nop() __asm__ __volatile__("nop;\n\t":::)
41
+
42
+  FORCE_INLINE static void __delay_4cycles(uint32_t cy) { // +1 cycle
43
+    #if ARCH_PIPELINE_RELOAD_CYCLES < 2
44
+      #define EXTRA_NOP_CYCLES A("nop")
45
+    #else
46
+      #define EXTRA_NOP_CYCLES ""
47
+    #endif
48
+
49
+    __asm__ __volatile__(
50
+      A(".syntax unified") // is to prevent CM0,CM1 non-unified syntax
51
+      L("1")
52
+      A("subs %[cnt],#1")
53
+      EXTRA_NOP_CYCLES
54
+      A("bne 1b")
55
+      : [cnt]"+r"(cy)   // output: +r means input+output
56
+      :                 // input:
57
+      : "cc"            // clobbers:
58
+    );
59
+  }
60
+
61
+  /* ---------------- Delay in cycles */
62
+  FORCE_INLINE static void DELAY_CYCLES(uint32_t x) {
63
+
64
+    if (__builtin_constant_p(x)) {
65
+      #define MAXNOPS 4
66
+
67
+      if (x <= (MAXNOPS)) {
68
+        switch (x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); }
69
+      }
70
+      else { // because of +1 cycle inside delay_4cycles
71
+        const uint32_t rem = (x - 1) % (MAXNOPS);
72
+        switch (rem) { case 3: nop(); case 2: nop(); case 1: nop(); }
73
+        if ((x = (x - 1) / (MAXNOPS)))
74
+          __delay_4cycles(x); // if need more then 4 nop loop is more optimal
75
+      }
76
+      #undef MAXNOPS
77
+    }
78
+    else
79
+      __delay_4cycles(x / 4);
80
+  }
81
+  #undef nop
82
+
83
+#elif defined(__AVR__)
84
+
85
+  #define nop() __asm__ __volatile__("nop;\n\t":::)
86
+
87
+  FORCE_INLINE static void __delay_4cycles(uint8_t cy) {
88
+    __asm__ __volatile__(
89
+      L("1")
90
+      A("dec %[cnt]")
91
+      A("nop")
92
+      A("brne 1b")
93
+      : [cnt] "+r"(cy)  // output: +r means input+output
94
+      :                 // input:
95
+      : "cc"            // clobbers:
96
+    );
97
+  }
98
+
99
+  /* ---------------- Delay in cycles */
100
+  FORCE_INLINE static void DELAY_CYCLES(uint16_t x) {
101
+
102
+    if (__builtin_constant_p(x)) {
103
+      #define MAXNOPS 4
104
+
105
+      if (x <= (MAXNOPS)) {
106
+        switch (x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); }
107
+      }
108
+      else {
109
+        const uint32_t rem = (x) % (MAXNOPS);
110
+        switch (rem) { case 3: nop(); case 2: nop(); case 1: nop(); }
111
+        if ((x = (x) / (MAXNOPS)))
112
+          __delay_4cycles(x); // if need more then 4 nop loop is more optimal
113
+      }
114
+
115
+      #undef MAXNOPS
116
+    }
117
+    else
118
+      __delay_4cycles(x / 4);
119
+  }
120
+  #undef nop
121
+
122
+#else
123
+  #error "Unsupported MCU architecture"
124
+#endif
125
+
126
+/* ---------------- Delay in nanoseconds */
127
+#define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) / 1000L )
128
+
129
+/* ---------------- Delay in microseconds */
130
+#define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) )
131
+
132
+#endif // MARLIN_DELAY_H
133
+

+ 40
- 83
Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp Voir le fichier

@@ -42,6 +42,7 @@
42 42
 // --------------------------------------------------------------------------
43 43
 
44 44
 #include "../../inc/MarlinConfig.h"
45
+#include "../Delay.h"
45 46
 
46 47
 // --------------------------------------------------------------------------
47 48
 // Public Variables
@@ -58,66 +59,16 @@
58 59
   // software SPI
59 60
   // --------------------------------------------------------------------------
60 61
 
61
-  // set optimization so ARDUINO optimizes this file
62
+  // Make sure GCC optimizes this file.
63
+  // Note that this line triggers a bug in GCC which is fixed by casting.
64
+  // See the note below.
62 65
   #pragma GCC optimize (3)
63 66
 
64
-  /* ---------------- Delay Cycles routine -------------- */
65
-
66
-  /* https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles */
67
-
68
-  #define nop() __asm__ __volatile__("nop;\n\t":::)
69
-
70
-  FORCE_INLINE static void __delay_4cycles(uint32_t cy) { // +1 cycle
71
-    #if ARCH_PIPELINE_RELOAD_CYCLES<2
72
-      #define EXTRA_NOP_CYCLES "nop"
73
-    #else
74
-      #define EXTRA_NOP_CYCLES ""
75
-    #endif
76
-
77
-    __asm__ __volatile__(
78
-      ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
79
-
80
-      L("loop%=")
81
-      A("subs %[cnt],#1")
82
-      A(EXTRA_NOP_CYCLES)
83
-      A("bne loop%=")
84
-      : [cnt]"+r"(cy) // output: +r means input+output
85
-      : // input:
86
-      : "cc" // clobbers:
87
-    );
88
-  }
89
-
90
-  FORCE_INLINE static void DELAY_CYCLES(uint32_t x) {
91
-
92
-    if (__builtin_constant_p(x)) {
93
-
94
-      #define MAXNOPS 4
95
-
96
-      if (x <= (MAXNOPS)) {
97
-        switch (x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); }
98
-      }
99
-      else { // because of +1 cycle inside delay_4cycles
100
-        const uint32_t rem = (x - 1) % (MAXNOPS);
101
-        switch (rem) { case 3: nop(); case 2: nop(); case 1: nop(); }
102
-        if ((x = (x - 1) / (MAXNOPS)))
103
-          __delay_4cycles(x); // if need more then 4 nop loop is more optimal
104
-      }
105
-    }
106
-    else
107
-      __delay_4cycles(x / 4);
108
-  }
109
-
110
-  /* ---------------- Delay in nanoseconds and in microseconds */
111
-
112
-  #define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU/1000000) / 1000)
113
-
114
-  typedef uint8_t (*pfnSpiTransfer) (uint8_t b);
67
+  typedef uint8_t (*pfnSpiTransfer)(uint8_t b);
115 68
   typedef void    (*pfnSpiRxBlock)(uint8_t* buf, uint32_t nbyte);
116 69
   typedef void    (*pfnSpiTxBlock)(const uint8_t* buf, uint32_t nbyte);
117 70
 
118
-
119 71
   /* ---------------- Macros to be able to access definitions from asm */
120
-
121 72
   #define _PORT(IO) DIO ##  IO ## _WPORT
122 73
   #define _PIN_MASK(IO) MASK(DIO ## IO ## _PIN)
123 74
   #define _PIN_SHIFT(IO) DIO ## IO ## _PIN
@@ -202,10 +153,10 @@
202 153
     return 0;
203 154
   }
204 155
 
205
- // Calculates the bit band alias address and returns a pointer address to word.
206
- // addr: The byte address of bitbanding bit.
207
- // bit:  The bit position of bitbanding bit.
208
-#define BITBAND_ADDRESS(addr, bit) \
156
+   // Calculates the bit band alias address and returns a pointer address to word.
157
+   // addr: The byte address of bitbanding bit.
158
+   // bit:  The bit position of bitbanding bit.
159
+  #define BITBAND_ADDRESS(addr, bit) \
209 160
     (((uint32_t)(addr) & 0xF0000000) + 0x02000000 + ((uint32_t)(addr)&0xFFFFF)*32 + (bit)*4)
210 161
 
211 162
   // run at ~8 .. ~10Mhz - Rx version (Tx line not altered)
@@ -319,8 +270,14 @@
319 270
   }
320 271
 
321 272
   // Pointers to generic functions for byte transfers
322
-  static pfnSpiTransfer spiTransferTx = spiTransferX;
323
-  static pfnSpiTransfer spiTransferRx = spiTransferX;
273
+
274
+  /**
275
+   * Note: The cast is unnecessary, but without it, this file triggers a GCC 4.8.3-2014 bug.
276
+   * Later GCC versions do not have this problem, but at this time (May 2018) Arduino still
277
+   * uses that buggy and obsolete GCC version!!
278
+   */
279
+  static pfnSpiTransfer spiTransferRx = (pfnSpiTransfer)spiTransferX;
280
+  static pfnSpiTransfer spiTransferTx = (pfnSpiTransfer)spiTransferX;
324 281
 
325 282
   // Block transfers run at ~8 .. ~10Mhz - Tx version (Rx data discarded)
326 283
   static void spiTxBlock0(const uint8_t* ptr, uint32_t todo) {
@@ -384,7 +341,7 @@
384 341
       A("str %[sck_mask],[%[sck_port],#0x4]")              /* CODR */
385 342
 
386 343
       /* Bit 0 */
387
-      A("str %[mosi_mask],[%[mosi_port], %[work],LSL #2]")  /* Access the proper SODR or CODR registers based on that bit */
344
+      A("str %[mosi_mask],[%[mosi_port], %[work],LSL #2]") /* Access the proper SODR or CODR registers based on that bit */
388 345
       A("str %[sck_mask],[%[sck_port]]")                   /* SODR */
389 346
       A("subs %[todo],#1")                                 /* Decrement count of pending words to send, update status */
390 347
       A("str %[sck_mask],[%[sck_port],#0x4]")              /* CODR */
@@ -491,8 +448,8 @@
491 448
   }
492 449
 
493 450
   // Pointers to generic functions for block tranfers
494
-  static pfnSpiTxBlock spiTxBlock = spiTxBlockX;
495
-  static pfnSpiRxBlock spiRxBlock = spiRxBlockX;
451
+  static pfnSpiTxBlock spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;
452
+  static pfnSpiRxBlock spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
496 453
 
497 454
   #if MB(ALLIGATOR)  // control SDSS pin
498 455
     void spiBegin() {
@@ -580,23 +537,23 @@
580 537
   void spiInit(uint8_t spiRate) {
581 538
     switch (spiRate) {
582 539
       case 0:
583
-        spiTransferTx = spiTransferTx0;
584
-        spiTransferRx = spiTransferRx0;
585
-        spiTxBlock = spiTxBlock0;
586
-        spiRxBlock = spiRxBlock0;
540
+        spiTransferTx = (pfnSpiTransfer)spiTransferTx0;
541
+        spiTransferRx = (pfnSpiTransfer)spiTransferRx0;
542
+        spiTxBlock = (pfnSpiTxBlock)spiTxBlock0;
543
+        spiRxBlock = (pfnSpiRxBlock)spiRxBlock0;
587 544
         break;
588 545
       case 1:
589
-        spiTransferTx = spiTransfer1;
590
-        spiTransferRx = spiTransfer1;
591
-        spiTxBlock = spiTxBlockX;
592
-        spiRxBlock = spiRxBlockX;
546
+        spiTransferTx = (pfnSpiTransfer)spiTransfer1;
547
+        spiTransferRx = (pfnSpiTransfer)spiTransfer1;
548
+        spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;
549
+        spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
593 550
         break;
594 551
       default:
595 552
         spiDelayCyclesX4 = (F_CPU/1000000) >> (6 - spiRate);
596
-        spiTransferTx = spiTransferX;
597
-        spiTransferRx = spiTransferX;
598
-        spiTxBlock = spiTxBlockX;
599
-        spiRxBlock = spiRxBlockX;
553
+        spiTransferTx = (pfnSpiTransfer)spiTransferX;
554
+        spiTransferRx = (pfnSpiTransfer)spiTransferX;
555
+        spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;
556
+        spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
600 557
         break;
601 558
     }
602 559
 
@@ -614,7 +571,7 @@
614 571
 
615 572
   #pragma GCC reset_options
616 573
 
617
-#else
574
+#else // !SOFTWARE_SPI
618 575
 
619 576
   #if MB(ALLIGATOR)
620 577
 
@@ -714,7 +671,7 @@
714 671
       while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
715 672
       // clear status
716 673
       SPI0->SPI_RDR;
717
-      //delayMicroseconds(1U);
674
+      //DELAY_US(1U);
718 675
     }
719 676
 
720 677
     void spiSend(const uint8_t* buf, size_t n) {
@@ -724,7 +681,7 @@
724 681
         while ((SPI0->SPI_SR & SPI_SR_TDRE) == 0);
725 682
         while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
726 683
         SPI0->SPI_RDR;
727
-        //delayMicroseconds(1U);
684
+        //DELAY_US(1U);
728 685
       }
729 686
       spiSend(buf[n - 1]);
730 687
     }
@@ -767,7 +724,7 @@
767 724
       // wait for receive register
768 725
       while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
769 726
       // get byte from receive register
770
-      //delayMicroseconds(1U);
727
+      //DELAY_US(1U);
771 728
       return SPI0->SPI_RDR;
772 729
     }
773 730
 
@@ -797,7 +754,7 @@
797 754
         SPI0->SPI_TDR = 0x000000FF | SPI_PCS(SPI_CHAN);
798 755
         while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
799 756
         buf[i] = SPI0->SPI_RDR;
800
-        //delayMicroseconds(1U);
757
+        //DELAY_US(1U);
801 758
       }
802 759
       buf[nbyte] = spiRec();
803 760
     }
@@ -813,7 +770,7 @@
813 770
         while ((SPI0->SPI_SR & SPI_SR_TDRE) == 0);
814 771
         while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
815 772
         SPI0->SPI_RDR;
816
-        //delayMicroseconds(1U);
773
+        //DELAY_US(1U);
817 774
       }
818 775
       spiSend(buf[511]);
819 776
     }
@@ -902,7 +859,7 @@
902 859
         spiTransfer(buf[i]);
903 860
     }
904 861
 
905
-  #endif  //MB(ALLIGATOR)
906
-#endif // ENABLED(SOFTWARE_SPI)
862
+  #endif // !ALLIGATOR
863
+#endif // !SOFTWARE_SPI
907 864
 
908 865
 #endif // ARDUINO_ARCH_SAM

+ 2
- 1
Marlin/src/HAL/HAL_LPC1768/HAL.cpp Voir le fichier

@@ -21,12 +21,13 @@
21 21
 #ifdef TARGET_LPC1768
22 22
 
23 23
 #include "../../inc/MarlinConfig.h"
24
+#include "../Delay.h"
24 25
 
25 26
 HalSerial usb_serial;
26 27
 
27 28
 // U8glib required functions
28 29
 extern "C" void u8g_xMicroDelay(uint16_t val) {
29
-  delayMicroseconds(val);
30
+  DELAY_US(val);
30 31
 }
31 32
 extern "C" void u8g_MicroDelay(void) {
32 33
   u8g_xMicroDelay(1);

+ 3
- 3
Marlin/src/HAL/HAL_LPC1768/HAL.h Voir le fichier

@@ -68,9 +68,9 @@ extern "C" volatile uint32_t _millis;
68 68
 #include "HAL_timers.h"
69 69
 #include "HardwareSerial.h"
70 70
 
71
-#define ST7920_DELAY_1 DELAY_20_NOP;DELAY_20_NOP;DELAY_20_NOP
72
-#define ST7920_DELAY_2 DELAY_20_NOP;DELAY_20_NOP;DELAY_20_NOP;DELAY_10_NOP;DELAY_5_NOP
73
-#define ST7920_DELAY_3 DELAY_20_NOP;DELAY_20_NOP;DELAY_20_NOP;DELAY_10_NOP;DELAY_5_NOP
71
+#define ST7920_DELAY_1 DELAY_NS(600)
72
+#define ST7920_DELAY_2 DELAY_NS(750)
73
+#define ST7920_DELAY_3 DELAY_NS(750)
74 74
 
75 75
 extern HalSerial usb_serial;
76 76
 

+ 2
- 20
Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp Voir le fichier

@@ -37,6 +37,7 @@
37 37
 //
38 38
 //#include <WInterrupts.h>
39 39
 #include "../../inc/MarlinConfig.h"
40
+#include "../Delay.h"
40 41
 #include <stdint.h>
41 42
 #include <stdarg.h>
42 43
 #include <Arduino.h>
@@ -78,28 +79,9 @@ static const DELAY_TABLE table[] = {
78 79
 // Private methods
79 80
 //
80 81
 
81
-#if 0
82
-/* static */
83
-inline void SoftwareSerial::tunedDelay(const uint32_t count) {
84
-
85
-  asm volatile(
86
-
87
-    "mov r3, %[loopsPerMicrosecond] \n\t" //load the initial loop counter
88
-    "1: \n\t"
89
-    "sub r3, r3, #1 \n\t"
90
-    "bne 1b \n\t"
91
-
92
-    ://empty output list
93
-    :[loopsPerMicrosecond] "r" (count)
94
-    :"r3", "cc" //clobber list
95
-  );
96
-
97
-}
98
-#else
99 82
 inline void SoftwareSerial::tunedDelay(const uint32_t count) {
100
-  delayMicroseconds(count);
83
+  DELAY_US(count);
101 84
 }
102
-#endif
103 85
 
104 86
 // This function sets the current object as the "listening"
105 87
 // one and returns true if it replaces another

+ 3
- 19
Marlin/src/HAL/HAL_LPC1768/arduino.cpp Voir le fichier

@@ -26,6 +26,7 @@
26 26
 #include <lpc17xx_pinsel.h>
27 27
 
28 28
 #include "../../inc/MarlinConfig.h"
29
+#include "../Delay.h"
29 30
 
30 31
 // Interrupts
31 32
 void cli(void) { __disable_irq(); } // Disable
@@ -40,26 +41,9 @@ uint32_t millis() {
40 41
   return _millis;
41 42
 }
42 43
 
44
+// This is required for some Arduino libraries we are using
43 45
 void delayMicroseconds(uint32_t us) {
44
-  static const int nop_factor = (SystemCoreClock / 11000000);
45
-  static volatile int loops = 0;
46
-
47
-  //previous ops already burned most of 1us, burn the rest
48
-  loops = nop_factor / 4; //measured at 1us
49
-  while (loops > 0) --loops;
50
-
51
-  if (us < 2) return;
52
-  us--;
53
-
54
-  //redirect to delay for large values, then set new delay to remainder
55
-  if (us > 1000) {
56
-    delay(us / 1000);
57
-    us = us % 1000;
58
-  }
59
-
60
-  // burn cycles, time in interrupts will not be taken into account
61
-  loops = us * nop_factor;
62
-  while (loops > 0) --loops;
46
+  DELAY_US(us);
63 47
 }
64 48
 
65 49
 extern "C" void delay(const int msec) {

+ 4
- 5
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction Voir le fichier

@@ -63,7 +63,6 @@
63 63
 
64 64
   #include <U8glib.h>
65 65
 
66
-void delayMicroseconds(uint32_t us);
67 66
 //void pinMode(int16_t pin, uint8_t mode);
68 67
 //void digitalWrite(int16_t pin, uint8_t pin_status);
69 68
 
@@ -122,13 +121,13 @@ uint8_t u8g_i2c_start_sw(uint8_t sla) {  // assert start condition and then send
122 121
 
123 122
   LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
124 123
   LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
125
-  delayMicroseconds(2);
124
+  DELAY_US(2);
126 125
   LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
127
-  delayMicroseconds(2);
126
+  DELAY_US(2);
128 127
   LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
129
-  delayMicroseconds(2);
128
+  DELAY_US(2);
130 129
   LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
131
-  delayMicroseconds(2);
130
+  DELAY_US(2);
132 131
   LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
133 132
 
134 133
   u8g_i2c_send_byte_sw(I2C_SLA);  // send slave address with write bit

+ 2
- 52
Marlin/src/core/macros.h Voir le fichier

@@ -50,58 +50,8 @@
50 50
   #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20 on AVR
51 51
 #endif
52 52
 
53
-// Processor-level delays for hardware interfaces
54
-#ifndef _NOP
55
-  #define _NOP() do { __asm__ volatile ("nop"); } while (0)
56
-#endif
57
-#define DELAY_NOPS(X) \
58
-  switch (X) { \
59
-    case 20: _NOP(); case 19: _NOP(); case 18: _NOP(); case 17: _NOP(); \
60
-    case 16: _NOP(); case 15: _NOP(); case 14: _NOP(); case 13: _NOP(); \
61
-    case 12: _NOP(); case 11: _NOP(); case 10: _NOP(); case  9: _NOP(); \
62
-    case  8: _NOP(); case  7: _NOP(); case  6: _NOP(); case  5: _NOP(); \
63
-    case  4: _NOP(); case  3: _NOP(); case  2: _NOP(); case  1: _NOP(); \
64
-  }
65
-#define DELAY_0_NOP   NOOP
66
-#define DELAY_1_NOP   DELAY_NOPS( 1)
67
-#define DELAY_2_NOP   DELAY_NOPS( 2)
68
-#define DELAY_3_NOP   DELAY_NOPS( 3)
69
-#define DELAY_4_NOP   DELAY_NOPS( 4)
70
-#define DELAY_5_NOP   DELAY_NOPS( 5)
71
-#define DELAY_10_NOP  DELAY_NOPS(10)
72
-#define DELAY_20_NOP  DELAY_NOPS(20)
73
-
74
-#if CYCLES_PER_MICROSECOND <= 200
75
-  #define DELAY_100NS DELAY_NOPS((CYCLES_PER_MICROSECOND + 9) / 10)
76
-#else
77
-  #define DELAY_100NS DELAY_20_NOP
78
-#endif
79
-
80
-// Microsecond delays for hardware interfaces
81
-#if CYCLES_PER_MICROSECOND <= 20
82
-  #define DELAY_1US DELAY_NOPS(CYCLES_PER_MICROSECOND)
83
-  #define DELAY_US(X) \
84
-    switch (X) { \
85
-      case 20: DELAY_1US; case 19: DELAY_1US; case 18: DELAY_1US; case 17: DELAY_1US; \
86
-      case 16: DELAY_1US; case 15: DELAY_1US; case 14: DELAY_1US; case 13: DELAY_1US; \
87
-      case 12: DELAY_1US; case 11: DELAY_1US; case 10: DELAY_1US; case  9: DELAY_1US; \
88
-      case  8: DELAY_1US; case  7: DELAY_1US; case  6: DELAY_1US; case  5: DELAY_1US; \
89
-      case  4: DELAY_1US; case  3: DELAY_1US; case  2: DELAY_1US; case  1: DELAY_1US; \
90
-    }
91
-#else
92
-  #define DELAY_US(X) delayMicroseconds(X) // May not be usable in CRITICAL_SECTION
93
-  #define DELAY_1US DELAY_US(1)
94
-#endif
95
-#define DELAY_2US  DELAY_US( 2)
96
-#define DELAY_3US  DELAY_US( 3)
97
-#define DELAY_4US  DELAY_US( 4)
98
-#define DELAY_5US  DELAY_US( 5)
99
-#define DELAY_6US  DELAY_US( 6)
100
-#define DELAY_7US  DELAY_US( 7)
101
-#define DELAY_8US  DELAY_US( 8)
102
-#define DELAY_9US  DELAY_US( 9)
103
-#define DELAY_10US DELAY_US(10)
104
-#define DELAY_20US DELAY_US(20)
53
+// Nanoseconds per cycle
54
+#define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
105 55
 
106 56
 // Remove compiler warning on an unused variable
107 57
 #define UNUSED(x) (void) (x)

+ 3
- 6
Marlin/src/feature/Max7219_Debug_LEDs.cpp Voir le fichier

@@ -60,19 +60,16 @@
60 60
 #include "../module/planner.h"
61 61
 #include "../module/stepper.h"
62 62
 #include "../Marlin.h"
63
+#include "../HAL/Delay.h"
63 64
 
64 65
 static uint8_t LEDs[8] = { 0 };
65 66
 
66 67
 #ifdef CPU_32_BIT
67 68
   // Approximate a 1µs delay on 32-bit ARM
68
-  void SIG_DELAY() {
69
-    int16_t delay_cycles = CYCLES_PER_MICROSECOND - 10;
70
-    while (delay_cycles >= 10) { DELAY_NOPS(6); delay_cycles -= 10; }
71
-    if (delay_cycles > 0) DELAY_NOPS(delay_cycles);
72
-  }
69
+  #define SIG_DELAY() DELAY_US(1)
73 70
 #else
74 71
   // Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
75
-  #define SIG_DELAY() DELAY_3_NOP
72
+  #define SIG_DELAY() DELAY_NS(188)
76 73
 #endif
77 74
 
78 75
 void Max7219_PutByte(uint8_t data) {

+ 12
- 11
Marlin/src/feature/dac/dac_dac084s085.cpp Voir le fichier

@@ -12,6 +12,7 @@
12 12
 
13 13
 #include "../../Marlin.h"
14 14
 #include "../../module/stepper.h"
15
+#include "../../HAL/Delay.h"
15 16
 
16 17
 dac084s085::dac084s085() { }
17 18
 
@@ -27,11 +28,11 @@ void dac084s085::begin() {
27 28
   spiBegin();
28 29
 
29 30
   //init onboard DAC
30
-  delayMicroseconds(2U);
31
+  DELAY_US(2);
31 32
   WRITE(DAC0_SYNC, LOW);
32
-  delayMicroseconds(2U);
33
+  DELAY_US(2);
33 34
   WRITE(DAC0_SYNC, HIGH);
34
-  delayMicroseconds(2U);
35
+  DELAY_US(2);
35 36
   WRITE(DAC0_SYNC, LOW);
36 37
 
37 38
   spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
@@ -39,11 +40,11 @@ void dac084s085::begin() {
39 40
 
40 41
   #if EXTRUDERS > 1
41 42
     //init Piggy DAC
42
-    delayMicroseconds(2U);
43
+    DELAY_US(2);
43 44
     WRITE(DAC1_SYNC, LOW);
44
-    delayMicroseconds(2U);
45
+    DELAY_US(2);
45 46
     WRITE(DAC1_SYNC, HIGH);
46
-    delayMicroseconds(2U);
47
+    DELAY_US(2);
47 48
     WRITE(DAC1_SYNC, LOW);
48 49
 
49 50
     spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
@@ -66,20 +67,20 @@ void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
66 67
 
67 68
   if (channel > 3) {        // DAC Piggy E1,E2,E3
68 69
     WRITE(DAC1_SYNC, LOW);
69
-    delayMicroseconds(2U);
70
+    DELAY_US(2);
70 71
     WRITE(DAC1_SYNC, HIGH);
71
-    delayMicroseconds(2U);
72
+    DELAY_US(2);
72 73
     WRITE(DAC1_SYNC, LOW);
73 74
   }
74 75
   else {                    // DAC onboard X,Y,Z,E0
75 76
     WRITE(DAC0_SYNC, LOW);
76
-    delayMicroseconds(2U);
77
+    DELAY_US(2);
77 78
     WRITE(DAC0_SYNC, HIGH);
78
-    delayMicroseconds(2U);
79
+    DELAY_US(2);
79 80
     WRITE(DAC0_SYNC, LOW);
80 81
   }
81 82
 
82
-  delayMicroseconds(2U);
83
+  DELAY_US(2);
83 84
   spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
84 85
 }
85 86
 

+ 3
- 3
Marlin/src/inc/Conditionals_LCD.h Voir le fichier

@@ -120,13 +120,13 @@
120 120
 
121 121
   #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
122 122
   #ifndef ST7920_DELAY_1
123
-    #define ST7920_DELAY_1 DELAY_2_NOP
123
+    #define ST7920_DELAY_1 DELAY_NS(125)
124 124
   #endif
125 125
   #ifndef ST7920_DELAY_2
126
-    #define ST7920_DELAY_2 DELAY_2_NOP
126
+    #define ST7920_DELAY_2 DELAY_NS(125)
127 127
   #endif
128 128
   #ifndef ST7920_DELAY_3
129
-    #define ST7920_DELAY_3 DELAY_2_NOP
129
+    #define ST7920_DELAY_3 DELAY_NS(125)
130 130
   #endif
131 131
 
132 132
 #elif ENABLED(MKS_12864OLED)

+ 21
- 20
Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp Voir le fichier

@@ -24,6 +24,7 @@
24 24
 // file u8g_dev_st7920_128x64_HAL.cpp for the HAL version.
25 25
 
26 26
 #include "../../inc/MarlinConfig.h"
27
+#include "../../HAL/Delay.h"
27 28
 
28 29
 #if ENABLED(U8GLIB_ST7920)
29 30
 
@@ -46,30 +47,30 @@
46 47
 #pragma GCC optimize (3)
47 48
 
48 49
 // If you want you can define your own set of delays in Configuration.h
49
-//#define ST7920_DELAY_1 DELAY_0_NOP
50
-//#define ST7920_DELAY_2 DELAY_0_NOP
51
-//#define ST7920_DELAY_3 DELAY_0_NOP
50
+//#define ST7920_DELAY_1 DELAY_NS(0)
51
+//#define ST7920_DELAY_2 DELAY_NS(0)
52
+//#define ST7920_DELAY_3 DELAY_NS(0)
52 53
 
53 54
 #if F_CPU >= 20000000
54
-  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
55
-  #define CPU_ST7920_DELAY_2 DELAY_0_NOP
56
-  #define CPU_ST7920_DELAY_3 DELAY_1_NOP
55
+  #define CPU_ST7920_DELAY_1 DELAY_NS(0)
56
+  #define CPU_ST7920_DELAY_2 DELAY_NS(0)
57
+  #define CPU_ST7920_DELAY_3 DELAY_NS(50)
57 58
 #elif MB(3DRAG) || MB(K8200) || MB(K8400) || MB(SILVER_GATE)
58
-  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
59
-  #define CPU_ST7920_DELAY_2 DELAY_3_NOP
60
-  #define CPU_ST7920_DELAY_3 DELAY_0_NOP
59
+  #define CPU_ST7920_DELAY_1 DELAY_NS(0)
60
+  #define CPU_ST7920_DELAY_2 DELAY_NS(188)
61
+  #define CPU_ST7920_DELAY_3 DELAY_NS(0)
61 62
 #elif MB(MINIRAMBO)
62
-  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
63
-  #define CPU_ST7920_DELAY_2 DELAY_4_NOP
64
-  #define CPU_ST7920_DELAY_3 DELAY_0_NOP
63
+  #define CPU_ST7920_DELAY_1 DELAY_NS(0)
64
+  #define CPU_ST7920_DELAY_2 DELAY_NS(250)
65
+  #define CPU_ST7920_DELAY_3 DELAY_NS(0)
65 66
 #elif MB(RAMBO)
66
-  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
67
-  #define CPU_ST7920_DELAY_2 DELAY_0_NOP
68
-  #define CPU_ST7920_DELAY_3 DELAY_0_NOP
67
+  #define CPU_ST7920_DELAY_1 DELAY_NS(0)
68
+  #define CPU_ST7920_DELAY_2 DELAY_NS(0)
69
+  #define CPU_ST7920_DELAY_3 DELAY_NS(0)
69 70
 #elif F_CPU == 16000000
70
-  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
71
-  #define CPU_ST7920_DELAY_2 DELAY_0_NOP
72
-  #define CPU_ST7920_DELAY_3 DELAY_1_NOP
71
+  #define CPU_ST7920_DELAY_1 DELAY_NS(0)
72
+  #define CPU_ST7920_DELAY_2 DELAY_NS(0)
73
+  #define CPU_ST7920_DELAY_3 DELAY_NS(63)
73 74
 #else
74 75
   #error "No valid condition for delays in 'ultralcd_st7920_u8glib_rrd.h'"
75 76
 #endif
@@ -101,8 +102,8 @@ static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
101 102
   ST7920_SND_BIT; // 8
102 103
 }
103 104
 
104
-#if defined(DOGM_SPI_DELAY_US) && DOGM_SPI_DELAY_US > 0
105
-  #define U8G_DELAY() delayMicroseconds(DOGM_SPI_DELAY_US)
105
+#if DOGM_SPI_DELAY_US > 0
106
+  #define U8G_DELAY() DELAY_US(DOGM_SPI_DELAY_US)
106 107
 #else
107 108
   #define U8G_DELAY() u8g_10MicroDelay()
108 109
 #endif

+ 19
- 15
Marlin/src/module/stepper.cpp Voir le fichier

@@ -41,15 +41,18 @@
41 41
  * along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
42 42
  */
43 43
 
44
-/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
45
-   and Philipp Tiefenbacher. */
44
+/**
45
+ * Timer calculations informed by the 'RepRap cartesian firmware' by Zack Smith
46
+ * and Philipp Tiefenbacher.
47
+ */
46 48
 
47
-/* Jerk controlled movements planner added by Eduardo José Tagle in April
48
-   2018, Equations based on Synthethos TinyG2 sources, but the fixed-point
49
-   implementation is a complete new one, as we are running the ISR with a
50
-   variable period.
51
-   Also implemented the Bézier velocity curve evaluation in ARM assembler,
52
-   to avoid impacting ISR speed. */
49
+/**
50
+ * Jerk controlled movements planner added Apr 2018 by Eduardo José Tagle.
51
+ * Equations based on Synthethos TinyG2 sources, but the fixed-point
52
+ * implementation is new, as we are running the ISR with a variable period.
53
+ * Also implemented the Bézier velocity curve evaluation in ARM assembler,
54
+ * to avoid impacting ISR speed.
55
+ */
53 56
 
54 57
 #include "stepper.h"
55 58
 
@@ -67,6 +70,7 @@
67 70
 #include "../gcode/queue.h"
68 71
 #include "../sd/cardreader.h"
69 72
 #include "../Marlin.h"
73
+#include "../HAL/Delay.h"
70 74
 
71 75
 #if MB(ALLIGATOR)
72 76
   #include "../feature/dac/dac_dac084s085.h"
@@ -1471,7 +1475,7 @@ void Stepper::isr() {
1471 1475
       while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
1472 1476
       pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
1473 1477
     #elif EXTRA_CYCLES_XYZE > 0
1474
-      DELAY_NOPS(EXTRA_CYCLES_XYZE);
1478
+      DELAY_NS(EXTRA_CYCLES_XYZE * NANOSECONDS_PER_CYCLE);
1475 1479
     #endif
1476 1480
 
1477 1481
     #if HAS_X_STEP
@@ -1506,7 +1510,7 @@ void Stepper::isr() {
1506 1510
     #if EXTRA_CYCLES_XYZE > 20
1507 1511
       if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
1508 1512
     #elif EXTRA_CYCLES_XYZE > 0
1509
-      if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
1513
+      if (i) DELAY_NS(EXTRA_CYCLES_XYZE * NANOSECONDS_PER_CYCLE);
1510 1514
     #endif
1511 1515
 
1512 1516
   } // steps_loop
@@ -1739,7 +1743,7 @@ void Stepper::isr() {
1739 1743
         while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
1740 1744
         pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
1741 1745
       #elif EXTRA_CYCLES_E > 0
1742
-        DELAY_NOPS(EXTRA_CYCLES_E);
1746
+        DELAY_NS(EXTRA_CYCLES_E * NANOSECONDS_PER_CYCLE);
1743 1747
       #endif
1744 1748
 
1745 1749
       switch (LA_active_extruder) {
@@ -1762,7 +1766,7 @@ void Stepper::isr() {
1762 1766
       #if EXTRA_CYCLES_E > 20
1763 1767
         if (e_steps) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
1764 1768
       #elif EXTRA_CYCLES_E > 0
1765
-        if (e_steps) DELAY_NOPS(EXTRA_CYCLES_E);
1769
+        if (e_steps) DELAY_NS(EXTRA_CYCLES_E * NANOSECONDS_PER_CYCLE);
1766 1770
       #endif
1767 1771
 
1768 1772
     } // e_steps
@@ -2146,13 +2150,13 @@ void Stepper::report_positions() {
2146 2150
   #else
2147 2151
     #define _SAVE_START NOOP
2148 2152
     #if EXTRA_CYCLES_BABYSTEP > 0
2149
-      #define _PULSE_WAIT DELAY_NOPS(EXTRA_CYCLES_BABYSTEP)
2153
+      #define _PULSE_WAIT DELAY_NS(EXTRA_CYCLES_BABYSTEP * NANOSECONDS_PER_CYCLE)
2150 2154
     #elif STEP_PULSE_CYCLES > 0
2151 2155
       #define _PULSE_WAIT NOOP
2152 2156
     #elif ENABLED(DELTA)
2153
-      #define _PULSE_WAIT delayMicroseconds(2);
2157
+      #define _PULSE_WAIT DELAY_US(2);
2154 2158
     #else
2155
-      #define _PULSE_WAIT delayMicroseconds(4);
2159
+      #define _PULSE_WAIT DELAY_US(4);
2156 2160
     #endif
2157 2161
   #endif
2158 2162
 

+ 5
- 4
Marlin/src/module/temperature.cpp Voir le fichier

@@ -30,6 +30,7 @@
30 30
 #include "../lcd/ultralcd.h"
31 31
 #include "planner.h"
32 32
 #include "../core/language.h"
33
+#include "../HAL/Delay.h"
33 34
 
34 35
 #if ENABLED(HEATER_0_USES_MAX6675)
35 36
   #include "../libs/private_spi.h"
@@ -681,14 +682,14 @@ float Temperature::get_pid_output(const int8_t e) {
681 682
         #if ENABLED(PID_EXTRUSION_SCALING)
682 683
           cTerm[HOTEND_INDEX] = 0;
683 684
           if (_HOTEND_TEST) {
684
-            long e_position = stepper.position(E_AXIS);
685
+            const long e_position = stepper.position(E_AXIS);
685 686
             if (e_position > last_e_position) {
686 687
               lpq[lpq_ptr] = e_position - last_e_position;
687 688
               last_e_position = e_position;
688 689
             }
689
-            else {
690
+            else
690 691
               lpq[lpq_ptr] = 0;
691
-            }
692
+
692 693
             if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
693 694
             cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
694 695
             pid_output += cTerm[HOTEND_INDEX];
@@ -1629,7 +1630,7 @@ void Temperature::disable_all_heaters() {
1629 1630
 
1630 1631
     WRITE(MAX6675_SS, 0); // enable TT_MAX6675
1631 1632
 
1632
-    DELAY_100NS;          // Ensure 100ns delay
1633
+    DELAY_NS(100);       // Ensure 100ns delay
1633 1634
 
1634 1635
     // Read a big-endian temperature value
1635 1636
     max6675_temp = 0;

+ 3
- 3
Marlin/src/pins/pins_ANET_10.h Voir le fichier

@@ -177,13 +177,13 @@
177 177
     #define BTN_EN2          10
178 178
     #define BTN_ENC          16
179 179
     #ifndef ST7920_DELAY_1
180
-      #define ST7920_DELAY_1 DELAY_0_NOP
180
+      #define ST7920_DELAY_1 DELAY_NS(0)
181 181
     #endif
182 182
     #ifndef ST7920_DELAY_2
183
-      #define ST7920_DELAY_2 DELAY_1_NOP
183
+      #define ST7920_DELAY_2 DELAY_NS(63)
184 184
     #endif
185 185
     #ifndef ST7920_DELAY_3
186
-      #define ST7920_DELAY_3 DELAY_2_NOP
186
+      #define ST7920_DELAY_3 DELAY_NS(125)
187 187
     #endif
188 188
     #define STD_ENCODER_PULSES_PER_STEP 4
189 189
     #define STD_ENCODER_STEPS_PER_MENU_ITEM 1

+ 3
- 3
Marlin/src/pins/pins_MELZI_CREALITY.h Voir le fichier

@@ -55,13 +55,13 @@
55 55
 
56 56
 // Alter timing for graphical display
57 57
 #ifndef ST7920_DELAY_1
58
-  #define ST7920_DELAY_1 DELAY_2_NOP
58
+  #define ST7920_DELAY_1 DELAY_NS(125)
59 59
 #endif
60 60
 #ifndef ST7920_DELAY_2
61
-  #define ST7920_DELAY_2 DELAY_2_NOP
61
+  #define ST7920_DELAY_2 DELAY_NS(125)
62 62
 #endif
63 63
 #ifndef ST7920_DELAY_3
64
-  #define ST7920_DELAY_3 DELAY_2_NOP
64
+  #define ST7920_DELAY_3 DELAY_NS(125)
65 65
 #endif
66 66
 
67 67
 #if ENABLED(MINIPANEL)

+ 3
- 3
Marlin/src/pins/pins_MELZI_MALYAN.h Voir le fichier

@@ -44,11 +44,11 @@
44 44
 
45 45
 // Alter timing for graphical display
46 46
 #ifndef ST7920_DELAY_1
47
-  #define ST7920_DELAY_1 DELAY_2_NOP
47
+  #define ST7920_DELAY_1 DELAY_NS(125)
48 48
 #endif
49 49
 #ifndef ST7920_DELAY_2
50
-  #define ST7920_DELAY_2 DELAY_2_NOP
50
+  #define ST7920_DELAY_2 DELAY_NS(125)
51 51
 #endif
52 52
 #ifndef ST7920_DELAY_3
53
-  #define ST7920_DELAY_3 DELAY_2_NOP
53
+  #define ST7920_DELAY_3 DELAY_NS(125)
54 54
 #endif

+ 3
- 3
Marlin/src/pins/pins_MELZI_TRONXY.h Voir le fichier

@@ -51,11 +51,11 @@
51 51
 #define BTN_ENC         26
52 52
 
53 53
 #ifndef ST7920_DELAY_1
54
-  #define ST7920_DELAY_1 DELAY_0_NOP
54
+  #define ST7920_DELAY_1 DELAY_NS(0)
55 55
 #endif
56 56
 #ifndef ST7920_DELAY_2
57
-  #define ST7920_DELAY_2 DELAY_2_NOP
57
+  #define ST7920_DELAY_2 DELAY_NS(125)
58 58
 #endif
59 59
 #ifndef ST7920_DELAY_3
60
-  #define ST7920_DELAY_3 DELAY_0_NOP
60
+  #define ST7920_DELAY_3 DELAY_NS(0)
61 61
 #endif

+ 3
- 3
Marlin/src/pins/pins_PRINTRBOARD_REVF.h Voir le fichier

@@ -244,13 +244,13 @@
244 244
 
245 245
     // increase delays
246 246
     #ifndef ST7920_DELAY_1
247
-      #define ST7920_DELAY_1 DELAY_5_NOP
247
+      #define ST7920_DELAY_1 DELAY_NS(313)
248 248
     #endif
249 249
     #ifndef ST7920_DELAY_2
250
-      #define ST7920_DELAY_2 DELAY_5_NOP
250
+      #define ST7920_DELAY_2 DELAY_NS(313)
251 251
     #endif
252 252
     #ifndef ST7920_DELAY_3
253
-      #define ST7920_DELAY_3 DELAY_5_NOP
253
+      #define ST7920_DELAY_3 DELAY_NS(313)
254 254
     #endif
255 255
 
256 256
   #else

+ 3
- 3
Marlin/src/pins/pins_SANGUINOLOLU_11.h Voir le fichier

@@ -239,13 +239,13 @@
239 239
     #define BTN_EN2             30
240 240
 
241 241
     #ifndef ST7920_DELAY_1
242
-      #define ST7920_DELAY_1 DELAY_0_NOP
242
+      #define ST7920_DELAY_1 DELAY_NS(0)
243 243
     #endif
244 244
     #ifndef ST7920_DELAY_2
245
-      #define ST7920_DELAY_2 DELAY_3_NOP
245
+      #define ST7920_DELAY_2 DELAY_NS(188)
246 246
     #endif
247 247
     #ifndef ST7920_DELAY_3
248
-      #define ST7920_DELAY_3 DELAY_0_NOP
248
+      #define ST7920_DELAY_3 DELAY_NS(0)
249 249
     #endif
250 250
 
251 251
   #elif ENABLED(ZONESTAR_LCD) // For the Tronxy Melzi boards

+ 3
- 8
Marlin/src/pins/pins_STM32F4.h Voir le fichier

@@ -176,19 +176,14 @@
176 176
 //
177 177
 // ST7920 Delays
178 178
 //
179
-
180
-#define STM_NOP __asm__("nop\n\t")
181
-#define STM_DELAY_SHORT { STM_NOP; STM_NOP; STM_NOP; STM_NOP; }
182
-#define STM_DELAY_LONG  { STM_DELAY_SHORT; STM_DELAY_SHORT; STM_NOP; STM_NOP; }
183
-
184 179
 #ifndef ST7920_DELAY_1
185
-  #define ST7920_DELAY_1 { STM_DELAY_SHORT; STM_DELAY_SHORT; }
180
+  #define ST7920_DELAY_1 DELAY_NS(96)
186 181
 #endif
187 182
 
188 183
 #ifndef ST7920_DELAY_2
189
-  #define ST7920_DELAY_2 { STM_DELAY_SHORT; }
184
+  #define ST7920_DELAY_2 DELAY_NS(48)
190 185
 #endif
191 186
 
192 187
 #ifndef ST7920_DELAY_3
193
-  #define ST7920_DELAY_3 { STM_DELAY_LONG; STM_DELAY_LONG; STM_DELAY_LONG; STM_DELAY_LONG; STM_DELAY_LONG; STM_DELAY_LONG; }
188
+  #define ST7920_DELAY_3 DELAY_NS(715)
194 189
 #endif

Chargement…
Annuler
Enregistrer