diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index da9f3a66c6..b95b0c49e0 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -2526,7 +2526,6 @@ // @section motion // The number of linear moves that can be in the planner at once. -// The value of BLOCK_BUFFER_SIZE must be a power of 2 (e.g., 8, 16, 32) #if ALL(HAS_MEDIA, DIRECT_STEPPING) #define BLOCK_BUFFER_SIZE 8 #elif HAS_MEDIA diff --git a/Marlin/src/feature/max7219.cpp b/Marlin/src/feature/max7219.cpp index 991f3e79db..e27f6eb974 100644 --- a/Marlin/src/feature/max7219.cpp +++ b/Marlin/src/feature/max7219.cpp @@ -706,7 +706,7 @@ void Max7219::idle_tasks() { #ifdef MAX7219_DEBUG_PLANNER_QUEUE static int16_t last_depth = 0; - const int16_t current_depth = (head - tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1) & 0xF; + const int16_t current_depth = BLOCK_MOD(head - tail + (BLOCK_BUFFER_SIZE)) & 0xF; if (current_depth != last_depth) { quantity16(MAX7219_DEBUG_PLANNER_QUEUE, last_depth, current_depth, &row_change_mask); last_depth = current_depth; diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index c45ff6ad1d..238657be7b 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -310,7 +310,11 @@ typedef struct PlannerBlock { #define HAS_POSITION_FLOAT 1 #endif -#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1)) +#if IS_POWER_OF_2(BLOCK_BUFFER_SIZE) + #define BLOCK_MOD(n) ((n)&((BLOCK_BUFFER_SIZE)-1)) +#else + #define BLOCK_MOD(n) ((n)%(BLOCK_BUFFER_SIZE)) +#endif #if ENABLED(LASER_FEATURE) typedef struct { @@ -366,7 +370,7 @@ typedef struct { #endif #if ENABLED(DISABLE_OTHER_EXTRUDERS) - typedef uvalue_t(BLOCK_BUFFER_SIZE * 2) last_move_t; + typedef uvalue_t((BLOCK_BUFFER_SIZE) * 2) last_move_t; #endif #if ENABLED(ARC_SUPPORT) @@ -780,7 +784,7 @@ class Planner { FORCE_INLINE static bool is_full() { return block_buffer_tail == next_block_index(block_buffer_head); } // Get count of movement slots free - FORCE_INLINE static uint8_t moves_free() { return BLOCK_BUFFER_SIZE - 1 - movesplanned(); } + FORCE_INLINE static uint8_t moves_free() { return (BLOCK_BUFFER_SIZE) - 1 - movesplanned(); } /** * Planner::get_next_free_block