Skip to content

Commit

Permalink
use references
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jun 22, 2022
1 parent 958c884 commit e5f24d9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
68 changes: 34 additions & 34 deletions Marlin/src/feature/max7219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,28 +273,28 @@ void Max7219::set(const uint8_t line, const uint8_t bits) {
#endif // MAX7219_NUMERIC

// 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, uint8_t* row_change_mask/*=0*/) {
void Max7219::led_set(const uint8_t x, const uint8_t y, const bool on, uint8_t &rcm) {
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));
if (row_change_mask)
*row_change_mask |= _BV(LED_IND(x, y) & 0x07);
if (rcm != nullptr)
*rcm |= _BV(LED_IND(x, y) & 0x07);
}

void Max7219::led_on(const uint8_t x, const uint8_t y, uint8_t* row_change_mask/*=0*/) {
void Max7219::led_on(const uint8_t x, const uint8_t y, uint8_t &rcm) {
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(F("led_on"), x, y);
led_set(x, y, true, row_change_mask);
led_set(x, y, true, rcm);
}

void Max7219::led_off(const uint8_t x, const uint8_t y, uint8_t* row_change_mask/*=0*/) {
void Max7219::led_off(const uint8_t x, const uint8_t y, uint8_t &rcm) {
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(F("led_off"), x, y);
led_set(x, y, false, row_change_mask);
led_set(x, y, false, rcm);
}

void Max7219::led_toggle(const uint8_t x, const uint8_t y, uint8_t* row_change_mask/*=0*/) {
void Max7219::led_toggle(const uint8_t x, const uint8_t y, uint8_t &rcm) {
if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(F("led_toggle"), x, y);
led_set(x, y, !BIT_7219(x, y), row_change_mask);
led_set(x, y, !BIT_7219(x, y), rcm);
}

void Max7219::send_row(const uint8_t row) {
Expand Down Expand Up @@ -559,47 +559,47 @@ void Max7219::init() {
*/

// Apply changes to update a marker
void Max7219::mark16(const uint8_t pos, const uint8_t v1, const uint8_t v2, uint8_t* row_change_mask/*=0*/) {
void Max7219::mark16(const uint8_t pos, const uint8_t v1, const uint8_t v2, uint8_t &rcm) {
#if MAX7219_X_LEDS > 8 // At least 16 LEDs on the X-Axis. Use single line.
led_off(v1 & 0xF, pos, row_change_mask);
led_on(v2 & 0xF, pos, row_change_mask);
led_off(v1 & 0xF, pos, rcm);
led_on(v2 & 0xF, pos, rcm);
#elif MAX7219_Y_LEDS > 8 // At least 16 LEDs on the Y-Axis. Use a single column.
led_off(pos, v1 & 0xF, row_change_mask);
led_on(pos, v2 & 0xF, row_change_mask);
led_off(pos, v1 & 0xF, rcm);
led_on(pos, v2 & 0xF, rcm);
#else // Single 8x8 LED matrix. Use two lines to get 16 LEDs.
led_off(v1 & 0x7, pos + (v1 >= 8), row_change_mask);
led_on(v2 & 0x7, pos + (v2 >= 8), row_change_mask);
led_off(v1 & 0x7, pos + (v1 >= 8), rcm);
led_on(v2 & 0x7, pos + (v2 >= 8), rcm);
#endif
}

// Apply changes to update a tail-to-head range
void Max7219::range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh,
const uint8_t nh, uint8_t* row_change_mask/*=0*/) {
const uint8_t nh, uint8_t &rcm) {
#if MAX7219_X_LEDS > 8 // At least 16 LEDs on the X-Axis. Use single line.
if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
led_off(n & 0xF, y, row_change_mask);
led_off(n & 0xF, y, rcm);
if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
led_on(n & 0xF, y, row_change_mask);
led_on(n & 0xF, y, rcm);
#elif MAX7219_Y_LEDS > 8 // At least 16 LEDs on the Y-Axis. Use a single column.
if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
led_off(y, n & 0xF, row_change_mask);
led_off(y, n & 0xF, rcm);
if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
led_on(y, n & 0xF, row_change_mask);
led_on(y, n & 0xF, rcm);
#else // Single 8x8 LED matrix. Use two lines to get 16 LEDs.
if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
led_off(n & 0x7, y + (n >= 8), row_change_mask);
led_off(n & 0x7, y + (n >= 8), rcm);
if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
led_on(n & 0x7, y + (n >= 8), row_change_mask);
led_on(n & 0x7, y + (n >= 8), rcm);
#endif
}

// Apply changes to update a quantity
void Max7219::quantity(const uint8_t pos, const uint8_t ov, const uint8_t nv, uint8_t* row_change_mask/*=0*/) {
void Max7219::quantity(const uint8_t pos, const uint8_t ov, const uint8_t nv, uint8_t &rcm) {
for (uint8_t i = _MIN(nv, ov); i < _MAX(nv, ov); i++)
led_set(i, pos, nv >= ov, row_change_mask);
led_set(i, pos, nv >= ov, rcm);
}

void Max7219::quantity16(const uint8_t pos, const uint8_t ov, const uint8_t nv, uint8_t* row_change_mask/*=0*/) {
void Max7219::quantity16(const uint8_t pos, const uint8_t ov, const uint8_t nv, uint8_t &rcm) {
for (uint8_t i = _MIN(nv, ov); i < _MAX(nv, ov); i++)
led_set(
#if MAX7219_X_LEDS > 8 // At least 16 LEDs on the X-Axis. Use single line.
Expand All @@ -610,7 +610,7 @@ void Max7219::quantity16(const uint8_t pos, const uint8_t ov, const uint8_t nv,
i >> 1, pos + (i & 1)
#endif
, nv >= ov
, row_change_mask
, rcm
);
}

Expand Down Expand Up @@ -661,7 +661,7 @@ void Max7219::idle_tasks() {

#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
if (do_blink) {
led_toggle(MAX7219_X_LEDS - 1, MAX7219_Y_LEDS - 1, &row_change_mask);
led_toggle(MAX7219_X_LEDS - 1, MAX7219_Y_LEDS - 1, row_change_mask);
next_blink = ms + 1000;
}
#endif
Expand All @@ -671,7 +671,7 @@ void Max7219::idle_tasks() {
static int16_t last_head_cnt = 0xF, last_tail_cnt = 0xF;

if (last_head_cnt != head || last_tail_cnt != tail) {
range16(MAX7219_DEBUG_PLANNER_HEAD, last_tail_cnt, tail, last_head_cnt, head, &row_change_mask);
range16(MAX7219_DEBUG_PLANNER_HEAD, last_tail_cnt, tail, last_head_cnt, head, row_change_mask);
last_head_cnt = head;
last_tail_cnt = tail;
}
Expand All @@ -681,15 +681,15 @@ void Max7219::idle_tasks() {
#ifdef MAX7219_DEBUG_PLANNER_HEAD
static int16_t last_head_cnt = 0x1;
if (last_head_cnt != head) {
mark16(MAX7219_DEBUG_PLANNER_HEAD, last_head_cnt, head, &row_change_mask);
mark16(MAX7219_DEBUG_PLANNER_HEAD, last_head_cnt, head, row_change_mask);
last_head_cnt = head;
}
#endif

#ifdef MAX7219_DEBUG_PLANNER_TAIL
static int16_t last_tail_cnt = 0x1;
if (last_tail_cnt != tail) {
mark16(MAX7219_DEBUG_PLANNER_TAIL, last_tail_cnt, tail, &row_change_mask);
mark16(MAX7219_DEBUG_PLANNER_TAIL, last_tail_cnt, tail, row_change_mask);
last_tail_cnt = tail;
}
#endif
Expand All @@ -700,16 +700,16 @@ void Max7219::idle_tasks() {
static int16_t last_depth = 0;
const int16_t current_depth = (head - tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1) & 0xF;
if (current_depth != last_depth) {
quantity16(MAX7219_DEBUG_PLANNER_QUEUE, last_depth, current_depth, &row_change_mask);
quantity16(MAX7219_DEBUG_PLANNER_QUEUE, last_depth, current_depth, row_change_mask);
last_depth = current_depth;
}
#endif

#ifdef MAX7219_DEBUG_PROFILE
static uint8_t last_time_fraction = 0;
const uint8_t current_time_fraction = (uint16_t(CodeProfiler::get_time_fraction()) * MAX7219_NUMBER_UNITS + 8) / 16;
const uint8_t current_time_fraction = (uint16_t(CodeProfiler::get_time_fraction()) * (MAX7219_NUMBER_UNITS) + 8) / 16;
if (current_time_fraction != last_time_fraction) {
quantity(MAX7219_DEBUG_PROFILE, last_time_fraction, current_time_fraction, &row_change_mask);
quantity(MAX7219_DEBUG_PROFILE, last_time_fraction, current_time_fraction, row_change_mask);
last_time_fraction = current_time_fraction;
}
#endif
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/feature/max7219.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
}
}

// returns fraction of total time which was measured, scaled from 0 to 128
// Return the fraction of total time measured, from 0 to 128
static uint8_t get_time_fraction() { return time_fraction; }
};
#endif
Expand Down Expand Up @@ -148,10 +148,10 @@ class Max7219 {
#endif

// Set a single LED by XY coordinate
static void led_set(const uint8_t x, const uint8_t y, const bool on, uint8_t* row_change_mask=0);
static void led_on(const uint8_t x, const uint8_t y, uint8_t* row_change_mask=0);
static void led_off(const uint8_t x, const uint8_t y, uint8_t* row_change_mask=0);
static void led_toggle(const uint8_t x, const uint8_t y, uint8_t* row_change_mask=0);
static void led_set(const uint8_t x, const uint8_t y, const bool on, uint8_t &rcm);
static void led_on(const uint8_t x, const uint8_t y, uint8_t &rcm);
static void led_off(const uint8_t x, const uint8_t y, uint8_t &rcm);
static void led_toggle(const uint8_t x, const uint8_t y, uint8_t &rcm);

// Set all LEDs in a single column
static void set_column(const uint8_t col, const uint32_t val);
Expand Down Expand Up @@ -185,10 +185,10 @@ class Max7219 {
static void set(const uint8_t line, const uint8_t bits);
static void send_row(const uint8_t row);
static void send_column(const uint8_t col);
static void mark16(const uint8_t y, const uint8_t v1, const uint8_t v2, uint8_t* row_change_mask=0);
static void range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh, uint8_t* row_change_mask=0);
static void quantity(const uint8_t y, const uint8_t ov, const uint8_t nv, uint8_t* row_change_mask=0);
static void quantity16(const uint8_t y, const uint8_t ov, const uint8_t nv, uint8_t* row_change_mask=0);
static void mark16(const uint8_t y, const uint8_t v1, const uint8_t v2, uint8_t &rcm);
static void range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh, uint8_t &rcm);
static void quantity(const uint8_t y, const uint8_t ov, const uint8_t nv, uint8_t &rcm);
static void quantity16(const uint8_t y, const uint8_t ov, const uint8_t nv, uint8_t &rcm);

#if MAX7219_INIT_TEST
static void test_pattern();
Expand Down

0 comments on commit e5f24d9

Please sign in to comment.