Skip to content

Commit

Permalink
Merge pull request #34 from ilc/tp-fix-sprintek
Browse files Browse the repository at this point in the history
trackpoint: Disable calibration - Fix the drift.
  • Loading branch information
morganvenable authored May 4, 2024
2 parents e98acd3 + 23f1cc2 commit 0367222
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 50 deletions.
9 changes: 7 additions & 2 deletions keyboards/svalboard/keymaps/vial/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum my_keycodes {
SV_RIGHT_DPI_DEC,
SV_LEFT_SCROLL_TOGGLE,
SV_RIGHT_SCROLL_TOGGLE,
SV_RECALIBRATE_POINTER,
KC_NORMAL_HOLD = SAFE_RANGE,
KC_FUNC_HOLD,
};
Expand Down Expand Up @@ -163,11 +164,11 @@ const uint16_t PROGMEM keymaps[NUM_LAYERS][MATRIX_ROWS][MATRIX_COLS] = {
/*R1*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_TRNS,
/*R2*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_TRNS,
/*R3*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN2, KC_TRNS,
/*R4*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
/*R4*/ SV_RECALIBRATE_POINTER, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
/*L1*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_TRNS,
/*L2*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_TRNS,
/*L3*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN2, KC_TRNS,
/*L4*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
/*L4*/ SV_RECALIBRATE_POINTER, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
/*RT*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
/*LT*/ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
)
Expand Down Expand Up @@ -296,6 +297,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case KC_RALT:
case KC_LGUI:
case KC_RGUI:
case SV_RECALIBRATE_POINTER:
break;
default:
mouse_mode(false);
Expand All @@ -322,6 +324,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case SV_RIGHT_SCROLL_TOGGLE:
global_saved_values.right_scroll = !global_saved_values.right_scroll;
write_eeprom_kb();
break;
case SV_RECALIBRATE_POINTER:
recalibrate_pointer();
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions keyboards/svalboard/keymaps/vial/vial.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"shortName": "Scroll\nRight\nToggle",
"title": "Toggle if the right pointer is scroll or pointer.",
"name": "SV_RIGHT_SCROLL_TOGGLE"
},
{
"shortName": "Fix\nDrift",
"title": "Reset the calibration of the pointing device",
"name": "SV_RECALIBRATE_POINTER"
}
],
"layouts": {
Expand Down
92 changes: 44 additions & 48 deletions keyboards/svalboard/svalboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,65 +98,61 @@ void bootmagic_lite(void) {
#ifdef PS2_MOUSE_ENABLE
#include "ps2_mouse.h"
#include "ps2.h"
#endif

#ifdef PS2_MOUSE_ENABLE
void ps2_mouse_init_user() {
//sensitivity command in fourth byte 00 = 0 multiplier, FF = 2.0 multiplier
//sensitivity command in fourth byte 00 = 0 multiplier, FF = 2.0 multiplier
/*
PS2_MOUSE_SEND(0xE2);
PS2_MOUSE_SEND(0x81);
PS2_MOUSE_SEND(0x4A);
PS2_MOUSE_SEND(0x59);
*/

//Z tap -- doesn't seem to work. 0x01 is on.
uint8_t val;

ps2_mouse_disable_data_reporting();

PS2_MOUSE_SEND(0xE2, "pts: 0xE2");
PS2_MOUSE_SEND(0x47, "pts: 0x47");
PS2_MOUSE_SEND(0x2C, "pts: 0x2C");
PS2_MOUSE_SEND(0x00, "pts: 0x00"); // 01 turns on Z tap, 00 turns off

PS2_MOUSE_RECEIVE("ztap - disable");

/*
E2 80 63
E2 81 63 XX
Drift Threshold [drift]
This parameter is used to set the threshold at which drift calibration will occur. Low drift
thresholds should be used to maximize the effectiveness of the drift calibration algorithms.
If the difference between the smoothed conversion value and the trial value remains within
the internal drift threshold, drift calibration will occur. The format of this parameter is
x"FF"- drift threshold. The default value for drift is x"FE", corresponding to a drift
threshold of 1. A reset (x"FF") or set default (x"F6") command will not affect this byte.
From Sprintek:
E2 47 FA 10 - Disable drift correction. - Flips the bit, it should boot enabled.
This was given to us to stop the trackpoint from calibrating at bad times.
*/
PS2_MOUSE_SEND(0xE2, "pts: 0xE2");
PS2_MOUSE_SEND(0x81, "pts: 0x81");
PS2_MOUSE_SEND(0x63, "pts: 0x63");
PS2_MOUSE_SEND(0x80, "pts: 0x80"); // 0xFE is default threshold of 1 try low and see what happens

PS2_MOUSE_SEND(0xE2, "pts: 0xE2");
PS2_MOUSE_SEND(0x80, "pts: 0x80");
PS2_MOUSE_SEND(0xFA, "pts: 0xFA");
val = ps2_host_recv_response();

if (~val & 0x10) {
PS2_MOUSE_SEND(0xE2, "pts: 0xE2");
PS2_MOUSE_SEND(0x47, "pts: 0x47");
PS2_MOUSE_SEND(0xFA, "pts: 0xFA");
PS2_MOUSE_SEND(0x10, "pts: 0x10");
PS2_MOUSE_RECEIVE("drift correction - disable");
}
/*
E2 80 64
E2 81 64 XX
XY running average drift time constant [xydriftavg]
This parameter sets the time constant used for the X and Y axis running average routines
used in conjunction with a high sensitivity TrackPoint circuit for drift control only. This
directly affects the performance of the drift cancellation algorithms. The least possible
averaging which allows calibration to take place should be used, otherwise improper
calibrations will occur during slow cursor movement. The formula used for running
average is: A = A + (N - A) X where A = running average, N = present sample (lowx or
256
lowy, low order l counts), and X is xydriftavg. The default value for xydriftavg will
depend upon the presence of a jumper between pins 26 and 21 of the TPM754. If the
jumper is present (noisier sensor), the default value will be x"40" (decimal 64)
corresponding to approximately a 4 sample average, otherwise the default value is x"80"
(decimal 128) corresponding to a 2 sample average. This value is not affected by a reset
(x"FF") or set default (x"F6") command
From Sprintek:
E2 81 92 XX - Set the deadzone - 0x0C default, claimed.
Increase this to get rid of the tail drift.
*/
PS2_MOUSE_SEND(0xE2, "pts: 0xE2");
PS2_MOUSE_SEND(0x81, "pts: 0x81");
PS2_MOUSE_SEND(0x63, "pts: 0x64");
PS2_MOUSE_SEND(0x80, "pts: 0x80"); // 0x80 is default threshold of 2 samples try low and see what happens
// PS2_MOUSE_SEND(0xE2, "pts: 0xE2");
// PS2_MOUSE_SEND(0x81, "pts: 0x81");
// PS2_MOUSE_SEND(0x92, "pts: 0x92");
// PS2_MOUSE_SEND(0x80, "pts: 0x0C"); // Experiment with this if it isn't enough.

/*
Timing on the double tap on the trackpoint:
Expand All @@ -183,18 +179,18 @@ Z Time Constant [zTc]
PS2_MOUSE_SEND(0x81, "pts: 0x81");
PS2_MOUSE_SEND(0x5E, "pts: 0x5E");
PS2_MOUSE_SEND(0x00, "pts: 0x00");
PS2_MOUSE_RECEIVE("double Z tap - disable");


// transfer function plateau speed -- default is 0x61
/*
PS2_MOUSE_SEND(0xE2, "tfups: 0xE2");
PS2_MOUSE_SEND(0x80, "tfups: 0x80");
PS2_MOUSE_SEND(0x60, "tfups: 0x60");
PS2_MOUSE_SEND(0xf0, "tfups: 0xf0");
*/


ps2_mouse_enable_data_reporting();

}
#endif

void recalibrate_pointer(void) {
#ifdef PS2_MOUSE_ENABLE
PS2_MOUSE_SEND(0xE2, "pts: 0xE2");
PS2_MOUSE_SEND(0x51, "pts: 0x51");
PS2_MOUSE_RECEIVE("trackpoint - recalibrate");
#endif
}

1 change: 1 addition & 0 deletions keyboards/svalboard/svalboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ void decrease_right_dpi(void);
void set_left_dpi(uint8_t index);
void set_right_dpi(uint8_t index);
void write_eeprom_kb(void);
void recalibrate_pointer(void);

0 comments on commit 0367222

Please sign in to comment.