Add encoder abstraction. (#21548)
This commit is contained in:
parent
2eb9ff8efd
commit
9d9cdaaa2d
50 changed files with 863 additions and 653 deletions
|
@ -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