Rename encoder pins defines (#24003)

This commit is contained in:
Ryan 2024-07-03 17:18:27 +10:00 committed by GitHub
parent 8471dcc563
commit bc0c69570b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 100 additions and 91 deletions

View file

@ -9,15 +9,15 @@ ENCODER_ENABLE = yes
and this to your `config.h`:
```c
#define ENCODERS_PAD_A { B12 }
#define ENCODERS_PAD_B { B13 }
#define ENCODER_A_PINS { B12 }
#define ENCODER_B_PINS { B13 }
```
Each PAD_A/B variable defines an array so multiple encoders can be defined, e.g.:
```c
#define ENCODERS_PAD_A { encoder1a, encoder2a }
#define ENCODERS_PAD_B { encoder1b, encoder2b }
#define ENCODER_A_PINS { encoder1a, encoder2a }
#define ENCODER_B_PINS { encoder1b, encoder2b }
```
If your encoder's clockwise directions are incorrect, you can swap the A & B pad definitions. They can also be flipped with a define:
@ -49,8 +49,8 @@ For 4× encoders you also can assign default position if encoder skips pulses wh
If you are using different pinouts for the encoders on each half of a split keyboard, you can define the pinout (and optionally, resolutions) for the right half like this:
```c
#define ENCODERS_PAD_A_RIGHT { encoder1a, encoder2a }
#define ENCODERS_PAD_B_RIGHT { encoder1b, encoder2b }
#define ENCODER_A_PINS_RIGHT { encoder1a, encoder2a }
#define ENCODER_B_PINS_RIGHT { encoder1b, encoder2b }
#define ENCODER_RESOLUTIONS_RIGHT { 2, 4 }
```
@ -59,11 +59,11 @@ If the `_RIGHT` definitions aren't specified in your `config.h`, then the non-`_
Additionally, if one side does not have an encoder, you can specify `{}` for the pins/resolution -- for example, a split keyboard with only a right-side encoder:
```c
#define ENCODERS_PAD_A { }
#define ENCODERS_PAD_B { }
#define ENCODER_A_PINS { }
#define ENCODER_B_PINS { }
#define ENCODER_RESOLUTIONS { }
#define ENCODERS_PAD_A_RIGHT { B12 }
#define ENCODERS_PAD_B_RIGHT { B13 }
#define ENCODER_A_PINS_RIGHT { B12 }
#define ENCODER_B_PINS_RIGHT { B13 }
#define ENCODER_RESOLUTIONS_RIGHT { 4 }
```
@ -174,13 +174,13 @@ Multiple encoders may share pins so long as each encoder has a distinct pair of
For example you can support two encoders using only 3 pins like this
```
#define ENCODERS_PAD_A { B1, B1 }
#define ENCODERS_PAD_B { B2, B3 }
#define ENCODER_A_PINS { B1, B1 }
#define ENCODER_B_PINS { B2, B3 }
```
You could even support three encoders using only three pins (one per encoder) however in this configuration, rotating two encoders which share pins simultaneously will often generate incorrect output. For example:
```
#define ENCODERS_PAD_A { B1, B1, B2 }
#define ENCODERS_PAD_B { B2, B3, B3 }
#define ENCODER_A_PINS { B1, B1, B2 }
#define ENCODER_B_PINS { B2, B3, B3 }
```
Here rotating Encoder 0 `B1 B2` and Encoder 1 `B1 B3` could be interpreted as rotating Encoder 2 `B2 B3` or `B3 B2` depending on the timing. This may still be a useful configuration depending on your use case

View file

@ -417,8 +417,8 @@ This allows you to specify a different set of pins for the matrix on the right s
This allows you to specify a different set of direct pins for the right side.
```c
#define ENCODERS_PAD_A_RIGHT { encoder1a, encoder2a }
#define ENCODERS_PAD_B_RIGHT { encoder1b, encoder2b }
#define ENCODER_A_PINS_RIGHT { encoder1a, encoder2a }
#define ENCODER_B_PINS_RIGHT { encoder1b, encoder2b }
```
This allows you to specify a different set of encoder pins for the right side.

View file

@ -22,7 +22,7 @@
#endif
#undef ENCODER_DEFAULT_PIN_API_IMPL
#if defined(ENCODERS_PAD_A) && defined(ENCODERS_PAD_B)
#if defined(ENCODER_A_PINS) && defined(ENCODER_B_PINS)
// Inform the quadrature driver that it needs to implement pin init/read functions
# define ENCODER_DEFAULT_PIN_API_IMPL
#endif
@ -34,8 +34,8 @@ __attribute__((weak)) uint8_t encoder_quadrature_read_pin(uint8_t index, bool pa
#ifdef ENCODER_DEFAULT_PIN_API_IMPL
static pin_t encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_A;
static pin_t encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_B;
static pin_t encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE] = ENCODER_A_PINS;
static pin_t encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE] = ENCODER_B_PINS;
__attribute__((weak)) void encoder_wait_pullup_charge(void) {
wait_us(100);
@ -123,25 +123,25 @@ void encoder_driver_init(void) {
// here, but it's the simplest solution.
memset(encoder_state, 0, sizeof(encoder_state));
memset(encoder_pulses, 0, sizeof(encoder_pulses));
const pin_t encoders_pad_a_left[] = ENCODERS_PAD_A;
const pin_t encoders_pad_b_left[] = ENCODERS_PAD_B;
const pin_t encoders_pad_a_left[] = ENCODER_A_PINS;
const pin_t encoders_pad_b_left[] = ENCODER_B_PINS;
for (uint8_t i = 0; i < thisCount; i++) {
encoders_pad_a[i] = encoders_pad_a_left[i];
encoders_pad_b[i] = encoders_pad_b_left[i];
}
#endif
#if defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT)
#if defined(SPLIT_KEYBOARD) && defined(ENCODER_A_PINS_RIGHT) && defined(ENCODER_B_PINS_RIGHT)
// Re-initialise the pads if it's the right-hand side
if (!isLeftHand) {
const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT;
const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT;
const pin_t encoders_pad_a_right[] = ENCODER_A_PINS_RIGHT;
const pin_t encoders_pad_b_right[] = ENCODER_B_PINS_RIGHT;
for (uint8_t i = 0; i < thisCount; i++) {
encoders_pad_a[i] = encoders_pad_a_right[i];
encoders_pad_b[i] = encoders_pad_b_right[i];
}
}
#endif // defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT)
#endif // defined(SPLIT_KEYBOARD) && defined(ENCODER_A_PINS_RIGHT) && defined(ENCODER_B_PINS_RIGHT)
// Encoder resolutions is defined differently in config.h, so concatenate
#if defined(SPLIT_KEYBOARD) && defined(ENCODER_RESOLUTIONS)

View file

@ -15,6 +15,6 @@
*/
#pragma once
#define ENCODERS_PAD_A { B5, B6 }
#define ENCODERS_PAD_B { B4, B2 }
#define ENCODER_A_PINS { B5, B6 }
#define ENCODER_B_PINS { B4, B2 }
#define ENCODER_RESOLUTION 4

View file

@ -15,6 +15,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ENCODERS_PAD_A { F0 }
#define ENCODERS_PAD_B { F1 }
#define ENCODER_A_PINS { F0 }
#define ENCODER_B_PINS { F1 }
#define ENCODER_RESOLUTION 4

View file

@ -16,8 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#define ENCODERS_PAD_A { D5 }
#define ENCODERS_PAD_B { D3 }
#define ENCODER_A_PINS { D5 }
#define ENCODER_B_PINS { D3 }
#define WS2812_DI_PIN D0
#define RGBLIGHT_EFFECT_BREATHING

View file

@ -6,8 +6,8 @@
#ifdef ENCODER_ENABLE // code based on encoder.c
#define ENCODER_PIN_A (((pin_t[])ENCODERS_PAD_A)[0])
#define ENCODER_PIN_B (((pin_t[])ENCODERS_PAD_B)[0])
#define ENCODER_PIN_A (((pin_t[])ENCODER_A_PINS)[0])
#define ENCODER_PIN_B (((pin_t[])ENCODER_B_PINS)[0])
// custom handler that returns encoder B pin status from slave side
void encoder_sync_slave_handler(uint8_t in_buflen, const void *in_data, uint8_t out_buflen, void *out_data) {

View file

@ -38,5 +38,5 @@
/* Custom encoder needs to specify just how many encoders we have */
#define NUM_ENCODERS 1
#define ENCODERS_PAD_A { F0 }
#define ENCODERS_PAD_B { F4 }
#define ENCODER_A_PINS { F0 }
#define ENCODER_B_PINS { F4 }

View file

@ -71,8 +71,8 @@ float scroll_accumulated_v = 0;
#ifdef ENCODER_ENABLE
uint16_t lastScroll = 0; // Previous confirmed wheel event
uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
pin_t encoder_pins_a[1] = ENCODERS_PAD_A;
pin_t encoder_pins_b[1] = ENCODERS_PAD_B;
pin_t encoder_pins_a[1] = ENCODER_A_PINS;
pin_t encoder_pins_b[1] = ENCODER_B_PINS;
bool debug_encoder = false;
bool encoder_update_kb(uint8_t index, bool clockwise) {

View file

@ -38,5 +38,5 @@
/* Custom encoder needs to specify just how many encoders we have */
#define NUM_ENCODERS 1
#define ENCODERS_PAD_A { F0 }
#define ENCODERS_PAD_B { F4 }
#define ENCODER_A_PINS { F0 }
#define ENCODER_B_PINS { F4 }

View file

@ -38,5 +38,5 @@
/* Custom encoder needs to specify just how many encoders we have */
#define NUM_ENCODERS 1
#define ENCODERS_PAD_A { F0 }
#define ENCODERS_PAD_B { F4 }
#define ENCODER_A_PINS { F0 }
#define ENCODER_B_PINS { F4 }

View file

@ -42,5 +42,5 @@
/* Custom encoder needs to specify just how many encoders we have */
#define NUM_ENCODERS 1
#define ENCODERS_PAD_A { F4 }
#define ENCODERS_PAD_B { F0 }
#define ENCODER_A_PINS { F4 }
#define ENCODER_B_PINS { F0 }

View file

@ -201,7 +201,7 @@ const rgb_matrix_f rgb_matrix_functions[6][2] = {
#ifdef ENCODER_ENABLE
static pin_t encoders_pad_a[] = ENCODERS_PAD_A;
static pin_t encoders_pad_a[] = ENCODER_A_PINS;
#define NUMBER_OF_ENCODERS ARRAY_SIZE(encoders_pad_a)
const uint16_t PROGMEM encoders[][NUMBER_OF_ENCODERS * 2][2] = {

View file

@ -49,12 +49,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Encoder support
#ifndef EXTRA_ENCODERS_ENABLE
#define ENCODERS_PAD_A { D2 }
#define ENCODERS_PAD_B { D6 }
#define ENCODER_A_PINS { D2 }
#define ENCODER_B_PINS { D6 }
#else
#ifdef OLED_ENABLE
#error Extra encoders cannot be enabled at the same time as the OLED Driver as they use the same pins.
#endif
#define ENCODERS_PAD_A { D2, D1, B0 }
#define ENCODERS_PAD_B { D6, B1, D0 }
#define ENCODER_A_PINS { D2, D1, B0 }
#define ENCODER_B_PINS { D6, B1, D0 }
#endif

View file

@ -82,8 +82,8 @@ Change pinouts, Pro Micro does not have the "F0" pin.
Set encoder to just top or bottom position.
```
#define ENCODERS_PAD_A { C6 }
#define ENCODERS_PAD_B { D4 }
#define ENCODER_A_PINS { C6 }
#define ENCODER_B_PINS { D4 }
```
## Encoder Setup

View file

@ -135,8 +135,8 @@ def generate_encoder_config(encoder_json, config_h_lines, postfix=''):
b_pads.append(encoder["pin_b"])
resolutions.append(encoder.get("resolution", None))
config_h_lines.append(generate_define(f'ENCODERS_PAD_A{postfix}', f'{{ {", ".join(a_pads)} }}'))
config_h_lines.append(generate_define(f'ENCODERS_PAD_B{postfix}', f'{{ {", ".join(b_pads)} }}'))
config_h_lines.append(generate_define(f'ENCODER_A_PINS{postfix}', f'{{ {", ".join(a_pads)} }}'))
config_h_lines.append(generate_define(f'ENCODER_B_PINS{postfix}', f'{{ {", ".join(b_pads)} }}'))
if None in resolutions:
cli.log.debug(f"Unable to generate ENCODER_RESOLUTION{postfix} configuration")

View file

@ -375,8 +375,8 @@ def _extract_audio(info_data, config_c):
def _extract_encoders_values(config_c, postfix=''):
"""Common encoder extraction logic
"""
a_pad = config_c.get(f'ENCODERS_PAD_A{postfix}', '').replace(' ', '')[1:-1]
b_pad = config_c.get(f'ENCODERS_PAD_B{postfix}', '').replace(' ', '')[1:-1]
a_pad = config_c.get(f'ENCODER_A_PINS{postfix}', '').replace(' ', '')[1:-1]
b_pad = config_c.get(f'ENCODER_B_PINS{postfix}', '').replace(' ', '')[1:-1]
resolutions = config_c.get(f'ENCODER_RESOLUTIONS{postfix}', '').replace(' ', '')[1:-1]
default_resolution = config_c.get('ENCODER_RESOLUTION', None)

View file

@ -22,6 +22,21 @@
#include "gpio.h"
#include "util.h"
// ======== DEPRECATED DEFINES - DO NOT USE ========
#ifdef ENCODERS_PAD_A
# define ENCODER_A_PINS ENCODERS_PAD_A
#endif
#ifdef ENCODERS_PAD_B
# define ENCODER_B_PINS ENCODERS_PAD_B
#endif
#ifdef ENCODERS_PAD_A_RIGHT
# define ENCODER_A_PINS_RIGHT ENCODERS_PAD_A_RIGHT
#endif
#ifdef ENCODERS_PAD_B_RIGHT
# define ENCODER_B_PINS_RIGHT ENCODERS_PAD_B_RIGHT
#endif
// ========
#ifdef ENCODER_ENABLE
__attribute__((weak)) bool should_process_encoder(void);
@ -36,16 +51,16 @@ bool encoder_update_user(uint8_t index, bool clockwise);
# ifdef SPLIT_KEYBOARD
# if defined(ENCODERS_PAD_A_RIGHT)
# if defined(ENCODER_A_PINS_RIGHT)
# ifndef NUM_ENCODERS_LEFT
# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODER_A_PINS))
# endif
# ifndef NUM_ENCODERS_RIGHT
# define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A_RIGHT))
# define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODER_A_PINS_RIGHT))
# endif
# else
# ifndef NUM_ENCODERS_LEFT
# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODER_A_PINS))
# endif
# ifndef NUM_ENCODERS_RIGHT
# define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT
@ -58,19 +73,13 @@ bool encoder_update_user(uint8_t index, bool clockwise);
# else // SPLIT_KEYBOARD
# ifndef NUM_ENCODERS
# define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
# define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODER_A_PINS))
# endif
# define NUM_ENCODERS_LEFT NUM_ENCODERS
# define NUM_ENCODERS_RIGHT 0
# endif // SPLIT_KEYBOARD
# ifndef NUM_ENCODERS
# define NUM_ENCODERS 0
# define NUM_ENCODERS_LEFT 0
# define NUM_ENCODERS_RIGHT 0
# endif // NUM_ENCODERS
# define NUM_ENCODERS_MAX_PER_SIDE MAX(NUM_ENCODERS_LEFT, NUM_ENCODERS_RIGHT)
# ifndef MAX_QUEUED_ENCODER_EVENTS

View file

@ -7,9 +7,9 @@
#define MATRIX_COLS 1
/* Here, "pins" from 0 to 31 are allowed. */
#define ENCODERS_PAD_A \
#define ENCODER_A_PINS \
{ 0 }
#define ENCODERS_PAD_B \
#define ENCODER_B_PINS \
{ 1 }
#ifdef __cplusplus

View file

@ -7,13 +7,13 @@
#define MATRIX_COLS 1
/* Here, "pins" from 0 to 31 are allowed. */
#define ENCODERS_PAD_A \
#define ENCODER_A_PINS \
{ 0, 2 }
#define ENCODERS_PAD_B \
#define ENCODER_B_PINS \
{ 1, 3 }
#define ENCODERS_PAD_A_RIGHT \
#define ENCODER_A_PINS_RIGHT \
{ 4, 6 }
#define ENCODERS_PAD_B_RIGHT \
#define ENCODER_B_PINS_RIGHT \
{ 5, 7 }
#ifdef __cplusplus

View file

@ -7,13 +7,13 @@
#define MATRIX_COLS 1
/* Here, "pins" from 0 to 31 are allowed. */
#define ENCODERS_PAD_A \
#define ENCODER_A_PINS \
{ 0, 2, 4 }
#define ENCODERS_PAD_B \
#define ENCODER_B_PINS \
{ 1, 3, 5 }
#define ENCODERS_PAD_A_RIGHT \
#define ENCODER_A_PINS_RIGHT \
{ 6, 8 }
#define ENCODERS_PAD_B_RIGHT \
#define ENCODER_B_PINS_RIGHT \
{ 7, 9 }
#ifdef __cplusplus

View file

@ -7,13 +7,13 @@
#define MATRIX_COLS 1
/* Here, "pins" from 0 to 31 are allowed. */
#define ENCODERS_PAD_A \
#define ENCODER_A_PINS \
{ 0, 2 }
#define ENCODERS_PAD_B \
#define ENCODER_B_PINS \
{ 1, 3 }
#define ENCODERS_PAD_A_RIGHT \
#define ENCODER_A_PINS_RIGHT \
{ 4, 6, 8 }
#define ENCODERS_PAD_B_RIGHT \
#define ENCODER_B_PINS_RIGHT \
{ 5, 7, 9 }
#ifdef __cplusplus

View file

@ -7,13 +7,13 @@
#define MATRIX_COLS 1
/* Here, "pins" from 0 to 31 are allowed. */
#define ENCODERS_PAD_A \
#define ENCODER_A_PINS \
{}
#define ENCODERS_PAD_B \
#define ENCODER_B_PINS \
{}
#define ENCODERS_PAD_A_RIGHT \
#define ENCODER_A_PINS_RIGHT \
{ 0, 2 }
#define ENCODERS_PAD_B_RIGHT \
#define ENCODER_B_PINS_RIGHT \
{ 1, 3 }
#ifdef __cplusplus

View file

@ -7,13 +7,13 @@
#define MATRIX_COLS 1
/* Here, "pins" from 0 to 31 are allowed. */
#define ENCODERS_PAD_A \
#define ENCODER_A_PINS \
{ 0, 2 }
#define ENCODERS_PAD_B \
#define ENCODER_B_PINS \
{ 1, 3 }
#define ENCODERS_PAD_A_RIGHT \
#define ENCODER_A_PINS_RIGHT \
{}
#define ENCODERS_PAD_B_RIGHT \
#define ENCODER_B_PINS_RIGHT \
{}
#ifdef __cplusplus

View file

@ -7,13 +7,13 @@
#define MATRIX_COLS 1
/* Here, "pins" from 0 to 31 are allowed. */
#define ENCODERS_PAD_A \
#define ENCODER_A_PINS \
{ 0, 2 }
#define ENCODERS_PAD_B \
#define ENCODER_B_PINS \
{ 1, 3 }
#define ENCODERS_PAD_A_RIGHT \
#define ENCODER_A_PINS_RIGHT \
{ 4, 6 }
#define ENCODERS_PAD_B_RIGHT \
#define ENCODER_B_PINS_RIGHT \
{ 5, 7 }
#ifdef __cplusplus