aboutsummaryrefslogtreecommitdiff
path: root/quantum/haptic.c
diff options
context:
space:
mode:
authorPurdea Andrei <andrei@purdea.ro>2021-11-02 07:54:29 +0200
committerGitHub <noreply@github.com>2021-11-02 16:54:29 +1100
commit76fb54403ccd3ebaf1ca49c5172335e3593c5c5c (patch)
tree30b41c0b027baa5b9494f80ec0fd83c50a53fd5b /quantum/haptic.c
parent85d94d0c4d97de3d1b7ce0476499f44e79c25944 (diff)
downloadqmk_firmware-76fb54403ccd3ebaf1ca49c5172335e3593c5c5c.tar.gz
qmk_firmware-76fb54403ccd3ebaf1ca49c5172335e3593c5c5c.zip
haptic: Feature to disable it when usb port is not configured or suspended. (#12692)
This also add support for specifying a LED pin to indicate haptic status, and also adds support for a haptic-enable pin, which is useful to turn off the boost converter on the solenoid driver.
Diffstat (limited to 'quantum/haptic.c')
-rw-r--r--quantum/haptic.c51
1 files changed, 48 insertions, 3 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
27haptic_config_t haptic_config; 29haptic_config_t haptic_config;
28 30
31static 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
49static void set_haptic_config_enable(bool enabled) {
50 haptic_config.enable = enabled;
51 update_haptic_enable_gpios();
52}
53
29void haptic_init(void) { 54void 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
59void haptic_task(void) { 94void haptic_task(void) {
@@ -69,13 +104,13 @@ void eeconfig_debug_haptic(void) {
69} 104}
70 105
71void haptic_enable(void) { 106void 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
77void haptic_disable(void) { 112void 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
159void haptic_reset(void) { 194void 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
332void 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}