瀏覽代碼

Apply loop shorthand macros (#17159)

Scott Lahteine 4 年之前
父節點
當前提交
118bd2f8b2
沒有連結到貢獻者的電子郵件帳戶。
共有 93 個檔案被更改,包括 458 行新增498 行删除
  1. 2
    2
      Marlin/src/HAL/AVR/HAL_SPI.cpp
  2. 1
    1
      Marlin/src/HAL/AVR/MarlinSerial.cpp
  3. 1
    1
      Marlin/src/HAL/AVR/fast_pwm.cpp
  4. 2
    2
      Marlin/src/HAL/AVR/pinsDebug.h
  5. 2
    2
      Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp
  6. 1
    1
      Marlin/src/HAL/DUE/MarlinSerial.cpp
  7. 1
    1
      Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
  8. 2
    2
      Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
  9. 1
    1
      Marlin/src/HAL/DUE/fastio/G2_PWM.h
  10. 1
    1
      Marlin/src/HAL/LPC1768/main.cpp
  11. 8
    8
      Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
  12. 3
    3
      Marlin/src/HAL/SAMD51/HAL.cpp
  13. 1
    1
      Marlin/src/HAL/STM32/fastio.cpp
  14. 8
    8
      Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
  15. 1
    1
      Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp
  16. 1
    1
      Marlin/src/HAL/shared/servo.cpp
  17. 1
    1
      Marlin/src/MarlinCore.cpp
  18. 5
    0
      Marlin/src/core/macros.h
  19. 0
    6
      Marlin/src/core/types.h
  20. 9
    9
      Marlin/src/feature/bedlevel/abl/abl.cpp
  21. 10
    11
      Marlin/src/feature/bedlevel/bedlevel.cpp
  22. 3
    5
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
  23. 1
    3
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h
  24. 8
    12
      Marlin/src/feature/bedlevel/ubl/ubl.cpp
  25. 1
    3
      Marlin/src/feature/bedlevel/ubl/ubl.h
  26. 130
    151
      Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
  27. 2
    2
      Marlin/src/feature/digipot/digipot_mcp4018.cpp
  28. 1
    1
      Marlin/src/feature/digipot/digipot_mcp4451.cpp
  29. 1
    1
      Marlin/src/feature/filwidth.cpp
  30. 3
    3
      Marlin/src/feature/fwretract.cpp
  31. 11
    11
      Marlin/src/feature/max7219.cpp
  32. 2
    2
      Marlin/src/feature/mixing.cpp
  33. 4
    4
      Marlin/src/feature/mmu2/mmu2.cpp
  34. 1
    1
      Marlin/src/feature/powerloss.cpp
  35. 3
    3
      Marlin/src/feature/probe_temp_comp.cpp
  36. 1
    1
      Marlin/src/feature/runout.h
  37. 1
    1
      Marlin/src/feature/twibus.cpp
  38. 54
    61
      Marlin/src/gcode/bedlevel/G26.cpp
  39. 6
    7
      Marlin/src/gcode/bedlevel/M420.cpp
  40. 2
    2
      Marlin/src/gcode/bedlevel/abl/G29.cpp
  41. 2
    2
      Marlin/src/gcode/calibrate/G425.cpp
  42. 2
    2
      Marlin/src/gcode/calibrate/M100.cpp
  43. 4
    4
      Marlin/src/gcode/calibrate/M48.cpp
  44. 1
    1
      Marlin/src/gcode/config/M305.cpp
  45. 4
    4
      Marlin/src/gcode/config/M43.cpp
  46. 1
    1
      Marlin/src/gcode/config/M672.cpp
  47. 1
    1
      Marlin/src/gcode/config/M92.cpp
  48. 1
    1
      Marlin/src/gcode/control/M111.cpp
  49. 1
    1
      Marlin/src/gcode/control/M350_M351.cpp
  50. 1
    1
      Marlin/src/gcode/feature/camera/M240.cpp
  51. 2
    2
      Marlin/src/gcode/feature/digipot/M907-M910.cpp
  52. 1
    1
      Marlin/src/gcode/feature/leds/M7219.cpp
  53. 1
    1
      Marlin/src/gcode/host/M114.cpp
  54. 2
    2
      Marlin/src/gcode/queue.cpp
  55. 44
    0
      Marlin/src/inc/Conditionals_LCD.h
  56. 4
    0
      Marlin/src/inc/Conditionals_adv.h
  57. 0
    47
      Marlin/src/inc/Conditionals_post.h
  58. 2
    2
      Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp
  59. 1
    1
      Marlin/src/lcd/dogm/status_screen_DOGM.cpp
  60. 4
    4
      Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp
  61. 2
    2
      Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp
  62. 1
    1
      Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp
  63. 1
    1
      Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h
  64. 2
    2
      Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/western_char_set.cpp
  65. 1
    1
      Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp
  66. 2
    2
      Marlin/src/lcd/extui_malyan_lcd.cpp
  67. 3
    3
      Marlin/src/lcd/menu/game/brickout.cpp
  68. 3
    3
      Marlin/src/lcd/menu/game/invaders.cpp
  69. 1
    1
      Marlin/src/lcd/menu/game/maze.cpp
  70. 7
    7
      Marlin/src/lcd/menu/game/snake.cpp
  71. 8
    8
      Marlin/src/lcd/menu/menu_advanced.cpp
  72. 4
    4
      Marlin/src/lcd/menu/menu_filament.cpp
  73. 1
    1
      Marlin/src/lcd/menu/menu_mixer.cpp
  74. 1
    1
      Marlin/src/lcd/menu/menu_mmu2.cpp
  75. 1
    1
      Marlin/src/lcd/menu/menu_motion.cpp
  76. 2
    2
      Marlin/src/lcd/menu/menu_temperature.cpp
  77. 2
    2
      Marlin/src/lcd/menu/menu_tune.cpp
  78. 1
    1
      Marlin/src/lcd/ultralcd.cpp
  79. 1
    1
      Marlin/src/libs/L64XX/L64XX_Marlin.cpp
  80. 4
    4
      Marlin/src/libs/nozzle.cpp
  81. 6
    6
      Marlin/src/libs/vector_3.cpp
  82. 3
    3
      Marlin/src/module/configuration_store.cpp
  83. 1
    1
      Marlin/src/module/endstops.cpp
  84. 2
    2
      Marlin/src/module/planner.cpp
  85. 2
    2
      Marlin/src/module/planner.h
  86. 2
    2
      Marlin/src/module/probe.cpp
  87. 2
    2
      Marlin/src/module/stepper.cpp
  88. 2
    2
      Marlin/src/module/temperature.cpp
  89. 1
    1
      Marlin/src/module/tool_change.cpp
  90. 1
    1
      Marlin/src/pins/pinsDebug.h
  91. 5
    5
      Marlin/src/sd/Sd2Card.cpp
  92. 5
    5
      Marlin/src/sd/SdBaseFile.cpp
  93. 3
    3
      Marlin/src/sd/cardreader.cpp

+ 2
- 2
Marlin/src/HAL/AVR/HAL_SPI.cpp 查看文件

@@ -197,7 +197,7 @@ void spiBegin() {
197 197
     // output pin high - like sending 0xFF
198 198
     WRITE(MOSI_PIN, HIGH);
199 199
 
200
-    for (uint8_t i = 0; i < 8; i++) {
200
+    LOOP_L_N(i, 8) {
201 201
       WRITE(SCK_PIN, HIGH);
202 202
 
203 203
       nop; // adjust so SCK is nice
@@ -224,7 +224,7 @@ void spiBegin() {
224 224
   void spiSend(uint8_t data) {
225 225
     // no interrupts during byte send - about 8µs
226 226
     cli();
227
-    for (uint8_t i = 0; i < 8; i++) {
227
+    LOOP_L_N(i, 8) {
228 228
       WRITE(SCK_PIN, LOW);
229 229
       WRITE(MOSI_PIN, data & 0x80);
230 230
       data <<= 1;

+ 1
- 1
Marlin/src/HAL/AVR/MarlinSerial.cpp 查看文件

@@ -682,7 +682,7 @@
682 682
 
683 683
     // Round correctly so that print(1.999, 2) prints as "2.00"
684 684
     double rounding = 0.5;
685
-    for (uint8_t i = 0; i < digits; ++i) rounding *= 0.1;
685
+    LOOP_L_N(i, digits) rounding *= 0.1;
686 686
     number += rounding;
687 687
 
688 688
     // Extract the integer part of the number and print it

+ 1
- 1
Marlin/src/HAL/AVR/fast_pwm.cpp 查看文件

@@ -167,7 +167,7 @@ void set_pwm_frequency(const pin_t pin, int f_desired) {
167 167
     uint16_t prescaler[] = { 0, 1, 8, /*TIMER2 ONLY*/32, 64, /*TIMER2 ONLY*/128, 256, 1024 };
168 168
 
169 169
     // loop over prescaler values
170
-    for (uint8_t i = 1; i < 8; i++) {
170
+    LOOP_S_L_N(i, 1, 8) {
171 171
       uint16_t res_temp_fast = 255, res_temp_phase_correct = 255;
172 172
       if (timer.n == 2) {
173 173
         // No resolution calculation for TIMER2 unless enabled USE_OCR2A_AS_TOP

+ 2
- 2
Marlin/src/HAL/AVR/pinsDebug.h 查看文件

@@ -70,12 +70,12 @@
70 70
 
71 71
 void PRINT_ARRAY_NAME(uint8_t x) {
72 72
   char *name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
73
-  for (uint8_t y = 0; y < MAX_NAME_LENGTH; y++) {
73
+  LOOP_L_N(y, MAX_NAME_LENGTH) {
74 74
     char temp_char = pgm_read_byte(name_mem_pointer + y);
75 75
     if (temp_char != 0)
76 76
       SERIAL_CHAR(temp_char);
77 77
     else {
78
-      for (uint8_t i = 0; i < MAX_NAME_LENGTH - y; i++) SERIAL_CHAR(' ');
78
+      LOOP_L_N(i, MAX_NAME_LENGTH - y) SERIAL_CHAR(' ');
79 79
       break;
80 80
     }
81 81
   }

+ 2
- 2
Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp 查看文件

@@ -88,7 +88,7 @@ void u8g_spiSend_sw_AVR_mode_0(uint8_t val) {
88 88
   volatile uint8_t *outData = u8g_outData,
89 89
                    *outClock = u8g_outClock;
90 90
   U8G_ATOMIC_START();
91
-  for (uint8_t i = 0; i < 8; i++) {
91
+  LOOP_L_N(i, 8) {
92 92
     if (val & 0x80)
93 93
       *outData |= bitData;
94 94
     else
@@ -108,7 +108,7 @@ void u8g_spiSend_sw_AVR_mode_3(uint8_t val) {
108 108
   volatile uint8_t *outData = u8g_outData,
109 109
                    *outClock = u8g_outClock;
110 110
   U8G_ATOMIC_START();
111
-  for (uint8_t i = 0; i < 8; i++) {
111
+  LOOP_L_N(i, 8) {
112 112
     *outClock &= bitNotClock;
113 113
     if (val & 0x80)
114 114
       *outData |= bitData;

+ 1
- 1
Marlin/src/HAL/DUE/MarlinSerial.cpp 查看文件

@@ -606,7 +606,7 @@ void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {
606 606
 
607 607
   // Round correctly so that print(1.999, 2) prints as "2.00"
608 608
   double rounding = 0.5;
609
-  for (uint8_t i = 0; i < digits; ++i) rounding *= 0.1;
609
+  LOOP_L_N(i, digits) rounding *= 0.1;
610 610
   number += rounding;
611 611
 
612 612
   // Extract the integer part of the number and print it

+ 1
- 1
Marlin/src/HAL/DUE/MarlinSerialUSB.cpp 查看文件

@@ -259,7 +259,7 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
259 259
 
260 260
   // Round correctly so that print(1.999, 2) prints as "2.00"
261 261
   double rounding = 0.5;
262
-  for (uint8_t i = 0; i < digits; ++i)
262
+  LOOP_L_N(i, digits)
263 263
     rounding *= 0.1;
264 264
 
265 265
   number += rounding;

+ 2
- 2
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp 查看文件

@@ -80,7 +80,7 @@ Pio *SCK_pPio, *MOSI_pPio;
80 80
 uint32_t SCK_dwMask, MOSI_dwMask;
81 81
 
82 82
 void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
83
-  for (uint8_t i = 0; i < 8; i++) {
83
+  LOOP_L_N(i, 8) {
84 84
     if (val & 0x80)
85 85
       MOSI_pPio->PIO_SODR = MOSI_dwMask;
86 86
     else
@@ -94,7 +94,7 @@ void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
94 94
 }
95 95
 
96 96
 void u8g_spiSend_sw_DUE_mode_3(uint8_t val) { // 3.5MHz
97
-  for (uint8_t i = 0; i < 8; i++) {
97
+  LOOP_L_N(i, 8) {
98 98
     SCK_pPio->PIO_CODR = SCK_dwMask;
99 99
     DELAY_NS(50);
100 100
     if (val & 0x80)

+ 1
- 1
Marlin/src/HAL/DUE/fastio/G2_PWM.h 查看文件

@@ -63,7 +63,7 @@ extern PWM_map ISR_table[NUM_PWMS];
63 63
 extern uint32_t motor_current_setting[3];
64 64
 
65 65
 #define IR_BIT(p) (WITHIN(p, 0, 3) ? (p) : (p) + 4)
66
-#define COPY_ACTIVE_TABLE() do{ for (uint8_t i = 0; i < 6 ; i++) work_table[i] = active_table[i]; }while(0)
66
+#define COPY_ACTIVE_TABLE() do{ LOOP_L_N(i, 6) work_table[i] = active_table[i]; }while(0)
67 67
 
68 68
 #define PWM_MR0 19999         // base repetition rate minus one count - 20mS
69 69
 #define PWM_PR 24             // prescaler value - prescaler divide by 24 + 1  -  1 MHz output

+ 1
- 1
Marlin/src/HAL/LPC1768/main.cpp 查看文件

@@ -67,7 +67,7 @@ void HAL_init() {
67 67
     #endif
68 68
 
69 69
     // Flash status LED 3 times to indicate Marlin has started booting
70
-    for (uint8_t i = 0; i < 6; ++i) {
70
+    LOOP_L_N(i, 6) {
71 71
       TOGGLE(LED_PIN);
72 72
       delay(100);
73 73
     }

+ 8
- 8
Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp 查看文件

@@ -73,7 +73,7 @@
73 73
 
74 74
 uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin ) {
75 75
 
76
-  for (uint8_t i = 0; i < 8; i++) {
76
+  LOOP_L_N(i, 8) {
77 77
     if (spi_speed == 0) {
78 78
       LPC176x::gpio_set(mosi_pin, !!(b & 0x80));
79 79
       LPC176x::gpio_set(sck_pin, HIGH);
@@ -83,16 +83,16 @@ uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck
83 83
     }
84 84
     else {
85 85
       const uint8_t state = (b & 0x80) ? HIGH : LOW;
86
-      for (uint8_t j = 0; j < spi_speed; j++)
86
+      LOOP_L_N(j, spi_speed)
87 87
         LPC176x::gpio_set(mosi_pin, state);
88 88
 
89
-      for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
89
+      LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
90 90
         LPC176x::gpio_set(sck_pin, HIGH);
91 91
 
92 92
       b <<= 1;
93 93
       if (miso_pin >= 0 && LPC176x::gpio_get(miso_pin)) b |= 1;
94 94
 
95
-      for (uint8_t j = 0; j < spi_speed; j++)
95
+      LOOP_L_N(j, spi_speed)
96 96
         LPC176x::gpio_set(sck_pin, LOW);
97 97
     }
98 98
   }
@@ -102,7 +102,7 @@ uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck
102 102
 
103 103
 uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin ) {
104 104
 
105
-  for (uint8_t i = 0; i < 8; i++) {
105
+  LOOP_L_N(i, 8) {
106 106
     const uint8_t state = (b & 0x80) ? HIGH : LOW;
107 107
     if (spi_speed == 0) {
108 108
       LPC176x::gpio_set(sck_pin, LOW);
@@ -111,13 +111,13 @@ uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck
111 111
       LPC176x::gpio_set(sck_pin, HIGH);
112 112
     }
113 113
     else {
114
-      for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
114
+      LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
115 115
         LPC176x::gpio_set(sck_pin, LOW);
116 116
 
117
-      for (uint8_t j = 0; j < spi_speed; j++)
117
+      LOOP_L_N(j, spi_speed)
118 118
         LPC176x::gpio_set(mosi_pin, state);
119 119
 
120
-      for (uint8_t j = 0; j < spi_speed; j++)
120
+      LOOP_L_N(j, spi_speed)
121 121
         LPC176x::gpio_set(sck_pin, HIGH);
122 122
     }
123 123
     b <<= 1;

+ 3
- 3
Marlin/src/HAL/SAMD51/HAL.cpp 查看文件

@@ -478,10 +478,10 @@ void HAL_adc_init() {
478 478
   #if ADC_IS_REQUIRED
479 479
     memset(HAL_adc_results, 0xFF, sizeof(HAL_adc_results));                 // Fill result with invalid values
480 480
 
481
-    for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi)
481
+    LOOP_L_N(pi, COUNT(adc_pins))
482 482
       pinPeripheral(adc_pins[pi], PIO_ANALOG);
483 483
 
484
-    for (uint8_t ai = FIRST_ADC; ai <= LAST_ADC; ++ai) {
484
+    LOOP_S_LE_N(ai, FIRST_ADC, LAST_ADC) {
485 485
       Adc* adc = ((Adc*[])ADC_INSTS)[ai];
486 486
 
487 487
       // ADC clock setup
@@ -513,7 +513,7 @@ void HAL_adc_init() {
513 513
 
514 514
 void HAL_adc_start_conversion(const uint8_t adc_pin) {
515 515
   #if ADC_IS_REQUIRED
516
-    for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi) {
516
+    LOOP_L_N(pi, COUNT(adc_pins)) {
517 517
       if (adc_pin == adc_pins[pi]) {
518 518
         HAL_adc_result = HAL_adc_results[pi];
519 519
         return;

+ 1
- 1
Marlin/src/HAL/STM32/fastio.cpp 查看文件

@@ -27,7 +27,7 @@
27 27
 GPIO_TypeDef* FastIOPortMap[LastPort + 1];
28 28
 
29 29
 void FastIO_init() {
30
-  for (uint8_t i = 0; i < NUM_DIGITAL_PINS; i++)
30
+  LOOP_L_N(i, NUM_DIGITAL_PINS)
31 31
     FastIOPortMap[STM_PORT(digitalPin[i])] = get_GPIO_Port(STM_PORT(digitalPin[i]));
32 32
 }
33 33
 

+ 8
- 8
Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp 查看文件

@@ -32,7 +32,7 @@
32 32
 static uint8_t SPI_speed = SPI_SPEED;
33 33
 
34 34
 static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
35
-  for (uint8_t i = 0; i < 8; i++) {
35
+  LOOP_L_N(i, 8) {
36 36
     if (spi_speed == 0) {
37 37
       WRITE(DOGLCD_MOSI, !!(b & 0x80));
38 38
       WRITE(DOGLCD_SCK, HIGH);
@@ -42,16 +42,16 @@ static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, c
42 42
     }
43 43
     else {
44 44
       const uint8_t state = (b & 0x80) ? HIGH : LOW;
45
-      for (uint8_t j = 0; j < spi_speed; j++)
45
+      LOOP_L_N(j, spi_speed)
46 46
         WRITE(DOGLCD_MOSI, state);
47 47
 
48
-      for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
48
+      LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
49 49
         WRITE(DOGLCD_SCK, HIGH);
50 50
 
51 51
       b <<= 1;
52 52
       if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
53 53
 
54
-      for (uint8_t j = 0; j < spi_speed; j++)
54
+      LOOP_L_N(j, spi_speed)
55 55
         WRITE(DOGLCD_SCK, LOW);
56 56
     }
57 57
   }
@@ -59,7 +59,7 @@ static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, c
59 59
 }
60 60
 
61 61
 static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
62
-  for (uint8_t i = 0; i < 8; i++) {
62
+  LOOP_L_N(i, 8) {
63 63
     const uint8_t state = (b & 0x80) ? HIGH : LOW;
64 64
     if (spi_speed == 0) {
65 65
       WRITE(DOGLCD_SCK, LOW);
@@ -68,13 +68,13 @@ static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, c
68 68
       WRITE(DOGLCD_SCK, HIGH);
69 69
     }
70 70
     else {
71
-      for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
71
+      LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
72 72
         WRITE(DOGLCD_SCK, LOW);
73 73
 
74
-      for (uint8_t j = 0; j < spi_speed; j++)
74
+      LOOP_L_N(j, spi_speed)
75 75
         WRITE(DOGLCD_MOSI, state);
76 76
 
77
-      for (uint8_t j = 0; j < spi_speed; j++)
77
+      LOOP_L_N(j, spi_speed)
78 78
         WRITE(DOGLCD_SCK, HIGH);
79 79
     }
80 80
     b <<= 1;

+ 1
- 1
Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp 查看文件

@@ -102,7 +102,7 @@ void eeprom_read_block(void *__dst, const void *__src, size_t __n) {
102 102
 
103 103
   uint16_t data = 0xFF;
104 104
   uint16_t eeprom_address = unsigned(__src);
105
-  for (uint8_t c = 0; c < __n; c++) {
105
+  LOOP_L_N(c, __n) {
106 106
     EE_ReadVariable(eeprom_address+c, &data);
107 107
     *((uint8_t*)__dst + c) = data;
108 108
   }

+ 1
- 1
Marlin/src/HAL/shared/servo.cpp 查看文件

@@ -68,7 +68,7 @@ uint8_t ServoCount = 0;                         // the total number of attached
68 68
 
69 69
 static boolean isTimerActive(timer16_Sequence_t timer) {
70 70
   // returns true if any servo is active on this timer
71
-  for (uint8_t channel = 0; channel < SERVOS_PER_TIMER; channel++) {
71
+  LOOP_L_N(channel, SERVOS_PER_TIMER) {
72 72
     if (SERVO(timer, channel).Pin.isActive)
73 73
       return true;
74 74
   }

+ 1
- 1
Marlin/src/MarlinCore.cpp 查看文件

@@ -274,7 +274,7 @@ void setup_powerhold() {
274 274
 
275 275
 bool pin_is_protected(const pin_t pin) {
276 276
   static const pin_t sensitive_pins[] PROGMEM = SENSITIVE_PINS;
277
-  for (uint8_t i = 0; i < COUNT(sensitive_pins); i++) {
277
+  LOOP_L_N(i, COUNT(sensitive_pins)) {
278 278
     pin_t sensitive_pin;
279 279
     memcpy_P(&sensitive_pin, &sensitive_pins[i], sizeof(pin_t));
280 280
     if (pin == sensitive_pin) return true;

+ 5
- 0
Marlin/src/core/macros.h 查看文件

@@ -248,6 +248,11 @@
248 248
 #define _JOIN_1(O)         (O)
249 249
 #define JOIN_N(N,C,V...)   (DO(JOIN,C,LIST_N(N,V)))
250 250
 
251
+#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
252
+#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
253
+#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
254
+#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
255
+
251 256
 #define NOOP (void(0))
252 257
 
253 258
 #define CEILING(x,y) (((x) + (y) - 1) / (y))

+ 0
- 6
Marlin/src/core/types.h 查看文件

@@ -50,12 +50,6 @@ enum AxisEnum : uint8_t {
50 50
 //
51 51
 // Loop over XYZE axes
52 52
 //
53
-
54
-#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
55
-#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
56
-#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
57
-#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
58
-
59 53
 #define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
60 54
 #define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
61 55
 #define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)

+ 9
- 9
Marlin/src/feature/bedlevel/abl/abl.cpp 查看文件

@@ -115,8 +115,8 @@ void extrapolate_unprobed_bed_level() {
115 115
                       ylen = ctry1;
116 116
   #endif
117 117
 
118
-  for (uint8_t xo = 0; xo <= xlen; xo++)
119
-    for (uint8_t yo = 0; yo <= ylen; yo++) {
118
+  LOOP_LE_N(xo, xlen)
119
+    LOOP_LE_N(yo, ylen) {
120 120
       uint8_t x2 = ctrx2 + xo, y2 = ctry2 + yo;
121 121
       #ifndef HALF_IN_X
122 122
         const uint8_t x1 = ctrx1 - xo;
@@ -209,8 +209,8 @@ void print_bilinear_leveling_grid() {
209 209
 
210 210
   static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
211 211
     float row[4], column[4];
212
-    for (uint8_t i = 0; i < 4; i++) {
213
-      for (uint8_t j = 0; j < 4; j++) {
212
+    LOOP_L_N(i, 4) {
213
+      LOOP_L_N(j, 4) {
214 214
         column[j] = bed_level_virt_coord(i + x - 1, j + y - 1);
215 215
       }
216 216
       row[i] = bed_level_virt_cmr(column, 1, ty);
@@ -221,11 +221,11 @@ void print_bilinear_leveling_grid() {
221 221
   void bed_level_virt_interpolate() {
222 222
     bilinear_grid_spacing_virt = bilinear_grid_spacing / (BILINEAR_SUBDIVISIONS);
223 223
     bilinear_grid_factor_virt = bilinear_grid_spacing_virt.reciprocal();
224
-    for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
225
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
226
-        for (uint8_t ty = 0; ty < BILINEAR_SUBDIVISIONS; ty++)
227
-          for (uint8_t tx = 0; tx < BILINEAR_SUBDIVISIONS; tx++) {
228
-            if ((ty && y == GRID_MAX_POINTS_Y - 1) || (tx && x == GRID_MAX_POINTS_X - 1))
224
+    LOOP_L_N(y, GRID_MAX_POINTS_Y)
225
+      LOOP_L_N(x, GRID_MAX_POINTS_X)
226
+        LOOP_L_N(ty, BILINEAR_SUBDIVISIONS)
227
+          LOOP_L_N(tx, BILINEAR_SUBDIVISIONS) {
228
+            if ((ty && y == (GRID_MAX_POINTS_Y) - 1) || (tx && x == (GRID_MAX_POINTS_X) - 1))
229 229
               continue;
230 230
             z_values_virt[x * (BILINEAR_SUBDIVISIONS) + tx][y * (BILINEAR_SUBDIVISIONS) + ty] =
231 231
               bed_level_virt_2cmr(

+ 10
- 11
Marlin/src/feature/bedlevel/bedlevel.cpp 查看文件

@@ -143,13 +143,12 @@ void reset_bed_level() {
143 143
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
144 144
       bilinear_start.reset();
145 145
       bilinear_grid_spacing.reset();
146
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
147
-        for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
148
-          z_values[x][y] = NAN;
149
-          #if ENABLED(EXTENSIBLE_UI)
150
-            ExtUI::onMeshUpdate(x, y, 0);
151
-          #endif
152
-        }
146
+      GRID_LOOP(x, y) {
147
+        z_values[x][y] = NAN;
148
+        #if ENABLED(EXTENSIBLE_UI)
149
+          ExtUI::onMeshUpdate(x, y, 0);
150
+        #endif
151
+      }
153 152
     #elif ABL_PLANAR
154 153
       planner.bed_level_matrix.set_to_identity();
155 154
     #endif
@@ -173,7 +172,7 @@ void reset_bed_level() {
173 172
    */
174 173
   void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, element_2d_fn fn) {
175 174
     #ifndef SCAD_MESH_OUTPUT
176
-      for (uint8_t x = 0; x < sx; x++) {
175
+      LOOP_L_N(x, sx) {
177 176
         serial_spaces(precision + (x < 10 ? 3 : 2));
178 177
         SERIAL_ECHO(int(x));
179 178
       }
@@ -182,14 +181,14 @@ void reset_bed_level() {
182 181
     #ifdef SCAD_MESH_OUTPUT
183 182
       SERIAL_ECHOLNPGM("measured_z = ["); // open 2D array
184 183
     #endif
185
-    for (uint8_t y = 0; y < sy; y++) {
184
+    LOOP_L_N(y, sy) {
186 185
       #ifdef SCAD_MESH_OUTPUT
187 186
         SERIAL_ECHOPGM(" [");             // open sub-array
188 187
       #else
189 188
         if (y < 10) SERIAL_CHAR(' ');
190 189
         SERIAL_ECHO(int(y));
191 190
       #endif
192
-      for (uint8_t x = 0; x < sx; x++) {
191
+      LOOP_L_N(x, sx) {
193 192
         SERIAL_CHAR(' ');
194 193
         const float offset = fn(x, y);
195 194
         if (!isnan(offset)) {
@@ -202,7 +201,7 @@ void reset_bed_level() {
202 201
               SERIAL_CHAR(' ');
203 202
             SERIAL_ECHOPGM("NAN");
204 203
           #else
205
-            for (uint8_t i = 0; i < precision + 3; i++)
204
+            LOOP_L_N(i, precision + 3)
206 205
               SERIAL_CHAR(i ? '=' : ' ');
207 206
           #endif
208 207
         }

+ 3
- 5
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp 查看文件

@@ -40,9 +40,9 @@
40 40
         mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
41 41
 
42 42
   mesh_bed_leveling::mesh_bed_leveling() {
43
-    for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
43
+    LOOP_L_N(i, GRID_MAX_POINTS_X)
44 44
       index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
45
-    for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i)
45
+    LOOP_L_N(i, GRID_MAX_POINTS_Y)
46 46
       index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
47 47
     reset();
48 48
   }
@@ -51,9 +51,7 @@
51 51
     z_offset = 0;
52 52
     ZERO(z_values);
53 53
     #if ENABLED(EXTENSIBLE_UI)
54
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
55
-        for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
56
-          ExtUI::onMeshUpdate(x, y, 0);
54
+      GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
57 55
     #endif
58 56
   }
59 57
 

+ 1
- 3
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h 查看文件

@@ -52,9 +52,7 @@ public:
52 52
   static void reset();
53 53
 
54 54
   FORCE_INLINE static bool has_mesh() {
55
-    for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
56
-      for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
57
-        if (z_values[x][y]) return true;
55
+    GRID_LOOP(x, y) if (z_values[x][y]) return true;
58 56
     return false;
59 57
   }
60 58
 

+ 8
- 12
Marlin/src/feature/bedlevel/ubl/ubl.cpp 查看文件

@@ -49,7 +49,7 @@
49 49
   void unified_bed_leveling::report_current_mesh() {
50 50
     if (!leveling_is_valid()) return;
51 51
     SERIAL_ECHO_MSG("  G29 I99");
52
-    for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
52
+    LOOP_L_N(x, GRID_MAX_POINTS_X)
53 53
       for (uint8_t y = 0;  y < GRID_MAX_POINTS_Y; y++)
54 54
         if (!isnan(z_values[x][y])) {
55 55
           SERIAL_ECHO_START();
@@ -101,9 +101,7 @@
101 101
     storage_slot = -1;
102 102
     ZERO(z_values);
103 103
     #if ENABLED(EXTENSIBLE_UI)
104
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
105
-        for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
106
-          ExtUI::onMeshUpdate(x, y, 0);
104
+      GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
107 105
     #endif
108 106
     if (was_enabled) report_current_position();
109 107
   }
@@ -114,13 +112,11 @@
114 112
   }
115 113
 
116 114
   void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
117
-    for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
118
-      for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
119
-        z_values[x][y] = value;
120
-        #if ENABLED(EXTENSIBLE_UI)
121
-          ExtUI::onMeshUpdate(x, y, value);
122
-        #endif
123
-      }
115
+    GRID_LOOP(x, y) {
116
+      z_values[x][y] = value;
117
+      #if ENABLED(EXTENSIBLE_UI)
118
+        ExtUI::onMeshUpdate(x, y, value);
119
+      #endif
124 120
     }
125 121
   }
126 122
 
@@ -190,7 +186,7 @@
190 186
       }
191 187
 
192 188
       // Row Values (I indexes)
193
-      for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
189
+      LOOP_L_N(i, GRID_MAX_POINTS_X) {
194 190
 
195 191
         // Opening Brace or Space
196 192
         const bool is_current = i == curr.x && j == curr.y;

+ 1
- 3
Marlin/src/feature/bedlevel/ubl/ubl.h 查看文件

@@ -298,9 +298,7 @@ class unified_bed_leveling {
298 298
     #endif
299 299
 
300 300
     static inline bool mesh_is_valid() {
301
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
302
-        for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
303
-          if (isnan(z_values[x][y])) return false;
301
+      GRID_LOOP(x, y) if (isnan(z_values[x][y])) return false;
304 302
       return true;
305 303
     }
306 304
 

+ 130
- 151
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp 查看文件

@@ -365,25 +365,23 @@
365 365
         #endif
366 366
 
367 367
         case 0:
368
-          for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {   // Create a bowl shape - similar to
369
-            for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
370
-              const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
371
-                          p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
372
-              z_values[x][y] += 2.0f * HYPOT(p1, p2);
373
-              #if ENABLED(EXTENSIBLE_UI)
374
-                ExtUI::onMeshUpdate(x, y, z_values[x][y]);
375
-              #endif
376
-            }
368
+          GRID_LOOP(x, y) {                                     // Create a bowl shape similar to a poorly-calibrated Delta
369
+            const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
370
+                        p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
371
+            z_values[x][y] += 2.0f * HYPOT(p1, p2);
372
+            #if ENABLED(EXTENSIBLE_UI)
373
+              ExtUI::onMeshUpdate(x, y, z_values[x][y]);
374
+            #endif
377 375
           }
378 376
           break;
379 377
 
380 378
         case 1:
381
-          for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {  // Create a diagonal line several Mesh cells thick that is raised
379
+          LOOP_L_N(x, GRID_MAX_POINTS_X) {                     // Create a diagonal line several Mesh cells thick that is raised
382 380
             z_values[x][x] += 9.999f;
383
-            z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
381
+            z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
384 382
             #if ENABLED(EXTENSIBLE_UI)
385 383
               ExtUI::onMeshUpdate(x, x, z_values[x][x]);
386
-              ExtUI::onMeshUpdate(x, (x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1), z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1]);
384
+              ExtUI::onMeshUpdate(x, (x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1), z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1]);
387 385
             #endif
388 386
 
389 387
           }
@@ -467,7 +465,7 @@
467 465
             //
468 466
             // Manually Probe Mesh in areas that can't be reached by the probe
469 467
             //
470
-            SERIAL_ECHOLNPGM("Manually probing unreachable mesh locations.");
468
+            SERIAL_ECHOLNPGM("Manually probing unreachable points.");
471 469
             do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
472 470
 
473 471
             if (parser.seen('C') && !xy_seen) {
@@ -537,9 +535,7 @@
537 535
                 if (cpos.x < 0) {
538 536
                   // No more REAL INVALID mesh points to populate, so we ASSUME
539 537
                   // user meant to populate ALL INVALID mesh points to value
540
-                  for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
541
-                    for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
542
-                      if (isnan(z_values[x][y])) z_values[x][y] = g29_constant;
538
+                  GRID_LOOP(x, y) if (isnan(z_values[x][y])) z_values[x][y] = g29_constant;
543 539
                   break; // No more invalid Mesh Points to populate
544 540
                 }
545 541
                 else {
@@ -696,12 +692,11 @@
696 692
   void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
697 693
     float sum = 0;
698 694
     int n = 0;
699
-    for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
700
-      for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
701
-        if (!isnan(z_values[x][y])) {
702
-          sum += z_values[x][y];
703
-          n++;
704
-        }
695
+    GRID_LOOP(x, y)
696
+      if (!isnan(z_values[x][y])) {
697
+        sum += z_values[x][y];
698
+        n++;
699
+      }
705 700
 
706 701
     const float mean = sum / n;
707 702
 
@@ -709,10 +704,9 @@
709 704
     // Sum the squares of difference from mean
710 705
     //
711 706
     float sum_of_diff_squared = 0;
712
-    for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
713
-      for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
714
-        if (!isnan(z_values[x][y]))
715
-          sum_of_diff_squared += sq(z_values[x][y] - mean);
707
+    GRID_LOOP(x, y)
708
+      if (!isnan(z_values[x][y]))
709
+        sum_of_diff_squared += sq(z_values[x][y] - mean);
716 710
 
717 711
     SERIAL_ECHOLNPAIR("# of samples: ", n);
718 712
     SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6);
@@ -721,27 +715,25 @@
721 715
     SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
722 716
 
723 717
     if (cflag)
724
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
725
-        for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
726
-          if (!isnan(z_values[x][y])) {
727
-            z_values[x][y] -= mean + value;
728
-            #if ENABLED(EXTENSIBLE_UI)
729
-              ExtUI::onMeshUpdate(x, y, z_values[x][y]);
730
-            #endif
731
-          }
732
-  }
733
-
734
-  void unified_bed_leveling::shift_mesh_height() {
735
-    for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
736
-      for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
718
+      GRID_LOOP(x, y)
737 719
         if (!isnan(z_values[x][y])) {
738
-          z_values[x][y] += g29_constant;
720
+          z_values[x][y] -= mean + value;
739 721
           #if ENABLED(EXTENSIBLE_UI)
740 722
             ExtUI::onMeshUpdate(x, y, z_values[x][y]);
741 723
           #endif
742 724
         }
743 725
   }
744 726
 
727
+  void unified_bed_leveling::shift_mesh_height() {
728
+    GRID_LOOP(x, y)
729
+      if (!isnan(z_values[x][y])) {
730
+        z_values[x][y] += g29_constant;
731
+        #if ENABLED(EXTENSIBLE_UI)
732
+          ExtUI::onMeshUpdate(x, y, z_values[x][y]);
733
+        #endif
734
+      }
735
+  }
736
+
745 737
   #if HAS_BED_PROBE
746 738
     /**
747 739
      * Probe all invalidated locations of the mesh that can be reached by the probe.
@@ -1243,52 +1235,46 @@
1243 1235
 
1244 1236
     mesh_index_pair farthest { -1, -1, -99999.99 };
1245 1237
 
1246
-    for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1247
-      for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1238
+    GRID_LOOP(i, j) {
1239
+      if (!isnan(z_values[i][j])) continue;  // Skip valid mesh points
1248 1240
 
1249
-        if (isnan(z_values[i][j])) {                  // Invalid mesh point?
1241
+      // Skip unreachable points
1242
+      if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
1243
+        continue;
1250 1244
 
1251
-          // Skip points the probe can't reach
1252
-          if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
1253
-            continue;
1245
+      found_a_NAN = true;
1254 1246
 
1255
-          found_a_NAN = true;
1247
+      xy_int8_t near { -1, -1 };
1248
+      float d1, d2 = 99999.9f;
1249
+      GRID_LOOP(k, l) {
1250
+        if (isnan(z_values[k][l])) continue;
1256 1251
 
1257
-          xy_int8_t near { -1, -1 };
1258
-          float d1, d2 = 99999.9f;
1259
-          for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
1260
-            for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
1261
-              if (!isnan(z_values[k][l])) {
1262
-                found_a_real = true;
1252
+        found_a_real = true;
1263 1253
 
1264
-                // Add in a random weighting factor that scrambles the probing of the
1265
-                // last half of the mesh (when every unprobed mesh point is one index
1266
-                // from a probed location).
1254
+        // Add in a random weighting factor that scrambles the probing of the
1255
+        // last half of the mesh (when every unprobed mesh point is one index
1256
+        // from a probed location).
1267 1257
 
1268
-                d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
1258
+        d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
1269 1259
 
1270
-                if (d1 < d2) {    // Invalid mesh point (i,j) is closer to the defined point (k,l)
1271
-                  d2 = d1;
1272
-                  near.set(i, j);
1273
-                }
1274
-              }
1275
-            }
1276
-          }
1260
+        if (d1 < d2) {    // Invalid mesh point (i,j) is closer to the defined point (k,l)
1261
+          d2 = d1;
1262
+          near.set(i, j);
1263
+        }
1264
+      }
1277 1265
 
1278
-          //
1279
-          // At this point d2 should have the near defined mesh point to invalid mesh point (i,j)
1280
-          //
1266
+      //
1267
+      // At this point d2 should have the near defined mesh point to invalid mesh point (i,j)
1268
+      //
1281 1269
 
1282
-          if (found_a_real && near.x >= 0 && d2 > farthest.distance) {
1283
-            farthest.pos = near;      // Found an invalid location farther from the defined mesh point
1284
-            farthest.distance = d2;
1285
-          }
1286
-        }
1287
-      } // for j
1288
-    } // for i
1270
+      if (found_a_real && near.x >= 0 && d2 > farthest.distance) {
1271
+        farthest.pos = near;      // Found an invalid location farther from the defined mesh point
1272
+        farthest.distance = d2;
1273
+      }
1274
+    } // GRID_LOOP
1289 1275
 
1290 1276
     if (!found_a_real && found_a_NAN) {        // if the mesh is totally unpopulated, start the probing
1291
-      farthest.pos.set(GRID_MAX_POINTS_X / 2, GRID_MAX_POINTS_Y / 2);
1277
+      farthest.pos.set((GRID_MAX_POINTS_X) / 2, (GRID_MAX_POINTS_Y) / 2);
1292 1278
       farthest.distance = 1;
1293 1279
     }
1294 1280
     return farthest;
@@ -1304,36 +1290,34 @@
1304 1290
 
1305 1291
     float best_so_far = 99999.99f;
1306 1292
 
1307
-    for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1308
-      for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1309
-        if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL))
1310
-          || (type == SET_IN_BITMAP && !done_flags->marked(i, j))
1311
-        ) {
1312
-          // Found a Mesh Point of the specified type!
1313
-          const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
1293
+    GRID_LOOP(i, j) {
1294
+      if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL))
1295
+        || (type == SET_IN_BITMAP && !done_flags->marked(i, j))
1296
+      ) {
1297
+        // Found a Mesh Point of the specified type!
1298
+        const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
1314 1299
 
1315
-          // If using the probe as the reference there are some unreachable locations.
1316
-          // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1317
-          // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1300
+        // If using the probe as the reference there are some unreachable locations.
1301
+        // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1302
+        // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1318 1303
 
1319
-          if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos)))
1320
-            continue;
1304
+        if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos)))
1305
+          continue;
1321 1306
 
1322
-          // Reachable. Check if it's the best_so_far location to the nozzle.
1307
+        // Reachable. Check if it's the best_so_far location to the nozzle.
1323 1308
 
1324
-          const xy_pos_t diff = current_position - mpos;
1325
-          const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f;
1309
+        const xy_pos_t diff = current_position - mpos;
1310
+        const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f;
1326 1311
 
1327
-          // factor in the distance from the current location for the normal case
1328
-          // so the nozzle isn't running all over the bed.
1329
-          if (distance < best_so_far) {
1330
-            best_so_far = distance;   // Found a closer location with the desired value type.
1331
-            closest.pos.set(i, j);
1332
-            closest.distance = best_so_far;
1333
-          }
1312
+        // factor in the distance from the current location for the normal case
1313
+        // so the nozzle isn't running all over the bed.
1314
+        if (distance < best_so_far) {
1315
+          best_so_far = distance;   // Found a closer location with the desired value type.
1316
+          closest.pos.set(i, j);
1317
+          closest.distance = best_so_far;
1334 1318
         }
1335
-      } // for j
1336
-    } // for i
1319
+      }
1320
+    } // GRID_LOOP
1337 1321
 
1338 1322
     return closest;
1339 1323
   }
@@ -1373,7 +1357,7 @@
1373 1357
       info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  };  // Right side of the mesh looking left
1374 1358
     static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
1375 1359
 
1376
-    for (uint8_t i = 0; i < COUNT(info); ++i) {
1360
+    LOOP_L_N(i, COUNT(info)) {
1377 1361
       const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
1378 1362
       const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
1379 1363
                    ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
@@ -1496,12 +1480,13 @@
1496 1480
 
1497 1481
         bool zig_zag = false;
1498 1482
 
1499
-        uint16_t total_points = g29_grid_size * g29_grid_size, point_num = 1;
1483
+        const uint16_t total_points = sq(g29_grid_size);
1484
+        uint16_t point_num = 1;
1500 1485
 
1501 1486
         xy_pos_t rpos;
1502
-        for (uint8_t ix = 0; ix < g29_grid_size; ix++) {
1487
+        LOOP_L_N(ix, g29_grid_size) {
1503 1488
           rpos.x = x_min + ix * dx;
1504
-          for (int8_t iy = 0; iy < g29_grid_size; iy++) {
1489
+          LOOP_L_N(iy, g29_grid_size) {
1505 1490
             rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
1506 1491
 
1507 1492
             if (!abort_flag) {
@@ -1569,39 +1554,37 @@
1569 1554
 
1570 1555
       matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
1571 1556
 
1572
-      for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1573
-        for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1574
-          float mx = mesh_index_to_xpos(i),
1575
-                my = mesh_index_to_ypos(j),
1576
-                mz = z_values[i][j];
1577
-
1578
-          if (DEBUGGING(LEVELING)) {
1579
-            DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
1580
-            DEBUG_CHAR(',');
1581
-            DEBUG_ECHO_F(my, 7);
1582
-            DEBUG_CHAR(',');
1583
-            DEBUG_ECHO_F(mz, 7);
1584
-            DEBUG_ECHOPGM("]   ---> ");
1585
-            DEBUG_DELAY(20);
1586
-          }
1557
+      GRID_LOOP(i, j) {
1558
+        float mx = mesh_index_to_xpos(i),
1559
+              my = mesh_index_to_ypos(j),
1560
+              mz = z_values[i][j];
1561
+
1562
+        if (DEBUGGING(LEVELING)) {
1563
+          DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
1564
+          DEBUG_CHAR(',');
1565
+          DEBUG_ECHO_F(my, 7);
1566
+          DEBUG_CHAR(',');
1567
+          DEBUG_ECHO_F(mz, 7);
1568
+          DEBUG_ECHOPGM("]   ---> ");
1569
+          DEBUG_DELAY(20);
1570
+        }
1587 1571
 
1588
-          apply_rotation_xyz(rotation, mx, my, mz);
1572
+        apply_rotation_xyz(rotation, mx, my, mz);
1589 1573
 
1590
-          if (DEBUGGING(LEVELING)) {
1591
-            DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
1592
-            DEBUG_CHAR(',');
1593
-            DEBUG_ECHO_F(my, 7);
1594
-            DEBUG_CHAR(',');
1595
-            DEBUG_ECHO_F(mz, 7);
1596
-            DEBUG_ECHOLNPGM("]");
1597
-            DEBUG_DELAY(20);
1598
-          }
1599
-
1600
-          z_values[i][j] = mz - lsf_results.D;
1601
-          #if ENABLED(EXTENSIBLE_UI)
1602
-            ExtUI::onMeshUpdate(i, j, z_values[i][j]);
1603
-          #endif
1574
+        if (DEBUGGING(LEVELING)) {
1575
+          DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
1576
+          DEBUG_CHAR(',');
1577
+          DEBUG_ECHO_F(my, 7);
1578
+          DEBUG_CHAR(',');
1579
+          DEBUG_ECHO_F(mz, 7);
1580
+          DEBUG_ECHOLNPGM("]");
1581
+          DEBUG_DELAY(20);
1604 1582
         }
1583
+
1584
+        z_values[i][j] = mz - lsf_results.D;
1585
+        #if ENABLED(EXTENSIBLE_UI)
1586
+          ExtUI::onMeshUpdate(i, j, z_values[i][j]);
1587
+        #endif
1605 1588
       }
1606 1589
 
1607 1590
       if (DEBUGGING(LEVELING)) {
@@ -1661,7 +1644,7 @@
1661 1644
       // being extrapolated so that nearby points will have greater influence on
1662 1645
       // the point being extrapolated.  Then extrapolate the mesh point from WLSF.
1663 1646
 
1664
-      static_assert(GRID_MAX_POINTS_Y <= 16, "GRID_MAX_POINTS_Y too big");
1647
+      static_assert((GRID_MAX_POINTS_Y) <= 16, "GRID_MAX_POINTS_Y too big");
1665 1648
       uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 };
1666 1649
       struct linear_fit_data lsf_results;
1667 1650
 
@@ -1669,23 +1652,20 @@
1669 1652
 
1670 1653
       const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST);
1671 1654
 
1672
-      for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++)
1673
-        for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++)
1674
-          if (!isnan(z_values[jx][jy]))
1675
-            SBI(bitmap[jx], jy);
1655
+      GRID_LOOP(jx, jy) if (!isnan(z_values[jx][jy])) SBI(bitmap[jx], jy);
1676 1656
 
1677 1657
       xy_pos_t ppos;
1678
-      for (uint8_t ix = 0; ix < GRID_MAX_POINTS_X; ix++) {
1658
+      LOOP_L_N(ix, GRID_MAX_POINTS_X) {
1679 1659
         ppos.x = mesh_index_to_xpos(ix);
1680
-        for (uint8_t iy = 0; iy < GRID_MAX_POINTS_Y; iy++) {
1660
+        LOOP_L_N(iy, GRID_MAX_POINTS_Y) {
1681 1661
           ppos.y = mesh_index_to_ypos(iy);
1682 1662
           if (isnan(z_values[ix][iy])) {
1683 1663
             // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
1684 1664
             incremental_LSF_reset(&lsf_results);
1685 1665
             xy_pos_t rpos;
1686
-            for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) {
1666
+            LOOP_L_N(jx, GRID_MAX_POINTS_X) {
1687 1667
               rpos.x = mesh_index_to_xpos(jx);
1688
-              for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) {
1668
+              LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
1689 1669
                 if (TEST(bitmap[jx], jy)) {
1690 1670
                   rpos.y = mesh_index_to_ypos(jy);
1691 1671
                   const float rz = z_values[jx][jy],
@@ -1747,7 +1727,7 @@
1747 1727
       SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);                         serial_delay(50);
1748 1728
 
1749 1729
       SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
1750
-      for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1730
+      LOOP_L_N(i, GRID_MAX_POINTS_X) {
1751 1731
         SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
1752 1732
         SERIAL_ECHOPGM("  ");
1753 1733
         serial_delay(25);
@@ -1755,7 +1735,7 @@
1755 1735
       SERIAL_EOL();
1756 1736
 
1757 1737
       SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
1758
-      for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
1738
+      LOOP_L_N(i, GRID_MAX_POINTS_Y) {
1759 1739
         SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
1760 1740
         SERIAL_ECHOPGM("  ");
1761 1741
         serial_delay(25);
@@ -1840,13 +1820,12 @@
1840 1820
 
1841 1821
       SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh.");
1842 1822
 
1843
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
1844
-        for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
1845
-          z_values[x][y] -= tmp_z_values[x][y];
1846
-          #if ENABLED(EXTENSIBLE_UI)
1847
-            ExtUI::onMeshUpdate(x, y, z_values[x][y]);
1848
-          #endif
1849
-        }
1823
+      GRID_LOOP(x, y) {
1824
+        z_values[x][y] -= tmp_z_values[x][y];
1825
+        #if ENABLED(EXTENSIBLE_UI)
1826
+          ExtUI::onMeshUpdate(x, y, z_values[x][y]);
1827
+        #endif
1828
+      }
1850 1829
     }
1851 1830
 
1852 1831
   #endif // UBL_DEVEL_DEBUGGING

+ 2
- 2
Marlin/src/feature/digipot/digipot_mcp4018.cpp 查看文件

@@ -92,11 +92,11 @@ void digipot_i2c_set_current(const uint8_t channel, const float current) {
92 92
 void digipot_i2c_init() {
93 93
   static const float digipot_motor_current[] PROGMEM = DIGIPOT_I2C_MOTOR_CURRENTS;
94 94
 
95
-  for (uint8_t i = 0; i < DIGIPOT_I2C_NUM_CHANNELS; i++)
95
+  LOOP_L_N(i, DIGIPOT_I2C_NUM_CHANNELS)
96 96
     pots[i].i2c_init();
97 97
 
98 98
   // setup initial currents as defined in Configuration_adv.h
99
-  for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++)
99
+  LOOP_L_N(i, COUNT(digipot_motor_current))
100 100
     digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
101 101
 }
102 102
 

+ 1
- 1
Marlin/src/feature/digipot/digipot_mcp4451.cpp 查看文件

@@ -83,7 +83,7 @@ void digipot_i2c_init() {
83 83
   #endif
84 84
   // setup initial currents as defined in Configuration_adv.h
85 85
   static const float digipot_motor_current[] PROGMEM = DIGIPOT_I2C_MOTOR_CURRENTS;
86
-  for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++)
86
+  LOOP_L_N(i, COUNT(digipot_motor_current))
87 87
     digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
88 88
 }
89 89
 

+ 1
- 1
Marlin/src/feature/filwidth.cpp 查看文件

@@ -42,7 +42,7 @@ int8_t FilamentWidthSensor::ratios[MAX_MEASUREMENT_DELAY + 1],          // Ring
42 42
 
43 43
 void FilamentWidthSensor::init() {
44 44
   const int8_t ratio = sample_to_size_ratio();
45
-  for (uint8_t i = 0; i < COUNT(ratios); ++i) ratios[i] = ratio;
45
+  LOOP_L_N(i, COUNT(ratios)) ratios[i] = ratio;
46 46
   index_r = index_w = 0;
47 47
 }
48 48
 

+ 3
- 3
Marlin/src/feature/fwretract.cpp 查看文件

@@ -73,7 +73,7 @@ void FWRetract::reset() {
73 73
   settings.swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
74 74
   current_hop = 0.0;
75 75
 
76
-  for (uint8_t i = 0; i < EXTRUDERS; ++i) {
76
+  LOOP_L_N(i, EXTRUDERS) {
77 77
     retracted[i] = false;
78 78
     #if EXTRUDERS > 1
79 79
       retracted_swap[i] = false;
@@ -117,7 +117,7 @@ void FWRetract::retract(const bool retracting
117 117
       " swapping ", swapping,
118 118
       " active extruder ", active_extruder
119 119
     );
120
-    for (uint8_t i = 0; i < EXTRUDERS; ++i) {
120
+    LOOP_L_N(i, EXTRUDERS) {
121 121
       SERIAL_ECHOLNPAIR("retracted[", i, "] ", retracted[i]);
122 122
       #if EXTRUDERS > 1
123 123
         SERIAL_ECHOLNPAIR("retracted_swap[", i, "] ", retracted_swap[i]);
@@ -201,7 +201,7 @@ void FWRetract::retract(const bool retracting
201 201
     SERIAL_ECHOLNPAIR("retracting ", retracting);
202 202
     SERIAL_ECHOLNPAIR("swapping ", swapping);
203 203
     SERIAL_ECHOLNPAIR("active_extruder ", active_extruder);
204
-    for (uint8_t i = 0; i < EXTRUDERS; ++i) {
204
+    LOOP_L_N(i, EXTRUDERS) {
205 205
       SERIAL_ECHOLNPAIR("retracted[", i, "] ", retracted[i]);
206 206
       #if EXTRUDERS > 1
207 207
         SERIAL_ECHOLNPAIR("retracted_swap[", i, "] ", retracted_swap[i]);

+ 11
- 11
Marlin/src/feature/max7219.cpp 查看文件

@@ -147,7 +147,7 @@ void Max7219::error(const char * const func, const int32_t v1, const int32_t v2/
147 147
  */
148 148
 inline uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) {
149 149
   uint32_t mask = 1, outbits = 0;
150
-  for (uint8_t b = 0; b < n_bytes * 8; b++) {
150
+  LOOP_L_N(b, n_bytes * 8) {
151 151
     outbits <<= 1;
152 152
     if (bits & mask) outbits |= 1;
153 153
     mask <<= 1;
@@ -329,13 +329,13 @@ void Max7219::fill() {
329 329
 
330 330
 void Max7219::clear_row(const uint8_t row) {
331 331
   if (row >= MAX7219_Y_LEDS) return error(PSTR("clear_row"), row);
332
-  for (uint8_t x = 0; x < MAX7219_X_LEDS; x++) CLR_7219(x, row);
332
+  LOOP_L_N(x, MAX7219_X_LEDS) CLR_7219(x, row);
333 333
   send_row(row);
334 334
 }
335 335
 
336 336
 void Max7219::clear_column(const uint8_t col) {
337 337
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
338
-  for (uint8_t y = 0; y < MAX7219_Y_LEDS; y++) CLR_7219(col, y);
338
+  LOOP_L_N(y, MAX7219_Y_LEDS) CLR_7219(col, y);
339 339
   send_column(col);
340 340
 }
341 341
 
@@ -347,7 +347,7 @@ void Max7219::clear_column(const uint8_t col) {
347 347
 void Max7219::set_row(const uint8_t row, const uint32_t val) {
348 348
   if (row >= MAX7219_Y_LEDS) return error(PSTR("set_row"), row);
349 349
   uint32_t mask = _BV32(MAX7219_X_LEDS - 1);
350
-  for (uint8_t x = 0; x < MAX7219_X_LEDS; x++) {
350
+  LOOP_L_N(x, MAX7219_X_LEDS) {
351 351
     if (val & mask) SET_7219(x, row); else CLR_7219(x, row);
352 352
     mask >>= 1;
353 353
   }
@@ -362,7 +362,7 @@ void Max7219::set_row(const uint8_t row, const uint32_t val) {
362 362
 void Max7219::set_column(const uint8_t col, const uint32_t val) {
363 363
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
364 364
   uint32_t mask = _BV32(MAX7219_Y_LEDS - 1);
365
-  for (uint8_t y = 0; y < MAX7219_Y_LEDS; y++) {
365
+  LOOP_L_N(y, MAX7219_Y_LEDS) {
366 366
     if (val & mask) SET_7219(col, y); else CLR_7219(col, y);
367 367
     mask >>= 1;
368 368
   }
@@ -427,23 +427,23 @@ void Max7219::set_columns_32bits(const uint8_t x, uint32_t val) {
427 427
 
428 428
 // Initialize the Max7219
429 429
 void Max7219::register_setup() {
430
-  for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
430
+  LOOP_L_N(i, MAX7219_NUMBER_UNITS)
431 431
     send(max7219_reg_scanLimit, 0x07);
432 432
   pulse_load();                               // Tell the chips to load the clocked out data
433 433
 
434
-  for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
434
+  LOOP_L_N(i, MAX7219_NUMBER_UNITS)
435 435
     send(max7219_reg_decodeMode, 0x00);       // Using an led matrix (not digits)
436 436
   pulse_load();                               // Tell the chips to load the clocked out data
437 437
 
438
-  for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
438
+  LOOP_L_N(i, MAX7219_NUMBER_UNITS)
439 439
     send(max7219_reg_shutdown, 0x01);         // Not in shutdown mode
440 440
   pulse_load();                               // Tell the chips to load the clocked out data
441 441
 
442
-  for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
442
+  LOOP_L_N(i, MAX7219_NUMBER_UNITS)
443 443
     send(max7219_reg_displayTest, 0x00);      // No display test
444 444
   pulse_load();                               // Tell the chips to load the clocked out data
445 445
 
446
-  for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
446
+  LOOP_L_N(i, MAX7219_NUMBER_UNITS)
447 447
     send(max7219_reg_intensity, 0x01 & 0x0F); // The first 0x0F is the value you can set
448 448
                                               // Range: 0x00 to 0x0F
449 449
   pulse_load();                               // Tell the chips to load the clocked out data
@@ -537,7 +537,7 @@ void Max7219::init() {
537 537
 
538 538
   register_setup();
539 539
 
540
-  for (uint8_t i = 0; i <= 7; i++) {  // Empty registers to turn all LEDs off
540
+  LOOP_LE_N(i, 7) {  // Empty registers to turn all LEDs off
541 541
     led_line[i] = 0x00;
542 542
     send(max7219_reg_digit0 + i, 0);
543 543
     pulse_load();                     // Tell the chips to load the clocked out data

+ 2
- 2
Marlin/src/feature/mixing.cpp 查看文件

@@ -98,13 +98,13 @@ void Mixer::normalize(const uint8_t tool_index) {
98 98
 void Mixer::reset_vtools() {
99 99
   // Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
100 100
   // Every virtual tool gets a pure filament
101
-  for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS; t++)
101
+  LOOP_L_N(t, MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS)
102 102
     MIXER_STEPPER_LOOP(i)
103 103
       color[t][i] = (t == i) ? COLOR_A_MASK : 0;
104 104
 
105 105
   // Remaining virtual tools are 100% filament 1
106 106
   #if MIXING_VIRTUAL_TOOLS > MIXING_STEPPERS
107
-    for (uint8_t t = MIXING_STEPPERS; t < MIXING_VIRTUAL_TOOLS; t++)
107
+    LOOP_S_L_N(t, MIXING_STEPPERS, MIXING_VIRTUAL_TOOLS)
108 108
       MIXER_STEPPER_LOOP(i)
109 109
         color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
110 110
   #endif

+ 4
- 4
Marlin/src/feature/mmu2/mmu2.cpp 查看文件

@@ -381,7 +381,7 @@ bool MMU2::rx_str_P(const char* str) {
381 381
 void MMU2::tx_str_P(const char* str) {
382 382
   clear_rx_buffer();
383 383
   uint8_t len = strlen_P(str);
384
-  for (uint8_t i = 0; i < len; i++) mmuSerial.write(pgm_read_byte(str++));
384
+  LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++));
385 385
   rx_buffer[0] = '\0';
386 386
   last_request = millis();
387 387
 }
@@ -392,7 +392,7 @@ void MMU2::tx_str_P(const char* str) {
392 392
 void MMU2::tx_printf_P(const char* format, int argument = -1) {
393 393
   clear_rx_buffer();
394 394
   uint8_t len = sprintf_P(tx_buffer, format, argument);
395
-  for (uint8_t i = 0; i < len; i++) mmuSerial.write(tx_buffer[i]);
395
+  LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
396 396
   rx_buffer[0] = '\0';
397 397
   last_request = millis();
398 398
 }
@@ -403,7 +403,7 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
403 403
 void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
404 404
   clear_rx_buffer();
405 405
   uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
406
-  for (uint8_t i = 0; i < len; i++) mmuSerial.write(tx_buffer[i]);
406
+  LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
407 407
   rx_buffer[0] = '\0';
408 408
   last_request = millis();
409 409
 }
@@ -780,7 +780,7 @@ void MMU2::filament_runout() {
780 780
 
781 781
     const E_Step* step = sequence;
782 782
 
783
-    for (uint8_t i = 0; i < steps; i++) {
783
+    LOOP_L_N(i, steps) {
784 784
       const float es = pgm_read_float(&(step->extrude));
785 785
       const feedRate_t fr_mm_m = pgm_read_float(&(step->feedRate));
786 786
 

+ 1
- 1
Marlin/src/feature/powerloss.cpp 查看文件

@@ -391,7 +391,7 @@ void PrintJobRecovery::resume() {
391 391
 
392 392
   // Restore retract and hop state
393 393
   #if ENABLED(FWRETRACT)
394
-    for (uint8_t e = 0; e < EXTRUDERS; e++) {
394
+    LOOP_L_N(e, EXTRUDERS) {
395 395
       if (info.retract[e] != 0.0) {
396 396
         fwretract.current_retract[e] = info.retract[e];
397 397
         fwretract.retracted[e] = true;

+ 3
- 3
Marlin/src/feature/probe_temp_comp.cpp 查看文件

@@ -54,7 +54,7 @@ uint8_t ProbeTempComp::calib_idx; // = 0
54 54
 float ProbeTempComp::init_measurement; // = 0.0
55 55
 
56 56
 void ProbeTempComp::clear_offsets(const TempSensorID tsi) {
57
-  for (uint8_t i = 0; i < cali_info[tsi].measurements; ++i)
57
+  LOOP_L_N(i, cali_info[tsi].measurements)
58 58
     sensor_z_offsets[tsi][i] = 0;
59 59
   calib_idx = 0;
60 60
 }
@@ -66,7 +66,7 @@ bool ProbeTempComp::set_offset(const TempSensorID tsi, const uint8_t idx, const
66 66
 }
67 67
 
68 68
 void ProbeTempComp::print_offsets() {
69
-  for (uint8_t s = 0; s < TSI_COUNT; s++) {
69
+  LOOP_L_N(s, TSI_COUNT) {
70 70
     float temp = cali_info[s].start_temp;
71 71
     for (int16_t i = -1; i < cali_info[s].measurements; ++i) {
72 72
       serialprintPGM(s == TSI_BED ? PSTR("Bed") :
@@ -198,7 +198,7 @@ bool ProbeTempComp::linear_regression(const TempSensorID tsi, float &k, float &d
198 198
         sum_x2 = sq(start_temp),
199 199
         sum_xy = 0, sum_y = 0;
200 200
 
201
-  for (uint8_t i = 0; i < calib_idx; ++i) {
201
+  LOOP_L_N(i, calib_idx) {
202 202
     const float xi = start_temp + (i + 1) * res_temp,
203 203
                 yi = static_cast<float>(data[i]);
204 204
     sum_x += xi;

+ 1
- 1
Marlin/src/feature/runout.h 查看文件

@@ -184,7 +184,7 @@ class FilamentSensorBase {
184 184
         #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG
185 185
           if (change) {
186 186
             SERIAL_ECHOPGM("Motion detected:");
187
-            for (uint8_t e = 0; e < NUM_RUNOUT_SENSORS; e++)
187
+            LOOP_L_N(e, NUM_RUNOUT_SENSORS)
188 188
               if (TEST(change, e)) SERIAL_CHAR(' ', '0' + e);
189 189
             SERIAL_EOL();
190 190
           }

+ 1
- 1
Marlin/src/feature/twibus.cpp 查看文件

@@ -104,7 +104,7 @@ void TWIBus::echodata(uint8_t bytes, const char prefix[], uint8_t adr) {
104 104
 
105 105
 void TWIBus::echobuffer(const char prefix[], uint8_t adr) {
106 106
   echoprefix(buffer_s, prefix, adr);
107
-  for (uint8_t i = 0; i < buffer_s; i++) SERIAL_CHAR(buffer[i]);
107
+  LOOP_L_N(i, buffer_s) SERIAL_CHAR(buffer[i]);
108 108
   SERIAL_EOL();
109 109
 }
110 110
 

+ 54
- 61
Marlin/src/gcode/bedlevel/G26.cpp 查看文件

@@ -157,7 +157,7 @@ float g26_extrusion_multiplier,
157 157
       g26_layer_height,
158 158
       g26_prime_length;
159 159
 
160
-xy_pos_t g26_pos; // = { 0, 0 }
160
+xy_pos_t g26_xy_pos; // = { 0, 0 }
161 161
 
162 162
 int16_t g26_bed_temp,
163 163
         g26_hotend_temp;
@@ -187,29 +187,27 @@ mesh_index_pair find_closest_circle_to_print(const xy_pos_t &pos) {
187 187
 
188 188
   out_point.pos = -1;
189 189
 
190
-  for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
191
-    for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
192
-      if (!circle_flags.marked(i, j)) {
193
-        // We found a circle that needs to be printed
194
-        const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
190
+  GRID_LOOP(i, j) {
191
+    if (!circle_flags.marked(i, j)) {
192
+      // We found a circle that needs to be printed
193
+      const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
195 194
 
196
-        // Get the distance to this intersection
197
-        float f = (pos - m).magnitude();
195
+      // Get the distance to this intersection
196
+      float f = (pos - m).magnitude();
198 197
 
199
-        // It is possible that we are being called with the values
200
-        // to let us find the closest circle to the start position.
201
-        // But if this is not the case, add a small weighting to the
202
-        // distance calculation to help it choose a better place to continue.
203
-        f += (g26_pos - m).magnitude() / 15.0f;
198
+      // It is possible that we are being called with the values
199
+      // to let us find the closest circle to the start position.
200
+      // But if this is not the case, add a small weighting to the
201
+      // distance calculation to help it choose a better place to continue.
202
+      f += (g26_xy_pos - m).magnitude() / 15.0f;
204 203
 
205
-        // Add the specified amount of Random Noise to our search
206
-        if (random_deviation > 1.0) f += random(0.0, random_deviation);
204
+      // Add the specified amount of Random Noise to our search
205
+      if (random_deviation > 1.0) f += random(0.0, random_deviation);
207 206
 
208
-        if (f < closest) {
209
-          closest = f;          // Found a closer un-printed location
210
-          out_point.pos.set(i, j);  // Save its data
211
-          out_point.distance = closest;
212
-        }
207
+      if (f < closest) {
208
+        closest = f;          // Found a closer un-printed location
209
+        out_point.pos.set(i, j);  // Save its data
210
+        out_point.distance = closest;
213 211
       }
214 212
     }
215 213
   }
@@ -308,51 +306,49 @@ inline bool look_for_lines_to_connect() {
308 306
   xyz_pos_t s, e;
309 307
   s.z = e.z = g26_layer_height;
310 308
 
311
-  for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
312
-    for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
309
+  GRID_LOOP(i, j) {
313 310
 
314
-      #if HAS_LCD_MENU
315
-        if (user_canceled()) return true;
316
-      #endif
311
+    #if HAS_LCD_MENU
312
+      if (user_canceled()) return true;
313
+    #endif
317 314
 
318
-      if (i < GRID_MAX_POINTS_X) {  // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
315
+    if (i < (GRID_MAX_POINTS_X)) {  // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
319 316
                                     // Already a half circle at the edge of the bed.
320 317
 
321
-        if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j)) {   // Test whether a leftward line can be done
322
-          if (!horizontal_mesh_line_flags.marked(i, j)) {
323
-            // Two circles need a horizontal line to connect them
324
-            s.x = _GET_MESH_X(  i  ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
325
-            e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
318
+      if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j)) {   // Test whether a leftward line can be done
319
+        if (!horizontal_mesh_line_flags.marked(i, j)) {
320
+          // Two circles need a horizontal line to connect them
321
+          s.x = _GET_MESH_X(  i  ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
322
+          e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
326 323
 
327
-            LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1);
328
-            s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
329
-            LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
324
+          LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1);
325
+          s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
326
+          LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
330 327
 
331
-            if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
332
-              print_line_from_here_to_there(s, e);
328
+          if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
329
+            print_line_from_here_to_there(s, e);
333 330
 
334
-            horizontal_mesh_line_flags.mark(i, j); // Mark done, even if skipped
335
-          }
331
+          horizontal_mesh_line_flags.mark(i, j); // Mark done, even if skipped
336 332
         }
333
+      }
337 334
 
338
-        if (j < GRID_MAX_POINTS_Y) {  // Can't connect to anything further back than GRID_MAX_POINTS_Y.
335
+      if (j < (GRID_MAX_POINTS_Y)) {  // Can't connect to anything further back than GRID_MAX_POINTS_Y.
339 336
                                       // Already a half circle at the edge of the bed.
340 337
 
341
-          if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1)) {   // Test whether a downward line can be done
342
-            if (!vertical_mesh_line_flags.marked(i, j)) {
343
-              // Two circles that need a vertical line to connect them
344
-              s.y = _GET_MESH_Y(  j  ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge
345
-              e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
338
+        if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1)) {   // Test whether a downward line can be done
339
+          if (!vertical_mesh_line_flags.marked(i, j)) {
340
+            // Two circles that need a vertical line to connect them
341
+            s.y = _GET_MESH_Y(  j  ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge
342
+            e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
346 343
 
347
-              s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
348
-              LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
349
-              LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
344
+            s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
345
+            LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
346
+            LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
350 347
 
351
-              if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
352
-                print_line_from_here_to_there(s, e);
348
+            if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
349
+              print_line_from_here_to_there(s, e);
353 350
 
354
-              vertical_mesh_line_flags.mark(i, j); // Mark done, even if skipped
355
-            }
351
+            vertical_mesh_line_flags.mark(i, j); // Mark done, even if skipped
356 352
           }
357 353
         }
358 354
       }
@@ -628,9 +624,9 @@ void GcodeSuite::G26() {
628 624
     return;
629 625
   }
630 626
 
631
-  g26_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
632
-              parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y);
633
-  if (!position_is_reachable(g26_pos.x, g26_pos.y)) {
627
+  g26_xy_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
628
+                 parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y);
629
+  if (!position_is_reachable(g26_xy_pos)) {
634 630
     SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds.");
635 631
     return;
636 632
   }
@@ -695,7 +691,7 @@ void GcodeSuite::G26() {
695 691
       #error "A_CNT must be a positive value. Please change A_INT."
696 692
     #endif
697 693
     float trig_table[A_CNT];
698
-    for (uint8_t i = 0; i < A_CNT; i++)
694
+    LOOP_L_N(i, A_CNT)
699 695
       trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT));
700 696
 
701 697
   #endif // !ARC_SUPPORT
@@ -703,7 +699,7 @@ void GcodeSuite::G26() {
703 699
   mesh_index_pair location;
704 700
   do {
705 701
     // Find the nearest confluence
706
-    location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_pos);
702
+    location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_xy_pos);
707 703
 
708 704
     if (location.valid()) {
709 705
       const xy_pos_t circle = _GET_MESH_POS(location.pos);
@@ -834,12 +830,9 @@ void GcodeSuite::G26() {
834 830
 
835 831
   retract_filament(destination);
836 832
   destination.z = Z_CLEARANCE_BETWEEN_PROBES;
833
+  move_to(destination, 0);                                    // Raise the nozzle
837 834
 
838
-  move_to(destination, 0); // Raise the nozzle
839
-
840
-  destination.set(g26_pos.x, g26_pos.y);                      // Move back to the starting position
841
-  //destination.z = Z_CLEARANCE_BETWEEN_PROBES;               // Keep the nozzle where it is
842
-
835
+  destination = g26_xy_pos;                                   // Move back to the starting XY position
843 836
   move_to(destination, 0);                                    // Move back to the starting position
844 837
 
845 838
   #if DISABLED(NO_VOLUMETRICS)

+ 6
- 7
Marlin/src/gcode/bedlevel/M420.cpp 查看文件

@@ -71,13 +71,12 @@ void GcodeSuite::M420() {
71 71
         bilinear_grid_spacing.set((x_max - x_min) / (GRID_MAX_POINTS_X - 1),
72 72
                                   (y_max - y_min) / (GRID_MAX_POINTS_Y - 1));
73 73
       #endif
74
-      for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
75
-        for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
76
-          Z_VALUES(x, y) = 0.001 * random(-200, 200);
77
-          #if ENABLED(EXTENSIBLE_UI)
78
-            ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
79
-          #endif
80
-        }
74
+      GRID_LOOP(x, y) {
75
+        Z_VALUES(x, y) = 0.001 * random(-200, 200);
76
+        #if ENABLED(EXTENSIBLE_UI)
77
+          ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
78
+        #endif
79
+      }
81 80
       SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
82 81
       SERIAL_ECHOPAIR(" (", x_min);
83 82
       SERIAL_CHAR(','); SERIAL_ECHO(y_min);

+ 2
- 2
Marlin/src/gcode/bedlevel/abl/G29.cpp 查看文件

@@ -746,7 +746,7 @@ G29_TYPE GcodeSuite::G29() {
746 746
 
747 747
       // Probe at 3 arbitrary points
748 748
 
749
-      for (uint8_t i = 0; i < 3; ++i) {
749
+      LOOP_L_N(i, 3) {
750 750
         if (verbose_level) SERIAL_ECHOLNPAIR("Probing point ", int(i), "/3.");
751 751
         #if HAS_DISPLAY
752 752
           ui.status_printf_P(0, PSTR(S_FMT " %i/3"), GET_TEXT(MSG_PROBING_MESH), int(i));
@@ -861,7 +861,7 @@ G29_TYPE GcodeSuite::G29() {
861 861
         auto print_topo_map = [&](PGM_P const title, const bool get_min) {
862 862
           serialprintPGM(title);
863 863
           for (int8_t yy = abl_grid_points.y - 1; yy >= 0; yy--) {
864
-            for (uint8_t xx = 0; xx < abl_grid_points.x; xx++) {
864
+            LOOP_L_N(xx, abl_grid_points.x) {
865 865
               const int ind = indexIntoAB[xx][yy];
866 866
               xyz_float_t tmp = { eqnAMatrix[ind + 0 * abl_points],
867 867
                                   eqnAMatrix[ind + 1 * abl_points], 0 };

+ 2
- 2
Marlin/src/gcode/calibrate/G425.cpp 查看文件

@@ -124,7 +124,7 @@ inline void park_above_object(measurements_t &m, const float uncertainty) {
124 124
 #if HAS_HOTEND_OFFSET
125 125
 
126 126
   inline void normalize_hotend_offsets() {
127
-    for (uint8_t e = 1; e < HOTENDS; e++)
127
+    LOOP_S_L_N(e, 1, HOTENDS)
128 128
       hotend_offset[e] -= hotend_offset[0];
129 129
     hotend_offset[0].reset();
130 130
   }
@@ -393,7 +393,7 @@ inline void probe_sides(measurements_t &m, const float uncertainty) {
393 393
     // This function requires normalize_hotend_offsets() to be called
394 394
     //
395 395
     inline void report_hotend_offsets() {
396
-      for (uint8_t e = 1; e < HOTENDS; e++)
396
+      LOOP_S_L_N(e, 1, HOTENDS)
397 397
         SERIAL_ECHOLNPAIR_P(PSTR("T"), int(e), PSTR(" Hotend Offset X"), hotend_offset[e].x, SP_Y_STR, hotend_offset[e].y, SP_Z_STR, hotend_offset[e].z);
398 398
     }
399 399
   #endif

+ 2
- 2
Marlin/src/gcode/calibrate/M100.cpp 查看文件

@@ -158,14 +158,14 @@ inline int32_t count_test_bytes(const char * const start_free_memory) {
158 158
     while (start_free_memory < end_free_memory) {
159 159
       print_hex_address(start_free_memory);             // Print the address
160 160
       SERIAL_CHAR(':');
161
-      for (uint8_t i = 0; i < 16; i++) {  // and 16 data bytes
161
+      LOOP_L_N(i, 16) {  // and 16 data bytes
162 162
         if (i == 8) SERIAL_CHAR('-');
163 163
         print_hex_byte(start_free_memory[i]);
164 164
         SERIAL_CHAR(' ');
165 165
       }
166 166
       serial_delay(25);
167 167
       SERIAL_CHAR('|');                   // Point out non test bytes
168
-      for (uint8_t i = 0; i < 16; i++) {
168
+      LOOP_L_N(i, 16) {
169 169
         char ccc = (char)start_free_memory[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken
170 170
         ccc = (ccc == TEST_BYTE) ? ' ' : '?';
171 171
         SERIAL_CHAR(ccc);

+ 4
- 4
Marlin/src/gcode/calibrate/M48.cpp 查看文件

@@ -126,7 +126,7 @@ void GcodeSuite::M48() {
126 126
   if (probing_good) {
127 127
     randomSeed(millis());
128 128
 
129
-    for (uint8_t n = 0; n < n_samples; n++) {
129
+    LOOP_L_N(n, n_samples) {
130 130
       #if HAS_SPI_LCD
131 131
         // Display M48 progress in the status bar
132 132
         ui.status_printf_P(0, PSTR(S_FMT ": %d/%d"), GET_TEXT(MSG_M48_POINT), int(n + 1), int(n_samples));
@@ -149,7 +149,7 @@ void GcodeSuite::M48() {
149 149
           SERIAL_ECHOLNPGM("CW");
150 150
         }
151 151
 
152
-        for (uint8_t l = 0; l < n_legs - 1; l++) {
152
+        LOOP_L_N(l, n_legs - 1) {
153 153
           float delta_angle;
154 154
 
155 155
           if (schizoid_flag) {
@@ -204,7 +204,7 @@ void GcodeSuite::M48() {
204 204
        * Get the current mean for the data points we have so far
205 205
        */
206 206
       float sum = 0.0;
207
-      for (uint8_t j = 0; j <= n; j++) sum += sample_set[j];
207
+      LOOP_LE_N(j, n) sum += sample_set[j];
208 208
       mean = sum / (n + 1);
209 209
 
210 210
       NOMORE(min, sample_set[n]);
@@ -215,7 +215,7 @@ void GcodeSuite::M48() {
215 215
        * data points we have so far
216 216
        */
217 217
       sum = 0.0;
218
-      for (uint8_t j = 0; j <= n; j++)
218
+      LOOP_LE_N(j, n)
219 219
         sum += sq(sample_set[j] - mean);
220 220
 
221 221
       sigma = SQRT(sum / (n + 1));

+ 1
- 1
Marlin/src/gcode/config/M305.cpp 查看文件

@@ -71,7 +71,7 @@ void GcodeSuite::M305() {
71 71
         SERIAL_ECHO_MSG("!Invalid Steinhart-Hart C coeff. (-0.01 < C < +0.01)");
72 72
   }                       // If not setting then report parameters
73 73
   else if (t_index < 0) { // ...all user thermistors
74
-    for (uint8_t i = 0; i < USER_THERMISTORS; i++)
74
+    LOOP_L_N(i, USER_THERMISTORS)
75 75
       thermalManager.log_user_thermistor(i);
76 76
   }
77 77
   else                    // ...one user thermistor

+ 4
- 4
Marlin/src/gcode/config/M43.cpp 查看文件

@@ -57,7 +57,7 @@ inline void toggle_pins() {
57 57
             end = PARSED_PIN_INDEX('L', NUM_DIGITAL_PINS - 1),
58 58
             wait = parser.intval('W', 500);
59 59
 
60
-  for (uint8_t i = start; i <= end; i++) {
60
+  LOOP_S_LE_N(i, start, end) {
61 61
     pin_t pin = GET_PIN_MAP_PIN_M43(i);
62 62
     if (!VALID_PIN(pin)) continue;
63 63
     if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) {
@@ -313,7 +313,7 @@ void GcodeSuite::M43() {
313 313
       NOLESS(first_pin, 2); // Don't hijack the UART pins
314 314
     #endif
315 315
     uint8_t pin_state[last_pin - first_pin + 1];
316
-    for (uint8_t i = first_pin; i <= last_pin; i++) {
316
+    LOOP_S_LE_N(i, first_pin, last_pin) {
317 317
       pin_t pin = GET_PIN_MAP_PIN_M43(i);
318 318
       if (!VALID_PIN(pin)) continue;
319 319
       if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
@@ -339,7 +339,7 @@ void GcodeSuite::M43() {
339 339
     #endif
340 340
 
341 341
     for (;;) {
342
-      for (uint8_t i = first_pin; i <= last_pin; i++) {
342
+      LOOP_S_LE_N(i, first_pin, last_pin) {
343 343
         pin_t pin = GET_PIN_MAP_PIN_M43(i);
344 344
         if (!VALID_PIN(pin)) continue;
345 345
         if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
@@ -365,7 +365,7 @@ void GcodeSuite::M43() {
365 365
   }
366 366
   else {
367 367
     // Report current state of selected pin(s)
368
-    for (uint8_t i = first_pin; i <= last_pin; i++) {
368
+    LOOP_S_LE_N(i, first_pin, last_pin) {
369 369
       pin_t pin = GET_PIN_MAP_PIN_M43(i);
370 370
       if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
371 371
     }

+ 1
- 1
Marlin/src/gcode/config/M672.cpp 查看文件

@@ -62,7 +62,7 @@
62 62
 //  b3 b2 b1 b0 ~b0  ... lo bits, NOT last bit
63 63
 //
64 64
 void M672_send(uint8_t b) {    // bit rate requirement: 1KHz +/- 30%
65
-  for (uint8_t bits = 0; bits < 14; bits++) {
65
+  LOOP_L_N(bits, 14) {
66 66
     switch (bits) {
67 67
       default: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); b <<= 1; break; } // send bit, shift next into place
68 68
       case  7:

+ 1
- 1
Marlin/src/gcode/config/M92.cpp 查看文件

@@ -34,7 +34,7 @@ void report_M92(const bool echo=true, const int8_t e=-1) {
34 34
   SERIAL_EOL();
35 35
 
36 36
   #if ENABLED(DISTINCT_E_FACTORS)
37
-    for (uint8_t i = 0; i < E_STEPPERS; i++) {
37
+    LOOP_L_N(i, E_STEPPERS) {
38 38
       if (e >= 0 && i != e) continue;
39 39
       if (echo) SERIAL_ECHO_START(); else SERIAL_CHAR(' ');
40 40
       SERIAL_ECHOLNPAIR_P(PSTR(" M92 T"), (int)i,

+ 1
- 1
Marlin/src/gcode/control/M111.cpp 查看文件

@@ -49,7 +49,7 @@ void GcodeSuite::M111() {
49 49
   SERIAL_ECHOPGM(STR_DEBUG_PREFIX);
50 50
   if (marlin_debug_flags) {
51 51
     uint8_t comma = 0;
52
-    for (uint8_t i = 0; i < COUNT(debug_strings); i++) {
52
+    LOOP_L_N(i, COUNT(debug_strings)) {
53 53
       if (TEST(marlin_debug_flags, i)) {
54 54
         if (comma++) SERIAL_CHAR(',');
55 55
         serialprintPGM((char*)pgm_read_ptr(&debug_strings[i]));

+ 1
- 1
Marlin/src/gcode/control/M350_M351.cpp 查看文件

@@ -33,7 +33,7 @@
33 33
  * Warning: Steps-per-unit remains unchanged.
34 34
  */
35 35
 void GcodeSuite::M350() {
36
-  if (parser.seen('S')) for (uint8_t i = 0; i <= 4; i++) stepper.microstep_mode(i, parser.value_byte());
36
+  if (parser.seen('S')) LOOP_LE_N(i, 4) stepper.microstep_mode(i, parser.value_byte());
37 37
   LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.microstep_mode(i, parser.value_byte());
38 38
   if (parser.seen('B')) stepper.microstep_mode(4, parser.value_byte());
39 39
   stepper.microstep_readings();

+ 1
- 1
Marlin/src/gcode/feature/camera/M240.cpp 查看文件

@@ -90,7 +90,7 @@
90 90
 
91 91
     inline void spin_photo_pin() {
92 92
       static constexpr uint32_t sequence[] = PHOTO_PULSES_US;
93
-      for (uint8_t i = 0; i < COUNT(sequence); i++)
93
+      LOOP_L_N(i, COUNT(sequence))
94 94
         pulse_photo_pin(sequence[i], !(i & 1));
95 95
     }
96 96
 

+ 2
- 2
Marlin/src/gcode/feature/digipot/M907-M910.cpp 查看文件

@@ -46,7 +46,7 @@ void GcodeSuite::M907() {
46 46
 
47 47
     LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
48 48
     if (parser.seenval('B')) stepper.digipot_current(4, parser.value_int());
49
-    if (parser.seenval('S')) for (uint8_t i = 0; i <= 4; i++) stepper.digipot_current(i, parser.value_int());
49
+    if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.digipot_current(i, parser.value_int());
50 50
 
51 51
   #elif HAS_MOTOR_CURRENT_PWM
52 52
 
@@ -74,7 +74,7 @@ void GcodeSuite::M907() {
74 74
   #if ENABLED(DAC_STEPPER_CURRENT)
75 75
     if (parser.seenval('S')) {
76 76
       const float dac_percent = parser.value_float();
77
-      for (uint8_t i = 0; i <= 4; i++) dac_current_percent(i, dac_percent);
77
+      LOOP_LE_N(i, 4) dac_current_percent(i, dac_percent);
78 78
     }
79 79
     LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) dac_current_percent(i, parser.value_float());
80 80
   #endif

+ 1
- 1
Marlin/src/gcode/feature/leds/M7219.cpp 查看文件

@@ -79,7 +79,7 @@ void GcodeSuite::M7219() {
79 79
   }
80 80
 
81 81
   if (parser.seen('P')) {
82
-    for (uint8_t r = 0; r < MAX7219_LINES; r++) {
82
+    LOOP_L_N(r, MAX7219_LINES) {
83 83
       SERIAL_ECHOPGM("led_line[");
84 84
       if (r < 10) SERIAL_CHAR(' ');
85 85
       SERIAL_ECHO(int(r));

+ 1
- 1
Marlin/src/gcode/host/M114.cpp 查看文件

@@ -36,7 +36,7 @@
36 36
 
37 37
   void report_xyze(const xyze_pos_t &pos, const uint8_t n=XYZE, const uint8_t precision=3) {
38 38
     char str[12];
39
-    for (uint8_t a = 0; a < n; a++) {
39
+    LOOP_L_N(a, n) {
40 40
       SERIAL_CHAR(' ', axis_codes[a], ':');
41 41
       SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
42 42
     }

+ 2
- 2
Marlin/src/gcode/queue.cpp 查看文件

@@ -94,7 +94,7 @@ static PGM_P injected_commands_P = nullptr;
94 94
 
95 95
 GCodeQueue::GCodeQueue() {
96 96
   // Send "ok" after commands by default
97
-  for (uint8_t i = 0; i < COUNT(send_ok); i++) send_ok[i] = true;
97
+  LOOP_L_N(i, COUNT(send_ok)) send_ok[i] = true;
98 98
 }
99 99
 
100 100
 /**
@@ -427,7 +427,7 @@ void GCodeQueue::get_serial_commands() {
427 427
    * Loop while serial characters are incoming and the queue is not full
428 428
    */
429 429
   while (length < BUFSIZE && serial_data_available()) {
430
-    for (uint8_t i = 0; i < NUM_SERIAL; ++i) {
430
+    LOOP_L_N(i, NUM_SERIAL) {
431 431
 
432 432
       const int c = read_serial(i);
433 433
       if (c < 0) continue;

+ 44
- 0
Marlin/src/inc/Conditionals_LCD.h 查看文件

@@ -604,8 +604,52 @@
604 604
   #undef Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
605 605
 #endif
606 606
 
607
+/**
608
+ * Set granular options based on the specific type of leveling
609
+ */
610
+#if ENABLED(AUTO_BED_LEVELING_UBL)
611
+  #undef LCD_BED_LEVELING
612
+  #if ENABLED(DELTA)
613
+    #define UBL_SEGMENTED 1
614
+  #endif
615
+#endif
616
+#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT)
617
+  #define ABL_PLANAR 1
618
+#endif
619
+#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR)
620
+  #define ABL_GRID 1
621
+#endif
622
+#if ANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_3POINT)
623
+  #define HAS_ABL_NOT_UBL 1
624
+#endif
625
+#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, MESH_BED_LEVELING)
626
+  #define HAS_MESH 1
627
+#endif
628
+#if EITHER(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_3POINT)
629
+  #define NEEDS_THREE_PROBE_POINTS 1
630
+#endif
631
+#if EITHER(HAS_ABL_NOT_UBL, AUTO_BED_LEVELING_UBL)
632
+  #define HAS_ABL_OR_UBL 1
633
+  #if DISABLED(PROBE_MANUALLY)
634
+    #define HAS_AUTOLEVEL 1
635
+  #endif
636
+#endif
637
+#if EITHER(HAS_ABL_OR_UBL, MESH_BED_LEVELING)
638
+  #define HAS_LEVELING 1
639
+  #if DISABLED(AUTO_BED_LEVELING_UBL)
640
+    #define PLANNER_LEVELING 1
641
+  #endif
642
+#endif
643
+#if EITHER(HAS_ABL_OR_UBL, Z_MIN_PROBE_REPEATABILITY_TEST)
644
+  #define HAS_PROBING_PROCEDURE 1
645
+#endif
646
+#if !HAS_LEVELING
647
+  #undef RESTORE_LEVELING_AFTER_G28
648
+#endif
649
+
607 650
 #ifdef GRID_MAX_POINTS_X
608 651
   #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
652
+  #define GRID_LOOP(A,B) LOOP_L_N(A, GRID_MAX_POINTS_X) LOOP_L_N(B, GRID_MAX_POINTS_Y)
609 653
 #endif
610 654
 
611 655
 #ifndef INVERT_X_DIR

+ 4
- 0
Marlin/src/inc/Conditionals_adv.h 查看文件

@@ -83,6 +83,10 @@
83 83
   #endif
84 84
 #endif
85 85
 
86
+#if ANY(FWRETRACT, HAS_LEVELING, SKEW_CORRECTION)
87
+  #define HAS_POSITION_MODIFIERS 1
88
+#endif
89
+
86 90
 #if ANY(X_DUAL_ENDSTOPS, Y_DUAL_ENDSTOPS, Z_MULTI_ENDSTOPS)
87 91
   #define HAS_EXTRA_ENDSTOPS 1
88 92
 #endif

+ 0
- 47
Marlin/src/inc/Conditionals_post.h 查看文件

@@ -1855,53 +1855,6 @@
1855 1855
 #endif // SKEW_CORRECTION
1856 1856
 
1857 1857
 /**
1858
- * Set granular options based on the specific type of leveling
1859
- */
1860
-#if ENABLED(AUTO_BED_LEVELING_UBL)
1861
-  #undef LCD_BED_LEVELING
1862
-  #if ENABLED(DELTA)
1863
-    #define UBL_SEGMENTED 1
1864
-  #endif
1865
-#endif
1866
-#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT)
1867
-  #define ABL_PLANAR 1
1868
-#endif
1869
-#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR)
1870
-  #define ABL_GRID 1
1871
-#endif
1872
-#if ANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_3POINT)
1873
-  #define HAS_ABL_NOT_UBL 1
1874
-#endif
1875
-#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, MESH_BED_LEVELING)
1876
-  #define HAS_MESH 1
1877
-#endif
1878
-#if EITHER(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_3POINT)
1879
-  #define NEEDS_THREE_PROBE_POINTS 1
1880
-#endif
1881
-#if EITHER(HAS_ABL_NOT_UBL, AUTO_BED_LEVELING_UBL)
1882
-  #define HAS_ABL_OR_UBL 1
1883
-  #if DISABLED(PROBE_MANUALLY)
1884
-    #define HAS_AUTOLEVEL 1
1885
-  #endif
1886
-#endif
1887
-#if EITHER(HAS_ABL_OR_UBL, MESH_BED_LEVELING)
1888
-  #define HAS_LEVELING 1
1889
-  #if DISABLED(AUTO_BED_LEVELING_UBL)
1890
-    #define PLANNER_LEVELING 1
1891
-  #endif
1892
-#endif
1893
-#if EITHER(HAS_ABL_OR_UBL, Z_MIN_PROBE_REPEATABILITY_TEST)
1894
-  #define HAS_PROBING_PROCEDURE 1
1895
-#endif
1896
-#if ANY(FWRETRACT, HAS_LEVELING, SKEW_CORRECTION)
1897
-  #define HAS_POSITION_MODIFIERS 1
1898
-#endif
1899
-
1900
-#if !HAS_LEVELING
1901
-  #undef RESTORE_LEVELING_AFTER_G28
1902
-#endif
1903
-
1904
-/**
1905 1858
  * Heater, Fan, and Probe interactions
1906 1859
  */
1907 1860
 #if FAN_COUNT == 0

+ 2
- 2
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp 查看文件

@@ -102,7 +102,7 @@
102 102
 
103 103
 static void createChar_P(const char c, const byte * const ptr) {
104 104
   byte temp[8];
105
-  for (uint8_t i = 0; i < 8; i++)
105
+  LOOP_L_N(i, 8)
106 106
     temp[i] = pgm_read_byte(&ptr[i]);
107 107
   lcd.createChar(c, temp);
108 108
 }
@@ -414,7 +414,7 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
414 414
     else {
415 415
       PGM_P p = text;
416 416
       int dly = time / _MAX(slen, 1);
417
-      for (uint8_t i = 0; i <= slen; i++) {
417
+      LOOP_LE_N(i, slen) {
418 418
 
419 419
         // Print the text at the correct place
420 420
         lcd_put_u8str_max_P(col, line, p, len);

+ 1
- 1
Marlin/src/lcd/dogm/status_screen_DOGM.cpp 查看文件

@@ -564,7 +564,7 @@ void MarlinUI::draw_status_screen() {
564 564
   if (PAGE_UNDER(6 + 1 + 12 + 1 + 6 + 1)) {
565 565
     // Extruders
566 566
     #if DO_DRAW_HOTENDS
567
-      for (uint8_t e = 0; e < MAX_HOTEND_DRAW; ++e)
567
+      LOOP_L_N(e, MAX_HOTEND_DRAW)
568 568
         _draw_hotend_status((heater_ind_t)e, blink);
569 569
     #endif
570 570
 

+ 4
- 4
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp 查看文件

@@ -209,7 +209,7 @@ void ST7920_Lite_Status_Screen::clear_ddram() {
209 209
 
210 210
 /* This fills the entire graphics buffer with zeros */
211 211
 void ST7920_Lite_Status_Screen::clear_gdram() {
212
-  for (uint8_t y = 0; y < BUFFER_HEIGHT; y++) {
212
+  LOOP_L_N(y, BUFFER_HEIGHT) {
213 213
     set_gdram_address(0, y);
214 214
     begin_data();
215 215
     for (uint8_t i = (BUFFER_WIDTH) / 16; i--;) write_word(0);
@@ -407,7 +407,7 @@ void ST7920_Lite_Status_Screen::draw_degree_symbol(uint8_t x, uint8_t y, const b
407 407
     const uint8_t x_word  = x >> 1,
408 408
                   y_top   = degree_symbol_y_top,
409 409
                   y_bot   = y_top + COUNT(degree_symbol);
410
-    for (uint8_t i = y_top; i < y_bot; i++) {
410
+    LOOP_S_L_N(i, y_top, y_bot) {
411 411
       uint8_t byte = pgm_read_byte(p_bytes++);
412 412
       set_gdram_address(x_word, i + y * 16);
413 413
       begin_data();
@@ -467,10 +467,10 @@ void ST7920_Lite_Status_Screen::draw_progress_bar(const uint8_t value) {
467 467
   const uint8_t char_pcnt  = 100 / width; // How many percent does each 16-bit word represent?
468 468
 
469 469
   // Draw the progress bar as a bitmap in CGRAM
470
-  for (uint8_t y = top; y <= bottom; y++) {
470
+  LOOP_S_LE_N(y, top, bottom) {
471 471
     set_gdram_address(left, y);
472 472
     begin_data();
473
-    for (uint8_t x = 0; x < width; x++) {
473
+    LOOP_L_N(x, width) {
474 474
       uint16_t gfx_word = 0x0000;
475 475
       if ((x + 1) * char_pcnt <= value)
476 476
         gfx_word = 0xFFFF;                                              // Draw completely filled bytes

+ 2
- 2
Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp 查看文件

@@ -87,11 +87,11 @@ void clear_graphics_DRAM(u8g_t *u8g, u8g_dev_t *dev) {
87 87
   u8g_SetAddress(u8g, dev, 0);         // cmd mode
88 88
   u8g_WriteByte(u8g, dev, 0x08);       //display off, cursor+blink off
89 89
   u8g_WriteByte(u8g, dev, 0x3E);       //extended mode + GDRAM active
90
-  for (uint8_t y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM
90
+  LOOP_L_N(y, (LCD_PIXEL_HEIGHT) / 2) { //clear GDRAM
91 91
     u8g_WriteByte(u8g, dev, 0x80 | y); //set y
92 92
     u8g_WriteByte(u8g, dev, 0x80);     //set x = 0
93 93
     u8g_SetAddress(u8g, dev, 1);                  /* data mode */
94
-    for (uint8_t i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) //2x width clears both segments
94
+    LOOP_L_N(i, 2 * (LCD_PIXEL_WIDTH) / 8) //2x width clears both segments
95 95
       u8g_WriteByte(u8g, dev, 0);
96 96
     u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
97 97
   }

+ 1
- 1
Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp 查看文件

@@ -670,7 +670,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
670 670
     case U8G_DEV_MSG_PAGE_NEXT:
671 671
       if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;
672 672
 
673
-      for (uint8_t y = 0; y < PAGE_HEIGHT; y++) {
673
+      LOOP_L_N(y, PAGE_HEIGHT) {
674 674
         uint32_t k = 0;
675 675
         #ifdef LCD_USE_DMA_FSMC
676 676
           buffer = (y & 1) ? bufferB : bufferA;

+ 1
- 1
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h 查看文件

@@ -237,7 +237,7 @@ public:
237 237
     if (!var.memadr) return;
238 238
     union { unsigned char tmp[sizeof(T)]; T t; } x;
239 239
     unsigned char *ptr = (unsigned char*)val_ptr;
240
-    for (uint8_t i = 0; i < sizeof(T); i++) x.tmp[i] = ptr[sizeof(T) - i - 1];
240
+    LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1];
241 241
     *(T*)var.memadr = x.t;
242 242
   }
243 243
 

+ 2
- 2
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/western_char_set.cpp 查看文件

@@ -339,11 +339,11 @@
339 339
     alt_fm.stride = 19;
340 340
     alt_fm.width  = 38;
341 341
     alt_fm.height = 49;
342
-    for (uint8_t i = 0; i < 127; i++)
342
+    LOOP_L_N(i, 127)
343 343
       alt_fm.char_widths[i] = 0;
344 344
 
345 345
     // For special characters, copy the character widths from the char tables
346
-    for (uint8_t i = 0; i < NUM_ELEMENTS(char_recipe); i++) {
346
+    LOOP_L_N(i, NUM_ELEMENTS(char_recipe)) {
347 347
       uint8_t std_char, alt_char, alt_data;
348 348
       get_char_data(i, std_char, alt_char, alt_data);
349 349
       if (std_char == 0)

+ 1
- 1
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp 查看文件

@@ -36,7 +36,7 @@ void MoveAxisScreen::onEntry() {
36 36
   // ourselves. The relative distances are reset to zero whenever this
37 37
   // screen is entered.
38 38
 
39
-  for (uint8_t i = 0; i < ExtUI::extruderCount; i++) {
39
+  LOOP_L_N(i, ExtUI::extruderCount) {
40 40
     screen_data.MoveAxisScreen.e_rel[i] = 0;
41 41
   }
42 42
   BaseNumericAdjustmentScreen::onEntry();

+ 2
- 2
Marlin/src/lcd/extui_malyan_lcd.cpp 查看文件

@@ -81,7 +81,7 @@ void write_to_lcd_P(PGM_P const message) {
81 81
   char encoded_message[MAX_CURLY_COMMAND];
82 82
   uint8_t message_length = _MIN(strlen_P(message), sizeof(encoded_message));
83 83
 
84
-  for (uint8_t i = 0; i < message_length; i++)
84
+  LOOP_L_N(i, message_length)
85 85
     encoded_message[i] = pgm_read_byte(&message[i]) | 0x80;
86 86
 
87 87
   LCD_SERIAL.Print::write(encoded_message, message_length);
@@ -91,7 +91,7 @@ void write_to_lcd(const char * const message) {
91 91
   char encoded_message[MAX_CURLY_COMMAND];
92 92
   const uint8_t message_length = _MIN(strlen(message), sizeof(encoded_message));
93 93
 
94
-  for (uint8_t i = 0; i < message_length; i++)
94
+  LOOP_L_N(i, message_length)
95 95
     encoded_message[i] = message[i] | 0x80;
96 96
 
97 97
   LCD_SERIAL.Print::write(encoded_message, message_length);

+ 3
- 3
Marlin/src/lcd/menu/game/brickout.cpp 查看文件

@@ -140,13 +140,13 @@ void BrickoutGame::game_screen() {
140 140
 
141 141
   // Draw bricks
142 142
   if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) {
143
-    for (uint8_t y = 0; y < BRICK_ROWS; ++y) {
143
+    LOOP_L_N(y, BRICK_ROWS) {
144 144
       const uint8_t yy = y * BRICK_H + BRICK_TOP;
145 145
       if (PAGE_CONTAINS(yy, yy + BRICK_H - 1)) {
146
-        for (uint8_t x = 0; x < BRICK_COLS; ++x) {
146
+        LOOP_L_N(x, BRICK_COLS) {
147 147
           if (TEST(bdat.bricks[y], x)) {
148 148
             const uint8_t xx = x * BRICK_W;
149
-            for (uint8_t v = 0; v < BRICK_H - 1; ++v)
149
+            LOOP_L_N(v, BRICK_H - 1)
150 150
               if (PAGE_CONTAINS(yy + v, yy + v))
151 151
                 u8g.drawHLine(xx, yy + v, BRICK_W - 1);
152 152
           }

+ 3
- 3
Marlin/src/lcd/menu/game/invaders.cpp 查看文件

@@ -170,7 +170,7 @@ inline void update_invader_data() {
170 170
     uint8_t m = idat.bugs[y];
171 171
     if (m) idat.botmost = y + 1;
172 172
     inv_mask |= m;
173
-    for (uint8_t x = 0; x < INVADER_COLS; ++x)
173
+    LOOP_L_N(x, INVADER_COLS)
174 174
       if (TEST(m, x)) idat.shooters[sc++] = (y << 4) | x;
175 175
   }
176 176
   idat.leftmost = 0;
@@ -371,11 +371,11 @@ void InvadersGame::game_screen() {
371 371
   // Draw invaders
372 372
   if (PAGE_CONTAINS(idat.pos.y, idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 - 1)) {
373 373
     int8_t yy = idat.pos.y;
374
-    for (uint8_t y = 0; y < INVADER_ROWS; ++y) {
374
+    LOOP_L_N(y, INVADER_ROWS) {
375 375
       const uint8_t type = inv_type[y];
376 376
       if (PAGE_CONTAINS(yy, yy + INVADER_H - 1)) {
377 377
         int8_t xx = idat.pos.x;
378
-        for (uint8_t x = 0; x < INVADER_COLS; ++x) {
378
+        LOOP_L_N(x, INVADER_COLS) {
379 379
           if (TEST(idat.bugs[y], x))
380 380
             u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]);
381 381
           xx += INVADER_COL_W;

+ 1
- 1
Marlin/src/lcd/menu/game/maze.cpp 查看文件

@@ -83,7 +83,7 @@ void MazeGame::game_screen() {
83 83
   if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score);
84 84
 
85 85
   // Draw the maze
86
-  // for (uint8_t n = 0; n < head_ind; ++n) {
86
+  // LOOP_L_N(n, head_ind) {
87 87
   //   const pos_t &p = maze_walls[n], &q = maze_walls[n + 1];
88 88
   //   if (p.x == q.x) {
89 89
   //     const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));

+ 7
- 7
Marlin/src/lcd/menu/game/snake.cpp 查看文件

@@ -84,14 +84,14 @@ void shorten_tail() {
84 84
   }
85 85
   if (shift) {
86 86
     sdat.head_ind--;
87
-    for (uint8_t i = 0; i <= sdat.head_ind; ++i)
87
+    LOOP_LE_N(i, sdat.head_ind)
88 88
       sdat.snake_tail[i] = sdat.snake_tail[i + 1];
89 89
   }
90 90
 }
91 91
 
92 92
 // The food is on a line
93 93
 inline bool food_on_line() {
94
-  for (uint8_t n = 0; n < sdat.head_ind; ++n) {
94
+  LOOP_L_N(n, sdat.head_ind) {
95 95
     pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
96 96
     if (p.x == q.x) {
97 97
       if ((sdat.foodx == p.x - 1 || sdat.foodx == p.x) && WITHIN(sdat.foody, _MIN(p.y, q.y), _MAX(p.y, q.y)))
@@ -151,7 +151,7 @@ bool snake_overlap() {
151 151
   // VERTICAL head segment?
152 152
   if (h1.x == h2.x) {
153 153
     // Loop from oldest to segment two away from head
154
-    for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
154
+    LOOP_L_N(n, sdat.head_ind - 2) {
155 155
       // Segment p to q
156 156
       const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
157 157
       if (p.x != q.x) {
@@ -163,7 +163,7 @@ bool snake_overlap() {
163 163
   }
164 164
   else {
165 165
     // Loop from oldest to segment two away from head
166
-    for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
166
+    LOOP_L_N(n, sdat.head_ind - 2) {
167 167
       // Segment p to q
168 168
       const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
169 169
       if (p.y != q.y) {
@@ -240,7 +240,7 @@ void SnakeGame::game_screen() {
240 240
   #if SNAKE_WH < 2
241 241
 
242 242
     // At this scale just draw a line
243
-    for (uint8_t n = 0; n < sdat.head_ind; ++n) {
243
+    LOOP_L_N(n, sdat.head_ind) {
244 244
       const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
245 245
       if (p.x == q.x) {
246 246
         const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@@ -256,7 +256,7 @@ void SnakeGame::game_screen() {
256 256
   #elif SNAKE_WH == 2
257 257
 
258 258
     // At this scale draw two lines
259
-    for (uint8_t n = 0; n < sdat.head_ind; ++n) {
259
+    LOOP_L_N(n, sdat.head_ind) {
260 260
       const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
261 261
       if (p.x == q.x) {
262 262
         const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@@ -275,7 +275,7 @@ void SnakeGame::game_screen() {
275 275
   #else
276 276
 
277 277
     // Draw a series of boxes
278
-    for (uint8_t n = 0; n < sdat.head_ind; ++n) {
278
+    LOOP_L_N(n, sdat.head_ind) {
279 279
       const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
280 280
       if (p.x == q.x) {
281 281
         const int8_t y1 = _MIN(p.y, q.y), y2 = _MAX(p.y, q.y);

+ 8
- 8
Marlin/src/lcd/menu/menu_advanced.cpp 查看文件

@@ -114,7 +114,7 @@ void menu_cancelobject();
114 114
       #if EXTRUDERS == 1
115 115
         EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
116 116
       #elif EXTRUDERS > 1
117
-        for (uint8_t n = 0; n < EXTRUDERS; n++)
117
+        LOOP_L_N(n, EXTRUDERS)
118 118
           EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
119 119
       #endif
120 120
     #endif
@@ -125,7 +125,7 @@ void menu_cancelobject();
125 125
       if (parser.volumetric_enabled) {
126 126
         EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
127 127
         #if EXTRUDERS > 1
128
-          for (uint8_t n = 0; n < EXTRUDERS; n++)
128
+          LOOP_L_N(n, EXTRUDERS)
129 129
             EDIT_ITEM_FAST_N(float43, n, MSG_FILAMENT_DIAM_E, &planner.filament_size[n], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
130 130
         #endif
131 131
       }
@@ -142,13 +142,13 @@ void menu_cancelobject();
142 142
 
143 143
       EDIT_ITEM_FAST(float3, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
144 144
       #if EXTRUDERS > 1
145
-        for (uint8_t n = 0; n < EXTRUDERS; n++)
145
+        LOOP_L_N(n, EXTRUDERS)
146 146
           EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTUNLOAD_E, &fc_settings[n].unload_length, 0, extrude_maxlength);
147 147
       #endif
148 148
 
149 149
       EDIT_ITEM_FAST(float3, MSG_FILAMENT_LOAD, &fc_settings[active_extruder].load_length, 0, extrude_maxlength);
150 150
       #if EXTRUDERS > 1
151
-        for (uint8_t n = 0; n < EXTRUDERS; n++)
151
+        LOOP_L_N(n, EXTRUDERS)
152 152
           EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTLOAD_E, &fc_settings[n].load_length, 0, extrude_maxlength);
153 153
       #endif
154 154
     #endif
@@ -358,7 +358,7 @@ void menu_cancelobject();
358 358
       EDIT_ITEM_FAST(float3, MSG_VMAX_E, &planner.settings.max_feedrate_mm_s[E_AXIS_N(active_extruder)], 1, max_fr_edit_scaled.e);
359 359
     #endif
360 360
     #if ENABLED(DISTINCT_E_FACTORS)
361
-      for (uint8_t n = 0; n < E_STEPPERS; n++)
361
+      LOOP_L_N(n, E_STEPPERS)
362 362
         EDIT_ITEM_FAST_N(float3, n, MSG_VMAX_EN, &planner.settings.max_feedrate_mm_s[E_AXIS_N(n)], 1, max_fr_edit_scaled.e);
363 363
     #endif
364 364
 
@@ -409,7 +409,7 @@ void menu_cancelobject();
409 409
 
410 410
     #if ENABLED(DISTINCT_E_FACTORS)
411 411
       EDIT_ITEM_FAST(long5_25, MSG_AMAX_E, &planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(active_extruder)], 100, max_accel_edit_scaled.e, []{ planner.reset_acceleration_rates(); });
412
-      for (uint8_t n = 0; n < E_STEPPERS; n++)
412
+      LOOP_L_N(n, E_STEPPERS)
413 413
         EDIT_ITEM_FAST_N(long5_25, n, MSG_AMAX_EN, &planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(n)], 100, max_accel_edit_scaled.e, []{ _reset_e_acceleration_rate(MenuItemBase::itemIndex); });
414 414
     #elif E_STEPPERS
415 415
       EDIT_ITEM_FAST(long5_25, MSG_AMAX_E, &planner.settings.max_acceleration_mm_per_s2[E_AXIS], 100, max_accel_edit_scaled.e, []{ planner.reset_acceleration_rates(); });
@@ -484,7 +484,7 @@ void menu_advanced_steps_per_mm() {
484 484
 
485 485
   #if ENABLED(DISTINCT_E_FACTORS)
486 486
     EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(active_extruder)], 5, 9999, []{ planner.refresh_positioning(); });
487
-    for (uint8_t n = 0; n < E_STEPPERS; n++)
487
+    LOOP_L_N(n, E_STEPPERS)
488 488
       EDIT_ITEM_FAST_N(float51, n, MSG_EN_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(n)], 5, 9999, []{ _planner_refresh_e_positioning(MenuItemBase::itemIndex); });
489 489
   #elif E_STEPPERS
490 490
     EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS], 5, 9999, []{ planner.refresh_positioning(); });
@@ -558,7 +558,7 @@ void menu_advanced_settings() {
558 558
     #if EXTRUDERS == 1
559 559
       EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
560 560
     #elif EXTRUDERS > 1
561
-      for (uint8_t n = 0; n < E_STEPPERS; n++)
561
+      LOOP_L_N(n, E_STEPPERS)
562 562
         EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
563 563
     #endif
564 564
   #endif

+ 4
- 4
Marlin/src/lcd/menu/menu_filament.cpp 查看文件

@@ -114,7 +114,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
114 114
         GCODES_ITEM_P(msg, PSTR("M600 B0"));
115 115
     #else
116 116
       PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE_E);
117
-      for (uint8_t s = 0; s < E_STEPPERS; s++) {
117
+      LOOP_L_N(s, E_STEPPERS) {
118 118
         if (thermalManager.targetTooColdToExtrude(s))
119 119
           SUBMENU_N_P(s, msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, MenuItemBase::itemIndex); });
120 120
         else {
@@ -138,7 +138,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
138 138
             GCODES_ITEM_P(msg_load, PSTR("M701"));
139 139
         #else
140 140
           PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD_E);
141
-          for (uint8_t s = 0; s < E_STEPPERS; s++) {
141
+          LOOP_L_N(s, E_STEPPERS) {
142 142
             if (thermalManager.targetTooColdToExtrude(s))
143 143
               SUBMENU_N_P(s, msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, MenuItemBase::itemIndex); });
144 144
             else {
@@ -162,7 +162,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
162 162
           #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
163 163
           {
164 164
             bool too_cold = false;
165
-            for (uint8_t s = 0; s < E_STEPPERS; s++) {
165
+            LOOP_L_N(s, E_STEPPERS) {
166 166
               if (thermalManager.targetTooColdToExtrude(s)) {
167 167
                 too_cold = true; break;
168 168
               }
@@ -174,7 +174,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
174 174
           }
175 175
           #endif
176 176
           PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD_E);
177
-          for (uint8_t s = 0; s < E_STEPPERS; s++) {
177
+          LOOP_L_N(s, E_STEPPERS) {
178 178
             if (thermalManager.targetTooColdToExtrude(s))
179 179
               SUBMENU_N_P(s, msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, MenuItemBase::itemIndex); });
180 180
             else {

+ 1
- 1
Marlin/src/lcd/menu/menu_mixer.cpp 查看文件

@@ -181,7 +181,7 @@ void lcd_mixer_mix_edit() {
181 181
 
182 182
     #if CHANNEL_MIX_EDITING
183 183
 
184
-      for (uint8_t n = 1; n <= MIXING_STEPPERS; n++)
184
+      LOOP_S_LE_N(n, 1, MIXING_STEPPERS)
185 185
         EDIT_ITEM_FAST_N(float52, n, MSG_MIX_COMPONENT_N, &mixer.collector[n-1], 0, 10);
186 186
 
187 187
       ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);

+ 1
- 1
Marlin/src/lcd/menu/menu_mmu2.cpp 查看文件

@@ -54,7 +54,7 @@ void _mmu2_load_filament(uint8_t index) {
54 54
   ui.reset_status();
55 55
 }
56 56
 void action_mmu2_load_all() {
57
-  for (uint8_t i = 0; i < EXTRUDERS; i++)
57
+  LOOP_L_N(i, EXTRUDERS)
58 58
     _mmu2_load_filament(i);
59 59
   ui.return_to_status();
60 60
 }

+ 1
- 1
Marlin/src/lcd/menu/menu_motion.cpp 查看文件

@@ -357,7 +357,7 @@ void menu_move() {
357 357
     #elif E_MANUAL > 1
358 358
 
359 359
       // Independent extruders with one E-stepper per hotend
360
-      for (uint8_t n = 0; n < E_MANUAL; n++) SUBMENU_MOVE_E(n);
360
+      LOOP_L_N(n, E_MANUAL) SUBMENU_MOVE_E(n);
361 361
 
362 362
     #endif
363 363
 

+ 2
- 2
Marlin/src/lcd/menu/menu_temperature.cpp 查看文件

@@ -111,7 +111,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
111 111
       #if HAS_HEATED_BED
112 112
         _PREHEAT_ITEMS(1,0);
113 113
       #endif
114
-      for (uint8_t n = 1; n < HOTENDS; n++) PREHEAT_ITEMS(1,n);
114
+      LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(1,n);
115 115
       ACTION_ITEM(MSG_PREHEAT_1_ALL, []() {
116 116
         #if HAS_HEATED_BED
117 117
           _preheat_bed(0);
@@ -139,7 +139,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
139 139
       #if HAS_HEATED_BED
140 140
         _PREHEAT_ITEMS(2,0);
141 141
       #endif
142
-      for (uint8_t n = 1; n < HOTENDS; n++) PREHEAT_ITEMS(2,n);
142
+      LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(2,n);
143 143
       ACTION_ITEM(MSG_PREHEAT_2_ALL, []() {
144 144
         #if HAS_HEATED_BED
145 145
           _preheat_bed(1);

+ 2
- 2
Marlin/src/lcd/menu/menu_tune.cpp 查看文件

@@ -222,7 +222,7 @@ void menu_tune() {
222 222
     EDIT_ITEM(int3, MSG_FLOW, &planner.flow_percentage[active_extruder], 10, 999, []{ planner.refresh_e_factor(active_extruder); });
223 223
     // Flow En:
224 224
     #if EXTRUDERS > 1
225
-      for (uint8_t n = 0; n < EXTRUDERS; n++)
225
+      LOOP_L_N(n, EXTRUDERS)
226 226
         EDIT_ITEM_N(int3, n, MSG_FLOW_N, &planner.flow_percentage[n], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
227 227
     #endif
228 228
   #endif
@@ -234,7 +234,7 @@ void menu_tune() {
234 234
     #if EXTRUDERS == 1
235 235
       EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
236 236
     #elif EXTRUDERS > 1
237
-      for (uint8_t n = 0; n < EXTRUDERS; n++)
237
+      LOOP_L_N(n, EXTRUDERS)
238 238
         EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
239 239
     #endif
240 240
   #endif

+ 1
- 1
Marlin/src/lcd/ultralcd.cpp 查看文件

@@ -1136,7 +1136,7 @@ void MarlinUI::update() {
1136 1136
       thermalManager.current_ADCKey_raw = HAL_ADC_RANGE;
1137 1137
       thermalManager.ADCKey_count = 0;
1138 1138
       if (currentkpADCValue < adc_other_button)
1139
-        for (uint8_t i = 0; i < ADC_KEY_NUM; i++) {
1139
+        LOOP_L_N(i, ADC_KEY_NUM) {
1140 1140
           const uint16_t lo = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMin),
1141 1141
                          hi = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMax);
1142 1142
           if (WITHIN(currentkpADCValue, lo, hi)) return pgm_read_byte(&stADCKeyTable[i].ADCKeyNo);

+ 1
- 1
Marlin/src/libs/L64XX/L64XX_Marlin.cpp 查看文件

@@ -508,7 +508,7 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in
508 508
   // Work on the drivers
509 509
   //
510 510
 
511
-  for (uint8_t k = 0; k < driver_count; k++) {
511
+  LOOP_L_N(k, driver_count) {
512 512
     uint8_t not_found = true;
513 513
     for (j = 1; j <= L64XX::chain[0]; j++) {
514 514
       PGM_P const str = (PGM_P)pgm_read_ptr(&index_to_axis[L64XX::chain[j]]);

+ 4
- 4
Marlin/src/libs/nozzle.cpp 查看文件

@@ -54,7 +54,7 @@ Nozzle nozzle;
54 54
     #endif
55 55
 
56 56
     // Start the stroke pattern
57
-    for (uint8_t i = 0; i < (strokes >> 1); i++) {
57
+    LOOP_L_N(i, strokes >> 1) {
58 58
       do_blocking_move_to_xy(end);
59 59
       do_blocking_move_to_xy(start);
60 60
     }
@@ -91,7 +91,7 @@ Nozzle nozzle;
91 91
     const bool horiz = ABS(diff.x) >= ABS(diff.y);    // Do a horizontal wipe?
92 92
     const float P = (horiz ? diff.x : diff.y) / zigs; // Period of each zig / zag
93 93
     const xyz_pos_t *side;
94
-    for (uint8_t j = 0; j < strokes; j++) {
94
+    LOOP_L_N(j, strokes) {
95 95
       for (int8_t i = 0; i < zigs; i++) {
96 96
         side = (i & 1) ? &end : &start;
97 97
         if (horiz)
@@ -134,8 +134,8 @@ Nozzle nozzle;
134 134
       do_blocking_move_to(start);
135 135
     #endif
136 136
 
137
-    for (uint8_t s = 0; s < strokes; s++)
138
-      for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++)
137
+    LOOP_L_N(s, strokes)
138
+      LOOP_L_N(i, NOZZLE_CLEAN_CIRCLE_FN)
139 139
         do_blocking_move_to_xy(
140 140
           middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius,
141 141
           middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius

+ 6
- 6
Marlin/src/libs/vector_3.cpp 查看文件

@@ -96,8 +96,8 @@ void apply_rotation_xyz(const matrix_3x3 &matrix, float &_x, float &_y, float &_
96 96
 
97 97
 // Reset to identity. No rotate or translate.
98 98
 void matrix_3x3::set_to_identity() {
99
-  for (uint8_t i = 0; i < 3; i++)
100
-    for (uint8_t j = 0; j < 3; j++)
99
+  LOOP_L_N(i, 3)
100
+    LOOP_L_N(j, 3)
101 101
       vectors[i][j] = float(i == j);
102 102
 }
103 103
 
@@ -134,8 +134,8 @@ matrix_3x3 matrix_3x3::create_look_at(const vector_3 &target) {
134 134
 // Get a transposed copy of the matrix
135 135
 matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) {
136 136
   matrix_3x3 new_matrix;
137
-  for (uint8_t i = 0; i < 3; i++)
138
-    for (uint8_t j = 0; j < 3; j++)
137
+  LOOP_L_N(i, 3)
138
+    LOOP_L_N(j, 3)
139 139
       new_matrix.vectors[i][j] = original.vectors[j][i];
140 140
   return new_matrix;
141 141
 }
@@ -145,8 +145,8 @@ void matrix_3x3::debug(PGM_P const title) {
145 145
     serialprintPGM(title);
146 146
     SERIAL_EOL();
147 147
   }
148
-  for (uint8_t i = 0; i < 3; i++) {
149
-    for (uint8_t j = 0; j < 3; j++) {
148
+  LOOP_L_N(i, 3) {
149
+    LOOP_L_N(j, 3) {
150 150
       if (vectors[i][j] >= 0.0) SERIAL_CHAR('+');
151 151
       SERIAL_ECHO_F(vectors[i][j], 6);
152 152
       SERIAL_CHAR(' ');

+ 3
- 3
Marlin/src/module/configuration_store.cpp 查看文件

@@ -583,7 +583,7 @@ void MarlinSettings::postprocess() {
583 583
 
584 584
       #if HAS_HOTEND_OFFSET
585 585
         // Skip hotend 0 which must be 0
586
-        for (uint8_t e = 1; e < HOTENDS; e++)
586
+        LOOP_S_L_N(e, 1, HOTENDS)
587 587
           EEPROM_WRITE(hotend_offset[e]);
588 588
       #endif
589 589
     }
@@ -1420,7 +1420,7 @@ void MarlinSettings::postprocess() {
1420 1420
       {
1421 1421
         #if HAS_HOTEND_OFFSET
1422 1422
           // Skip hotend 0 which must be 0
1423
-          for (uint8_t e = 1; e < HOTENDS; e++)
1423
+          LOOP_S_L_N(e, 1, HOTENDS)
1424 1424
             EEPROM_READ(hotend_offset[e]);
1425 1425
         #endif
1426 1426
       }
@@ -2915,7 +2915,7 @@ void MarlinSettings::reset() {
2915 2915
     #if HAS_HOTEND_OFFSET
2916 2916
       CONFIG_ECHO_HEADING("Hotend offsets:");
2917 2917
       CONFIG_ECHO_START();
2918
-      for (uint8_t e = 1; e < HOTENDS; e++) {
2918
+      LOOP_S_L_N(e, 1, HOTENDS) {
2919 2919
         SERIAL_ECHOPAIR_P(
2920 2920
           PSTR("  M218 T"), (int)e,
2921 2921
           SP_X_STR, LINEAR_UNIT(hotend_offset[e].x),

+ 1
- 1
Marlin/src/module/endstops.cpp 查看文件

@@ -481,7 +481,7 @@ void _O2 Endstops::report_states() {
481 481
       print_es_state(READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_INVERTING, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
482 482
     #else
483 483
       #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; break;
484
-      for (uint8_t i = 1; i <= NUM_RUNOUT_SENSORS; i++) {
484
+      LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) {
485 485
         pin_t pin;
486 486
         switch (i) {
487 487
           default: continue;

+ 2
- 2
Marlin/src/module/planner.cpp 查看文件

@@ -1408,7 +1408,7 @@ void Planner::check_axes_activity() {
1408 1408
    * The multiplier converts a given E value into a length.
1409 1409
    */
1410 1410
   void Planner::calculate_volumetric_multipliers() {
1411
-    for (uint8_t i = 0; i < COUNT(filament_size); i++) {
1411
+    LOOP_L_N(i, COUNT(filament_size)) {
1412 1412
       volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
1413 1413
       refresh_e_factor(i);
1414 1414
     }
@@ -1991,7 +1991,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
1991 1991
 
1992 1992
       #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
1993 1993
 
1994
-        for (uint8_t i = 0; i < EXTRUDERS; i++)
1994
+        LOOP_L_N(i, EXTRUDERS)
1995 1995
           if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
1996 1996
 
1997 1997
         #if HAS_DUPLICATION_MODE

+ 2
- 2
Marlin/src/module/planner.h 查看文件

@@ -403,7 +403,7 @@ class Planner {
403 403
       FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
404 404
         filament_size[e] = v;
405 405
         // make sure all extruders have some sane value for the filament size
406
-        for (uint8_t i = 0; i < COUNT(filament_size); i++)
406
+        LOOP_L_N(i, COUNT(filament_size))
407 407
           if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
408 408
       }
409 409
 
@@ -807,7 +807,7 @@ class Planner {
807 807
       FORCE_INLINE static void recalculate_max_e_jerk() {
808 808
         #define GET_MAX_E_JERK(N) SQRT(SQRT(0.5) * junction_deviation_mm * (N) * RECIPROCAL(1.0 - SQRT(0.5)))
809 809
         #if ENABLED(DISTINCT_E_FACTORS)
810
-          for (uint8_t i = 0; i < EXTRUDERS; i++)
810
+          LOOP_L_N(i, EXTRUDERS)
811 811
             max_e_jerk[i] = GET_MAX_E_JERK(settings.max_acceleration_mm_per_s2[E_AXIS_N(i)]);
812 812
         #else
813 813
           max_e_jerk = GET_MAX_E_JERK(settings.max_acceleration_mm_per_s2[E_AXIS]);

+ 2
- 2
Marlin/src/module/probe.cpp 查看文件

@@ -624,7 +624,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
624 624
 
625 625
       #if EXTRA_PROBING
626 626
         // Insert Z measurement into probes[]. Keep it sorted ascending.
627
-        for (uint8_t i = 0; i <= p; i++) {                            // Iterate the saved Zs to insert the new Z
627
+        LOOP_LE_N(i, p) {                            // Iterate the saved Zs to insert the new Z
628 628
           if (i == p || probes[i] > z) {                              // Last index or new Z is smaller than this Z
629 629
             for (int8_t m = p; --m >= i;) probes[m + 1] = probes[m];  // Shift items down after the insertion point
630 630
             probes[i] = z;                                            // Insert the new Z measurement
@@ -662,7 +662,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
662 662
           max_avg_idx--; else min_avg_idx++;
663 663
 
664 664
       // Return the average value of all remaining probes.
665
-      for (uint8_t i = min_avg_idx; i <= max_avg_idx; i++)
665
+      LOOP_S_LE_N(i, min_avg_idx, max_avg_idx)
666 666
         probes_z_sum += probes[i];
667 667
 
668 668
     #endif

+ 2
- 2
Marlin/src/module/stepper.cpp 查看文件

@@ -2116,7 +2116,7 @@ void Stepper::init() {
2116 2116
   #if MB(ALLIGATOR)
2117 2117
     const float motor_current[] = MOTOR_CURRENT;
2118 2118
     unsigned int digipot_motor = 0;
2119
-    for (uint8_t i = 0; i < 3 + EXTRUDERS; i++) {
2119
+    LOOP_L_N(i, 3 + EXTRUDERS) {
2120 2120
       digipot_motor = 255 * (motor_current[i] / 2.5);
2121 2121
       dac084s085::setValue(i, digipot_motor);
2122 2122
     }
@@ -2756,7 +2756,7 @@ void Stepper::report_positions() {
2756 2756
         SPI.begin();
2757 2757
         SET_OUTPUT(DIGIPOTSS_PIN);
2758 2758
 
2759
-        for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++) {
2759
+        LOOP_L_N(i, COUNT(digipot_motor_current)) {
2760 2760
           //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
2761 2761
           digipot_current(i, digipot_motor_current[i]);
2762 2762
         }

+ 2
- 2
Marlin/src/module/temperature.cpp 查看文件

@@ -708,7 +708,7 @@ int16_t Temperature::getHeaterPower(const heater_ind_t heater_id) {
708 708
     }while(0)
709 709
 
710 710
     uint8_t fanDone = 0;
711
-    for (uint8_t f = 0; f < COUNT(fanBit); f++) {
711
+    LOOP_L_N(f, COUNT(fanBit)) {
712 712
       const uint8_t realFan = pgm_read_byte(&fanBit[f]);
713 713
       if (TEST(fanDone, realFan)) continue;
714 714
       const bool fan_on = TEST(fanState, realFan);
@@ -2422,7 +2422,7 @@ void Temperature::readings_ready() {
2422 2422
       #endif // HOTENDS > 1
2423 2423
     };
2424 2424
 
2425
-    for (uint8_t e = 0; e < COUNT(temp_dir); e++) {
2425
+    LOOP_L_N(e, COUNT(temp_dir)) {
2426 2426
       const int8_t tdir = temp_dir[e];
2427 2427
       if (tdir) {
2428 2428
         const int16_t rawtemp = temp_hotend[e].raw * tdir; // normal direction, +rawtemp, else -rawtemp

+ 1
- 1
Marlin/src/module/tool_change.cpp 查看文件

@@ -251,7 +251,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
251 251
 #elif ENABLED(PARKING_EXTRUDER)
252 252
 
253 253
   void pe_solenoid_init() {
254
-    for (uint8_t n = 0; n <= 1; ++n)
254
+    LOOP_LE_N(n, 1)
255 255
       #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
256 256
         pe_activate_solenoid(n);
257 257
       #else

+ 1
- 1
Marlin/src/pins/pinsDebug.h 查看文件

@@ -228,7 +228,7 @@ inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool e
228 228
     return true;
229 229
   };
230 230
 
231
-  for (uint8_t x = 0; x < COUNT(pin_array); x++)  {    // scan entire array and report all instances of this pin
231
+  LOOP_L_N(x, COUNT(pin_array))  {    // scan entire array and report all instances of this pin
232 232
     if (GET_ARRAY_PIN(x) == pin) {
233 233
       if (!found) {    // report digital and analog pin number only on the first time through
234 234
         if (start_string) serialprintPGM(start_string);

+ 5
- 5
Marlin/src/sd/Sd2Card.cpp 查看文件

@@ -74,7 +74,7 @@
74 74
   #else
75 75
     static uint8_t CRC7(const uint8_t* data, uint8_t n) {
76 76
       uint8_t crc = 0;
77
-      for (uint8_t i = 0; i < n; i++) {
77
+      LOOP_L_N(i, n) {
78 78
         uint8_t d = data[i];
79 79
         d ^= crc << 1;
80 80
         if (d & 0x80) d ^= 9;
@@ -106,7 +106,7 @@ uint8_t Sd2Card::cardCommand(const uint8_t cmd, const uint32_t arg) {
106 106
     d[5] = CRC7(d, 5);
107 107
 
108 108
     // Send message
109
-    for (uint8_t k = 0; k < 6; k++) spiSend(d[k]);
109
+    LOOP_L_N(k, 6) spiSend(d[k]);
110 110
 
111 111
   #else
112 112
     // Send command
@@ -246,7 +246,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
246 246
   spiInit(spiRate_);
247 247
 
248 248
   // Must supply min of 74 clock cycles with CS high.
249
-  for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
249
+  LOOP_L_N(i, 10) spiSend(0xFF);
250 250
 
251 251
   watchdog_refresh(); // In case init takes too long
252 252
 
@@ -272,7 +272,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
272 272
     }
273 273
 
274 274
     // Get the last byte of r7 response
275
-    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
275
+    LOOP_L_N(i, 4) status_ = spiRec();
276 276
     if (status_ == 0xAA) {
277 277
       type(SD_CARD_TYPE_SD2);
278 278
       break;
@@ -303,7 +303,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
303 303
     }
304 304
     if ((spiRec() & 0xC0) == 0xC0) type(SD_CARD_TYPE_SDHC);
305 305
     // Discard rest of ocr - contains allowed voltage range
306
-    for (uint8_t i = 0; i < 3; i++) spiRec();
306
+    LOOP_L_N(i, 3) spiRec();
307 307
   }
308 308
   chipDeselect();
309 309
 

+ 5
- 5
Marlin/src/sd/SdBaseFile.cpp 查看文件

@@ -204,7 +204,7 @@ bool SdBaseFile::dirEntry(dir_t* dir) {
204 204
  */
205 205
 void SdBaseFile::dirName(const dir_t& dir, char* name) {
206 206
   uint8_t j = 0;
207
-  for (uint8_t i = 0; i < 11; i++) {
207
+  LOOP_L_N(i, 11) {
208 208
     if (dir.name[i] == ' ')continue;
209 209
     if (i == 8) name[j++] = '.';
210 210
     name[j++] = dir.name[i];
@@ -345,10 +345,10 @@ int8_t SdBaseFile::lsPrintNext(uint8_t flags, uint8_t indent) {
345 345
         && DIR_IS_FILE_OR_SUBDIR(&dir)) break;
346 346
   }
347 347
   // indent for dir level
348
-  for (uint8_t i = 0; i < indent; i++) SERIAL_CHAR(' ');
348
+  LOOP_L_N(i, indent) SERIAL_CHAR(' ');
349 349
 
350 350
   // print name
351
-  for (uint8_t i = 0; i < 11; i++) {
351
+  LOOP_L_N(i, 11) {
352 352
     if (dir.name[i] == ' ')continue;
353 353
     if (i == 8) {
354 354
       SERIAL_CHAR('.');
@@ -478,7 +478,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
478 478
   // make entry for '.'
479 479
   memcpy(&d, p, sizeof(d));
480 480
   d.name[0] = '.';
481
-  for (uint8_t i = 1; i < 11; i++) d.name[i] = ' ';
481
+  LOOP_S_L_N(i, 1, 11) d.name[i] = ' ';
482 482
 
483 483
   // cache block for '.'  and '..'
484 484
   block = vol_->clusterStartBlock(firstCluster_);
@@ -1088,7 +1088,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
1088 1088
         if (WITHIN(seq, 1, MAX_VFAT_ENTRIES)) {
1089 1089
           // TODO: Store the filename checksum to verify if a long-filename-unaware system modified the file table.
1090 1090
           n = (seq - 1) * (FILENAME_LENGTH);
1091
-          for (uint8_t i = 0; i < FILENAME_LENGTH; i++)
1091
+          LOOP_L_N(i, FILENAME_LENGTH)
1092 1092
             longFilename[n + i] = (i < 5) ? VFAT->name1[i] : (i < 11) ? VFAT->name2[i - 5] : VFAT->name3[i - 11];
1093 1093
           // If this VFAT entry is the last one, add a NUL terminator at the end of the string
1094 1094
           if (VFAT->sequenceNumber & 0x40) longFilename[n + FILENAME_LENGTH] = '\0';

+ 3
- 3
Marlin/src/sd/cardreader.cpp 查看文件

@@ -143,7 +143,7 @@ CardReader::CardReader() {
143 143
 //
144 144
 char *createFilename(char * const buffer, const dir_t &p) {
145 145
   char *pos = buffer;
146
-  for (uint8_t i = 0; i < 11; i++) {
146
+  LOOP_L_N(i, 11) {
147 147
     if (p.name[i] == ' ') continue;
148 148
     if (i == 8) *pos++ = '.';
149 149
     *pos++ = p.name[i];
@@ -435,7 +435,7 @@ void CardReader::getAbsFilename(char *dst) {
435 435
     if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; }
436 436
   };
437 437
 
438
-  for (uint8_t i = 0; i < workDirDepth; i++)                // Loop down to current work dir
438
+  LOOP_L_N(i, workDirDepth)                // Loop down to current work dir
439 439
     appendAtom(workDirParents[i]);
440 440
 
441 441
   if (cnt < MAXPATHNAMELENGTH - (FILENAME_LENGTH) - 1) {    // Leave room for filename and nul
@@ -1046,7 +1046,7 @@ void CardReader::cdroot() {
1046 1046
       #if ENABLED(SDSORT_DYNAMIC_RAM)
1047 1047
         delete sort_order;
1048 1048
         #if ENABLED(SDSORT_CACHE_NAMES)
1049
-          for (uint8_t i = 0; i < sort_count; ++i) {
1049
+          LOOP_L_N(i, sort_count) {
1050 1050
             free(sortshort[i]); // strdup
1051 1051
             free(sortnames[i]); // strdup
1052 1052
           }

Loading…
取消
儲存