Skip to content

Commit ab8af7f

Browse files
committed
🔧 Allow arbitrary BLOCK_BUFFER_SIZE
1 parent fb74cae commit ab8af7f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Marlin/Configuration_adv.h

-1
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,6 @@
25262526
// @section motion
25272527

25282528
// The number of linear moves that can be in the planner at once.
2529-
// The value of BLOCK_BUFFER_SIZE must be a power of 2 (e.g., 8, 16, 32)
25302529
#if ALL(HAS_MEDIA, DIRECT_STEPPING)
25312530
#define BLOCK_BUFFER_SIZE 8
25322531
#elif HAS_MEDIA

Marlin/src/feature/max7219.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ void Max7219::idle_tasks() {
706706

707707
#ifdef MAX7219_DEBUG_PLANNER_QUEUE
708708
static int16_t last_depth = 0;
709-
const int16_t current_depth = (head - tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1) & 0xF;
709+
const int16_t current_depth = BLOCK_MOD(head - tail + (BLOCK_BUFFER_SIZE)) & 0xF;
710710
if (current_depth != last_depth) {
711711
quantity16(MAX7219_DEBUG_PLANNER_QUEUE, last_depth, current_depth, &row_change_mask);
712712
last_depth = current_depth;

Marlin/src/module/planner.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ typedef struct PlannerBlock {
310310
#define HAS_POSITION_FLOAT 1
311311
#endif
312312

313-
#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
313+
#if IS_POWER_OF_2(BLOCK_BUFFER_SIZE)
314+
#define BLOCK_MOD(n) ((n)&((BLOCK_BUFFER_SIZE)-1))
315+
#else
316+
#define BLOCK_MOD(n) ((n)%(BLOCK_BUFFER_SIZE))
317+
#endif
314318

315319
#if ENABLED(LASER_FEATURE)
316320
typedef struct {
@@ -366,7 +370,7 @@ typedef struct {
366370
#endif
367371

368372
#if ENABLED(DISABLE_OTHER_EXTRUDERS)
369-
typedef uvalue_t(BLOCK_BUFFER_SIZE * 2) last_move_t;
373+
typedef uvalue_t((BLOCK_BUFFER_SIZE) * 2) last_move_t;
370374
#endif
371375

372376
#if ENABLED(ARC_SUPPORT)
@@ -780,7 +784,7 @@ class Planner {
780784
FORCE_INLINE static bool is_full() { return block_buffer_tail == next_block_index(block_buffer_head); }
781785

782786
// Get count of movement slots free
783-
FORCE_INLINE static uint8_t moves_free() { return BLOCK_BUFFER_SIZE - 1 - movesplanned(); }
787+
FORCE_INLINE static uint8_t moves_free() { return (BLOCK_BUFFER_SIZE) - 1 - movesplanned(); }
784788

785789
/**
786790
* Planner::get_next_free_block

0 commit comments

Comments
 (0)