Skip to content

NUM_ENDSTOP_STATES incorrect when Z_MIN_PROBE = Z_MIN - #27190

Merged
thinkyhead merged 3 commits into
MarlinFirmware:bugfix-2.1.xfrom
tombrazier:endstop_count_bug
Jul 13, 2024
Merged

NUM_ENDSTOP_STATES incorrect when Z_MIN_PROBE = Z_MIN#27190
thinkyhead merged 3 commits into
MarlinFirmware:bugfix-2.1.xfrom
tombrazier:endstop_count_bug

Conversation

@tombrazier

Copy link
Copy Markdown
Contributor

Description

When Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN is defined, NUM_ENDSTOP_STATES can end up being incorrect. This is because NUM_ENDSTOP_STATES is assigned the value Z_MIN_PROBE + 1 by the compiler and, in this particular case, Z_MIN_PROBE is an alias for Z_MIN.

An example case is when Z_HOME_DIR == 1, in which case the following asserts should work:

static_assert(X_MIN == 0);
static_assert(Y_MIN == 1);
static_assert(Z_MIN == 2);
static_assert(Z_MAX == 3);
static_assert(NUM_ENDSTOP_STATES == 4);
static_assert(X_ENDSTOP == X_MIN);
static_assert(Y_ENDSTOP == Y_MIN);
static_assert(Z_ENDSTOP == Z_MAX);
static_assert(Z_MIN_PROBE == Z_MIN);

However in this case NUM_ENDSTOP_STATES ends up being Z_MIN_PROBE + 1 == Z_MIN + 1 == 3.

Requirements

N/A

Benefits

This fixes an edge case where endstop_mask_t has an underlying type which is too narrow.

Configurations

configs.zip

Related Issues

@thinkyhead
thinkyhead force-pushed the endstop_count_bug branch from dbe9f13 to 7258958 Compare July 5, 2024 03:09
@thinkyhead
thinkyhead merged commit 57bda2f into MarlinFirmware:bugfix-2.1.x Jul 13, 2024
thinkyhead added a commit to thinkyhead/Marlin that referenced this pull request Oct 27, 2024
EvilGremlin pushed a commit to EvilGremlin/Marlin that referenced this pull request May 15, 2025
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants