Explorar el Código

Max7219 suspend/resume

Scott Lahteine hace 5 años
padre
commit
c99773bae0

+ 16
- 5
Marlin/src/feature/Max7219_Debug_LEDs.cpp Ver fichero

73
 Max7219 max7219;
73
 Max7219 max7219;
74
 
74
 
75
 uint8_t Max7219::led_line[MAX7219_LINES]; // = { 0 };
75
 uint8_t Max7219::led_line[MAX7219_LINES]; // = { 0 };
76
+uint8_t Max7219::suspended; // = 0;
76
 
77
 
77
 #define LINE_REG(Q)     (max7219_reg_digit0 + ((Q) & 0x7))
78
 #define LINE_REG(Q)     (max7219_reg_digit0 + ((Q) & 0x7))
78
 
79
 
212
 
213
 
213
 // Send out a single native row of bits to just one unit
214
 // Send out a single native row of bits to just one unit
214
 void Max7219::refresh_unit_line(const uint8_t line) {
215
 void Max7219::refresh_unit_line(const uint8_t line) {
216
+  if (suspended) return;
215
   #if MAX7219_NUMBER_UNITS == 1
217
   #if MAX7219_NUMBER_UNITS == 1
216
     send(LINE_REG(line), led_line[line]);
218
     send(LINE_REG(line), led_line[line]);
217
   #else
219
   #else
223
 
225
 
224
 // Send out a single native row of bits to all units
226
 // Send out a single native row of bits to all units
225
 void Max7219::refresh_line(const uint8_t line) {
227
 void Max7219::refresh_line(const uint8_t line) {
228
+  if (suspended) return;
226
   #if MAX7219_NUMBER_UNITS == 1
229
   #if MAX7219_NUMBER_UNITS == 1
227
     refresh_unit_line(line);
230
     refresh_unit_line(line);
228
   #else
231
   #else
241
 
244
 
242
   // Draw an integer with optional leading zeros and optional decimal point
245
   // Draw an integer with optional leading zeros and optional decimal point
243
   void Max7219::print(const uint8_t start, int16_t value, uint8_t size, const bool leadzero=false, bool dec=false) {
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
     constexpr uint8_t led_numeral[10] = { 0x7E, 0x60, 0x6D, 0x79, 0x63, 0x5B, 0x5F, 0x70, 0x7F, 0x7A },
248
     constexpr uint8_t led_numeral[10] = { 0x7E, 0x60, 0x6D, 0x79, 0x63, 0x5B, 0x5F, 0x70, 0x7F, 0x7A },
245
                       led_decimal = 0x80, led_minus = 0x01;
249
                       led_decimal = 0x80, led_minus = 0x01;
246
-
247
     bool blank = false, neg = value < 0;
250
     bool blank = false, neg = value < 0;
248
     if (neg) value *= -1;
251
     if (neg) value *= -1;
249
     while (size--) {
252
     while (size--) {
295
 }
298
 }
296
 
299
 
297
 void Max7219::send_row(const uint8_t row) {
300
 void Max7219::send_row(const uint8_t row) {
301
+  if (suspended) return;
298
   #if _ROT == 0 || _ROT == 180            // Native Lines are horizontal too
302
   #if _ROT == 0 || _ROT == 180            // Native Lines are horizontal too
299
     #if MAX7219_X_LEDS <= 8
303
     #if MAX7219_X_LEDS <= 8
300
       refresh_unit_line(LED_IND(0, row)); // A single unit line
304
       refresh_unit_line(LED_IND(0, row)); // A single unit line
308
 }
312
 }
309
 
313
 
310
 void Max7219::send_column(const uint8_t col) {
314
 void Max7219::send_column(const uint8_t col) {
315
+  if (suspended) return;
311
   #if _ROT == 90 || _ROT == 270           // Native Lines are vertical too
316
   #if _ROT == 90 || _ROT == 270           // Native Lines are vertical too
312
     #if MAX7219_Y_LEDS <= 8
317
     #if MAX7219_Y_LEDS <= 8
313
       refresh_unit_line(LED_IND(col, 0)); // A single unit line
318
       refresh_unit_line(LED_IND(col, 0)); // A single unit line
344
 
349
 
345
 /**
350
 /**
346
  * Plot the low order bits of val to the specified row of the matrix.
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
 void Max7219::set_row(const uint8_t row, const uint32_t val) {
355
 void Max7219::set_row(const uint8_t row, const uint32_t val) {
351
   if (row >= MAX7219_Y_LEDS) return error(PSTR("set_row"), row);
356
   if (row >= MAX7219_Y_LEDS) return error(PSTR("set_row"), row);
359
 
364
 
360
 /**
365
 /**
361
  * Plot the low order bits of val to the specified column of the matrix.
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
 void Max7219::set_column(const uint8_t col, const uint32_t val) {
370
 void Max7219::set_column(const uint8_t col, const uint32_t val) {
366
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
371
   if (col >= MAX7219_X_LEDS) return error(PSTR("set_column"), col);
692
       last_depth = current_depth;
697
       last_depth = current_depth;
693
     }
698
     }
694
   #endif
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
 #endif // MAX7219_DEBUG
708
 #endif // MAX7219_DEBUG

+ 7
- 0
Marlin/src/feature/Max7219_Debug_LEDs.h Ver fichero

88
   // Refresh all units
88
   // Refresh all units
89
   static inline void refresh() { for (uint8_t i = 0; i < 8; i++) refresh_line(i); }
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
   // Update a single native line on all units
97
   // Update a single native line on all units
92
   static void refresh_line(const uint8_t line);
98
   static void refresh_line(const uint8_t line);
93
 
99
 
126
   static void idle_tasks();
132
   static void idle_tasks();
127
 
133
 
128
 private:
134
 private:
135
+  static uint8_t suspended;
129
   static void error(const char * const func, const int32_t v1, const int32_t v2=-1);
136
   static void error(const char * const func, const int32_t v1, const int32_t v2=-1);
130
   static void noop();
137
   static void noop();
131
   static void set(const uint8_t line, const uint8_t bits);
138
   static void set(const uint8_t line, const uint8_t bits);

Loading…
Cancelar
Guardar