Skip to content

Commit

Permalink
Move pimoroni trackball to drivers/sensors/ too
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Jun 16, 2021
1 parent 6497558 commit 39227f7
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ static float precisionSpeed = 1;

static uint16_t i2c_timeout_timer;

#ifndef I2C_TIMEOUT
# define I2C_TIMEOUT 100
#ifndef PIMORONI_I2C_TIMEOUT
# define PIMORONI_I2C_TIMEOUT 100
#endif
#ifndef I2C_WAITCHECK
# define I2C_WAITCHECK 1000
Expand All @@ -38,7 +38,7 @@ static uint16_t i2c_timeout_timer;

void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
uint8_t data[] = {0x00, red, green, blue, white};
i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), I2C_TIMEOUT);
i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), PIMORONI_I2C_TIMEOUT);
}

int16_t mouse_offset(uint8_t positive, uint8_t negative, int16_t scale) {
Expand Down Expand Up @@ -68,59 +68,19 @@ __attribute__((weak)) void trackball_check_click(bool pressed, report_mouse_t* m
}
}

bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
if (true) {
xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
}


if (!process_record_user(keycode, record)) { return false; }

/* 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;
}

void trackball_register_button(bool pressed, enum mouse_buttons button) {
report_mouse_t currentReport = pointing_device_get_report();
if (pressed) {
currentReport.buttons |= button;
} else {
currentReport.buttons &= ~button;
}
pointing_device_set_report(currentReport);
}

float trackball_get_precision(void) { return precisionSpeed; }
void trackball_set_precision(float precision) { precisionSpeed = precision; }
bool trackball_is_scrolling(void) { return scrolling; }
void trackball_set_scrolling(bool scroll) { scrolling = scroll; }


__attribute__((weak)) void pointing_device_init(void) { trackball_set_rgbw(0x80, 0x00, 0x00, 0x00); }
__attribute__((weak)) void pointing_device_init(void) { trackball_set_rgbw(0x00, 0x00, 0x00, 0x00); }

void pointing_device_task(void) {
static bool debounce;
static uint16_t debounce_timer;
uint8_t state[5] = {};
if (timer_elapsed(i2c_timeout_timer) > I2C_WAITCHECK) {
if (i2c_readReg(TRACKBALL_WRITE, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
if (i2c_readReg(TRACKBALL_READ, 0x04, state, 5, PIMORONI_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
if (!state[4] && !debounce) {
if (scrolling) {
#ifdef PIMORONI_TRACKBALL_INVERT_X
Expand Down Expand Up @@ -159,7 +119,10 @@ void pointing_device_task(void) {
if (timer_elapsed(debounce_timer) > MOUSE_DEBOUNCE) debounce = false;

report_mouse_t mouse = pointing_device_get_report();
// trackball_check_click(state[4] & (1 << 7), &mouse);

#ifdef PIMORONI_TRACKBALL_CLICK
trackball_check_click(state[4] & (1 << 7), &mouse);
#endif

#ifndef PIMORONI_TRACKBALL_ROTATE
update_member(&mouse.x, &x_offset);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion keyboards/draculad/keymaps/pimoroni/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include QMK_KEYBOARD_H
#include "pimoroni_trackball.h"
#include "drivers/sensors/pimoroni_trackball.h"
#include "pointing_device.h"


Expand Down
35 changes: 0 additions & 35 deletions keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.h

This file was deleted.

2 changes: 1 addition & 1 deletion keyboards/draculad/keymaps/pimoroni/rules.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# only uncomment on the side you have your trackball on
POINTING_DEVICE_ENABLE = yes
SRC += pimoroni_trackball.c
SRC += drivers/sensors/pimoroni_trackball.c
QUANTUM_LIB_SRC += i2c_master.c
OLED_DRIVER_ENABLE = yes
MOUSEKEY_ENABLE = no
1 change: 1 addition & 0 deletions layouts/community/ergodox/drashna/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@

#define PIMORONI_TRACKBALL_INVERT_X
#define PIMORONI_TRACKBALL_INVERT_Y
#define PIMORONI_TRACKBALL_CLICK
2 changes: 1 addition & 1 deletion users/drashna/drashna.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# include "oled_stuff.h"
#endif
#if defined(PIMORONI_TRACKBALL_ENABLE)
# include "pimoroni_trackball.h"
# include "drivers/sensors/pimoroni_trackball.h"
#endif

/* Define layer names */
Expand Down
151 changes: 0 additions & 151 deletions users/drashna/pimoroni_trackball.c

This file was deleted.

2 changes: 1 addition & 1 deletion users/drashna/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ endif
ifeq ($(strip $(PIMORONI_TRACKBALL_ENABLE)), yes)
POINTING_DEVICE_ENABLE := yes
OPT_DEFS += -DPIMORONI_TRACKBALL_ENABLE
SRC += pimoroni_trackball.c
SRC += drivers/sensors/pimoroni_trackball.c
QUANTUM_LIB_SRC += i2c_master.c
endif

Expand Down

0 comments on commit 39227f7

Please sign in to comment.