diff options
| author | Ryan <fauxpark@gmail.com> | 2024-11-10 09:10:10 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-09 14:10:10 -0800 |
| commit | a3cfb1dab7679a774d8aa09f7b609f3302dad73d (patch) | |
| tree | 315e8c7a35ae390b56f84def0d37b867bfa428c7 /quantum | |
| parent | 69093f6de9b551bd84ff0a8eabcccca73026d55e (diff) | |
Joystick: add support for 8-way hat switch (#24515)
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/joystick.c | 10 | ||||
| -rw-r--r-- | quantum/joystick.h | 22 |
2 files changed, 31 insertions, 1 deletions
diff --git a/quantum/joystick.c b/quantum/joystick.c index 32f19b2cd9..62893fd199 100644 --- a/quantum/joystick.c +++ b/quantum/joystick.c | |||
| @@ -29,6 +29,9 @@ joystick_t joystick_state = { | |||
| 29 | 0 | 29 | 0 |
| 30 | #endif | 30 | #endif |
| 31 | }, | 31 | }, |
| 32 | #ifdef JOYSTICK_HAS_HAT | ||
| 33 | .hat = -1, | ||
| 34 | #endif | ||
| 32 | .dirty = false, | 35 | .dirty = false, |
| 33 | }; | 36 | }; |
| 34 | 37 | ||
| @@ -145,6 +148,13 @@ void joystick_set_axis(uint8_t axis, int16_t value) { | |||
| 145 | } | 148 | } |
| 146 | } | 149 | } |
| 147 | 150 | ||
| 151 | #ifdef JOYSTICK_HAS_HAT | ||
| 152 | void joystick_set_hat(int8_t value) { | ||
| 153 | joystick_state.hat = value; | ||
| 154 | joystick_state.dirty = true; | ||
| 155 | } | ||
| 156 | #endif | ||
| 157 | |||
| 148 | void joystick_init(void) { | 158 | void joystick_init(void) { |
| 149 | joystick_init_axes(); | 159 | joystick_init_axes(); |
| 150 | } | 160 | } |
diff --git a/quantum/joystick.h b/quantum/joystick.h index 5a69ceac64..24f80c1ad6 100644 --- a/quantum/joystick.h +++ b/quantum/joystick.h | |||
| @@ -52,6 +52,16 @@ | |||
| 52 | 52 | ||
| 53 | #define JOYSTICK_MAX_VALUE ((1L << (JOYSTICK_AXIS_RESOLUTION - 1)) - 1) | 53 | #define JOYSTICK_MAX_VALUE ((1L << (JOYSTICK_AXIS_RESOLUTION - 1)) - 1) |
| 54 | 54 | ||
| 55 | #define JOYSTICK_HAT_CENTER -1 | ||
| 56 | #define JOYSTICK_HAT_NORTH 0 | ||
| 57 | #define JOYSTICK_HAT_NORTHEAST 1 | ||
| 58 | #define JOYSTICK_HAT_EAST 2 | ||
| 59 | #define JOYSTICK_HAT_SOUTHEAST 3 | ||
| 60 | #define JOYSTICK_HAT_SOUTH 4 | ||
| 61 | #define JOYSTICK_HAT_SOUTHWEST 5 | ||
| 62 | #define JOYSTICK_HAT_WEST 6 | ||
| 63 | #define JOYSTICK_HAT_NORTHWEST 7 | ||
| 64 | |||
| 55 | // configure on input_pin of the joystick_axes array entry to NO_PIN | 65 | // configure on input_pin of the joystick_axes array entry to NO_PIN |
| 56 | // to prevent it from being read from the ADC. This allows outputting forged axis value. | 66 | // to prevent it from being read from the ADC. This allows outputting forged axis value. |
| 57 | #define JOYSTICK_AXIS_VIRTUAL \ | 67 | #define JOYSTICK_AXIS_VIRTUAL \ |
| @@ -73,7 +83,10 @@ extern joystick_config_t joystick_axes[JOYSTICK_AXIS_COUNT]; | |||
| 73 | typedef struct { | 83 | typedef struct { |
| 74 | uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; | 84 | uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; |
| 75 | int16_t axes[JOYSTICK_AXIS_COUNT]; | 85 | int16_t axes[JOYSTICK_AXIS_COUNT]; |
| 76 | bool dirty; | 86 | #ifdef JOYSTICK_HAS_HAT |
| 87 | int8_t hat; | ||
| 88 | #endif | ||
| 89 | bool dirty; | ||
| 77 | } joystick_t; | 90 | } joystick_t; |
| 78 | 91 | ||
| 79 | extern joystick_t joystick_state; | 92 | extern joystick_t joystick_state; |
| @@ -129,4 +142,11 @@ void joystick_read_axes(void); | |||
| 129 | */ | 142 | */ |
| 130 | void joystick_set_axis(uint8_t axis, int16_t value); | 143 | void joystick_set_axis(uint8_t axis, int16_t value); |
| 131 | 144 | ||
| 145 | /** | ||
| 146 | * \brief Set the position of the hat switch. | ||
| 147 | * | ||
| 148 | * \param value The hat switch position to set. | ||
| 149 | */ | ||
| 150 | void joystick_set_hat(int8_t value); | ||
| 151 | |||
| 132 | /** \} */ | 152 | /** \} */ |
