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.

mixing.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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/MarlinConfig.h"
  24. #ifdef __AVR__
  25. #define MIXER_ACCU_SIGNED
  26. typedef uint8_t mixer_color_t;
  27. typedef int8_t mixer_accu_t;
  28. #define COLOR_A_MASK 0x80
  29. #define COLOR_MASK 0x7F
  30. #else
  31. typedef uint_fast16_t mixer_color_t;
  32. typedef uint_fast16_t mixer_accu_t;
  33. #define COLOR_A_MASK 0x8000
  34. #define COLOR_MASK 0x7FFF
  35. #endif
  36. #ifndef MIXING_VIRTUAL_TOOLS
  37. #define MIXING_VIRTUAL_TOOLS 1
  38. #endif
  39. #ifdef RETRACT_SYNC_MIXING
  40. #define NR_MIXING_VIRTUAL_TOOLS (MIXING_VIRTUAL_TOOLS + 1)
  41. #define MIXER_AUTORETRACT_TOOL MIXING_VIRTUAL_TOOLS
  42. #if NR_MIXING_VIRTUAL_TOOLS > 254
  43. #error "MIXING_VIRTUAL_TOOLS must be <= 254!"
  44. #endif
  45. #else
  46. #define NR_MIXING_VIRTUAL_TOOLS (MIXING_VIRTUAL_TOOLS)
  47. #if NR_MIXING_VIRTUAL_TOOLS > 255
  48. #error "MIXING_VIRTUAL_TOOLS must be <= 255!"
  49. #endif
  50. #endif
  51. #define MIXER_STEPPER_LOOP(VAR) \
  52. for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
  53. #define MIXER_BLOCK_DEFINITION mixer_color_t b_color[MIXING_STEPPERS]
  54. #define MIXER_POPULATE_BLOCK() mixer.populate_block(block->b_color)
  55. #define MIXER_STEPPER_SETUP() mixer.stepper_setup(current_block->b_color)
  56. class Mixer {
  57. public:
  58. static void init(void); // Populate colors at boot time
  59. // Used up to Planner level
  60. static void normalize(const uint8_t tool_index);
  61. FORCE_INLINE static uint8_t get_current_v_tool(void) { return selected_v_tool; }
  62. FORCE_INLINE static void T(const uint_fast8_t c) { selected_v_tool = c; }
  63. FORCE_INLINE static void set_M163_collector(const uint8_t c, const float f) { M163_collector[c] = f; }
  64. // Used when dealing with blocks
  65. FORCE_INLINE static void populate_block(mixer_color_t b_color[]) {
  66. uint_fast8_t j = get_current_v_tool();
  67. MIXER_STEPPER_LOOP(i) b_color[i] = color[j][i];
  68. }
  69. FORCE_INLINE static void stepper_setup(mixer_color_t b_color[]) { MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i]; }
  70. // Used in Stepper
  71. FORCE_INLINE static uint8_t get_stepper(void) { return runner; }
  72. FORCE_INLINE static uint8_t get_next_stepper(void) {
  73. do {
  74. if (--runner < 0) runner = MIXING_STEPPERS - 1;
  75. accu[runner] += s_color[runner];
  76. if (
  77. #ifdef MIXER_ACCU_SIGNED
  78. accu[runner] < 0
  79. #else
  80. accu[runner] & COLOR_A_MASK
  81. #endif
  82. ) {
  83. accu[runner] &= COLOR_MASK;
  84. return runner;
  85. }
  86. } while( true );
  87. }
  88. private:
  89. // Used up to Planner level
  90. static uint_fast8_t selected_v_tool;
  91. static float M163_collector[MIXING_STEPPERS];
  92. static mixer_color_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
  93. // Used in Stepper
  94. static int_fast8_t runner;
  95. static mixer_color_t s_color[MIXING_STEPPERS];
  96. static mixer_accu_t accu[MIXING_STEPPERS];
  97. };
  98. extern Mixer mixer;