aboutsummaryrefslogtreecommitdiff
path: root/quantum/joystick.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/joystick.h')
-rw-r--r--quantum/joystick.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/quantum/joystick.h b/quantum/joystick.h
new file mode 100644
index 000000000..a95472b9f
--- /dev/null
+++ b/quantum/joystick.h
@@ -0,0 +1,54 @@
1#pragma once
2
3#ifndef JOYSTICK_BUTTON_COUNT
4# define JOYSTICK_BUTTON_COUNT 8
5#endif
6
7#ifndef JOYSTICK_AXES_COUNT
8# define JOYSTICK_AXES_COUNT 4
9#endif
10
11#include "quantum.h"
12
13#include <stdint.h>
14
15// configure on input_pin of the joystick_axes array entry to JS_VIRTUAL_AXIS
16// to prevent it from being read from the ADC. This allows outputing forged axis value.
17//
18#define JS_VIRTUAL_AXIS 0xFF
19
20#define JOYSTICK_AXIS_VIRTUAL \
21 { JS_VIRTUAL_AXIS, JS_VIRTUAL_AXIS, JS_VIRTUAL_AXIS, 0, 1023 }
22#define JOYSTICK_AXIS_IN(INPUT_PIN, LOW, REST, HIGH) \
23 { JS_VIRTUAL_AXIS, INPUT_PIN, JS_VIRTUAL_AXIS, LOW, REST, HIGH }
24#define JOYSTICK_AXIS_IN_OUT(INPUT_PIN, OUTPUT_PIN, LOW, REST, HIGH) \
25 { OUTPUT_PIN, INPUT_PIN, JS_VIRTUAL_AXIS, LOW, REST, HIGH }
26#define JOYSTICK_AXIS_IN_OUT_GROUND(INPUT_PIN, OUTPUT_PIN, GROUND_PIN, LOW, REST, HIGH) \
27 { OUTPUT_PIN, INPUT_PIN, GROUND_PIN, LOW, REST, HIGH }
28
29typedef struct {
30 pin_t output_pin;
31 pin_t input_pin;
32 pin_t ground_pin;
33
34 // the AVR ADC offers 10 bit precision, with significant bits on the higher part
35 uint16_t min_digit;
36 uint16_t mid_digit;
37 uint16_t max_digit;
38} joystick_config_t;
39
40extern joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT];
41
42enum joystick_status { JS_INITIALIZED = 1, JS_UPDATED = 2 };
43
44typedef struct {
45 uint8_t buttons[JOYSTICK_BUTTON_COUNT / 8 + 1];
46
47 int16_t axes[JOYSTICK_AXES_COUNT];
48 uint8_t status : 2;
49} joystick_t;
50
51extern joystick_t joystick_status;
52
53// to be implemented in the hid protocol library
54void send_joystick_packet(joystick_t *joystick);