[Keyboard] Overhaul ploopyco devices (#22967)
This commit is contained in:
parent
359cec14fa
commit
68e8d74188
51 changed files with 355 additions and 1909 deletions
|
|
@ -1,5 +1,4 @@
|
|||
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2019 Sunjun Kim
|
||||
* Copyright 2020 Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -15,13 +14,19 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include QMK_KEYBOARD_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = LAYOUT(/* Base */
|
||||
C(KC_C), KC_BTN1, KC_BTN3, LT(1, KC_BTN2), C(KC_V), KC_BTN4, KC_BTN5, DPI_CONFIG),
|
||||
[1] = LAYOUT(/* Base */
|
||||
_______, DRAG_SCROLL, _______, _______, _______, _______, _______, QK_BOOT),
|
||||
#ifndef SCROLLER_AR_SIZE
|
||||
# define SCROLLER_AR_SIZE 31
|
||||
#endif
|
||||
|
||||
};
|
||||
#ifndef SCROLL_THRESH_RANGE_LIM
|
||||
# define SCROLL_THRESH_RANGE_LIM 10
|
||||
#endif
|
||||
|
||||
void opt_encoder_init(void);
|
||||
/* Return the rotation direction, positive value means clockwise, negative value
|
||||
* means counter-clockwise */
|
||||
int8_t opt_encoder_handler(uint16_t curA, uint16_t curB);
|
||||
254
keyboards/ploopyco/common/opt_encoder_default.c
Normal file
254
keyboards/ploopyco/common/opt_encoder_default.c
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2020 Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "opt_encoder.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
enum State { HIHI, HILO, LOLO, LOHI };
|
||||
|
||||
enum State state;
|
||||
|
||||
/* Variables used for scroll wheel functionality. */
|
||||
bool lohif;
|
||||
bool hilof;
|
||||
int lowA;
|
||||
int highA;
|
||||
bool cLowA;
|
||||
bool cHighA;
|
||||
int lowIndexA;
|
||||
int highIndexA;
|
||||
bool lowOverflowA;
|
||||
bool highOverflowA;
|
||||
int lowB;
|
||||
int highB;
|
||||
bool cLowB;
|
||||
bool cHighB;
|
||||
int lowIndexB;
|
||||
int highIndexB;
|
||||
bool lowOverflowB;
|
||||
bool highOverflowB;
|
||||
int scrollThresholdA;
|
||||
int scrollThresholdB;
|
||||
int arLowA[SCROLLER_AR_SIZE];
|
||||
int arHighA[SCROLLER_AR_SIZE];
|
||||
int arLowB[SCROLLER_AR_SIZE];
|
||||
int arHighB[SCROLLER_AR_SIZE];
|
||||
|
||||
void calculateThresholdA(int curA);
|
||||
void calculateThresholdB(int curB);
|
||||
int calculateThreshold(int cur, int* low, int* high, bool* cLow, bool* cHigh, int arLow[], int arHigh[], int* lowIndex, int* highIndex, bool* lowOverflow, bool* highOverflow);
|
||||
int thresholdEquation(int lo, int hi);
|
||||
void incrementIndex(int* index, bool* ovflw);
|
||||
|
||||
/* Setup function for the scroll wheel. Initializes
|
||||
the relevant variables. */
|
||||
void opt_encoder_init(void) {
|
||||
state = HIHI;
|
||||
lohif = false;
|
||||
hilof = false;
|
||||
lowA = 1023;
|
||||
highA = 0;
|
||||
cLowA = false;
|
||||
cHighA = false;
|
||||
lowIndexA = 0;
|
||||
highIndexA = 0;
|
||||
lowOverflowA = false;
|
||||
highOverflowA = false;
|
||||
lowB = 1023;
|
||||
highB = 0;
|
||||
cLowB = false;
|
||||
cHighB = false;
|
||||
lowIndexB = 0;
|
||||
highIndexB = 0;
|
||||
lowOverflowB = false;
|
||||
highOverflowB = false;
|
||||
scrollThresholdA = 0;
|
||||
scrollThresholdB = 0;
|
||||
}
|
||||
|
||||
int8_t opt_encoder_handler(uint16_t curA, uint16_t curB) {
|
||||
if (lowOverflowA == false || highOverflowA == false) calculateThresholdA(curA);
|
||||
if (lowOverflowB == false || highOverflowB == false) calculateThresholdB(curB);
|
||||
|
||||
bool LO = false;
|
||||
bool HI = true;
|
||||
bool sA, sB;
|
||||
int ret = 0;
|
||||
|
||||
if (curA < scrollThresholdA)
|
||||
sA = LO;
|
||||
else
|
||||
sA = HI;
|
||||
|
||||
if (curB < scrollThresholdB)
|
||||
sB = LO;
|
||||
else
|
||||
sB = HI;
|
||||
|
||||
if (state == HIHI) {
|
||||
if (sA == LO && sB == HI) {
|
||||
state = LOHI;
|
||||
if (hilof) {
|
||||
ret = 1;
|
||||
hilof = false;
|
||||
}
|
||||
} else if (sA == HI && sB == LO) {
|
||||
state = HILO;
|
||||
if (lohif) {
|
||||
ret = -1;
|
||||
lohif = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (state == HILO) {
|
||||
if (sA == HI && sB == HI) {
|
||||
state = HIHI;
|
||||
hilof = true;
|
||||
lohif = false;
|
||||
} else if (sA == LO && sB == LO) {
|
||||
state = LOLO;
|
||||
hilof = true;
|
||||
lohif = false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (state == LOLO) {
|
||||
if (sA == HI && sB == LO) {
|
||||
state = HILO;
|
||||
if (lohif) {
|
||||
ret = 1;
|
||||
lohif = false;
|
||||
}
|
||||
} else if (sA == LO && sB == HI) {
|
||||
state = LOHI;
|
||||
if (hilof) {
|
||||
ret = -1;
|
||||
hilof = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else { // state must be LOHI
|
||||
if (sA == HI && sB == HI) {
|
||||
state = HIHI;
|
||||
lohif = true;
|
||||
hilof = false;
|
||||
} else if (sA == LO && sB == LO) {
|
||||
state = LOLO;
|
||||
lohif = true;
|
||||
hilof = false;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void calculateThresholdA(int curA) {
|
||||
scrollThresholdA = calculateThreshold(curA, &lowA, &highA, &cLowA, &cHighA, arLowA, arHighA, &lowIndexA, &highIndexA, &lowOverflowA, &highOverflowA);
|
||||
}
|
||||
|
||||
void calculateThresholdB(int curB) {
|
||||
scrollThresholdB = calculateThreshold(curB, &lowB, &highB, &cLowB, &cHighB, arLowB, arHighB, &lowIndexB, &highIndexB, &lowOverflowB, &highOverflowB);
|
||||
}
|
||||
|
||||
int calculateThreshold(int cur, int* low, int* high, bool* cLow, bool* cHigh, int arLow[], int arHigh[], int* lowIndex, int* highIndex, bool* lowOverflow, bool* highOverflow) {
|
||||
if (cur < *low) *low = cur;
|
||||
if (cur > *high) *high = cur;
|
||||
|
||||
int curThresh = thresholdEquation(*low, *high);
|
||||
int range = *high - *low;
|
||||
|
||||
// The range is enforced to be over a certain limit because noise
|
||||
// can cause erroneous readings, making these calculations unstable.
|
||||
if (range >= SCROLL_THRESH_RANGE_LIM) {
|
||||
if (cur < curThresh) {
|
||||
if (*cHigh == true) {
|
||||
// We were just high, and now we crossed to low.
|
||||
// high reflects a sample of a high reading.
|
||||
arHigh[*highIndex] = *high;
|
||||
incrementIndex(highIndex, highOverflow);
|
||||
int midpoint = ((*high - *low) / 2) + *low;
|
||||
*low = midpoint;
|
||||
*high = midpoint;
|
||||
*cLow = false;
|
||||
*cHigh = false;
|
||||
} else {
|
||||
*cLow = true;
|
||||
}
|
||||
}
|
||||
if (cur > curThresh) {
|
||||
if (*cLow == true) {
|
||||
// We were just low, and now we crossed to high.
|
||||
// low reflects a sample of a low reading.
|
||||
arLow[*lowIndex] = *low;
|
||||
incrementIndex(lowIndex, lowOverflow);
|
||||
int midpoint = ((*high - *low) / 2) + *low;
|
||||
*low = midpoint;
|
||||
*high = midpoint;
|
||||
*cLow = false;
|
||||
*cHigh = false;
|
||||
} else {
|
||||
*cHigh = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int calcHigh = 0;
|
||||
if (*highOverflow == true) {
|
||||
for (int i = 0; i < SCROLLER_AR_SIZE; i++) {
|
||||
calcHigh += arHigh[i];
|
||||
}
|
||||
calcHigh = calcHigh / SCROLLER_AR_SIZE;
|
||||
} else if (*highIndex != 0) {
|
||||
for (int i = 0; i < *highIndex; i++) {
|
||||
calcHigh += arHigh[i];
|
||||
}
|
||||
calcHigh = calcHigh / *highIndex;
|
||||
} else {
|
||||
calcHigh = *high;
|
||||
}
|
||||
|
||||
int calcLow = 0;
|
||||
if (*lowOverflow == true) {
|
||||
for (int i = 0; i < SCROLLER_AR_SIZE; i++) {
|
||||
calcLow += arLow[i];
|
||||
}
|
||||
calcLow = calcLow / SCROLLER_AR_SIZE;
|
||||
} else if (*lowIndex != 0) {
|
||||
for (int i = 0; i < *lowIndex; i++) {
|
||||
calcLow += arLow[i];
|
||||
}
|
||||
calcLow = calcLow / *lowIndex;
|
||||
} else {
|
||||
calcLow = *low;
|
||||
}
|
||||
|
||||
return thresholdEquation(calcLow, calcHigh);
|
||||
}
|
||||
|
||||
int thresholdEquation(int lo, int hi) {
|
||||
return ((hi - lo) / 3) + lo;
|
||||
}
|
||||
|
||||
void incrementIndex(int* index, bool* ovflw) {
|
||||
if (*index < SCROLLER_AR_SIZE - 1)
|
||||
(*index)++;
|
||||
else {
|
||||
*index = 0;
|
||||
*ovflw = true;
|
||||
}
|
||||
}
|
||||
142
keyboards/ploopyco/common/opt_encoder_simple.c
Normal file
142
keyboards/ploopyco/common/opt_encoder_simple.c
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2020 Ploopy Corporation
|
||||
* Copyright 2022 Leorize <leorize+oss@disroot.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "opt_encoder.h"
|
||||
#include "util.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* An alternative implementation for interpreting the encoder status:
|
||||
*
|
||||
* From graphing the phototransistor voltages, the peak and baseline appears to
|
||||
* be rather stable. Therefore there is no need to average them out, and instead
|
||||
* just simply store the min and max voltages of each phototransistor.
|
||||
*
|
||||
* This algorithm then distinguish between high and low states by employing an
|
||||
* approach similar to a Schmitt trigger: a low and high threshold is defined
|
||||
* for each phototransistor based on their min and max voltages.
|
||||
*
|
||||
* Currently, the thresholds are:
|
||||
*
|
||||
* * High threshold: The upper quarter of the voltage range.
|
||||
* * Low threshold: The lower quarter of the voltage range.
|
||||
*
|
||||
* these thresholds are defined for each phototransistor.
|
||||
*
|
||||
* For a state to cross from high -> low, it must fall below the low threshold.
|
||||
* Similarly, to cross from low -> high, the voltage must be higher than the
|
||||
* high threshold.
|
||||
*
|
||||
* Having two distinct thresholds filters out the bulk of noise from the
|
||||
* phototransistors.
|
||||
*
|
||||
* For converting the resulting high and low signals into rotation, a simple
|
||||
* quadrature decoder is used.
|
||||
*/
|
||||
|
||||
/* The minimum value returned by the ADC */
|
||||
#define ENCODER_MIN 0
|
||||
/* The maximum value returned by the ADC */
|
||||
#define ENCODER_MAX 1023
|
||||
|
||||
/* Utilities for composing the encoder state */
|
||||
#define MAKE_STATE(HI_A, HI_B) (((uint8_t)((HI_A) & 0x1) << 1) | ((uint8_t)((HI_B) & 0x1)))
|
||||
#define STATE_A(st) ((st & 0x2) >> 1)
|
||||
#define STATE_B(st) (st & 0x1)
|
||||
#define LOLO MAKE_STATE(0, 0)
|
||||
#define HILO MAKE_STATE(1, 0)
|
||||
#define LOHI MAKE_STATE(0, 1)
|
||||
|
||||
typedef enum {
|
||||
CALIBRATION, /* Recalibrate encoder state by waiting for a 01 -> 00 or 10 -> 00 transistion */
|
||||
DECODE /* Translate changes in the encoder state into movement */
|
||||
} encoder_state_t;
|
||||
|
||||
static encoder_state_t mode;
|
||||
|
||||
static uint8_t lastState;
|
||||
|
||||
static uint16_t lowA;
|
||||
static uint16_t highA;
|
||||
static uint16_t lowB;
|
||||
static uint16_t highB;
|
||||
|
||||
#define MOVE_UP 1
|
||||
#define MOVE_DOWN -1
|
||||
#define MOVE_NONE 0
|
||||
#define MOVE_ERR 0x7F
|
||||
static const uint8_t movement[] = {
|
||||
// 00 -> 00, 01, 10, 11
|
||||
MOVE_NONE, MOVE_DOWN, MOVE_UP, MOVE_ERR,
|
||||
// 01 -> 00, 01, 10, 11
|
||||
MOVE_UP, MOVE_NONE, MOVE_ERR, MOVE_DOWN,
|
||||
// 10 -> 00, 01, 10, 11
|
||||
MOVE_DOWN, MOVE_ERR, MOVE_NONE, MOVE_UP,
|
||||
// 11 -> 00, 01, 10, 11
|
||||
MOVE_ERR, MOVE_UP, MOVE_DOWN, MOVE_NONE};
|
||||
|
||||
void opt_encoder_init(void) {
|
||||
mode = CALIBRATION;
|
||||
lastState = 0;
|
||||
|
||||
lowA = ENCODER_MAX;
|
||||
lowB = ENCODER_MAX;
|
||||
highA = ENCODER_MIN;
|
||||
highB = ENCODER_MIN;
|
||||
}
|
||||
|
||||
int8_t opt_encoder_handler(uint16_t encA, uint16_t encB) {
|
||||
int8_t result = 0;
|
||||
|
||||
highA = MAX(encA, highA);
|
||||
lowA = MIN(encA, lowA);
|
||||
highB = MAX(encB, highB);
|
||||
lowB = MIN(encB, lowB);
|
||||
|
||||
/* Only compute the thresholds after a large enough range is established */
|
||||
if (highA - lowA > SCROLL_THRESH_RANGE_LIM && highB - lowB > SCROLL_THRESH_RANGE_LIM) {
|
||||
const int16_t lowThresholdA = (highA + lowA) / 4;
|
||||
const int16_t highThresholdA = (highA + lowA) - lowThresholdA;
|
||||
const int16_t lowThresholdB = (highB + lowB) / 4;
|
||||
const int16_t highThresholdB = (highB + lowB) - lowThresholdB;
|
||||
|
||||
uint8_t state = MAKE_STATE(STATE_A(lastState) ? encA > lowThresholdA : encA > highThresholdA, STATE_B(lastState) ? encB > lowThresholdB : encB > highThresholdB);
|
||||
|
||||
switch (mode) {
|
||||
case CALIBRATION:
|
||||
if ((lastState == HILO && state == LOLO) || (lastState == LOHI && state == LOLO))
|
||||
mode = DECODE;
|
||||
else
|
||||
mode = CALIBRATION;
|
||||
break;
|
||||
|
||||
case DECODE:
|
||||
result = movement[lastState * 4 + state];
|
||||
/* If we detect a state change that should not be possible,
|
||||
* then the wheel might have moved too fast and we need to
|
||||
* recalibrate the encoder position. */
|
||||
mode = result == MOVE_ERR ? CALIBRATION : mode;
|
||||
result = result == MOVE_ERR ? MOVE_NONE : result;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
116
keyboards/ploopyco/common/opt_encoder_tiny.c
Normal file
116
keyboards/ploopyco/common/opt_encoder_tiny.c
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/* Copyright 2023 Leorize <leorize+oss@disroot.org>
|
||||
* Copyright 2011 Ben Buxton <bb@cactii.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "opt_encoder.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* An extremely simple implementation of the encoder:
|
||||
*
|
||||
* For read out, the mechanism mimics that of a Schmitt trigger, with
|
||||
* statically defined high/low thresholds used instead of computing
|
||||
* one at runtime.
|
||||
*
|
||||
* The advantage of this approach is computing less in the decoder
|
||||
* implementation and allow the state to be measured before the wheel
|
||||
* moved.
|
||||
*
|
||||
* Compared to opt_encoder_simple.c, the use of an intermediary state
|
||||
* reduces sensitivity and de-sensitize against tiny movements caused
|
||||
* when lifting finger off the wheel.
|
||||
*
|
||||
* For turning decoded values into rotation, an algorithm inspired by
|
||||
* http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
|
||||
* is employed.
|
||||
*/
|
||||
|
||||
#if !defined(ENCODER_LOW_THRES_A) || !defined(ENCODER_HIGH_THRES_A)
|
||||
# error "The thresholds for phototransistors A is not defined in config.h"
|
||||
#endif
|
||||
#if !defined(ENCODER_LOW_THRES_B) || !defined(ENCODER_HIGH_THRES_B)
|
||||
# error "The thresholds for phototransistors B is not defined in config.h"
|
||||
#endif
|
||||
/*
|
||||
* Sample values, captured for a Ploopy Mini Trackball
|
||||
*
|
||||
* The following min-max values was captured by aggregating data recorded
|
||||
* when debug_encoder is enabled:
|
||||
*
|
||||
* A: min: 0, max: 214
|
||||
* B: min: 0, max: 204
|
||||
*
|
||||
* The threshold specified is then defined at the 1/4 and the 3/4 points.
|
||||
*
|
||||
* As these values might vary between units, you're encouraged to
|
||||
* measure your own.
|
||||
*/
|
||||
#if 0
|
||||
# define ENCODER_LOW_THRES_A 53
|
||||
# define ENCODER_HIGH_THRES_A 161
|
||||
# define ENCODER_LOW_THRES_B 52
|
||||
# define ENCODER_HIGH_THRES_B 153
|
||||
#endif
|
||||
|
||||
/* Utilities for composing the encoder state */
|
||||
#define MAKE_STATE(HI_A, HI_B) (((uint8_t)((HI_A) & 0x1) << 1) | ((uint8_t)((HI_B) & 0x1)))
|
||||
#define STATE_A(st) ((st & 0x2) >> 1)
|
||||
#define STATE_B(st) (st & 0x1)
|
||||
|
||||
typedef enum {
|
||||
START,
|
||||
DOWN_BEGIN,
|
||||
UP_BEGIN,
|
||||
START_MID,
|
||||
DOWN_BEGIN_MID,
|
||||
UP_BEGIN_MID,
|
||||
STATE_MASK = 0xf, /* 0b1111 */
|
||||
EMIT_UP = 0x10,
|
||||
EMIT_UP_MID = EMIT_UP & START_MID,
|
||||
EMIT_DOWN = 0x80,
|
||||
EMIT_DOWN_MID = EMIT_DOWN & START_MID,
|
||||
EMIT_MASK = 0xf0
|
||||
} encoder_state_t;
|
||||
|
||||
static encoder_state_t state;
|
||||
static uint8_t encState;
|
||||
|
||||
static const uint8_t transitions[] = {
|
||||
// clang-format off
|
||||
// START -> 00, 01, 10, 11
|
||||
START, DOWN_BEGIN, UP_BEGIN, START_MID,
|
||||
// DOWN_BEGIN -> 00, 01, 10, 11
|
||||
START, DOWN_BEGIN, START, EMIT_DOWN_MID,
|
||||
// UP_BEGIN -> 00, 01, 10, 11
|
||||
START, START, UP_BEGIN, EMIT_UP_MID,
|
||||
// START_MID -> 00, 01, 10, 11
|
||||
START, UP_BEGIN_MID, DOWN_BEGIN_MID, START_MID,
|
||||
// DOWN_BEGIN_MID -> 00, 01, 10, 11
|
||||
EMIT_DOWN, START_MID, DOWN_BEGIN_MID, START_MID,
|
||||
// UP_BEGIN_MID -> 00, 01, 10, 11
|
||||
EMIT_UP, UP_BEGIN_MID, START_MID, START_MID,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
void opt_encoder_init(void) {
|
||||
state = START;
|
||||
encState = 0;
|
||||
}
|
||||
|
||||
int8_t opt_encoder_handler(uint16_t encA, uint16_t encB) {
|
||||
encState = MAKE_STATE((STATE_A(encState) & (encA > ENCODER_LOW_THRES_A)) | (encA > ENCODER_HIGH_THRES_A), (STATE_B(encState) & (encB > ENCODER_LOW_THRES_B)) | (encB > ENCODER_HIGH_THRES_B));
|
||||
state = transitions[((state & STATE_MASK) << 2) + encState];
|
||||
return state & EMIT_MASK;
|
||||
}
|
||||
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define UNUSABLE_PINS \
|
||||
{ GP1, GP3, GP4, GP6, GP8, GP10, GP14, GP16, GP18, GP20, GP22, GP24, GP25, GP26, GP27, GP28, GP29 }
|
||||
|
||||
// #define ROTATIONAL_TRANSFORM_ANGLE 0
|
||||
#define POINTING_DEVICE_INVERT_Y
|
||||
|
||||
|
|
@ -26,4 +29,4 @@
|
|||
#define PMW33XX_CS_PIN GP5
|
||||
#define SPI_SCK_PIN GP2
|
||||
#define SPI_MISO_PIN GP0
|
||||
#define SPI_MOSI_PIN GP7
|
||||
#define SPI_MOSI_PIN GP7
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
"extrakey": true,
|
||||
"mousekey": true,
|
||||
"nkro": true,
|
||||
"pointing_device": true,
|
||||
"pointing_device": true
|
||||
},
|
||||
"layouts": {
|
||||
"LAYOUT": {
|
||||
|
|
@ -31,5 +31,5 @@
|
|||
},
|
||||
"dynamic_keymap": {
|
||||
"layer_count": 8
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,176 +0,0 @@
|
|||
/* Copyright 2023 Colin Lam (Ploopy Corporation)
|
||||
* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2019 Sunjun Kim
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "madromys.h"
|
||||
|
||||
#ifndef PLOOPY_DPI_OPTIONS
|
||||
# define PLOOPY_DPI_OPTIONS \
|
||||
{ 600, 900, 1200, 1600 }
|
||||
# ifndef PLOOPY_DPI_DEFAULT
|
||||
# define PLOOPY_DPI_DEFAULT 1
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PLOOPY_DPI_DEFAULT
|
||||
# define PLOOPY_DPI_DEFAULT 0
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_DPI
|
||||
# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_FIXED
|
||||
# define PLOOPY_DRAGSCROLL_FIXED 1
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER
|
||||
# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_SEMAPHORE
|
||||
# define PLOOPY_DRAGSCROLL_SEMAPHORE 4
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_MOMENTARY
|
||||
# define PLOOPY_DRAGSCROLL_MOMENTARY 1
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_INVERT
|
||||
# define PLOOPY_DRAGSCROLL_INVERT 1
|
||||
#endif
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
|
||||
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
|
||||
|
||||
// TODO: Implement libinput profiles
|
||||
// https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html
|
||||
// Compile time accel selection
|
||||
// Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC
|
||||
|
||||
// Trackball State
|
||||
bool is_drag_scroll = false;
|
||||
|
||||
// drag scroll divisor state
|
||||
int8_t drag_scroll_x_semaphore = 0;
|
||||
int8_t drag_scroll_y_semaphore = 0;
|
||||
|
||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||
if (is_drag_scroll) {
|
||||
int16_t mouse_report_x_temp = mouse_report.x;
|
||||
int16_t mouse_report_y_temp = mouse_report.y;
|
||||
int16_t mouse_report_x_calc = 0;
|
||||
int16_t mouse_report_y_calc = 0;
|
||||
int16_t valx = (mouse_report_x_temp > 0) ? -1 : 1;
|
||||
int16_t valy = (mouse_report_y_temp > 0) ? -1 : 1;
|
||||
|
||||
while (mouse_report_x_temp != 0) {
|
||||
mouse_report_x_temp += valx;
|
||||
drag_scroll_x_semaphore -= valx;
|
||||
|
||||
if (abs(drag_scroll_x_semaphore) >= PLOOPY_DRAGSCROLL_SEMAPHORE) {
|
||||
mouse_report_x_calc -= valx;
|
||||
drag_scroll_x_semaphore = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while (mouse_report_y_temp != 0) {
|
||||
mouse_report_y_temp += valy;
|
||||
drag_scroll_y_semaphore -= valy;
|
||||
|
||||
if (abs(drag_scroll_y_semaphore) >= PLOOPY_DRAGSCROLL_SEMAPHORE) {
|
||||
mouse_report_y_calc -= valy;
|
||||
drag_scroll_y_semaphore = 0;
|
||||
}
|
||||
}
|
||||
|
||||
mouse_report.h = mouse_report_x_calc;
|
||||
|
||||
#ifdef PLOOPY_DRAGSCROLL_INVERT
|
||||
// Invert vertical scroll direction
|
||||
mouse_report.v = -mouse_report_y_calc;
|
||||
#else
|
||||
mouse_report.v = mouse_report_y_calc;
|
||||
#endif
|
||||
mouse_report.x = 0;
|
||||
mouse_report.y = 0;
|
||||
}
|
||||
|
||||
return pointing_device_task_user(mouse_report);
|
||||
}
|
||||
|
||||
bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
|
||||
if (!process_record_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == DPI_CONFIG && record->event.pressed) {
|
||||
keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
|
||||
eeconfig_update_kb(keyboard_config.raw);
|
||||
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
|
||||
}
|
||||
|
||||
if (keycode == DRAG_SCROLL) {
|
||||
#ifndef PLOOPY_DRAGSCROLL_MOMENTARY
|
||||
if (record->event.pressed)
|
||||
#endif
|
||||
{
|
||||
is_drag_scroll ^= 1;
|
||||
}
|
||||
#ifdef PLOOPY_DRAGSCROLL_FIXED
|
||||
pointing_device_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]);
|
||||
#else
|
||||
pointing_device_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hardware Setup
|
||||
void keyboard_pre_init_kb(void) {
|
||||
// debug_enable = true;
|
||||
// debug_matrix = true;
|
||||
// debug_mouse = true;
|
||||
// debug_encoder = true;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
const pin_t unused_pins[] = { GP1, GP3, GP4, GP6, GP8, GP10, GP14, GP16,
|
||||
GP18, GP20, GP22, GP24, GP25, GP26, GP27, GP28, GP29 };
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
|
||||
setPinOutput(unused_pins[i]);
|
||||
writePinLow(unused_pins[i]);
|
||||
}
|
||||
|
||||
keyboard_pre_init_user();
|
||||
}
|
||||
|
||||
void pointing_device_init_kb(void) { pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); }
|
||||
|
||||
void eeconfig_init_kb(void) {
|
||||
keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT;
|
||||
eeconfig_update_kb(keyboard_config.raw);
|
||||
eeconfig_init_user();
|
||||
}
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
// is safe to just read DPI setting since matrix init
|
||||
// comes before pointing device init.
|
||||
keyboard_config.raw = eeconfig_read_kb();
|
||||
if (keyboard_config.dpi_config > DPI_OPTION_SIZE) {
|
||||
eeconfig_init_kb();
|
||||
}
|
||||
matrix_init_user();
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/* Copyright 2023 Colin Lam (Ploopy Corporation)
|
||||
* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2019 Sunjun Kim
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
uint8_t dpi_config;
|
||||
};
|
||||
} keyboard_config_t;
|
||||
_Static_assert(sizeof(keyboard_config_t) == sizeof(uint32_t), "keyboard_config_t size mismatch compared to EEPROM area");
|
||||
|
||||
extern keyboard_config_t keyboard_config;
|
||||
extern uint16_t dpi_array[];
|
||||
|
||||
enum ploopy_keycodes {
|
||||
DPI_CONFIG = QK_KB_0,
|
||||
DRAG_SCROLL,
|
||||
};
|
||||
|
|
@ -27,17 +27,6 @@ If you want to upload a new firmware file (a ".uf2" file, like "madromys_awesome
|
|||
|
||||
**TIP**: If your firmware is in some kind of strange state and uploading new firmware isn't fixing it, try uploading [a flash nuke](https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython#flash-resetting-uf2-3083182) to the Madromys board before flashing the new firmware. It wipes the memory of the Madromys board completely clean, which can help clear a few types of errors.
|
||||
|
||||
# Drag Scroll
|
||||
# Customizing your Ploopy Madromys
|
||||
|
||||
Drag Scroll is a custom keycode for Ploopy devices that allows you to hold or tap a button and have the mouse movement translate into scrolling instead.
|
||||
|
||||
Nothing needs to be enabled to use this functionality; it's enabled on Madromys by default.
|
||||
|
||||
### Drag Scroll Configuration
|
||||
|
||||
* `#define PLOOPY_DRAGSCROLL_MOMENTARY` - Makes the key into a momentary key, rather than a toggle.
|
||||
* `#define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75` - Sets the DPI multiplier to use when drag scroll is enabled.
|
||||
* `#define PLOOPY_DRAGSCROLL_FIXED` - Normally, when activating Drag Scroll, it uses a fraction of the current DPI. You can define this to use a specific, set DPI rather than a fraction of the current DPI.
|
||||
* `#define PLOOPY_DRAGSCROLL_DPI 100` - When the fixed DPI option is enabled, this sets the DPI to be used for Drag Scroll.
|
||||
* `#define PLOOPY_DRAGSCROLL_INVERT` - This reverses the direction that the scroll is performed.
|
||||
* `#define PLOOPY_DRAGSCROLL_SEMAPHORE` - This is a divisor on the drag scroll sensitivity. The default is 0, which means that the drag scroll is at maximum sensitivity. A value of 4 would mean that the drag scroll is 4 times less sensitive.
|
||||
You can find customziation options [here](../readme.md).
|
||||
|
|
|
|||
|
|
@ -33,5 +33,10 @@
|
|||
/* PMW33XX Settings */
|
||||
#define PMW33XX_CS_PIN B0
|
||||
|
||||
#define ENCODER_BUTTON_COL 1
|
||||
#define ENCODER_BUTTON_ROW 0
|
||||
/* 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 }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,15 @@
|
|||
"device_version": "0.0.1",
|
||||
"max_power": 100
|
||||
},
|
||||
"features": {
|
||||
"bootmagic": true,
|
||||
"extrakey": true,
|
||||
"mousekey": true,
|
||||
"nkro": false,
|
||||
"pointing_device": true,
|
||||
"rgblight": false,
|
||||
"encoder": true
|
||||
},
|
||||
"bootmagic": {
|
||||
"matrix": [0, 3]
|
||||
},
|
||||
|
|
@ -31,9 +40,6 @@
|
|||
["D4", "D2", "E6", "B6", "D7", "C6", "C7", "B7"]
|
||||
]
|
||||
},
|
||||
"features": {
|
||||
"encoder": true
|
||||
},
|
||||
"encoder": {
|
||||
"driver": "custom"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
# The Drag Scroll keymap for PloopyCo Mouse
|
||||
|
||||
This is a sample keymap showing off what you can do with the custom callback drivers.
|
||||
|
|
@ -19,48 +19,4 @@ See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_to
|
|||
|
||||
# Customizing your PloopyCo Mouse
|
||||
|
||||
While the defaults are designed so that it can be plugged in and used right away, there are a number of things that you may want to change. Such as adding DPI control, or to use the ball to scroll while holding a button. To allow for this sort of control, there is a callback for both the scroll wheel and the mouse sensor.
|
||||
|
||||
The default behavior for this is:
|
||||
|
||||
```c
|
||||
void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
|
||||
mouse_report->h = h;
|
||||
mouse_report->v = v;
|
||||
}
|
||||
|
||||
void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
|
||||
mouse_report->x = x;
|
||||
mouse_report->y = y;
|
||||
}
|
||||
```
|
||||
|
||||
This should allow you to more heavily customize the behavior.
|
||||
|
||||
Alternatively, the `process_wheel` and `process_mouse` functions can both be replaced too, to allow for even more functionality.
|
||||
|
||||
Additionally, you can change the DPI/CPI or speed of the trackball by calling `pointing_device_set_cpi` at any time. Additionally, there is a `DPI_CONFIG` macro that will cycle through an array of options for the DPI. This is set to 1200, 1600, and 2400, but can be changed. 1600 is also set to the default.
|
||||
|
||||
To configure/set your own array, there are two defines to use, `PLOOPY_DPI_OPTIONS` to set the array, and `PLOOPY_DPI_DEFAULT`.
|
||||
|
||||
```c
|
||||
#define PLOOPY_DPI_OPTIONS { 1200, 1600, 2400 }
|
||||
#define PLOOPY_DPI_DEFAULT 1
|
||||
```
|
||||
The `PLOOPY_DPI_OPTIONS` array sets the values that you want to be able to cycle through, and the order they are in. The "default" define lets the firmware know which of these options is the default and should be loaded by default.
|
||||
|
||||
The `DPI_CONFIG` macro will cycle through the values in the array, each time you hit it. And it stores this value in persistent memory, so it will load it the next time the device powers up.
|
||||
|
||||
## Drag Scroll
|
||||
|
||||
Drag Sroll is a custom keycode for the Ploopy devices that allow you to hold or tap a button and have the mouse movement translate into scrolling instead.
|
||||
|
||||
Nothing needs to be enabled to use this functionality. Just add the `DRAG_SCROLL` to your keymap.
|
||||
|
||||
### Drag Scroll Configuration
|
||||
|
||||
* `#define PLOOPY_DRAGSCROLL_MOMENTARY` - Makes the key into a momentary key, rather than a toggle.
|
||||
* `#define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75` - Sets the DPI multiplier to use when drag scroll is enabled.
|
||||
* `#define PLOOPY_DRAGSCROLL_FIXED` - Normally, when activating Drag Scroll, it uses a fraction of the current DPI. You can define this to use a specific, set DPI rather than a fraction of the current DPI.
|
||||
* `#define PLOOPY_DRAGSCROLL_DPI 100` - When the fixed DPI option is enabled, this sets the DPI to be used for Drag Scroll.
|
||||
* `#define PLOOPY_DRAGSCROLL_INVERT` - This reverses the direction that the scroll is performed.
|
||||
You can find customziation options [here](../readme.md).
|
||||
|
|
|
|||
|
|
@ -1,21 +1,4 @@
|
|||
# Processor frequency
|
||||
F_CPU = 8000000
|
||||
|
||||
# Build Options
|
||||
# change yes to no to disable
|
||||
#
|
||||
BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite
|
||||
EXTRAKEY_ENABLE = yes # Audio control and System control
|
||||
CONSOLE_ENABLE = no # Console for debug
|
||||
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||
NKRO_ENABLE = no # Enable N-Key Rollover
|
||||
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
|
||||
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
|
||||
AUDIO_ENABLE = no # Audio output
|
||||
POINTING_DEVICE_ENABLE = yes
|
||||
POINTING_DEVICE_DRIVER = pmw3360
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||
|
||||
ANALOG_DRIVER_REQUIRED = yes
|
||||
|
||||
SRC += opt_encoder.c
|
||||
|
|
|
|||
236
keyboards/ploopyco/ploopyco.c
Normal file
236
keyboards/ploopyco/ploopyco.c
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2019 Sunjun Kim
|
||||
* Copyright 2020 Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ploopyco.h"
|
||||
#include "analog.h"
|
||||
#include "opt_encoder.h"
|
||||
|
||||
// for legacy support
|
||||
#if defined(OPT_DEBOUNCE) && !defined(PLOOPY_SCROLL_DEBOUNCE)
|
||||
# define PLOOPY_SCROLL_DEBOUNCE OPT_DEBOUNCE
|
||||
#endif
|
||||
#if defined(SCROLL_BUTT_DEBOUNCE) && !defined(PLOOPY_SCROLL_BUTTON_DEBOUNCE)
|
||||
# define PLOOPY_SCROLL_BUTTON_DEBOUNCE SCROLL_BUTT_DEBOUNCE
|
||||
#endif
|
||||
|
||||
#ifndef PLOOPY_SCROLL_DEBOUNCE
|
||||
# define PLOOPY_SCROLL_DEBOUNCE 5
|
||||
#endif
|
||||
#ifndef PLOOPY_SCROLL_BUTTON_DEBOUNCE
|
||||
# define PLOOPY_SCROLL_BUTTON_DEBOUNCE 100
|
||||
#endif
|
||||
|
||||
#ifndef PLOOPY_DPI_OPTIONS
|
||||
# define PLOOPY_DPI_OPTIONS \
|
||||
{ 600, 900, 1200, 1600, 2400 }
|
||||
# ifndef PLOOPY_DPI_DEFAULT
|
||||
# define PLOOPY_DPI_DEFAULT 1
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PLOOPY_DPI_DEFAULT
|
||||
# define PLOOPY_DPI_DEFAULT 0
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_DIVISOR_H
|
||||
# define PLOOPY_DRAGSCROLL_DIVISOR_H 8.0
|
||||
#endif
|
||||
#ifndef PLOOPY_DRAGSCROLL_DIVISOR_V
|
||||
# define PLOOPY_DRAGSCROLL_DIVISOR_V 8.0
|
||||
#endif
|
||||
#ifndef ENCODER_BUTTON_ROW
|
||||
# define ENCODER_BUTTON_ROW 0
|
||||
#endif
|
||||
#ifndef ENCODER_BUTTON_COL
|
||||
# define ENCODER_BUTTON_COL 0
|
||||
#endif
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
|
||||
#define DPI_OPTION_SIZE ARRAY_SIZE(dpi_array)
|
||||
|
||||
// Trackball State
|
||||
bool is_scroll_clicked = false;
|
||||
bool is_drag_scroll = false;
|
||||
float scroll_accumulated_h = 0;
|
||||
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;
|
||||
bool debug_encoder = false;
|
||||
|
||||
bool encoder_update_kb(uint8_t index, bool clockwise) {
|
||||
if (!encoder_update_user(index, clockwise)) {
|
||||
return false;
|
||||
}
|
||||
# ifdef MOUSEKEY_ENABLE
|
||||
tap_code(clockwise ? KC_WH_U : KC_WH_D);
|
||||
# else
|
||||
report_mouse_t mouse_report = pointing_device_get_report();
|
||||
mouse_report.v = clockwise ? 1 : -1;
|
||||
pointing_device_set_report(mouse_report);
|
||||
pointing_device_send();
|
||||
# endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void encoder_driver_init(void) {
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(encoder_pins_a); i++) {
|
||||
gpio_set_pin_input(encoder_pins_a[i]);
|
||||
gpio_set_pin_input(encoder_pins_b[i]);
|
||||
}
|
||||
opt_encoder_init();
|
||||
}
|
||||
|
||||
void encoder_driver_task(void) {
|
||||
uint16_t p1 = analogReadPin(encoder_pins_a[0]);
|
||||
uint16_t p2 = analogReadPin(encoder_pins_b[0]);
|
||||
|
||||
if (debug_encoder) dprintf("OPT1: %d, OPT2: %d\n", p1, p2);
|
||||
|
||||
int8_t dir = opt_encoder_handler(p1, p2);
|
||||
// If the mouse wheel was just released, do not scroll.
|
||||
if (timer_elapsed(lastMidClick) < PLOOPY_SCROLL_BUTTON_DEBOUNCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Limit the number of scrolls per unit time.
|
||||
if (timer_elapsed(lastScroll) < PLOOPY_SCROLL_DEBOUNCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't scroll if the middle button is depressed.
|
||||
if (is_scroll_clicked) {
|
||||
# ifndef PLOOPY_IGNORE_SCROLL_CLICK
|
||||
return;
|
||||
# endif
|
||||
}
|
||||
|
||||
if (dir == 0) return;
|
||||
encoder_queue_event(0, dir > 0);
|
||||
lastScroll = timer_read();
|
||||
}
|
||||
#endif
|
||||
|
||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||
if (is_drag_scroll) {
|
||||
scroll_accumulated_h += (float)mouse_report.x / PLOOPY_DRAGSCROLL_DIVISOR_H;
|
||||
scroll_accumulated_v += (float)mouse_report.y / PLOOPY_DRAGSCROLL_DIVISOR_V;
|
||||
|
||||
// Assign integer parts of accumulated scroll values to the mouse report
|
||||
mouse_report.h = (int8_t)scroll_accumulated_h;
|
||||
#ifdef PLOOPY_DRAGSCROLL_INVERT
|
||||
mouse_report.v = -(int8_t)scroll_accumulated_v;
|
||||
#else
|
||||
mouse_report.v = (int8_t)scroll_accumulated_v;
|
||||
#endif
|
||||
|
||||
// Update accumulated scroll values by subtracting the integer parts
|
||||
scroll_accumulated_h -= (int8_t)scroll_accumulated_h;
|
||||
scroll_accumulated_v -= (int8_t)scroll_accumulated_v;
|
||||
|
||||
// Clear the X and Y values of the mouse report
|
||||
mouse_report.x = 0;
|
||||
mouse_report.y = 0;
|
||||
|
||||
mouse_report.x = 0;
|
||||
mouse_report.y = 0;
|
||||
}
|
||||
|
||||
return pointing_device_task_user(mouse_report);
|
||||
}
|
||||
|
||||
bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
|
||||
if (debug_mouse) {
|
||||
dprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
|
||||
}
|
||||
|
||||
// Update Timer to prevent accidental scrolls
|
||||
#ifdef ENCODER_ENABLE
|
||||
if ((record->event.key.col == ENCODER_BUTTON_COL) && (record->event.key.row == ENCODER_BUTTON_ROW)) {
|
||||
lastMidClick = timer_read();
|
||||
is_scroll_clicked = record->event.pressed;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!process_record_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == DPI_CONFIG && record->event.pressed) {
|
||||
keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
|
||||
eeconfig_update_kb(keyboard_config.raw);
|
||||
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
|
||||
}
|
||||
|
||||
if (keycode == DRAG_SCROLL) {
|
||||
#ifdef PLOOPY_DRAGSCROLL_MOMENTARY
|
||||
is_drag_scroll = record->event.pressed;
|
||||
#else
|
||||
if (record->event.pressed) {
|
||||
is_drag_scroll ^= 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hardware Setup
|
||||
void keyboard_pre_init_kb(void) {
|
||||
// debug_enable = true;
|
||||
// debug_matrix = true;
|
||||
// debug_mouse = true;
|
||||
// debug_encoder = true;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
#ifdef UNUSABLE_PINS
|
||||
const pin_t unused_pins[] = UNUSABLE_PINS;
|
||||
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(unused_pins); i++) {
|
||||
gpio_set_pin_output_push_pull(unused_pins[i]);
|
||||
gpio_write_pin_low(unused_pins[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
// This is the debug LED.
|
||||
#if defined(DEBUG_LED_PIN)
|
||||
gpio_set_pin_output_push_pull(DEBUG_LED_PIN);
|
||||
gpio_write_pin(DEBUG_LED_PIN, debug_enable);
|
||||
#endif
|
||||
|
||||
keyboard_pre_init_user();
|
||||
}
|
||||
|
||||
void pointing_device_init_kb(void) {
|
||||
keyboard_config.raw = eeconfig_read_kb();
|
||||
if (keyboard_config.dpi_config > DPI_OPTION_SIZE) {
|
||||
eeconfig_init_kb();
|
||||
}
|
||||
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
|
||||
}
|
||||
|
||||
void eeconfig_init_kb(void) {
|
||||
keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT;
|
||||
eeconfig_update_kb(keyboard_config.raw);
|
||||
eeconfig_init_user();
|
||||
}
|
||||
|
|
@ -19,16 +19,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
#include "analog.h"
|
||||
#include "opt_encoder.h"
|
||||
|
||||
// Sensor defs
|
||||
#define OPT_ENC1 F0
|
||||
#define OPT_ENC2 F4
|
||||
#define OPT_ENC1_MUX 0
|
||||
#define OPT_ENC2_MUX 4
|
||||
|
||||
void process_wheel(void);
|
||||
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
12
keyboards/ploopyco/post_rules.mk
Normal file
12
keyboards/ploopyco/post_rules.mk
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
OPT_ENCODER_TYPE ?= default
|
||||
VALID_OPT_ENCODER_TYPES := default simple tiny custom
|
||||
|
||||
ifeq ($(filter $(OPT_ENCODER_TYPE),$(VALID_OPT_ENCODER_TYPES)),)
|
||||
$(call CATASTROPHIC_ERROR,Invalid OPT_ENCODER_TYPE,OPT_ENCODER_TYPE="$(OPT_ENCODER_TYPE)" is not a valid pointing device type)
|
||||
else
|
||||
ifneq ($(strip $(OPT_ENCODER_TYPE)), custom)
|
||||
VPATH += keyboards/ploopyco/common
|
||||
SRC += opt_encoder_$(strip $(OPT_ENCODER_TYPE)).c
|
||||
ANALOG_DRIVER_REQUIRED = yes
|
||||
endif
|
||||
endif
|
||||
45
keyboards/ploopyco/readme.md
Normal file
45
keyboards/ploopyco/readme.md
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Ploopyco
|
||||
|
||||
* [Mouse](mouse/)
|
||||
* [Trackball](trackball/)
|
||||
* [Trackball Mini](trackball_mini/)
|
||||
* [Trackball Nano](trackball_nano/)
|
||||
* [Trackball Thumb](trackball_thumb/)
|
||||
* [Adept/Madromys](manromys/)
|
||||
|
||||
# Customizing your PloopyCo Device
|
||||
|
||||
There are a number of behavioral settings that you can use to help customize your experience
|
||||
| | | |
|
||||
|---------------------------------|-------------------|-----------------------------------------------------------|
|
||||
| `PLOOPY_IGNORE_SCROLL_CLICK` | *__not_defined__* | Ignores scroll wheel if it is pressed down. |
|
||||
| `PLOOPY_SCROLL_DEBOUNCE` | `5` | Number of milliseconds between scroll events. |
|
||||
| `PLOOPY_SCROLL_BUTTON_DEBOUNCE` | `100` | Time to ignore scroll events after pressing scroll wheel. |
|
||||
|
||||
## DPI
|
||||
|
||||
You can change the DPI/CPI or speed of the trackball by calling `pointing_device_set_cpi` at any time. Additionally, there is a `DPI_CONFIG` macro that will cycle through an array of options for the DPI. This is set to 1200, 1600, and 2400, but can be changed. 1600 is also set to the default.
|
||||
|
||||
To configure/set your own array, there are two defines to use, `PLOOPY_DPI_OPTIONS` to set the array, and `PLOOPY_DPI_DEFAULT`.
|
||||
|
||||
```c
|
||||
#define PLOOPY_DPI_OPTIONS { 1200, 1600, 2400 }
|
||||
#define PLOOPY_DPI_DEFAULT 1
|
||||
```
|
||||
|
||||
The `PLOOPY_DPI_OPTIONS` array sets the values that you want to be able to cycle through, and the order they are in. The "default" define lets the firmware know which of these options is the default and should be loaded by default.
|
||||
|
||||
The `DPI_CONFIG` macro will cycle through the values in the array, each time you hit it. And it stores this value in persistent memory, so it will load it the next time the device powers up.
|
||||
|
||||
## Drag Scroll
|
||||
|
||||
Drag Sroll is a custom keycode for the Ploopy devices that allow you to hold or tap a button and have the mouse movement translate into scrolling instead.
|
||||
|
||||
Nothing needs to be enabled to use this functionality. Just add the `DRAG_SCROLL` to your keymap.
|
||||
|
||||
### Drag Scroll Configuration
|
||||
|
||||
* `#define PLOOPY_DRAGSCROLL_MOMENTARY` - Makes the key into a momentary key, rather than a toggle.
|
||||
* `#define PLOOPY_DRAGSCROLL_DIVISOR_H 8.0` - Sets the horizontal movement divisor to use when drag scroll is enabled.
|
||||
* `#define PLOOPY_DRAGSCROLL_DIVISOR_V 8.0` - Sets the vertical movement divisor to use when drag scroll is enabled.
|
||||
* `#define PLOOPY_DRAGSCROLL_INVERT` - This reverses the direction that the scroll is performed.
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue