From 73de064b75837a0e8a4cd50f6480467ef4257863 Mon Sep 17 00:00:00 2001 From: MURAOKA Taro Date: Thu, 21 Mar 2024 23:41:07 +0900 Subject: [PATCH] more primitive way to reduce size --- .../keyboards/keyball/lib/keyball/keyball.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c b/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c index 18581e486..f1ab9f7e8 100644 --- a/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c +++ b/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c @@ -65,6 +65,13 @@ static int16_t add16(int16_t a, int16_t b) { return r; } +// divmod16 divides *v by div, return the quotient, and put the remainder in *v. +static int16_t divmod16(int16_t *v, int16_t div) { + int16_t r = *v / div; + *v -= r * div; + return r; +} + // clip2int8 clips an integer fit into int8_t. static inline int8_t clip2int8(int16_t v) { return (v) < -127 ? -127 : (v) > 127 ? 127 : (int8_t)v; @@ -171,11 +178,9 @@ static void motion_to_mouse_move(keyball_motion_t *m, report_mouse_t *r, bool is static void motion_to_mouse_scroll(keyball_motion_t *m, report_mouse_t *r, bool is_left) { // consume motion of trackball. - uint8_t div = keyball_get_scroll_div() - 1; - int16_t x = m->x / (1 << div); - m->x -= x << div; - int16_t y = m->y / (1 << div); - m->y -= y << div; + int16_t div = 1 << (keyball_get_scroll_div() - 1); + int16_t x = divmod16(&m->x, div); + int16_t y = divmod16(&m->y, div); // apply to mouse report. #if KEYBALL_MODEL == 61 || KEYBALL_MODEL == 39 || KEYBALL_MODEL == 147 || KEYBALL_MODEL == 44