Browse Source

🐛 Fix DGUS Reloaded + STM32 (#24600)

Protomosh 1 year ago
parent
commit
4ae9bf3b9d
No account linked to committer's email address

+ 0
- 1
Marlin/src/lcd/extui/dgus/DGUSDisplay.h View File

@@ -39,7 +39,6 @@
39 39
 
40 40
 enum DGUSLCD_Screens : uint8_t;
41 41
 
42
-//#define DEBUG_DGUSLCD
43 42
 #define DEBUG_OUT ENABLED(DEBUG_DGUSLCD)
44 43
 #include "../../../core/debug_out.h"
45 44
 

+ 21
- 26
Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp View File

@@ -152,10 +152,10 @@ void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var) {
152 152
 // Send an uint8_t between 0 and 100 to a variable scale to 0..255
153 153
 void DGUSScreenHandler::DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr) {
154 154
   if (var.memadr) {
155
-    uint16_t value = swap16(*(uint16_t*)val_ptr);
156
-    DEBUG_ECHOLNPGM("FAN value get:", value);
155
+    const uint16_t value = BE16_P(val_ptr);
156
+    DEBUG_ECHOLNPGM("Got percent:", value);
157 157
     *(uint8_t*)var.memadr = map(constrain(value, 0, 100), 0, 100, 0, 255);
158
-    DEBUG_ECHOLNPGM("FAN value change:", *(uint8_t*)var.memadr);
158
+    DEBUG_ECHOLNPGM("Set uint8:", *(uint8_t*)var.memadr);
159 159
   }
160 160
 }
161 161
 
@@ -264,10 +264,10 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var)
264 264
     static uint16_t period = 0;
265 265
     static uint16_t index = 0;
266 266
     //DEBUG_ECHOPGM(" DGUSLCD_SendWaitingStatusToDisplay ", var.VP);
267
-    //DEBUG_ECHOLNPGM(" data ", swap16(index));
267
+    //DEBUG_ECHOLNPGM(" data ", BE16_P(&index));
268 268
     if (period++ > DGUS_UI_WAITING_STATUS_PERIOD) {
269 269
       dgusdisplay.WriteVariable(var.VP, index);
270
-      //DEBUG_ECHOLNPGM(" data ", swap16(index));
270
+      //DEBUG_ECHOLNPGM(" data ", BE16_P(&index));
271 271
       if (++index >= DGUS_UI_WAITING_STATUS) index = 0;
272 272
       period = 0;
273 273
     }
@@ -306,7 +306,7 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var)
306 306
 
307 307
   void DGUSScreenHandler::DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable& var, void *val_ptr) {
308 308
     auto old_top = top_file;
309
-    const int16_t scroll = (int16_t)swap16(*(uint16_t*)val_ptr);
309
+    const int16_t scroll = (int16_t)BE16_P(val_ptr);
310 310
     if (scroll) {
311 311
       top_file += scroll;
312 312
       DEBUG_ECHOPGM("new topfile calculated:", top_file);
@@ -391,7 +391,7 @@ void DGUSScreenHandler::HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr
391 391
 }
392 392
 
393 393
 void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr) {
394
-  celsius_t newvalue = swap16(*(uint16_t*)val_ptr);
394
+  celsius_t newvalue = BE16_P(val_ptr);
395 395
   celsius_t acceptedvalue;
396 396
 
397 397
   switch (var.VP) {
@@ -426,7 +426,7 @@ void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *va
426 426
 
427 427
 void DGUSScreenHandler::HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr) {
428 428
   #if HAS_EXTRUDERS
429
-    uint16_t newvalue = swap16(*(uint16_t*)val_ptr);
429
+    const uint16_t newvalue = BE16_P(val_ptr);
430 430
     uint8_t target_extruder;
431 431
     switch (var.VP) {
432 432
       default: return;
@@ -446,7 +446,7 @@ void DGUSScreenHandler::HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_p
446 446
 void DGUSScreenHandler::HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr) {
447 447
   DEBUG_ECHOLNPGM("HandleManualExtrude");
448 448
 
449
-  int16_t movevalue = swap16(*(uint16_t*)val_ptr);
449
+  const int16_t movevalue = BE16_P(val_ptr);
450 450
   float target = movevalue * 0.01f;
451 451
   ExtUI::extruder_t target_extruder;
452 452
 
@@ -468,19 +468,19 @@ void DGUSScreenHandler::HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr
468 468
 #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
469 469
   void DGUSScreenHandler::HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr) {
470 470
     DEBUG_ECHOLNPGM("HandleManualMoveOption");
471
-    *(uint16_t*)var.memadr = swap16(*(uint16_t*)val_ptr);
471
+    *(uint16_t*)var.memadr = BE16_P(val_ptr);
472 472
   }
473 473
 #endif
474 474
 
475 475
 void DGUSScreenHandler::HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr) {
476 476
   DEBUG_ECHOLNPGM("HandleMotorLockUnlock");
477
-  const int16_t lock = swap16(*(uint16_t*)val_ptr);
477
+  const int16_t lock = BE16_P(val_ptr);
478 478
   queue.enqueue_one_now(lock ? F("M18") : F("M17"));
479 479
 }
480 480
 
481 481
 void DGUSScreenHandler::HandleSettings(DGUS_VP_Variable &var, void *val_ptr) {
482 482
   DEBUG_ECHOLNPGM("HandleSettings");
483
-  uint16_t value = swap16(*(uint16_t*)val_ptr);
483
+  const uint16_t value = BE16_P(val_ptr);
484 484
   switch (value) {
485 485
     default: break;
486 486
     case 1:
@@ -494,11 +494,9 @@ void DGUSScreenHandler::HandleSettings(DGUS_VP_Variable &var, void *val_ptr) {
494 494
 }
495 495
 
496 496
 void DGUSScreenHandler::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr) {
497
-  DEBUG_ECHOLNPGM("HandleStepPerMMChanged");
498
-
499
-  uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
500
-  DEBUG_ECHOLNPGM("value_raw:", value_raw);
501
-  float value = (float)value_raw / 10;
497
+  const uint16_t value_raw = BE16_P(val_ptr);
498
+  DEBUG_ECHOLNPGM("HandleStepPerMMChanged:", value_raw);
499
+  const float value = (float)value_raw / 10;
502 500
   ExtUI::axis_t axis;
503 501
   switch (var.VP) {
504 502
     case VP_X_STEP_PER_MM: axis = ExtUI::axis_t::X; break;
@@ -510,15 +508,12 @@ void DGUSScreenHandler::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_
510 508
   ExtUI::setAxisSteps_per_mm(value, axis);
511 509
   DEBUG_ECHOLNPGM("value_set:", ExtUI::getAxisSteps_per_mm(axis));
512 510
   skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
513
-  return;
514 511
 }
515 512
 
516 513
 void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr) {
517
-  DEBUG_ECHOLNPGM("HandleStepPerMMExtruderChanged");
518
-
519
-  uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
520
-  DEBUG_ECHOLNPGM("value_raw:", value_raw);
521
-  float value = (float)value_raw / 10;
514
+  const uint16_t value_raw = BE16_P(val_ptr);
515
+  DEBUG_ECHOLNPGM("HandleStepPerMMExtruderChanged:", value_raw);
516
+  const float value = (float)value_raw / 10;
522 517
   ExtUI::extruder_t extruder;
523 518
   switch (var.VP) {
524 519
     default: return;
@@ -575,7 +570,7 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo
575 570
   void DGUSScreenHandler::HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr) {
576 571
     DEBUG_ECHOLNPGM("HandleProbeOffsetZChanged");
577 572
 
578
-    const float offset = float(int16_t(swap16(*(uint16_t*)val_ptr))) / 100.0f;
573
+    const float offset = float(int16_t(BE16_P(val_ptr))) / 100.0f;
579 574
     ExtUI::setZOffset_mm(offset);
580 575
     skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
581 576
     return;
@@ -621,7 +616,7 @@ void DGUSScreenHandler::HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr
621 616
   void DGUSScreenHandler::HandlePreheat(DGUS_VP_Variable &var, void *val_ptr) {
622 617
     DEBUG_ECHOLNPGM("HandlePreheat");
623 618
 
624
-    const uint16_t preheat_option = swap16(*(uint16_t*)val_ptr);
619
+    const uint16_t preheat_option = BE16_P(val_ptr);
625 620
     switch (preheat_option) {
626 621
       default:
627 622
       switch (var.VP) {
@@ -644,7 +639,7 @@ void DGUSScreenHandler::HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr
644 639
 #if ENABLED(POWER_LOSS_RECOVERY)
645 640
 
646 641
   void DGUSScreenHandler::HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr) {
647
-    uint16_t value = swap16(*(uint16_t*)val_ptr);
642
+    uint16_t value = BE16_P(val_ptr);
648 643
     if (value) {
649 644
       queue.inject(F("M1000"));
650 645
       dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), 32, true);

+ 4
- 0
Marlin/src/lcd/extui/dgus/DGUSScreenHandler.h View File

@@ -42,6 +42,10 @@
42 42
 
43 43
 #endif
44 44
 
45
+// endianness swap
46
+#define BE16_P(V) ( ((uint8_t*)(V))[0] << 8U | ((uint8_t*)(V))[1] )
47
+#define BE32_P(V) ( ((uint8_t*)(V))[0] << 24U | ((uint8_t*)(V))[1] << 16U | ((uint8_t*)(V))[2] << 8U | ((uint8_t*)(V))[3] )
48
+
45 49
 #if ENABLED(DGUS_LCD_UI_ORIGIN)
46 50
   #include "origin/DGUSScreenHandler.h"
47 51
 #elif ENABLED(DGUS_LCD_UI_MKS)

+ 55
- 66
Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp View File

@@ -54,9 +54,6 @@
54 54
 bool DGUSAutoTurnOff = false;
55 55
 MKS_Language mks_language_index; // Initialized by settings.load()
56 56
 
57
-// endianness swap
58
-uint32_t swap32(const uint32_t value) { return (value & 0x000000FFU) << 24U | (value & 0x0000FF00U) << 8U | (value & 0x00FF0000U) >> 8U | (value & 0xFF000000U) >> 24U; }
59
-
60 57
 #if 0
61 58
 void DGUSScreenHandlerMKS::sendinfoscreen_ch(const uint16_t *line1, const uint16_t *line2, const uint16_t *line3, const uint16_t *line4) {
62 59
   dgusdisplay.WriteVariable(VP_MSGSTR1, line1, 32, true);
@@ -108,10 +105,10 @@ void DGUSScreenHandlerMKS::DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var)
108 105
 
109 106
 void DGUSScreenHandlerMKS::DGUSLCD_SetUint8(DGUS_VP_Variable &var, void *val_ptr) {
110 107
   if (var.memadr) {
111
-    const uint16_t value = swap16(*(uint16_t*)val_ptr);
112
-    DEBUG_ECHOLNPGM("FAN value get:", value);
108
+    const uint16_t value = BE16_P(val_ptr);
109
+    DEBUG_ECHOLNPGM("Got uint8:", value);
113 110
     *(uint8_t*)var.memadr = map(constrain(value, 0, 255), 0, 255, 0, 255);
114
-    DEBUG_ECHOLNPGM("FAN value change:", *(uint8_t*)var.memadr);
111
+    DEBUG_ECHOLNPGM("Set uint8:", *(uint8_t*)var.memadr);
115 112
   }
116 113
 }
117 114
 
@@ -152,7 +149,7 @@ void DGUSScreenHandlerMKS::DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var) {
152 149
 #if ENABLED(SDSUPPORT)
153 150
 
154 151
   void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) {
155
-    uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file;
152
+    uint16_t touched_nr = (int16_t)BE16_P(val_ptr) + top_file;
156 153
     if (touched_nr != 0x0F && touched_nr > filelist.count()) return;
157 154
     if (!filelist.seek(touched_nr) && touched_nr != 0x0F) return;
158 155
 
@@ -191,7 +188,7 @@ void DGUSScreenHandlerMKS::DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var) {
191 188
   void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) {
192 189
 
193 190
     if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes.
194
-    switch (swap16(*(uint16_t*)val_ptr)) {
191
+    switch (BE16_P(val_ptr)) {
195 192
       case 0: { // Resume
196 193
         auto cs = getCurrentScreen();
197 194
         if (runout_mks.runout_status != RUNOUT_WAITING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) {
@@ -268,7 +265,7 @@ void DGUSScreenHandlerMKS::DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var) {
268 265
 
269 266
 #else
270 267
   void DGUSScreenHandlerMKS::PrintReturn(DGUS_VP_Variable& var, void *val_ptr) {
271
-    uint16_t value = swap16(*(uint16_t*)val_ptr);
268
+    const uint16_t value = BE16_P(val_ptr);
272 269
     if (value == 0x0F) GotoScreen(DGUSLCD_SCREEN_MAIN);
273 270
   }
274 271
 #endif // SDSUPPORT
@@ -315,7 +312,7 @@ void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) {
315 312
 }
316 313
 
317 314
 void DGUSScreenHandlerMKS::ScreenBackChange(DGUS_VP_Variable &var, void *val_ptr) {
318
-  const uint16_t target = swap16(*(uint16_t *)val_ptr);
315
+  const uint16_t target = BE16_P(val_ptr);
319 316
   DEBUG_ECHOLNPGM(" back = 0x%x", target);
320 317
   switch (target) {
321 318
   }
@@ -331,7 +328,7 @@ void DGUSScreenHandlerMKS::ZoffsetConfirm(DGUS_VP_Variable &var, void *val_ptr)
331 328
 
332 329
 void DGUSScreenHandlerMKS::GetTurnOffCtrl(DGUS_VP_Variable &var, void *val_ptr) {
333 330
   DEBUG_ECHOLNPGM("GetTurnOffCtrl\n");
334
-  const uint16_t value = swap16(*(uint16_t *)val_ptr);
331
+  const uint16_t value = BE16_P(val_ptr);
335 332
   switch (value) {
336 333
     case 0 ... 1: DGUSAutoTurnOff = (bool)value; break;
337 334
     default: break;
@@ -340,7 +337,7 @@ void DGUSScreenHandlerMKS::GetTurnOffCtrl(DGUS_VP_Variable &var, void *val_ptr)
340 337
 
341 338
 void DGUSScreenHandlerMKS::GetMinExtrudeTemp(DGUS_VP_Variable &var, void *val_ptr) {
342 339
   DEBUG_ECHOLNPGM("GetMinExtrudeTemp");
343
-  const uint16_t value = swap16(*(uint16_t *)val_ptr);
340
+  const uint16_t value = BE16_P(val_ptr);
344 341
   TERN_(PREVENT_COLD_EXTRUSION, thermalManager.extrude_min_temp = value);
345 342
   mks_min_extrusion_temp = value;
346 343
   settings.save();
@@ -348,7 +345,7 @@ void DGUSScreenHandlerMKS::GetMinExtrudeTemp(DGUS_VP_Variable &var, void *val_pt
348 345
 
349 346
 void DGUSScreenHandlerMKS::GetZoffsetDistance(DGUS_VP_Variable &var, void *val_ptr) {
350 347
   DEBUG_ECHOLNPGM("GetZoffsetDistance");
351
-  const uint16_t value = swap16(*(uint16_t *)val_ptr);
348
+  const uint16_t value = BE16_P(val_ptr);
352 349
   float val_distance = 0;
353 350
   switch (value) {
354 351
     case 0: val_distance = 0.01; break;
@@ -362,11 +359,11 @@ void DGUSScreenHandlerMKS::GetZoffsetDistance(DGUS_VP_Variable &var, void *val_p
362 359
 
363 360
 void DGUSScreenHandlerMKS::GetManualMovestep(DGUS_VP_Variable &var, void *val_ptr) {
364 361
   DEBUG_ECHOLNPGM("\nGetManualMovestep");
365
-  *(uint16_t *)var.memadr = swap16(*(uint16_t *)val_ptr);
362
+  *(uint16_t *)var.memadr = BE16_P(val_ptr);
366 363
 }
367 364
 
368 365
 void DGUSScreenHandlerMKS::EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr) {
369
-  const uint16_t eep_flag = swap16(*(uint16_t *)val_ptr);
366
+  const uint16_t eep_flag = BE16_P(val_ptr);
370 367
   switch (eep_flag) {
371 368
     case 0:
372 369
       settings.save();
@@ -384,7 +381,7 @@ void DGUSScreenHandlerMKS::EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr) {
384 381
 }
385 382
 
386 383
 void DGUSScreenHandlerMKS::Z_offset_select(DGUS_VP_Variable &var, void *val_ptr) {
387
-  const uint16_t z_value = swap16(*(uint16_t *)val_ptr);
384
+  const uint16_t z_value = BE16_P(val_ptr);
388 385
   switch (z_value) {
389 386
     case 0: Z_distance = 0.01; break;
390 387
     case 1: Z_distance = 0.1; break;
@@ -396,22 +393,22 @@ void DGUSScreenHandlerMKS::Z_offset_select(DGUS_VP_Variable &var, void *val_ptr)
396 393
 void DGUSScreenHandlerMKS::GetOffsetValue(DGUS_VP_Variable &var, void *val_ptr) {
397 394
 
398 395
   #if HAS_BED_PROBE
399
-    int32_t value = swap32(*(int32_t *)val_ptr);
400
-    float Offset = value / 100.0f;
396
+    const int32_t value = BE32_P(val_ptr);
397
+    const float Offset = value / 100.0f;
401 398
     DEBUG_ECHOLNPGM("\nget int6 offset >> ", value, 6);
402
-  #endif
403 399
 
404
-  switch (var.VP) {
405
-    case VP_OFFSET_X: TERN_(HAS_BED_PROBE, probe.offset.x = Offset); break;
406
-    case VP_OFFSET_Y: TERN_(HAS_BED_PROBE, probe.offset.y = Offset); break;
407
-    case VP_OFFSET_Z: TERN_(HAS_BED_PROBE, probe.offset.z = Offset); break;
408
-    default: break;
409
-  }
410
-  settings.save();
400
+    switch (var.VP) {
401
+      default: break;
402
+        case VP_OFFSET_X: probe.offset.x = Offset; break;
403
+        case VP_OFFSET_Y: probe.offset.y = Offset; break;
404
+        case VP_OFFSET_Z: probe.offset.z = Offset; break;
405
+    }
406
+    settings.save();
407
+  #endif
411 408
 }
412 409
 
413 410
 void DGUSScreenHandlerMKS::LanguageChange(DGUS_VP_Variable &var, void *val_ptr) {
414
-  const uint16_t lag_flag = swap16(*(uint16_t *)val_ptr);
411
+  const uint16_t lag_flag = BE16_P(val_ptr);
415 412
   switch (lag_flag) {
416 413
     case MKS_SimpleChinese:
417 414
       DGUS_LanguageDisplay(MKS_SimpleChinese);
@@ -436,10 +433,10 @@ void DGUSScreenHandlerMKS::LanguageChange(DGUS_VP_Variable &var, void *val_ptr)
436 433
 #endif
437 434
 
438 435
 void DGUSScreenHandlerMKS::Level_Ctrl(DGUS_VP_Variable &var, void *val_ptr) {
439
-  const uint16_t lev_but = swap16(*(uint16_t *)val_ptr);
440 436
   #if ENABLED(MESH_BED_LEVELING)
441 437
     auto cs = getCurrentScreen();
442 438
   #endif
439
+  const uint16_t lev_but = BE16_P(val_ptr);
443 440
   switch (lev_but) {
444 441
     case 0:
445 442
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@@ -483,7 +480,7 @@ void DGUSScreenHandlerMKS::Level_Ctrl(DGUS_VP_Variable &var, void *val_ptr) {
483 480
 }
484 481
 
485 482
 void DGUSScreenHandlerMKS::MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *val_ptr) {
486
-  const uint16_t mesh_dist = swap16(*(uint16_t *)val_ptr);
483
+  const uint16_t mesh_dist = BE16_P(val_ptr);
487 484
   switch (mesh_dist) {
488 485
     case 0: mesh_adj_distance = 0.01; break;
489 486
     case 1: mesh_adj_distance = 0.1; break;
@@ -494,7 +491,7 @@ void DGUSScreenHandlerMKS::MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *
494 491
 
495 492
 void DGUSScreenHandlerMKS::MeshLevel(DGUS_VP_Variable &var, void *val_ptr) {
496 493
   #if ENABLED(MESH_BED_LEVELING)
497
-    const uint16_t mesh_value = swap16(*(uint16_t *)val_ptr);
494
+    const uint16_t mesh_value = BE16_P(val_ptr);
498 495
     // static uint8_t a_first_level = 1;
499 496
     char cmd_buf[30];
500 497
     float offset = mesh_adj_distance;
@@ -592,8 +589,8 @@ void DGUSScreenHandlerMKS::SD_FileBack(DGUS_VP_Variable&, void*) {
592 589
 }
593 590
 
594 591
 void DGUSScreenHandlerMKS::LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr) {
595
-  const uint16_t lcd_value = swap16(*(uint16_t *)val_ptr);
596 592
 
593
+  const uint16_t lcd_value = BE16_P(val_ptr);
597 594
   lcd_default_light = constrain(lcd_value, 10, 100);
598 595
 
599 596
   const uint16_t lcd_data[2] = { lcd_default_light, lcd_default_light };
@@ -601,7 +598,7 @@ void DGUSScreenHandlerMKS::LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr)
601 598
 }
602 599
 
603 600
 void DGUSScreenHandlerMKS::ManualAssistLeveling(DGUS_VP_Variable &var, void *val_ptr) {
604
-  const int16_t point_value = swap16(*(uint16_t *)val_ptr);
601
+  const int16_t point_value = BE16_P(val_ptr);
605 602
 
606 603
   // Insist on leveling first time at this screen
607 604
   static bool first_level_flag = false;
@@ -655,7 +652,7 @@ void DGUSScreenHandlerMKS::ManualAssistLeveling(DGUS_VP_Variable &var, void *val
655 652
 #define mks_max(a, b) ((a) > (b)) ? (a) : (b)
656 653
 void DGUSScreenHandlerMKS::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr) {
657 654
   #if EITHER(HAS_TRINAMIC_CONFIG, HAS_STEALTHCHOP)
658
-    const uint16_t tmc_value = swap16(*(uint16_t*)val_ptr);
655
+    const uint16_t tmc_value = BE16_P(val_ptr);
659 656
   #endif
660 657
 
661 658
   switch (var.VP) {
@@ -748,7 +745,7 @@ void DGUSScreenHandlerMKS::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr
748 745
 void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
749 746
   DEBUG_ECHOLNPGM("HandleManualMove");
750 747
 
751
-  int16_t movevalue = swap16(*(uint16_t*)val_ptr);
748
+  int16_t movevalue = BE16_P(val_ptr);
752 749
 
753 750
   // Choose Move distance
754 751
        if (manualMoveStep == 0x01) manualMoveStep =   10;
@@ -893,7 +890,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
893 890
 }
894 891
 
895 892
 void DGUSScreenHandlerMKS::GetParkPos(DGUS_VP_Variable &var, void *val_ptr) {
896
-  const int16_t value_pos = swap16(*(int16_t*)val_ptr);
893
+  const int16_t value_pos = BE16_P(val_ptr);
897 894
 
898 895
   switch (var.VP) {
899 896
     case VP_X_PARK_POS: mks_park_pos.x = value_pos; break;
@@ -907,7 +904,7 @@ void DGUSScreenHandlerMKS::GetParkPos(DGUS_VP_Variable &var, void *val_ptr) {
907 904
 void DGUSScreenHandlerMKS::HandleChangeLevelPoint(DGUS_VP_Variable &var, void *val_ptr) {
908 905
   DEBUG_ECHOLNPGM("HandleChangeLevelPoint");
909 906
 
910
-  const int16_t value_raw = swap16(*(int16_t*)val_ptr);
907
+  const int16_t value_raw = BE16_P(val_ptr);
911 908
   DEBUG_ECHOLNPGM("value_raw:", value_raw);
912 909
 
913 910
   *(int16_t*)var.memadr = value_raw;
@@ -919,7 +916,7 @@ void DGUSScreenHandlerMKS::HandleChangeLevelPoint(DGUS_VP_Variable &var, void *v
919 916
 void DGUSScreenHandlerMKS::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr) {
920 917
   DEBUG_ECHOLNPGM("HandleStepPerMMChanged");
921 918
 
922
-  const uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
919
+  const uint16_t value_raw = BE16_P(val_ptr);
923 920
   const float value = (float)value_raw;
924 921
 
925 922
   DEBUG_ECHOLNPGM("value_raw:", value_raw);
@@ -941,7 +938,7 @@ void DGUSScreenHandlerMKS::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *v
941 938
 void DGUSScreenHandlerMKS::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr) {
942 939
   DEBUG_ECHOLNPGM("HandleStepPerMMExtruderChanged");
943 940
 
944
-  const uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
941
+  const uint16_t value_raw = BE16_P(val_ptr);
945 942
   const float value = (float)value_raw;
946 943
 
947 944
   DEBUG_ECHOLNPGM("value_raw:", value_raw);
@@ -966,7 +963,7 @@ void DGUSScreenHandlerMKS::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var,
966 963
 void DGUSScreenHandlerMKS::HandleMaxSpeedChange(DGUS_VP_Variable &var, void *val_ptr) {
967 964
   DEBUG_ECHOLNPGM("HandleMaxSpeedChange");
968 965
 
969
-  const uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
966
+  const uint16_t value_raw = BE16_P(val_ptr);
970 967
   const float value = (float)value_raw;
971 968
 
972 969
   DEBUG_ECHOLNPGM("value_raw:", value_raw);
@@ -988,7 +985,7 @@ void DGUSScreenHandlerMKS::HandleMaxSpeedChange(DGUS_VP_Variable &var, void *val
988 985
 void DGUSScreenHandlerMKS::HandleExtruderMaxSpeedChange(DGUS_VP_Variable &var, void *val_ptr) {
989 986
   DEBUG_ECHOLNPGM("HandleExtruderMaxSpeedChange");
990 987
 
991
-  const uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
988
+  const uint16_t value_raw = BE16_P(val_ptr);
992 989
   const float value = (float)value_raw;
993 990
 
994 991
   DEBUG_ECHOLNPGM("value_raw:", value_raw);
@@ -1013,7 +1010,7 @@ void DGUSScreenHandlerMKS::HandleExtruderMaxSpeedChange(DGUS_VP_Variable &var, v
1013 1010
 void DGUSScreenHandlerMKS::HandleMaxAccChange(DGUS_VP_Variable &var, void *val_ptr) {
1014 1011
   DEBUG_ECHOLNPGM("HandleMaxAccChange");
1015 1012
 
1016
-  const uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
1013
+  const uint16_t value_raw = BE16_P(val_ptr);
1017 1014
   const float value = (float)value_raw;
1018 1015
 
1019 1016
   DEBUG_ECHOLNPGM("value_raw:", value_raw);
@@ -1035,7 +1032,7 @@ void DGUSScreenHandlerMKS::HandleMaxAccChange(DGUS_VP_Variable &var, void *val_p
1035 1032
 void DGUSScreenHandlerMKS::HandleExtruderAccChange(DGUS_VP_Variable &var, void *val_ptr) {
1036 1033
   DEBUG_ECHOLNPGM("HandleExtruderAccChange");
1037 1034
 
1038
-  uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
1035
+  uint16_t value_raw = BE16_P(val_ptr);
1039 1036
   DEBUG_ECHOLNPGM("value_raw:", value_raw);
1040 1037
   float value = (float)value_raw;
1041 1038
   ExtUI::extruder_t extruder;
@@ -1056,32 +1053,32 @@ void DGUSScreenHandlerMKS::HandleExtruderAccChange(DGUS_VP_Variable &var, void *
1056 1053
 }
1057 1054
 
1058 1055
 void DGUSScreenHandlerMKS::HandleTravelAccChange(DGUS_VP_Variable &var, void *val_ptr) {
1059
-  uint16_t value_travel = swap16(*(uint16_t*)val_ptr);
1056
+  uint16_t value_travel = BE16_P(val_ptr);
1060 1057
   planner.settings.travel_acceleration = (float)value_travel;
1061 1058
   skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
1062 1059
 }
1063 1060
 
1064 1061
 void DGUSScreenHandlerMKS::HandleFeedRateMinChange(DGUS_VP_Variable &var, void *val_ptr) {
1065
-  uint16_t value_t = swap16(*(uint16_t*)val_ptr);
1062
+  uint16_t value_t = BE16_P(val_ptr);
1066 1063
   planner.settings.min_feedrate_mm_s = (float)value_t;
1067 1064
   skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
1068 1065
 }
1069 1066
 
1070 1067
 void DGUSScreenHandlerMKS::HandleMin_T_F(DGUS_VP_Variable &var, void *val_ptr) {
1071
-  uint16_t value_t_f = swap16(*(uint16_t*)val_ptr);
1068
+  uint16_t value_t_f = BE16_P(val_ptr);
1072 1069
   planner.settings.min_travel_feedrate_mm_s = (float)value_t_f;
1073 1070
   skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
1074 1071
 }
1075 1072
 
1076 1073
 void DGUSScreenHandlerMKS::HandleAccChange(DGUS_VP_Variable &var, void *val_ptr) {
1077
-  uint16_t value_acc = swap16(*(uint16_t*)val_ptr);
1074
+  uint16_t value_acc = BE16_P(val_ptr);
1078 1075
   planner.settings.acceleration = (float)value_acc;
1079 1076
   skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
1080 1077
 }
1081 1078
 
1082 1079
 #if ENABLED(PREVENT_COLD_EXTRUSION)
1083 1080
   void DGUSScreenHandlerMKS::HandleGetExMinTemp(DGUS_VP_Variable &var, void *val_ptr) {
1084
-    const uint16_t value_ex_min_temp = swap16(*(uint16_t*)val_ptr);
1081
+    const uint16_t value_ex_min_temp = BE16_P(val_ptr);
1085 1082
     thermalManager.extrude_min_temp = value_ex_min_temp;
1086 1083
     skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
1087 1084
   }
@@ -1089,7 +1086,7 @@ void DGUSScreenHandlerMKS::HandleAccChange(DGUS_VP_Variable &var, void *val_ptr)
1089 1086
 
1090 1087
 #if HAS_PID_HEATING
1091 1088
   void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) {
1092
-    const uint16_t rawvalue = swap16(*(uint16_t*)val_ptr);
1089
+    const uint16_t rawvalue = BE16_P(val_ptr);
1093 1090
     DEBUG_ECHOLNPGM("V1:", rawvalue);
1094 1091
     const float value = 1.0f * rawvalue;
1095 1092
     DEBUG_ECHOLNPGM("V2:", value);
@@ -1125,9 +1122,9 @@ void DGUSScreenHandlerMKS::HandleAccChange(DGUS_VP_Variable &var, void *val_ptr)
1125 1122
 #if ENABLED(BABYSTEPPING)
1126 1123
   void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) {
1127 1124
     DEBUG_ECHOLNPGM("HandleLiveAdjustZ");
1128
-    float step = ZOffset_distance;
1125
+    const float step = ZOffset_distance;
1129 1126
 
1130
-    uint16_t flag = swap16(*(uint16_t*)val_ptr);
1127
+    const uint16_t flag = BE16_P(val_ptr);
1131 1128
     switch (flag) {
1132 1129
       case 0:
1133 1130
         if (step == 0.01)
@@ -1159,34 +1156,26 @@ void DGUSScreenHandlerMKS::HandleAccChange(DGUS_VP_Variable &var, void *val_ptr)
1159 1156
         z_offset_add += ZOffset_distance;
1160 1157
         break;
1161 1158
 
1162
-      default:
1163
-        break;
1159
+      default: break;
1164 1160
     }
1165 1161
     ForceCompleteUpdate();
1166 1162
   }
1167 1163
 #endif // BABYSTEPPING
1168 1164
 
1169 1165
 void DGUSScreenHandlerMKS::GetManualFilament(DGUS_VP_Variable &var, void *val_ptr) {
1170
-  DEBUG_ECHOLNPGM("GetManualFilament");
1171
-
1172
-  uint16_t value_len = swap16(*(uint16_t*)val_ptr);
1166
+  const uint16_t value_len = BE16_P(val_ptr);
1167
+  const float value = (float)value_len;
1173 1168
 
1174
-  float value = (float)value_len;
1175
-
1176
-  DEBUG_ECHOLNPGM("Get Filament len value:", value);
1169
+  DEBUG_ECHOLNPGM("GetManualFilament:", value);
1177 1170
   distanceFilament = value;
1178 1171
 
1179 1172
   skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
1180 1173
 }
1181 1174
 
1182 1175
 void DGUSScreenHandlerMKS::GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ptr) {
1183
-  DEBUG_ECHOLNPGM("GetManualFilamentSpeed");
1184
-
1185
-  uint16_t value_len = swap16(*(uint16_t*)val_ptr);
1186
-
1187
-  DEBUG_ECHOLNPGM("filamentSpeed_mm_s value:", value_len);
1188
-
1176
+  const uint16_t value_len = BE16_P(val_ptr);
1189 1177
   filamentSpeed_mm_s = value_len;
1178
+  DEBUG_ECHOLNPGM("GetManualFilamentSpeed:", value_len);
1190 1179
 
1191 1180
   skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
1192 1181
 }
@@ -1205,7 +1194,7 @@ void DGUSScreenHandlerMKS::FilamentLoadUnload(DGUS_VP_Variable &var, void *val_p
1205 1194
   if (!print_job_timer.isPaused() && !queue.ring_buffer.empty())
1206 1195
     return;
1207 1196
 
1208
-  const uint16_t val_t = swap16(*(uint16_t*)val_ptr);
1197
+  const uint16_t val_t = BE16_P(val_ptr);
1209 1198
   switch (val_t) {
1210 1199
     default: break;
1211 1200
     case 0:
@@ -1291,7 +1280,7 @@ void DGUSScreenHandlerMKS::FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr)
1291 1280
 
1292 1281
     uint8_t e_temp = 0;
1293 1282
     filament_data.heated = false;
1294
-    uint16_t preheat_option = swap16(*(uint16_t*)val_ptr);
1283
+    uint16_t preheat_option = BE16_P(val_ptr);
1295 1284
     if (preheat_option >= 10) {     // Unload filament type
1296 1285
       preheat_option -= 10;
1297 1286
       filament_data.action = 2;

+ 8
- 3
Marlin/src/lcd/extui/dgus_reloaded/DGUSDisplay.h View File

@@ -21,7 +21,10 @@
21 21
  */
22 22
 #pragma once
23 23
 
24
-/* DGUS implementation written by coldtobi in 2019 for Marlin */
24
+/**
25
+ * DGUS implementation written by coldtobi in 2019.
26
+ * Updated for STM32G0B1RE by Protomosh in 2022.
27
+ */
25 28
 
26 29
 #include "config/DGUS_Screen.h"
27 30
 #include "config/DGUS_Control.h"
@@ -30,11 +33,13 @@
30 33
 #include "../../../inc/MarlinConfigPre.h"
31 34
 #include "../../../MarlinCore.h"
32 35
 
36
+#define DEBUG_DGUSLCD // Uncomment for debug messages
33 37
 #define DEBUG_OUT ENABLED(DEBUG_DGUSLCD)
34 38
 #include "../../../core/debug_out.h"
35 39
 
36
-#define Swap16(val) ((uint16_t)(((uint16_t)(val) >> 8) |\
37
-                                ((uint16_t)(val) << 8)))
40
+// New endianness swap for 32bit mcu (tested with STM32G0B1RE)
41
+#define BE16_P(V) ( ((uint8_t*)(V))[0] << 8U | ((uint8_t*)(V))[1] )
42
+#define BE32_P(V) ( ((uint8_t*)(V))[0] << 24U | ((uint8_t*)(V))[1] << 16U | ((uint8_t*)(V))[2] << 8U | ((uint8_t*)(V))[3] )
38 43
 
39 44
 // Low-Level access to the display.
40 45
 class DGUSDisplay {

+ 11
- 11
Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp View File

@@ -215,7 +215,7 @@ void DGUSRxHandler::PrintResume(DGUS_VP &vp, void *data_ptr) {
215 215
 void DGUSRxHandler::Feedrate(DGUS_VP &vp, void *data_ptr) {
216 216
   UNUSED(vp);
217 217
 
218
-  const int16_t feedrate = Swap16(*(int16_t*)data_ptr);
218
+  const int16_t feedrate = BE16_P(data_ptr);
219 219
 
220 220
   ExtUI::setFeedrate_percent(feedrate);
221 221
 
@@ -223,7 +223,7 @@ void DGUSRxHandler::Feedrate(DGUS_VP &vp, void *data_ptr) {
223 223
 }
224 224
 
225 225
 void DGUSRxHandler::Flowrate(DGUS_VP &vp, void *data_ptr) {
226
-  const int16_t flowrate = Swap16(*(int16_t*)data_ptr);
226
+  const int16_t flowrate = BE16_P(data_ptr);
227 227
 
228 228
   switch (vp.addr) {
229 229
     default: return;
@@ -246,7 +246,7 @@ void DGUSRxHandler::Flowrate(DGUS_VP &vp, void *data_ptr) {
246 246
 void DGUSRxHandler::BabystepSet(DGUS_VP &vp, void *data_ptr) {
247 247
   UNUSED(vp);
248 248
 
249
-  const int16_t data = Swap16(*(int16_t*)data_ptr);
249
+  const int16_t data = BE16_P(data_ptr);
250 250
   const float offset = dgus_display.FromFixedPoint<int16_t, float, 2>(data);
251 251
 
252 252
   const int16_t steps = ExtUI::mmToWholeSteps(offset - ExtUI::getZOffset_mm(), ExtUI::Z);
@@ -315,7 +315,7 @@ void DGUSRxHandler::TempPreset(DGUS_VP &vp, void *data_ptr) {
315 315
 }
316 316
 
317 317
 void DGUSRxHandler::TempTarget(DGUS_VP &vp, void *data_ptr) {
318
-  const int16_t temp = Swap16(*(int16_t*)data_ptr);
318
+  const int16_t temp = BE16_P(data_ptr);
319 319
 
320 320
   switch (vp.addr) {
321 321
     default: return;
@@ -338,7 +338,7 @@ void DGUSRxHandler::TempTarget(DGUS_VP &vp, void *data_ptr) {
338 338
 void DGUSRxHandler::TempCool(DGUS_VP &vp, void *data_ptr) {
339 339
   UNUSED(vp);
340 340
 
341
-  const DGUS_Data::Heater heater = (DGUS_Data::Heater)Swap16(*(uint16_t*)data_ptr);
341
+  const DGUS_Data::Heater heater = (DGUS_Data::Heater)BE16_P(data_ptr);
342 342
 
343 343
   switch (heater) {
344 344
     default: return;
@@ -397,7 +397,7 @@ void DGUSRxHandler::ZOffset(DGUS_VP &vp, void *data_ptr) {
397 397
     return;
398 398
   }
399 399
 
400
-  const int16_t data = Swap16(*(int16_t*)data_ptr);
400
+  const int16_t data = BE16_P(data_ptr);
401 401
   const float offset = dgus_display.FromFixedPoint<int16_t, float, 2>(data);
402 402
 
403 403
   const int16_t steps = ExtUI::mmToWholeSteps(offset - ExtUI::getZOffset_mm(), ExtUI::Z);
@@ -546,7 +546,7 @@ void DGUSRxHandler::DisableABL(DGUS_VP &vp, void *data_ptr) {
546 546
 void DGUSRxHandler::FilamentSelect(DGUS_VP &vp, void *data_ptr) {
547 547
   UNUSED(vp);
548 548
 
549
-  const DGUS_Data::Extruder extruder = (DGUS_Data::Extruder)Swap16(*(uint16_t*)data_ptr);
549
+  const DGUS_Data::Extruder extruder = (DGUS_Data::Extruder)BE16_P(data_ptr);
550 550
 
551 551
   switch (extruder) {
552 552
     default: return;
@@ -563,7 +563,7 @@ void DGUSRxHandler::FilamentSelect(DGUS_VP &vp, void *data_ptr) {
563 563
 void DGUSRxHandler::FilamentLength(DGUS_VP &vp, void *data_ptr) {
564 564
   UNUSED(vp);
565 565
 
566
-  const uint16_t length = Swap16(*(uint16_t*)data_ptr);
566
+  const uint16_t length = BE16_P(data_ptr);
567 567
 
568 568
   dgus_screen_handler.filament_length = constrain(length, 0, EXTRUDE_MAXLENGTH);
569 569
 
@@ -644,7 +644,7 @@ void DGUSRxHandler::Home(DGUS_VP &vp, void *data_ptr) {
644 644
 }
645 645
 
646 646
 void DGUSRxHandler::Move(DGUS_VP &vp, void *data_ptr) {
647
-  const int16_t data = Swap16(*(int16_t*)data_ptr);
647
+  const int16_t data = BE16_P(data_ptr);
648 648
   const float position = dgus_display.FromFixedPoint<int16_t, float, 1>(data);
649 649
   ExtUI::axis_t axis;
650 650
 
@@ -816,7 +816,7 @@ void DGUSRxHandler::SettingsExtra(DGUS_VP &vp, void *data_ptr) {
816 816
 void DGUSRxHandler::PIDSelect(DGUS_VP &vp, void *data_ptr) {
817 817
   UNUSED(vp);
818 818
 
819
-  const DGUS_Data::Heater heater = (DGUS_Data::Heater)Swap16(*(uint16_t*)data_ptr);
819
+  const DGUS_Data::Heater heater = (DGUS_Data::Heater)BE16_P(data_ptr);
820 820
 
821 821
   switch (heater) {
822 822
     default: return;
@@ -846,7 +846,7 @@ void DGUSRxHandler::PIDSetTemp(DGUS_VP &vp, void *data_ptr) {
846 846
     return;
847 847
   }
848 848
 
849
-  uint16_t temp = Swap16(*(uint16_t*)data_ptr);
849
+  uint16_t temp = BE16_P(data_ptr);
850 850
 
851 851
   switch (dgus_screen_handler.pid_heater) {
852 852
     default: return;

+ 1
- 1
Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.h View File

@@ -107,7 +107,7 @@ namespace DGUSRxHandler {
107 107
         break;
108 108
       }
109 109
       case 2: {
110
-        const uint16_t data = Swap16(*(uint16_t*)data_ptr);
110
+        const uint16_t data = BE16_P(data_ptr);
111 111
         *(T*)vp.extra = (T)data;
112 112
         break;
113 113
       }

+ 2
- 0
Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.h View File

@@ -24,6 +24,8 @@
24 24
 #include "DGUSDisplay.h"
25 25
 #include "definition/DGUS_VP.h"
26 26
 
27
+#define Swap16(val) ((uint16_t)(((uint16_t)(val) >> 8) | ((uint16_t)(val) << 8)))
28
+
27 29
 namespace DGUSTxHandler {
28 30
 
29 31
   #if ENABLED(SDSUPPORT)

Loading…
Cancel
Save