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.

direct_stepping.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/MarlinConfig.h"
  24. namespace DirectStepping {
  25. enum State : char {
  26. MONITOR, NEWLINE, ADDRESS, SIZE, COLLECT, CHECKSUM, UNFAIL
  27. };
  28. enum PageState : uint8_t {
  29. FREE, WRITING, OK, FAIL
  30. };
  31. // Static state used for stepping through direct stepping pages
  32. struct page_step_state_t {
  33. // Current page
  34. uint8_t *page;
  35. // Current segment
  36. uint16_t segment_idx;
  37. // Current steps within segment
  38. uint8_t segment_steps;
  39. // Segment delta
  40. xyze_uint8_t sd;
  41. // Block delta
  42. xyze_int_t bd;
  43. };
  44. template<typename Cfg>
  45. class SerialPageManager {
  46. public:
  47. typedef typename Cfg::page_idx_t page_idx_t;
  48. static bool maybe_store_rxd_char(uint8_t c);
  49. static void write_responses();
  50. // common methods for page managers
  51. static void init();
  52. static uint8_t *get_page(const page_idx_t page_idx);
  53. static void free_page(const page_idx_t page_idx);
  54. protected:
  55. typedef typename Cfg::write_byte_idx_t write_byte_idx_t;
  56. static State state;
  57. static volatile bool fatal_error;
  58. static volatile PageState page_states[Cfg::PAGE_COUNT];
  59. static volatile bool page_states_dirty;
  60. static uint8_t pages[Cfg::PAGE_COUNT][Cfg::PAGE_SIZE];
  61. static uint8_t checksum;
  62. static write_byte_idx_t write_byte_idx;
  63. static page_idx_t write_page_idx;
  64. static write_byte_idx_t write_page_size;
  65. static void set_page_state(const page_idx_t page_idx, const PageState page_state);
  66. };
  67. template<bool b, typename T, typename F> struct TypeSelector { typedef T type;} ;
  68. template<typename T, typename F> struct TypeSelector<false, T, F> { typedef F type; };
  69. template <int num_pages, int num_axes, int bits_segment, bool dir, int segments>
  70. struct config_t {
  71. static constexpr char CONTROL_CHAR = '!';
  72. static constexpr int PAGE_COUNT = num_pages;
  73. static constexpr int AXIS_COUNT = num_axes;
  74. static constexpr int BITS_SEGMENT = bits_segment;
  75. static constexpr int DIRECTIONAL = dir ? 1 : 0;
  76. static constexpr int SEGMENTS = segments;
  77. static constexpr int NUM_SEGMENTS = _BV(BITS_SEGMENT);
  78. static constexpr int SEGMENT_STEPS = _BV(BITS_SEGMENT - DIRECTIONAL) - 1;
  79. static constexpr int TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS;
  80. static constexpr int PAGE_SIZE = (AXIS_COUNT * BITS_SEGMENT * SEGMENTS) / 8;
  81. typedef typename TypeSelector<(PAGE_SIZE>256), uint16_t, uint8_t>::type write_byte_idx_t;
  82. typedef typename TypeSelector<(PAGE_COUNT>256), uint16_t, uint8_t>::type page_idx_t;
  83. };
  84. template <uint8_t num_pages>
  85. using SP_4x4D_128 = config_t<num_pages, 4, 4, true, 128>;
  86. template <uint8_t num_pages>
  87. using SP_4x2_256 = config_t<num_pages, 4, 2, false, 256>;
  88. template <uint8_t num_pages>
  89. using SP_4x1_512 = config_t<num_pages, 4, 1, false, 512>;
  90. // configured types
  91. typedef STEPPER_PAGE_FORMAT<STEPPER_PAGES> Config;
  92. template class PAGE_MANAGER<Config>;
  93. typedef PAGE_MANAGER<Config> PageManager;
  94. };
  95. #define SP_4x4D_128 1
  96. //#define SP_4x4_128 2
  97. //#define SP_4x2D_256 3
  98. #define SP_4x2_256 4
  99. #define SP_4x1_512 5
  100. typedef typename DirectStepping::Config::page_idx_t page_idx_t;
  101. // TODO: use config
  102. typedef DirectStepping::page_step_state_t page_step_state_t;
  103. extern const uint8_t segment_table[DirectStepping::Config::NUM_SEGMENTS][DirectStepping::Config::SEGMENT_STEPS];
  104. extern DirectStepping::PageManager page_manager;