aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ploopyco
diff options
context:
space:
mode:
authorploopyco <54917504+ploopyco@users.noreply.github.com>2021-03-25 08:10:55 -0400
committerGitHub <noreply@github.com>2021-03-25 23:10:55 +1100
commit666623d39adc052d2f585e908694279a9d5a65c6 (patch)
treec32dbeb25af4596a1f94a036db2fb8698ee31ebf /keyboards/ploopyco
parent0eabb01e27216611662d7e3c814a1a21bd20c90b (diff)
downloadqmk_firmware-666623d39adc052d2f585e908694279a9d5a65c6.tar.gz
qmk_firmware-666623d39adc052d2f585e908694279a9d5a65c6.zip
ADNS-5050 / Ploopy Nano / Ploopy Mini Trackballs (#11994)
* added adns5050 sensor code, as well as implementations for the Ploopy Mini and the Ploopy Nano * fixed spurious scrolling issue * recommended fixes for pr linting and cleanup
Diffstat (limited to 'keyboards/ploopyco')
-rw-r--r--keyboards/ploopyco/adns5050.c197
-rw-r--r--keyboards/ploopyco/adns5050.h79
-rw-r--r--keyboards/ploopyco/trackball_mini/config.h59
-rw-r--r--keyboards/ploopyco/trackball_mini/info.json19
-rw-r--r--keyboards/ploopyco/trackball_mini/keymaps/default/keymap.c28
-rw-r--r--keyboards/ploopyco/trackball_mini/keymaps/default/readme.md3
-rw-r--r--keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c66
-rw-r--r--keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/readme.md5
-rw-r--r--keyboards/ploopyco/trackball_mini/keymaps/via/config.h21
-rw-r--r--keyboards/ploopyco/trackball_mini/keymaps/via/keymap.c30
-rw-r--r--keyboards/ploopyco/trackball_mini/keymaps/via/rules.mk1
-rw-r--r--keyboards/ploopyco/trackball_mini/readme.md75
-rw-r--r--keyboards/ploopyco/trackball_mini/rev1_001/config.h40
-rw-r--r--keyboards/ploopyco/trackball_mini/rev1_001/readme.md1
-rw-r--r--keyboards/ploopyco/trackball_mini/rev1_001/rev1_001.h22
-rw-r--r--keyboards/ploopyco/trackball_mini/rev1_001/rules.mk0
-rw-r--r--keyboards/ploopyco/trackball_mini/rules.mk32
-rw-r--r--keyboards/ploopyco/trackball_mini/trackball_mini.c235
-rw-r--r--keyboards/ploopyco/trackball_mini/trackball_mini.h54
-rw-r--r--keyboards/ploopyco/trackball_nano/config.h48
-rw-r--r--keyboards/ploopyco/trackball_nano/info.json13
-rw-r--r--keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c23
-rw-r--r--keyboards/ploopyco/trackball_nano/keymaps/default/readme.md3
-rw-r--r--keyboards/ploopyco/trackball_nano/readme.md54
-rw-r--r--keyboards/ploopyco/trackball_nano/rev1_001/config.h37
-rw-r--r--keyboards/ploopyco/trackball_nano/rev1_001/readme.md1
-rw-r--r--keyboards/ploopyco/trackball_nano/rev1_001/rev1_001.h22
-rw-r--r--keyboards/ploopyco/trackball_nano/rev1_001/rules.mk0
-rw-r--r--keyboards/ploopyco/trackball_nano/rules.mk32
-rw-r--r--keyboards/ploopyco/trackball_nano/trackball_nano.c211
-rw-r--r--keyboards/ploopyco/trackball_nano/trackball_nano.h53
31 files changed, 1464 insertions, 0 deletions
diff --git a/keyboards/ploopyco/adns5050.c b/keyboards/ploopyco/adns5050.c
new file mode 100644
index 000000000..fcf2f213e
--- /dev/null
+++ b/keyboards/ploopyco/adns5050.c
@@ -0,0 +1,197 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#include "adns5050.h"
22#include "quantum.h"
23#include "wait.h"
24
25#ifdef CONSOLE_ENABLE
26# include "print.h"
27#endif
28
29#ifndef OPTIC_ROTATED
30# define OPTIC_ROTATED false
31#endif
32
33// Definitions for the ADNS serial line.
34// These really ought to be defined in your config.h, but defaults are
35// here if you're really lazy.
36#ifndef ADNS_SCLK_PIN
37# define ADNS_SCLK_PIN B7
38#endif
39
40#ifndef ADNS_SDIO_PIN
41# define ADNS_SDIO_PIN C6
42#endif
43
44#ifndef ADNS_CS_PIN
45# define ADNS_CS_PIN B4
46#endif
47
48#ifdef CONSOLE_ENABLE
49void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
50#endif
51
52// Initialize the ADNS serial pins.
53void adns_init(void) {
54 setPinOutput(ADNS_SCLK_PIN);
55 setPinOutput(ADNS_SDIO_PIN);
56 setPinOutput(ADNS_CS_PIN);
57}
58
59// Perform a synchronization with the ADNS.
60// Just as with the serial protocol, this is used by the slave to send a
61// synchronization signal to the master.
62void adns_sync(void) {
63 writePinLow(ADNS_CS_PIN);
64 wait_us(1);
65 writePinHigh(ADNS_CS_PIN);
66}
67
68void adns_cs_select(void) {
69 writePinLow(ADNS_CS_PIN);
70}
71
72void adns_cs_deselect(void) {
73 writePinHigh(ADNS_CS_PIN);
74}
75
76uint8_t adns_serial_read(void) {
77 setPinInput(ADNS_SDIO_PIN);
78 uint8_t byte = 0;
79
80 for (uint8_t i = 0; i < 8; ++i) {
81 writePinLow(ADNS_SCLK_PIN);
82 wait_us(1);
83
84 byte = (byte << 1) | readPin(ADNS_SDIO_PIN);
85
86 writePinHigh(ADNS_SCLK_PIN);
87 wait_us(1);
88 }
89
90 return byte;
91}
92
93void adns_serial_write(uint8_t data) {
94 setPinOutput(ADNS_SDIO_PIN);
95
96 for (int8_t b = 7; b >= 0; b--) {
97 writePinLow(ADNS_SCLK_PIN);
98
99 if (data & (1 << b))
100 writePinHigh(ADNS_SDIO_PIN);
101 else
102 writePinLow(ADNS_SDIO_PIN);
103
104 wait_us(2);
105
106 writePinHigh(ADNS_SCLK_PIN);
107 }
108
109 // tSWR. See page 15 of the ADNS spec sheet.
110 // Technically, this is only necessary if the next operation is an SDIO
111 // read. This is not guaranteed to be the case, but we're being lazy.
112 wait_us(4);
113
114 // Note that tSWW is never necessary. All write operations require at
115 // least 32us, which exceeds tSWW, so there's never a need to wait for it.
116}
117
118// Read a byte of data from a register on the ADNS.
119// Don't forget to use the register map (as defined in the header file).
120uint8_t adns_read_reg(uint8_t reg_addr) {
121 adns_cs_select();
122
123 adns_serial_write(reg_addr);
124
125 // We don't need a minimum tSRAD here. That's because a 4ms wait time is
126 // already included in adns_serial_write(), so we're good.
127 // See page 10 and 15 of the ADNS spec sheet.
128 //wait_us(4);
129
130 uint8_t byte = adns_serial_read();
131
132 // tSRW & tSRR. See page 15 of the ADNS spec sheet.
133 // Technically, this is only necessary if the next operation is an SDIO
134 // read or write. This is not guaranteed to be the case.
135 // Honestly, this wait could probably be removed.
136 wait_us(1);
137
138 adns_cs_deselect();
139
140 return byte;
141}
142
143void adns_write_reg(uint8_t reg_addr, uint8_t data) {
144 adns_cs_select();
145 adns_serial_write(reg_addr);
146 adns_serial_write(data);
147 adns_cs_deselect();
148}
149
150report_adns_t adns_read_burst(void) {
151 adns_cs_select();
152
153 report_adns_t data;
154 data.dx = 0;
155 data.dy = 0;
156
157 adns_serial_write(REG_MOTION_BURST);
158
159 // We don't need a minimum tSRAD here. That's because a 4ms wait time is
160 // already included in adns_serial_write(), so we're good.
161 // See page 10 and 15 of the ADNS spec sheet.
162 //wait_us(4);
163
164 uint8_t x = adns_serial_read();
165 uint8_t y = adns_serial_read();
166
167 // Burst mode returns a bunch of other shit that we don't really need.
168 // Setting CS to high ends burst mode early.
169 adns_cs_deselect();
170
171 data.dx = convert_twoscomp(x);
172 data.dy = convert_twoscomp(y);
173
174 return data;
175}
176
177// Convert a two's complement byte from an unsigned data type into a signed
178// data type.
179int8_t convert_twoscomp(uint8_t data) {
180 if ((data & 0x80) == 0x80)
181 return -128 + (data & 0x7F);
182 else
183 return data;
184}
185
186// Don't forget to use the definitions for CPI in the header file.
187void adns_set_cpi(uint8_t cpi) {
188 adns_write_reg(REG_MOUSE_CONTROL2, cpi);
189}
190
191bool adns_check_signature(void) {
192 uint8_t pid = adns_read_reg(REG_PRODUCT_ID);
193 uint8_t rid = adns_read_reg(REG_REVISION_ID);
194 uint8_t pid2 = adns_read_reg(REG_PRODUCT_ID2);
195
196 return (pid == 0x12 && rid == 0x01 && pid2 == 0x26);
197}
diff --git a/keyboards/ploopyco/adns5050.h b/keyboards/ploopyco/adns5050.h
new file mode 100644
index 000000000..ff8e8f78e
--- /dev/null
+++ b/keyboards/ploopyco/adns5050.h
@@ -0,0 +1,79 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <stdbool.h>
23
24// Registers
25#define REG_PRODUCT_ID 0x00
26#define REG_REVISION_ID 0x01
27#define REG_MOTION 0x02
28#define REG_DELTA_X 0x03
29#define REG_DELTA_Y 0x04
30#define REG_SQUAL 0x05
31#define REG_SHUTTER_UPPER 0x06
32#define REG_SHUTTER_LOWER 0x07
33#define REG_MAXIMUM_PIXEL 0x08
34#define REG_PIXEL_SUM 0x09
35#define REG_MINIMUM_PIXEL 0x0a
36#define REG_PIXEL_GRAB 0x0b
37#define REG_MOUSE_CONTROL 0x0d
38#define REG_MOUSE_CONTROL2 0x19
39#define REG_LED_DC_MODE 0x22
40#define REG_CHIP_RESET 0x3a
41#define REG_PRODUCT_ID2 0x3e
42#define REG_INV_REV_ID 0x3f
43#define REG_MOTION_BURST 0x63
44
45// CPI values
46#define CPI125 0x11
47#define CPI250 0x12
48#define CPI375 0x13
49#define CPI500 0x14
50#define CPI625 0x15
51#define CPI750 0x16
52#define CPI875 0x17
53#define CPI1000 0x18
54#define CPI1125 0x19
55#define CPI1250 0x1a
56#define CPI1375 0x1b
57
58#ifdef CONSOLE_ENABLE
59void print_byte(uint8_t byte);
60#endif
61
62typedef struct {
63 int8_t dx;
64 int8_t dy;
65} report_adns_t;
66
67// A bunch of functions to implement the ADNS5050-specific serial protocol.
68// Note that the "serial.h" driver is insufficient, because it does not
69// manually manipulate a serial clock signal.
70void adns_init(void);
71void adns_sync(void);
72uint8_t adns_serial_read(void);
73void adns_serial_write(uint8_t data);
74uint8_t adns_read_reg(uint8_t reg_addr);
75void adns_write_reg(uint8_t reg_addr, uint8_t data);
76report_adns_t adns_read_burst(void);
77int8_t convert_twoscomp(uint8_t data);
78void adns_set_cpi(uint8_t cpi);
79bool adns_check_signature(void);
diff --git a/keyboards/ploopyco/trackball_mini/config.h b/keyboards/ploopyco/trackball_mini/config.h
new file mode 100644
index 000000000..7a94e193f
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/config.h
@@ -0,0 +1,59 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "config_common.h"
23
24/* USB Device descriptor parameter */
25#define VENDOR_ID 0x5043
26#define PRODUCT_ID 0x1EAB
27#define DEVICE_VER 0x0001
28#define MANUFACTURER PloopyCo
29#define PRODUCT Trackball Mini
30
31/* key matrix size */
32#define MATRIX_ROWS 1
33#define MATRIX_COLS 5
34
35
36/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
37#define DEBOUNCE 5
38
39/* define if matrix has ghost (lacks anti-ghosting diodes) */
40//#define MATRIX_HAS_GHOST
41
42/* disable action features */
43//#define NO_ACTION_LAYER
44//#define NO_ACTION_TAPPING
45//#define NO_ACTION_ONESHOT
46#define NO_ACTION_MACRO
47#define NO_ACTION_FUNCTION
48
49/* Much more so than a keyboard, speed matters for a mouse. So we'll go for as high
50 a polling rate as possible. */
51#define USB_POLLING_INTERVAL_MS 1
52#define USB_MAX_POWER_CONSUMPTION 100
53
54/* Bootmagic Lite key configuration */
55#define BOOTMAGIC_LITE_ROW 0
56#define BOOTMAGIC_LITE_COLUMN 3
57
58// If board has a debug LED, you can enable it by defining this
59// #define DEBUG_LED_PIN F7
diff --git a/keyboards/ploopyco/trackball_mini/info.json b/keyboards/ploopyco/trackball_mini/info.json
new file mode 100644
index 000000000..7b30e0595
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/info.json
@@ -0,0 +1,19 @@
1{
2 "keyboard_name": "Ploopy Trackball Mini",
3 "url": "www.ploopy.co",
4 "maintainer": "ploopyco",
5 "manufacturer": "Ploopy Corporation",
6 "width": 8,
7 "height": 3,
8 "layouts": {
9 "LAYOUT": {
10 "layout": [
11 {"x":0, "y":0, "h":2},
12 {"x":1, "y":0.25, "h":1.5},
13 {"x":2, "y":0, "h":2},
14 {"x":3.5, "y":0, "h":2},
15 {"x":4.5, "y":0, "h":2}
16 ]
17 }
18 }
19}
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/default/keymap.c b/keyboards/ploopyco/trackball_mini/keymaps/default/keymap.c
new file mode 100644
index 000000000..5e7c684d1
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/default/keymap.c
@@ -0,0 +1,28 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include QMK_KEYBOARD_H
20
21// safe range starts at `PLOOPY_SAFE_RANGE` instead.
22
23const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
24 [0] = LAYOUT( /* Base */
25 KC_BTN1, KC_BTN3, KC_BTN2,
26 KC_BTN4, KC_BTN5
27 ),
28};
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/default/readme.md b/keyboards/ploopyco/trackball_mini/keymaps/default/readme.md
new file mode 100644
index 000000000..ebb90d299
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/default/readme.md
@@ -0,0 +1,3 @@
1The default keymap for the Ploopy Trackball Mini.
2
3Note that kits bought from PloopyCo actually ship with the VIA keymap, not this one. \ No newline at end of file
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c
new file mode 100644
index 000000000..7784bc855
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c
@@ -0,0 +1,66 @@
1/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
2 * Copyright 2019 Sunjun Kim
3 * Copyright 2020 Ploopy Corporation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include QMK_KEYBOARD_H
19
20// used for tracking the state
21bool is_drag_scroll = false;
22
23enum custom_keycodes {
24 DRAG_SCROLL = PLOOPY_SAFE_RANGE,
25};
26
27bool process_record_user(uint16_t keycode, keyrecord_t *record) {
28 switch (keycode) {
29 case DRAG_SCROLL:
30 if (record->event.pressed) {
31 // this toggles the state each time you tap it
32 is_drag_scroll ^= 1;
33 }
34 break;
35 }
36 return true;
37}
38
39// The real magic is here.
40// This function is called to translate the processed sensor movement
41// from the mouse sensor and translates it into x and y movement for
42// the mouse report. Normally. So if "drag scroll" is toggled on,
43// moving the ball scrolls instead. You could remove the x or y here
44// to only scroll in one direction, if you wanted, as well. In fact,
45// there is no reason that you need to send this to the mouse report.
46// You could have it register a key, instead.
47void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
48 if (is_drag_scroll) {
49 mouse_report->h = x;
50 mouse_report->v = y;
51 } else {
52 mouse_report->x = x;
53 mouse_report->y = y;
54 }
55}
56
57const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
58 [0] = LAYOUT( /* Base */
59 KC_BTN1, KC_BTN3, KC_BTN2,
60 KC_BTN4, LT(1, KC_BTN5)
61 ),
62 [1] = LAYOUT(
63 DRAG_SCROLL, _______, _______,
64 _______, _______
65 )
66};
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/readme.md b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/readme.md
new file mode 100644
index 000000000..362821832
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/readme.md
@@ -0,0 +1,5 @@
1# The Drag Scroll keymap for the Ploopy Trackball Mini
2
3This is a sample keymap showing off what you can do with the custom callback drivers.
4
5This particular example enables "drag scrolling". The movement of the ball is used to scroll up and down. \ No newline at end of file
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/via/config.h b/keyboards/ploopyco/trackball_mini/keymaps/via/config.h
new file mode 100644
index 000000000..0ba4c7e0c
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/via/config.h
@@ -0,0 +1,21 @@
1/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
2 * Copyright 2019 Sunjun Kim
3 * Copyright 2020 Ploopy Corporation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#define DYNAMIC_KEYMAP_LAYER_COUNT 8
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/via/keymap.c b/keyboards/ploopyco/trackball_mini/keymaps/via/keymap.c
new file mode 100644
index 000000000..31539be2e
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/via/keymap.c
@@ -0,0 +1,30 @@
1/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
2 * Copyright 2019 Sunjun Kim
3 * Copyright 2020 Ploopy Corporation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include QMK_KEYBOARD_H
19
20
21const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
22 [0] = LAYOUT( KC_BTN1, KC_BTN3, KC_BTN2, KC_BTN4, KC_BTN5 ),
23 [1] = LAYOUT( _______, _______, _______, _______, _______ ),
24 [2] = LAYOUT( _______, _______, _______, _______, _______ ),
25 [3] = LAYOUT( _______, _______, _______, _______, _______ ),
26 [4] = LAYOUT( _______, _______, _______, _______, _______ ),
27 [5] = LAYOUT( _______, _______, _______, _______, _______ ),
28 [6] = LAYOUT( _______, _______, _______, _______, _______ ),
29 [7] = LAYOUT( _______, _______, _______, _______, _______ )
30};
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/via/rules.mk b/keyboards/ploopyco/trackball_mini/keymaps/via/rules.mk
new file mode 100644
index 000000000..1e5b99807
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/via/rules.mk
@@ -0,0 +1 @@
VIA_ENABLE = yes
diff --git a/keyboards/ploopyco/trackball_mini/readme.md b/keyboards/ploopyco/trackball_mini/readme.md
new file mode 100644
index 000000000..8b8482a38
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/readme.md
@@ -0,0 +1,75 @@
1
2# Ploopy Trackball Mini
3
4![Ploopyco Trackball Mini](mini.jpg)
5
6It's a DIY, QMK Powered Trackball...Mini!
7
8* Maintainer: [PloopyCo](https://github.com/ploopyco)
9* Key contributors: [Drashna Jael're](https://github.com/drashna/), [Germ](https://github.com/germ/)
10* Hardware Supported: ATMega32u4 16MHz(5v)
11* Hardware Availability: [Store](https://ploopy.co), [GitHub](https://github.com/ploopyco)
12
13Make example for this trackball (after setting up your build environment):
14
15 make ploopyco/trackball_mini/rev1_001:default:flash
16 make ploopyco/trackball_mini/rev1_001:via:flash
17
18To jump to the bootloader, hold down "Button 4" (immediate right of the ball)
19
20See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
21
22## Hardware Reset Button
23
24The Ploopy Mini has a handy bootloader reset mechanism: two via pins on the board, designated by the reference designator `MCU.J.X BOOTLOADER`. If you stick an uninsulated paperclip or a pair of metal tweezers into both holes and plug in the Mini, it will start in bootloader mode.
25
26## Revisions
27
28Occasionally, new revisions of the PCB will be released. Every board comes with a designator that looks something like `R1.001`.
29
30Match the firmware that you flash onto the board with the designator on the board.
31
32# Customzing your Ploopy Mini Trackball
33
34While 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 using 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.
35
36The default behavior for this is:
37
38```c
39void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
40 mouse_report->h = h;
41 mouse_report->v = v;
42}
43
44void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
45 mouse_report->x = x;
46 mouse_report->y = y;
47}
48```
49
50This should allow you to more heavily customize the behavior.
51
52Alternatively, the `process_wheel` and `process_mouse` functions can both be replaced too, to allow for even more functionality.
53
54Additionally, you can change the DPI/CPI or speed of the trackball by calling `adns_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 375, 750, and 1375, but can be changed. 750 is the default.
55
56To configure/set your own array, there are two defines to use, `PLOOPY_DPI_OPTIONS` to set the array, and `PLOOPY_DPI_DEFAULT`.
57
58```c
59#define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375}
60#define PLOOPY_DPI_DEFAULT 1
61```
62
63The `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.
64
65The `DPI_CONFIG` macro will cycle through the values in the array, each time you hit it. It stores this value in persistent memory, so it will load it the next time the device powers up.
66
67## Fuse settings
68
69When flashing the bootloader, use the following fuse settings:
70
71| Fuse | Setting |
72|----------|-------------|
73| Low | `0x5E` |
74| High | `0x99` |
75| Extended | `0xC3` | \ No newline at end of file
diff --git a/keyboards/ploopyco/trackball_mini/rev1_001/config.h b/keyboards/ploopyco/trackball_mini/rev1_001/config.h
new file mode 100644
index 000000000..3f5941dec
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rev1_001/config.h
@@ -0,0 +1,40 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22/*
23 * Keyboard Matrix Assignments
24 *
25 * Change this to how you wired your keyboard
26 * COLS: AVR pins used for columns, left to right
27 * ROWS: AVR pins used for rows, top to bottom
28 * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
29 * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
30 *
31 */
32#define DIRECT_PINS \
33 { \
34 { D4, D2, E6, D7, B6 } \
35 }
36
37// These pins are not broken out, and cannot be used normally.
38// They are set as output and pulled high, by default
39#define UNUSED_PINS \
40 { B5, C7, D0, D1, D3, D5, D6, F1, F3, F5, F6, F7 }
diff --git a/keyboards/ploopyco/trackball_mini/rev1_001/readme.md b/keyboards/ploopyco/trackball_mini/rev1_001/readme.md
new file mode 100644
index 000000000..e8a5a918e
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rev1_001/readme.md
@@ -0,0 +1 @@
See the main readme for more details. This is just here for when future revisions are released.
diff --git a/keyboards/ploopyco/trackball_mini/rev1_001/rev1_001.h b/keyboards/ploopyco/trackball_mini/rev1_001/rev1_001.h
new file mode 100644
index 000000000..4f34e17dd
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rev1_001/rev1_001.h
@@ -0,0 +1,22 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "trackball_mini.h"
diff --git a/keyboards/ploopyco/trackball_mini/rev1_001/rules.mk b/keyboards/ploopyco/trackball_mini/rev1_001/rules.mk
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rev1_001/rules.mk
diff --git a/keyboards/ploopyco/trackball_mini/rules.mk b/keyboards/ploopyco/trackball_mini/rules.mk
new file mode 100644
index 000000000..58fad239f
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rules.mk
@@ -0,0 +1,32 @@
1# MCU name
2MCU = atmega32u4
3
4# Processor frequency
5F_CPU = 16000000
6
7# Bootloader selection
8BOOTLOADER = atmel-dfu
9
10# Build Options
11# change yes to no to disable
12#
13BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
14EXTRAKEY_ENABLE = yes # Audio control and System control
15CONSOLE_ENABLE = yes # Console for debug
16COMMAND_ENABLE = no # Commands for debug and configuration
17# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
18SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
19# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
20NKRO_ENABLE = no # USB Nkey Rollover
21BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
22RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
23UNICODE_ENABLE = no # Unicode
24BLUETOOTH_ENABLE = no # Enable Bluetooth
25AUDIO_ENABLE = no # Audio output
26POINTING_DEVICE_ENABLE = yes
27MOUSEKEY_ENABLE = no # Mouse keys
28
29QUANTUM_LIB_SRC += analog.c
30SRC += adns5050.c opt_encoder.c
31
32DEFAULT_FOLDER = ploopyco/trackball_mini/rev1_001
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.c b/keyboards/ploopyco/trackball_mini/trackball_mini.c
new file mode 100644
index 000000000..4ae5df083
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.c
@@ -0,0 +1,235 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "trackball_mini.h"
21
22#ifndef OPT_DEBOUNCE
23# define OPT_DEBOUNCE 5 // (ms) Time between scroll events
24#endif
25
26#ifndef SCROLL_BUTT_DEBOUNCE
27# define SCROLL_BUTT_DEBOUNCE 100 // (ms) Time between scroll events
28#endif
29
30#ifndef OPT_THRES
31# define OPT_THRES 150 // (0-1024) Threshold for actication
32#endif
33
34#ifndef OPT_SCALE
35# define OPT_SCALE 1 // Multiplier for wheel
36#endif
37
38#ifndef PLOOPY_DPI_OPTIONS
39# define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 }
40# ifndef PLOOPY_DPI_DEFAULT
41# define PLOOPY_DPI_DEFAULT 2
42# endif
43#endif
44
45#ifndef PLOOPY_DPI_DEFAULT
46# define PLOOPY_DPI_DEFAULT 1
47#endif
48
49// Transformation constants for delta-X and delta-Y
50const static float ADNS_X_TRANSFORM = -1.0;
51const static float ADNS_Y_TRANSFORM = 1.0;
52
53keyboard_config_t keyboard_config;
54uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
55#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
56
57// TODO: Implement libinput profiles
58// https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html
59// Compile time accel selection
60// Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC
61
62// Trackball State
63bool is_scroll_clicked = false;
64bool BurstState = false; // init burst state for Trackball module
65uint16_t MotionStart = 0; // Timer for accel, 0 is resting state
66uint16_t lastScroll = 0; // Previous confirmed wheel event
67uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
68uint8_t OptLowPin = OPT_ENC1;
69bool debug_encoder = false;
70
71__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
72 mouse_report->h = h;
73 mouse_report->v = v;
74}
75
76__attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) {
77 // If the mouse wheel was just released, do not scroll.
78 if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE)
79 return;
80
81 // Limit the number of scrolls per unit time.
82 if (timer_elapsed(lastScroll) < OPT_DEBOUNCE)
83 return;
84
85 // Don't scroll if the middle button is depressed.
86 if (is_scroll_clicked) {
87#ifndef IGNORE_SCROLL_CLICK
88 return;
89#endif
90 }
91
92 lastScroll = timer_read();
93 uint16_t p1 = adc_read(OPT_ENC1_MUX);
94 uint16_t p2 = adc_read(OPT_ENC2_MUX);
95
96 if (debug_encoder)
97 dprintf("OPT1: %d, OPT2: %d\n", p1, p2);
98
99 uint8_t dir = opt_encoder_handler(p1, p2);
100
101 if (dir == 0)
102 return;
103
104 process_wheel_user(mouse_report, mouse_report->h, (int)(mouse_report->v + (dir * OPT_SCALE)));
105}
106
107__attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
108 // x and y are swapped
109 // the sensor is rotated
110 // by 90 degrees
111 int16_t temp = x;
112 x = y;
113 y = temp;
114
115 // Apply delta-X and delta-Y transformations.
116 float xt = (float) x * ADNS_X_TRANSFORM;
117 float yt = (float) y * ADNS_Y_TRANSFORM;
118
119 int16_t xti = xt;
120 int16_t yti = yt;
121
122 mouse_report->x = xti;
123 mouse_report->y = yti;
124}
125
126__attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) {
127 report_adns_t data = adns_read_burst();
128
129 if (data.dx != 0 || data.dy != 0) {
130 if (debug_mouse)
131 dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
132
133 process_mouse_user(mouse_report, data.dx, data.dy);
134 }
135}
136
137bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
138 xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
139
140 // Update Timer to prevent accidental scrolls
141 if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
142 lastMidClick = timer_read();
143 is_scroll_clicked = record->event.pressed;
144 }
145
146 if (!process_record_user(keycode, record))
147 return false;
148
149 if (keycode == DPI_CONFIG && record->event.pressed) {
150 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
151 eeconfig_update_kb(keyboard_config.raw);
152 adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
153 }
154
155/* If Mousekeys is disabled, then use handle the mouse button
156 * keycodes. This makes things simpler, and allows usage of
157 * the keycodes in a consistent manner. But only do this if
158 * Mousekeys is not enable, so it's not handled twice.
159 */
160#ifndef MOUSEKEY_ENABLE
161 if (IS_MOUSEKEY_BUTTON(keycode)) {
162 report_mouse_t currentReport = pointing_device_get_report();
163 if (record->event.pressed) {
164 currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
165 } else {
166 currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
167 }
168 pointing_device_set_report(currentReport);
169 pointing_device_send();
170 }
171#endif
172
173 return true;
174}
175
176// Hardware Setup
177void keyboard_pre_init_kb(void) {
178 // debug_enable = true;
179 // debug_matrix = true;
180 debug_mouse = true;
181 // debug_encoder = true;
182
183 setPinInput(OPT_ENC1);
184 setPinInput(OPT_ENC2);
185
186 /* Ground all output pins connected to ground. This provides additional
187 * pathways to ground. If you're messing with this, know this: driving ANY
188 * of these pins high will cause a short. On the MCU. Ka-blooey.
189 */
190#ifdef UNUSED_PINS
191 const pin_t unused_pins[] = UNUSED_PINS;
192
193 for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
194 setPinOutput(unused_pins[i]);
195 writePinLow(unused_pins[i]);
196 }
197#endif
198
199 keyboard_pre_init_user();
200}
201
202void pointing_device_init(void) {
203 adns_init();
204 opt_encoder_init();
205}
206
207void pointing_device_task(void) {
208 report_mouse_t mouse_report = pointing_device_get_report();
209 process_wheel(&mouse_report);
210 process_mouse(&mouse_report);
211 pointing_device_set_report(mouse_report);
212 pointing_device_send();
213}
214
215void eeconfig_init_kb(void) {
216 keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT;
217 eeconfig_update_kb(keyboard_config.raw);
218 eeconfig_init_user();
219}
220
221void matrix_init_kb(void) {
222 // is safe to just read DPI setting since matrix init
223 // comes before pointing device init.
224 keyboard_config.raw = eeconfig_read_kb();
225 if (keyboard_config.dpi_config > DPI_OPTION_SIZE) {
226 eeconfig_init_kb();
227 }
228 matrix_init_user();
229}
230
231void keyboard_post_init_kb(void) {
232 adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
233
234 keyboard_post_init_user();
235}
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.h b/keyboards/ploopyco/trackball_mini/trackball_mini.h
new file mode 100644
index 000000000..b9754cbc7
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.h
@@ -0,0 +1,54 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "quantum.h"
23#include "adns5050.h"
24#include "analog.h"
25#include "opt_encoder.h"
26#include "pointing_device.h"
27
28// Sensor defs
29#define OPT_ENC1 F0
30#define OPT_ENC2 F4
31#define OPT_ENC1_MUX 0
32#define OPT_ENC2_MUX 4
33
34void process_mouse(report_mouse_t* mouse_report);
35void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y);
36void process_wheel(report_mouse_t* mouse_report);
37void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v);
38
39#define LAYOUT(BL, BM, BR, BF, BB) \
40 { {BL, BM, BR, BF, BB}, }
41
42typedef union {
43 uint32_t raw;
44 struct {
45 uint8_t dpi_config;
46 };
47} keyboard_config_t;
48
49extern keyboard_config_t keyboard_config;
50
51enum ploopy_keycodes {
52 DPI_CONFIG = SAFE_RANGE,
53 PLOOPY_SAFE_RANGE,
54};
diff --git a/keyboards/ploopyco/trackball_nano/config.h b/keyboards/ploopyco/trackball_nano/config.h
new file mode 100644
index 000000000..54fe840ce
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/config.h
@@ -0,0 +1,48 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "config_common.h"
23
24/* USB Device descriptor parameter */
25#define VENDOR_ID 0x5043
26#define PRODUCT_ID 0x1EAB
27#define DEVICE_VER 0x0001
28#define MANUFACTURER PloopyCo
29#define PRODUCT Trackball Nano
30
31/* key matrix size */
32#define MATRIX_ROWS 1
33#define MATRIX_COLS 1
34
35/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
36#define DEBOUNCE 0
37
38/* disable action features */
39//#define NO_ACTION_LAYER
40//#define NO_ACTION_TAPPING
41//#define NO_ACTION_ONESHOT
42#define NO_ACTION_MACRO
43#define NO_ACTION_FUNCTION
44
45/* Much more so than a keyboard, speed matters for a mouse. So we'll go for as high
46 a polling rate as possible. */
47#define USB_POLLING_INTERVAL_MS 1
48#define USB_MAX_POWER_CONSUMPTION 100
diff --git a/keyboards/ploopyco/trackball_nano/info.json b/keyboards/ploopyco/trackball_nano/info.json
new file mode 100644
index 000000000..a788ce9eb
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/info.json
@@ -0,0 +1,13 @@
1{
2 "keyboard_name": "Ploopy Trackball Nano",
3 "url": "www.ploopy.co",
4 "maintainer": "ploopyco",
5 "manufacturer": "Ploopy Corporation",
6 "layouts": {
7 "LAYOUT": {
8 "layout": [
9 {"x":0, "y":0}
10 ]
11 }
12 }
13}
diff --git a/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c b/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c
new file mode 100644
index 000000000..1140c30a1
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c
@@ -0,0 +1,23 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include QMK_KEYBOARD_H
20
21// safe range starts at `PLOOPY_SAFE_RANGE` instead.
22
23// placeholder file so it will compile \ No newline at end of file
diff --git a/keyboards/ploopyco/trackball_nano/keymaps/default/readme.md b/keyboards/ploopyco/trackball_nano/keymaps/default/readme.md
new file mode 100644
index 000000000..ebb90d299
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/keymaps/default/readme.md
@@ -0,0 +1,3 @@
1The default keymap for the Ploopy Trackball Mini.
2
3Note that kits bought from PloopyCo actually ship with the VIA keymap, not this one. \ No newline at end of file
diff --git a/keyboards/ploopyco/trackball_nano/readme.md b/keyboards/ploopyco/trackball_nano/readme.md
new file mode 100644
index 000000000..8a293602a
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/readme.md
@@ -0,0 +1,54 @@
1
2
3# Ploopy Trackball Nano
4
5![Ploopyco Trackball Nano](https://www.ploopy.co/uploads/b/113cb4122f867acc306a72a2741c5237a9b1d0db13abfe4e8e394cd466c4a311/_MG_7710_1614037372.jpg)
6
7It's a DIY, QMK Powered Trackball...Nano!
8
9* Maintainer: [PloopyCo](https://github.com/ploopyco)
10* Key contributors: [Drashna Jael're](https://github.com/drashna/), [Germ](https://github.com/germ/)
11* Hardware Supported: ATMega32u4 16MHz(5v)
12* Hardware Availability: [Store](https://ploopy.co/nano-trackball), [GitHub](https://github.com/ploopyco/nano-trackball)
13
14Make example for this trackball (after setting up your build environment):
15
16 make ploopyco/trackball_nano/rev1_001:default:flash
17 make ploopyco/trackball_nano/rev1_001:via:flash
18
19See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
20
21## Hardware Reset Button
22
23The Ploopy Nano has a handy bootloader reset mechanism: two via pins on the board, designated by the reference designator `MCU.J.X BOOTLOADER`. If you stick an uninsulated paperclip or a pair of metal tweezers into both holes and plug in the Nano, it will start in bootloader mode.
24
25## Revisions
26
27Occasionally, new revisions of the PCB will be released. Every board comes with a designator that looks something like `R1.001`.
28
29Match the firmware that you flash onto the board with the designator on the board.
30
31# Customzing your Ploopy Nano Trackball
32
33You can change the DPI/CPI or speed of the trackball by calling `adns_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 375, 750, and 1375, but can be changed. 750 is the default.
34
35To configure/set your own array, there are two defines to use, `PLOOPY_DPI_OPTIONS` to set the array, and `PLOOPY_DPI_DEFAULT`.
36
37```c
38#define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375}
39#define PLOOPY_DPI_DEFAULT 1
40```
41
42The `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.
43
44The `DPI_CONFIG` macro will cycle through the values in the array, each time you hit it. It stores this value in persistent memory, so it will load it the next time the device powers up.
45
46## Fuse settings
47
48When flashing the bootloader, use the following fuse settings:
49
50| Fuse | Setting |
51|----------|-------------|
52| Low | `0x5E` |
53| High | `0x99` |
54| Extended | `0xC3` | \ No newline at end of file
diff --git a/keyboards/ploopyco/trackball_nano/rev1_001/config.h b/keyboards/ploopyco/trackball_nano/rev1_001/config.h
new file mode 100644
index 000000000..63780ef04
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rev1_001/config.h
@@ -0,0 +1,37 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22/*
23 * Keyboard Matrix Assignments
24 *
25 * Change this to how you wired your keyboard
26 * COLS: AVR pins used for columns, left to right
27 * ROWS: AVR pins used for rows, top to bottom
28 * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
29 * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
30 *
31 */
32#define DIRECT_PINS {}
33
34// These pins are not broken out, and cannot be used normally.
35// They are set as output and pulled high, by default
36#define UNUSED_PINS \
37 { B5, B6, C7, D0, D1, D2, D3, D4, D5, D6, D7, E6, F1, F3, F5, F6, F7 }
diff --git a/keyboards/ploopyco/trackball_nano/rev1_001/readme.md b/keyboards/ploopyco/trackball_nano/rev1_001/readme.md
new file mode 100644
index 000000000..052a17f39
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rev1_001/readme.md
@@ -0,0 +1 @@
See the main readme for more details. This is just here for when future revisions of the board are released.
diff --git a/keyboards/ploopyco/trackball_nano/rev1_001/rev1_001.h b/keyboards/ploopyco/trackball_nano/rev1_001/rev1_001.h
new file mode 100644
index 000000000..4f34e17dd
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rev1_001/rev1_001.h
@@ -0,0 +1,22 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "trackball_mini.h"
diff --git a/keyboards/ploopyco/trackball_nano/rev1_001/rules.mk b/keyboards/ploopyco/trackball_nano/rev1_001/rules.mk
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rev1_001/rules.mk
diff --git a/keyboards/ploopyco/trackball_nano/rules.mk b/keyboards/ploopyco/trackball_nano/rules.mk
new file mode 100644
index 000000000..0286194b9
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rules.mk
@@ -0,0 +1,32 @@
1# MCU name
2MCU = atmega32u4
3
4# Processor frequency
5F_CPU = 16000000
6
7# Bootloader selection
8BOOTLOADER = atmel-dfu
9
10# Build Options
11# change yes to no to disable
12#
13BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
14EXTRAKEY_ENABLE = yes # Audio control and System control
15CONSOLE_ENABLE = yes # Console for debug
16COMMAND_ENABLE = no # Commands for debug and configuration
17# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
18SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
19# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
20NKRO_ENABLE = no # USB Nkey Rollover
21BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
22RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
23UNICODE_ENABLE = no # Unicode
24BLUETOOTH_ENABLE = no # Enable Bluetooth
25AUDIO_ENABLE = no # Audio output
26POINTING_DEVICE_ENABLE = yes
27MOUSEKEY_ENABLE = no # Mouse keys
28
29QUANTUM_LIB_SRC += analog.c
30SRC += adns5050.c opt_encoder.c
31
32DEFAULT_FOLDER = ploopyco/trackball_nano/rev1_001
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.c b/keyboards/ploopyco/trackball_nano/trackball_nano.c
new file mode 100644
index 000000000..93cb60bd4
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/trackball_nano.c
@@ -0,0 +1,211 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "trackball_nano.h"
21
22#ifndef OPT_DEBOUNCE
23# define OPT_DEBOUNCE 5 // (ms) Time between scroll events
24#endif
25
26#ifndef SCROLL_BUTT_DEBOUNCE
27# define SCROLL_BUTT_DEBOUNCE 100 // (ms) Time between scroll events
28#endif
29
30#ifndef OPT_THRES
31# define OPT_THRES 150 // (0-1024) Threshold for actication
32#endif
33
34#ifndef OPT_SCALE
35# define OPT_SCALE 1 // Multiplier for wheel
36#endif
37
38#ifndef PLOOPY_DPI_OPTIONS
39# define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 }
40# ifndef PLOOPY_DPI_DEFAULT
41# define PLOOPY_DPI_DEFAULT 2
42# endif
43#endif
44
45#ifndef PLOOPY_DPI_DEFAULT
46# define PLOOPY_DPI_DEFAULT 1
47#endif
48
49const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { };
50
51// Transformation constants for delta-X and delta-Y
52const static float ADNS_X_TRANSFORM = -1.0;
53const static float ADNS_Y_TRANSFORM = 1.0;
54
55keyboard_config_t keyboard_config;
56uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
57#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
58
59// TODO: Implement libinput profiles
60// https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html
61// Compile time accel selection
62// Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC
63
64// Trackball State
65bool is_scroll_clicked = false;
66bool BurstState = false; // init burst state for Trackball module
67uint16_t MotionStart = 0; // Timer for accel, 0 is resting state
68uint16_t lastScroll = 0; // Previous confirmed wheel event
69uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
70uint8_t OptLowPin = OPT_ENC1;
71bool debug_encoder = false;
72
73__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
74 // There's no scroller on this device.
75 return;
76}
77
78__attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) {
79 // There's no scroller on this device.
80 return;
81}
82
83__attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
84 // x and y are swapped
85 // the sensor is rotated
86 // by 90 degrees
87 int16_t temp = x;
88 x = y;
89 y = temp;
90
91 // Apply delta-X and delta-Y transformations.
92 float xt = (float) x * ADNS_X_TRANSFORM;
93 float yt = (float) y * ADNS_Y_TRANSFORM;
94
95 int16_t xti = xt;
96 int16_t yti = yt;
97
98 mouse_report->x = xti;
99 mouse_report->y = yti;
100}
101
102__attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) {
103 report_adns_t data = adns_read_burst();
104
105 if (data.dx != 0 || data.dy != 0) {
106 if (debug_mouse)
107 dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
108
109 process_mouse_user(mouse_report, data.dx, data.dy);
110 }
111}
112
113bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
114 xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
115
116 // Update Timer to prevent accidental scrolls
117 if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
118 lastMidClick = timer_read();
119 is_scroll_clicked = record->event.pressed;
120 }
121
122 if (!process_record_user(keycode, record))
123 return false;
124
125 if (keycode == DPI_CONFIG && record->event.pressed) {
126 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
127 eeconfig_update_kb(keyboard_config.raw);
128 adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
129 }
130
131/* If Mousekeys is disabled, then use handle the mouse button
132 * keycodes. This makes things simpler, and allows usage of
133 * the keycodes in a consistent manner. But only do this if
134 * Mousekeys is not enable, so it's not handled twice.
135 */
136#ifndef MOUSEKEY_ENABLE
137 if (IS_MOUSEKEY_BUTTON(keycode)) {
138 report_mouse_t currentReport = pointing_device_get_report();
139 if (record->event.pressed) {
140 currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
141 } else {
142 currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
143 }
144 pointing_device_set_report(currentReport);
145 pointing_device_send();
146 }
147#endif
148
149 return true;
150}
151
152// Hardware Setup
153void keyboard_pre_init_kb(void) {
154 // debug_enable = true;
155 // debug_matrix = true;
156 debug_mouse = true;
157 // debug_encoder = true;
158
159 setPinInput(OPT_ENC1);
160 setPinInput(OPT_ENC2);
161
162 /* Ground all output pins connected to ground. This provides additional
163 * pathways to ground. If you're messing with this, know this: driving ANY
164 * of these pins high will cause a short. On the MCU. Ka-blooey.
165 */
166#ifdef UNUSED_PINS
167 const pin_t unused_pins[] = UNUSED_PINS;
168
169 for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
170 setPinOutput(unused_pins[i]);
171 writePinLow(unused_pins[i]);
172 }
173#endif
174
175 keyboard_pre_init_user();
176}
177
178void pointing_device_init(void) {
179 adns_init();
180 opt_encoder_init();
181}
182
183void pointing_device_task(void) {
184 report_mouse_t mouse_report = pointing_device_get_report();
185 process_wheel(&mouse_report);
186 process_mouse(&mouse_report);
187 pointing_device_set_report(mouse_report);
188 pointing_device_send();
189}
190
191void eeconfig_init_kb(void) {
192 keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT;
193 eeconfig_update_kb(keyboard_config.raw);
194 eeconfig_init_user();
195}
196
197void matrix_init_kb(void) {
198 // is safe to just read DPI setting since matrix init
199 // comes before pointing device init.
200 keyboard_config.raw = eeconfig_read_kb();
201 if (keyboard_config.dpi_config > DPI_OPTION_SIZE) {
202 eeconfig_init_kb();
203 }
204 matrix_init_user();
205}
206
207void keyboard_post_init_kb(void) {
208 adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
209
210 keyboard_post_init_user();
211}
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.h b/keyboards/ploopyco/trackball_nano/trackball_nano.h
new file mode 100644
index 000000000..4bffb0460
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/trackball_nano.h
@@ -0,0 +1,53 @@
1/* Copyright 2021 Colin Lam (Ploopy Corporation)
2 * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
3 * Copyright 2019 Sunjun Kim
4 * Copyright 2019 Hiroyuki Okada
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "quantum.h"
23#include "adns5050.h"
24#include "analog.h"
25#include "opt_encoder.h"
26#include "pointing_device.h"
27
28// Sensor defs
29#define OPT_ENC1 F0
30#define OPT_ENC2 F4
31#define OPT_ENC1_MUX 0
32#define OPT_ENC2_MUX 4
33
34void process_mouse(report_mouse_t* mouse_report);
35void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y);
36void process_wheel(report_mouse_t* mouse_report);
37void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v);
38
39#define LAYOUT(k00) {{ KC_NO }}
40
41typedef union {
42 uint32_t raw;
43 struct {
44 uint8_t dpi_config;
45 };
46} keyboard_config_t;
47
48extern keyboard_config_t keyboard_config;
49
50enum ploopy_keycodes {
51 DPI_CONFIG = SAFE_RANGE,
52 PLOOPY_SAFE_RANGE,
53};