My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utility.h 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfigPre.h"
  24. #include "../core/types.h"
  25. #include "../core/millis_t.h"
  26. void safe_delay(millis_t ms); // Delay ensuring that temperatures are updated and the watchdog is kept alive.
  27. #if ENABLED(MARLIN_DEV_MODE)
  28. void early_safe_delay(millis_t ms); // Delay ensuring that the watchdog is kept alive. Can be used before the Temperature ISR starts.
  29. #else
  30. inline void early_safe_delay(millis_t ms) { safe_delay(ms); }
  31. #endif
  32. #if ENABLED(SERIAL_OVERRUN_PROTECTION)
  33. void serial_delay(const millis_t ms);
  34. #else
  35. inline void serial_delay(const millis_t) {}
  36. #endif
  37. #if (GRID_MAX_POINTS_X) && (GRID_MAX_POINTS_Y)
  38. // 16x16 bit arrays
  39. template <int W, int H>
  40. struct FlagBits {
  41. typename IF<(W>8), uint16_t, uint8_t>::type bits[H];
  42. void fill() { memset(bits, 0xFF, sizeof(bits)); }
  43. void reset() { memset(bits, 0x00, sizeof(bits)); }
  44. void unmark(const uint8_t x, const uint8_t y) { CBI(bits[y], x); }
  45. void mark(const uint8_t x, const uint8_t y) { SBI(bits[y], x); }
  46. bool marked(const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
  47. inline void unmark(const xy_int8_t &xy) { unmark(xy.x, xy.y); }
  48. inline void mark(const xy_int8_t &xy) { mark(xy.x, xy.y); }
  49. inline bool marked(const xy_int8_t &xy) { return marked(xy.x, xy.y); }
  50. };
  51. typedef FlagBits<GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y> MeshFlags;
  52. #endif
  53. #if ENABLED(DEBUG_LEVELING_FEATURE)
  54. void log_machine_info();
  55. #else
  56. #define log_machine_info() NOOP
  57. #endif
  58. template<typename T>
  59. class restorer {
  60. T& ref_;
  61. T val_;
  62. public:
  63. restorer(T& perm) : ref_(perm), val_(perm) {}
  64. restorer(T& perm, T temp_val) : ref_(perm), val_(perm) { perm = temp_val; }
  65. ~restorer() { restore(); }
  66. inline void restore() { ref_ = val_; }
  67. };
  68. #define REMEMBER(N,X,V...) restorer<__typeof__(X)> restorer_##N(X, ##V)
  69. #define RESTORE(N) restorer_##N.restore()
  70. // Converts from an uint8_t in the range of 0-255 to an uint8_t
  71. // in the range 0-100 while avoiding rounding artifacts
  72. constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }