summaryrefslogtreecommitdiff
path: root/quantum/joystick.c
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2022-05-29 15:38:33 -0700
committerDrashna Jael're <drashna@live.com>2022-05-29 15:38:33 -0700
commit30aac80d5a6d8c6f7c06efb49189d748e70edc4a (patch)
treeceb11968ae41228e4b110c07467cdca7cc9cff22 /quantum/joystick.c
parent67f4e5f34489abf986dedb4984b256692086c615 (diff)
parente22a183329fd05d39f88bb9dfebe98cfa7cd8402 (diff)
Merge remote-tracking branch 'qmk 0.17.0' into firmware21
Diffstat (limited to 'quantum/joystick.c')
-rw-r--r--quantum/joystick.c37
1 files changed, 31 insertions, 6 deletions
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();
+}