diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/haptic.c | 51 | ||||
-rw-r--r-- | quantum/haptic.h | 27 | ||||
-rw-r--r-- | quantum/process_keycode/process_haptic.c | 3 |
3 files changed, 77 insertions, 4 deletions
diff --git a/quantum/haptic.c b/quantum/haptic.c index 65abcc15f..f915acf94 100644 --- a/quantum/haptic.c +++ b/quantum/haptic.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include "haptic.h" | 17 | #include "haptic.h" |
18 | #include "eeconfig.h" | 18 | #include "eeconfig.h" |
19 | #include "debug.h" | 19 | #include "debug.h" |
20 | #include "usb_device_state.h" | ||
21 | #include "gpio.h" | ||
20 | #ifdef DRV2605L | 22 | #ifdef DRV2605L |
21 | # include "DRV2605L.h" | 23 | # include "DRV2605L.h" |
22 | #endif | 24 | #endif |
@@ -26,6 +28,29 @@ | |||
26 | 28 | ||
27 | haptic_config_t haptic_config; | 29 | haptic_config_t haptic_config; |
28 | 30 | ||
31 | static void update_haptic_enable_gpios(void) { | ||
32 | if (haptic_config.enable && ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state == USB_DEVICE_STATE_CONFIGURED))) { | ||
33 | #if defined(HAPTIC_ENABLE_PIN) | ||
34 | HAPTIC_ENABLE_PIN_WRITE_ACTIVE(); | ||
35 | #endif | ||
36 | #if defined(HAPTIC_ENABLE_STATUS_LED) | ||
37 | HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE(); | ||
38 | #endif | ||
39 | } else { | ||
40 | #if defined(HAPTIC_ENABLE_PIN) | ||
41 | HAPTIC_ENABLE_PIN_WRITE_INACTIVE(); | ||
42 | #endif | ||
43 | #if defined(HAPTIC_ENABLE_STATUS_LED) | ||
44 | HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE(); | ||
45 | #endif | ||
46 | } | ||
47 | } | ||
48 | |||
49 | static void set_haptic_config_enable(bool enabled) { | ||
50 | haptic_config.enable = enabled; | ||
51 | update_haptic_enable_gpios(); | ||
52 | } | ||
53 | |||
29 | void haptic_init(void) { | 54 | void haptic_init(void) { |
30 | if (!eeconfig_is_enabled()) { | 55 | if (!eeconfig_is_enabled()) { |
31 | eeconfig_init(); | 56 | eeconfig_init(); |
@@ -44,6 +69,10 @@ void haptic_init(void) { | |||
44 | // or the previous firmware didn't have solenoid enabled, | 69 | // or the previous firmware didn't have solenoid enabled, |
45 | // and the current one has solenoid enabled. | 70 | // and the current one has solenoid enabled. |
46 | haptic_reset(); | 71 | haptic_reset(); |
72 | } else { | ||
73 | // Haptic configuration has been loaded through the "raw" union item. | ||
74 | // This is to execute any side effects of the configuration. | ||
75 | set_haptic_config_enable(haptic_config.enable); | ||
47 | } | 76 | } |
48 | #ifdef SOLENOID_ENABLE | 77 | #ifdef SOLENOID_ENABLE |
49 | solenoid_setup(); | 78 | solenoid_setup(); |
@@ -54,6 +83,12 @@ void haptic_init(void) { | |||
54 | dprintf("DRV2605 driver initialized\n"); | 83 | dprintf("DRV2605 driver initialized\n"); |
55 | #endif | 84 | #endif |
56 | eeconfig_debug_haptic(); | 85 | eeconfig_debug_haptic(); |
86 | #ifdef HAPTIC_ENABLE_PIN | ||
87 | setPinOutput(HAPTIC_ENABLE_PIN); | ||
88 | #endif | ||
89 | #ifdef HAPTIC_ENABLE_STATUS_LED | ||
90 | setPinOutput(HAPTIC_ENABLE_STATUS_LED); | ||
91 | #endif | ||
57 | } | 92 | } |
58 | 93 | ||
59 | void haptic_task(void) { | 94 | void haptic_task(void) { |
@@ -69,13 +104,13 @@ void eeconfig_debug_haptic(void) { | |||
69 | } | 104 | } |
70 | 105 | ||
71 | void haptic_enable(void) { | 106 | void haptic_enable(void) { |
72 | haptic_config.enable = 1; | 107 | set_haptic_config_enable(true); |
73 | xprintf("haptic_config.enable = %u\n", haptic_config.enable); | 108 | xprintf("haptic_config.enable = %u\n", haptic_config.enable); |
74 | eeconfig_update_haptic(haptic_config.raw); | 109 | eeconfig_update_haptic(haptic_config.raw); |
75 | } | 110 | } |
76 | 111 | ||
77 | void haptic_disable(void) { | 112 | void haptic_disable(void) { |
78 | haptic_config.enable = 0; | 113 | set_haptic_config_enable(false); |
79 | xprintf("haptic_config.enable = %u\n", haptic_config.enable); | 114 | xprintf("haptic_config.enable = %u\n", haptic_config.enable); |
80 | eeconfig_update_haptic(haptic_config.raw); | 115 | eeconfig_update_haptic(haptic_config.raw); |
81 | } | 116 | } |
@@ -157,7 +192,7 @@ void haptic_dwell_decrease(void) { | |||
157 | } | 192 | } |
158 | 193 | ||
159 | void haptic_reset(void) { | 194 | void haptic_reset(void) { |
160 | haptic_config.enable = true; | 195 | set_haptic_config_enable(true); |
161 | uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT; | 196 | uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT; |
162 | haptic_config.feedback = feedback; | 197 | haptic_config.feedback = feedback; |
163 | #ifdef DRV2605L | 198 | #ifdef DRV2605L |
@@ -293,3 +328,13 @@ void haptic_shutdown(void) { | |||
293 | solenoid_shutdown(); | 328 | solenoid_shutdown(); |
294 | #endif | 329 | #endif |
295 | } | 330 | } |
331 | |||
332 | void haptic_notify_usb_device_state_change(void) { | ||
333 | update_haptic_enable_gpios(); | ||
334 | #if defined(HAPTIC_ENABLE_PIN) | ||
335 | setPinOutput(HAPTIC_ENABLE_PIN); | ||
336 | #endif | ||
337 | #if defined(HAPTIC_ENABLE_STATUS_LED) | ||
338 | setPinOutput(HAPTIC_ENABLE_STATUS_LED); | ||
339 | #endif | ||
340 | } | ||
diff --git a/quantum/haptic.h b/quantum/haptic.h index fc7ca2f3e..7d70a0133 100644 --- a/quantum/haptic.h +++ b/quantum/haptic.h | |||
@@ -75,3 +75,30 @@ void haptic_cont_decrease(void); | |||
75 | 75 | ||
76 | void haptic_play(void); | 76 | void haptic_play(void); |
77 | void haptic_shutdown(void); | 77 | void haptic_shutdown(void); |
78 | void haptic_notify_usb_device_state_change(void); | ||
79 | |||
80 | #ifdef HAPTIC_ENABLE_PIN_ACTIVE_LOW | ||
81 | # ifndef HAPTIC_ENABLE_PIN | ||
82 | # error HAPTIC_ENABLE_PIN not defined | ||
83 | # endif | ||
84 | # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() writePinLow(HAPTIC_ENABLE_PIN) | ||
85 | # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() writePinHigh(HAPTIC_ENABLE_PIN) | ||
86 | #else | ||
87 | # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() writePinHigh(HAPTIC_ENABLE_PIN) | ||
88 | # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() writePinLow(HAPTIC_ENABLE_PIN) | ||
89 | #endif | ||
90 | |||
91 | #ifdef HAPTIC_ENABLE_STATUS_LED_ACTIVE_LOW | ||
92 | # ifndef HAPTIC_ENABLE_STATUS_LED | ||
93 | # error HAPTIC_ENABLE_STATUS_LED not defined | ||
94 | # endif | ||
95 | # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() writePinLow(HAPTIC_ENABLE_STATUS_LED) | ||
96 | # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() writePinHigh(HAPTIC_ENABLE_STATUS_LED) | ||
97 | #else | ||
98 | # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() writePinHigh(HAPTIC_ENABLE_STATUS_LED) | ||
99 | # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() writePinLow(HAPTIC_ENABLE_STATUS_LED) | ||
100 | #endif | ||
101 | |||
102 | #ifndef HAPTIC_OFF_IN_LOW_POWER | ||
103 | # define HAPTIC_OFF_IN_LOW_POWER 0 | ||
104 | #endif | ||
diff --git a/quantum/process_keycode/process_haptic.c b/quantum/process_keycode/process_haptic.c index 1b9c2f24f..466c8e554 100644 --- a/quantum/process_keycode/process_haptic.c +++ b/quantum/process_keycode/process_haptic.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "process_haptic.h" | 17 | #include "process_haptic.h" |
18 | #include "quantum_keycodes.h" | 18 | #include "quantum_keycodes.h" |
19 | #include "action_tapping.h" | 19 | #include "action_tapping.h" |
20 | #include "usb_device_state.h" | ||
20 | 21 | ||
21 | __attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) { | 22 | __attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) { |
22 | switch (keycode) { | 23 | switch (keycode) { |
@@ -131,7 +132,7 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) { | |||
131 | } | 132 | } |
132 | } | 133 | } |
133 | 134 | ||
134 | if (haptic_get_enable()) { | 135 | if (haptic_get_enable() && ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state == USB_DEVICE_STATE_CONFIGURED))) { |
135 | if (record->event.pressed) { | 136 | if (record->event.pressed) { |
136 | // keypress | 137 | // keypress |
137 | if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) { | 138 | if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) { |