Browse Source

Max7219 suspend/resume

Scott Lahteine 4 years ago
parent
commit
c99773bae0
2 changed files with 23 additions and 5 deletions
  1. 16
    5
      Marlin/src/feature/Max7219_Debug_LEDs.cpp
  2. 7
    0
      Marlin/src/feature/Max7219_Debug_LEDs.h

+ 16
- 5
Marlin/src/feature/Max7219_Debug_LEDs.cpp View File

@@ -73,6 +73,7 @@
73 73
 Max7219 max7219;
74 74
 
75 75
 uint8_t Max7219::led_line[MAX7219_LINES]; // = { 0 };
76
+uint8_t Max7219::suspended; // = 0;
76 77
 
77 78
 #define LINE_REG(Q)     (max7219_reg_digit0 + ((Q) & 0x7))
78 79
 
@@ -212,6 +213,7 @@ void Max7219::send(const uint8_t reg, const uint8_t data) {
212 213
 
213 214
 // Send out a single native row of bits to just one unit
214 215
 void Max7219::refresh_unit_line(const uint8_t line) {
216
+  if (suspended) return;
215 217
   #if MAX7219_NUMBER_UNITS == 1
216 218
     send(LINE_REG(line), led_line[line]);
217 219
   #else
@@ -223,6 +225,7 @@ void Max7219::refresh_unit_line(const uint8_t line) {
223 225
 
224 226
 // Send out a single native row of bits to all units
225 227
 void Max7219::refresh_line(const uint8_t line) {
228
+  if (suspended) return;
226 229
   #if MAX7219_NUMBER_UNITS == 1
227 230
     refresh_unit_line(line);
228 231
   #else
@@ -241,9 +244,9 @@ void Max7219::set(const uint8_t line, const uint8_t bits) {
241 244
 
242 245
   // Draw an integer with optional leading zeros and optional decimal point
243 246
   void Max7219::print(const uint8_t start, int16_t value, uint8_t size, const bool leadzero=false, bool dec=false) {
247
+    if (suspended) return;
244 248
     constexpr uint8_t led_numeral[10] = { 0x7E, 0x60, 0x6D, 0x79, 0x63, 0x5B, 0x5F, 0x70, 0x7F, 0x7A },
245 249
                       led_decimal = 0x80, led_minus = 0x01;
246
-
247 250
     bool blank = false, neg = value < 0;
248 251
     if (neg) value *= -1;
249 252
     while (size--) {
@@ -295,6 +298,7 @@ void Max7219::led_toggle(const uint8_t x, const uint8_t y) {
295 298
 }
296 299
 
297 300
 void Max7219::send_row(const uint8_t row) {
301
+  if (suspended) return;
298 302
   #if _ROT == 0 || _ROT == 180            // Native Lines are horizontal too
299 303
     #if MAX7219_X_LEDS <= 8
300 304
       refresh_unit_line(LED_IND(0, row)); // A single unit line
@@ -308,6 +312,7 @@ void Max7219::send_row(const uint8_t row) {
308 312
 }
309 313
 
310 314
 void Max7219::send_column(const uint8_t col) {
315
+  if (suspended) return;
311 316
   #if _ROT == 90 || _ROT == 270           // Native Lines are vertical too
312 317
     #if MAX7219_Y_LEDS <= 8
313 318
       refresh_unit_line(LED_IND(col, 0)); // A single unit line
@@ -344,8 +349,8 @@ void Max7219::clear_column(const uint8_t col) {
344 349
 
345 350
 /**
346 351
  * Plot the low order bits of val to the specified row of the matrix.
347
- * With 4 Max7219 units in the chain, it's possible to set 32 bits at once with
348
- * one call to the function (if rotated 90° or 180°).
352
+ * With 4 Max7219 units in the chain, it's possible to set 32 bits at
353
+ * once with a single call to the function (if rotated 90° or 270°).
349 354
  */
350 355
 void Max7219::set_row(const uint8_t row, const uint32_t val) {
351 356
   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) {
359 364
 
360 365
 /**
361 366
  * Plot the low order bits of val to the specified column of the matrix.
362
- * With 4 Max7219 units in the chain, it's possible to set 32 bits at once with
363
- * one call to the function (if rotated 90° or 180°).
367
+ * With 4 Max7219 units in the chain, it's possible to set 32 bits at
368
+ * once with a single call to the function (if rotated 0° or 180°).
364 369
  */
365 370
 void Max7219::set_column(const uint8_t col, const uint32_t val) {
366 371
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
@@ -692,6 +697,12 @@ void Max7219::idle_tasks() {
692 697
       last_depth = current_depth;
693 698
     }
694 699
   #endif
700
+
701
+  // After resume() automatically do a refresh()
702
+  if (suspended == 0x80) {
703
+    suspended = 0;
704
+    refresh();
705
+  }
695 706
 }
696 707
 
697 708
 #endif // MAX7219_DEBUG

+ 7
- 0
Marlin/src/feature/Max7219_Debug_LEDs.h View File

@@ -88,6 +88,12 @@ public:
88 88
   // Refresh all units
89 89
   static inline void refresh() { for (uint8_t i = 0; i < 8; i++) refresh_line(i); }
90 90
 
91
+  // Suspend / resume updates to the LED unit
92
+  // Use these methods to speed up multiple changes
93
+  // or to apply updates from interrupt context.
94
+  static inline void suspend() { suspended++; }
95
+  static inline void resume() { suspended--; suspended |= 0x80; }
96
+
91 97
   // Update a single native line on all units
92 98
   static void refresh_line(const uint8_t line);
93 99
 
@@ -126,6 +132,7 @@ public:
126 132
   static void idle_tasks();
127 133
 
128 134
 private:
135
+  static uint8_t suspended;
129 136
   static void error(const char * const func, const int32_t v1, const int32_t v2=-1);
130 137
   static void noop();
131 138
   static void set(const uint8_t line, const uint8_t bits);

Loading…
Cancel
Save