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 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <http://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. // Delay that ensures heaters and watchdog are kept alive
  27. void safe_delay(millis_t ms);
  28. #if ENABLED(SERIAL_OVERRUN_PROTECTION)
  29. void serial_delay(const millis_t ms);
  30. #else
  31. inline void serial_delay(const millis_t) {}
  32. #endif
  33. #if GRID_MAX_POINTS_X && GRID_MAX_POINTS_Y
  34. // 16x16 bit arrays
  35. template <int W, int H>
  36. struct FlagBits {
  37. typename IF<(W>8), uint16_t, uint8_t>::type bits[H];
  38. void fill() { memset(bits, 0xFF, sizeof(bits)); }
  39. void reset() { memset(bits, 0x00, sizeof(bits)); }
  40. void unmark(const uint8_t x, const uint8_t y) { CBI(bits[y], x); }
  41. void mark(const uint8_t x, const uint8_t y) { SBI(bits[y], x); }
  42. bool marked(const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
  43. inline void unmark(const xy_int8_t &xy) { unmark(xy.x, xy.y); }
  44. inline void mark(const xy_int8_t &xy) { mark(xy.x, xy.y); }
  45. inline bool marked(const xy_int8_t &xy) { return marked(xy.x, xy.y); }
  46. };
  47. typedef FlagBits<GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y> MeshFlags;
  48. #endif
  49. #if ENABLED(DEBUG_LEVELING_FEATURE)
  50. void log_machine_info();
  51. #else
  52. #define log_machine_info() NOOP
  53. #endif
  54. template<typename T>
  55. class restorer {
  56. T& ref_;
  57. T val_;
  58. public:
  59. restorer(T& perm) : ref_(perm), val_(perm) {}
  60. restorer(T& perm, T temp_val) : ref_(perm), val_(perm) { perm = temp_val; }
  61. ~restorer() { restore(); }
  62. inline void restore() { ref_ = val_; }
  63. };
  64. #define REMEMBER(N,X,V...) restorer<typeof(X)> restorer_##N(X, ##V)
  65. #define RESTORE(N) restorer_##N.restore()
  66. // Converts from an uint8_t in the range of 0-255 to an uint8_t
  67. // in the range 0-100 while avoiding rounding artifacts
  68. constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }