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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. constexpr char axis_codes[XYZE] = { 'X', 'Y', 'Z', 'E' };
  25. // Delay that ensures heaters and watchdog are kept alive
  26. void safe_delay(millis_t ms);
  27. // A delay to provide brittle hosts time to receive bytes
  28. inline void serial_delay(const millis_t ms) {
  29. #if ENABLED(SERIAL_OVERRUN_PROTECTION)
  30. safe_delay(ms);
  31. #else
  32. UNUSED(ms);
  33. #endif
  34. }
  35. // 16x16 bit arrays
  36. FORCE_INLINE void bitmap_clear(uint16_t bits[16], const uint8_t x, const uint8_t y) { CBI(bits[y], x); }
  37. FORCE_INLINE void bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { SBI(bits[y], x); }
  38. FORCE_INLINE bool is_bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
  39. #if ENABLED(DEBUG_LEVELING_FEATURE)
  40. void log_machine_info();
  41. #else
  42. #define log_machine_info() NOOP
  43. #endif
  44. template<typename T>
  45. class restorer {
  46. T& ref_;
  47. T val_;
  48. public:
  49. restorer(T& perm) : ref_(perm), val_(perm) {}
  50. restorer(T& perm, T temp_val) : ref_(perm), val_(perm) { perm = temp_val; }
  51. ~restorer() { restore(); }
  52. inline void restore() { ref_ = val_; }
  53. };
  54. #define REMEMBER(N,X, ...) restorer<typeof(X)> restorer_##N(X, ##__VA_ARGS__)
  55. #define RESTORE(N) restorer_##N.restore()
  56. // Converts from an uint8_t in the range of 0-255 to an uint8_t
  57. // in the range 0-100 while avoiding rounding artifacts
  58. constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }