Skip to content

Commit

Permalink
more primitive way to reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
koron committed Mar 21, 2024
1 parent d4ff08c commit 73de064
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions qmk_firmware/keyboards/keyball/lib/keyball/keyball.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73de064

Please sign in to comment.