Browse Source

Max7219 suspend/resume

vanilla_fb_2.0.x
Scott Lahteine 5 years ago
parent
commit
c99773bae0
  1. 21
      Marlin/src/feature/Max7219_Debug_LEDs.cpp
  2. 7
      Marlin/src/feature/Max7219_Debug_LEDs.h

21
Marlin/src/feature/Max7219_Debug_LEDs.cpp

@ -73,6 +73,7 @@
Max7219 max7219; Max7219 max7219;
uint8_t Max7219::led_line[MAX7219_LINES]; // = { 0 }; uint8_t Max7219::led_line[MAX7219_LINES]; // = { 0 };
uint8_t Max7219::suspended; // = 0;
#define LINE_REG(Q) (max7219_reg_digit0 + ((Q) & 0x7)) #define LINE_REG(Q) (max7219_reg_digit0 + ((Q) & 0x7))
@ -212,6 +213,7 @@ void Max7219::send(const uint8_t reg, const uint8_t data) {
// Send out a single native row of bits to just one unit // Send out a single native row of bits to just one unit
void Max7219::refresh_unit_line(const uint8_t line) { void Max7219::refresh_unit_line(const uint8_t line) {
if (suspended) return;
#if MAX7219_NUMBER_UNITS == 1 #if MAX7219_NUMBER_UNITS == 1
send(LINE_REG(line), led_line[line]); send(LINE_REG(line), led_line[line]);
#else #else
@ -223,6 +225,7 @@ void Max7219::refresh_unit_line(const uint8_t line) {
// Send out a single native row of bits to all units // Send out a single native row of bits to all units
void Max7219::refresh_line(const uint8_t line) { void Max7219::refresh_line(const uint8_t line) {
if (suspended) return;
#if MAX7219_NUMBER_UNITS == 1 #if MAX7219_NUMBER_UNITS == 1
refresh_unit_line(line); refresh_unit_line(line);
#else #else
@ -241,9 +244,9 @@ void Max7219::set(const uint8_t line, const uint8_t bits) {
// Draw an integer with optional leading zeros and optional decimal point // Draw an integer with optional leading zeros and optional decimal point
void Max7219::print(const uint8_t start, int16_t value, uint8_t size, const bool leadzero=false, bool dec=false) { void Max7219::print(const uint8_t start, int16_t value, uint8_t size, const bool leadzero=false, bool dec=false) {
if (suspended) return;
constexpr uint8_t led_numeral[10] = { 0x7E, 0x60, 0x6D, 0x79, 0x63, 0x5B, 0x5F, 0x70, 0x7F, 0x7A }, constexpr uint8_t led_numeral[10] = { 0x7E, 0x60, 0x6D, 0x79, 0x63, 0x5B, 0x5F, 0x70, 0x7F, 0x7A },
led_decimal = 0x80, led_minus = 0x01; led_decimal = 0x80, led_minus = 0x01;
bool blank = false, neg = value < 0; bool blank = false, neg = value < 0;
if (neg) value *= -1; if (neg) value *= -1;
while (size--) { while (size--) {
@ -295,6 +298,7 @@ void Max7219::led_toggle(const uint8_t x, const uint8_t y) {
} }
void Max7219::send_row(const uint8_t row) { void Max7219::send_row(const uint8_t row) {
if (suspended) return;
#if _ROT == 0 || _ROT == 180 // Native Lines are horizontal too #if _ROT == 0 || _ROT == 180 // Native Lines are horizontal too
#if MAX7219_X_LEDS <= 8 #if MAX7219_X_LEDS <= 8
refresh_unit_line(LED_IND(0, row)); // A single unit line refresh_unit_line(LED_IND(0, row)); // A single unit line
@ -308,6 +312,7 @@ void Max7219::send_row(const uint8_t row) {
} }
void Max7219::send_column(const uint8_t col) { void Max7219::send_column(const uint8_t col) {
if (suspended) return;
#if _ROT == 90 || _ROT == 270 // Native Lines are vertical too #if _ROT == 90 || _ROT == 270 // Native Lines are vertical too
#if MAX7219_Y_LEDS <= 8 #if MAX7219_Y_LEDS <= 8
refresh_unit_line(LED_IND(col, 0)); // A single unit line refresh_unit_line(LED_IND(col, 0)); // A single unit line
@ -344,8 +349,8 @@ void Max7219::clear_column(const uint8_t col) {
/** /**
* Plot the low order bits of val to the specified row of the matrix. * Plot the low order bits of val to the specified row of the matrix.
* With 4 Max7219 units in the chain, it's possible to set 32 bits at once with * With 4 Max7219 units in the chain, it's possible to set 32 bits at
* one call to the function (if rotated 90° or 180°). * 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) { 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(PSTR("set_row"), row);
@ -359,8 +364,8 @@ void Max7219::set_row(const uint8_t row, const uint32_t val) {
/** /**
* Plot the low order bits of val to the specified column of the matrix. * Plot the low order bits of val to the specified column of the matrix.
* With 4 Max7219 units in the chain, it's possible to set 32 bits at once with * With 4 Max7219 units in the chain, it's possible to set 32 bits at
* one call to the function (if rotated 90° or 180°). * 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) { 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(PSTR("set_column"), col);
@ -692,6 +697,12 @@ void Max7219::idle_tasks() {
last_depth = current_depth; last_depth = current_depth;
} }
#endif #endif
// After resume() automatically do a refresh()
if (suspended == 0x80) {
suspended = 0;
refresh();
}
} }
#endif // MAX7219_DEBUG #endif // MAX7219_DEBUG

7
Marlin/src/feature/Max7219_Debug_LEDs.h

@ -88,6 +88,12 @@ public:
// Refresh all units // Refresh all units
static inline void refresh() { for (uint8_t i = 0; i < 8; i++) refresh_line(i); } static inline void refresh() { for (uint8_t i = 0; i < 8; i++) refresh_line(i); }
// Suspend / resume updates to the LED unit
// Use these methods to speed up multiple changes
// or to apply updates from interrupt context.
static inline void suspend() { suspended++; }
static inline void resume() { suspended--; suspended |= 0x80; }
// Update a single native line on all units // Update a single native line on all units
static void refresh_line(const uint8_t line); static void refresh_line(const uint8_t line);
@ -126,6 +132,7 @@ public:
static void idle_tasks(); static void idle_tasks();
private: private:
static uint8_t suspended;
static void error(const char * const func, const int32_t v1, const int32_t v2=-1); static void error(const char * const func, const int32_t v1, const int32_t v2=-1);
static void noop(); static void noop();
static void set(const uint8_t line, const uint8_t bits); static void set(const uint8_t line, const uint8_t bits);

Loading…
Cancel
Save