Add encoder abstraction. (#21548)
This commit is contained in:
parent
2eb9ff8efd
commit
9d9cdaaa2d
50 changed files with 863 additions and 653 deletions
|
@ -32,3 +32,6 @@
|
|||
|
||||
/* PMW33XX Settings */
|
||||
#define PMW33XX_CS_PIN B0
|
||||
|
||||
/* Custom encoder needs to specify just how many encoders we have */
|
||||
#define NUM_ENCODERS 1
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
["D4", "D2", "E6", "B6", "D7", "C6", "C7", "B7"]
|
||||
]
|
||||
},
|
||||
"features": {
|
||||
"encoder": true
|
||||
},
|
||||
"encoder": {
|
||||
"driver": "custom"
|
||||
},
|
||||
"layouts": {
|
||||
"LAYOUT": {
|
||||
"layout": [
|
||||
|
|
|
@ -66,8 +66,6 @@ uint8_t OptLowPin = OPT_ENC1;
|
|||
bool debug_encoder = false;
|
||||
bool is_drag_scroll = false;
|
||||
|
||||
__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
|
||||
|
||||
bool encoder_update_kb(uint8_t index, bool clockwise) {
|
||||
if (!encoder_update_user(index, clockwise)) {
|
||||
return false;
|
||||
|
@ -83,7 +81,14 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void process_wheel(void) {
|
||||
void encoder_driver_init(void) {
|
||||
setPinInput(OPT_ENC1);
|
||||
setPinInput(OPT_ENC2);
|
||||
|
||||
opt_encoder_init();
|
||||
}
|
||||
|
||||
void encoder_driver_task(void) {
|
||||
// Lovingly ripped from the Ploopy Source
|
||||
|
||||
// If the mouse wheel was just released, do not scroll.
|
||||
|
@ -111,12 +116,10 @@ void process_wheel(void) {
|
|||
int dir = opt_encoder_handler(p1, p2);
|
||||
|
||||
if (dir == 0) return;
|
||||
encoder_update_kb(0, dir > 0);
|
||||
encoder_queue_event(0, dir == 1);
|
||||
}
|
||||
|
||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||
process_wheel();
|
||||
|
||||
if (is_drag_scroll) {
|
||||
mouse_report.h = mouse_report.x;
|
||||
#ifdef PLOOPY_DRAGSCROLL_INVERT
|
||||
|
@ -177,9 +180,6 @@ void keyboard_pre_init_kb(void) {
|
|||
// debug_mouse = true;
|
||||
// debug_encoder = true;
|
||||
|
||||
setPinInput(OPT_ENC1);
|
||||
setPinInput(OPT_ENC2);
|
||||
|
||||
/* Ground all output pins connected to ground. This provides additional
|
||||
* pathways to ground. If you're messing with this, know this: driving ANY
|
||||
* of these pins high will cause a short. On the MCU. Ka-blooey.
|
||||
|
@ -204,8 +204,6 @@ void keyboard_pre_init_kb(void) {
|
|||
|
||||
void pointing_device_init_kb(void) {
|
||||
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
|
||||
// initialize the scroll wheel's optical encoder
|
||||
opt_encoder_init();
|
||||
}
|
||||
|
||||
void eeconfig_init_kb(void) {
|
||||
|
|
|
@ -16,9 +16,6 @@ POINTING_DEVICE_ENABLE = yes
|
|||
POINTING_DEVICE_DRIVER = pmw3360
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||
|
||||
ENCODER_ENABLE := no
|
||||
OPTS_DEF += -DENCODER_ENABLE
|
||||
|
||||
ANALOG_DRIVER_REQUIRED = yes
|
||||
|
||||
SRC += opt_encoder.c
|
||||
|
|
|
@ -31,3 +31,6 @@
|
|||
/* PMW33XX Settings */
|
||||
#define PMW33XX_CS_PIN B0
|
||||
#define POINTING_DEVICE_INVERT_Y
|
||||
|
||||
/* Custom encoder needs to specify just how many encoders we have */
|
||||
#define NUM_ENCODERS 1
|
||||
|
|
|
@ -12,6 +12,12 @@
|
|||
"bootmagic": {
|
||||
"matrix": [0, 3]
|
||||
},
|
||||
"features": {
|
||||
"encoder": true
|
||||
},
|
||||
"encoder": {
|
||||
"driver": "custom"
|
||||
},
|
||||
"layouts": {
|
||||
"LAYOUT": {
|
||||
"layout": [
|
||||
|
|
|
@ -16,9 +16,6 @@ POINTING_DEVICE_ENABLE = yes
|
|||
POINTING_DEVICE_DRIVER = pmw3360
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||
|
||||
ENCODER_ENABLE := no
|
||||
OPTS_DEF += -DENCODER_ENABLE
|
||||
|
||||
ANALOG_DRIVER_REQUIRED = yes
|
||||
|
||||
SRC += opt_encoder.c
|
||||
|
|
|
@ -66,8 +66,6 @@ uint8_t OptLowPin = OPT_ENC1;
|
|||
bool debug_encoder = false;
|
||||
bool is_drag_scroll = false;
|
||||
|
||||
__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
|
||||
|
||||
bool encoder_update_kb(uint8_t index, bool clockwise) {
|
||||
if (!encoder_update_user(index, clockwise)) {
|
||||
return false;
|
||||
|
@ -83,7 +81,15 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void process_wheel(void) {
|
||||
|
||||
void encoder_driver_init(void) {
|
||||
setPinInput(OPT_ENC1);
|
||||
setPinInput(OPT_ENC2);
|
||||
|
||||
opt_encoder_init();
|
||||
}
|
||||
|
||||
void encoder_driver_task(void) {
|
||||
// TODO: Replace this with interrupt driven code, polling is S L O W
|
||||
// Lovingly ripped from the Ploopy Source
|
||||
|
||||
|
@ -112,11 +118,10 @@ void process_wheel(void) {
|
|||
int dir = opt_encoder_handler(p1, p2);
|
||||
|
||||
if (dir == 0) return;
|
||||
encoder_update_kb(0, dir > 0);
|
||||
encoder_queue_event(0, dir == 1);
|
||||
}
|
||||
|
||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||
process_wheel();
|
||||
|
||||
if (is_drag_scroll) {
|
||||
#ifdef PLOOPY_DRAGSCROLL_H_INVERT
|
||||
|
@ -189,9 +194,6 @@ void keyboard_pre_init_kb(void) {
|
|||
// debug_mouse = true;
|
||||
// debug_encoder = true;
|
||||
|
||||
setPinInput(OPT_ENC1);
|
||||
setPinInput(OPT_ENC2);
|
||||
|
||||
/* Ground all output pins connected to ground. This provides additional
|
||||
* pathways to ground. If you're messing with this, know this: driving ANY
|
||||
* of these pins high will cause a short. On the MCU. Ka-blooey.
|
||||
|
@ -216,8 +218,6 @@ void keyboard_pre_init_kb(void) {
|
|||
|
||||
void pointing_device_init_kb(void) {
|
||||
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
|
||||
// initialize the scroll wheel's optical encoder
|
||||
opt_encoder_init();
|
||||
}
|
||||
|
||||
void eeconfig_init_kb(void) {
|
||||
|
|
|
@ -32,3 +32,6 @@
|
|||
#define ADNS5050_CS_PIN B4
|
||||
|
||||
#define POINTING_DEVICE_ROTATION_270
|
||||
|
||||
/* Custom encoder needs to specify just how many encoders we have */
|
||||
#define NUM_ENCODERS 1
|
||||
|
|
|
@ -14,6 +14,12 @@
|
|||
},
|
||||
"processor": "atmega32u4",
|
||||
"bootloader": "atmel-dfu",
|
||||
"features": {
|
||||
"encoder": true
|
||||
},
|
||||
"encoder": {
|
||||
"driver": "custom"
|
||||
},
|
||||
"layouts": {
|
||||
"LAYOUT": {
|
||||
"layout": [
|
||||
|
|
|
@ -13,9 +13,6 @@ POINTING_DEVICE_ENABLE = yes
|
|||
POINTING_DEVICE_DRIVER = adns5050
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||
|
||||
ENCODER_ENABLE := no
|
||||
OPTS_DEF += -DENCODER_ENABLE
|
||||
|
||||
ANALOG_DRIVER_REQUIRED = yes
|
||||
|
||||
SRC += opt_encoder.c
|
||||
|
|
|
@ -74,8 +74,6 @@ uint8_t OptLowPin = OPT_ENC1;
|
|||
bool debug_encoder = false;
|
||||
bool is_drag_scroll = false;
|
||||
|
||||
__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
|
||||
|
||||
bool encoder_update_kb(uint8_t index, bool clockwise) {
|
||||
if (!encoder_update_user(index, clockwise)) {
|
||||
return false;
|
||||
|
@ -91,7 +89,14 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void process_wheel(void) {
|
||||
void encoder_driver_init(void) {
|
||||
setPinInput(OPT_ENC1);
|
||||
setPinInput(OPT_ENC2);
|
||||
|
||||
opt_encoder_init();
|
||||
}
|
||||
|
||||
void encoder_driver_task(void) {
|
||||
uint16_t p1 = adc_read(OPT_ENC1_MUX);
|
||||
uint16_t p2 = adc_read(OPT_ENC2_MUX);
|
||||
|
||||
|
@ -113,21 +118,17 @@ void process_wheel(void) {
|
|||
}
|
||||
|
||||
if (dir == 0) return;
|
||||
encoder_update_kb(0, dir > 0);
|
||||
encoder_queue_event(0, dir == 1);
|
||||
|
||||
lastScroll = timer_read();
|
||||
}
|
||||
|
||||
void pointing_device_init_kb(void) {
|
||||
opt_encoder_init();
|
||||
|
||||
// set the DPI.
|
||||
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
|
||||
}
|
||||
|
||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||
process_wheel();
|
||||
|
||||
if (is_drag_scroll) {
|
||||
mouse_report.h = mouse_report.x;
|
||||
#ifdef PLOOPY_DRAGSCROLL_INVERT
|
||||
|
@ -180,9 +181,6 @@ void keyboard_pre_init_kb(void) {
|
|||
// debug_mouse = true;
|
||||
// debug_encoder = true;
|
||||
|
||||
setPinInput(OPT_ENC1);
|
||||
setPinInput(OPT_ENC2);
|
||||
|
||||
/* Ground all output pins connected to ground. This provides additional
|
||||
* pathways to ground. If you're messing with this, know this: driving ANY
|
||||
* of these pins high will cause a short. On the MCU. Ka-blooey.
|
||||
|
|
|
@ -31,3 +31,6 @@
|
|||
|
||||
/* PMW3360 Settings */
|
||||
#define POINTING_DEVICE_CS_PIN B0
|
||||
|
||||
/* Custom encoder needs to specify just how many encoders we have */
|
||||
#define NUM_ENCODERS 1
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
"mousekey": true,
|
||||
"nkro": true,
|
||||
"pointing_device": true,
|
||||
"encoder": false
|
||||
"encoder": true
|
||||
},
|
||||
"encoder": {
|
||||
"driver": "custom"
|
||||
},
|
||||
"layouts": {
|
||||
"LAYOUT": {
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
# Force encoder to be disabled
|
||||
# But enable the defines for it
|
||||
ENCODER_ENABLE := no
|
||||
OPT_DEFS += -DENCODER_ENABLE
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "trackball_thumb.h"
|
||||
#include "encoder.h"
|
||||
|
||||
#ifndef OPT_DEBOUNCE
|
||||
# define OPT_DEBOUNCE 5 // (ms) Time between scroll events
|
||||
|
@ -57,9 +58,6 @@ uint16_t last_mid_click = 0; // Stops scrollwheel from being read if it was
|
|||
bool debug_encoder = false;
|
||||
bool is_drag_scroll = false;
|
||||
|
||||
// require, since core encoder.c (where is is normally defined isn't present
|
||||
__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
|
||||
|
||||
bool encoder_update_kb(uint8_t index, bool clockwise) {
|
||||
if (!encoder_update_user(index, clockwise)) {
|
||||
return false;
|
||||
|
@ -75,25 +73,25 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void encoder_init(void) { opt_encoder_init(); }
|
||||
void encoder_driver_init(void) { opt_encoder_init(); }
|
||||
|
||||
bool encoder_read(void) {
|
||||
void encoder_driver_task(void) {
|
||||
// Lovingly ripped from the Ploopy Source
|
||||
|
||||
// If the mouse wheel was just released, do not scroll.
|
||||
if (timer_elapsed(last_mid_click) < SCROLL_BUTT_DEBOUNCE) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Limit the number of scrolls per unit time.
|
||||
if (timer_elapsed(last_scroll) < OPT_DEBOUNCE) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't scroll if the middle button is depressed.
|
||||
if (is_scroll_clicked) {
|
||||
#ifndef IGNORE_SCROLL_CLICK
|
||||
return false;
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -104,10 +102,8 @@ bool encoder_read(void) {
|
|||
|
||||
int dir = opt_encoder_handler(p1, p2);
|
||||
|
||||
if (dir == 0) return false;
|
||||
;
|
||||
encoder_update_kb(0, dir == 1);
|
||||
return true;
|
||||
if (dir == 0) return;
|
||||
encoder_queue_event(0, dir == 1);
|
||||
}
|
||||
|
||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
#define OPT_ENC1_MUX 4
|
||||
#define OPT_ENC2_MUX 0
|
||||
|
||||
bool encoder_update_kb(uint8_t index, bool clockwise);
|
||||
bool encoder_update_user(uint8_t index, bool clockwise);
|
||||
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue