summaryrefslogtreecommitdiff
path: root/quantum/joystick.c
blob: 86b2c64036b1886f33fb3fbd35a9a860c0c5f771 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "joystick.h"

// clang-format off
joystick_t joystick_status = {
    .buttons = {0},
    .axes = {
#if JOYSTICK_AXES_COUNT > 0
        0
#endif
    },
    .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();
}