From 9d540fb028a8352b724dc03cf9d8bc966ab8372a Mon Sep 17 00:00:00 2001 From: thpoll83 <67008047+thpoll83@users.noreply.github.com> Date: Wed, 15 Jun 2022 08:05:19 +0200 Subject: [PATCH] Apply suggestions from code review Updated documentation and renamed callbacks as suggested Co-authored-by: Drashna Jaelre --- docs/feature_encoders.md | 10 +++++----- quantum/encoder.c | 12 ++---------- quantum/encoder.h | 4 ++-- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md index 44449bd14b6..2acba59abd6 100644 --- a/docs/feature_encoders.md +++ b/docs/feature_encoders.md @@ -158,18 +158,18 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } ``` -Initialization code should be implemented in `encoder_init_state_kb`: +Initialization code should be implemented in `encoder_init_state`: ```c -void encoder_init_state_kb(uint8_t index) { +void encoder_init_state(uint8_t index) { // set up encoder at the required index } -To read an encoder that is not directly connected to an input pin but to another interface, implement `encoder_read_state_kb`: +To read an encoder that is not directly connected to an input pin but to another interface, implement `encoder_read_state`: ```c -uint8_t encoder_read_state_kb(uint8_t index) { - return ... ; // This should return `-1`, `0`, or `1`, to match standard encoder "Gray Code" outputs. +uint8_t encoder_read_state(uint8_t index) { + return ... ; // Set the first two bits as performed by a pin based encoder with A = bit 0 and B = bit 1 } ``` diff --git a/quantum/encoder.c b/quantum/encoder.c index ca487b8c424..ccdbefa8f75 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -79,23 +79,15 @@ __attribute__((weak)) bool encoder_update_kb(uint8_t index, bool clockwise) { return encoder_update_user(index, clockwise); } -__attribute__((weak)) uint8_t encoder_read_state_kb(uint8_t index) { +__attribute__((weak)) uint8_t encoder_read_state(uint8_t index) { return (readPin(encoders_pad_a[index]) << 0) | (readPin(encoders_pad_b[index]) << 1); } -uint8_t encoder_read_state(uint8_t index) { - return encoder_read_state_kb(index); -} - -__attribute__((weak)) void encoder_init_state_kb(uint8_t index) { +__attribute__((weak)) void encoder_init_state(uint8_t index) { setPinInputHigh(encoders_pad_a[index]); setPinInputHigh(encoders_pad_b[index]); } -void encoder_init_state(uint8_t index) { - encoder_init_state_kb(index); -} - void encoder_init(void) { #ifdef SPLIT_KEYBOARD thisHand = isLeftHand ? 0 : NUM_ENCODERS_LEFT; diff --git a/quantum/encoder.h b/quantum/encoder.h index 87ffa74f7d4..a2f3510da6b 100644 --- a/quantum/encoder.h +++ b/quantum/encoder.h @@ -26,8 +26,8 @@ bool encoder_read(void); bool encoder_update_kb(uint8_t index, bool clockwise); bool encoder_update_user(uint8_t index, bool clockwise); -uint8_t encoder_read_state_kb(uint8_t index); -void encoder_init_state_kb(uint8_t index); +uint8_t encoder_read_state(uint8_t index); +void encoder_init_state(uint8_t index); #ifdef SPLIT_KEYBOARD