Browse Source

Apply loop shorthand macros (#17159)

Scott Lahteine 4 years ago
parent
commit
118bd2f8b2
No account linked to committer's email address
93 changed files with 458 additions and 498 deletions
  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 View File

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

+ 1
- 1
Marlin/src/HAL/AVR/MarlinSerial.cpp View File

682
 
682
 
683
     // Round correctly so that print(1.999, 2) prints as "2.00"
683
     // Round correctly so that print(1.999, 2) prints as "2.00"
684
     double rounding = 0.5;
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
     number += rounding;
686
     number += rounding;
687
 
687
 
688
     // Extract the integer part of the number and print it
688
     // Extract the integer part of the number and print it

+ 1
- 1
Marlin/src/HAL/AVR/fast_pwm.cpp View File

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

+ 2
- 2
Marlin/src/HAL/AVR/pinsDebug.h View File

70
 
70
 
71
 void PRINT_ARRAY_NAME(uint8_t x) {
71
 void PRINT_ARRAY_NAME(uint8_t x) {
72
   char *name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
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
     char temp_char = pgm_read_byte(name_mem_pointer + y);
74
     char temp_char = pgm_read_byte(name_mem_pointer + y);
75
     if (temp_char != 0)
75
     if (temp_char != 0)
76
       SERIAL_CHAR(temp_char);
76
       SERIAL_CHAR(temp_char);
77
     else {
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
       break;
79
       break;
80
     }
80
     }
81
   }
81
   }

+ 2
- 2
Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp View File

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

+ 1
- 1
Marlin/src/HAL/DUE/MarlinSerial.cpp View File

606
 
606
 
607
   // Round correctly so that print(1.999, 2) prints as "2.00"
607
   // Round correctly so that print(1.999, 2) prints as "2.00"
608
   double rounding = 0.5;
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
   number += rounding;
610
   number += rounding;
611
 
611
 
612
   // Extract the integer part of the number and print it
612
   // Extract the integer part of the number and print it

+ 1
- 1
Marlin/src/HAL/DUE/MarlinSerialUSB.cpp View File

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

+ 2
- 2
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp View File

80
 uint32_t SCK_dwMask, MOSI_dwMask;
80
 uint32_t SCK_dwMask, MOSI_dwMask;
81
 
81
 
82
 void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
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
     if (val & 0x80)
84
     if (val & 0x80)
85
       MOSI_pPio->PIO_SODR = MOSI_dwMask;
85
       MOSI_pPio->PIO_SODR = MOSI_dwMask;
86
     else
86
     else
94
 }
94
 }
95
 
95
 
96
 void u8g_spiSend_sw_DUE_mode_3(uint8_t val) { // 3.5MHz
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
     SCK_pPio->PIO_CODR = SCK_dwMask;
98
     SCK_pPio->PIO_CODR = SCK_dwMask;
99
     DELAY_NS(50);
99
     DELAY_NS(50);
100
     if (val & 0x80)
100
     if (val & 0x80)

+ 1
- 1
Marlin/src/HAL/DUE/fastio/G2_PWM.h View File

63
 extern uint32_t motor_current_setting[3];
63
 extern uint32_t motor_current_setting[3];
64
 
64
 
65
 #define IR_BIT(p) (WITHIN(p, 0, 3) ? (p) : (p) + 4)
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
 #define PWM_MR0 19999         // base repetition rate minus one count - 20mS
68
 #define PWM_MR0 19999         // base repetition rate minus one count - 20mS
69
 #define PWM_PR 24             // prescaler value - prescaler divide by 24 + 1  -  1 MHz output
69
 #define PWM_PR 24             // prescaler value - prescaler divide by 24 + 1  -  1 MHz output

+ 1
- 1
Marlin/src/HAL/LPC1768/main.cpp View File

67
     #endif
67
     #endif
68
 
68
 
69
     // Flash status LED 3 times to indicate Marlin has started booting
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
       TOGGLE(LED_PIN);
71
       TOGGLE(LED_PIN);
72
       delay(100);
72
       delay(100);
73
     }
73
     }

+ 8
- 8
Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp View File

73
 
73
 
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 ) {
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
     if (spi_speed == 0) {
77
     if (spi_speed == 0) {
78
       LPC176x::gpio_set(mosi_pin, !!(b & 0x80));
78
       LPC176x::gpio_set(mosi_pin, !!(b & 0x80));
79
       LPC176x::gpio_set(sck_pin, HIGH);
79
       LPC176x::gpio_set(sck_pin, HIGH);
83
     }
83
     }
84
     else {
84
     else {
85
       const uint8_t state = (b & 0x80) ? HIGH : LOW;
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
         LPC176x::gpio_set(mosi_pin, state);
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
         LPC176x::gpio_set(sck_pin, HIGH);
90
         LPC176x::gpio_set(sck_pin, HIGH);
91
 
91
 
92
       b <<= 1;
92
       b <<= 1;
93
       if (miso_pin >= 0 && LPC176x::gpio_get(miso_pin)) b |= 1;
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
         LPC176x::gpio_set(sck_pin, LOW);
96
         LPC176x::gpio_set(sck_pin, LOW);
97
     }
97
     }
98
   }
98
   }
102
 
102
 
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 ) {
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
     const uint8_t state = (b & 0x80) ? HIGH : LOW;
106
     const uint8_t state = (b & 0x80) ? HIGH : LOW;
107
     if (spi_speed == 0) {
107
     if (spi_speed == 0) {
108
       LPC176x::gpio_set(sck_pin, LOW);
108
       LPC176x::gpio_set(sck_pin, LOW);
111
       LPC176x::gpio_set(sck_pin, HIGH);
111
       LPC176x::gpio_set(sck_pin, HIGH);
112
     }
112
     }
113
     else {
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
         LPC176x::gpio_set(sck_pin, LOW);
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
         LPC176x::gpio_set(mosi_pin, state);
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
         LPC176x::gpio_set(sck_pin, HIGH);
121
         LPC176x::gpio_set(sck_pin, HIGH);
122
     }
122
     }
123
     b <<= 1;
123
     b <<= 1;

+ 3
- 3
Marlin/src/HAL/SAMD51/HAL.cpp View File

478
   #if ADC_IS_REQUIRED
478
   #if ADC_IS_REQUIRED
479
     memset(HAL_adc_results, 0xFF, sizeof(HAL_adc_results));                 // Fill result with invalid values
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
       pinPeripheral(adc_pins[pi], PIO_ANALOG);
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
       Adc* adc = ((Adc*[])ADC_INSTS)[ai];
485
       Adc* adc = ((Adc*[])ADC_INSTS)[ai];
486
 
486
 
487
       // ADC clock setup
487
       // ADC clock setup
513
 
513
 
514
 void HAL_adc_start_conversion(const uint8_t adc_pin) {
514
 void HAL_adc_start_conversion(const uint8_t adc_pin) {
515
   #if ADC_IS_REQUIRED
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
       if (adc_pin == adc_pins[pi]) {
517
       if (adc_pin == adc_pins[pi]) {
518
         HAL_adc_result = HAL_adc_results[pi];
518
         HAL_adc_result = HAL_adc_results[pi];
519
         return;
519
         return;

+ 1
- 1
Marlin/src/HAL/STM32/fastio.cpp View File

27
 GPIO_TypeDef* FastIOPortMap[LastPort + 1];
27
 GPIO_TypeDef* FastIOPortMap[LastPort + 1];
28
 
28
 
29
 void FastIO_init() {
29
 void FastIO_init() {
30
-  for (uint8_t i = 0; i < NUM_DIGITAL_PINS; i++)
30
+  LOOP_L_N(i, NUM_DIGITAL_PINS)
31
     FastIOPortMap[STM_PORT(digitalPin[i])] = get_GPIO_Port(STM_PORT(digitalPin[i]));
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 View File

32
 static uint8_t SPI_speed = SPI_SPEED;
32
 static uint8_t SPI_speed = SPI_SPEED;
33
 
33
 
34
 static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
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
     if (spi_speed == 0) {
36
     if (spi_speed == 0) {
37
       WRITE(DOGLCD_MOSI, !!(b & 0x80));
37
       WRITE(DOGLCD_MOSI, !!(b & 0x80));
38
       WRITE(DOGLCD_SCK, HIGH);
38
       WRITE(DOGLCD_SCK, HIGH);
42
     }
42
     }
43
     else {
43
     else {
44
       const uint8_t state = (b & 0x80) ? HIGH : LOW;
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
         WRITE(DOGLCD_MOSI, state);
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
         WRITE(DOGLCD_SCK, HIGH);
49
         WRITE(DOGLCD_SCK, HIGH);
50
 
50
 
51
       b <<= 1;
51
       b <<= 1;
52
       if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
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
         WRITE(DOGLCD_SCK, LOW);
55
         WRITE(DOGLCD_SCK, LOW);
56
     }
56
     }
57
   }
57
   }
59
 }
59
 }
60
 
60
 
61
 static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
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
     const uint8_t state = (b & 0x80) ? HIGH : LOW;
63
     const uint8_t state = (b & 0x80) ? HIGH : LOW;
64
     if (spi_speed == 0) {
64
     if (spi_speed == 0) {
65
       WRITE(DOGLCD_SCK, LOW);
65
       WRITE(DOGLCD_SCK, LOW);
68
       WRITE(DOGLCD_SCK, HIGH);
68
       WRITE(DOGLCD_SCK, HIGH);
69
     }
69
     }
70
     else {
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
         WRITE(DOGLCD_SCK, LOW);
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
         WRITE(DOGLCD_MOSI, state);
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
         WRITE(DOGLCD_SCK, HIGH);
78
         WRITE(DOGLCD_SCK, HIGH);
79
     }
79
     }
80
     b <<= 1;
80
     b <<= 1;

+ 1
- 1
Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp View File

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

+ 1
- 1
Marlin/src/HAL/shared/servo.cpp View File

68
 
68
 
69
 static boolean isTimerActive(timer16_Sequence_t timer) {
69
 static boolean isTimerActive(timer16_Sequence_t timer) {
70
   // returns true if any servo is active on this timer
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
     if (SERVO(timer, channel).Pin.isActive)
72
     if (SERVO(timer, channel).Pin.isActive)
73
       return true;
73
       return true;
74
   }
74
   }

+ 1
- 1
Marlin/src/MarlinCore.cpp View File

274
 
274
 
275
 bool pin_is_protected(const pin_t pin) {
275
 bool pin_is_protected(const pin_t pin) {
276
   static const pin_t sensitive_pins[] PROGMEM = SENSITIVE_PINS;
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
     pin_t sensitive_pin;
278
     pin_t sensitive_pin;
279
     memcpy_P(&sensitive_pin, &sensitive_pins[i], sizeof(pin_t));
279
     memcpy_P(&sensitive_pin, &sensitive_pins[i], sizeof(pin_t));
280
     if (pin == sensitive_pin) return true;
280
     if (pin == sensitive_pin) return true;

+ 5
- 0
Marlin/src/core/macros.h View File

248
 #define _JOIN_1(O)         (O)
248
 #define _JOIN_1(O)         (O)
249
 #define JOIN_N(N,C,V...)   (DO(JOIN,C,LIST_N(N,V)))
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
 #define NOOP (void(0))
256
 #define NOOP (void(0))
252
 
257
 
253
 #define CEILING(x,y) (((x) + (y) - 1) / (y))
258
 #define CEILING(x,y) (((x) + (y) - 1) / (y))

+ 0
- 6
Marlin/src/core/types.h View File

50
 //
50
 //
51
 // Loop over XYZE axes
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
 #define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
53
 #define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
60
 #define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
54
 #define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
61
 #define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
55
 #define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)

+ 9
- 9
Marlin/src/feature/bedlevel/abl/abl.cpp View File

115
                       ylen = ctry1;
115
                       ylen = ctry1;
116
   #endif
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
       uint8_t x2 = ctrx2 + xo, y2 = ctry2 + yo;
120
       uint8_t x2 = ctrx2 + xo, y2 = ctry2 + yo;
121
       #ifndef HALF_IN_X
121
       #ifndef HALF_IN_X
122
         const uint8_t x1 = ctrx1 - xo;
122
         const uint8_t x1 = ctrx1 - xo;
209
 
209
 
210
   static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
210
   static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
211
     float row[4], column[4];
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
         column[j] = bed_level_virt_coord(i + x - 1, j + y - 1);
214
         column[j] = bed_level_virt_coord(i + x - 1, j + y - 1);
215
       }
215
       }
216
       row[i] = bed_level_virt_cmr(column, 1, ty);
216
       row[i] = bed_level_virt_cmr(column, 1, ty);
221
   void bed_level_virt_interpolate() {
221
   void bed_level_virt_interpolate() {
222
     bilinear_grid_spacing_virt = bilinear_grid_spacing / (BILINEAR_SUBDIVISIONS);
222
     bilinear_grid_spacing_virt = bilinear_grid_spacing / (BILINEAR_SUBDIVISIONS);
223
     bilinear_grid_factor_virt = bilinear_grid_spacing_virt.reciprocal();
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
               continue;
229
               continue;
230
             z_values_virt[x * (BILINEAR_SUBDIVISIONS) + tx][y * (BILINEAR_SUBDIVISIONS) + ty] =
230
             z_values_virt[x * (BILINEAR_SUBDIVISIONS) + tx][y * (BILINEAR_SUBDIVISIONS) + ty] =
231
               bed_level_virt_2cmr(
231
               bed_level_virt_2cmr(

+ 10
- 11
Marlin/src/feature/bedlevel/bedlevel.cpp View File

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

+ 3
- 5
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp View File

40
         mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
40
         mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
41
 
41
 
42
   mesh_bed_leveling::mesh_bed_leveling() {
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
       index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
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
       index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
46
       index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
47
     reset();
47
     reset();
48
   }
48
   }
51
     z_offset = 0;
51
     z_offset = 0;
52
     ZERO(z_values);
52
     ZERO(z_values);
53
     #if ENABLED(EXTENSIBLE_UI)
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
     #endif
55
     #endif
58
   }
56
   }
59
 
57
 

+ 1
- 3
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h View File

52
   static void reset();
52
   static void reset();
53
 
53
 
54
   FORCE_INLINE static bool has_mesh() {
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
     return false;
56
     return false;
59
   }
57
   }
60
 
58
 

+ 8
- 12
Marlin/src/feature/bedlevel/ubl/ubl.cpp View File

49
   void unified_bed_leveling::report_current_mesh() {
49
   void unified_bed_leveling::report_current_mesh() {
50
     if (!leveling_is_valid()) return;
50
     if (!leveling_is_valid()) return;
51
     SERIAL_ECHO_MSG("  G29 I99");
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
       for (uint8_t y = 0;  y < GRID_MAX_POINTS_Y; y++)
53
       for (uint8_t y = 0;  y < GRID_MAX_POINTS_Y; y++)
54
         if (!isnan(z_values[x][y])) {
54
         if (!isnan(z_values[x][y])) {
55
           SERIAL_ECHO_START();
55
           SERIAL_ECHO_START();
101
     storage_slot = -1;
101
     storage_slot = -1;
102
     ZERO(z_values);
102
     ZERO(z_values);
103
     #if ENABLED(EXTENSIBLE_UI)
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
     #endif
105
     #endif
108
     if (was_enabled) report_current_position();
106
     if (was_enabled) report_current_position();
109
   }
107
   }
114
   }
112
   }
115
 
113
 
116
   void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
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
       }
186
       }
191
 
187
 
192
       // Row Values (I indexes)
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
         // Opening Brace or Space
191
         // Opening Brace or Space
196
         const bool is_current = i == curr.x && j == curr.y;
192
         const bool is_current = i == curr.x && j == curr.y;

+ 1
- 3
Marlin/src/feature/bedlevel/ubl/ubl.h View File

298
     #endif
298
     #endif
299
 
299
 
300
     static inline bool mesh_is_valid() {
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
       return true;
302
       return true;
305
     }
303
     }
306
 
304
 

+ 130
- 151
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

365
         #endif
365
         #endif
366
 
366
 
367
         case 0:
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
           break;
376
           break;
379
 
377
 
380
         case 1:
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
             z_values[x][x] += 9.999f;
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
             #if ENABLED(EXTENSIBLE_UI)
382
             #if ENABLED(EXTENSIBLE_UI)
385
               ExtUI::onMeshUpdate(x, x, z_values[x][x]);
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
             #endif
385
             #endif
388
 
386
 
389
           }
387
           }
467
             //
465
             //
468
             // Manually Probe Mesh in areas that can't be reached by the probe
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
             do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
469
             do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
472
 
470
 
473
             if (parser.seen('C') && !xy_seen) {
471
             if (parser.seen('C') && !xy_seen) {
537
                 if (cpos.x < 0) {
535
                 if (cpos.x < 0) {
538
                   // No more REAL INVALID mesh points to populate, so we ASSUME
536
                   // No more REAL INVALID mesh points to populate, so we ASSUME
539
                   // user meant to populate ALL INVALID mesh points to value
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
                   break; // No more invalid Mesh Points to populate
539
                   break; // No more invalid Mesh Points to populate
544
                 }
540
                 }
545
                 else {
541
                 else {
696
   void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
692
   void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
697
     float sum = 0;
693
     float sum = 0;
698
     int n = 0;
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
     const float mean = sum / n;
701
     const float mean = sum / n;
707
 
702
 
709
     // Sum the squares of difference from mean
704
     // Sum the squares of difference from mean
710
     //
705
     //
711
     float sum_of_diff_squared = 0;
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
     SERIAL_ECHOLNPAIR("# of samples: ", n);
711
     SERIAL_ECHOLNPAIR("# of samples: ", n);
718
     SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6);
712
     SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6);
721
     SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
715
     SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
722
 
716
 
723
     if (cflag)
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
         if (!isnan(z_values[x][y])) {
719
         if (!isnan(z_values[x][y])) {
738
-          z_values[x][y] += g29_constant;
720
+          z_values[x][y] -= mean + value;
739
           #if ENABLED(EXTENSIBLE_UI)
721
           #if ENABLED(EXTENSIBLE_UI)
740
             ExtUI::onMeshUpdate(x, y, z_values[x][y]);
722
             ExtUI::onMeshUpdate(x, y, z_values[x][y]);
741
           #endif
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
   #if HAS_BED_PROBE
737
   #if HAS_BED_PROBE
746
     /**
738
     /**
747
      * Probe all invalidated locations of the mesh that can be reached by the probe.
739
      * Probe all invalidated locations of the mesh that can be reached by the probe.
1243
 
1235
 
1244
     mesh_index_pair farthest { -1, -1, -99999.99 };
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
     if (!found_a_real && found_a_NAN) {        // if the mesh is totally unpopulated, start the probing
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
       farthest.distance = 1;
1278
       farthest.distance = 1;
1293
     }
1279
     }
1294
     return farthest;
1280
     return farthest;
1304
 
1290
 
1305
     float best_so_far = 99999.99f;
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
     return closest;
1322
     return closest;
1339
   }
1323
   }
1373
       info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  };  // Right side of the mesh looking left
1357
       info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  };  // Right side of the mesh looking left
1374
     static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
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
       const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
1361
       const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
1378
       const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
1362
       const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
1379
                    ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
1363
                    ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
1496
 
1480
 
1497
         bool zig_zag = false;
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
         xy_pos_t rpos;
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
           rpos.x = x_min + ix * dx;
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
             rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
1490
             rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
1506
 
1491
 
1507
             if (!abort_flag) {
1492
             if (!abort_flag) {
1569
 
1554
 
1570
       matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
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
       if (DEBUGGING(LEVELING)) {
1590
       if (DEBUGGING(LEVELING)) {
1661
       // being extrapolated so that nearby points will have greater influence on
1644
       // being extrapolated so that nearby points will have greater influence on
1662
       // the point being extrapolated.  Then extrapolate the mesh point from WLSF.
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
       uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 };
1648
       uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 };
1666
       struct linear_fit_data lsf_results;
1649
       struct linear_fit_data lsf_results;
1667
 
1650
 
1669
 
1652
 
1670
       const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST);
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
       xy_pos_t ppos;
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
         ppos.x = mesh_index_to_xpos(ix);
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
           ppos.y = mesh_index_to_ypos(iy);
1661
           ppos.y = mesh_index_to_ypos(iy);
1682
           if (isnan(z_values[ix][iy])) {
1662
           if (isnan(z_values[ix][iy])) {
1683
             // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
1663
             // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
1684
             incremental_LSF_reset(&lsf_results);
1664
             incremental_LSF_reset(&lsf_results);
1685
             xy_pos_t rpos;
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
               rpos.x = mesh_index_to_xpos(jx);
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
                 if (TEST(bitmap[jx], jy)) {
1669
                 if (TEST(bitmap[jx], jy)) {
1690
                   rpos.y = mesh_index_to_ypos(jy);
1670
                   rpos.y = mesh_index_to_ypos(jy);
1691
                   const float rz = z_values[jx][jy],
1671
                   const float rz = z_values[jx][jy],
1747
       SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);                         serial_delay(50);
1727
       SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);                         serial_delay(50);
1748
 
1728
 
1749
       SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
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
         SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
1731
         SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
1752
         SERIAL_ECHOPGM("  ");
1732
         SERIAL_ECHOPGM("  ");
1753
         serial_delay(25);
1733
         serial_delay(25);
1755
       SERIAL_EOL();
1735
       SERIAL_EOL();
1756
 
1736
 
1757
       SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
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
         SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
1739
         SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
1760
         SERIAL_ECHOPGM("  ");
1740
         SERIAL_ECHOPGM("  ");
1761
         serial_delay(25);
1741
         serial_delay(25);
1840
 
1820
 
1841
       SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh.");
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
   #endif // UBL_DEVEL_DEBUGGING
1831
   #endif // UBL_DEVEL_DEBUGGING

+ 2
- 2
Marlin/src/feature/digipot/digipot_mcp4018.cpp View File

92
 void digipot_i2c_init() {
92
 void digipot_i2c_init() {
93
   static const float digipot_motor_current[] PROGMEM = DIGIPOT_I2C_MOTOR_CURRENTS;
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
     pots[i].i2c_init();
96
     pots[i].i2c_init();
97
 
97
 
98
   // setup initial currents as defined in Configuration_adv.h
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
     digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
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 View File

83
   #endif
83
   #endif
84
   // setup initial currents as defined in Configuration_adv.h
84
   // setup initial currents as defined in Configuration_adv.h
85
   static const float digipot_motor_current[] PROGMEM = DIGIPOT_I2C_MOTOR_CURRENTS;
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
     digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
87
     digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
88
 }
88
 }
89
 
89
 

+ 1
- 1
Marlin/src/feature/filwidth.cpp View File

42
 
42
 
43
 void FilamentWidthSensor::init() {
43
 void FilamentWidthSensor::init() {
44
   const int8_t ratio = sample_to_size_ratio();
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
   index_r = index_w = 0;
46
   index_r = index_w = 0;
47
 }
47
 }
48
 
48
 

+ 3
- 3
Marlin/src/feature/fwretract.cpp View File

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

+ 11
- 11
Marlin/src/feature/max7219.cpp View File

147
  */
147
  */
148
 inline uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) {
148
 inline uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) {
149
   uint32_t mask = 1, outbits = 0;
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
     outbits <<= 1;
151
     outbits <<= 1;
152
     if (bits & mask) outbits |= 1;
152
     if (bits & mask) outbits |= 1;
153
     mask <<= 1;
153
     mask <<= 1;
329
 
329
 
330
 void Max7219::clear_row(const uint8_t row) {
330
 void Max7219::clear_row(const uint8_t row) {
331
   if (row >= MAX7219_Y_LEDS) return error(PSTR("clear_row"), row);
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
   send_row(row);
333
   send_row(row);
334
 }
334
 }
335
 
335
 
336
 void Max7219::clear_column(const uint8_t col) {
336
 void Max7219::clear_column(const uint8_t col) {
337
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
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
   send_column(col);
339
   send_column(col);
340
 }
340
 }
341
 
341
 
347
 void Max7219::set_row(const uint8_t row, const uint32_t val) {
347
 void Max7219::set_row(const uint8_t row, const uint32_t val) {
348
   if (row >= MAX7219_Y_LEDS) return error(PSTR("set_row"), row);
348
   if (row >= MAX7219_Y_LEDS) return error(PSTR("set_row"), row);
349
   uint32_t mask = _BV32(MAX7219_X_LEDS - 1);
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
     if (val & mask) SET_7219(x, row); else CLR_7219(x, row);
351
     if (val & mask) SET_7219(x, row); else CLR_7219(x, row);
352
     mask >>= 1;
352
     mask >>= 1;
353
   }
353
   }
362
 void Max7219::set_column(const uint8_t col, const uint32_t val) {
362
 void Max7219::set_column(const uint8_t col, const uint32_t val) {
363
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
363
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
364
   uint32_t mask = _BV32(MAX7219_Y_LEDS - 1);
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
     if (val & mask) SET_7219(col, y); else CLR_7219(col, y);
366
     if (val & mask) SET_7219(col, y); else CLR_7219(col, y);
367
     mask >>= 1;
367
     mask >>= 1;
368
   }
368
   }
427
 
427
 
428
 // Initialize the Max7219
428
 // Initialize the Max7219
429
 void Max7219::register_setup() {
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
     send(max7219_reg_scanLimit, 0x07);
431
     send(max7219_reg_scanLimit, 0x07);
432
   pulse_load();                               // Tell the chips to load the clocked out data
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
     send(max7219_reg_decodeMode, 0x00);       // Using an led matrix (not digits)
435
     send(max7219_reg_decodeMode, 0x00);       // Using an led matrix (not digits)
436
   pulse_load();                               // Tell the chips to load the clocked out data
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
     send(max7219_reg_shutdown, 0x01);         // Not in shutdown mode
439
     send(max7219_reg_shutdown, 0x01);         // Not in shutdown mode
440
   pulse_load();                               // Tell the chips to load the clocked out data
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
     send(max7219_reg_displayTest, 0x00);      // No display test
443
     send(max7219_reg_displayTest, 0x00);      // No display test
444
   pulse_load();                               // Tell the chips to load the clocked out data
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
     send(max7219_reg_intensity, 0x01 & 0x0F); // The first 0x0F is the value you can set
447
     send(max7219_reg_intensity, 0x01 & 0x0F); // The first 0x0F is the value you can set
448
                                               // Range: 0x00 to 0x0F
448
                                               // Range: 0x00 to 0x0F
449
   pulse_load();                               // Tell the chips to load the clocked out data
449
   pulse_load();                               // Tell the chips to load the clocked out data
537
 
537
 
538
   register_setup();
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
     led_line[i] = 0x00;
541
     led_line[i] = 0x00;
542
     send(max7219_reg_digit0 + i, 0);
542
     send(max7219_reg_digit0 + i, 0);
543
     pulse_load();                     // Tell the chips to load the clocked out data
543
     pulse_load();                     // Tell the chips to load the clocked out data

+ 2
- 2
Marlin/src/feature/mixing.cpp View File

98
 void Mixer::reset_vtools() {
98
 void Mixer::reset_vtools() {
99
   // Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
99
   // Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
100
   // Every virtual tool gets a pure filament
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
     MIXER_STEPPER_LOOP(i)
102
     MIXER_STEPPER_LOOP(i)
103
       color[t][i] = (t == i) ? COLOR_A_MASK : 0;
103
       color[t][i] = (t == i) ? COLOR_A_MASK : 0;
104
 
104
 
105
   // Remaining virtual tools are 100% filament 1
105
   // Remaining virtual tools are 100% filament 1
106
   #if MIXING_VIRTUAL_TOOLS > MIXING_STEPPERS
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
       MIXER_STEPPER_LOOP(i)
108
       MIXER_STEPPER_LOOP(i)
109
         color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
109
         color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
110
   #endif
110
   #endif

+ 4
- 4
Marlin/src/feature/mmu2/mmu2.cpp View File

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

+ 1
- 1
Marlin/src/feature/powerloss.cpp View File

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

+ 3
- 3
Marlin/src/feature/probe_temp_comp.cpp View File

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

+ 1
- 1
Marlin/src/feature/runout.h View File

184
         #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG
184
         #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG
185
           if (change) {
185
           if (change) {
186
             SERIAL_ECHOPGM("Motion detected:");
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
               if (TEST(change, e)) SERIAL_CHAR(' ', '0' + e);
188
               if (TEST(change, e)) SERIAL_CHAR(' ', '0' + e);
189
             SERIAL_EOL();
189
             SERIAL_EOL();
190
           }
190
           }

+ 1
- 1
Marlin/src/feature/twibus.cpp View File

104
 
104
 
105
 void TWIBus::echobuffer(const char prefix[], uint8_t adr) {
105
 void TWIBus::echobuffer(const char prefix[], uint8_t adr) {
106
   echoprefix(buffer_s, prefix, adr);
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
   SERIAL_EOL();
108
   SERIAL_EOL();
109
 }
109
 }
110
 
110
 

+ 54
- 61
Marlin/src/gcode/bedlevel/G26.cpp View File

157
       g26_layer_height,
157
       g26_layer_height,
158
       g26_prime_length;
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
 int16_t g26_bed_temp,
162
 int16_t g26_bed_temp,
163
         g26_hotend_temp;
163
         g26_hotend_temp;
187
 
187
 
188
   out_point.pos = -1;
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
   xyz_pos_t s, e;
306
   xyz_pos_t s, e;
309
   s.z = e.z = g26_layer_height;
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
                                     // Already a half circle at the edge of the bed.
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
                                       // Already a half circle at the edge of the bed.
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
     return;
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
     SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds.");
630
     SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds.");
635
     return;
631
     return;
636
   }
632
   }
695
       #error "A_CNT must be a positive value. Please change A_INT."
691
       #error "A_CNT must be a positive value. Please change A_INT."
696
     #endif
692
     #endif
697
     float trig_table[A_CNT];
693
     float trig_table[A_CNT];
698
-    for (uint8_t i = 0; i < A_CNT; i++)
694
+    LOOP_L_N(i, A_CNT)
699
       trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT));
695
       trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT));
700
 
696
 
701
   #endif // !ARC_SUPPORT
697
   #endif // !ARC_SUPPORT
703
   mesh_index_pair location;
699
   mesh_index_pair location;
704
   do {
700
   do {
705
     // Find the nearest confluence
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
     if (location.valid()) {
704
     if (location.valid()) {
709
       const xy_pos_t circle = _GET_MESH_POS(location.pos);
705
       const xy_pos_t circle = _GET_MESH_POS(location.pos);
834
 
830
 
835
   retract_filament(destination);
831
   retract_filament(destination);
836
   destination.z = Z_CLEARANCE_BETWEEN_PROBES;
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
   move_to(destination, 0);                                    // Move back to the starting position
836
   move_to(destination, 0);                                    // Move back to the starting position
844
 
837
 
845
   #if DISABLED(NO_VOLUMETRICS)
838
   #if DISABLED(NO_VOLUMETRICS)

+ 6
- 7
Marlin/src/gcode/bedlevel/M420.cpp View File

71
         bilinear_grid_spacing.set((x_max - x_min) / (GRID_MAX_POINTS_X - 1),
71
         bilinear_grid_spacing.set((x_max - x_min) / (GRID_MAX_POINTS_X - 1),
72
                                   (y_max - y_min) / (GRID_MAX_POINTS_Y - 1));
72
                                   (y_max - y_min) / (GRID_MAX_POINTS_Y - 1));
73
       #endif
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
       SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
80
       SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
82
       SERIAL_ECHOPAIR(" (", x_min);
81
       SERIAL_ECHOPAIR(" (", x_min);
83
       SERIAL_CHAR(','); SERIAL_ECHO(y_min);
82
       SERIAL_CHAR(','); SERIAL_ECHO(y_min);

+ 2
- 2
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

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

+ 2
- 2
Marlin/src/gcode/calibrate/G425.cpp View File

124
 #if HAS_HOTEND_OFFSET
124
 #if HAS_HOTEND_OFFSET
125
 
125
 
126
   inline void normalize_hotend_offsets() {
126
   inline void normalize_hotend_offsets() {
127
-    for (uint8_t e = 1; e < HOTENDS; e++)
127
+    LOOP_S_L_N(e, 1, HOTENDS)
128
       hotend_offset[e] -= hotend_offset[0];
128
       hotend_offset[e] -= hotend_offset[0];
129
     hotend_offset[0].reset();
129
     hotend_offset[0].reset();
130
   }
130
   }
393
     // This function requires normalize_hotend_offsets() to be called
393
     // This function requires normalize_hotend_offsets() to be called
394
     //
394
     //
395
     inline void report_hotend_offsets() {
395
     inline void report_hotend_offsets() {
396
-      for (uint8_t e = 1; e < HOTENDS; e++)
396
+      LOOP_S_L_N(e, 1, HOTENDS)
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);
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
   #endif
399
   #endif

+ 2
- 2
Marlin/src/gcode/calibrate/M100.cpp View File

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

+ 4
- 4
Marlin/src/gcode/calibrate/M48.cpp View File

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

+ 1
- 1
Marlin/src/gcode/config/M305.cpp View File

71
         SERIAL_ECHO_MSG("!Invalid Steinhart-Hart C coeff. (-0.01 < C < +0.01)");
71
         SERIAL_ECHO_MSG("!Invalid Steinhart-Hart C coeff. (-0.01 < C < +0.01)");
72
   }                       // If not setting then report parameters
72
   }                       // If not setting then report parameters
73
   else if (t_index < 0) { // ...all user thermistors
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
       thermalManager.log_user_thermistor(i);
75
       thermalManager.log_user_thermistor(i);
76
   }
76
   }
77
   else                    // ...one user thermistor
77
   else                    // ...one user thermistor

+ 4
- 4
Marlin/src/gcode/config/M43.cpp View File

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

+ 1
- 1
Marlin/src/gcode/config/M672.cpp View File

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

+ 1
- 1
Marlin/src/gcode/config/M92.cpp View File

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

+ 1
- 1
Marlin/src/gcode/control/M111.cpp View File

49
   SERIAL_ECHOPGM(STR_DEBUG_PREFIX);
49
   SERIAL_ECHOPGM(STR_DEBUG_PREFIX);
50
   if (marlin_debug_flags) {
50
   if (marlin_debug_flags) {
51
     uint8_t comma = 0;
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
       if (TEST(marlin_debug_flags, i)) {
53
       if (TEST(marlin_debug_flags, i)) {
54
         if (comma++) SERIAL_CHAR(',');
54
         if (comma++) SERIAL_CHAR(',');
55
         serialprintPGM((char*)pgm_read_ptr(&debug_strings[i]));
55
         serialprintPGM((char*)pgm_read_ptr(&debug_strings[i]));

+ 1
- 1
Marlin/src/gcode/control/M350_M351.cpp View File

33
  * Warning: Steps-per-unit remains unchanged.
33
  * Warning: Steps-per-unit remains unchanged.
34
  */
34
  */
35
 void GcodeSuite::M350() {
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
   LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.microstep_mode(i, parser.value_byte());
37
   LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.microstep_mode(i, parser.value_byte());
38
   if (parser.seen('B')) stepper.microstep_mode(4, parser.value_byte());
38
   if (parser.seen('B')) stepper.microstep_mode(4, parser.value_byte());
39
   stepper.microstep_readings();
39
   stepper.microstep_readings();

+ 1
- 1
Marlin/src/gcode/feature/camera/M240.cpp View File

90
 
90
 
91
     inline void spin_photo_pin() {
91
     inline void spin_photo_pin() {
92
       static constexpr uint32_t sequence[] = PHOTO_PULSES_US;
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
         pulse_photo_pin(sequence[i], !(i & 1));
94
         pulse_photo_pin(sequence[i], !(i & 1));
95
     }
95
     }
96
 
96
 

+ 2
- 2
Marlin/src/gcode/feature/digipot/M907-M910.cpp View File

46
 
46
 
47
     LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
47
     LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
48
     if (parser.seenval('B')) stepper.digipot_current(4, parser.value_int());
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
   #elif HAS_MOTOR_CURRENT_PWM
51
   #elif HAS_MOTOR_CURRENT_PWM
52
 
52
 
74
   #if ENABLED(DAC_STEPPER_CURRENT)
74
   #if ENABLED(DAC_STEPPER_CURRENT)
75
     if (parser.seenval('S')) {
75
     if (parser.seenval('S')) {
76
       const float dac_percent = parser.value_float();
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
     LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) dac_current_percent(i, parser.value_float());
79
     LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) dac_current_percent(i, parser.value_float());
80
   #endif
80
   #endif

+ 1
- 1
Marlin/src/gcode/feature/leds/M7219.cpp View File

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

+ 1
- 1
Marlin/src/gcode/host/M114.cpp View File

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

+ 2
- 2
Marlin/src/gcode/queue.cpp View File

94
 
94
 
95
 GCodeQueue::GCodeQueue() {
95
 GCodeQueue::GCodeQueue() {
96
   // Send "ok" after commands by default
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
    * Loop while serial characters are incoming and the queue is not full
427
    * Loop while serial characters are incoming and the queue is not full
428
    */
428
    */
429
   while (length < BUFSIZE && serial_data_available()) {
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
       const int c = read_serial(i);
432
       const int c = read_serial(i);
433
       if (c < 0) continue;
433
       if (c < 0) continue;

+ 44
- 0
Marlin/src/inc/Conditionals_LCD.h View File

604
   #undef Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
604
   #undef Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
605
 #endif
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
 #ifdef GRID_MAX_POINTS_X
650
 #ifdef GRID_MAX_POINTS_X
608
   #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
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
 #endif
653
 #endif
610
 
654
 
611
 #ifndef INVERT_X_DIR
655
 #ifndef INVERT_X_DIR

+ 4
- 0
Marlin/src/inc/Conditionals_adv.h View File

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

+ 0
- 47
Marlin/src/inc/Conditionals_post.h View File

1855
 #endif // SKEW_CORRECTION
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
  * Heater, Fan, and Probe interactions
1858
  * Heater, Fan, and Probe interactions
1906
  */
1859
  */
1907
 #if FAN_COUNT == 0
1860
 #if FAN_COUNT == 0

+ 2
- 2
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp View File

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

+ 1
- 1
Marlin/src/lcd/dogm/status_screen_DOGM.cpp View File

564
   if (PAGE_UNDER(6 + 1 + 12 + 1 + 6 + 1)) {
564
   if (PAGE_UNDER(6 + 1 + 12 + 1 + 6 + 1)) {
565
     // Extruders
565
     // Extruders
566
     #if DO_DRAW_HOTENDS
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
         _draw_hotend_status((heater_ind_t)e, blink);
568
         _draw_hotend_status((heater_ind_t)e, blink);
569
     #endif
569
     #endif
570
 
570
 

+ 4
- 4
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp View File

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

+ 2
- 2
Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp View File

87
   u8g_SetAddress(u8g, dev, 0);         // cmd mode
87
   u8g_SetAddress(u8g, dev, 0);         // cmd mode
88
   u8g_WriteByte(u8g, dev, 0x08);       //display off, cursor+blink off
88
   u8g_WriteByte(u8g, dev, 0x08);       //display off, cursor+blink off
89
   u8g_WriteByte(u8g, dev, 0x3E);       //extended mode + GDRAM active
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
     u8g_WriteByte(u8g, dev, 0x80 | y); //set y
91
     u8g_WriteByte(u8g, dev, 0x80 | y); //set y
92
     u8g_WriteByte(u8g, dev, 0x80);     //set x = 0
92
     u8g_WriteByte(u8g, dev, 0x80);     //set x = 0
93
     u8g_SetAddress(u8g, dev, 1);                  /* data mode */
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
       u8g_WriteByte(u8g, dev, 0);
95
       u8g_WriteByte(u8g, dev, 0);
96
     u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
96
     u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
97
   }
97
   }

+ 1
- 1
Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp View File

670
     case U8G_DEV_MSG_PAGE_NEXT:
670
     case U8G_DEV_MSG_PAGE_NEXT:
671
       if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;
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
         uint32_t k = 0;
674
         uint32_t k = 0;
675
         #ifdef LCD_USE_DMA_FSMC
675
         #ifdef LCD_USE_DMA_FSMC
676
           buffer = (y & 1) ? bufferB : bufferA;
676
           buffer = (y & 1) ? bufferB : bufferA;

+ 1
- 1
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h View File

237
     if (!var.memadr) return;
237
     if (!var.memadr) return;
238
     union { unsigned char tmp[sizeof(T)]; T t; } x;
238
     union { unsigned char tmp[sizeof(T)]; T t; } x;
239
     unsigned char *ptr = (unsigned char*)val_ptr;
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
     *(T*)var.memadr = x.t;
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 View File

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

+ 1
- 1
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp View File

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

+ 2
- 2
Marlin/src/lcd/extui_malyan_lcd.cpp View File

81
   char encoded_message[MAX_CURLY_COMMAND];
81
   char encoded_message[MAX_CURLY_COMMAND];
82
   uint8_t message_length = _MIN(strlen_P(message), sizeof(encoded_message));
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
     encoded_message[i] = pgm_read_byte(&message[i]) | 0x80;
85
     encoded_message[i] = pgm_read_byte(&message[i]) | 0x80;
86
 
86
 
87
   LCD_SERIAL.Print::write(encoded_message, message_length);
87
   LCD_SERIAL.Print::write(encoded_message, message_length);
91
   char encoded_message[MAX_CURLY_COMMAND];
91
   char encoded_message[MAX_CURLY_COMMAND];
92
   const uint8_t message_length = _MIN(strlen(message), sizeof(encoded_message));
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
     encoded_message[i] = message[i] | 0x80;
95
     encoded_message[i] = message[i] | 0x80;
96
 
96
 
97
   LCD_SERIAL.Print::write(encoded_message, message_length);
97
   LCD_SERIAL.Print::write(encoded_message, message_length);

+ 3
- 3
Marlin/src/lcd/menu/game/brickout.cpp View File

140
 
140
 
141
   // Draw bricks
141
   // Draw bricks
142
   if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) {
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
       const uint8_t yy = y * BRICK_H + BRICK_TOP;
144
       const uint8_t yy = y * BRICK_H + BRICK_TOP;
145
       if (PAGE_CONTAINS(yy, yy + BRICK_H - 1)) {
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
           if (TEST(bdat.bricks[y], x)) {
147
           if (TEST(bdat.bricks[y], x)) {
148
             const uint8_t xx = x * BRICK_W;
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
               if (PAGE_CONTAINS(yy + v, yy + v))
150
               if (PAGE_CONTAINS(yy + v, yy + v))
151
                 u8g.drawHLine(xx, yy + v, BRICK_W - 1);
151
                 u8g.drawHLine(xx, yy + v, BRICK_W - 1);
152
           }
152
           }

+ 3
- 3
Marlin/src/lcd/menu/game/invaders.cpp View File

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

+ 1
- 1
Marlin/src/lcd/menu/game/maze.cpp View File

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

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

114
       #if EXTRUDERS == 1
114
       #if EXTRUDERS == 1
115
         EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
115
         EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
116
       #elif EXTRUDERS > 1
116
       #elif EXTRUDERS > 1
117
-        for (uint8_t n = 0; n < EXTRUDERS; n++)
117
+        LOOP_L_N(n, EXTRUDERS)
118
           EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
118
           EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
119
       #endif
119
       #endif
120
     #endif
120
     #endif
125
       if (parser.volumetric_enabled) {
125
       if (parser.volumetric_enabled) {
126
         EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
126
         EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
127
         #if EXTRUDERS > 1
127
         #if EXTRUDERS > 1
128
-          for (uint8_t n = 0; n < EXTRUDERS; n++)
128
+          LOOP_L_N(n, EXTRUDERS)
129
             EDIT_ITEM_FAST_N(float43, n, MSG_FILAMENT_DIAM_E, &planner.filament_size[n], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
129
             EDIT_ITEM_FAST_N(float43, n, MSG_FILAMENT_DIAM_E, &planner.filament_size[n], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
130
         #endif
130
         #endif
131
       }
131
       }
142
 
142
 
143
       EDIT_ITEM_FAST(float3, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
143
       EDIT_ITEM_FAST(float3, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
144
       #if EXTRUDERS > 1
144
       #if EXTRUDERS > 1
145
-        for (uint8_t n = 0; n < EXTRUDERS; n++)
145
+        LOOP_L_N(n, EXTRUDERS)
146
           EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTUNLOAD_E, &fc_settings[n].unload_length, 0, extrude_maxlength);
146
           EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTUNLOAD_E, &fc_settings[n].unload_length, 0, extrude_maxlength);
147
       #endif
147
       #endif
148
 
148
 
149
       EDIT_ITEM_FAST(float3, MSG_FILAMENT_LOAD, &fc_settings[active_extruder].load_length, 0, extrude_maxlength);
149
       EDIT_ITEM_FAST(float3, MSG_FILAMENT_LOAD, &fc_settings[active_extruder].load_length, 0, extrude_maxlength);
150
       #if EXTRUDERS > 1
150
       #if EXTRUDERS > 1
151
-        for (uint8_t n = 0; n < EXTRUDERS; n++)
151
+        LOOP_L_N(n, EXTRUDERS)
152
           EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTLOAD_E, &fc_settings[n].load_length, 0, extrude_maxlength);
152
           EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTLOAD_E, &fc_settings[n].load_length, 0, extrude_maxlength);
153
       #endif
153
       #endif
154
     #endif
154
     #endif
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);
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
     #endif
359
     #endif
360
     #if ENABLED(DISTINCT_E_FACTORS)
360
     #if ENABLED(DISTINCT_E_FACTORS)
361
-      for (uint8_t n = 0; n < E_STEPPERS; n++)
361
+      LOOP_L_N(n, E_STEPPERS)
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);
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
     #endif
363
     #endif
364
 
364
 
409
 
409
 
410
     #if ENABLED(DISTINCT_E_FACTORS)
410
     #if ENABLED(DISTINCT_E_FACTORS)
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(); });
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
         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); });
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
     #elif E_STEPPERS
414
     #elif E_STEPPERS
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(); });
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
 
484
 
485
   #if ENABLED(DISTINCT_E_FACTORS)
485
   #if ENABLED(DISTINCT_E_FACTORS)
486
     EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(active_extruder)], 5, 9999, []{ planner.refresh_positioning(); });
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
       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); });
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
   #elif E_STEPPERS
489
   #elif E_STEPPERS
490
     EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS], 5, 9999, []{ planner.refresh_positioning(); });
490
     EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS], 5, 9999, []{ planner.refresh_positioning(); });
558
     #if EXTRUDERS == 1
558
     #if EXTRUDERS == 1
559
       EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
559
       EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
560
     #elif EXTRUDERS > 1
560
     #elif EXTRUDERS > 1
561
-      for (uint8_t n = 0; n < E_STEPPERS; n++)
561
+      LOOP_L_N(n, E_STEPPERS)
562
         EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
562
         EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
563
     #endif
563
     #endif
564
   #endif
564
   #endif

+ 4
- 4
Marlin/src/lcd/menu/menu_filament.cpp View File

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

+ 1
- 1
Marlin/src/lcd/menu/menu_mixer.cpp View File

181
 
181
 
182
     #if CHANNEL_MIX_EDITING
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
         EDIT_ITEM_FAST_N(float52, n, MSG_MIX_COMPONENT_N, &mixer.collector[n-1], 0, 10);
185
         EDIT_ITEM_FAST_N(float52, n, MSG_MIX_COMPONENT_N, &mixer.collector[n-1], 0, 10);
186
 
186
 
187
       ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);
187
       ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);

+ 1
- 1
Marlin/src/lcd/menu/menu_mmu2.cpp View File

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

+ 1
- 1
Marlin/src/lcd/menu/menu_motion.cpp View File

357
     #elif E_MANUAL > 1
357
     #elif E_MANUAL > 1
358
 
358
 
359
       // Independent extruders with one E-stepper per hotend
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
     #endif
362
     #endif
363
 
363
 

+ 2
- 2
Marlin/src/lcd/menu/menu_temperature.cpp View File

111
       #if HAS_HEATED_BED
111
       #if HAS_HEATED_BED
112
         _PREHEAT_ITEMS(1,0);
112
         _PREHEAT_ITEMS(1,0);
113
       #endif
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
       ACTION_ITEM(MSG_PREHEAT_1_ALL, []() {
115
       ACTION_ITEM(MSG_PREHEAT_1_ALL, []() {
116
         #if HAS_HEATED_BED
116
         #if HAS_HEATED_BED
117
           _preheat_bed(0);
117
           _preheat_bed(0);
139
       #if HAS_HEATED_BED
139
       #if HAS_HEATED_BED
140
         _PREHEAT_ITEMS(2,0);
140
         _PREHEAT_ITEMS(2,0);
141
       #endif
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
       ACTION_ITEM(MSG_PREHEAT_2_ALL, []() {
143
       ACTION_ITEM(MSG_PREHEAT_2_ALL, []() {
144
         #if HAS_HEATED_BED
144
         #if HAS_HEATED_BED
145
           _preheat_bed(1);
145
           _preheat_bed(1);

+ 2
- 2
Marlin/src/lcd/menu/menu_tune.cpp View File

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

+ 1
- 1
Marlin/src/lcd/ultralcd.cpp View File

1136
       thermalManager.current_ADCKey_raw = HAL_ADC_RANGE;
1136
       thermalManager.current_ADCKey_raw = HAL_ADC_RANGE;
1137
       thermalManager.ADCKey_count = 0;
1137
       thermalManager.ADCKey_count = 0;
1138
       if (currentkpADCValue < adc_other_button)
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
           const uint16_t lo = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMin),
1140
           const uint16_t lo = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMin),
1141
                          hi = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMax);
1141
                          hi = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMax);
1142
           if (WITHIN(currentkpADCValue, lo, hi)) return pgm_read_byte(&stADCKeyTable[i].ADCKeyNo);
1142
           if (WITHIN(currentkpADCValue, lo, hi)) return pgm_read_byte(&stADCKeyTable[i].ADCKeyNo);

+ 1
- 1
Marlin/src/libs/L64XX/L64XX_Marlin.cpp View File

508
   // Work on the drivers
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
     uint8_t not_found = true;
512
     uint8_t not_found = true;
513
     for (j = 1; j <= L64XX::chain[0]; j++) {
513
     for (j = 1; j <= L64XX::chain[0]; j++) {
514
       PGM_P const str = (PGM_P)pgm_read_ptr(&index_to_axis[L64XX::chain[j]]);
514
       PGM_P const str = (PGM_P)pgm_read_ptr(&index_to_axis[L64XX::chain[j]]);

+ 4
- 4
Marlin/src/libs/nozzle.cpp View File

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

+ 6
- 6
Marlin/src/libs/vector_3.cpp View File

96
 
96
 
97
 // Reset to identity. No rotate or translate.
97
 // Reset to identity. No rotate or translate.
98
 void matrix_3x3::set_to_identity() {
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
       vectors[i][j] = float(i == j);
101
       vectors[i][j] = float(i == j);
102
 }
102
 }
103
 
103
 
134
 // Get a transposed copy of the matrix
134
 // Get a transposed copy of the matrix
135
 matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) {
135
 matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) {
136
   matrix_3x3 new_matrix;
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
       new_matrix.vectors[i][j] = original.vectors[j][i];
139
       new_matrix.vectors[i][j] = original.vectors[j][i];
140
   return new_matrix;
140
   return new_matrix;
141
 }
141
 }
145
     serialprintPGM(title);
145
     serialprintPGM(title);
146
     SERIAL_EOL();
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
       if (vectors[i][j] >= 0.0) SERIAL_CHAR('+');
150
       if (vectors[i][j] >= 0.0) SERIAL_CHAR('+');
151
       SERIAL_ECHO_F(vectors[i][j], 6);
151
       SERIAL_ECHO_F(vectors[i][j], 6);
152
       SERIAL_CHAR(' ');
152
       SERIAL_CHAR(' ');

+ 3
- 3
Marlin/src/module/configuration_store.cpp View File

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

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

481
       print_es_state(READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_INVERTING, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
481
       print_es_state(READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_INVERTING, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
482
     #else
482
     #else
483
       #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; break;
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
         pin_t pin;
485
         pin_t pin;
486
         switch (i) {
486
         switch (i) {
487
           default: continue;
487
           default: continue;

+ 2
- 2
Marlin/src/module/planner.cpp View File

1408
    * The multiplier converts a given E value into a length.
1408
    * The multiplier converts a given E value into a length.
1409
    */
1409
    */
1410
   void Planner::calculate_volumetric_multipliers() {
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
       volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
1412
       volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
1413
       refresh_e_factor(i);
1413
       refresh_e_factor(i);
1414
     }
1414
     }
1991
 
1991
 
1992
       #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
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
           if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
1995
           if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
1996
 
1996
 
1997
         #if HAS_DUPLICATION_MODE
1997
         #if HAS_DUPLICATION_MODE

+ 2
- 2
Marlin/src/module/planner.h View File

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

+ 2
- 2
Marlin/src/module/probe.cpp View File

624
 
624
 
625
       #if EXTRA_PROBING
625
       #if EXTRA_PROBING
626
         // Insert Z measurement into probes[]. Keep it sorted ascending.
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
           if (i == p || probes[i] > z) {                              // Last index or new Z is smaller than this Z
628
           if (i == p || probes[i] > z) {                              // Last index or new Z is smaller than this Z
629
             for (int8_t m = p; --m >= i;) probes[m + 1] = probes[m];  // Shift items down after the insertion point
629
             for (int8_t m = p; --m >= i;) probes[m + 1] = probes[m];  // Shift items down after the insertion point
630
             probes[i] = z;                                            // Insert the new Z measurement
630
             probes[i] = z;                                            // Insert the new Z measurement
662
           max_avg_idx--; else min_avg_idx++;
662
           max_avg_idx--; else min_avg_idx++;
663
 
663
 
664
       // Return the average value of all remaining probes.
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
         probes_z_sum += probes[i];
666
         probes_z_sum += probes[i];
667
 
667
 
668
     #endif
668
     #endif

+ 2
- 2
Marlin/src/module/stepper.cpp View File

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

+ 2
- 2
Marlin/src/module/temperature.cpp View File

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

+ 1
- 1
Marlin/src/module/tool_change.cpp View File

251
 #elif ENABLED(PARKING_EXTRUDER)
251
 #elif ENABLED(PARKING_EXTRUDER)
252
 
252
 
253
   void pe_solenoid_init() {
253
   void pe_solenoid_init() {
254
-    for (uint8_t n = 0; n <= 1; ++n)
254
+    LOOP_LE_N(n, 1)
255
       #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
255
       #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
256
         pe_activate_solenoid(n);
256
         pe_activate_solenoid(n);
257
       #else
257
       #else

+ 1
- 1
Marlin/src/pins/pinsDebug.h View File

228
     return true;
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
     if (GET_ARRAY_PIN(x) == pin) {
232
     if (GET_ARRAY_PIN(x) == pin) {
233
       if (!found) {    // report digital and analog pin number only on the first time through
233
       if (!found) {    // report digital and analog pin number only on the first time through
234
         if (start_string) serialprintPGM(start_string);
234
         if (start_string) serialprintPGM(start_string);

+ 5
- 5
Marlin/src/sd/Sd2Card.cpp View File

74
   #else
74
   #else
75
     static uint8_t CRC7(const uint8_t* data, uint8_t n) {
75
     static uint8_t CRC7(const uint8_t* data, uint8_t n) {
76
       uint8_t crc = 0;
76
       uint8_t crc = 0;
77
-      for (uint8_t i = 0; i < n; i++) {
77
+      LOOP_L_N(i, n) {
78
         uint8_t d = data[i];
78
         uint8_t d = data[i];
79
         d ^= crc << 1;
79
         d ^= crc << 1;
80
         if (d & 0x80) d ^= 9;
80
         if (d & 0x80) d ^= 9;
106
     d[5] = CRC7(d, 5);
106
     d[5] = CRC7(d, 5);
107
 
107
 
108
     // Send message
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
   #else
111
   #else
112
     // Send command
112
     // Send command
246
   spiInit(spiRate_);
246
   spiInit(spiRate_);
247
 
247
 
248
   // Must supply min of 74 clock cycles with CS high.
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
   watchdog_refresh(); // In case init takes too long
251
   watchdog_refresh(); // In case init takes too long
252
 
252
 
272
     }
272
     }
273
 
273
 
274
     // Get the last byte of r7 response
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
     if (status_ == 0xAA) {
276
     if (status_ == 0xAA) {
277
       type(SD_CARD_TYPE_SD2);
277
       type(SD_CARD_TYPE_SD2);
278
       break;
278
       break;
303
     }
303
     }
304
     if ((spiRec() & 0xC0) == 0xC0) type(SD_CARD_TYPE_SDHC);
304
     if ((spiRec() & 0xC0) == 0xC0) type(SD_CARD_TYPE_SDHC);
305
     // Discard rest of ocr - contains allowed voltage range
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
   chipDeselect();
308
   chipDeselect();
309
 
309
 

+ 5
- 5
Marlin/src/sd/SdBaseFile.cpp View File

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

+ 3
- 3
Marlin/src/sd/cardreader.cpp View File

143
 //
143
 //
144
 char *createFilename(char * const buffer, const dir_t &p) {
144
 char *createFilename(char * const buffer, const dir_t &p) {
145
   char *pos = buffer;
145
   char *pos = buffer;
146
-  for (uint8_t i = 0; i < 11; i++) {
146
+  LOOP_L_N(i, 11) {
147
     if (p.name[i] == ' ') continue;
147
     if (p.name[i] == ' ') continue;
148
     if (i == 8) *pos++ = '.';
148
     if (i == 8) *pos++ = '.';
149
     *pos++ = p.name[i];
149
     *pos++ = p.name[i];
435
     if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; }
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
     appendAtom(workDirParents[i]);
439
     appendAtom(workDirParents[i]);
440
 
440
 
441
   if (cnt < MAXPATHNAMELENGTH - (FILENAME_LENGTH) - 1) {    // Leave room for filename and nul
441
   if (cnt < MAXPATHNAMELENGTH - (FILENAME_LENGTH) - 1) {    // Leave room for filename and nul
1046
       #if ENABLED(SDSORT_DYNAMIC_RAM)
1046
       #if ENABLED(SDSORT_DYNAMIC_RAM)
1047
         delete sort_order;
1047
         delete sort_order;
1048
         #if ENABLED(SDSORT_CACHE_NAMES)
1048
         #if ENABLED(SDSORT_CACHE_NAMES)
1049
-          for (uint8_t i = 0; i < sort_count; ++i) {
1049
+          LOOP_L_N(i, sort_count) {
1050
             free(sortshort[i]); // strdup
1050
             free(sortshort[i]); // strdup
1051
             free(sortnames[i]); // strdup
1051
             free(sortnames[i]); // strdup
1052
           }
1052
           }

Loading…
Cancel
Save