aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ploopyco/trackball_nano/trackball_nano.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ploopyco/trackball_nano/trackball_nano.c')
-rw-r--r--keyboards/ploopyco/trackball_nano/trackball_nano.c116
1 files changed, 9 insertions, 107 deletions
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.c b/keyboards/ploopyco/trackball_nano/trackball_nano.c
index 9bcfa59ef..2702f6055 100644
--- a/keyboards/ploopyco/trackball_nano/trackball_nano.c
+++ b/keyboards/ploopyco/trackball_nano/trackball_nano.c
@@ -37,7 +37,8 @@
37#endif 37#endif
38 38
39#ifndef PLOOPY_DPI_OPTIONS 39#ifndef PLOOPY_DPI_OPTIONS
40# define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 } 40# define PLOOPY_DPI_OPTIONS \
41 { 375, 750, 1375 }
41# ifndef PLOOPY_DPI_DEFAULT 42# ifndef PLOOPY_DPI_DEFAULT
42# define PLOOPY_DPI_DEFAULT 2 43# define PLOOPY_DPI_DEFAULT 2
43# endif 44# endif
@@ -49,12 +50,8 @@
49 50
50const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; 51const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { };
51 52
52// Transformation constants for delta-X and delta-Y
53const static float ADNS_X_TRANSFORM = -1.0;
54const static float ADNS_Y_TRANSFORM = 1.0;
55
56keyboard_config_t keyboard_config; 53keyboard_config_t keyboard_config;
57uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; 54uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
58#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) 55#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
59 56
60// TODO: Implement libinput profiles 57// TODO: Implement libinput profiles
@@ -63,77 +60,13 @@ uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
63// Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC 60// Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC
64 61
65// Trackball State 62// Trackball State
66bool is_scroll_clicked = false; 63bool is_scroll_clicked = false;
67bool BurstState = false; // init burst state for Trackball module 64bool BurstState = false; // init burst state for Trackball module
68uint16_t MotionStart = 0; // Timer for accel, 0 is resting state 65uint16_t MotionStart = 0; // Timer for accel, 0 is resting state
69uint16_t lastScroll = 0; // Previous confirmed wheel event
70uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
71uint8_t OptLowPin = OPT_ENC1;
72bool debug_encoder = false;
73
74__attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
75 mouse_report->x = x;
76 mouse_report->y = y;
77}
78
79__attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) {
80 report_adns_t data = adns_read_burst();
81
82 if (data.dx != 0 || data.dy != 0) {
83 if (debug_mouse)
84 dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
85
86 // Apply delta-X and delta-Y transformations.
87 // x and y are swapped
88 // the sensor is rotated
89 // by 90 degrees
90 float xt = (float) data.dy * ADNS_X_TRANSFORM;
91 float yt = (float) data.dx * ADNS_Y_TRANSFORM;
92
93 int16_t xti = (int16_t)xt;
94 int16_t yti = (int16_t)yt;
95
96 process_mouse_user(mouse_report, xti, yti);
97 }
98}
99
100bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
101 xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
102
103 // Update Timer to prevent accidental scrolls
104 if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
105 lastMidClick = timer_read();
106 is_scroll_clicked = record->event.pressed;
107 }
108
109 if (!process_record_user(keycode, record))
110 return false;
111
112 if (keycode == DPI_CONFIG && record->event.pressed) {
113 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
114 eeconfig_update_kb(keyboard_config.raw);
115 adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
116 }
117 66
118/* If Mousekeys is disabled, then use handle the mouse button 67void pointing_device_init_kb(void) {
119 * keycodes. This makes things simpler, and allows usage of 68 // set the DPI.
120 * the keycodes in a consistent manner. But only do this if 69 pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
121 * Mousekeys is not enable, so it's not handled twice.
122 */
123#ifndef MOUSEKEY_ENABLE
124 if (IS_MOUSEKEY_BUTTON(keycode)) {
125 report_mouse_t currentReport = pointing_device_get_report();
126 if (record->event.pressed) {
127 currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
128 } else {
129 currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
130 }
131 pointing_device_set_report(currentReport);
132 pointing_device_send();
133 }
134#endif
135
136 return true;
137} 70}
138 71
139// Hardware Setup 72// Hardware Setup
@@ -143,9 +76,6 @@ void keyboard_pre_init_kb(void) {
143 // debug_mouse = true; 76 // debug_mouse = true;
144 // debug_encoder = true; 77 // debug_encoder = true;
145 78
146 setPinInput(OPT_ENC1);
147 setPinInput(OPT_ENC2);
148
149 /* Ground all output pins connected to ground. This provides additional 79 /* Ground all output pins connected to ground. This provides additional
150 * pathways to ground. If you're messing with this, know this: driving ANY 80 * pathways to ground. If you're messing with this, know this: driving ANY
151 * of these pins high will cause a short. On the MCU. Ka-blooey. 81 * of these pins high will cause a short. On the MCU. Ka-blooey.
@@ -162,34 +92,6 @@ void keyboard_pre_init_kb(void) {
162 keyboard_pre_init_user(); 92 keyboard_pre_init_user();
163} 93}
164 94
165void pointing_device_init(void) {
166 adns_init();
167 opt_encoder_init();
168
169 // reboot the adns.
170 // if the adns hasn't initialized yet, this is harmless.
171 adns_write_reg(REG_CHIP_RESET, 0x5a);
172
173 // wait maximum time before adns is ready.
174 // this ensures that the adns is actuall ready after reset.
175 wait_ms(55);
176
177 // read a burst from the adns and then discard it.
178 // gets the adns ready for write commands
179 // (for example, setting the dpi).
180 adns_read_burst();
181
182 // set the DPI.
183 adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
184}
185
186void pointing_device_task(void) {
187 report_mouse_t mouse_report = pointing_device_get_report();
188 process_mouse(&mouse_report);
189 pointing_device_set_report(mouse_report);
190 pointing_device_send();
191}
192
193void eeconfig_init_kb(void) { 95void eeconfig_init_kb(void) {
194 keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; 96 keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT;
195 eeconfig_update_kb(keyboard_config.raw); 97 eeconfig_update_kb(keyboard_config.raw);