Skip to content

Commit

Permalink
馃帹 Apply F() to various reports
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 25, 2021
1 parent cabd538 commit 24dbece
Show file tree
Hide file tree
Showing 30 changed files with 288 additions and 291 deletions.
36 changes: 19 additions & 17 deletions Marlin/src/HAL/shared/Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@

#if ENABLED(MARLIN_DEV_MODE)
void dump_delay_accuracy_check() {
auto report_call_time = [](PGM_P const name, PGM_P const unit, const uint32_t cycles, const uint32_t total, const bool do_flush=true) {
auto report_call_time = [](FSTR_P const name, FSTR_P const unit, const uint32_t cycles, const uint32_t total, const bool do_flush=true) {
SERIAL_ECHOPGM("Calling ");
SERIAL_ECHOPGM_P(name);
SERIAL_ECHOF(name);
SERIAL_ECHOLNPGM(" for ", cycles);
SERIAL_ECHOPGM_P(unit);
SERIAL_ECHOF(unit);
SERIAL_ECHOLNPGM(" took: ", total);
SERIAL_ECHOPGM_P(unit);
SERIAL_CHAR(' ');
SERIAL_ECHOF(unit);
if (do_flush) SERIAL_FLUSHTX();
};

Expand All @@ -126,41 +127,42 @@
constexpr uint32_t testValues[] = { 1, 5, 10, 20, 50, 100, 150, 200, 350, 500, 750, 1000 };
for (auto i : testValues) {
s = micros(); DELAY_US(i); e = micros();
report_call_time(PSTR("delay"), PSTR("us"), i, e - s);
report_call_time(F("delay"), F("us"), i, e - s);
}

if (HW_REG(_DWT_CTRL)) {
static FSTR_P cyc = F("cycles");
static FSTR_P dcd = F("DELAY_CYCLES directly ");

for (auto i : testValues) {
s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(i); e = HW_REG(_DWT_CYCCNT);
report_call_time(PSTR("runtime delay"), PSTR("cycles"), i, e - s);
report_call_time(F("runtime delay"), cyc, i, e - s);
}

// Measure the delay to call a real function compared to a function pointer
s = HW_REG(_DWT_CYCCNT); delay_dwt(1); e = HW_REG(_DWT_CYCCNT);
report_call_time(PSTR("delay_dwt"), PSTR("cycles"), 1, e - s);

static PGMSTR(dcd, "DELAY_CYCLES directly ");
report_call_time(F("delay_dwt"), cyc, 1, e - s);

s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES( 1); e = HW_REG(_DWT_CYCCNT);
report_call_time(dcd, PSTR("cycles"), 1, e - s, false);
report_call_time(dcd, cyc, 1, e - s, false);

s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES( 5); e = HW_REG(_DWT_CYCCNT);
report_call_time(dcd, PSTR("cycles"), 5, e - s, false);
report_call_time(dcd, cyc, 5, e - s, false);

s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(10); e = HW_REG(_DWT_CYCCNT);
report_call_time(dcd, PSTR("cycles"), 10, e - s, false);
report_call_time(dcd, cyc, 10, e - s, false);

s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(20); e = HW_REG(_DWT_CYCCNT);
report_call_time(dcd, PSTR("cycles"), 20, e - s, false);
report_call_time(dcd, cyc, 20, e - s, false);

s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(50); e = HW_REG(_DWT_CYCCNT);
report_call_time(dcd, PSTR("cycles"), 50, e - s, false);
report_call_time(dcd, cyc, 50, e - s, false);

s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(100); e = HW_REG(_DWT_CYCCNT);
report_call_time(dcd, PSTR("cycles"), 100, e - s, false);
report_call_time(dcd, cyc, 100, e - s, false);

s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(200); e = HW_REG(_DWT_CYCCNT);
report_call_time(dcd, PSTR("cycles"), 200, e - s, false);
report_call_time(dcd, cyc, 200, e - s, false);
}
}
#endif // MARLIN_DEV_MODE
Expand All @@ -170,7 +172,7 @@

void calibrate_delay_loop() {}
#if ENABLED(MARLIN_DEV_MODE)
void dump_delay_accuracy_check() { SERIAL_ECHOPGM_P(PSTR("N/A on this platform")); }
void dump_delay_accuracy_check() { SERIAL_ECHOPGM("N/A on this platform"); }
#endif

#endif
12 changes: 6 additions & 6 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ void unified_bed_leveling::smart_fill_mesh() {
}

if (DEBUGGING(LEVELING)) {
rotation.debug(PSTR("rotation matrix:\n"));
rotation.debug(F("rotation matrix:\n"));
DEBUG_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7);
DEBUG_ECHOPAIR_F(" B=", lsf_results.B, 7);
DEBUG_ECHOLNPAIR_F(" D=", lsf_results.D, 7);
Expand All @@ -1636,14 +1636,14 @@ void unified_bed_leveling::smart_fill_mesh() {
auto normed = [&](const xy_pos_t &pos, const_float_t zadd) {
return normal.x * pos.x + normal.y * pos.y + zadd;
};
auto debug_pt = [](PGM_P const pre, const xy_pos_t &pos, const_float_t zadd) {
d_from(); SERIAL_ECHOPGM_P(pre);
auto debug_pt = [](FSTR_P const pre, const xy_pos_t &pos, const_float_t zadd) {
d_from(); SERIAL_ECHOF(pre);
DEBUG_ECHO_F(normed(pos, zadd), 6);
DEBUG_ECHOLNPAIR_F(" Z error = ", zadd - get_z_correction(pos), 6);
};
debug_pt(PSTR("1st point: "), probe_pt[0], normal.z * z1);
debug_pt(PSTR("2nd point: "), probe_pt[1], normal.z * z2);
debug_pt(PSTR("3rd point: "), probe_pt[2], normal.z * z3);
debug_pt(F("1st point: "), probe_pt[0], normal.z * z1);
debug_pt(F("2nd point: "), probe_pt[1], normal.z * z2);
debug_pt(F("3rd point: "), probe_pt[2], normal.z * z3);
d_from(); DEBUG_ECHOPGM("safe home with Z=");
DEBUG_ECHOLNPAIR_F("0 : ", normed(safe_homing_xy, 0), 6);
d_from(); DEBUG_ECHOPGM("safe home with Z=");
Expand Down
41 changes: 20 additions & 21 deletions Marlin/src/feature/max7219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ uint8_t Max7219::suspended; // = 0;
#define SIG_DELAY() DELAY_NS(250)
#endif

void Max7219::error(const char * const func, const int32_t v1, const int32_t v2/*=-1*/) {
void Max7219::error(FSTR_P const func, const int32_t v1, const int32_t v2/*=-1*/) {
#if ENABLED(MAX7219_ERRORS)
SERIAL_ECHOPGM("??? Max7219::");
SERIAL_ECHOPGM_P(func);
SERIAL_CHAR('(');
SERIAL_ECHOF(func, AS_CHAR('('));
SERIAL_ECHO(v1);
if (v2 > 0) SERIAL_ECHOPGM(", ", v2);
SERIAL_CHAR(')');
Expand Down Expand Up @@ -268,24 +267,24 @@ void Max7219::set(const uint8_t line, const uint8_t bits) {

// Modify a single LED bit and send the changed line
void Max7219::led_set(const uint8_t x, const uint8_t y, const bool on) {
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_set"), x, y);
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(F("led_set"), x, y);
if (BIT_7219(x, y) == on) return;
XOR_7219(x, y);
refresh_unit_line(LED_IND(x, y));
}

void Max7219::led_on(const uint8_t x, const uint8_t y) {
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_on"), x, y);
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(F("led_on"), x, y);
led_set(x, y, true);
}

void Max7219::led_off(const uint8_t x, const uint8_t y) {
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_off"), x, y);
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(F("led_off"), x, y);
led_set(x, y, false);
}

void Max7219::led_toggle(const uint8_t x, const uint8_t y) {
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_toggle"), x, y);
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(F("led_toggle"), x, y);
led_set(x, y, !BIT_7219(x, y));
}

Expand Down Expand Up @@ -328,13 +327,13 @@ void Max7219::fill() {
}

void Max7219::clear_row(const uint8_t row) {
if (row >= MAX7219_Y_LEDS) return error(PSTR("clear_row"), row);
if (row >= MAX7219_Y_LEDS) return error(F("clear_row"), 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);
if (col >= MAX7219_X_LEDS) return error(F("set_column"), col);
LOOP_L_N(y, MAX7219_Y_LEDS) CLR_7219(col, y);
send_column(col);
}
Expand All @@ -345,7 +344,7 @@ void Max7219::clear_column(const uint8_t col) {
* once with a single call to the function (if rotated 90掳 or 270掳).
*/
void Max7219::set_row(const uint8_t row, const uint32_t val) {
if (row >= MAX7219_Y_LEDS) return error(PSTR("set_row"), row);
if (row >= MAX7219_Y_LEDS) return error(F("set_row"), row);
uint32_t mask = _BV32(MAX7219_X_LEDS - 1);
LOOP_L_N(x, MAX7219_X_LEDS) {
if (val & mask) SET_7219(x, row); else CLR_7219(x, row);
Expand All @@ -360,7 +359,7 @@ void Max7219::set_row(const uint8_t row, const uint32_t val) {
* once with a single call to the function (if rotated 0掳 or 180掳).
*/
void Max7219::set_column(const uint8_t col, const uint32_t val) {
if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
if (col >= MAX7219_X_LEDS) return error(F("set_column"), col);
uint32_t mask = _BV32(MAX7219_Y_LEDS - 1);
LOOP_L_N(y, MAX7219_Y_LEDS) {
if (val & mask) SET_7219(col, y); else CLR_7219(col, y);
Expand All @@ -371,56 +370,56 @@ void Max7219::set_column(const uint8_t col, const uint32_t val) {

void Max7219::set_rows_16bits(const uint8_t y, uint32_t val) {
#if MAX7219_X_LEDS == 8
if (y > MAX7219_Y_LEDS - 2) return error(PSTR("set_rows_16bits"), y, val);
if (y > MAX7219_Y_LEDS - 2) return error(F("set_rows_16bits"), y, val);
set_row(y + 1, val); val >>= 8;
set_row(y + 0, val);
#else // at least 16 bits on each row
if (y > MAX7219_Y_LEDS - 1) return error(PSTR("set_rows_16bits"), y, val);
if (y > MAX7219_Y_LEDS - 1) return error(F("set_rows_16bits"), y, val);
set_row(y, val);
#endif
}

void Max7219::set_rows_32bits(const uint8_t y, uint32_t val) {
#if MAX7219_X_LEDS == 8
if (y > MAX7219_Y_LEDS - 4) return error(PSTR("set_rows_32bits"), y, val);
if (y > MAX7219_Y_LEDS - 4) return error(F("set_rows_32bits"), y, val);
set_row(y + 3, val); val >>= 8;
set_row(y + 2, val); val >>= 8;
set_row(y + 1, val); val >>= 8;
set_row(y + 0, val);
#elif MAX7219_X_LEDS == 16
if (y > MAX7219_Y_LEDS - 2) return error(PSTR("set_rows_32bits"), y, val);
if (y > MAX7219_Y_LEDS - 2) return error(F("set_rows_32bits"), y, val);
set_row(y + 1, val); val >>= 16;
set_row(y + 0, val);
#else // at least 24 bits on each row. In the 3 matrix case, just display the low 24 bits
if (y > MAX7219_Y_LEDS - 1) return error(PSTR("set_rows_32bits"), y, val);
if (y > MAX7219_Y_LEDS - 1) return error(F("set_rows_32bits"), y, val);
set_row(y, val);
#endif
}

void Max7219::set_columns_16bits(const uint8_t x, uint32_t val) {
#if MAX7219_Y_LEDS == 8
if (x > MAX7219_X_LEDS - 2) return error(PSTR("set_columns_16bits"), x, val);
if (x > MAX7219_X_LEDS - 2) return error(F("set_columns_16bits"), x, val);
set_column(x + 0, val); val >>= 8;
set_column(x + 1, val);
#else // at least 16 bits in each column
if (x > MAX7219_X_LEDS - 1) return error(PSTR("set_columns_16bits"), x, val);
if (x > MAX7219_X_LEDS - 1) return error(F("set_columns_16bits"), x, val);
set_column(x, val);
#endif
}

void Max7219::set_columns_32bits(const uint8_t x, uint32_t val) {
#if MAX7219_Y_LEDS == 8
if (x > MAX7219_X_LEDS - 4) return error(PSTR("set_rows_32bits"), x, val);
if (x > MAX7219_X_LEDS - 4) return error(F("set_rows_32bits"), x, val);
set_column(x + 3, val); val >>= 8;
set_column(x + 2, val); val >>= 8;
set_column(x + 1, val); val >>= 8;
set_column(x + 0, val);
#elif MAX7219_Y_LEDS == 16
if (x > MAX7219_X_LEDS - 2) return error(PSTR("set_rows_32bits"), x, val);
if (x > MAX7219_X_LEDS - 2) return error(F("set_rows_32bits"), x, val);
set_column(x + 1, val); val >>= 16;
set_column(x + 0, val);
#else // at least 24 bits on each row. In the 3 matrix case, just display the low 24 bits
if (x > MAX7219_X_LEDS - 1) return error(PSTR("set_rows_32bits"), x, val);
if (x > MAX7219_X_LEDS - 1) return error(F("set_rows_32bits"), x, val);
set_column(x, val);
#endif
}
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/feature/max7219.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
* a Max7219_Set_Row(). The opposite is true for rotations of 0 or 180 degrees.
*/

#include "../inc/MarlinConfig.h"

#ifndef MAX7219_ROTATE
#define MAX7219_ROTATE 0
#endif
Expand Down Expand Up @@ -140,7 +142,7 @@ class Max7219 {

private:
static uint8_t suspended;
static void error(const char * const func, const int32_t v1, const int32_t v2=-1);
static void error(FSTR_P const func, const int32_t v1, const int32_t v2=-1);
static void noop();
static void set(const uint8_t line, const uint8_t bits);
static void send_row(const uint8_t row);
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void PrintJobRecovery::load() {
(void)file.read(&info, sizeof(info));
close();
}
debug(PSTR("Load"));
debug(F("Load"));
}

/**
Expand Down Expand Up @@ -311,7 +311,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
*/
void PrintJobRecovery::write() {

debug(PSTR("Write"));
debug(F("Write"));

open(false);
file.seekSet(0);
Expand Down Expand Up @@ -575,8 +575,8 @@ void PrintJobRecovery::resume() {

#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)

void PrintJobRecovery::debug(PGM_P const prefix) {
DEBUG_ECHOPGM_P(prefix);
void PrintJobRecovery::debug(FSTR_P const prefix) {
DEBUG_ECHOF(prefix);
DEBUG_ECHOLNPGM(" Job Recovery Info...\nvalid_head:", info.valid_head, " valid_foot:", info.valid_foot);
if (info.valid_head) {
if (info.valid_head == info.valid_foot) {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/powerloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ class PrintJobRecovery {
static inline bool valid() { return info.valid() && interrupted_file_exists(); }

#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
static void debug(PGM_P const prefix);
static void debug(FSTR_P const prefix);
#else
static inline void debug(PGM_P const) {}
static inline void debug(FSTR_P const) {}
#endif

private:
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/feature/stepper_driver_safety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

static uint32_t axis_plug_backward = 0;

void stepper_driver_backward_error(PGM_P str) {
void stepper_driver_backward_error(FSTR_P const fstr) {
SERIAL_ERROR_START();
SERIAL_ECHOPGM_P(str);
SERIAL_ECHOF(fstr);
SERIAL_ECHOLNPGM(" driver is backward!");
ui.status_printf(2, F(S_FMT S_FMT), str, GET_TEXT(MSG_DRIVER_BACKWARD));
ui.status_printf(2, F(S_FMT S_FMT), FTOP(fstr), GET_TEXT(MSG_DRIVER_BACKWARD));
}

void stepper_driver_backward_check() {
Expand All @@ -45,7 +45,7 @@ void stepper_driver_backward_check() {
delay(20); \
if (READ(AXIS##_ENABLE_PIN) == false) { \
SBI(axis_plug_backward, BIT); \
stepper_driver_backward_error(PSTR(STRINGIFY(AXIS))); \
stepper_driver_backward_error(F(STRINGIFY(AXIS))); \
} \
}while(0)

Expand Down Expand Up @@ -82,12 +82,12 @@ void stepper_driver_backward_check() {
void stepper_driver_backward_report() {
if (!axis_plug_backward) return;

auto _report_if_backward = [](PGM_P axis, uint8_t bit) {
auto _report_if_backward = [](FSTR_P const axis, uint8_t bit) {
if (TEST(axis_plug_backward, bit))
stepper_driver_backward_error(axis);
};

#define REPORT_BACKWARD(axis, bit) TERN_(HAS_##axis##_ENABLE, _report_if_backward(PSTR(STRINGIFY(axis)), bit))
#define REPORT_BACKWARD(axis, bit) TERN_(HAS_##axis##_ENABLE, _report_if_backward(F(STRINGIFY(axis)), bit))

REPORT_BACKWARD(X, 0);
REPORT_BACKWARD(X2, 1);
Expand Down

0 comments on commit 24dbece

Please sign in to comment.