Browse Source

Save up to 94 bytes of RAM on 20x4 LCD Display machines (#6964)

* Save up to 94 bytes of RAM on 20x4 LCD Display machines

Moved the custom screen characters out of RAM into Program Memory.  With
SD-Card support and the Progress Bar enabled, this saves 94 bytes of RAM
memory.

This was tested using the example_configurations/FolgerTech-i3-2020
files.  So a couple small changes to those files snuck into this Pull
Request.

Probably...  We can find similar savings in the Graphics LCD code it we
comb through it.   And if so...  That is the place we really need to
save RAM memory!

* Tidy up white space and indentation
Roxy-3D 8 years ago
parent
commit
0dd0033b33

+ 7
- 7
Marlin/Conditionals_LCD.h View File

@@ -241,14 +241,14 @@
241 241
     #define LCD_STR_FILAM_MUL   "\xa4"
242 242
   #else
243 243
     /* Custom characters defined in the first 8 characters of the LCD */
244
-    #define LCD_STR_BEDTEMP     "\x00"  // Print only as a char. This will have 'unexpected' results when used in a string!
245
-    #define LCD_STR_DEGREE      "\x01"
246
-    #define LCD_STR_THERMOMETER "\x02"
247
-    #define LCD_STR_UPLEVEL     "\x03"
248
-    #define LCD_STR_REFRESH     "\x04"
244
+    #define LCD_BEDTEMP_CHAR     0x00  // Print only as a char. This will have 'unexpected' results when used in a string!
245
+    #define LCD_DEGREE_CHAR      0x01
246
+    #define LCD_STR_THERMOMETER "\x02" // Too many places use preprocessor string concatination to change this to a char right now.
247
+    #define LCD_UPLEVEL_CHAR     0x03
248
+    #define LCD_REFRESH_CHAR     0x04
249 249
     #define LCD_STR_FOLDER      "\x05"
250
-    #define LCD_STR_FEEDRATE    "\x06"
251
-    #define LCD_STR_CLOCK       "\x07"
250
+    #define LCD_FEEDRATE_CHAR    0x06
251
+    #define LCD_CLOCK_CHAR       0x07
252 252
     #define LCD_STR_ARROW_RIGHT ">"  /* from the default character set */
253 253
   #endif
254 254
 

+ 1
- 1
Marlin/example_configurations/FolgerTech-i3-2020/Configuration.h View File

@@ -649,7 +649,7 @@
649 649
  */
650 650
 #define X_PROBE_OFFSET_FROM_EXTRUDER 38     // X offset: -left  +right  [of the nozzle]
651 651
 #define Y_PROBE_OFFSET_FROM_EXTRUDER -7     // Y offset: -front +behind [the nozzle]
652
-#define Z_PROBE_OFFSET_FROM_EXTRUDER -10.1  // Z offset: -below +above  [the nozzle]
652
+#define Z_PROBE_OFFSET_FROM_EXTRUDER -10.4  // Z offset: -below +above  [the nozzle]
653 653
 
654 654
 // X and Y axis travel speed (mm/m) between probes
655 655
 #define XY_PROBE_SPEED 7500

+ 2
- 2
Marlin/example_configurations/FolgerTech-i3-2020/Configuration_adv.h View File

@@ -509,7 +509,7 @@
509 509
   #endif
510 510
 
511 511
   // Show a progress bar on HD44780 LCDs for SD printing
512
-  //#define LCD_PROGRESS_BAR
512
+  #define LCD_PROGRESS_BAR
513 513
 
514 514
   #if ENABLED(LCD_PROGRESS_BAR)
515 515
     // Amount of time (ms) to show the bar
@@ -1228,7 +1228,7 @@
1228 1228
  *  - M206 and M428 are disabled.
1229 1229
  *  - G92 will revert to its behavior from Marlin 1.0.
1230 1230
  */
1231
-//#define NO_WORKSPACE_OFFSETS
1231
+#define NO_WORKSPACE_OFFSETS
1232 1232
 
1233 1233
 /**
1234 1234
  * Set the number of proportional font spaces required to fill up a typical character space.

+ 67
- 44
Marlin/ultralcd_impl_HD44780.h View File

@@ -193,12 +193,18 @@ extern volatile uint8_t buttons;  //an extended version of the last checked butt
193 193
   static void lcd_implementation_update_indicators();
194 194
 #endif
195 195
 
196
-static void lcd_set_custom_characters(
197
-  #if ENABLED(LCD_PROGRESS_BAR)
198
-    const bool info_screen_charset = true
199
-  #endif
200
-) {
201
-  static byte bedTemp[8] = {
196
+
197
+static void createChar_P(char c, PROGMEM byte *ptr) {
198
+  byte temp[8];
199
+  int8_t i;
200
+
201
+  for(i=0; i<8; i++)  {
202
+    temp[i] = pgm_read_byte(&ptr[i]);
203
+  }
204
+  lcd.createChar(c, temp);
205
+}
206
+
207
+const static PROGMEM byte bedTemp[8] = {
202 208
     B00000,
203 209
     B11111,
204 210
     B10101,
@@ -207,8 +213,9 @@ static void lcd_set_custom_characters(
207 213
     B11111,
208 214
     B00000,
209 215
     B00000
210
-  }; //thanks Sonny Mounicou
211
-  static byte degree[8] = {
216
+};
217
+
218
+const static PROGMEM byte degree[8] = {
212 219
     B01100,
213 220
     B10010,
214 221
     B10010,
@@ -218,7 +225,8 @@ static void lcd_set_custom_characters(
218 225
     B00000,
219 226
     B00000
220 227
   };
221
-  static byte thermometer[8] = {
228
+
229
+const static PROGMEM byte thermometer[8] = {
222 230
     B00100,
223 231
     B01010,
224 232
     B01010,
@@ -228,7 +236,8 @@ static void lcd_set_custom_characters(
228 236
     B10001,
229 237
     B01110
230 238
   };
231
-  static byte uplevel[8] = {
239
+
240
+const static PROGMEM byte uplevel[8] = {
232 241
     B00100,
233 242
     B01110,
234 243
     B11111,
@@ -237,8 +246,9 @@ static void lcd_set_custom_characters(
237 246
     B00000,
238 247
     B00000,
239 248
     B00000
240
-  }; //thanks joris
241
-  static byte feedrate[8] = {
249
+};
250
+
251
+const static PROGMEM byte feedrate[8] = {
242 252
     B11100,
243 253
     B10000,
244 254
     B11000,
@@ -247,8 +257,9 @@ static void lcd_set_custom_characters(
247 257
     B00110,
248 258
     B00101,
249 259
     B00000
250
-  }; //thanks Sonny Mounicou
251
-  static byte clock[8] = {
260
+};
261
+
262
+const static PROGMEM byte clock[8] = {
252 263
     B00000,
253 264
     B01110,
254 265
     B10011,
@@ -257,16 +268,10 @@ static void lcd_set_custom_characters(
257 268
     B01110,
258 269
     B00000,
259 270
     B00000
260
-  }; //thanks Sonny Mounicou
271
+};
261 272
 
262
-  lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
263
-  lcd.createChar(LCD_STR_DEGREE[0], degree);
264
-  lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
265
-  lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
266
-  lcd.createChar(LCD_STR_CLOCK[0], clock);
267
-
268
-  #if ENABLED(SDSUPPORT)
269
-    static byte refresh[8] = {
273
+#if ENABLED(SDSUPPORT)
274
+  const static PROGMEM byte refresh[8] = {
270 275
       B00000,
271 276
       B00110,
272 277
       B11001,
@@ -275,8 +280,8 @@ static void lcd_set_custom_characters(
275 280
       B10011,
276 281
       B01100,
277 282
       B00000,
278
-    }; //thanks joris
279
-    static byte folder[8] = {
283
+  };
284
+  const static PROGMEM byte folder[8] = {
280 285
       B00000,
281 286
       B11100,
282 287
       B11111,
@@ -285,10 +290,10 @@ static void lcd_set_custom_characters(
285 290
       B11111,
286 291
       B00000,
287 292
       B00000
288
-    }; //thanks joris
293
+  };
289 294
 
290
-    #if ENABLED(LCD_PROGRESS_BAR)
291
-      static byte progress[3][8] = { {
295
+  #if ENABLED(LCD_PROGRESS_BAR)
296
+    const static PROGMEM byte progress[3][8] = { {
292 297
         B00000,
293 298
         B10000,
294 299
         B10000,
@@ -316,26 +321,43 @@ static void lcd_set_custom_characters(
316 321
         B10101,
317 322
         B00000
318 323
       } };
324
+  #endif
325
+#endif
326
+
327
+static void lcd_set_custom_characters(
328
+  #if ENABLED(LCD_PROGRESS_BAR)
329
+    const bool info_screen_charset = true
330
+  #endif
331
+) {
332
+
333
+  createChar_P(LCD_BEDTEMP_CHAR, bedTemp);
334
+  createChar_P(LCD_DEGREE_CHAR, degree);
335
+  createChar_P(LCD_STR_THERMOMETER[0], thermometer);
336
+  createChar_P(LCD_FEEDRATE_CHAR, feedrate);
337
+  createChar_P(LCD_CLOCK_CHAR, clock);
338
+
339
+  #if ENABLED(SDSUPPORT)
340
+    #if ENABLED(LCD_PROGRESS_BAR)
319 341
       static bool char_mode = false;
320 342
       if (info_screen_charset != char_mode) {
321 343
         char_mode = info_screen_charset;
322 344
         if (info_screen_charset) { // Progress bar characters for info screen
323
-          for (int i = 3; i--;) lcd.createChar(LCD_STR_PROGRESS[i], progress[i]);
345
+          for (int i = 3; i--;) createChar_P(LCD_STR_PROGRESS[i], progress[i]);
324 346
         }
325 347
         else { // Custom characters for submenus
326
-          lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
327
-          lcd.createChar(LCD_STR_REFRESH[0], refresh);
328
-          lcd.createChar(LCD_STR_FOLDER[0], folder);
348
+          createChar_P(LCD_UPLEVEL_CHAR, uplevel);
349
+          createChar_P(LCD_REFRESH_CHAR, refresh);
350
+          createChar_P(LCD_STR_FOLDER[0], folder);
329 351
         }
330 352
       }
331 353
     #else
332
-      lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
333
-      lcd.createChar(LCD_STR_REFRESH[0], refresh);
334
-      lcd.createChar(LCD_STR_FOLDER[0], folder);
354
+      createChar_P(LCD_UPLEVEL_CHAR, uplevel);
355
+      createChar_P(LCD_REFRESH_CHAR, refresh);
356
+      createChar_P(LCD_STR_FOLDER[0], folder);
335 357
     #endif
336 358
 
337 359
   #else
338
-    lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
360
+    createChar_P(LCD_UPLEVEL_CHAR, uplevel);
339 361
   #endif
340 362
 }
341 363
 
@@ -607,7 +629,8 @@ FORCE_INLINE void _draw_heater_status(const int8_t heater, const char prefix, co
607 629
       lcd.print(itostr3left(t2 + 0.5));
608 630
 
609 631
   if (prefix >= 0) {
610
-    lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
632
+    lcd.print((char)LCD_DEGREE_CHAR);
633
+    lcd.print(' ');
611 634
     if (t2 < 10) lcd.print(' ');
612 635
   }
613 636
 }
@@ -677,10 +700,10 @@ static void lcd_implementation_status_screen() {
677 700
 
678 701
       lcd.setCursor(8, 0);
679 702
       #if HOTENDS > 1
680
-        lcd.print(LCD_STR_THERMOMETER[0]);
703
+        lcd.print((CHAR)LCD_STR_THERMOMETER[0]);
681 704
         _draw_heater_status(1, -1, blink);
682 705
       #else
683
-        lcd.print(LCD_STR_BEDTEMP[0]);
706
+        lcd.print((CHAR)LCD_BEDTEMP_CHAR);
684 707
         _draw_heater_status(-1, -1, blink);
685 708
       #endif
686 709
 
@@ -701,7 +724,7 @@ static void lcd_implementation_status_screen() {
701 724
       #if HOTENDS > 1
702 725
         _draw_heater_status(1, LCD_STR_THERMOMETER[0], blink);
703 726
       #else
704
-        _draw_heater_status(-1, LCD_STR_BEDTEMP[0], blink);
727
+        _draw_heater_status(-1, LCD_BEDTEMP_CHAR, blink);
705 728
       #endif
706 729
 
707 730
     #endif // HOTENDS > 1 || TEMP_SENSOR_BED != 0
@@ -735,7 +758,7 @@ static void lcd_implementation_status_screen() {
735 758
         // If we both have a 2nd extruder and a heated bed,
736 759
         // show the heated bed temp on the left,
737 760
         // since the first line is filled with extruder temps
738
-      _draw_heater_status(-1, LCD_STR_BEDTEMP[0], blink);
761
+      _draw_heater_status(-1, LCD_BEDTEMP_CHAR, blink);
739 762
 
740 763
       #else
741 764
         // Before homing the axis letters are blinking 'X' <-> '?'.
@@ -767,7 +790,7 @@ static void lcd_implementation_status_screen() {
767 790
   #if LCD_HEIGHT > 3
768 791
 
769 792
     lcd.setCursor(0, 2);
770
-    lcd.print(LCD_STR_FEEDRATE[0]);
793
+    lcd.print((char)LCD_FEEDRATE_CHAR);
771 794
     lcd.print(itostr3(feedrate_percentage));
772 795
     lcd.print('%');
773 796
 
@@ -788,7 +811,7 @@ static void lcd_implementation_status_screen() {
788 811
     uint8_t len = elapsed.toDigital(buffer);
789 812
 
790 813
     lcd.setCursor(LCD_WIDTH - len - 1, 2);
791
-    lcd.print(LCD_STR_CLOCK[0]);
814
+    lcd.print((char)LCD_CLOCK_CHAR);
792 815
     lcd_print(buffer);
793 816
 
794 817
   #endif // LCD_HEIGHT > 3
@@ -980,7 +1003,7 @@ static void lcd_implementation_status_screen() {
980 1003
 
981 1004
   #endif // SDSUPPORT
982 1005
 
983
-  #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
1006
+  #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_UPLEVEL_CHAR,LCD_UPLEVEL_CHAR)
984 1007
   #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
985 1008
   #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
986 1009
   #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')

Loading…
Cancel
Save