Browse Source

Update the delay functions and change the default pinmap for character displays (#7434)

Chris Pepper 6 years ago
parent
commit
9a950e3a5a
2 changed files with 22 additions and 9 deletions
  1. 3
    3
      Marlin/pins_RAMPS_RE_ARM.h
  2. 19
    6
      Marlin/src/HAL/HAL_LPC1768/arduino.cpp

+ 3
- 3
Marlin/pins_RAMPS_RE_ARM.h View File

@@ -275,11 +275,11 @@
275 275
   #define LCD_PINS_ENABLE     51  // (MOSI) J3-10 & AUX-3
276 276
   #define LCD_PINS_D4         52  // (SCK)  J3-9 & AUX-3
277 277
 
278
-  #define LCD_PINS_D5         59  // J3-8 & AUX-2
278
+  #define LCD_PINS_D5         71  // ENET_MDIO
279 279
   #define DOGLCD_A0           59  // J3-8 & AUX-2
280
-  #define LCD_PINS_D6         63  // J5-3 & AUX-2
280
+  #define LCD_PINS_D6         73  // ENET_RX_ER
281 281
   #define DOGLCD_CS           63  // J5-3 & AUX-2
282
-  #define LCD_PINS_D7          6  // (SERVO1) J5-1 & SERVO connector
282
+  #define LCD_PINS_D7         75  // ENET_RXD1
283 283
 
284 284
 
285 285
   //#define MISO                50  // system defined J3-10 & AUX-3

+ 19
- 6
Marlin/src/HAL/HAL_LPC1768/arduino.cpp View File

@@ -43,17 +43,28 @@ uint32_t millis() {
43 43
   return _millis;
44 44
 }
45 45
 
46
-//todo: recheck all of this
47 46
 void delayMicroseconds(uint32_t us) {
48
-  if (us < 2) return; // function jump, compare, return about 1us
49
-  us--;
50
-  static const int nop_factor = (SystemCoreClock / 10000000); // measured accurate at 10us
47
+  static const int nop_factor = (SystemCoreClock / 11000000);
51 48
   static volatile int loops = 0;
52
-  if (us < 20) { // burn cycles
49
+
50
+  //previous ops already burned most of 1us, burn the rest
51
+  loops = nop_factor / 4; //measured at 1us
52
+  while (loops > 0) --loops;
53
+
54
+  if (us < 2) return;
55
+  us--;
56
+
57
+  //redirect to delay for large values, then set new delay to remainder
58
+  if (us > 1000) {
59
+    delay(us / 1000);
60
+    us = us % 1000;
61
+  }
62
+
63
+  if (us < 5) { // burn cycles, time in interrupts will not be taken into account
53 64
     loops = us * nop_factor;
54 65
     while (loops > 0) --loops;
55 66
   }
56
-  else { // poll systick
67
+  else { // poll systick, more accurate through interrupts
57 68
     int32_t start = SysTick->VAL;
58 69
     int32_t load = SysTick->LOAD;
59 70
     int32_t end = start - (load / 1000) * us;
@@ -67,6 +78,8 @@ void delayMicroseconds(uint32_t us) {
67 78
 
68 79
 extern "C" void delay(int msec) {
69 80
    volatile int32_t end = _millis + msec;
81
+   SysTick->VAL = SysTick->LOAD; // reset systick counter so next systick is in exactly 1ms
82
+                                 // this could extend the time between systicks by upto 1ms
70 83
    while (_millis < end) __WFE();
71 84
 }
72 85
 

Loading…
Cancel
Save