This commit is contained in:
ale1800
2025-09-11 00:32:31 +08:00
committed by GitHub
4 changed files with 156 additions and 1 deletions

View File

@@ -125,7 +125,7 @@ ifeq ($(strip $(MOUSEKEY_ENABLE)), yes)
MOUSE_ENABLE := yes
endif
VALID_POINTING_DEVICE_DRIVER_TYPES := adns5050 adns9800 analog_joystick azoteq_iqs5xx cirque_pinnacle_i2c cirque_pinnacle_spi paw3204 pmw3320 pmw3360 pmw3389 pimoroni_trackball custom
VALID_POINTING_DEVICE_DRIVER_TYPES := adns5050 adns9800 analog_joystick azoteq_iqs5xx cirque_pinnacle_i2c cirque_pinnacle_spi paw3204 pmw3320 pmw3360 pmw3389 pimoroni_trackball blackberry_trackball custom
ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes)
ifeq ($(filter $(POINTING_DEVICE_DRIVER),$(VALID_POINTING_DEVICE_DRIVER_TYPES)),)
$(call CATASTROPHIC_ERROR,Invalid POINTING_DEVICE_DRIVER,POINTING_DEVICE_DRIVER="$(POINTING_DEVICE_DRIVER)" is not a valid pointing device type)
@@ -159,6 +159,8 @@ ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/pointing_device/pointing_device_gestures.c
else ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pimoroni_trackball)
I2C_DRIVER_REQUIRED = yes
else ifeq ($(strip $(POINTING_DEVICE_DRIVER)), blackberry_trackball)
SRC += drivers/sensors/blackberry_trackball.c
else ifneq ($(filter $(strip $(POINTING_DEVICE_DRIVER)),pmw3360 pmw3389),)
SPI_DRIVER_REQUIRED = yes
SRC += drivers/sensors/pmw33xx_common.c

View File

@@ -0,0 +1,95 @@
/*
*
* 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 "blackberry_trackball.h"
#include "ch.h"
#include "hal.h"
#include "gpio.h"
#include "print.h"
volatile int8_t x = 0;
volatile int8_t y = 0;
char debug = '\0';
const pointing_device_driver_t blackberry_trackball_pointing_device_driver = {
.init = blackberry_trackball_init,
.get_report = blackberry_trackball_get_report,
.set_cpi = NULL,
.get_cpi = NULL,
};
void trackball_movement_cb(void *arg) {
switch ((intptr_t)arg) {
case M_UP:
y -= BLACKBERRY_TRACKBALL_STEP;
debug = 'U';
break;
case M_DOWN:
y += BLACKBERRY_TRACKBALL_STEP;
debug = 'D';
break;
case M_RIGHT:
x += BLACKBERRY_TRACKBALL_STEP;
debug = 'R';
break;
case M_LEFT:
x -= BLACKBERRY_TRACKBALL_STEP;
debug = 'L';
break;
}
}
void blackberry_trackball_init(void) {
palSetLineMode(BLACKBERRY_TRACKBALL_UP_PIN, PAL_MODE_INPUT);
palEnableLineEvent(BLACKBERRY_TRACKBALL_UP_PIN, PAL_EVENT_MODE_RISING_EDGE );
palSetLineCallback(BLACKBERRY_TRACKBALL_UP_PIN, trackball_movement_cb, (void *)M_UP);
palSetLineMode(BLACKBERRY_TRACKBALL_DOWN_PIN, PAL_MODE_INPUT);
palEnableLineEvent(BLACKBERRY_TRACKBALL_DOWN_PIN, PAL_EVENT_MODE_RISING_EDGE );
palSetLineCallback(BLACKBERRY_TRACKBALL_DOWN_PIN, trackball_movement_cb, (void *)M_DOWN);
palSetLineMode(BLACKBERRY_TRACKBALL_LEFT_PIN, PAL_MODE_INPUT);
palEnableLineEvent(BLACKBERRY_TRACKBALL_LEFT_PIN, PAL_EVENT_MODE_RISING_EDGE );
palSetLineCallback(BLACKBERRY_TRACKBALL_LEFT_PIN, trackball_movement_cb, (void *)M_LEFT);
palSetLineMode(BLACKBERRY_TRACKBALL_RIGHT_PIN, PAL_MODE_INPUT);
palEnableLineEvent(BLACKBERRY_TRACKBALL_RIGHT_PIN, PAL_EVENT_MODE_RISING_EDGE );
palSetLineCallback(BLACKBERRY_TRACKBALL_RIGHT_PIN, trackball_movement_cb, (void *)M_RIGHT);
}
report_mouse_t blackberry_trackball_get_report(report_mouse_t mouse_report) {
mouse_report.x = x;
mouse_report.y = y;
x = 0;
y = 0;
#ifdef BLACKBERRY_TRACKBALL_DEBUG
if (debug != '\0') {
uprintf("%c\n", debug);
}
debug = '\0';
#endif
return mouse_report;
}

View File

@@ -0,0 +1,56 @@
/*
* 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/>.
*/
/*
USAGE
In your rules.mk add:
POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = blackberry_trackball
Then define the following:
#define BLACKBERRY_TRACKBALL_DEBUG (optional, if you want to read the recognized direction)
#define BLACKBERRY_TRACKBALL_STEP 30 (optional. Cursor moves faster or slower, if you don't define it, defualt step is 5)
#define BLACKBERRY_TRACKBALL_UP_PIN pin_1 (required, where the "up" hall effect sensor is connected)
#define BLACKBERRY_TRACKBALL_DOWN_PIN pin_2 (required, where the "down" hall effect sensor is connected)
#define BLACKBERRY_TRACKBALL_LEFT_PIN pin_3 (required, where the "left" hall effect sensor is connected)
#define BLACKBERRY_TRACKBALL_RIGHT_PIN pin_4 (required, where the "right" hall effect sensor is connected)
*/
#pragma once
#include "pointing_device.h"
#ifndef BLACKBERRY_TRACKBALL_STEP
# define BLACKBERRY_TRACKBALL_STEP 5
#endif
#define M_UP 0
#define M_DOWN 1
#define M_LEFT 2
#define M_RIGHT 3
const pointing_device_driver_t blackberry_trackball_pointing_device_driver;
void blackberry_trackball_init(void);
report_mouse_t blackberry_trackball_get_report(report_mouse_t mouse_report);

View File

@@ -70,6 +70,8 @@ typedef struct {
# define POINTING_DEVICE_ROTATION_90
# endif
# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#elif defined(POINTING_DEVICE_DRIVER_blackberry_trackball)
# include "drivers/sensors/blackberry_trackball.h"
#elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389)
# include "spi_master.h"
# include "drivers/sensors/pmw33xx_common.h"