Skip to content

Commit

Permalink
Merge pull request qmk#28 from ilc/dpi
Browse files Browse the repository at this point in the history
pointing-devices: General work, but mostly on trackball.
  • Loading branch information
morganvenable committed Apr 12, 2024
2 parents f912026 + 73114f3 commit c43e7f5
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 65 deletions.
13 changes: 2 additions & 11 deletions keyboards/svalboard/ballpoint/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// CS pins.
#define PMW33XX_CS_PIN GP17
#endif
#define PMW33XX_CS_DIVISOR 4
#define PMW33XX_CPI 2000
#define POINTING_DEVICE_LEFT
#define POINTING_DEVICE_INVERT_Y
#define ROTATIONAL_TRANSFORM_ANGLE 90
#define POINTING_DEVICE_INVERT_X
#define POINTING_DEVICE_ROTATION_90
#endif
#endif

Expand All @@ -90,10 +87,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
// #define PS2_MOUSE_SCROLL_BTN_MASK 0 // just normal middle button for panning and relative scroll
#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) /* Default -- tap to enter relative scroll, hold to use direct scroll*/
#endif

//@manna-harbour's automousekeys
#if defined MH_AUTO_BUTTONS
#define MH_AUTO_BUTTONS_LAYER MBO
#define MH_AUTO_BUTTONS_TIMEOUT 5000
#endif
4 changes: 1 addition & 3 deletions keyboards/svalboard/ballpoint/right/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#define SERIAL_USART_TX_PIN GP1
#define SERIAL_USART_RX_PIN GP0
#define SERIAL_USART_FULL_DUPLEX
#define SERIAL_PIO_USE_PIO0
#define SPLIT_POINTING_ENABLE
#define POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE
#define SERIAL_PIO_USE_PIO0
14 changes: 14 additions & 0 deletions keyboards/svalboard/ballpoint/rules.mk
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
POINTING_DEVICE_ENABLE = yes
# this selects trackball driver
POINTING_DEVICE_DRIVER = pmw3360

ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pimoroni_trackball)
OPT_DEFS += -DPOINTING_DEVICE_IS_PIMORONI
endif

ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pmw3360)
OPT_DEFS += -DPOINTING_DEVICE_IS_PMW3360
endif

ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pmw3389)
OPT_DEFS += -DPOINTING_DEVICE_IS_PMW3389
endif
8 changes: 6 additions & 2 deletions keyboards/svalboard/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

//#define FORTY_FOUR_MM_TB
/* key matrix size */
// Rows are doubled-up
#define MATRIX_ROWS 10
Expand All @@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FORCE_NKRO
#define EE_HANDS
//#define DEBUG_MATRIX_SCAN_RATE

#define EECONFIG_KB_DATA_SIZE 4

// wiring of each half
//Layout for svalboard v0 (different from lalboard_v2)
Expand Down Expand Up @@ -56,6 +56,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define USB_SUSPEND_WAKEUP_DELAY 500
#define SELECT_SOFT_SERIAL_RATE {0}

#define SPLIT_POINTING_ENABLE
#define POINTING_DEVICE_COMBINED
#define POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE

// Avoid slave-slave deadlock due to missing USB_VBUS_PIN.
//
// End result of enabling this: when you plug the keyboard to a finnicky USB
Expand Down
52 changes: 51 additions & 1 deletion keyboards/svalboard/keymaps/vial/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include QMK_KEYBOARD_H
#include <stdbool.h>
#include <stdint.h>
#include "svalboard.h"

#define MH_AUTO_BUTTONS_LAYER MBO
#define MH_AUTO_BUTTONS_TIMEOUT 5000
#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) // this mask disables the key for non-PS2 purposes

void keyboard_post_init_user(void) {
// Customise these values if you need to debug the matrix
Expand All @@ -36,8 +41,14 @@ void pointing_device_init_user(void) {
#endif

enum my_keycodes {
SV_LEFT_DPI_INC = QK_KB_0,
SV_LEFT_DPI_DEC,
SV_RIGHT_DPI_INC,
SV_RIGHT_DPI_DEC,
SV_LEFT_SCROLL_TOGGLE,
SV_RIGHT_SCROLL_TOGGLE,
KC_NORMAL_HOLD = SAFE_RANGE,
KC_FUNC_HOLD
KC_FUNC_HOLD,
};

enum layer {
Expand Down Expand Up @@ -178,6 +189,20 @@ report_mouse_t pointing_device_task_combined_user(report_mouse_t reportMouse1, r
if (reportMouse1.x == 0 && reportMouse1.y == 0 && reportMouse2.x == 0 && reportMouse2.y == 0)
return pointing_device_combine_reports(reportMouse1, reportMouse2);

if (global_saved_values.left_scroll) {
reportMouse1.h = reportMouse1.x;
reportMouse1.v = -reportMouse1.y;
reportMouse1.x = 0;
reportMouse1.y = 0;
}

if (global_saved_values.right_scroll) {
reportMouse2.h = reportMouse2.x;
reportMouse2.v = -reportMouse2.y;
reportMouse2.x = 0;
reportMouse2.y = 0;
}

if (mh_auto_buttons_timer) {
mh_auto_buttons_timer = timer_read();
} else {
Expand Down Expand Up @@ -230,6 +255,31 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
mouse_mode(false);
}
}
if (!record->event.pressed) {
switch (keycode) {
case SV_LEFT_DPI_INC:
increase_left_dpi();
break;
case SV_LEFT_DPI_DEC:
decrease_left_dpi();
break;
case SV_RIGHT_DPI_INC:
increase_right_dpi();
break;
case SV_RIGHT_DPI_DEC:
decrease_right_dpi();
break;
case SV_LEFT_SCROLL_TOGGLE:
global_saved_values.left_scroll = !global_saved_values.left_scroll;
write_eeprom_kb();
break;
case SV_RIGHT_SCROLL_TOGGLE:
global_saved_values.right_scroll = !global_saved_values.right_scroll;
write_eeprom_kb();
default:
break;
}
}
#endif

switch (keycode) {
Expand Down
28 changes: 28 additions & 0 deletions keyboards/svalboard/keymaps/vial/vial.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@
"rows": 10,
"cols": 6
},
"customKeycodes": [
{"shortName": "Left\nDPI +",
"title": "Increase the DPI of the left pointing device.",
"name": "SV_LEFT_DPI_INC"
},
{"shortName": "Left\nDPI -",
"title": "Decrease the DPI of the left pointing device.",
"name": "SV_LEFT_DPI_DEC"
},
{"shortName": "Right\nDPI +",
"title": "Increase the DPI of the right pointing device.",
"name": "SV_RIGHT_DPI_INC"
},
{"shortName": "Right\nDPI -",
"title": "Decrease the DPI of the right pointing device.",
"name": "SV_RIGHT_DPI_DEC"
},
{
"shortName": "Scroll\nLeft\nToggle",
"title": "Toggle if the left pointer is scroll or pointer.",
"name": "SV_LEFT_SCROLL_TOGGLE"
},
{
"shortName": "Scroll\nRight\nToggle",
"title": "Toggle if the right pointer is scroll or pointer.",
"name": "SV_RIGHT_SCROLL_TOGGLE"
}
],
"layouts": {
"keymap": [
[{"x":3.5},"3,3",{"x":2.5},"2,3",{"x":9},"7,3",{"x":2.5},"8,3"],
Expand Down
13 changes: 2 additions & 11 deletions keyboards/svalboard/pointball/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// CS pins.
#define PMW33XX_CS_PIN GP17
#endif
#define PMW33XX_CS_DIVISOR 4
#define PMW33XX_CPI 2000
#define POINTING_DEVICE_RIGHT
#define POINTING_DEVICE_INVERT_Y
#define ROTATIONAL_TRANSFORM_ANGLE 90
#define POINTING_DEVICE_INVERT_X_RIGHT
#define POINTING_DEVICE_ROTATION_90_RIGHT
//^ rotation is CCW
#endif
#endif
Expand All @@ -91,10 +88,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
// #define PS2_MOUSE_SCROLL_BTN_MASK 0 // just normal middle button for panning and relative scroll
#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) /* Default -- tap to enter relative scroll, hold to use direct scroll*/
#endif

//@manna-harbour's automousekeys
#if defined MH_AUTO_BUTTONS
#define MH_AUTO_BUTTONS_LAYER MBO
#define MH_AUTO_BUTTONS_TIMEOUT 5000
#endif
4 changes: 1 addition & 3 deletions keyboards/svalboard/pointball/left/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#define SERIAL_USART_TX_PIN GP0
#define SERIAL_USART_RX_PIN GP1
#define SERIAL_USART_FULL_DUPLEX
#define SERIAL_PIO_USE_PIO0
#define SPLIT_POINTING_ENABLE
#define POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE
#define SERIAL_PIO_USE_PIO0
14 changes: 14 additions & 0 deletions keyboards/svalboard/pointball/rules.mk
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
POINTING_DEVICE_ENABLE = yes
# this selects trackball driver
POINTING_DEVICE_DRIVER = pmw3360

ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pimoroni_trackball)
OPT_DEFS += -DPOINTING_DEVICE_IS_PIMORONI
endif

ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pmw3360)
OPT_DEFS += -DPOINTING_DEVICE_IS_PMW3360
endif

ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pmw3389)
OPT_DEFS += -DPOINTING_DEVICE_IS_PMW3389
endif
4 changes: 2 additions & 2 deletions keyboards/svalboard/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ SERIAL_DRIVER = vendor
# this turns on trackpoint -- dupe in info.json?
# PS2_MOUSE_ENABLE = yes
# this turns on trackballs including pimoroni
POINTING_DEVICE_ENABLE = no
POINTING_DEVICE_ENABLE = yes
# this selects trackball driver
POINTING_DEVICE_DRIVER = pmw3360
POINTING_DEVICE_DRIVER = custom
# pimoroni_trackball
# pmw3389

Expand Down
79 changes: 79 additions & 0 deletions keyboards/svalboard/svalboard.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,83 @@
#include "svalboard.h"
#include "eeconfig.h"

saved_values_t global_saved_values;

void write_eeprom_kb(void) {
eeconfig_update_kb_datablock(&global_saved_values);
}

void read_eeprom_kb(void) {
bool modified = false;
eeconfig_read_kb_datablock(&global_saved_values);
if (global_saved_values.version < 1) {
global_saved_values.version = 1;
global_saved_values.left_scroll = true;
global_saved_values.right_dpi_index=2;
global_saved_values.left_dpi_index=2;
modified = true;
}
// As we add versions, just append here.
if (modified) {
write_eeprom_kb();
}
}

const uint16_t dpi_choices[] = { 200, 400, 800, 1200, 1600, 2400 }; // If we need more, add them.
#define DPI_CHOICES_LENGTH (sizeof(dpi_choices)/sizeof(dpi_choices[0]))

void increase_left_dpi(void) {
if (global_saved_values.left_dpi_index + 1 < DPI_CHOICES_LENGTH) {
global_saved_values.left_dpi_index++;
set_left_dpi(global_saved_values.left_dpi_index);
write_eeprom_kb();
}
}

void decrease_left_dpi(void) {
if (global_saved_values.left_dpi_index > 0) {
global_saved_values.left_dpi_index--;
set_left_dpi(global_saved_values.left_dpi_index);
write_eeprom_kb();
}
}

void increase_right_dpi(void) {
if (global_saved_values.right_dpi_index + 1 < DPI_CHOICES_LENGTH) {
global_saved_values.right_dpi_index++;
set_right_dpi(global_saved_values.right_dpi_index);
write_eeprom_kb();
}
}

void decrease_right_dpi(void) {
if (global_saved_values.right_dpi_index > 0) {
global_saved_values.right_dpi_index--;
set_right_dpi(global_saved_values.right_dpi_index);
write_eeprom_kb();
}
}
// TODO: Still need to add code to save values.
void set_left_dpi(uint8_t index) {
uprintf("LDPI: %d %d\n", index, dpi_choices[index]);
pointing_device_set_cpi_on_side(true, dpi_choices[index]);
}

void set_right_dpi(uint8_t index) {
uprintf("RDPI: %d %d\n", index, dpi_choices[index]);
pointing_device_set_cpi_on_side(false, dpi_choices[index]);
}

void pointing_device_init_kb(void) {
read_eeprom_kb();
set_left_dpi(global_saved_values.left_dpi_index);
set_right_dpi(global_saved_values.right_dpi_index);
}

void keyboard_post_init_kb(void) {
pointing_device_init_kb();
keyboard_post_init_user();
}

#ifndef SVALBOARD_REENABLE_BOOTMAGIC_LITE
// This is to override `bootmagic_lite` feature (see docs/feature_bootmagic.md),
Expand Down
21 changes: 21 additions & 0 deletions keyboards/svalboard/svalboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once

#include "quantum.h"

struct saved_values {
uint8_t version; // Currently at 1, We assume all new data will be zeroed.
bool left_scroll :1;
bool right_scroll :1;
unsigned int unused0 :6;
uint8_t left_dpi_index;
uint8_t right_dpi_index;
};

typedef struct saved_values saved_values_t;

extern saved_values_t global_saved_values;

void increase_left_dpi(void);
void increase_right_dpi(void);
void decrease_left_dpi(void);
void decrease_right_dpi(void);
void set_left_dpi(uint8_t index);
void set_right_dpi(uint8_t index);
void write_eeprom_kb(void);
9 changes: 0 additions & 9 deletions keyboards/svalboard/trackball.c

This file was deleted.

Loading

0 comments on commit c43e7f5

Please sign in to comment.