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

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