Browse Source

Apply suggestions from code review

Updated documentation and renamed callbacks as suggested

Co-authored-by: Drashna Jaelre <drashna@live.com>
pull/17321/head
thpoll83 1 year ago
committed by GitHub
parent
commit
9d540fb028
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 17 deletions
  1. +5
    -5
      docs/feature_encoders.md
  2. +2
    -10
      quantum/encoder.c
  3. +2
    -2
      quantum/encoder.h

+ 5
- 5
docs/feature_encoders.md View File

@ -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
}
```


+ 2
- 10
quantum/encoder.c View File

@ -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;


+ 2
- 2
quantum/encoder.h View File

@ -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


Loading…
Cancel
Save