diff options
Diffstat (limited to 'keyboards/ploopyco/trackball_nano')
| -rw-r--r-- | keyboards/ploopyco/trackball_nano/config.h | 6 | ||||
| -rw-r--r-- | keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c | 22 | ||||
| -rw-r--r-- | keyboards/ploopyco/trackball_nano/rules.mk | 7 | ||||
| -rw-r--r-- | keyboards/ploopyco/trackball_nano/trackball_nano.c | 116 | ||||
| -rw-r--r-- | keyboards/ploopyco/trackball_nano/trackball_nano.h | 13 |
5 files changed, 27 insertions, 137 deletions
diff --git a/keyboards/ploopyco/trackball_nano/config.h b/keyboards/ploopyco/trackball_nano/config.h index 7450f5574..7d109db99 100644 --- a/keyboards/ploopyco/trackball_nano/config.h +++ b/keyboards/ploopyco/trackball_nano/config.h | |||
| @@ -45,3 +45,9 @@ | |||
| 45 | a polling rate as possible. */ | 45 | a polling rate as possible. */ |
| 46 | #define USB_POLLING_INTERVAL_MS 1 | 46 | #define USB_POLLING_INTERVAL_MS 1 |
| 47 | #define USB_MAX_POWER_CONSUMPTION 100 | 47 | #define USB_MAX_POWER_CONSUMPTION 100 |
| 48 | |||
| 49 | #define ADNS5050_SCLK_PIN B7 | ||
| 50 | #define ADNS5050_SDIO_PIN C6 | ||
| 51 | #define ADNS5050_CS_PIN B4 | ||
| 52 | |||
| 53 | #define POINTING_DEVICE_ROTATION_90 | ||
diff --git a/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c b/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c index 6f568ecf5..9e33db378 100644 --- a/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c +++ b/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c | |||
| @@ -21,14 +21,14 @@ | |||
| 21 | // safe range starts at `PLOOPY_SAFE_RANGE` instead. | 21 | // safe range starts at `PLOOPY_SAFE_RANGE` instead. |
| 22 | uint8_t scroll_enabled = 0; | 22 | uint8_t scroll_enabled = 0; |
| 23 | uint8_t lock_state = 0; | 23 | uint8_t lock_state = 0; |
| 24 | int16_t delta_x = 0; | 24 | int8_t delta_x = 0; |
| 25 | int16_t delta_y = 0; | 25 | int8_t delta_y = 0; |
| 26 | 26 | ||
| 27 | void process_mouse_user(report_mouse_t *mouse_report, int16_t x, int16_t y) { | 27 | void process_mouse_user(report_mouse_t *mouse_report, int8_t x, int8_t y) { |
| 28 | if (scroll_enabled) { | 28 | if (scroll_enabled) { |
| 29 | delta_x += x; | 29 | delta_x += x; |
| 30 | delta_y += y; | 30 | delta_y += y; |
| 31 | 31 | ||
| 32 | if (delta_x > 60) { | 32 | if (delta_x > 60) { |
| 33 | mouse_report->h = 1; | 33 | mouse_report->h = 1; |
| 34 | delta_x = 0; | 34 | delta_x = 0; |
| @@ -44,10 +44,10 @@ void process_mouse_user(report_mouse_t *mouse_report, int16_t x, int16_t y) { | |||
| 44 | mouse_report->v = 1; | 44 | mouse_report->v = 1; |
| 45 | delta_y = 0; | 45 | delta_y = 0; |
| 46 | } | 46 | } |
| 47 | } else { | 47 | } else { |
| 48 | mouse_report->x = x; | 48 | mouse_report->x = x; |
| 49 | mouse_report->y = y; | 49 | mouse_report->y = y; |
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | void keyboard_post_init_user(void) { | 53 | void keyboard_post_init_user(void) { |
| @@ -62,7 +62,7 @@ bool led_update_user(led_t led_state) { | |||
| 62 | scroll_timer = timer_read(); | 62 | scroll_timer = timer_read(); |
| 63 | lock_count = 0; | 63 | lock_count = 0; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | if (led_state.num_lock != lock_state) { | 66 | if (led_state.num_lock != lock_state) { |
| 67 | lock_count++; | 67 | lock_count++; |
| 68 | 68 | ||
| @@ -73,7 +73,7 @@ bool led_update_user(led_t led_state) { | |||
| 73 | delta_y = 0; | 73 | delta_y = 0; |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | lock_state = led_state.num_lock; | 77 | lock_state = led_state.num_lock; |
| 78 | return true; | 78 | return true; |
| 79 | } | 79 | } |
diff --git a/keyboards/ploopyco/trackball_nano/rules.mk b/keyboards/ploopyco/trackball_nano/rules.mk index a26ad93c8..1a29a561e 100644 --- a/keyboards/ploopyco/trackball_nano/rules.mk +++ b/keyboards/ploopyco/trackball_nano/rules.mk | |||
| @@ -1,9 +1,6 @@ | |||
| 1 | # MCU name | 1 | # MCU name |
| 2 | MCU = atmega32u4 | 2 | MCU = atmega32u4 |
| 3 | 3 | ||
| 4 | # Processor frequency | ||
| 5 | F_CPU = 16000000 | ||
| 6 | |||
| 7 | # Bootloader selection | 4 | # Bootloader selection |
| 8 | BOOTLOADER = atmel-dfu | 5 | BOOTLOADER = atmel-dfu |
| 9 | 6 | ||
| @@ -22,9 +19,7 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | |||
| 22 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow | 19 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow |
| 23 | AUDIO_ENABLE = no # Audio output | 20 | AUDIO_ENABLE = no # Audio output |
| 24 | POINTING_DEVICE_ENABLE = yes | 21 | POINTING_DEVICE_ENABLE = yes |
| 22 | POINTING_DEVICE_DRIVER = adns5050 | ||
| 25 | MOUSEKEY_ENABLE = no # Mouse keys | 23 | MOUSEKEY_ENABLE = no # Mouse keys |
| 26 | 24 | ||
| 27 | QUANTUM_LIB_SRC += analog.c | ||
| 28 | SRC += drivers/sensors/adns5050.c opt_encoder.c | ||
| 29 | |||
| 30 | DEFAULT_FOLDER = ploopyco/trackball_nano/rev1_001 | 25 | 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 index 9bcfa59ef..2702f6055 100644 --- a/keyboards/ploopyco/trackball_nano/trackball_nano.c +++ b/keyboards/ploopyco/trackball_nano/trackball_nano.c | |||
| @@ -37,7 +37,8 @@ | |||
| 37 | #endif | 37 | #endif |
| 38 | 38 | ||
| 39 | #ifndef PLOOPY_DPI_OPTIONS | 39 | #ifndef PLOOPY_DPI_OPTIONS |
| 40 | # define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 } | 40 | # define PLOOPY_DPI_OPTIONS \ |
| 41 | { 375, 750, 1375 } | ||
| 41 | # ifndef PLOOPY_DPI_DEFAULT | 42 | # ifndef PLOOPY_DPI_DEFAULT |
| 42 | # define PLOOPY_DPI_DEFAULT 2 | 43 | # define PLOOPY_DPI_DEFAULT 2 |
| 43 | # endif | 44 | # endif |
| @@ -49,12 +50,8 @@ | |||
| 49 | 50 | ||
| 50 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; | 51 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; |
| 51 | 52 | ||
| 52 | // Transformation constants for delta-X and delta-Y | ||
| 53 | const static float ADNS_X_TRANSFORM = -1.0; | ||
| 54 | const static float ADNS_Y_TRANSFORM = 1.0; | ||
| 55 | |||
| 56 | keyboard_config_t keyboard_config; | 53 | keyboard_config_t keyboard_config; |
| 57 | uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; | 54 | uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; |
| 58 | #define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) | 55 | #define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) |
| 59 | 56 | ||
| 60 | // TODO: Implement libinput profiles | 57 | // TODO: Implement libinput profiles |
| @@ -63,77 +60,13 @@ uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; | |||
| 63 | // Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC | 60 | // Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC |
| 64 | 61 | ||
| 65 | // Trackball State | 62 | // Trackball State |
| 66 | bool is_scroll_clicked = false; | 63 | bool is_scroll_clicked = false; |
| 67 | bool BurstState = false; // init burst state for Trackball module | 64 | bool BurstState = false; // init burst state for Trackball module |
| 68 | uint16_t MotionStart = 0; // Timer for accel, 0 is resting state | 65 | uint16_t MotionStart = 0; // Timer for accel, 0 is resting state |
| 69 | uint16_t lastScroll = 0; // Previous confirmed wheel event | ||
| 70 | uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed | ||
| 71 | uint8_t OptLowPin = OPT_ENC1; | ||
| 72 | bool debug_encoder = false; | ||
| 73 | |||
| 74 | __attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { | ||
| 75 | mouse_report->x = x; | ||
| 76 | mouse_report->y = y; | ||
| 77 | } | ||
| 78 | |||
| 79 | __attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) { | ||
| 80 | report_adns_t data = adns_read_burst(); | ||
| 81 | |||
| 82 | if (data.dx != 0 || data.dy != 0) { | ||
| 83 | if (debug_mouse) | ||
| 84 | dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); | ||
| 85 | |||
| 86 | // Apply delta-X and delta-Y transformations. | ||
| 87 | // x and y are swapped | ||
| 88 | // the sensor is rotated | ||
| 89 | // by 90 degrees | ||
| 90 | float xt = (float) data.dy * ADNS_X_TRANSFORM; | ||
| 91 | float yt = (float) data.dx * ADNS_Y_TRANSFORM; | ||
| 92 | |||
| 93 | int16_t xti = (int16_t)xt; | ||
| 94 | int16_t yti = (int16_t)yt; | ||
| 95 | |||
| 96 | process_mouse_user(mouse_report, xti, yti); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | ||
| 101 | xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); | ||
| 102 | |||
| 103 | // Update Timer to prevent accidental scrolls | ||
| 104 | if ((record->event.key.col == 1) && (record->event.key.row == 0)) { | ||
| 105 | lastMidClick = timer_read(); | ||
| 106 | is_scroll_clicked = record->event.pressed; | ||
| 107 | } | ||
| 108 | |||
| 109 | if (!process_record_user(keycode, record)) | ||
| 110 | return false; | ||
| 111 | |||
| 112 | if (keycode == DPI_CONFIG && record->event.pressed) { | ||
| 113 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; | ||
| 114 | eeconfig_update_kb(keyboard_config.raw); | ||
| 115 | adns_set_cpi(dpi_array[keyboard_config.dpi_config]); | ||
| 116 | } | ||
| 117 | 66 | ||
| 118 | /* If Mousekeys is disabled, then use handle the mouse button | 67 | void pointing_device_init_kb(void) { |
| 119 | * keycodes. This makes things simpler, and allows usage of | 68 | // set the DPI. |
| 120 | * the keycodes in a consistent manner. But only do this if | 69 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
| 121 | * Mousekeys is not enable, so it's not handled twice. | ||
| 122 | */ | ||
| 123 | #ifndef MOUSEKEY_ENABLE | ||
| 124 | if (IS_MOUSEKEY_BUTTON(keycode)) { | ||
| 125 | report_mouse_t currentReport = pointing_device_get_report(); | ||
| 126 | if (record->event.pressed) { | ||
| 127 | currentReport.buttons |= 1 << (keycode - KC_MS_BTN1); | ||
| 128 | } else { | ||
| 129 | currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1)); | ||
| 130 | } | ||
| 131 | pointing_device_set_report(currentReport); | ||
| 132 | pointing_device_send(); | ||
| 133 | } | ||
| 134 | #endif | ||
| 135 | |||
| 136 | return true; | ||
| 137 | } | 70 | } |
| 138 | 71 | ||
| 139 | // Hardware Setup | 72 | // Hardware Setup |
| @@ -143,9 +76,6 @@ void keyboard_pre_init_kb(void) { | |||
| 143 | // debug_mouse = true; | 76 | // debug_mouse = true; |
| 144 | // debug_encoder = true; | 77 | // debug_encoder = true; |
| 145 | 78 | ||
| 146 | setPinInput(OPT_ENC1); | ||
| 147 | setPinInput(OPT_ENC2); | ||
| 148 | |||
| 149 | /* Ground all output pins connected to ground. This provides additional | 79 | /* Ground all output pins connected to ground. This provides additional |
| 150 | * pathways to ground. If you're messing with this, know this: driving ANY | 80 | * pathways to ground. If you're messing with this, know this: driving ANY |
| 151 | * of these pins high will cause a short. On the MCU. Ka-blooey. | 81 | * of these pins high will cause a short. On the MCU. Ka-blooey. |
| @@ -162,34 +92,6 @@ void keyboard_pre_init_kb(void) { | |||
| 162 | keyboard_pre_init_user(); | 92 | keyboard_pre_init_user(); |
| 163 | } | 93 | } |
| 164 | 94 | ||
| 165 | void pointing_device_init(void) { | ||
| 166 | adns_init(); | ||
| 167 | opt_encoder_init(); | ||
| 168 | |||
| 169 | // reboot the adns. | ||
| 170 | // if the adns hasn't initialized yet, this is harmless. | ||
| 171 | adns_write_reg(REG_CHIP_RESET, 0x5a); | ||
| 172 | |||
| 173 | // wait maximum time before adns is ready. | ||
| 174 | // this ensures that the adns is actuall ready after reset. | ||
| 175 | wait_ms(55); | ||
| 176 | |||
| 177 | // read a burst from the adns and then discard it. | ||
| 178 | // gets the adns ready for write commands | ||
| 179 | // (for example, setting the dpi). | ||
| 180 | adns_read_burst(); | ||
| 181 | |||
| 182 | // set the DPI. | ||
| 183 | adns_set_cpi(dpi_array[keyboard_config.dpi_config]); | ||
| 184 | } | ||
| 185 | |||
| 186 | void pointing_device_task(void) { | ||
| 187 | report_mouse_t mouse_report = pointing_device_get_report(); | ||
| 188 | process_mouse(&mouse_report); | ||
| 189 | pointing_device_set_report(mouse_report); | ||
| 190 | pointing_device_send(); | ||
| 191 | } | ||
| 192 | |||
| 193 | void eeconfig_init_kb(void) { | 95 | void eeconfig_init_kb(void) { |
| 194 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; | 96 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; |
| 195 | eeconfig_update_kb(keyboard_config.raw); | 97 | eeconfig_update_kb(keyboard_config.raw); |
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.h b/keyboards/ploopyco/trackball_nano/trackball_nano.h index 6c8ecace7..88725eab6 100644 --- a/keyboards/ploopyco/trackball_nano/trackball_nano.h +++ b/keyboards/ploopyco/trackball_nano/trackball_nano.h | |||
| @@ -20,19 +20,6 @@ | |||
| 20 | #pragma once | 20 | #pragma once |
| 21 | 21 | ||
| 22 | #include "quantum.h" | 22 | #include "quantum.h" |
| 23 | #include "drivers/sensors/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 | |||
| 34 | void process_mouse(report_mouse_t* mouse_report); | ||
| 35 | void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y); | ||
| 36 | 23 | ||
| 37 | #define LAYOUT(k00) {{ KC_NO }} | 24 | #define LAYOUT(k00) {{ KC_NO }} |
| 38 | 25 | ||
