summaryrefslogtreecommitdiff
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)
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 0000000000..fcf2f213e4
--- /dev/null
+++ b/keyboards/ploopyco/adns5050.c
@@ -0,0 +1,197 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 "adns5050.h"
+#include "quantum.h"
+#include "wait.h"
+
+#ifdef CONSOLE_ENABLE
+# include "print.h"
+#endif
+
+#ifndef OPTIC_ROTATED
+# define OPTIC_ROTATED false
+#endif
+
+// Definitions for the ADNS serial line.
+// These really ought to be defined in your config.h, but defaults are
+// here if you're really lazy.
+#ifndef ADNS_SCLK_PIN
+# define ADNS_SCLK_PIN B7
+#endif
+
+#ifndef ADNS_SDIO_PIN
+# define ADNS_SDIO_PIN C6
+#endif
+
+#ifndef ADNS_CS_PIN
+# define ADNS_CS_PIN B4
+#endif
+
+#ifdef CONSOLE_ENABLE
+void 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')); }
+#endif
+
+// Initialize the ADNS serial pins.
+void adns_init(void) {
+ setPinOutput(ADNS_SCLK_PIN);
+ setPinOutput(ADNS_SDIO_PIN);
+ setPinOutput(ADNS_CS_PIN);
+}
+
+// Perform a synchronization with the ADNS.
+// Just as with the serial protocol, this is used by the slave to send a
+// synchronization signal to the master.
+void adns_sync(void) {
+ writePinLow(ADNS_CS_PIN);
+ wait_us(1);
+ writePinHigh(ADNS_CS_PIN);
+}
+
+void adns_cs_select(void) {
+ writePinLow(ADNS_CS_PIN);
+}
+
+void adns_cs_deselect(void) {
+ writePinHigh(ADNS_CS_PIN);
+}
+
+uint8_t adns_serial_read(void) {
+ setPinInput(ADNS_SDIO_PIN);
+ uint8_t byte = 0;
+
+ for (uint8_t i = 0; i < 8; ++i) {
+ writePinLow(ADNS_SCLK_PIN);
+ wait_us(1);
+
+ byte = (byte << 1) | readPin(ADNS_SDIO_PIN);
+
+ writePinHigh(ADNS_SCLK_PIN);
+ wait_us(1);
+ }
+
+ return byte;
+}
+
+void adns_serial_write(uint8_t data) {
+ setPinOutput(ADNS_SDIO_PIN);
+
+ for (int8_t b = 7; b >= 0; b--) {
+ writePinLow(ADNS_SCLK_PIN);
+
+ if (data & (1 << b))
+ writePinHigh(ADNS_SDIO_PIN);
+ else
+ writePinLow(ADNS_SDIO_PIN);
+
+ wait_us(2);
+
+ writePinHigh(ADNS_SCLK_PIN);
+ }
+
+ // tSWR. See page 15 of the ADNS spec sheet.
+ // Technically, this is only necessary if the next operation is an SDIO
+ // read. This is not guaranteed to be the case, but we're being lazy.
+ wait_us(4);
+
+ // Note that tSWW is never necessary. All write operations require at
+ // least 32us, which exceeds tSWW, so there's never a need to wait for it.
+}
+
+// Read a byte of data from a register on the ADNS.
+// Don't forget to use the register map (as defined in the header file).
+uint8_t adns_read_reg(uint8_t reg_addr) {
+ adns_cs_select();
+
+ adns_serial_write(reg_addr);
+
+ // We don't need a minimum tSRAD here. That's because a 4ms wait time is
+ // already included in adns_serial_write(), so we're good.
+ // See page 10 and 15 of the ADNS spec sheet.
+ //wait_us(4);
+
+ uint8_t byte = adns_serial_read();
+
+ // tSRW & tSRR. See page 15 of the ADNS spec sheet.
+ // Technically, this is only necessary if the next operation is an SDIO
+ // read or write. This is not guaranteed to be the case.
+ // Honestly, this wait could probably be removed.
+ wait_us(1);
+
+ adns_cs_deselect();
+
+ return byte;
+}
+
+void adns_write_reg(uint8_t reg_addr, uint8_t data) {
+ adns_cs_select();
+ adns_serial_write(reg_addr);
+ adns_serial_write(data);
+ adns_cs_deselect();
+}
+
+report_adns_t adns_read_burst(void) {
+ adns_cs_select();
+
+ report_adns_t data;
+ data.dx = 0;
+ data.dy = 0;
+
+ adns_serial_write(REG_MOTION_BURST);
+
+ // We don't need a minimum tSRAD here. That's because a 4ms wait time is
+ // already included in adns_serial_write(), so we're good.
+ // See page 10 and 15 of the ADNS spec sheet.
+ //wait_us(4);
+
+ uint8_t x = adns_serial_read();
+ uint8_t y = adns_serial_read();
+
+ // Burst mode returns a bunch of other shit that we don't really need.
+ // Setting CS to high ends burst mode early.
+ adns_cs_deselect();
+
+ data.dx = convert_twoscomp(x);
+ data.dy = convert_twoscomp(y);
+
+ return data;
+}
+
+// Convert a two's complement byte from an unsigned data type into a signed
+// data type.
+int8_t convert_twoscomp(uint8_t data) {
+ if ((data & 0x80) == 0x80)
+ return -128 + (data & 0x7F);
+ else
+ return data;
+}
+
+// Don't forget to use the definitions for CPI in the header file.
+void adns_set_cpi(uint8_t cpi) {
+ adns_write_reg(REG_MOUSE_CONTROL2, cpi);
+}
+
+bool adns_check_signature(void) {
+ uint8_t pid = adns_read_reg(REG_PRODUCT_ID);
+ uint8_t rid = adns_read_reg(REG_REVISION_ID);
+ uint8_t pid2 = adns_read_reg(REG_PRODUCT_ID2);
+
+ return (pid == 0x12 && rid == 0x01 && pid2 == 0x26);
+}
diff --git a/keyboards/ploopyco/adns5050.h b/keyboards/ploopyco/adns5050.h
new file mode 100644
index 0000000000..ff8e8f78e9
--- /dev/null
+++ b/keyboards/ploopyco/adns5050.h
@@ -0,0 +1,79 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 <stdbool.h>
+
+// Registers
+#define REG_PRODUCT_ID 0x00
+#define REG_REVISION_ID 0x01
+#define REG_MOTION 0x02
+#define REG_DELTA_X 0x03
+#define REG_DELTA_Y 0x04
+#define REG_SQUAL 0x05
+#define REG_SHUTTER_UPPER 0x06
+#define REG_SHUTTER_LOWER 0x07
+#define REG_MAXIMUM_PIXEL 0x08
+#define REG_PIXEL_SUM 0x09
+#define REG_MINIMUM_PIXEL 0x0a
+#define REG_PIXEL_GRAB 0x0b
+#define REG_MOUSE_CONTROL 0x0d
+#define REG_MOUSE_CONTROL2 0x19
+#define REG_LED_DC_MODE 0x22
+#define REG_CHIP_RESET 0x3a
+#define REG_PRODUCT_ID2 0x3e
+#define REG_INV_REV_ID 0x3f
+#define REG_MOTION_BURST 0x63
+
+// CPI values
+#define CPI125 0x11
+#define CPI250 0x12
+#define CPI375 0x13
+#define CPI500 0x14
+#define CPI625 0x15
+#define CPI750 0x16
+#define CPI875 0x17
+#define CPI1000 0x18
+#define CPI1125 0x19
+#define CPI1250 0x1a
+#define CPI1375 0x1b
+
+#ifdef CONSOLE_ENABLE
+void print_byte(uint8_t byte);
+#endif
+
+typedef struct {
+ int8_t dx;
+ int8_t dy;
+} report_adns_t;
+
+// A bunch of functions to implement the ADNS5050-specific serial protocol.
+// Note that the "serial.h" driver is insufficient, because it does not
+// manually manipulate a serial clock signal.
+void adns_init(void);
+void adns_sync(void);
+uint8_t adns_serial_read(void);
+void adns_serial_write(uint8_t data);
+uint8_t adns_read_reg(uint8_t reg_addr);
+void adns_write_reg(uint8_t reg_addr, uint8_t data);
+report_adns_t adns_read_burst(void);
+int8_t convert_twoscomp(uint8_t data);
+void adns_set_cpi(uint8_t cpi);
+bool 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 0000000000..7a94e193fb
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/config.h
@@ -0,0 +1,59 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 "config_common.h"
+
+/* USB Device descriptor parameter */
+#define VENDOR_ID 0x5043
+#define PRODUCT_ID 0x1EAB
+#define DEVICE_VER 0x0001
+#define MANUFACTURER PloopyCo
+#define PRODUCT Trackball Mini
+
+/* key matrix size */
+#define MATRIX_ROWS 1
+#define MATRIX_COLS 5
+
+
+/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
+#define DEBOUNCE 5
+
+/* define if matrix has ghost (lacks anti-ghosting diodes) */
+//#define MATRIX_HAS_GHOST
+
+/* disable action features */
+//#define NO_ACTION_LAYER
+//#define NO_ACTION_TAPPING
+//#define NO_ACTION_ONESHOT
+#define NO_ACTION_MACRO
+#define NO_ACTION_FUNCTION
+
+/* Much more so than a keyboard, speed matters for a mouse. So we'll go for as high
+ a polling rate as possible. */
+#define USB_POLLING_INTERVAL_MS 1
+#define USB_MAX_POWER_CONSUMPTION 100
+
+/* Bootmagic Lite key configuration */
+#define BOOTMAGIC_LITE_ROW 0
+#define BOOTMAGIC_LITE_COLUMN 3
+
+// If board has a debug LED, you can enable it by defining this
+// #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 0000000000..7b30e0595f
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/info.json
@@ -0,0 +1,19 @@
+{
+ "keyboard_name": "Ploopy Trackball Mini",
+ "url": "www.ploopy.co",
+ "maintainer": "ploopyco",
+ "manufacturer": "Ploopy Corporation",
+ "width": 8,
+ "height": 3,
+ "layouts": {
+ "LAYOUT": {
+ "layout": [
+ {"x":0, "y":0, "h":2},
+ {"x":1, "y":0.25, "h":1.5},
+ {"x":2, "y":0, "h":2},
+ {"x":3.5, "y":0, "h":2},
+ {"x":4.5, "y":0, "h":2}
+ ]
+ }
+ }
+}
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 0000000000..5e7c684d19
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/default/keymap.c
@@ -0,0 +1,28 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 QMK_KEYBOARD_H
+
+// safe range starts at `PLOOPY_SAFE_RANGE` instead.
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+ [0] = LAYOUT( /* Base */
+ KC_BTN1, KC_BTN3, KC_BTN2,
+ KC_BTN4, KC_BTN5
+ ),
+};
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 0000000000..ebb90d2999
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/default/readme.md
@@ -0,0 +1,3 @@
+The default keymap for the Ploopy Trackball Mini.
+
+Note 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 0000000000..7784bc8553
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c
@@ -0,0 +1,66 @@
+/* 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 QMK_KEYBOARD_H
+
+// used for tracking the state
+bool is_drag_scroll = false;
+
+enum custom_keycodes {
+ DRAG_SCROLL = PLOOPY_SAFE_RANGE,
+};
+
+bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ switch (keycode) {
+ case DRAG_SCROLL:
+ if (record->event.pressed) {
+ // this toggles the state each time you tap it
+ is_drag_scroll ^= 1;
+ }
+ break;
+ }
+ return true;
+}
+
+// The real magic is here.
+// This function is called to translate the processed sensor movement
+// from the mouse sensor and translates it into x and y movement for
+// the mouse report. Normally. So if "drag scroll" is toggled on,
+// moving the ball scrolls instead. You could remove the x or y here
+// to only scroll in one direction, if you wanted, as well. In fact,
+// there is no reason that you need to send this to the mouse report.
+// You could have it register a key, instead.
+void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
+ if (is_drag_scroll) {
+ mouse_report->h = x;
+ mouse_report->v = y;
+ } else {
+ mouse_report->x = x;
+ mouse_report->y = y;
+ }
+}
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+ [0] = LAYOUT( /* Base */
+ KC_BTN1, KC_BTN3, KC_BTN2,
+ KC_BTN4, LT(1, KC_BTN5)
+ ),
+ [1] = LAYOUT(
+ DRAG_SCROLL, _______, _______,
+ _______, _______
+ )
+};
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 0000000000..362821832f
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/readme.md
@@ -0,0 +1,5 @@
+# The Drag Scroll keymap for the Ploopy Trackball Mini
+
+This is a sample keymap showing off what you can do with the custom callback drivers.
+
+This 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 0000000000..0ba4c7e0c8
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/via/config.h
@@ -0,0 +1,21 @@
+/* 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/>.
+ */
+
+#pragma once
+
+#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 0000000000..31539be2ec
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/keymaps/via/keymap.c
@@ -0,0 +1,30 @@
+/* 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 QMK_KEYBOARD_H
+
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+ [0] = LAYOUT( KC_BTN1, KC_BTN3, KC_BTN2, KC_BTN4, KC_BTN5 ),
+ [1] = LAYOUT( _______, _______, _______, _______, _______ ),
+ [2] = LAYOUT( _______, _______, _______, _______, _______ ),
+ [3] = LAYOUT( _______, _______, _______, _______, _______ ),
+ [4] = LAYOUT( _______, _______, _______, _______, _______ ),
+ [5] = LAYOUT( _______, _______, _______, _______, _______ ),
+ [6] = LAYOUT( _______, _______, _______, _______, _______ ),
+ [7] = LAYOUT( _______, _______, _______, _______, _______ )
+};
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 0000000000..1e5b99807c
--- /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 0000000000..8b8482a387
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/readme.md
@@ -0,0 +1,75 @@
+
+# Ploopy Trackball Mini
+
+![Ploopyco Trackball Mini](mini.jpg)
+
+It's a DIY, QMK Powered Trackball...Mini!
+
+* Maintainer: [PloopyCo](https://github.com/ploopyco)
+* Key contributors: [Drashna Jael're](https://github.com/drashna/), [Germ](https://github.com/germ/)
+* Hardware Supported: ATMega32u4 16MHz(5v)
+* Hardware Availability: [Store](https://ploopy.co), [GitHub](https://github.com/ploopyco)
+
+Make example for this trackball (after setting up your build environment):
+
+ make ploopyco/trackball_mini/rev1_001:default:flash
+ make ploopyco/trackball_mini/rev1_001:via:flash
+
+To jump to the bootloader, hold down "Button 4" (immediate right of the ball)
+
+See 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).
+
+## Hardware Reset Button
+
+The 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.
+
+## Revisions
+
+Occasionally, new revisions of the PCB will be released. Every board comes with a designator that looks something like `R1.001`.
+
+Match the firmware that you flash onto the board with the designator on the board.
+
+# Customzing your Ploopy Mini Trackball
+
+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 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.
+
+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 `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.
+
+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 { CPI375, CPI750, CPI1375}
+#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. It stores this value in persistent memory, so it will load it the next time the device powers up.
+
+## Fuse settings
+
+When flashing the bootloader, use the following fuse settings:
+
+| Fuse | Setting |
+|----------|-------------|
+| Low | `0x5E` |
+| High | `0x99` |
+| 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 0000000000..3f5941decc
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rev1_001/config.h
@@ -0,0 +1,40 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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
+
+/*
+ * Keyboard Matrix Assignments
+ *
+ * Change this to how you wired your keyboard
+ * COLS: AVR pins used for columns, left to right
+ * ROWS: AVR pins used for rows, top to bottom
+ * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
+ * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
+ *
+ */
+#define DIRECT_PINS \
+ { \
+ { D4, D2, E6, D7, B6 } \
+ }
+
+// These pins are not broken out, and cannot be used normally.
+// They are set as output and pulled high, by default
+#define UNUSED_PINS \
+ { 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 0000000000..e8a5a918e4
--- /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 0000000000..4f34e17dd4
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rev1_001/rev1_001.h
@@ -0,0 +1,22 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 "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 0000000000..e69de29bb2
--- /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 0000000000..58fad239f4
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/rules.mk
@@ -0,0 +1,32 @@
+# MCU name
+MCU = atmega32u4
+
+# Processor frequency
+F_CPU = 16000000
+
+# Bootloader selection
+BOOTLOADER = atmel-dfu
+
+# Build Options
+# change yes to no to disable
+#
+BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
+EXTRAKEY_ENABLE = yes # Audio control and System control
+CONSOLE_ENABLE = yes # Console for debug
+COMMAND_ENABLE = no # Commands for debug and configuration
+# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
+SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
+# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
+NKRO_ENABLE = no # USB Nkey Rollover
+BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
+UNICODE_ENABLE = no # Unicode
+BLUETOOTH_ENABLE = no # Enable Bluetooth
+AUDIO_ENABLE = no # Audio output
+POINTING_DEVICE_ENABLE = yes
+MOUSEKEY_ENABLE = no # Mouse keys
+
+QUANTUM_LIB_SRC += analog.c
+SRC += adns5050.c opt_encoder.c
+
+DEFAULT_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 0000000000..4ae5df0837
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.c
@@ -0,0 +1,235 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 "trackball_mini.h"
+
+#ifndef OPT_DEBOUNCE
+# define OPT_DEBOUNCE 5 // (ms) Time between scroll events
+#endif
+
+#ifndef SCROLL_BUTT_DEBOUNCE
+# define SCROLL_BUTT_DEBOUNCE 100 // (ms) Time between scroll events
+#endif
+
+#ifndef OPT_THRES
+# define OPT_THRES 150 // (0-1024) Threshold for actication
+#endif
+
+#ifndef OPT_SCALE
+# define OPT_SCALE 1 // Multiplier for wheel
+#endif
+
+#ifndef PLOOPY_DPI_OPTIONS
+# define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 }
+# ifndef PLOOPY_DPI_DEFAULT
+# define PLOOPY_DPI_DEFAULT 2
+# endif
+#endif
+
+#ifndef PLOOPY_DPI_DEFAULT
+# define PLOOPY_DPI_DEFAULT 1
+#endif
+
+// Transformation constants for delta-X and delta-Y
+const static float ADNS_X_TRANSFORM = -1.0;
+const static float ADNS_Y_TRANSFORM = 1.0;
+
+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_scroll_clicked = false;
+bool BurstState = false; // init burst state for Trackball module
+uint16_t MotionStart = 0; // Timer for accel, 0 is resting state
+uint16_t lastScroll = 0; // Previous confirmed wheel event
+uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
+uint8_t OptLowPin = OPT_ENC1;
+bool debug_encoder = false;
+
+__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
+ mouse_report->h = h;
+ mouse_report->v = v;
+}
+
+__attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) {
+ // If the mouse wheel was just released, do not scroll.
+ if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE)
+ return;
+
+ // Limit the number of scrolls per unit time.
+ if (timer_elapsed(lastScroll) < OPT_DEBOUNCE)
+ return;
+
+ // Don't scroll if the middle button is depressed.
+ if (is_scroll_clicked) {
+#ifndef IGNORE_SCROLL_CLICK
+ return;
+#endif
+ }
+
+ lastScroll = timer_read();
+ uint16_t p1 = adc_read(OPT_ENC1_MUX);
+ uint16_t p2 = adc_read(OPT_ENC2_MUX);
+
+ if (debug_encoder)
+ dprintf("OPT1: %d, OPT2: %d\n", p1, p2);
+
+ uint8_t dir = opt_encoder_handler(p1, p2);
+
+ if (dir == 0)
+ return;
+
+ process_wheel_user(mouse_report, mouse_report->h, (int)(mouse_report->v + (dir * OPT_SCALE)));
+}
+
+__attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
+ // x and y are swapped
+ // the sensor is rotated
+ // by 90 degrees
+ int16_t temp = x;
+ x = y;
+ y = temp;
+
+ // Apply delta-X and delta-Y transformations.
+ float xt = (float) x * ADNS_X_TRANSFORM;
+ float yt = (float) y * ADNS_Y_TRANSFORM;
+
+ int16_t xti = xt;
+ int16_t yti = yt;
+
+ mouse_report->x = xti;
+ mouse_report->y = yti;
+}
+
+__attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) {
+ report_adns_t data = adns_read_burst();
+
+ if (data.dx != 0 || data.dy != 0) {
+ if (debug_mouse)
+ dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
+
+ process_mouse_user(mouse_report, data.dx, data.dy);
+ }
+}
+
+bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
+ xprintf("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
+ if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
+ lastMidClick = timer_read();
+ is_scroll_clicked = record->event.pressed;
+ }
+
+ 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);
+ adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
+ }
+
+/* If Mousekeys is disabled, then use handle the mouse button
+ * keycodes. This makes things simpler, and allows usage of
+ * the keycodes in a consistent manner. But only do this if
+ * Mousekeys is not enable, so it's not handled twice.
+ */
+#ifndef MOUSEKEY_ENABLE
+ if (IS_MOUSEKEY_BUTTON(keycode)) {
+ report_mouse_t currentReport = pointing_device_get_report();
+ if (record->event.pressed) {
+ currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
+ } else {
+ currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
+ }
+ pointing_device_set_report(currentReport);
+ pointing_device_send();
+ }
+#endif
+
+ return true;
+}
+
+// Hardware Setup
+void keyboard_pre_init_kb(void) {
+ // debug_enable = true;
+ // debug_matrix = true;
+ debug_mouse = true;
+ // debug_encoder = true;
+
+ setPinInput(OPT_ENC1);
+ setPinInput(OPT_ENC2);
+
+ /* 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 UNUSED_PINS
+ const pin_t unused_pins[] = UNUSED_PINS;
+
+ for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
+ setPinOutput(unused_pins[i]);
+ writePinLow(unused_pins[i]);
+ }
+#endif
+
+ keyboard_pre_init_user();
+}
+
+void pointing_device_init(void) {
+ adns_init();
+ opt_encoder_init();
+}
+
+void pointing_device_task(void) {
+ report_mouse_t mouse_report = pointing_device_get_report();
+ process_wheel(&mouse_report);
+ process_mouse(&mouse_report);
+ pointing_device_set_report(mouse_report);
+ pointing_device_send();
+}
+
+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();
+}
+
+void keyboard_post_init_kb(void) {
+ adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
+
+ keyboard_post_init_user();
+}
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.h b/keyboards/ploopyco/trackball_mini/trackball_mini.h
new file mode 100644
index 0000000000..b9754cbc72
--- /dev/null
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.h
@@ -0,0 +1,54 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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"
+#include "adns5050.h"
+#include "analog.h"
+#include "opt_encoder.h"
+#include "pointing_device.h"
+
+// Sensor defs
+#define OPT_ENC1 F0
+#define OPT_ENC2 F4
+#define OPT_ENC1_MUX 0
+#define OPT_ENC2_MUX 4
+
+void process_mouse(report_mouse_t* mouse_report);
+void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y);
+void process_wheel(report_mouse_t* mouse_report);
+void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v);
+
+#define LAYOUT(BL, BM, BR, BF, BB) \
+ { {BL, BM, BR, BF, BB}, }
+
+typedef union {
+ uint32_t raw;
+ struct {
+ uint8_t dpi_config;
+ };
+} keyboard_config_t;
+
+extern keyboard_config_t keyboard_config;
+
+enum ploopy_keycodes {
+ DPI_CONFIG = SAFE_RANGE,
+ PLOOPY_SAFE_RANGE,
+};
diff --git a/keyboards/ploopyco/trackball_nano/config.h b/keyboards/ploopyco/trackball_nano/config.h
new file mode 100644
index 0000000000..54fe840ceb
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/config.h
@@ -0,0 +1,48 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 "config_common.h"
+
+/* USB Device descriptor parameter */
+#define VENDOR_ID 0x5043
+#define PRODUCT_ID 0x1EAB
+#define DEVICE_VER 0x0001
+#define MANUFACTURER PloopyCo
+#define PRODUCT Trackball Nano
+
+/* key matrix size */
+#define MATRIX_ROWS 1
+#define MATRIX_COLS 1
+
+/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
+#define DEBOUNCE 0
+
+/* disable action features */
+//#define NO_ACTION_LAYER
+//#define NO_ACTION_TAPPING
+//#define NO_ACTION_ONESHOT
+#define NO_ACTION_MACRO
+#define NO_ACTION_FUNCTION
+
+/* Much more so than a keyboard, speed matters for a mouse. So we'll go for as high
+ a polling rate as possible. */
+#define USB_POLLING_INTERVAL_MS 1
+#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 0000000000..a788ce9eb1
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/info.json
@@ -0,0 +1,13 @@
+{
+ "keyboard_name": "Ploopy Trackball Nano",
+ "url": "www.ploopy.co",
+ "maintainer": "ploopyco",
+ "manufacturer": "Ploopy Corporation",
+ "layouts": {
+ "LAYOUT": {
+ "layout": [
+ {"x":0, "y":0}
+ ]
+ }
+ }
+}
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 0000000000..1140c30a1d
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c
@@ -0,0 +1,23 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 QMK_KEYBOARD_H
+
+// safe range starts at `PLOOPY_SAFE_RANGE` instead.
+
+// 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 0000000000..ebb90d2999
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/keymaps/default/readme.md
@@ -0,0 +1,3 @@
+The default keymap for the Ploopy Trackball Mini.
+
+Note 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 0000000000..8a293602a8
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/readme.md
@@ -0,0 +1,54 @@
+
+
+# Ploopy Trackball Nano
+
+![Ploopyco Trackball Nano](https://www.ploopy.co/uploads/b/113cb4122f867acc306a72a2741c5237a9b1d0db13abfe4e8e394cd466c4a311/_MG_7710_1614037372.jpg)
+
+It's a DIY, QMK Powered Trackball...Nano!
+
+* Maintainer: [PloopyCo](https://github.com/ploopyco)
+* Key contributors: [Drashna Jael're](https://github.com/drashna/), [Germ](https://github.com/germ/)
+* Hardware Supported: ATMega32u4 16MHz(5v)
+* Hardware Availability: [Store](https://ploopy.co/nano-trackball), [GitHub](https://github.com/ploopyco/nano-trackball)
+
+Make example for this trackball (after setting up your build environment):
+
+ make ploopyco/trackball_nano/rev1_001:default:flash
+ make ploopyco/trackball_nano/rev1_001:via:flash
+
+See 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).
+
+## Hardware Reset Button
+
+The 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.
+
+## Revisions
+
+Occasionally, new revisions of the PCB will be released. Every board comes with a designator that looks something like `R1.001`.
+
+Match the firmware that you flash onto the board with the designator on the board.
+
+# Customzing your Ploopy Nano Trackball
+
+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.
+
+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 { CPI375, CPI750, CPI1375}
+#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. It stores this value in persistent memory, so it will load it the next time the device powers up.
+
+## Fuse settings
+
+When flashing the bootloader, use the following fuse settings:
+
+| Fuse | Setting |
+|----------|-------------|
+| Low | `0x5E` |
+| High | `0x99` |
+| 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 0000000000..63780ef048
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rev1_001/config.h
@@ -0,0 +1,37 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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
+
+/*
+ * Keyboard Matrix Assignments
+ *
+ * Change this to how you wired your keyboard
+ * COLS: AVR pins used for columns, left to right
+ * ROWS: AVR pins used for rows, top to bottom
+ * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
+ * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
+ *
+ */
+#define DIRECT_PINS {}
+
+// These pins are not broken out, and cannot be used normally.
+// They are set as output and pulled high, by default
+#define UNUSED_PINS \
+ { 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 0000000000..052a17f396
--- /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 0000000000..4f34e17dd4
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rev1_001/rev1_001.h
@@ -0,0 +1,22 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 "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 0000000000..e69de29bb2
--- /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 0000000000..0286194b9f
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/rules.mk
@@ -0,0 +1,32 @@
+# MCU name
+MCU = atmega32u4
+
+# Processor frequency
+F_CPU = 16000000
+
+# Bootloader selection
+BOOTLOADER = atmel-dfu
+
+# Build Options
+# change yes to no to disable
+#
+BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
+EXTRAKEY_ENABLE = yes # Audio control and System control
+CONSOLE_ENABLE = yes # Console for debug
+COMMAND_ENABLE = no # Commands for debug and configuration
+# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
+SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
+# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
+NKRO_ENABLE = no # USB Nkey Rollover
+BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
+UNICODE_ENABLE = no # Unicode
+BLUETOOTH_ENABLE = no # Enable Bluetooth
+AUDIO_ENABLE = no # Audio output
+POINTING_DEVICE_ENABLE = yes
+MOUSEKEY_ENABLE = no # Mouse keys
+
+QUANTUM_LIB_SRC += analog.c
+SRC += adns5050.c opt_encoder.c
+
+DEFAULT_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 0000000000..93cb60bd4b
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/trackball_nano.c
@@ -0,0 +1,211 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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 "trackball_nano.h"
+
+#ifndef OPT_DEBOUNCE
+# define OPT_DEBOUNCE 5 // (ms) Time between scroll events
+#endif
+
+#ifndef SCROLL_BUTT_DEBOUNCE
+# define SCROLL_BUTT_DEBOUNCE 100 // (ms) Time between scroll events
+#endif
+
+#ifndef OPT_THRES
+# define OPT_THRES 150 // (0-1024) Threshold for actication
+#endif
+
+#ifndef OPT_SCALE
+# define OPT_SCALE 1 // Multiplier for wheel
+#endif
+
+#ifndef PLOOPY_DPI_OPTIONS
+# define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 }
+# ifndef PLOOPY_DPI_DEFAULT
+# define PLOOPY_DPI_DEFAULT 2
+# endif
+#endif
+
+#ifndef PLOOPY_DPI_DEFAULT
+# define PLOOPY_DPI_DEFAULT 1
+#endif
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { };
+
+// Transformation constants for delta-X and delta-Y
+const static float ADNS_X_TRANSFORM = -1.0;
+const static float ADNS_Y_TRANSFORM = 1.0;
+
+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_scroll_clicked = false;
+bool BurstState = false; // init burst state for Trackball module
+uint16_t MotionStart = 0; // Timer for accel, 0 is resting state
+uint16_t lastScroll = 0; // Previous confirmed wheel event
+uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
+uint8_t OptLowPin = OPT_ENC1;
+bool debug_encoder = false;
+
+__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
+ // There's no scroller on this device.
+ return;
+}
+
+__attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) {
+ // There's no scroller on this device.
+ return;
+}
+
+__attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
+ // x and y are swapped
+ // the sensor is rotated
+ // by 90 degrees
+ int16_t temp = x;
+ x = y;
+ y = temp;
+
+ // Apply delta-X and delta-Y transformations.
+ float xt = (float) x * ADNS_X_TRANSFORM;
+ float yt = (float) y * ADNS_Y_TRANSFORM;
+
+ int16_t xti = xt;
+ int16_t yti = yt;
+
+ mouse_report->x = xti;
+ mouse_report->y = yti;
+}
+
+__attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) {
+ report_adns_t data = adns_read_burst();
+
+ if (data.dx != 0 || data.dy != 0) {
+ if (debug_mouse)
+ dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
+
+ process_mouse_user(mouse_report, data.dx, data.dy);
+ }
+}
+
+bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
+ xprintf("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
+ if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
+ lastMidClick = timer_read();
+ is_scroll_clicked = record->event.pressed;
+ }
+
+ 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);
+ adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
+ }
+
+/* If Mousekeys is disabled, then use handle the mouse button
+ * keycodes. This makes things simpler, and allows usage of
+ * the keycodes in a consistent manner. But only do this if
+ * Mousekeys is not enable, so it's not handled twice.
+ */
+#ifndef MOUSEKEY_ENABLE
+ if (IS_MOUSEKEY_BUTTON(keycode)) {
+ report_mouse_t currentReport = pointing_device_get_report();
+ if (record->event.pressed) {
+ currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
+ } else {
+ currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
+ }
+ pointing_device_set_report(currentReport);
+ pointing_device_send();
+ }
+#endif
+
+ return true;
+}
+
+// Hardware Setup
+void keyboard_pre_init_kb(void) {
+ // debug_enable = true;
+ // debug_matrix = true;
+ debug_mouse = true;
+ // debug_encoder = true;
+
+ setPinInput(OPT_ENC1);
+ setPinInput(OPT_ENC2);
+
+ /* 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 UNUSED_PINS
+ const pin_t unused_pins[] = UNUSED_PINS;
+
+ for (uint8_t i = 0; i < (sizeof(unused_pins) / sizeof(pin_t)); i++) {
+ setPinOutput(unused_pins[i]);
+ writePinLow(unused_pins[i]);
+ }
+#endif
+
+ keyboard_pre_init_user();
+}
+
+void pointing_device_init(void) {
+ adns_init();
+ opt_encoder_init();
+}
+
+void pointing_device_task(void) {
+ report_mouse_t mouse_report = pointing_device_get_report();
+ process_wheel(&mouse_report);
+ process_mouse(&mouse_report);
+ pointing_device_set_report(mouse_report);
+ pointing_device_send();
+}
+
+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();
+}
+
+void keyboard_post_init_kb(void) {
+ adns_set_cpi(dpi_array[keyboard_config.dpi_config]);
+
+ keyboard_post_init_user();
+}
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.h b/keyboards/ploopyco/trackball_nano/trackball_nano.h
new file mode 100644
index 0000000000..4bffb04607
--- /dev/null
+++ b/keyboards/ploopyco/trackball_nano/trackball_nano.h
@@ -0,0 +1,53 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * 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"
+#include "adns5050.h"
+#include "analog.h"
+#include "opt_encoder.h"
+#include "pointing_device.h"
+
+// Sensor defs
+#define OPT_ENC1 F0
+#define OPT_ENC2 F4
+#define OPT_ENC1_MUX 0
+#define OPT_ENC2_MUX 4
+
+void process_mouse(report_mouse_t* mouse_report);
+void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y);
+void process_wheel(report_mouse_t* mouse_report);
+void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v);
+
+#define LAYOUT(k00) {{ KC_NO }}
+
+typedef union {
+ uint32_t raw;
+ struct {
+ uint8_t dpi_config;
+ };
+} keyboard_config_t;
+
+extern keyboard_config_t keyboard_config;
+
+enum ploopy_keycodes {
+ DPI_CONFIG = SAFE_RANGE,
+ PLOOPY_SAFE_RANGE,
+};