🧑‍💻 Width/Magnitude-based types (#25458)

This commit is contained in:
Scott Lahteine
2023-03-03 20:44:24 -06:00
committed by GitHub
parent e977232735
commit f0c8c91820
15 changed files with 102 additions and 110 deletions

View File

@@ -34,6 +34,7 @@
#include <WString.h> #include <WString.h>
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#include "../../core/types.h"
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
#ifndef SERIAL_PORT #ifndef SERIAL_PORT
@@ -138,10 +139,6 @@
#define BYTE 0 #define BYTE 0
// Templated type selector
template<bool b, typename T, typename F> struct TypeSelector { typedef T type;} ;
template<typename T, typename F> struct TypeSelector<false, T, F> { typedef F type; };
template<typename Cfg> template<typename Cfg>
class MarlinSerial { class MarlinSerial {
protected: protected:
@@ -164,7 +161,7 @@
static constexpr B_U2Xx<Cfg::PORT> B_U2X = 0; static constexpr B_U2Xx<Cfg::PORT> B_U2X = 0;
// Base size of type on buffer size // Base size of type on buffer size
typedef typename TypeSelector<(Cfg::RX_SIZE>256), uint16_t, uint8_t>::type ring_buffer_pos_t; typedef uvalue_t(Cfg::RX_SIZE - 1) ring_buffer_pos_t;
struct ring_buffer_r { struct ring_buffer_r {
volatile ring_buffer_pos_t head, tail; volatile ring_buffer_pos_t head, tail;

View File

@@ -30,6 +30,7 @@
#include <WString.h> #include <WString.h>
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#include "../../core/types.h"
#include "../../core/serial_hook.h" #include "../../core/serial_hook.h"
// Define constants and variables for buffering incoming serial data. We're // Define constants and variables for buffering incoming serial data. We're
@@ -52,10 +53,6 @@
// #error "TX_BUFFER_SIZE must be 0, a power of 2 greater than 1, and no greater than 256." // #error "TX_BUFFER_SIZE must be 0, a power of 2 greater than 1, and no greater than 256."
//#endif //#endif
// Templated type selector
template<bool b, typename T, typename F> struct TypeSelector { typedef T type;} ;
template<typename T, typename F> struct TypeSelector<false, T, F> { typedef F type; };
// Templated structure wrapper // Templated structure wrapper
template<typename S, unsigned int addr> struct StructWrapper { template<typename S, unsigned int addr> struct StructWrapper {
constexpr StructWrapper(int) {} constexpr StructWrapper(int) {}
@@ -76,7 +73,7 @@ protected:
static constexpr int HWUART_IRQ_ID = IRQ_IDS[Cfg::PORT]; static constexpr int HWUART_IRQ_ID = IRQ_IDS[Cfg::PORT];
// Base size of type on buffer size // Base size of type on buffer size
typedef typename TypeSelector<(Cfg::RX_SIZE>256), uint16_t, uint8_t>::type ring_buffer_pos_t; typedef uvalue_t(Cfg::RX_SIZE - 1) ring_buffer_pos_t;
struct ring_buffer_r { struct ring_buffer_r {
volatile ring_buffer_pos_t head, tail; volatile ring_buffer_pos_t head, tail;

View File

@@ -31,10 +31,8 @@
// //
// typename IF<(MYOPT==12), int, float>::type myvar; // typename IF<(MYOPT==12), int, float>::type myvar;
// //
template <bool, class L, class R> template <bool, class L, class R> struct IF { typedef R type; };
struct IF { typedef R type; }; template <class L, class R> struct IF<true, L, R> { typedef L type; };
template <class L, class R>
struct IF<true, L, R> { typedef L type; };
#define ALL_AXIS_NAMES X, X2, Y, Y2, Z, Z2, Z3, Z4, I, J, K, U, V, W, E0, E1, E2, E3, E4, E5, E6, E7 #define ALL_AXIS_NAMES X, X2, Y, Y2, Z, Z2, Z3, Z4, I, J, K, U, V, W, E0, E1, E2, E3, E4, E5, E6, E7
@@ -86,20 +84,27 @@ struct IF<true, L, R> { typedef L type; };
#define AXIS_COLLISION(L) (AXIS4_NAME == L || AXIS5_NAME == L || AXIS6_NAME == L || AXIS7_NAME == L || AXIS8_NAME == L || AXIS9_NAME == L) #define AXIS_COLLISION(L) (AXIS4_NAME == L || AXIS5_NAME == L || AXIS6_NAME == L || AXIS7_NAME == L || AXIS8_NAME == L || AXIS9_NAME == L)
// Define types based on largest bit width stored value required
#define bits_t(W) typename IF<((W)> 16), uint32_t, typename IF<((W)> 8), uint16_t, uint8_t>::type>::type
#define uvalue_t(V) typename IF<((V)>65535), uint32_t, typename IF<((V)>255), uint16_t, uint8_t>::type>::type
#define value_t(V) typename IF<((V)>32767), int32_t, typename IF<((V)>127), int16_t, int8_t>::type>::type
// General Flags for some number of states // General Flags for some number of states
template<size_t N> template<size_t N>
struct Flags { struct Flags {
typedef typename IF<(N>8), uint16_t, uint8_t>::type bits_t; typedef value_t(N) flagbits_t;
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1; } N8; typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1; } N8;
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1, b8:1, b9:1, b10:1, b11:1, b12:1, b13:1, b14:1, b15:1; } N16; typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1, b8:1, b9:1, b10:1, b11:1, b12:1, b13:1, b14:1, b15:1; } N16;
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1, b8:1, b9:1, b10:1, b11:1, b12:1, b13:1, b14:1, b15:1,
b16:1, b17:1, b18:1, b19:1, b20:1, b21:1, b22:1, b23:1, b24:1, b25:1, b26:1, b27:1, b28:1, b29:1, b30:1, b31:1; } N32;
union { union {
bits_t b; flagbits_t b;
typename IF<(N>8), N16, N8>::type flag; typename IF<(N>16), N32, typename IF<(N>8), N16, N8>::type>::type flag;
}; };
void reset() { b = 0; } void reset() { b = 0; }
void set(const int n, const bool onoff) { onoff ? set(n) : clear(n); } void set(const int n, const bool onoff) { onoff ? set(n) : clear(n); }
void set(const int n) { b |= (bits_t)_BV(n); } void set(const int n) { b |= (flagbits_t)_BV(n); }
void clear(const int n) { b &= ~(bits_t)_BV(n); } void clear(const int n) { b &= ~(flagbits_t)_BV(n); }
bool test(const int n) const { return TEST(b, n); } bool test(const int n) const { return TEST(b, n); }
bool operator[](const int n) { return test(n); } bool operator[](const int n) { return test(n); }
bool operator[](const int n) const { return test(n); } bool operator[](const int n) const { return test(n); }
@@ -182,7 +187,7 @@ enum AxisEnum : uint8_t {
, ALL_AXES_ENUM = 0xFE, NO_AXIS_ENUM = 0xFF , ALL_AXES_ENUM = 0xFE, NO_AXIS_ENUM = 0xFF
}; };
typedef IF<(NUM_AXIS_ENUMS > 8), uint16_t, uint8_t>::type axis_bits_t; typedef bits_t(NUM_AXIS_ENUMS) axis_bits_t;
// //
// Loop over axes // Loop over axes

View File

@@ -38,12 +38,12 @@ void safe_delay(millis_t ms); // Delay ensuring that temperatures are
// 16x16 bit arrays // 16x16 bit arrays
template <int W, int H> template <int W, int H>
struct FlagBits { struct FlagBits {
typename IF<(W>8), uint16_t, uint8_t>::type bits[H]; bits_t(W) flags[H];
void fill() { memset(bits, 0xFF, sizeof(bits)); } void fill() { memset(flags, 0xFF, sizeof(flags)); }
void reset() { memset(bits, 0x00, sizeof(bits)); } void reset() { memset(flags, 0x00, sizeof(flags)); }
void unmark(const uint8_t x, const uint8_t y) { CBI(bits[y], x); } void unmark(const uint8_t x, const uint8_t y) { CBI(flags[y], x); }
void mark(const uint8_t x, const uint8_t y) { SBI(bits[y], x); } void mark(const uint8_t x, const uint8_t y) { SBI(flags[y], x); }
bool marked(const uint8_t x, const uint8_t y) { return TEST(bits[y], x); } bool marked(const uint8_t x, const uint8_t y) { return TEST(flags[y], x); }
inline void unmark(const xy_int8_t &xy) { unmark(xy.x, xy.y); } inline void unmark(const xy_int8_t &xy) { unmark(xy.x, xy.y); }
inline void mark(const xy_int8_t &xy) { mark(xy.x, xy.y); } inline void mark(const xy_int8_t &xy) { mark(xy.x, xy.y); }
inline bool marked(const xy_int8_t &xy) { return marked(xy.x, xy.y); } inline bool marked(const xy_int8_t &xy) { return marked(xy.x, xy.y); }

View File

@@ -80,9 +80,6 @@ namespace DirectStepping {
static void set_page_state(const page_idx_t page_idx, const PageState page_state); static void set_page_state(const page_idx_t page_idx, const PageState page_state);
}; };
template<bool b, typename T, typename F> struct TypeSelector { typedef T type;} ;
template<typename T, typename F> struct TypeSelector<false, T, F> { typedef F type; };
template <int num_pages, int num_axes, int bits_segment, bool dir, int segments> template <int num_pages, int num_axes, int bits_segment, bool dir, int segments>
struct config_t { struct config_t {
static constexpr char CONTROL_CHAR = '!'; static constexpr char CONTROL_CHAR = '!';
@@ -98,8 +95,8 @@ namespace DirectStepping {
static constexpr int TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS; static constexpr int TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS;
static constexpr int PAGE_SIZE = (AXIS_COUNT * BITS_SEGMENT * SEGMENTS) / 8; static constexpr int PAGE_SIZE = (AXIS_COUNT * BITS_SEGMENT * SEGMENTS) / 8;
typedef typename TypeSelector<(PAGE_SIZE>256), uint16_t, uint8_t>::type write_byte_idx_t; typedef uvalue_t(PAGE_SIZE - 1) write_byte_idx_t;
typedef typename TypeSelector<(PAGE_COUNT>256), uint16_t, uint8_t>::type page_idx_t; typedef uvalue_t(PAGE_COUNT - 1) page_idx_t;
}; };
template <uint8_t num_pages> template <uint8_t num_pages>

View File

@@ -66,7 +66,7 @@
// Types // Types
// ------------------------ // ------------------------
typedef IF<(TERN0(NEOPIXEL_LED, NEOPIXEL_PIXELS > 127)), int16_t, int8_t>::type pixel_index_t; typedef value_t(TERN0(NEOPIXEL_LED, NEOPIXEL_PIXELS)) pixel_index_t;
// ------------------------ // ------------------------
// Classes // Classes

View File

@@ -471,7 +471,7 @@ void Max7219::register_setup() {
constexpr millis_t pattern_delay = 4; constexpr millis_t pattern_delay = 4;
int8_t spiralx, spiraly, spiral_dir; int8_t spiralx, spiraly, spiral_dir;
IF<(MAX7219_LEDS > 255), uint16_t, uint8_t>::type spiral_count; uvalue_t(MAX7219_LEDS) spiral_count;
void Max7219::test_pattern() { void Max7219::test_pattern() {
constexpr int8_t way[][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } }; constexpr int8_t way[][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };

View File

@@ -57,7 +57,7 @@
#endif #endif
#endif #endif
typedef IF<(SPEED_POWER_MAX > 255), uint16_t, uint8_t>::type cutter_cpower_t; typedef uvalue_t(SPEED_POWER_MAX) cutter_cpower_t;
#if CUTTER_UNIT_IS(RPM) && SPEED_POWER_MAX > 255 #if CUTTER_UNIT_IS(RPM) && SPEED_POWER_MAX > 255
typedef uint16_t cutter_power_t; typedef uint16_t cutter_power_t;

View File

@@ -96,9 +96,10 @@
DRAWBIT_HOTEND, DRAWBIT_HOTEND,
DRAWBIT_BED = HOTENDS, DRAWBIT_BED = HOTENDS,
DRAWBIT_CHAMBER, DRAWBIT_CHAMBER,
DRAWBIT_CUTTER DRAWBIT_CUTTER,
DRAWBIT_COUNT
}; };
IF<(DRAWBIT_CUTTER > 7), uint16_t, uint8_t>::type draw_bits; bits_t(DRAWBIT_COUNT) draw_bits;
#endif #endif
#if ANIM_HOTEND #if ANIM_HOTEND

View File

@@ -368,8 +368,8 @@ void DGUSScreenHandlerMKS::EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr) {
} }
void DGUSScreenHandlerMKS::Z_offset_select(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::Z_offset_select(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t z_value = BE16_P(val_ptr); const uint16_t z = BE16_P(val_ptr);
switch (z_value) { switch (z) {
case 0: Z_distance = 0.01; break; case 0: Z_distance = 0.01; break;
case 1: Z_distance = 0.1; break; case 1: Z_distance = 0.1; break;
case 2: Z_distance = 0.5; break; case 2: Z_distance = 0.5; break;
@@ -477,7 +477,7 @@ void DGUSScreenHandlerMKS::MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *
void DGUSScreenHandlerMKS::MeshLevel(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::MeshLevel(DGUS_VP_Variable &var, void *val_ptr) {
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(MESH_BED_LEVELING)
const uint16_t mesh_value = BE16_P(val_ptr); const uint16_t mesh_val = BE16_P(val_ptr);
// static uint8_t a_first_level = 1; // static uint8_t a_first_level = 1;
char cmd_buf[30]; char cmd_buf[30];
float offset = mesh_adj_distance; float offset = mesh_adj_distance;
@@ -485,7 +485,7 @@ void DGUSScreenHandlerMKS::MeshLevel(DGUS_VP_Variable &var, void *val_ptr) {
if (!queue.ring_buffer.empty()) return; if (!queue.ring_buffer.empty()) return;
switch (mesh_value) { switch (mesh_val) {
case 0: case 0:
offset = mesh_adj_distance; offset = mesh_adj_distance;
integer = offset; // get int integer = offset; // get int
@@ -575,20 +575,19 @@ void DGUSScreenHandlerMKS::SD_FileBack(DGUS_VP_Variable&, void*) {
} }
void DGUSScreenHandlerMKS::LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t lcd_val = BE16_P(val_ptr);
const uint16_t lcd_value = BE16_P(val_ptr); lcd_default_light = constrain(lcd_val, 10, 100);
lcd_default_light = constrain(lcd_value, 10, 100);
const uint16_t lcd_data[2] = { lcd_default_light, lcd_default_light }; const uint16_t lcd_data[2] = { lcd_default_light, lcd_default_light };
dgusdisplay.WriteVariable(0x0082, &lcd_data, 5, true); dgusdisplay.WriteVariable(0x0082, &lcd_data, 5, true);
} }
void DGUSScreenHandlerMKS::ManualAssistLeveling(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::ManualAssistLeveling(DGUS_VP_Variable &var, void *val_ptr) {
const int16_t point_value = BE16_P(val_ptr); const int16_t point_val = BE16_P(val_ptr);
// Insist on leveling first time at this screen // Insist on leveling first time at this screen
static bool first_level_flag = false; static bool first_level_flag = false;
if (!first_level_flag || point_value == 0x0001) { if (!first_level_flag || point_val == 0x0001) {
queue.enqueue_now_P(G28_STR); queue.enqueue_now_P(G28_STR);
first_level_flag = true; first_level_flag = true;
} }
@@ -601,10 +600,10 @@ void DGUSScreenHandlerMKS::ManualAssistLeveling(DGUS_VP_Variable &var, void *val
queue.enqueue_one_now(buf_level); queue.enqueue_one_now(buf_level);
}; };
if (WITHIN(point_value, 0x0001, 0x0005)) if (WITHIN(point_val, 0x0001, 0x0005))
queue.enqueue_now(F("G1Z10")); queue.enqueue_now(F("G1Z10"));
switch (point_value) { switch (point_val) {
case 0x0001: case 0x0001:
enqueue_corner_move(X_MIN_POS + ABS(mks_corner_offsets[0].x), enqueue_corner_move(X_MIN_POS + ABS(mks_corner_offsets[0].x),
Y_MIN_POS + ABS(mks_corner_offsets[0].y), level_speed); Y_MIN_POS + ABS(mks_corner_offsets[0].y), level_speed);
@@ -628,7 +627,7 @@ void DGUSScreenHandlerMKS::ManualAssistLeveling(DGUS_VP_Variable &var, void *val
break; break;
} }
if (WITHIN(point_value, 0x0002, 0x0005)) { if (WITHIN(point_val, 0x0002, 0x0005)) {
//queue.enqueue_now(F("G28Z")); //queue.enqueue_now(F("G28Z"));
queue.enqueue_now(F("G1Z-10")); queue.enqueue_now(F("G1Z-10"));
} }
@@ -638,14 +637,14 @@ void DGUSScreenHandlerMKS::ManualAssistLeveling(DGUS_VP_Variable &var, void *val
#define mks_max(a, b) ((a) > (b)) ? (a) : (b) #define mks_max(a, b) ((a) > (b)) ? (a) : (b)
void DGUSScreenHandlerMKS::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr) {
#if EITHER(HAS_TRINAMIC_CONFIG, HAS_STEALTHCHOP) #if EITHER(HAS_TRINAMIC_CONFIG, HAS_STEALTHCHOP)
const uint16_t tmc_value = BE16_P(val_ptr); const uint16_t tmc_val = BE16_P(val_ptr);
#endif #endif
switch (var.VP) { switch (var.VP) {
case VP_TMC_X_STEP: case VP_TMC_X_STEP:
#if USE_SENSORLESS #if USE_SENSORLESS
#if X_HAS_STEALTHCHOP #if X_HAS_STEALTHCHOP
stepperX.homing_threshold(mks_min(tmc_value, 255)); stepperX.homing_threshold(mks_min(tmc_val, 255));
settings.save(); settings.save();
//tmc_step.x = stepperX.homing_threshold(); //tmc_step.x = stepperX.homing_threshold();
#endif #endif
@@ -654,7 +653,7 @@ void DGUSScreenHandlerMKS::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr
case VP_TMC_Y_STEP: case VP_TMC_Y_STEP:
#if USE_SENSORLESS #if USE_SENSORLESS
#if Y_HAS_STEALTHCHOP #if Y_HAS_STEALTHCHOP
stepperY.homing_threshold(mks_min(tmc_value, 255)); stepperY.homing_threshold(mks_min(tmc_val, 255));
settings.save(); settings.save();
//tmc_step.y = stepperY.homing_threshold(); //tmc_step.y = stepperY.homing_threshold();
#endif #endif
@@ -663,7 +662,7 @@ void DGUSScreenHandlerMKS::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr
case VP_TMC_Z_STEP: case VP_TMC_Z_STEP:
#if USE_SENSORLESS #if USE_SENSORLESS
#if Z_HAS_STEALTHCHOP #if Z_HAS_STEALTHCHOP
stepperZ.homing_threshold(mks_min(tmc_value, 255)); stepperZ.homing_threshold(mks_min(tmc_val, 255));
settings.save(); settings.save();
//tmc_step.z = stepperZ.homing_threshold(); //tmc_step.z = stepperZ.homing_threshold();
#endif #endif
@@ -671,49 +670,49 @@ void DGUSScreenHandlerMKS::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr
break; break;
case VP_TMC_X_Current: case VP_TMC_X_Current:
#if AXIS_IS_TMC(X) #if AXIS_IS_TMC(X)
stepperX.rms_current(tmc_value); stepperX.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
case VP_TMC_X1_Current: case VP_TMC_X1_Current:
#if AXIS_IS_TMC(X2) #if AXIS_IS_TMC(X2)
stepperX2.rms_current(tmc_value); stepperX2.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
case VP_TMC_Y_Current: case VP_TMC_Y_Current:
#if AXIS_IS_TMC(Y) #if AXIS_IS_TMC(Y)
stepperY.rms_current(tmc_value); stepperY.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
case VP_TMC_Y1_Current: case VP_TMC_Y1_Current:
#if AXIS_IS_TMC(X2) #if AXIS_IS_TMC(X2)
stepperY2.rms_current(tmc_value); stepperY2.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
case VP_TMC_Z_Current: case VP_TMC_Z_Current:
#if AXIS_IS_TMC(Z) #if AXIS_IS_TMC(Z)
stepperZ.rms_current(tmc_value); stepperZ.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
case VP_TMC_Z1_Current: case VP_TMC_Z1_Current:
#if AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(Z2)
stepperZ2.rms_current(tmc_value); stepperZ2.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
case VP_TMC_E0_Current: case VP_TMC_E0_Current:
#if AXIS_IS_TMC(E0) #if AXIS_IS_TMC(E0)
stepperE0.rms_current(tmc_value); stepperE0.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
case VP_TMC_E1_Current: case VP_TMC_E1_Current:
#if AXIS_IS_TMC(E1) #if AXIS_IS_TMC(E1)
stepperE1.rms_current(tmc_value); stepperE1.rms_current(tmc_val);
settings.save(); settings.save();
#endif #endif
break; break;
@@ -849,29 +848,29 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
} }
void DGUSScreenHandlerMKS::GetParkPos(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::GetParkPos(DGUS_VP_Variable &var, void *val_ptr) {
const int16_t value_pos = BE16_P(val_ptr); const int16_t pos = BE16_P(val_ptr);
switch (var.VP) { switch (var.VP) {
case VP_X_PARK_POS: mks_park_pos.x = value_pos; break; case VP_X_PARK_POS: mks_park_pos.x = pos; break;
case VP_Y_PARK_POS: mks_park_pos.y = value_pos; break; case VP_Y_PARK_POS: mks_park_pos.y = pos; break;
case VP_Z_PARK_POS: mks_park_pos.z = value_pos; break; case VP_Z_PARK_POS: mks_park_pos.z = pos; break;
default: break; default: break;
} }
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }
void DGUSScreenHandlerMKS::HandleChangeLevelPoint(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleChangeLevelPoint(DGUS_VP_Variable &var, void *val_ptr) {
const int16_t value_raw = BE16_P(val_ptr); const int16_t raw = BE16_P(val_ptr);
*(int16_t*)var.memadr = value_raw; *(int16_t*)var.memadr = raw;
settings.save(); settings.save();
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }
void DGUSScreenHandlerMKS::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_raw = BE16_P(val_ptr); const uint16_t raw = BE16_P(val_ptr);
const float value = (float)value_raw; const float value = (float)raw;
ExtUI::axis_t axis; ExtUI::axis_t axis;
switch (var.VP) { switch (var.VP) {
@@ -886,8 +885,8 @@ void DGUSScreenHandlerMKS::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *v
} }
void DGUSScreenHandlerMKS::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_raw = BE16_P(val_ptr); const uint16_t raw = BE16_P(val_ptr);
const float value = (float)value_raw; const float value = (float)raw;
ExtUI::extruder_t extruder; ExtUI::extruder_t extruder;
switch (var.VP) { switch (var.VP) {
@@ -905,8 +904,8 @@ void DGUSScreenHandlerMKS::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var,
} }
void DGUSScreenHandlerMKS::HandleMaxSpeedChange(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleMaxSpeedChange(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_raw = BE16_P(val_ptr); const uint16_t raw = BE16_P(val_ptr);
const float value = (float)value_raw; const float value = (float)raw;
ExtUI::axis_t axis; ExtUI::axis_t axis;
switch (var.VP) { switch (var.VP) {
@@ -921,8 +920,8 @@ void DGUSScreenHandlerMKS::HandleMaxSpeedChange(DGUS_VP_Variable &var, void *val
} }
void DGUSScreenHandlerMKS::HandleExtruderMaxSpeedChange(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleExtruderMaxSpeedChange(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_raw = BE16_P(val_ptr); const uint16_t raw = BE16_P(val_ptr);
const float value = (float)value_raw; const float value = (float)raw;
ExtUI::extruder_t extruder; ExtUI::extruder_t extruder;
switch (var.VP) { switch (var.VP) {
@@ -940,8 +939,8 @@ void DGUSScreenHandlerMKS::HandleExtruderMaxSpeedChange(DGUS_VP_Variable &var, v
} }
void DGUSScreenHandlerMKS::HandleMaxAccChange(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleMaxAccChange(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_raw = BE16_P(val_ptr); const uint16_t raw = BE16_P(val_ptr);
const float value = (float)value_raw; const float value = (float)raw;
ExtUI::axis_t axis; ExtUI::axis_t axis;
switch (var.VP) { switch (var.VP) {
@@ -956,8 +955,8 @@ void DGUSScreenHandlerMKS::HandleMaxAccChange(DGUS_VP_Variable &var, void *val_p
} }
void DGUSScreenHandlerMKS::HandleExtruderAccChange(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleExtruderAccChange(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t value_raw = BE16_P(val_ptr); uint16_t raw = BE16_P(val_ptr);
float value = (float)value_raw; float value = (float)raw;
ExtUI::extruder_t extruder; ExtUI::extruder_t extruder;
switch (var.VP) { switch (var.VP) {
default: return; default: return;
@@ -974,33 +973,33 @@ void DGUSScreenHandlerMKS::HandleExtruderAccChange(DGUS_VP_Variable &var, void *
} }
void DGUSScreenHandlerMKS::HandleTravelAccChange(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleTravelAccChange(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t value_travel = BE16_P(val_ptr); uint16_t travel = BE16_P(val_ptr);
planner.settings.travel_acceleration = (float)value_travel; planner.settings.travel_acceleration = (float)travel;
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }
void DGUSScreenHandlerMKS::HandleFeedRateMinChange(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleFeedRateMinChange(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t value_t = BE16_P(val_ptr); uint16_t t = BE16_P(val_ptr);
planner.settings.min_feedrate_mm_s = (float)value_t; planner.settings.min_feedrate_mm_s = (float)t;
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }
void DGUSScreenHandlerMKS::HandleMin_T_F(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleMin_T_F(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t value_t_f = BE16_P(val_ptr); uint16_t t_f = BE16_P(val_ptr);
planner.settings.min_travel_feedrate_mm_s = (float)value_t_f; planner.settings.min_travel_feedrate_mm_s = (float)t_f;
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }
void DGUSScreenHandlerMKS::HandleAccChange(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleAccChange(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t value_acc = BE16_P(val_ptr); uint16_t acc = BE16_P(val_ptr);
planner.settings.acceleration = (float)value_acc; planner.settings.acceleration = (float)acc;
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }
#if ENABLED(PREVENT_COLD_EXTRUSION) #if ENABLED(PREVENT_COLD_EXTRUSION)
void DGUSScreenHandlerMKS::HandleGetExMinTemp(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::HandleGetExMinTemp(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_ex_min_temp = BE16_P(val_ptr); const uint16_t ex_min_temp = BE16_P(val_ptr);
thermalManager.extrude_min_temp = value_ex_min_temp; thermalManager.extrude_min_temp = ex_min_temp;
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }
#endif #endif
@@ -1080,8 +1079,8 @@ void DGUSScreenHandlerMKS::HandleAccChange(DGUS_VP_Variable &var, void *val_ptr)
#endif // BABYSTEPPING #endif // BABYSTEPPING
void DGUSScreenHandlerMKS::GetManualFilament(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::GetManualFilament(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_len = BE16_P(val_ptr); const uint16_t len = BE16_P(val_ptr);
const float value = (float)value_len; const float value = (float)len;
distanceFilament = value; distanceFilament = value;
@@ -1089,8 +1088,8 @@ void DGUSScreenHandlerMKS::GetManualFilament(DGUS_VP_Variable &var, void *val_pt
} }
void DGUSScreenHandlerMKS::GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandlerMKS::GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ptr) {
const uint16_t value_len = BE16_P(val_ptr); const uint16_t len = BE16_P(val_ptr);
filamentSpeed_mm_s = value_len; filamentSpeed_mm_s = len;
skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
} }

View File

@@ -115,7 +115,7 @@ enum EndstopEnum : char {
class Endstops { class Endstops {
public: public:
typedef IF<(NUM_ENDSTOP_STATES > 8), uint16_t, uint8_t>::type endstop_mask_t; typedef bits_t(NUM_ENDSTOP_STATES) endstop_mask_t;
#if ENABLED(X_DUAL_ENDSTOPS) #if ENABLED(X_DUAL_ENDSTOPS)
static float x2_endstop_adj; static float x2_endstop_adj;

View File

@@ -411,10 +411,10 @@ void restore_feedrate_and_scaling();
/** /**
* Homing and Trusted Axes * Homing and Trusted Axes
*/ */
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type main_axes_bits_t; typedef bits_t(NUM_AXES) main_axes_bits_t;
constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1; constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1;
typedef IF<(NUM_AXES + EXTRUDERS > 8), uint16_t, uint8_t>::type e_axis_bits_t; typedef bits_t(NUM_AXES + EXTRUDERS) e_axis_bits_t;
constexpr e_axis_bits_t e_axis_mask = (_BV(EXTRUDERS) - 1) << NUM_AXES; constexpr e_axis_bits_t e_axis_mask = (_BV(EXTRUDERS) - 1) << NUM_AXES;
void set_axis_is_at_home(const AxisEnum axis); void set_axis_is_at_home(const AxisEnum axis);

View File

@@ -216,7 +216,7 @@ xyze_float_t Planner::previous_speed;
float Planner::previous_nominal_speed; float Planner::previous_nominal_speed;
#if ENABLED(DISABLE_INACTIVE_EXTRUDER) #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
last_move_t Planner::g_uc_extruder_last_move[E_STEPPERS] = { 0 }; last_move_t Planner::extruder_last_move[E_STEPPERS] = { 0 };
#endif #endif
#ifdef XY_FREQUENCY_LIMIT #ifdef XY_FREQUENCY_LIMIT
@@ -2280,7 +2280,7 @@ bool Planner::_populate_block(
// Count down all steppers that were recently moved // Count down all steppers that were recently moved
LOOP_L_N(i, E_STEPPERS) LOOP_L_N(i, E_STEPPERS)
if (g_uc_extruder_last_move[i]) g_uc_extruder_last_move[i]--; if (extruder_last_move[i]) extruder_last_move[i]--;
// Switching Extruder uses one E stepper motor per two nozzles // Switching Extruder uses one E stepper motor per two nozzles
#define E_STEPPER_INDEX(E) TERN(HAS_SWITCHING_EXTRUDER, (E) / 2, E) #define E_STEPPER_INDEX(E) TERN(HAS_SWITCHING_EXTRUDER, (E) / 2, E)
@@ -2291,9 +2291,9 @@ bool Planner::_populate_block(
#define ENABLE_ONE_E(N) do{ \ #define ENABLE_ONE_E(N) do{ \
if (N == E_STEPPER_INDEX(extruder) || _IS_DUPE(N)) { /* N is 'extruder', or N is duplicating */ \ if (N == E_STEPPER_INDEX(extruder) || _IS_DUPE(N)) { /* N is 'extruder', or N is duplicating */ \
stepper.ENABLE_EXTRUDER(N); /* Enable the relevant E stepper... */ \ stepper.ENABLE_EXTRUDER(N); /* Enable the relevant E stepper... */ \
g_uc_extruder_last_move[N] = (BLOCK_BUFFER_SIZE) * 2; /* ...and reset its counter */ \ extruder_last_move[N] = (BLOCK_BUFFER_SIZE) * 2; /* ...and reset its counter */ \
} \ } \
else if (!g_uc_extruder_last_move[N]) /* Counter expired since last E stepper enable */ \ else if (!extruder_last_move[N]) /* Counter expired since last E stepper enable */ \
stepper.DISABLE_EXTRUDER(N); /* Disable the E stepper */ \ stepper.DISABLE_EXTRUDER(N); /* Disable the E stepper */ \
}while(0); }while(0);

View File

@@ -353,7 +353,7 @@ typedef struct {
#endif #endif
#if ENABLED(DISABLE_INACTIVE_EXTRUDER) #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
typedef IF<(BLOCK_BUFFER_SIZE > 64), uint16_t, uint8_t>::type last_move_t; typedef uvalue_t(BLOCK_BUFFER_SIZE * 2) last_move_t;
#endif #endif
#if ENABLED(ARC_SUPPORT) #if ENABLED(ARC_SUPPORT)
@@ -535,7 +535,7 @@ class Planner {
#if ENABLED(DISABLE_INACTIVE_EXTRUDER) #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
// Counters to manage disabling inactive extruder steppers // Counters to manage disabling inactive extruder steppers
static last_move_t g_uc_extruder_last_move[E_STEPPERS]; static last_move_t extruder_last_move[E_STEPPERS];
#endif #endif
#if HAS_WIRED_LCD #if HAS_WIRED_LCD

View File

@@ -263,11 +263,7 @@
#define MIN_STEP_ISR_FREQUENCY (MAX_STEP_ISR_FREQUENCY_1X / 2) #define MIN_STEP_ISR_FREQUENCY (MAX_STEP_ISR_FREQUENCY_1X / 2)
#define ENABLE_COUNT (NUM_AXES + E_STEPPERS) #define ENABLE_COUNT (NUM_AXES + E_STEPPERS)
#if ENABLE_COUNT > 16 typedef bits_t(ENABLE_COUNT) ena_mask_t;
typedef uint32_t ena_mask_t;
#else
typedef IF<(ENABLE_COUNT > 8), uint16_t, uint8_t>::type ena_mask_t;
#endif
// Axis flags type, for enabled state or other simple state // Axis flags type, for enabled state or other simple state
typedef struct { typedef struct {
@@ -358,7 +354,7 @@ constexpr ena_mask_t enable_overlap[] = {
constexpr uint16_t shaping_min_freq = SHAPING_MIN_FREQ, constexpr uint16_t shaping_min_freq = SHAPING_MIN_FREQ,
shaping_echoes = max_step_rate / shaping_min_freq / 2 + 3; shaping_echoes = max_step_rate / shaping_min_freq / 2 + 3;
typedef IF<ENABLED(__AVR__), uint16_t, uint32_t>::type shaping_time_t; typedef hal_timer_t shaping_time_t;
enum shaping_echo_t { ECHO_NONE = 0, ECHO_FWD = 1, ECHO_BWD = 2 }; enum shaping_echo_t { ECHO_NONE = 0, ECHO_FWD = 1, ECHO_BWD = 2 };
struct shaping_echo_axis_t { struct shaping_echo_axis_t {
TERN_(INPUT_SHAPING_X, shaping_echo_t x:2); TERN_(INPUT_SHAPING_X, shaping_echo_t x:2);