Skip to content

Commit

Permalink
core: Mouse buttons state integration #101
Browse files Browse the repository at this point in the history
This allows users to use mousekey buttons with PS/2, ADB or
Serial pointing device.
  • Loading branch information
tmk committed Nov 13, 2021
1 parent b981b8e commit 5f7d388
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 0 deletions.
5 changes: 5 additions & 0 deletions converter/adb_usb/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ void adb_mouse_task(void)

return;
}

uint8_t adb_mouse_buttons(void)
{
return mouse_report.buttons;
}
#endif

uint8_t matrix_scan(void)
Expand Down
9 changes: 9 additions & 0 deletions converter/ibmpc_usb/ibmpc_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ action_t action_for_key(uint8_t layer, keypos_t key)
return (action_t){ .code = pgm_read_word(&actionmaps[(layer)][key.row & 0x07][key.col & 0x0F]) };
}

#ifdef IBMPC_MOUSE_ENABLE
static uint8_t last_buttons;
uint8_t ibmpc_mouse_buttons(void)
{
return last_buttons;
}
#endif


void IBMPCConverter::set_led(uint8_t usb_led)
{
Expand Down Expand Up @@ -607,6 +615,7 @@ uint8_t IBMPCConverter::process_interface(void)
mouse_report.v = -CHOP8(v);
mouse_report.h = CHOP8(h);
host_mouse_send(&mouse_report);
last_buttons = mouse_report.buttons;
xprintf("M[x:%d y:%d v:%d h:%d b:%02X]\n", mouse_report.x, mouse_report.y,
mouse_report.v, mouse_report.h, mouse_report.buttons);
break; }
Expand Down
4 changes: 4 additions & 0 deletions converter/ibmpc_usb/ibmpc_usb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#define ROW(code) ((code>>4)&0x07)
#define COL(code) (code&0x0F)

#ifdef IBMPC_MOUSE_ENABLE
extern "C" uint8_t ibmpc_mouse_buttons(void);
#endif


class IBMPCConverter {
public:
Expand Down
35 changes: 35 additions & 0 deletions tmk_core/common/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "util.h"
#include "debug.h"

#ifdef MOUSEKEY_ENABLE
# include "mousekey.h"
#endif
#ifdef PS2_MOUSE_ENABLE
# include "ps2_mouse.h"
#endif
#ifdef SERIAL_MOUSE_ENABLE
# include "serial_mouse.h"
#endif
#ifdef ADB_MOUSE_ENABLE
# include "adb.h"
#endif
#ifdef IBMPC_MOUSE_ENABLE
uint8_t ibmpc_mouse_buttons(void);
#endif


#if defined(NKRO_ENABLE) || defined(NKRO_6KRO_ENABLE)
bool keyboard_nkro = true;
Expand Down Expand Up @@ -70,7 +86,26 @@ void host_mouse_send(report_mouse_t *report)
report->boot_x = (report->x > 127) ? 127 : ((report->x < -127) ? -127 : report->x);
report->boot_y = (report->y > 127) ? 127 : ((report->y < -127) ? -127 : report->y);
#endif

/* Mouse buttons integration */
uint8_t b = report->buttons;
#ifdef MOUSEKEY_ENABLE
report->buttons |= mousekey_buttons();
#endif
#ifdef PS2_MOUSE_ENABLE
report->buttons |= ps2_mouse_buttons();
#endif
#ifdef SERIAL_MOUSE_ENABLE
report->buttons |= serial_mouse_buttons();
#endif
#ifdef ADB_MOUSE_ENABLE
report->buttons |= adb_mouse_buttons();
#endif
#ifdef IBMPC_MOUSE_ENABLE
report->buttons |= ibmpc_mouse_buttons();
#endif
(*driver->send_mouse)(report);
report->buttons = b;
}

void host_system_send(uint16_t report)
Expand Down
5 changes: 5 additions & 0 deletions tmk_core/common/mousekey.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ void mousekey_clear(void)
mousekey_accel = 0;
}

uint8_t mousekey_buttons(void)
{
return mouse_report.buttons;
}

static void mousekey_debug(void)
{
if (!debug_mouse) return;
Expand Down
1 change: 1 addition & 0 deletions tmk_core/common/mousekey.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void mousekey_on(uint8_t code);
void mousekey_off(uint8_t code);
void mousekey_clear(void);
void mousekey_send(void);
uint8_t mousekey_buttons(void);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions tmk_core/protocol/adb.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void adb_host_reset_hard(void);
void adb_host_kbd_led(uint8_t addr, uint8_t led);
void adb_mouse_task(void);
void adb_mouse_init(void);
uint8_t adb_mouse_buttons(void);


#endif
7 changes: 7 additions & 0 deletions tmk_core/protocol/ps2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.


static report_mouse_t mouse_report = {};
static uint8_t last_buttons;


static void print_usb_data(void);
Expand Down Expand Up @@ -161,6 +162,7 @@ void ps2_mouse_task(void)


host_mouse_send(&mouse_report);
last_buttons = mouse_report.buttons;
print_usb_data();
}
// clear report
Expand All @@ -171,6 +173,11 @@ void ps2_mouse_task(void)
mouse_report.buttons = 0;
}

uint8_t ps2_mouse_buttons(void)
{
return last_buttons;
}

static void print_usb_data(void)
{
if (!debug_mouse) return;
Expand Down
1 change: 1 addition & 0 deletions tmk_core/protocol/ps2_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

uint8_t ps2_mouse_init(void);
void ps2_mouse_task(void);
uint8_t ps2_mouse_buttons(void);

#endif
1 change: 1 addition & 0 deletions tmk_core/protocol/serial_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ static inline uint8_t serial_mouse_init(void)
}

void serial_mouse_task(void);
uint8_t serial_mouse_buttons(void);

#endif
8 changes: 8 additions & 0 deletions tmk_core/protocol/serial_mouse_microsoft.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))

static uint8_t last_buttons;
static void print_usb_data(const report_mouse_t *report);

void serial_mouse_task(void)
Expand Down Expand Up @@ -71,6 +72,7 @@ void serial_mouse_task(void)

print_usb_data(&report);
host_mouse_send(&report);
last_buttons = report.buttons;
return;
}

Expand Down Expand Up @@ -111,6 +113,12 @@ void serial_mouse_task(void)

print_usb_data(&report);
host_mouse_send(&report);
last_buttons = report.buttons;
}

uint8_t serial_mouse_buttons(void)
{
return last_buttons;
}

static void print_usb_data(const report_mouse_t *report)
Expand Down
9 changes: 9 additions & 0 deletions tmk_core/protocol/serial_mouse_mousesystems.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

//#define SERIAL_MOUSE_CENTER_SCROLL

static uint8_t last_buttons;
static void print_usb_data(const report_mouse_t *report);

void serial_mouse_task(void)
Expand Down Expand Up @@ -78,13 +79,15 @@ void serial_mouse_task(void)

print_usb_data(&report);
host_mouse_send(&report);
last_buttons = report.buttons;

if (buffer[3] || buffer[4]) {
report.h = MAX((int8_t)buffer[3], -127);
report.v = MAX((int8_t)buffer[4], -127);

print_usb_data(&report);
host_mouse_send(&report);
last_buttons = report.buttons;
}

return;
Expand Down Expand Up @@ -117,9 +120,15 @@ void serial_mouse_task(void)

print_usb_data(&report);
host_mouse_send(&report);
last_buttons = report.buttons;
}
}

uint8_t serial_mouse_buttons(void)
{
return last_buttons;
}

static void print_usb_data(const report_mouse_t *report)
{
if (!debug_mouse)
Expand Down

0 comments on commit 5f7d388

Please sign in to comment.