From c05e8afe454bf3706d69314c251dc5266c557007 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 27 Mar 2022 05:38:09 +1100 Subject: Joystick feature updates (#16732) * Joystick feature updates * Move new functions to joystick.h * Docs --- quantum/joystick.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'quantum/joystick.c') diff --git a/quantum/joystick.c b/quantum/joystick.c index 7b87201aef..86b2c64036 100644 --- a/quantum/joystick.c +++ b/quantum/joystick.c @@ -1,13 +1,38 @@ #include "joystick.h" -joystick_t joystick_status = {.buttons = {0}, - .axes = - { +// clang-format off +joystick_t joystick_status = { + .buttons = {0}, + .axes = { #if JOYSTICK_AXES_COUNT > 0 - 0 + 0 #endif - }, - .status = 0}; + }, + .status = 0 +}; +// clang-format on // array defining the reading of analog values for each axis __attribute__((weak)) joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {}; + +// to be implemented in the hid protocol library +void send_joystick_packet(joystick_t *joystick); + +void joystick_flush(void) { + if ((joystick_status.status & JS_UPDATED) > 0) { + send_joystick_packet(&joystick_status); + joystick_status.status &= ~JS_UPDATED; + } +} + +void register_joystick_button(uint8_t button) { + joystick_status.buttons[button / 8] |= 1 << (button % 8); + joystick_status.status |= JS_UPDATED; + joystick_flush(); +} + +void unregister_joystick_button(uint8_t button) { + joystick_status.buttons[button / 8] &= ~(1 << (button % 8)); + joystick_status.status |= JS_UPDATED; + joystick_flush(); +} -- cgit v1.2.3