Skip to content

Commit

Permalink
Simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarc committed Mar 2, 2024
1 parent d698aed commit 50bb700
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
18 changes: 7 additions & 11 deletions quantum/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string.h>
#include "action.h"
#include "encoder.h"
#include "crc.h"
#include "wait.h"

#ifndef ENCODER_MAP_KEY_DELAY
Expand Down Expand Up @@ -93,22 +92,19 @@ void encoder_retrieve_events(encoder_events_t *events) {
memcpy(events, &encoder_events, sizeof(encoder_events));
}

uint8_t encoder_retrieve_events_checksum(void) {
return crc8((uint8_t *)&encoder_events, sizeof(encoder_events));
}

#ifdef SPLIT_KEYBOARD
void encoder_set_tail_index(uint8_t tail_index) {
encoder_events.tail = tail_index;
}

void encoder_handle_slave_events(encoder_events_t *events) {
if (events->tail < MAX_QUEUED_ENCODER_EVENTS && events->head < MAX_QUEUED_ENCODER_EVENTS) {
while (events->tail != events->head) {
encoder_event_t event = events->queue[events->tail];
events->tail = (events->tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
encoder_queue_event(event.index, event.clockwise ? true : false);
}
if (events->tail >= MAX_QUEUED_ENCODER_EVENTS || events->head >= MAX_QUEUED_ENCODER_EVENTS) {
return;
}
while (events->tail != events->head) {
encoder_event_t event = events->queue[events->tail];
events->tail = (events->tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
encoder_queue_event(event.index, event.clockwise ? true : false);
}
}
#endif // SPLIT_KEYBOARD
Expand Down
3 changes: 1 addition & 2 deletions quantum/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ typedef struct encoder_events_t {
} encoder_events_t;

// Get the current queued events
void encoder_retrieve_events(encoder_events_t *events);
uint8_t encoder_retrieve_events_checksum(void);
void encoder_retrieve_events(encoder_events_t *events);

# ifdef SPLIT_KEYBOARD
void encoder_set_tail_index(uint8_t tail_index);
Expand Down
4 changes: 2 additions & 2 deletions quantum/split_common/transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sl

static void encoder_handlers_slave_reset(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) {
uint8_t tail_index = *(uint8_t *)initiator2target_buffer;
encoder_set_tail_index(tail_index);
split_shmem->encoders.checksum = encoder_retrieve_events_checksum();
encoder_set_tail_index(tail_index); // no need to update shmem's tail as `[PUT_ENCODER_TAIL]` has already done so
split_shmem->encoders.checksum = crc8(&split_shmem->encoders.events, sizeof(split_shmem->encoders.events));
}

// clang-format off
Expand Down

0 comments on commit 50bb700

Please sign in to comment.