24 #include "../inc/MarlinConfig.h"
28 #ifndef __AVR__ // || DUAL_MIXING_EXTRUDER
32 #define COLOR_A_MASK 0x8000
33 #define COLOR_MASK 0x7FFF
37 #define MIXER_ACCU_SIGNED
40 #define COLOR_A_MASK 0x80
41 #define COLOR_MASK 0x7F
46 #ifndef MIXING_VIRTUAL_TOOLS
47 #define MIXING_VIRTUAL_TOOLS 1
55 #if ENABLED(RETRACT_SYNC_MIXING)
56 MIXER_AUTORETRACT_TOOL,
61 #if ENABLED(RETRACT_SYNC_MIXING)
62 #define MAX_VTOOLS 254
64 #define MAX_VTOOLS 255
68 #define MIXER_STEPPER_LOOP(VAR) \
69 for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
71 #define MIXER_BLOCK_FIELD mixer_comp_t b_color[MIXING_STEPPERS]
72 #define MIXER_POPULATE_BLOCK() mixer.populate_block(block->b_color)
73 #define MIXER_STEPPER_SETUP() mixer.stepper_setup(current_block->b_color)
75 #if ENABLED(GRADIENT_MIX)
81 int8_t start_vtool, end_vtool;
83 end_mix[MIXING_STEPPERS];
84 #if ENABLED(GRADIENT_VTOOL)
115 #if ENABLED(GRADIENT_VTOOL)
118 #if DUAL_MIXING_EXTRUDER
119 update_mix_from_vtool();
125 #if ENABLED(GRADIENT_MIX)
126 if (gradient.enabled) {
138 #if DUAL_MIXING_EXTRUDER || ENABLED(GRADIENT_MIX)
142 static inline void copy_mix_to_color(
mixer_comp_t (&tcolor)[MIXING_STEPPERS]) {
146 LIST_N(MIXING_STEPPERS, mix[0], mix[1], mix[2], mix[3], mix[4], mix[5])
152 #ifdef MIXER_NORMALIZER_DEBUG
154 SERIAL_ECHOLIST_N(MIXING_STEPPERS,
int(mix[0]),
int(mix[1]),
int(mix[2]),
int(mix[3]),
int(mix[4]),
int(mix[5]));
156 SERIAL_ECHOLIST_N(MIXING_STEPPERS,
int(tcolor[0]),
int(tcolor[1]),
int(tcolor[2]),
int(tcolor[3]),
int(tcolor[4]),
int(tcolor[5]));
161 static inline void update_mix_from_vtool(
const uint8_t j=selected_vtool) {
167 #ifdef MIXER_NORMALIZER_DEBUG
169 SERIAL_ECHOLIST_N(MIXING_STEPPERS,
int(color[j][0]),
int(color[j][1]),
int(color[j][2]),
int(color[j][3]),
int(color[j][4]),
int(color[j][5]));
171 SERIAL_ECHOLIST_N(MIXING_STEPPERS,
int(mix[0]),
int(mix[1]),
int(mix[2]),
int(mix[3]),
int(mix[4]),
int(mix[5]));
176 #endif // DUAL_MIXING_EXTRUDER || GRADIENT_MIX
178 #if DUAL_MIXING_EXTRUDER
181 static inline void update_vtool_from_mix() {
182 copy_mix_to_color(color[selected_vtool]);
183 #if ENABLED(GRADIENT_MIX)
190 #endif // DUAL_MIXING_EXTRUDER
192 #if ENABLED(GRADIENT_MIX)
194 static gradient_t gradient;
198 static void update_gradient_for_z(
const float z);
199 static void update_gradient_for_planner_z();
200 static inline void gradient_control(
const float z) {
201 if (gradient.enabled) {
202 if (z >= gradient.end_z)
203 T(gradient.end_vtool);
205 update_gradient_for_z(z);
209 static inline void update_mix_from_gradient() {
214 #ifdef MIXER_NORMALIZER_DEBUG
216 SERIAL_ECHOLIST_N(MIXING_STEPPERS,
int(gradient.color[0]),
int(gradient.color[1]),
int(gradient.color[2]),
int(gradient.color[3]),
int(gradient.color[4]),
int(gradient.color[5]));
218 SERIAL_ECHOLIST_N(MIXING_STEPPERS,
int(mix[0]),
int(mix[1]),
int(mix[2]),
int(mix[3]),
int(mix[4]),
int(mix[5]));
224 static void refresh_gradient() {
225 #if ENABLED(GRADIENT_VTOOL)
226 const bool is_grd = (gradient.vtool_index == -1 || selected_vtool == (
uint8_t)gradient.vtool_index);
228 constexpr
bool is_grd =
true;
230 gradient.enabled = is_grd && gradient.start_vtool != gradient.end_vtool && gradient.start_z < gradient.end_z;
231 if (gradient.enabled) {
234 update_mix_from_vtool(gradient.start_vtool);
235 COPY(gradient.start_mix, mix);
236 update_mix_from_vtool(gradient.end_vtool);
237 COPY(gradient.end_mix, mix);
238 update_gradient_for_planner_z();
244 #endif // GRADIENT_MIX
250 if (--runner < 0) runner = MIXING_STEPPERS - 1;
251 accu[runner] += s_color[runner];
253 #ifdef MIXER_ACCU_SIGNED
268 static uint_fast8_t selected_vtool;
272 static int_fast8_t runner;