Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoder breakage with 4 or more encoders #23595

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix encoder_queue_full_advanced() for non-power-of-2 queue sizes
`(events->tail - 1) % MAX_QUEUED_ENCODER_EVENTS` did not calculate what
the rest of code expected when `events->tail` was 0, except when
`MAX_QUEUED_ENCODER_EVENTS` happened to be a power of 2, so the code
seemed to work when the number of encoders was less than 4 (in that case
`MAX_QUEUED_ENCODER_EVENTS` was set to 4), but broke when the number of
encoders was 4 or more.  Fix the queue full check to avoid negative
numbers in calculations.
  • Loading branch information
sigprof committed Apr 23, 2024
commit af6fd646e09539569946dbe8c4130e0415d46f1b
2 changes: 1 addition & 1 deletion quantum/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool encoder_task(void) {
}

bool encoder_queue_full_advanced(encoder_events_t *events) {
return events->head == (events->tail - 1) % MAX_QUEUED_ENCODER_EVENTS;
return events->tail == (events->head + 1) % MAX_QUEUED_ENCODER_EVENTS;
}

bool encoder_queue_full(void) {
Expand Down
Loading