From d059624bfb32e268ff0972609d7eadbb212fa2d2 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Mon, 5 Dec 2016 01:07:12 +0700 Subject: [PATCH 1/2] Implemented weak ps2_mouse_init_user() There are a lot of PS/2 commands, some are vendor/device specific, so we provide a weak ps2_mouse_init_user() to be implemented in each keyboard that need it. --- tmk_core/protocol/ps2_mouse.c | 54 +++++------------------------------ tmk_core/protocol/ps2_mouse.h | 49 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index af971dd49..e3c697444 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -28,53 +28,7 @@ along with this program. If not, see . /* ============================= MACROS ============================ */ -#define PS2_MOUSE_SEND(command, message) \ -do { \ - uint8_t rcv = ps2_host_send(command); \ - if (debug_mouse) { \ - print((message)); \ - xprintf(" command: %X, result: %X, error: %X \n", command, rcv, ps2_error); \ - } \ -} while(0) - -#define PS2_MOUSE_SEND_SAFE(command, message) \ -do { \ - if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ - ps2_mouse_disable_data_reporting(); \ - } \ - PS2_MOUSE_SEND(command, message); \ - if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ - ps2_mouse_enable_data_reporting(); \ - } \ -} while(0) - -#define PS2_MOUSE_SET_SAFE(command, value, message) \ -do { \ - if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ - ps2_mouse_disable_data_reporting(); \ - } \ - PS2_MOUSE_SEND(command, message); \ - PS2_MOUSE_SEND(value, "Sending value"); \ - if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ - ps2_mouse_enable_data_reporting(); \ - } \ -} while(0) - -#define PS2_MOUSE_RECEIVE(message) \ -do { \ - uint8_t rcv = ps2_host_recv_response(); \ - if (debug_mouse) { \ - print((message)); \ - xprintf(" result: %X, error: %X \n", rcv, ps2_error); \ - } \ -} while(0) - -static enum ps2_mouse_mode_e { - PS2_MOUSE_STREAM_MODE, - PS2_MOUSE_REMOTE_MODE, -} ps2_mouse_mode = PS2_MOUSE_STREAM_MODE; - -static report_mouse_t mouse_report = {}; +static report_mouse_t mouse_report = {};./ static inline void ps2_mouse_print_report(report_mouse_t *mouse_report); static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report); @@ -108,6 +62,12 @@ void ps2_mouse_init(void) { #ifdef PS2_MOUSE_USE_2_1_SCALING ps2_mouse_set_scaling_2_1(); #endif + + ps2_mouse_init_user(); +} + +__attribute__((weak)) +void ps2_mouse_init_user(void) { } void ps2_mouse_task(void) { diff --git a/tmk_core/protocol/ps2_mouse.h b/tmk_core/protocol/ps2_mouse.h index e11c705fc..3c93a4634 100644 --- a/tmk_core/protocol/ps2_mouse.h +++ b/tmk_core/protocol/ps2_mouse.h @@ -19,6 +19,53 @@ along with this program. If not, see . #define PS2_MOUSE_H #include +#include "debug.h" + +#define PS2_MOUSE_SEND(command, message) \ +do { \ + uint8_t rcv = ps2_host_send(command); \ + if (debug_mouse) { \ + print((message)); \ + xprintf(" command: %X, result: %X, error: %X \n", command, rcv, ps2_error); \ + } \ +} while(0) + +#define PS2_MOUSE_SEND_SAFE(command, message) \ +do { \ + if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ + ps2_mouse_disable_data_reporting(); \ + } \ + PS2_MOUSE_SEND(command, message); \ + if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ + ps2_mouse_enable_data_reporting(); \ + } \ +} while(0) + +#define PS2_MOUSE_SET_SAFE(command, value, message) \ +do { \ + if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ + ps2_mouse_disable_data_reporting(); \ + } \ + PS2_MOUSE_SEND(command, message); \ + PS2_MOUSE_SEND(value, "Sending value"); \ + if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ + ps2_mouse_enable_data_reporting(); \ + } \ +} while(0) + +#define PS2_MOUSE_RECEIVE(message) \ +do { \ + uint8_t rcv = ps2_host_recv_response(); \ + if (debug_mouse) { \ + print((message)); \ + xprintf(" result: %X, error: %X \n", rcv, ps2_error); \ + } \ +} while(0) + +static enum ps2_mouse_mode_e { + PS2_MOUSE_STREAM_MODE, + PS2_MOUSE_REMOTE_MODE, +} ps2_mouse_mode = PS2_MOUSE_STREAM_MODE; /* * Data format: @@ -107,6 +154,8 @@ typedef enum ps2_mouse_sample_rate_e { void ps2_mouse_init(void); +void ps2_mouse_init_user(void); + void ps2_mouse_task(void); void ps2_mouse_disable_data_reporting(void); From 07d29b7d29ce13a22f50270ab54d39f80103cc44 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Mon, 5 Dec 2016 01:22:40 +0700 Subject: [PATCH 2/2] syntax error fix --- tmk_core/protocol/ps2_mouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index e3c697444..d9ccbecb4 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -28,7 +28,7 @@ along with this program. If not, see . /* ============================= MACROS ============================ */ -static report_mouse_t mouse_report = {};./ +static report_mouse_t mouse_report = {}; static inline void ps2_mouse_print_report(report_mouse_t *mouse_report); static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report);