Browse Source

Apply loop shorthand macros (#17159)

vanilla_fb_2.0.x
Scott Lahteine 4 years ago
committed by GitHub
parent
commit
118bd2f8b2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Marlin/src/HAL/AVR/HAL_SPI.cpp
  2. 2
      Marlin/src/HAL/AVR/MarlinSerial.cpp
  3. 2
      Marlin/src/HAL/AVR/fast_pwm.cpp
  4. 4
      Marlin/src/HAL/AVR/pinsDebug.h
  5. 4
      Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp
  6. 2
      Marlin/src/HAL/DUE/MarlinSerial.cpp
  7. 2
      Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
  8. 4
      Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
  9. 2
      Marlin/src/HAL/DUE/fastio/G2_PWM.h
  10. 2
      Marlin/src/HAL/LPC1768/main.cpp
  11. 16
      Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
  12. 6
      Marlin/src/HAL/SAMD51/HAL.cpp
  13. 2
      Marlin/src/HAL/STM32/fastio.cpp
  14. 16
      Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
  15. 2
      Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp
  16. 2
      Marlin/src/HAL/shared/servo.cpp
  17. 2
      Marlin/src/MarlinCore.cpp
  18. 5
      Marlin/src/core/macros.h
  19. 6
      Marlin/src/core/types.h
  20. 18
      Marlin/src/feature/bedlevel/abl/abl.cpp
  21. 21
      Marlin/src/feature/bedlevel/bedlevel.cpp
  22. 8
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
  23. 4
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h
  24. 20
      Marlin/src/feature/bedlevel/ubl/ubl.cpp
  25. 4
      Marlin/src/feature/bedlevel/ubl/ubl.h
  26. 281
      Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
  27. 4
      Marlin/src/feature/digipot/digipot_mcp4018.cpp
  28. 2
      Marlin/src/feature/digipot/digipot_mcp4451.cpp
  29. 2
      Marlin/src/feature/filwidth.cpp
  30. 6
      Marlin/src/feature/fwretract.cpp
  31. 22
      Marlin/src/feature/max7219.cpp
  32. 4
      Marlin/src/feature/mixing.cpp
  33. 8
      Marlin/src/feature/mmu2/mmu2.cpp
  34. 2
      Marlin/src/feature/powerloss.cpp
  35. 6
      Marlin/src/feature/probe_temp_comp.cpp
  36. 2
      Marlin/src/feature/runout.h
  37. 2
      Marlin/src/feature/twibus.cpp
  38. 115
      Marlin/src/gcode/bedlevel/G26.cpp
  39. 13
      Marlin/src/gcode/bedlevel/M420.cpp
  40. 4
      Marlin/src/gcode/bedlevel/abl/G29.cpp
  41. 4
      Marlin/src/gcode/calibrate/G425.cpp
  42. 4
      Marlin/src/gcode/calibrate/M100.cpp
  43. 8
      Marlin/src/gcode/calibrate/M48.cpp
  44. 2
      Marlin/src/gcode/config/M305.cpp
  45. 8
      Marlin/src/gcode/config/M43.cpp
  46. 2
      Marlin/src/gcode/config/M672.cpp
  47. 2
      Marlin/src/gcode/config/M92.cpp
  48. 2
      Marlin/src/gcode/control/M111.cpp
  49. 2
      Marlin/src/gcode/control/M350_M351.cpp
  50. 2
      Marlin/src/gcode/feature/camera/M240.cpp
  51. 4
      Marlin/src/gcode/feature/digipot/M907-M910.cpp
  52. 2
      Marlin/src/gcode/feature/leds/M7219.cpp
  53. 2
      Marlin/src/gcode/host/M114.cpp
  54. 4
      Marlin/src/gcode/queue.cpp
  55. 44
      Marlin/src/inc/Conditionals_LCD.h
  56. 4
      Marlin/src/inc/Conditionals_adv.h
  57. 47
      Marlin/src/inc/Conditionals_post.h
  58. 4
      Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp
  59. 2
      Marlin/src/lcd/dogm/status_screen_DOGM.cpp
  60. 8
      Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp
  61. 4
      Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp
  62. 2
      Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp
  63. 2
      Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h
  64. 4
      Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/western_char_set.cpp
  65. 2
      Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp
  66. 4
      Marlin/src/lcd/extui_malyan_lcd.cpp
  67. 6
      Marlin/src/lcd/menu/game/brickout.cpp
  68. 6
      Marlin/src/lcd/menu/game/invaders.cpp
  69. 2
      Marlin/src/lcd/menu/game/maze.cpp
  70. 14
      Marlin/src/lcd/menu/game/snake.cpp
  71. 16
      Marlin/src/lcd/menu/menu_advanced.cpp
  72. 8
      Marlin/src/lcd/menu/menu_filament.cpp
  73. 2
      Marlin/src/lcd/menu/menu_mixer.cpp
  74. 2
      Marlin/src/lcd/menu/menu_mmu2.cpp
  75. 2
      Marlin/src/lcd/menu/menu_motion.cpp
  76. 4
      Marlin/src/lcd/menu/menu_temperature.cpp
  77. 4
      Marlin/src/lcd/menu/menu_tune.cpp
  78. 2
      Marlin/src/lcd/ultralcd.cpp
  79. 2
      Marlin/src/libs/L64XX/L64XX_Marlin.cpp
  80. 8
      Marlin/src/libs/nozzle.cpp
  81. 12
      Marlin/src/libs/vector_3.cpp
  82. 6
      Marlin/src/module/configuration_store.cpp
  83. 2
      Marlin/src/module/endstops.cpp
  84. 4
      Marlin/src/module/planner.cpp
  85. 4
      Marlin/src/module/planner.h
  86. 4
      Marlin/src/module/probe.cpp
  87. 4
      Marlin/src/module/stepper.cpp
  88. 4
      Marlin/src/module/temperature.cpp
  89. 2
      Marlin/src/module/tool_change.cpp
  90. 2
      Marlin/src/pins/pinsDebug.h
  91. 10
      Marlin/src/sd/Sd2Card.cpp
  92. 10
      Marlin/src/sd/SdBaseFile.cpp
  93. 6
      Marlin/src/sd/cardreader.cpp

4
Marlin/src/HAL/AVR/HAL_SPI.cpp

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

2
Marlin/src/HAL/AVR/MarlinSerial.cpp

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

2
Marlin/src/HAL/AVR/fast_pwm.cpp

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

4
Marlin/src/HAL/AVR/pinsDebug.h

@ -70,12 +70,12 @@
void PRINT_ARRAY_NAME(uint8_t x) {
char *name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
for (uint8_t y = 0; y < MAX_NAME_LENGTH; y++) {
LOOP_L_N(y, MAX_NAME_LENGTH) {
char temp_char = pgm_read_byte(name_mem_pointer + y);
if (temp_char != 0)
SERIAL_CHAR(temp_char);
else {
for (uint8_t i = 0; i < MAX_NAME_LENGTH - y; i++) SERIAL_CHAR(' ');
LOOP_L_N(i, MAX_NAME_LENGTH - y) SERIAL_CHAR(' ');
break;
}
}

4
Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp

@ -88,7 +88,7 @@ void u8g_spiSend_sw_AVR_mode_0(uint8_t val) {
volatile uint8_t *outData = u8g_outData,
*outClock = u8g_outClock;
U8G_ATOMIC_START();
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (val & 0x80)
*outData |= bitData;
else
@ -108,7 +108,7 @@ void u8g_spiSend_sw_AVR_mode_3(uint8_t val) {
volatile uint8_t *outData = u8g_outData,
*outClock = u8g_outClock;
U8G_ATOMIC_START();
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
*outClock &= bitNotClock;
if (val & 0x80)
*outData |= bitData;

2
Marlin/src/HAL/DUE/MarlinSerial.cpp

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

2
Marlin/src/HAL/DUE/MarlinSerialUSB.cpp

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

4
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp

@ -80,7 +80,7 @@ Pio *SCK_pPio, *MOSI_pPio;
uint32_t SCK_dwMask, MOSI_dwMask;
void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (val & 0x80)
MOSI_pPio->PIO_SODR = MOSI_dwMask;
else
@ -94,7 +94,7 @@ void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
}
void u8g_spiSend_sw_DUE_mode_3(uint8_t val) { // 3.5MHz
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
SCK_pPio->PIO_CODR = SCK_dwMask;
DELAY_NS(50);
if (val & 0x80)

2
Marlin/src/HAL/DUE/fastio/G2_PWM.h

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

2
Marlin/src/HAL/LPC1768/main.cpp

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

16
Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp

@ -73,7 +73,7 @@
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 ) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (spi_speed == 0) {
LPC176x::gpio_set(mosi_pin, !!(b & 0x80));
LPC176x::gpio_set(sck_pin, HIGH);
@ -83,16 +83,16 @@ uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck
}
else {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(mosi_pin, state);
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
LPC176x::gpio_set(sck_pin, HIGH);
b <<= 1;
if (miso_pin >= 0 && LPC176x::gpio_get(miso_pin)) b |= 1;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(sck_pin, LOW);
}
}
@ -102,7 +102,7 @@ uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck
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 ) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
if (spi_speed == 0) {
LPC176x::gpio_set(sck_pin, LOW);
@ -111,13 +111,13 @@ uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck
LPC176x::gpio_set(sck_pin, HIGH);
}
else {
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
LPC176x::gpio_set(sck_pin, LOW);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(mosi_pin, state);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
LPC176x::gpio_set(sck_pin, HIGH);
}
b <<= 1;

6
Marlin/src/HAL/SAMD51/HAL.cpp

@ -478,10 +478,10 @@ void HAL_adc_init() {
#if ADC_IS_REQUIRED
memset(HAL_adc_results, 0xFF, sizeof(HAL_adc_results)); // Fill result with invalid values
for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi)
LOOP_L_N(pi, COUNT(adc_pins))
pinPeripheral(adc_pins[pi], PIO_ANALOG);
for (uint8_t ai = FIRST_ADC; ai <= LAST_ADC; ++ai) {
LOOP_S_LE_N(ai, FIRST_ADC, LAST_ADC) {
Adc* adc = ((Adc*[])ADC_INSTS)[ai];
// ADC clock setup
@ -513,7 +513,7 @@ void HAL_adc_init() {
void HAL_adc_start_conversion(const uint8_t adc_pin) {
#if ADC_IS_REQUIRED
for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi) {
LOOP_L_N(pi, COUNT(adc_pins)) {
if (adc_pin == adc_pins[pi]) {
HAL_adc_result = HAL_adc_results[pi];
return;

2
Marlin/src/HAL/STM32/fastio.cpp

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

16
Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp

@ -32,7 +32,7 @@
static uint8_t SPI_speed = SPI_SPEED;
static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
if (spi_speed == 0) {
WRITE(DOGLCD_MOSI, !!(b & 0x80));
WRITE(DOGLCD_SCK, HIGH);
@ -42,16 +42,16 @@ static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, c
}
else {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_MOSI, state);
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
WRITE(DOGLCD_SCK, HIGH);
b <<= 1;
if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_SCK, LOW);
}
}
@ -59,7 +59,7 @@ static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, c
}
static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
for (uint8_t i = 0; i < 8; i++) {
LOOP_L_N(i, 8) {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
if (spi_speed == 0) {
WRITE(DOGLCD_SCK, LOW);
@ -68,13 +68,13 @@ static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, c
WRITE(DOGLCD_SCK, HIGH);
}
else {
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
WRITE(DOGLCD_SCK, LOW);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_MOSI, state);
for (uint8_t j = 0; j < spi_speed; j++)
LOOP_L_N(j, spi_speed)
WRITE(DOGLCD_SCK, HIGH);
}
b <<= 1;

2
Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp

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

2
Marlin/src/HAL/shared/servo.cpp

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

2
Marlin/src/MarlinCore.cpp

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

5
Marlin/src/core/macros.h

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

6
Marlin/src/core/types.h

@ -50,12 +50,6 @@ enum AxisEnum : uint8_t {
//
// Loop over XYZE axes
//
#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)
#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)

18
Marlin/src/feature/bedlevel/abl/abl.cpp

@ -115,8 +115,8 @@ void extrapolate_unprobed_bed_level() {
ylen = ctry1;
#endif
for (uint8_t xo = 0; xo <= xlen; xo++)
for (uint8_t yo = 0; yo <= ylen; yo++) {
LOOP_LE_N(xo, xlen)
LOOP_LE_N(yo, ylen) {
uint8_t x2 = ctrx2 + xo, y2 = ctry2 + yo;
#ifndef HALF_IN_X
const uint8_t x1 = ctrx1 - xo;
@ -209,8 +209,8 @@ void print_bilinear_leveling_grid() {
static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
float row[4], column[4];
for (uint8_t i = 0; i < 4; i++) {
for (uint8_t j = 0; j < 4; j++) {
LOOP_L_N(i, 4) {
LOOP_L_N(j, 4) {
column[j] = bed_level_virt_coord(i + x - 1, j + y - 1);
}
row[i] = bed_level_virt_cmr(column, 1, ty);
@ -221,11 +221,11 @@ void print_bilinear_leveling_grid() {
void bed_level_virt_interpolate() {
bilinear_grid_spacing_virt = bilinear_grid_spacing / (BILINEAR_SUBDIVISIONS);
bilinear_grid_factor_virt = bilinear_grid_spacing_virt.reciprocal();
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t ty = 0; ty < BILINEAR_SUBDIVISIONS; ty++)
for (uint8_t tx = 0; tx < BILINEAR_SUBDIVISIONS; tx++) {
if ((ty && y == GRID_MAX_POINTS_Y - 1) || (tx && x == GRID_MAX_POINTS_X - 1))
LOOP_L_N(y, GRID_MAX_POINTS_Y)
LOOP_L_N(x, GRID_MAX_POINTS_X)
LOOP_L_N(ty, BILINEAR_SUBDIVISIONS)
LOOP_L_N(tx, BILINEAR_SUBDIVISIONS) {
if ((ty && y == (GRID_MAX_POINTS_Y) - 1) || (tx && x == (GRID_MAX_POINTS_X) - 1))
continue;
z_values_virt[x * (BILINEAR_SUBDIVISIONS) + tx][y * (BILINEAR_SUBDIVISIONS) + ty] =
bed_level_virt_2cmr(

21
Marlin/src/feature/bedlevel/bedlevel.cpp

@ -143,13 +143,12 @@ void reset_bed_level() {
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
bilinear_start.reset();
bilinear_grid_spacing.reset();
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
z_values[x][y] = NAN;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, 0);
#endif
}
GRID_LOOP(x, y) {
z_values[x][y] = NAN;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, 0);
#endif
}
#elif ABL_PLANAR
planner.bed_level_matrix.set_to_identity();
#endif
@ -173,7 +172,7 @@ void reset_bed_level() {
*/
void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, element_2d_fn fn) {
#ifndef SCAD_MESH_OUTPUT
for (uint8_t x = 0; x < sx; x++) {
LOOP_L_N(x, sx) {
serial_spaces(precision + (x < 10 ? 3 : 2));
SERIAL_ECHO(int(x));
}
@ -182,14 +181,14 @@ void reset_bed_level() {
#ifdef SCAD_MESH_OUTPUT
SERIAL_ECHOLNPGM("measured_z = ["); // open 2D array
#endif
for (uint8_t y = 0; y < sy; y++) {
LOOP_L_N(y, sy) {
#ifdef SCAD_MESH_OUTPUT
SERIAL_ECHOPGM(" ["); // open sub-array
#else
if (y < 10) SERIAL_CHAR(' ');
SERIAL_ECHO(int(y));
#endif
for (uint8_t x = 0; x < sx; x++) {
LOOP_L_N(x, sx) {
SERIAL_CHAR(' ');
const float offset = fn(x, y);
if (!isnan(offset)) {
@ -202,7 +201,7 @@ void reset_bed_level() {
SERIAL_CHAR(' ');
SERIAL_ECHOPGM("NAN");
#else
for (uint8_t i = 0; i < precision + 3; i++)
LOOP_L_N(i, precision + 3)
SERIAL_CHAR(i ? '=' : ' ');
#endif
}

8
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp

@ -40,9 +40,9 @@
mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
mesh_bed_leveling::mesh_bed_leveling() {
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
LOOP_L_N(i, GRID_MAX_POINTS_X)
index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i)
LOOP_L_N(i, GRID_MAX_POINTS_Y)
index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
reset();
}
@ -51,9 +51,7 @@
z_offset = 0;
ZERO(z_values);
#if ENABLED(EXTENSIBLE_UI)
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
ExtUI::onMeshUpdate(x, y, 0);
GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
#endif
}

4
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h

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

20
Marlin/src/feature/bedlevel/ubl/ubl.cpp

@ -49,7 +49,7 @@
void unified_bed_leveling::report_current_mesh() {
if (!leveling_is_valid()) return;
SERIAL_ECHO_MSG(" G29 I99");
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
LOOP_L_N(x, GRID_MAX_POINTS_X)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (!isnan(z_values[x][y])) {
SERIAL_ECHO_START();
@ -101,9 +101,7 @@
storage_slot = -1;
ZERO(z_values);
#if ENABLED(EXTENSIBLE_UI)
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
ExtUI::onMeshUpdate(x, y, 0);
GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
#endif
if (was_enabled) report_current_position();
}
@ -114,13 +112,11 @@
}
void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
z_values[x][y] = value;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, value);
#endif
}
GRID_LOOP(x, y) {
z_values[x][y] = value;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, value);
#endif
}
}
@ -190,7 +186,7 @@
}
// Row Values (I indexes)
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
LOOP_L_N(i, GRID_MAX_POINTS_X) {
// Opening Brace or Space
const bool is_current = i == curr.x && j == curr.y;

4
Marlin/src/feature/bedlevel/ubl/ubl.h

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

281
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

@ -365,25 +365,23 @@
#endif
case 0:
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a bowl shape - similar to
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
z_values[x][y] += 2.0f * HYPOT(p1, p2);
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
#endif
}
GRID_LOOP(x, y) { // Create a bowl shape similar to a poorly-calibrated Delta
const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
z_values[x][y] += 2.0f * HYPOT(p1, p2);
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
#endif
}
break;
case 1:
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a diagonal line several Mesh cells thick that is raised
LOOP_L_N(x, GRID_MAX_POINTS_X) { // Create a diagonal line several Mesh cells thick that is raised
z_values[x][x] += 9.999f;
z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, x, z_values[x][x]);
ExtUI::onMeshUpdate(x, (x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1), z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1]);
ExtUI::onMeshUpdate(x, (x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1), z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1]);
#endif
}
@ -467,7 +465,7 @@
//
// Manually Probe Mesh in areas that can't be reached by the probe
//
SERIAL_ECHOLNPGM("Manually probing unreachable mesh locations.");
SERIAL_ECHOLNPGM("Manually probing unreachable points.");
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
if (parser.seen('C') && !xy_seen) {
@ -537,9 +535,7 @@
if (cpos.x < 0) {
// No more REAL INVALID mesh points to populate, so we ASSUME
// user meant to populate ALL INVALID mesh points to value
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (isnan(z_values[x][y])) z_values[x][y] = g29_constant;
GRID_LOOP(x, y) if (isnan(z_values[x][y])) z_values[x][y] = g29_constant;
break; // No more invalid Mesh Points to populate
}
else {
@ -696,12 +692,11 @@
void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
float sum = 0;
int n = 0;
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (!isnan(z_values[x][y])) {
sum += z_values[x][y];
n++;
}
GRID_LOOP(x, y)
if (!isnan(z_values[x][y])) {
sum += z_values[x][y];
n++;
}
const float mean = sum / n;
@ -709,10 +704,9 @@
// Sum the squares of difference from mean
//
float sum_of_diff_squared = 0;
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (!isnan(z_values[x][y]))
sum_of_diff_squared += sq(z_values[x][y] - mean);
GRID_LOOP(x, y)
if (!isnan(z_values[x][y]))
sum_of_diff_squared += sq(z_values[x][y] - mean);
SERIAL_ECHOLNPAIR("# of samples: ", n);
SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6);
@ -721,27 +715,25 @@
SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
if (cflag)
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (!isnan(z_values[x][y])) {
z_values[x][y] -= mean + value;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
#endif
}
}
void unified_bed_leveling::shift_mesh_height() {
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
GRID_LOOP(x, y)
if (!isnan(z_values[x][y])) {
z_values[x][y] += g29_constant;
z_values[x][y] -= mean + value;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
#endif
}
}
void unified_bed_leveling::shift_mesh_height() {
GRID_LOOP(x, y)
if (!isnan(z_values[x][y])) {
z_values[x][y] += g29_constant;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
#endif
}
}
#if HAS_BED_PROBE
/**
* Probe all invalidated locations of the mesh that can be reached by the probe.
@ -1243,52 +1235,46 @@
mesh_index_pair farthest { -1, -1, -99999.99 };
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
GRID_LOOP(i, j) {
if (!isnan(z_values[i][j])) continue; // Skip valid mesh points
if (isnan(z_values[i][j])) { // Invalid mesh point?
// Skip unreachable points
if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
continue;
// Skip points the probe can't reach
if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
continue;
found_a_NAN = true;
found_a_NAN = true;
xy_int8_t near { -1, -1 };
float d1, d2 = 99999.9f;
GRID_LOOP(k, l) {
if (isnan(z_values[k][l])) continue;
xy_int8_t near { -1, -1 };
float d1, d2 = 99999.9f;
for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
if (!isnan(z_values[k][l])) {
found_a_real = true;
found_a_real = true;
// Add in a random weighting factor that scrambles the probing of the
// last half of the mesh (when every unprobed mesh point is one index
// from a probed location).
// Add in a random weighting factor that scrambles the probing of the
// last half of the mesh (when every unprobed mesh point is one index
// from a probed location).
d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
if (d1 < d2) { // Invalid mesh point (i,j) is closer to the defined point (k,l)
d2 = d1;
near.set(i, j);
}
}
}
}
if (d1 < d2) { // Invalid mesh point (i,j) is closer to the defined point (k,l)
d2 = d1;
near.set(i, j);
}
}
//
// At this point d2 should have the near defined mesh point to invalid mesh point (i,j)
//
//
// At this point d2 should have the near defined mesh point to invalid mesh point (i,j)
//
if (found_a_real && near.x >= 0 && d2 > farthest.distance) {
farthest.pos = near; // Found an invalid location farther from the defined mesh point
farthest.distance = d2;
}
}
} // for j
} // for i
if (found_a_real && near.x >= 0 && d2 > farthest.distance) {
farthest.pos = near; // Found an invalid location farther from the defined mesh point
farthest.distance = d2;
}
} // GRID_LOOP
if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing
farthest.pos.set(GRID_MAX_POINTS_X / 2, GRID_MAX_POINTS_Y / 2);
farthest.pos.set((GRID_MAX_POINTS_X) / 2, (GRID_MAX_POINTS_Y) / 2);
farthest.distance = 1;
}
return farthest;
@ -1304,36 +1290,34 @@
float best_so_far = 99999.99f;
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL))
|| (type == SET_IN_BITMAP && !done_flags->marked(i, j))
) {
// Found a Mesh Point of the specified type!
const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
GRID_LOOP(i, j) {
if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL))
|| (type == SET_IN_BITMAP && !done_flags->marked(i, j))
) {
// Found a Mesh Point of the specified type!
const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
// If using the probe as the reference there are some unreachable locations.
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
// Prune them from the list and ignore them till the next Phase (manual nozzle probing).
// If using the probe as the reference there are some unreachable locations.
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
// Prune them from the list and ignore them till the next Phase (manual nozzle probing).
if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos)))
continue;
if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos)))
continue;
// Reachable. Check if it's the best_so_far location to the nozzle.
// Reachable. Check if it's the best_so_far location to the nozzle.
const xy_pos_t diff = current_position - mpos;
const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f;
const xy_pos_t diff = current_position - mpos;
const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f;
// factor in the distance from the current location for the normal case
// so the nozzle isn't running all over the bed.
if (distance < best_so_far) {
best_so_far = distance; // Found a closer location with the desired value type.
closest.pos.set(i, j);
closest.distance = best_so_far;
}
// factor in the distance from the current location for the normal case
// so the nozzle isn't running all over the bed.
if (distance < best_so_far) {
best_so_far = distance; // Found a closer location with the desired value type.
closest.pos.set(i, j);
closest.distance = best_so_far;
}
} // for j
} // for i
}
} // GRID_LOOP
return closest;
}
@ -1373,7 +1357,7 @@
info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
for (uint8_t i = 0; i < COUNT(info); ++i) {
LOOP_L_N(i, COUNT(info)) {
const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
@ -1496,12 +1480,13 @@
bool zig_zag = false;
uint16_t total_points = g29_grid_size * g29_grid_size, point_num = 1;
const uint16_t total_points = sq(g29_grid_size);
uint16_t point_num = 1;
xy_pos_t rpos;
for (uint8_t ix = 0; ix < g29_grid_size; ix++) {
LOOP_L_N(ix, g29_grid_size) {
rpos.x = x_min + ix * dx;
for (int8_t iy = 0; iy < g29_grid_size; iy++) {
LOOP_L_N(iy, g29_grid_size) {
rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
if (!abort_flag) {
@ -1569,39 +1554,37 @@
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
float mx = mesh_index_to_xpos(i),
my = mesh_index_to_ypos(j),
mz = z_values[i][j];
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(my, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(mz, 7);
DEBUG_ECHOPGM("] ---> ");
DEBUG_DELAY(20);
}
GRID_LOOP(i, j) {
float mx = mesh_index_to_xpos(i),
my = mesh_index_to_ypos(j),
mz = z_values[i][j];
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(my, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(mz, 7);
DEBUG_ECHOPGM("] ---> ");
DEBUG_DELAY(20);
}
apply_rotation_xyz(rotation, mx, my, mz);
apply_rotation_xyz(rotation, mx, my, mz);
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(my, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(mz, 7);
DEBUG_ECHOLNPGM("]");
DEBUG_DELAY(20);
}
z_values[i][j] = mz - lsf_results.D;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(i, j, z_values[i][j]);
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(my, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(mz, 7);
DEBUG_ECHOLNPGM("]");
DEBUG_DELAY(20);
}
z_values[i][j] = mz - lsf_results.D;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(i, j, z_values[i][j]);
#endif
}
if (DEBUGGING(LEVELING)) {
@ -1661,7 +1644,7 @@
// being extrapolated so that nearby points will have greater influence on
// the point being extrapolated. Then extrapolate the mesh point from WLSF.
static_assert(GRID_MAX_POINTS_Y <= 16, "GRID_MAX_POINTS_Y too big");
static_assert((GRID_MAX_POINTS_Y) <= 16, "GRID_MAX_POINTS_Y too big");
uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 };
struct linear_fit_data lsf_results;
@ -1669,23 +1652,20 @@
const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST);
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++)
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++)
if (!isnan(z_values[jx][jy]))
SBI(bitmap[jx], jy);
GRID_LOOP(jx, jy) if (!isnan(z_values[jx][jy])) SBI(bitmap[jx], jy);
xy_pos_t ppos;
for (uint8_t ix = 0; ix < GRID_MAX_POINTS_X; ix++) {
LOOP_L_N(ix, GRID_MAX_POINTS_X) {
ppos.x = mesh_index_to_xpos(ix);
for (uint8_t iy = 0; iy < GRID_MAX_POINTS_Y; iy++) {
LOOP_L_N(iy, GRID_MAX_POINTS_Y) {
ppos.y = mesh_index_to_ypos(iy);
if (isnan(z_values[ix][iy])) {
// undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
incremental_LSF_reset(&lsf_results);
xy_pos_t rpos;
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) {
LOOP_L_N(jx, GRID_MAX_POINTS_X) {
rpos.x = mesh_index_to_xpos(jx);
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) {
LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
if (TEST(bitmap[jx], jy)) {
rpos.y = mesh_index_to_ypos(jy);
const float rz = z_values[jx][jy],
@ -1747,7 +1727,7 @@
SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50);
SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
LOOP_L_N(i, GRID_MAX_POINTS_X) {
SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
SERIAL_ECHOPGM(" ");
serial_delay(25);
@ -1755,7 +1735,7 @@
SERIAL_EOL();
SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
LOOP_L_N(i, GRID_MAX_POINTS_Y) {
SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
SERIAL_ECHOPGM(" ");
serial_delay(25);
@ -1840,13 +1820,12 @@
SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh.");
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
z_values[x][y] -= tmp_z_values[x][y];
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
#endif
}
GRID_LOOP(x, y) {
z_values[x][y] -= tmp_z_values[x][y];
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
#endif
}
}
#endif // UBL_DEVEL_DEBUGGING

4
Marlin/src/feature/digipot/digipot_mcp4018.cpp

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

2
Marlin/src/feature/digipot/digipot_mcp4451.cpp

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

2
Marlin/src/feature/filwidth.cpp

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

6
Marlin/src/feature/fwretract.cpp

@ -73,7 +73,7 @@ void FWRetract::reset() {
settings.swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
current_hop = 0.0;
for (uint8_t i = 0; i < EXTRUDERS; ++i) {
LOOP_L_N(i, EXTRUDERS) {
retracted[i] = false;
#if EXTRUDERS > 1
retracted_swap[i] = false;
@ -117,7 +117,7 @@ void FWRetract::retract(const bool retracting
" swapping ", swapping,
" active extruder ", active_extruder
);
for (uint8_t i = 0; i < EXTRUDERS; ++i) {
LOOP_L_N(i, EXTRUDERS) {
SERIAL_ECHOLNPAIR("retracted[", i, "] ", retracted[i]);
#if EXTRUDERS > 1
SERIAL_ECHOLNPAIR("retracted_swap[", i, "] ", retracted_swap[i]);
@ -201,7 +201,7 @@ void FWRetract::retract(const bool retracting
SERIAL_ECHOLNPAIR("retracting ", retracting);
SERIAL_ECHOLNPAIR("swapping ", swapping);
SERIAL_ECHOLNPAIR("active_extruder ", active_extruder);
for (uint8_t i = 0; i < EXTRUDERS; ++i) {
LOOP_L_N(i, EXTRUDERS) {
SERIAL_ECHOLNPAIR("retracted[", i, "] ", retracted[i]);
#if EXTRUDERS > 1
SERIAL_ECHOLNPAIR("retracted_swap[", i, "] ", retracted_swap[i]);

22
Marlin/src/feature/max7219.cpp

@ -147,7 +147,7 @@ void Max7219::error(const char * const func, const int32_t v1, const int32_t v2/
*/
inline uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) {
uint32_t mask = 1, outbits = 0;
for (uint8_t b = 0; b < n_bytes * 8; b++) {
LOOP_L_N(b, n_bytes * 8) {
outbits <<= 1;
if (bits & mask) outbits |= 1;
mask <<= 1;
@ -329,13 +329,13 @@ void Max7219::fill() {
void Max7219::clear_row(const uint8_t row) {
if (row >= MAX7219_Y_LEDS) return error(PSTR("clear_row"), row);
for (uint8_t x = 0; x < MAX7219_X_LEDS; x++) CLR_7219(x, row);
LOOP_L_N(x, MAX7219_X_LEDS) CLR_7219(x, row);
send_row(row);
}
void Max7219::clear_column(const uint8_t col) {
if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
for (uint8_t y = 0; y < MAX7219_Y_LEDS; y++) CLR_7219(col, y);
LOOP_L_N(y, MAX7219_Y_LEDS) CLR_7219(col, y);
send_column(col);
}
@ -347,7 +347,7 @@ void Max7219::clear_column(const uint8_t col) {
void Max7219::set_row(const uint8_t row, const uint32_t val) {
if (row >= MAX7219_Y_LEDS) return error(PSTR("set_row"), row);
uint32_t mask = _BV32(MAX7219_X_LEDS - 1);
for (uint8_t x = 0; x < MAX7219_X_LEDS; x++) {
LOOP_L_N(x, MAX7219_X_LEDS) {
if (val & mask) SET_7219(x, row); else CLR_7219(x, row);
mask >>= 1;
}
@ -362,7 +362,7 @@ void Max7219::set_row(const uint8_t row, const uint32_t val) {
void Max7219::set_column(const uint8_t col, const uint32_t val) {
if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
uint32_t mask = _BV32(MAX7219_Y_LEDS - 1);
for (uint8_t y = 0; y < MAX7219_Y_LEDS; y++) {
LOOP_L_N(y, MAX7219_Y_LEDS) {
if (val & mask) SET_7219(col, y); else CLR_7219(col, y);
mask >>= 1;
}
@ -427,23 +427,23 @@ void Max7219::set_columns_32bits(const uint8_t x, uint32_t val) {
// Initialize the Max7219
void Max7219::register_setup() {
for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
LOOP_L_N(i, MAX7219_NUMBER_UNITS)
send(max7219_reg_scanLimit, 0x07);
pulse_load(); // Tell the chips to load the clocked out data
for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
LOOP_L_N(i, MAX7219_NUMBER_UNITS)
send(max7219_reg_decodeMode, 0x00); // Using an led matrix (not digits)
pulse_load(); // Tell the chips to load the clocked out data
for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
LOOP_L_N(i, MAX7219_NUMBER_UNITS)
send(max7219_reg_shutdown, 0x01); // Not in shutdown mode
pulse_load(); // Tell the chips to load the clocked out data
for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
LOOP_L_N(i, MAX7219_NUMBER_UNITS)
send(max7219_reg_displayTest, 0x00); // No display test
pulse_load(); // Tell the chips to load the clocked out data
for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
LOOP_L_N(i, MAX7219_NUMBER_UNITS)
send(max7219_reg_intensity, 0x01 & 0x0F); // The first 0x0F is the value you can set
// Range: 0x00 to 0x0F
pulse_load(); // Tell the chips to load the clocked out data
@ -537,7 +537,7 @@ void Max7219::init() {
register_setup();
for (uint8_t i = 0; i <= 7; i++) { // Empty registers to turn all LEDs off
LOOP_LE_N(i, 7) { // Empty registers to turn all LEDs off
led_line[i] = 0x00;
send(max7219_reg_digit0 + i, 0);
pulse_load(); // Tell the chips to load the clocked out data

4
Marlin/src/feature/mixing.cpp

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

8
Marlin/src/feature/mmu2/mmu2.cpp

@ -381,7 +381,7 @@ bool MMU2::rx_str_P(const char* str) {
void MMU2::tx_str_P(const char* str) {
clear_rx_buffer();
uint8_t len = strlen_P(str);
for (uint8_t i = 0; i < len; i++) mmuSerial.write(pgm_read_byte(str++));
LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++));
rx_buffer[0] = '\0';
last_request = millis();
}
@ -392,7 +392,7 @@ void MMU2::tx_str_P(const char* str) {
void MMU2::tx_printf_P(const char* format, int argument = -1) {
clear_rx_buffer();
uint8_t len = sprintf_P(tx_buffer, format, argument);
for (uint8_t i = 0; i < len; i++) mmuSerial.write(tx_buffer[i]);
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
rx_buffer[0] = '\0';
last_request = millis();
}
@ -403,7 +403,7 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
clear_rx_buffer();
uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
for (uint8_t i = 0; i < len; i++) mmuSerial.write(tx_buffer[i]);
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
rx_buffer[0] = '\0';
last_request = millis();
}
@ -780,7 +780,7 @@ void MMU2::filament_runout() {
const E_Step* step = sequence;
for (uint8_t i = 0; i < steps; i++) {
LOOP_L_N(i, steps) {
const float es = pgm_read_float(&(step->extrude));
const feedRate_t fr_mm_m = pgm_read_float(&(step->feedRate));

2
Marlin/src/feature/powerloss.cpp

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

6
Marlin/src/feature/probe_temp_comp.cpp

@ -54,7 +54,7 @@ uint8_t ProbeTempComp::calib_idx; // = 0
float ProbeTempComp::init_measurement; // = 0.0
void ProbeTempComp::clear_offsets(const TempSensorID tsi) {
for (uint8_t i = 0; i < cali_info[tsi].measurements; ++i)
LOOP_L_N(i, cali_info[tsi].measurements)
sensor_z_offsets[tsi][i] = 0;
calib_idx = 0;
}
@ -66,7 +66,7 @@ bool ProbeTempComp::set_offset(const TempSensorID tsi, const uint8_t idx, const
}
void ProbeTempComp::print_offsets() {
for (uint8_t s = 0; s < TSI_COUNT; s++) {
LOOP_L_N(s, TSI_COUNT) {
float temp = cali_info[s].start_temp;
for (int16_t i = -1; i < cali_info[s].measurements; ++i) {
serialprintPGM(s == TSI_BED ? PSTR("Bed") :
@ -198,7 +198,7 @@ bool ProbeTempComp::linear_regression(const TempSensorID tsi, float &k, float &d
sum_x2 = sq(start_temp),
sum_xy = 0, sum_y = 0;
for (uint8_t i = 0; i < calib_idx; ++i) {
LOOP_L_N(i, calib_idx) {
const float xi = start_temp + (i + 1) * res_temp,
yi = static_cast<float>(data[i]);
sum_x += xi;

2
Marlin/src/feature/runout.h

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

2
Marlin/src/feature/twibus.cpp

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

115
Marlin/src/gcode/bedlevel/G26.cpp

@ -157,7 +157,7 @@ float g26_extrusion_multiplier,
g26_layer_height,
g26_prime_length;
xy_pos_t g26_pos; // = { 0, 0 }
xy_pos_t g26_xy_pos; // = { 0, 0 }
int16_t g26_bed_temp,
g26_hotend_temp;
@ -187,29 +187,27 @@ mesh_index_pair find_closest_circle_to_print(const xy_pos_t &pos) {
out_point.pos = -1;
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
if (!circle_flags.marked(i, j)) {
// We found a circle that needs to be printed
const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
GRID_LOOP(i, j) {
if (!circle_flags.marked(i, j)) {
// We found a circle that needs to be printed
const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
// Get the distance to this intersection
float f = (pos - m).magnitude();
// Get the distance to this intersection
float f = (pos - m).magnitude();
// It is possible that we are being called with the values
// to let us find the closest circle to the start position.
// But if this is not the case, add a small weighting to the
// distance calculation to help it choose a better place to continue.
f += (g26_pos - m).magnitude() / 15.0f;
// It is possible that we are being called with the values
// to let us find the closest circle to the start position.
// But if this is not the case, add a small weighting to the
// distance calculation to help it choose a better place to continue.
f += (g26_xy_pos - m).magnitude() / 15.0f;
// Add the specified amount of Random Noise to our search
if (random_deviation > 1.0) f += random(0.0, random_deviation);
// Add the specified amount of Random Noise to our search
if (random_deviation > 1.0) f += random(0.0, random_deviation);
if (f < closest) {
closest = f; // Found a closer un-printed location
out_point.pos.set(i, j); // Save its data
out_point.distance = closest;
}
if (f < closest) {
closest = f; // Found a closer un-printed location
out_point.pos.set(i, j); // Save its data
out_point.distance = closest;
}
}
}
@ -308,51 +306,49 @@ inline bool look_for_lines_to_connect() {
xyz_pos_t s, e;
s.z = e.z = g26_layer_height;
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
GRID_LOOP(i, j) {
#if HAS_LCD_MENU
if (user_canceled()) return true;
#endif
#if HAS_LCD_MENU
if (user_canceled()) return true;
#endif
if (i < GRID_MAX_POINTS_X) { // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
if (i < (GRID_MAX_POINTS_X)) { // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
// Already a half circle at the edge of the bed.
if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j)) { // Test whether a leftward line can be done
if (!horizontal_mesh_line_flags.marked(i, j)) {
// Two circles need a horizontal line to connect them
s.x = _GET_MESH_X( i ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j)) { // Test whether a leftward line can be done
if (!horizontal_mesh_line_flags.marked(i, j)) {
// Two circles need a horizontal line to connect them
s.x = _GET_MESH_X( i ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1);
s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1);
s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
print_line_from_here_to_there(s, e);
if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
print_line_from_here_to_there(s, e);
horizontal_mesh_line_flags.mark(i, j); // Mark done, even if skipped
}
horizontal_mesh_line_flags.mark(i, j); // Mark done, even if skipped
}
}
if (j < GRID_MAX_POINTS_Y) { // Can't connect to anything further back than GRID_MAX_POINTS_Y.
if (j < (GRID_MAX_POINTS_Y)) { // Can't connect to anything further back than GRID_MAX_POINTS_Y.
// Already a half circle at the edge of the bed.
if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1)) { // Test whether a downward line can be done
if (!vertical_mesh_line_flags.marked(i, j)) {
// Two circles that need a vertical line to connect them
s.y = _GET_MESH_Y( j ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge
e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1)) { // Test whether a downward line can be done
if (!vertical_mesh_line_flags.marked(i, j)) {
// Two circles that need a vertical line to connect them
s.y = _GET_MESH_Y( j ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge
e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
print_line_from_here_to_there(s, e);
if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
print_line_from_here_to_there(s, e);
vertical_mesh_line_flags.mark(i, j); // Mark done, even if skipped
}
vertical_mesh_line_flags.mark(i, j); // Mark done, even if skipped
}
}
}
@ -628,9 +624,9 @@ void GcodeSuite::G26() {
return;
}
g26_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y);
if (!position_is_reachable(g26_pos.x, g26_pos.y)) {
g26_xy_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y);
if (!position_is_reachable(g26_xy_pos)) {
SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds.");
return;
}
@ -695,7 +691,7 @@ void GcodeSuite::G26() {
#error "A_CNT must be a positive value. Please change A_INT."
#endif
float trig_table[A_CNT];
for (uint8_t i = 0; i < A_CNT; i++)
LOOP_L_N(i, A_CNT)
trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT));
#endif // !ARC_SUPPORT
@ -703,7 +699,7 @@ void GcodeSuite::G26() {
mesh_index_pair location;
do {
// Find the nearest confluence
location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_pos);
location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_xy_pos);
if (location.valid()) {
const xy_pos_t circle = _GET_MESH_POS(location.pos);
@ -834,12 +830,9 @@ void GcodeSuite::G26() {
retract_filament(destination);
destination.z = Z_CLEARANCE_BETWEEN_PROBES;
move_to(destination, 0); // Raise the nozzle
move_to(destination, 0); // Raise the nozzle
destination.set(g26_pos.x, g26_pos.y); // Move back to the starting position
//destination.z = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is
destination = g26_xy_pos; // Move back to the starting XY position
move_to(destination, 0); // Move back to the starting position
#if DISABLED(NO_VOLUMETRICS)

13
Marlin/src/gcode/bedlevel/M420.cpp

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

4
Marlin/src/gcode/bedlevel/abl/G29.cpp

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

4
Marlin/src/gcode/calibrate/G425.cpp

@ -124,7 +124,7 @@ inline void park_above_object(measurements_t &m, const float uncertainty) {
#if HAS_HOTEND_OFFSET
inline void normalize_hotend_offsets() {
for (uint8_t e = 1; e < HOTENDS; e++)
LOOP_S_L_N(e, 1, HOTENDS)
hotend_offset[e] -= hotend_offset[0];
hotend_offset[0].reset();
}
@ -393,7 +393,7 @@ inline void probe_sides(measurements_t &m, const float uncertainty) {
// This function requires normalize_hotend_offsets() to be called
//
inline void report_hotend_offsets() {
for (uint8_t e = 1; e < HOTENDS; e++)
LOOP_S_L_N(e, 1, HOTENDS)
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);
}
#endif

4
Marlin/src/gcode/calibrate/M100.cpp

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

8
Marlin/src/gcode/calibrate/M48.cpp

@ -126,7 +126,7 @@ void GcodeSuite::M48() {
if (probing_good) {
randomSeed(millis());
for (uint8_t n = 0; n < n_samples; n++) {
LOOP_L_N(n, n_samples) {
#if HAS_SPI_LCD
// Display M48 progress in the status bar
ui.status_printf_P(0, PSTR(S_FMT ": %d/%d"), GET_TEXT(MSG_M48_POINT), int(n + 1), int(n_samples));
@ -149,7 +149,7 @@ void GcodeSuite::M48() {
SERIAL_ECHOLNPGM("CW");
}
for (uint8_t l = 0; l < n_legs - 1; l++) {
LOOP_L_N(l, n_legs - 1) {
float delta_angle;
if (schizoid_flag) {
@ -204,7 +204,7 @@ void GcodeSuite::M48() {
* Get the current mean for the data points we have so far
*/
float sum = 0.0;
for (uint8_t j = 0; j <= n; j++) sum += sample_set[j];
LOOP_LE_N(j, n) sum += sample_set[j];
mean = sum / (n + 1);
NOMORE(min, sample_set[n]);
@ -215,7 +215,7 @@ void GcodeSuite::M48() {
* data points we have so far
*/
sum = 0.0;
for (uint8_t j = 0; j <= n; j++)
LOOP_LE_N(j, n)
sum += sq(sample_set[j] - mean);
sigma = SQRT(sum / (n + 1));

2
Marlin/src/gcode/config/M305.cpp

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

8
Marlin/src/gcode/config/M43.cpp

@ -57,7 +57,7 @@ inline void toggle_pins() {
end = PARSED_PIN_INDEX('L', NUM_DIGITAL_PINS - 1),
wait = parser.intval('W', 500);
for (uint8_t i = start; i <= end; i++) {
LOOP_S_LE_N(i, start, end) {
pin_t pin = GET_PIN_MAP_PIN_M43(i);
if (!VALID_PIN(pin)) continue;
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) {
@ -313,7 +313,7 @@ void GcodeSuite::M43() {
NOLESS(first_pin, 2); // Don't hijack the UART pins
#endif
uint8_t pin_state[last_pin - first_pin + 1];
for (uint8_t i = first_pin; i <= last_pin; i++) {
LOOP_S_LE_N(i, first_pin, last_pin) {
pin_t pin = GET_PIN_MAP_PIN_M43(i);
if (!VALID_PIN(pin)) continue;
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
@ -339,7 +339,7 @@ void GcodeSuite::M43() {
#endif
for (;;) {
for (uint8_t i = first_pin; i <= last_pin; i++) {
LOOP_S_LE_N(i, first_pin, last_pin) {
pin_t pin = GET_PIN_MAP_PIN_M43(i);
if (!VALID_PIN(pin)) continue;
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
@ -365,7 +365,7 @@ void GcodeSuite::M43() {
}
else {
// Report current state of selected pin(s)
for (uint8_t i = first_pin; i <= last_pin; i++) {
LOOP_S_LE_N(i, first_pin, last_pin) {
pin_t pin = GET_PIN_MAP_PIN_M43(i);
if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
}

2
Marlin/src/gcode/config/M672.cpp

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

2
Marlin/src/gcode/config/M92.cpp

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

2
Marlin/src/gcode/control/M111.cpp

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

2
Marlin/src/gcode/control/M350_M351.cpp

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

2
Marlin/src/gcode/feature/camera/M240.cpp

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

4
Marlin/src/gcode/feature/digipot/M907-M910.cpp

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

2
Marlin/src/gcode/feature/leds/M7219.cpp

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

2
Marlin/src/gcode/host/M114.cpp

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

4
Marlin/src/gcode/queue.cpp

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

44
Marlin/src/inc/Conditionals_LCD.h

@ -604,8 +604,52 @@
#undef Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
#endif
/**
* Set granular options based on the specific type of leveling
*/
#if ENABLED(AUTO_BED_LEVELING_UBL)
#undef LCD_BED_LEVELING
#if ENABLED(DELTA)
#define UBL_SEGMENTED 1
#endif
#endif
#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT)
#define ABL_PLANAR 1
#endif
#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR)
#define ABL_GRID 1
#endif
#if ANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_3POINT)
#define HAS_ABL_NOT_UBL 1
#endif
#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, MESH_BED_LEVELING)
#define HAS_MESH 1
#endif
#if EITHER(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_3POINT)
#define NEEDS_THREE_PROBE_POINTS 1
#endif
#if EITHER(HAS_ABL_NOT_UBL, AUTO_BED_LEVELING_UBL)
#define HAS_ABL_OR_UBL 1
#if DISABLED(PROBE_MANUALLY)
#define HAS_AUTOLEVEL 1
#endif
#endif
#if EITHER(HAS_ABL_OR_UBL, MESH_BED_LEVELING)
#define HAS_LEVELING 1
#if DISABLED(AUTO_BED_LEVELING_UBL)
#define PLANNER_LEVELING 1
#endif
#endif
#if EITHER(HAS_ABL_OR_UBL, Z_MIN_PROBE_REPEATABILITY_TEST)
#define HAS_PROBING_PROCEDURE 1
#endif
#if !HAS_LEVELING
#undef RESTORE_LEVELING_AFTER_G28
#endif
#ifdef GRID_MAX_POINTS_X
#define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
#define GRID_LOOP(A,B) LOOP_L_N(A, GRID_MAX_POINTS_X) LOOP_L_N(B, GRID_MAX_POINTS_Y)
#endif
#ifndef INVERT_X_DIR

4
Marlin/src/inc/Conditionals_adv.h

@ -83,6 +83,10 @@
#endif
#endif
#if ANY(FWRETRACT, HAS_LEVELING, SKEW_CORRECTION)
#define HAS_POSITION_MODIFIERS 1
#endif
#if ANY(X_DUAL_ENDSTOPS, Y_DUAL_ENDSTOPS, Z_MULTI_ENDSTOPS)
#define HAS_EXTRA_ENDSTOPS 1
#endif

47
Marlin/src/inc/Conditionals_post.h

@ -1854,53 +1854,6 @@
#endif
#endif // SKEW_CORRECTION
/**
* Set granular options based on the specific type of leveling
*/
#if ENABLED(AUTO_BED_LEVELING_UBL)
#undef LCD_BED_LEVELING
#if ENABLED(DELTA)
#define UBL_SEGMENTED 1
#endif
#endif
#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT)
#define ABL_PLANAR 1
#endif
#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR)
#define ABL_GRID 1
#endif
#if ANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_3POINT)
#define HAS_ABL_NOT_UBL 1
#endif
#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, MESH_BED_LEVELING)
#define HAS_MESH 1
#endif
#if EITHER(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_3POINT)
#define NEEDS_THREE_PROBE_POINTS 1
#endif
#if EITHER(HAS_ABL_NOT_UBL, AUTO_BED_LEVELING_UBL)
#define HAS_ABL_OR_UBL 1
#if DISABLED(PROBE_MANUALLY)
#define HAS_AUTOLEVEL 1
#endif
#endif
#if EITHER(HAS_ABL_OR_UBL, MESH_BED_LEVELING)
#define HAS_LEVELING 1
#if DISABLED(AUTO_BED_LEVELING_UBL)
#define PLANNER_LEVELING 1
#endif
#endif
#if EITHER(HAS_ABL_OR_UBL, Z_MIN_PROBE_REPEATABILITY_TEST)
#define HAS_PROBING_PROCEDURE 1
#endif
#if ANY(FWRETRACT, HAS_LEVELING, SKEW_CORRECTION)
#define HAS_POSITION_MODIFIERS 1
#endif
#if !HAS_LEVELING
#undef RESTORE_LEVELING_AFTER_G28
#endif
/**
* Heater, Fan, and Probe interactions
*/

4
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp

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

2
Marlin/src/lcd/dogm/status_screen_DOGM.cpp

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

8
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp

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

4
Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp

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

2
Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp

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

2
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h

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

4
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/western_char_set.cpp

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

2
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp

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

4
Marlin/src/lcd/extui_malyan_lcd.cpp

@ -81,7 +81,7 @@ void write_to_lcd_P(PGM_P const message) {
char encoded_message[MAX_CURLY_COMMAND];
uint8_t message_length = _MIN(strlen_P(message), sizeof(encoded_message));
for (uint8_t i = 0; i < message_length; i++)
LOOP_L_N(i, message_length)
encoded_message[i] = pgm_read_byte(&message[i]) | 0x80;
LCD_SERIAL.Print::write(encoded_message, message_length);
@ -91,7 +91,7 @@ void write_to_lcd(const char * const message) {
char encoded_message[MAX_CURLY_COMMAND];
const uint8_t message_length = _MIN(strlen(message), sizeof(encoded_message));
for (uint8_t i = 0; i < message_length; i++)
LOOP_L_N(i, message_length)
encoded_message[i] = message[i] | 0x80;
LCD_SERIAL.Print::write(encoded_message, message_length);

6
Marlin/src/lcd/menu/game/brickout.cpp

@ -140,13 +140,13 @@ void BrickoutGame::game_screen() {
// Draw bricks
if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) {
for (uint8_t y = 0; y < BRICK_ROWS; ++y) {
LOOP_L_N(y, BRICK_ROWS) {
const uint8_t yy = y * BRICK_H + BRICK_TOP;
if (PAGE_CONTAINS(yy, yy + BRICK_H - 1)) {
for (uint8_t x = 0; x < BRICK_COLS; ++x) {
LOOP_L_N(x, BRICK_COLS) {
if (TEST(bdat.bricks[y], x)) {
const uint8_t xx = x * BRICK_W;
for (uint8_t v = 0; v < BRICK_H - 1; ++v)
LOOP_L_N(v, BRICK_H - 1)
if (PAGE_CONTAINS(yy + v, yy + v))
u8g.drawHLine(xx, yy + v, BRICK_W - 1);
}

6
Marlin/src/lcd/menu/game/invaders.cpp

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

2
Marlin/src/lcd/menu/game/maze.cpp

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

14
Marlin/src/lcd/menu/game/snake.cpp

@ -84,14 +84,14 @@ void shorten_tail() {
}
if (shift) {
sdat.head_ind--;
for (uint8_t i = 0; i <= sdat.head_ind; ++i)
LOOP_LE_N(i, sdat.head_ind)
sdat.snake_tail[i] = sdat.snake_tail[i + 1];
}
}
// The food is on a line
inline bool food_on_line() {
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
if ((sdat.foodx == p.x - 1 || sdat.foodx == p.x) && WITHIN(sdat.foody, _MIN(p.y, q.y), _MAX(p.y, q.y)))
@ -151,7 +151,7 @@ bool snake_overlap() {
// VERTICAL head segment?
if (h1.x == h2.x) {
// Loop from oldest to segment two away from head
for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
LOOP_L_N(n, sdat.head_ind - 2) {
// Segment p to q
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x != q.x) {
@ -163,7 +163,7 @@ bool snake_overlap() {
}
else {
// Loop from oldest to segment two away from head
for (uint8_t n = 0; n < sdat.head_ind - 2; ++n) {
LOOP_L_N(n, sdat.head_ind - 2) {
// Segment p to q
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.y != q.y) {
@ -240,7 +240,7 @@ void SnakeGame::game_screen() {
#if SNAKE_WH < 2
// At this scale just draw a line
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@ -256,7 +256,7 @@ void SnakeGame::game_screen() {
#elif SNAKE_WH == 2
// At this scale draw two lines
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y));
@ -275,7 +275,7 @@ void SnakeGame::game_screen() {
#else
// Draw a series of boxes
for (uint8_t n = 0; n < sdat.head_ind; ++n) {
LOOP_L_N(n, sdat.head_ind) {
const pos_t &p = sdat.snake_tail[n], &q = sdat.snake_tail[n + 1];
if (p.x == q.x) {
const int8_t y1 = _MIN(p.y, q.y), y2 = _MAX(p.y, q.y);

16
Marlin/src/lcd/menu/menu_advanced.cpp

@ -114,7 +114,7 @@ void menu_cancelobject();
#if EXTRUDERS == 1
EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
#elif EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
#endif
#endif
@ -125,7 +125,7 @@ void menu_cancelobject();
if (parser.volumetric_enabled) {
EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#if EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float43, n, MSG_FILAMENT_DIAM_E, &planner.filament_size[n], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#endif
}
@ -142,13 +142,13 @@ void menu_cancelobject();
EDIT_ITEM_FAST(float3, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
#if EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTUNLOAD_E, &fc_settings[n].unload_length, 0, extrude_maxlength);
#endif
EDIT_ITEM_FAST(float3, MSG_FILAMENT_LOAD, &fc_settings[active_extruder].load_length, 0, extrude_maxlength);
#if EXTRUDERS > 1
for (uint8_t n = 0; n < EXTRUDERS; n++)
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float3, n, MSG_FILAMENTLOAD_E, &fc_settings[n].load_length, 0, extrude_maxlength);
#endif
#endif
@ -358,7 +358,7 @@ void menu_cancelobject();
EDIT_ITEM_FAST(float3, MSG_VMAX_E, &planner.settings.max_feedrate_mm_s[E_AXIS_N(active_extruder)], 1, max_fr_edit_scaled.e);
#endif
#if ENABLED(DISTINCT_E_FACTORS)
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
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);
#endif
@ -409,7 +409,7 @@ void menu_cancelobject();
#if ENABLED(DISTINCT_E_FACTORS)
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(); });
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
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); });
#elif E_STEPPERS
EDIT_ITEM_FAST(long5_25, MSG_AMAX_E, &planner.settings.max_acceleration_mm_per_s2[E_AXIS], 100, max_accel_edit_scaled.e, []{ planner.reset_acceleration_rates(); });
@ -484,7 +484,7 @@ void menu_advanced_steps_per_mm() {
#if ENABLED(DISTINCT_E_FACTORS)
EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(active_extruder)], 5, 9999, []{ planner.refresh_positioning(); });
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
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); });
#elif E_STEPPERS
EDIT_ITEM_FAST(float51, MSG_E_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS], 5, 9999, []{ planner.refresh_positioning(); });
@ -558,7 +558,7 @@ void menu_advanced_settings() {
#if EXTRUDERS == 1
EDIT_ITEM(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
#elif EXTRUDERS > 1
for (uint8_t n = 0; n < E_STEPPERS; n++)
LOOP_L_N(n, E_STEPPERS)
EDIT_ITEM_N(float52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 999);
#endif
#endif

8
Marlin/src/lcd/menu/menu_filament.cpp

@ -114,7 +114,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
GCODES_ITEM_P(msg, PSTR("M600 B0"));
#else
PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE_E);
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, MenuItemBase::itemIndex); });
else {
@ -138,7 +138,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
GCODES_ITEM_P(msg_load, PSTR("M701"));
#else
PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD_E);
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, MenuItemBase::itemIndex); });
else {
@ -162,7 +162,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
#if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
{
bool too_cold = false;
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s)) {
too_cold = true; break;
}
@ -174,7 +174,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
}
#endif
PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD_E);
for (uint8_t s = 0; s < E_STEPPERS; s++) {
LOOP_L_N(s, E_STEPPERS) {
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, MenuItemBase::itemIndex); });
else {

2
Marlin/src/lcd/menu/menu_mixer.cpp

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

2
Marlin/src/lcd/menu/menu_mmu2.cpp

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

2
Marlin/src/lcd/menu/menu_motion.cpp

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

4
Marlin/src/lcd/menu/menu_temperature.cpp

@ -111,7 +111,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
#if HAS_HEATED_BED
_PREHEAT_ITEMS(1,0);
#endif
for (uint8_t n = 1; n < HOTENDS; n++) PREHEAT_ITEMS(1,n);
LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(1,n);
ACTION_ITEM(MSG_PREHEAT_1_ALL, []() {
#if HAS_HEATED_BED
_preheat_bed(0);
@ -139,7 +139,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
#if HAS_HEATED_BED
_PREHEAT_ITEMS(2,0);
#endif
for (uint8_t n = 1; n < HOTENDS; n++) PREHEAT_ITEMS(2,n);
LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(2,n);
ACTION_ITEM(MSG_PREHEAT_2_ALL, []() {
#if HAS_HEATED_BED
_preheat_bed(1);

4
Marlin/src/lcd/menu/menu_tune.cpp

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

2
Marlin/src/lcd/ultralcd.cpp

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

2
Marlin/src/libs/L64XX/L64XX_Marlin.cpp

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

8
Marlin/src/libs/nozzle.cpp

@ -54,7 +54,7 @@ Nozzle nozzle;
#endif
// Start the stroke pattern
for (uint8_t i = 0; i < (strokes >> 1); i++) {
LOOP_L_N(i, strokes >> 1) {
do_blocking_move_to_xy(end);
do_blocking_move_to_xy(start);
}
@ -91,7 +91,7 @@ Nozzle nozzle;
const bool horiz = ABS(diff.x) >= ABS(diff.y); // Do a horizontal wipe?
const float P = (horiz ? diff.x : diff.y) / zigs; // Period of each zig / zag
const xyz_pos_t *side;
for (uint8_t j = 0; j < strokes; j++) {
LOOP_L_N(j, strokes) {
for (int8_t i = 0; i < zigs; i++) {
side = (i & 1) ? &end : &start;
if (horiz)
@ -134,8 +134,8 @@ Nozzle nozzle;
do_blocking_move_to(start);
#endif
for (uint8_t s = 0; s < strokes; s++)
for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++)
LOOP_L_N(s, strokes)
LOOP_L_N(i, NOZZLE_CLEAN_CIRCLE_FN)
do_blocking_move_to_xy(
middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius,
middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius

12
Marlin/src/libs/vector_3.cpp

@ -96,8 +96,8 @@ void apply_rotation_xyz(const matrix_3x3 &matrix, float &_x, float &_y, float &_
// Reset to identity. No rotate or translate.
void matrix_3x3::set_to_identity() {
for (uint8_t i = 0; i < 3; i++)
for (uint8_t j = 0; j < 3; j++)
LOOP_L_N(i, 3)
LOOP_L_N(j, 3)
vectors[i][j] = float(i == j);
}
@ -134,8 +134,8 @@ matrix_3x3 matrix_3x3::create_look_at(const vector_3 &target) {
// Get a transposed copy of the matrix
matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) {
matrix_3x3 new_matrix;
for (uint8_t i = 0; i < 3; i++)
for (uint8_t j = 0; j < 3; j++)
LOOP_L_N(i, 3)
LOOP_L_N(j, 3)
new_matrix.vectors[i][j] = original.vectors[j][i];
return new_matrix;
}
@ -145,8 +145,8 @@ void matrix_3x3::debug(PGM_P const title) {
serialprintPGM(title);
SERIAL_EOL();
}
for (uint8_t i = 0; i < 3; i++) {
for (uint8_t j = 0; j < 3; j++) {
LOOP_L_N(i, 3) {
LOOP_L_N(j, 3) {
if (vectors[i][j] >= 0.0) SERIAL_CHAR('+');
SERIAL_ECHO_F(vectors[i][j], 6);
SERIAL_CHAR(' ');

6
Marlin/src/module/configuration_store.cpp

@ -583,7 +583,7 @@ void MarlinSettings::postprocess() {
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
for (uint8_t e = 1; e < HOTENDS; e++)
LOOP_S_L_N(e, 1, HOTENDS)
EEPROM_WRITE(hotend_offset[e]);
#endif
}
@ -1420,7 +1420,7 @@ void MarlinSettings::postprocess() {
{
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
for (uint8_t e = 1; e < HOTENDS; e++)
LOOP_S_L_N(e, 1, HOTENDS)
EEPROM_READ(hotend_offset[e]);
#endif
}
@ -2915,7 +2915,7 @@ void MarlinSettings::reset() {
#if HAS_HOTEND_OFFSET
CONFIG_ECHO_HEADING("Hotend offsets:");
CONFIG_ECHO_START();
for (uint8_t e = 1; e < HOTENDS; e++) {
LOOP_S_L_N(e, 1, HOTENDS) {
SERIAL_ECHOPAIR_P(
PSTR(" M218 T"), (int)e,
SP_X_STR, LINEAR_UNIT(hotend_offset[e].x),

2
Marlin/src/module/endstops.cpp

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

4
Marlin/src/module/planner.cpp

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

4
Marlin/src/module/planner.h

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

4
Marlin/src/module/probe.cpp

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

4
Marlin/src/module/stepper.cpp

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

4
Marlin/src/module/temperature.cpp

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

2
Marlin/src/module/tool_change.cpp

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

2
Marlin/src/pins/pinsDebug.h

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

10
Marlin/src/sd/Sd2Card.cpp

@ -74,7 +74,7 @@
#else
static uint8_t CRC7(const uint8_t* data, uint8_t n) {
uint8_t crc = 0;
for (uint8_t i = 0; i < n; i++) {
LOOP_L_N(i, n) {
uint8_t d = data[i];
d ^= crc << 1;
if (d & 0x80) d ^= 9;
@ -106,7 +106,7 @@ uint8_t Sd2Card::cardCommand(const uint8_t cmd, const uint32_t arg) {
d[5] = CRC7(d, 5);
// Send message
for (uint8_t k = 0; k < 6; k++) spiSend(d[k]);
LOOP_L_N(k, 6) spiSend(d[k]);
#else
// Send command
@ -246,7 +246,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
spiInit(spiRate_);
// Must supply min of 74 clock cycles with CS high.
for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
LOOP_L_N(i, 10) spiSend(0xFF);
watchdog_refresh(); // In case init takes too long
@ -272,7 +272,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
}
// Get the last byte of r7 response
for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
LOOP_L_N(i, 4) status_ = spiRec();
if (status_ == 0xAA) {
type(SD_CARD_TYPE_SD2);
break;
@ -303,7 +303,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
}
if ((spiRec() & 0xC0) == 0xC0) type(SD_CARD_TYPE_SDHC);
// Discard rest of ocr - contains allowed voltage range
for (uint8_t i = 0; i < 3; i++) spiRec();
LOOP_L_N(i, 3) spiRec();
}
chipDeselect();

10
Marlin/src/sd/SdBaseFile.cpp

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

6
Marlin/src/sd/cardreader.cpp

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

Loading…
Cancel
Save