diff options
| author | Purdea Andrei <andrei@purdea.ro> | 2021-11-02 07:54:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-02 16:54:29 +1100 |
| commit | 76fb54403ccd3ebaf1ca49c5172335e3593c5c5c (patch) | |
| tree | 30b41c0b027baa5b9494f80ec0fd83c50a53fd5b /drivers | |
| parent | 85d94d0c4d97de3d1b7ce0476499f44e79c25944 (diff) | |
| download | qmk_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 'drivers')
| -rw-r--r-- | drivers/haptic/solenoid.c | 16 | ||||
| -rw-r--r-- | drivers/haptic/solenoid.h | 8 |
2 files changed, 18 insertions, 6 deletions
diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c index 25cf34465..7a09940f7 100644 --- a/drivers/haptic/solenoid.c +++ b/drivers/haptic/solenoid.c | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "solenoid.h" | 19 | #include "solenoid.h" |
| 20 | #include "haptic.h" | 20 | #include "haptic.h" |
| 21 | #include "gpio.h" | 21 | #include "gpio.h" |
| 22 | #include "usb_device_state.h" | ||
| 22 | 23 | ||
| 23 | bool solenoid_on = false; | 24 | bool solenoid_on = false; |
| 24 | bool solenoid_buzzing = false; | 25 | bool solenoid_buzzing = false; |
| @@ -36,7 +37,7 @@ void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); } | |||
| 36 | void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; } | 37 | void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; } |
| 37 | 38 | ||
| 38 | void solenoid_stop(void) { | 39 | void solenoid_stop(void) { |
| 39 | writePinLow(SOLENOID_PIN); | 40 | SOLENOID_PIN_WRITE_INACTIVE(); |
| 40 | solenoid_on = false; | 41 | solenoid_on = false; |
| 41 | solenoid_buzzing = false; | 42 | solenoid_buzzing = false; |
| 42 | } | 43 | } |
| @@ -48,7 +49,7 @@ void solenoid_fire(void) { | |||
| 48 | solenoid_on = true; | 49 | solenoid_on = true; |
| 49 | solenoid_buzzing = true; | 50 | solenoid_buzzing = true; |
| 50 | solenoid_start = timer_read(); | 51 | solenoid_start = timer_read(); |
| 51 | writePinHigh(SOLENOID_PIN); | 52 | SOLENOID_PIN_WRITE_ACTIVE(); |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | void solenoid_check(void) { | 55 | void solenoid_check(void) { |
| @@ -69,20 +70,23 @@ void solenoid_check(void) { | |||
| 69 | if ((elapsed % (SOLENOID_BUZZ_ACTUATED + SOLENOID_BUZZ_NONACTUATED)) < SOLENOID_BUZZ_ACTUATED) { | 70 | if ((elapsed % (SOLENOID_BUZZ_ACTUATED + SOLENOID_BUZZ_NONACTUATED)) < SOLENOID_BUZZ_ACTUATED) { |
| 70 | if (!solenoid_buzzing) { | 71 | if (!solenoid_buzzing) { |
| 71 | solenoid_buzzing = true; | 72 | solenoid_buzzing = true; |
| 72 | writePinHigh(SOLENOID_PIN); | 73 | SOLENOID_PIN_WRITE_ACTIVE(); |
| 73 | } | 74 | } |
| 74 | } else { | 75 | } else { |
| 75 | if (solenoid_buzzing) { | 76 | if (solenoid_buzzing) { |
| 76 | solenoid_buzzing = false; | 77 | solenoid_buzzing = false; |
| 77 | writePinLow(SOLENOID_PIN); | 78 | SOLENOID_PIN_WRITE_INACTIVE(); |
| 78 | } | 79 | } |
| 79 | } | 80 | } |
| 80 | } | 81 | } |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | void solenoid_setup(void) { | 84 | void solenoid_setup(void) { |
| 85 | SOLENOID_PIN_WRITE_INACTIVE(); | ||
| 84 | setPinOutput(SOLENOID_PIN); | 86 | setPinOutput(SOLENOID_PIN); |
| 85 | solenoid_fire(); | 87 | if ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state == USB_DEVICE_STATE_CONFIGURED)) { |
| 88 | solenoid_fire(); | ||
| 89 | } | ||
| 86 | } | 90 | } |
| 87 | 91 | ||
| 88 | void solenoid_shutdown(void) { writePinLow(SOLENOID_PIN); } | 92 | void solenoid_shutdown(void) { SOLENOID_PIN_WRITE_INACTIVE(); } |
diff --git a/drivers/haptic/solenoid.h b/drivers/haptic/solenoid.h index f2a3bc4c3..653148154 100644 --- a/drivers/haptic/solenoid.h +++ b/drivers/haptic/solenoid.h | |||
| @@ -49,6 +49,14 @@ | |||
| 49 | # error SOLENOID_PIN not defined | 49 | # error SOLENOID_PIN not defined |
| 50 | #endif | 50 | #endif |
| 51 | 51 | ||
| 52 | #ifdef SOLENOID_PIN_ACTIVE_LOW | ||
| 53 | # define SOLENOID_PIN_WRITE_ACTIVE() writePinLow(SOLENOID_PIN) | ||
| 54 | # define SOLENOID_PIN_WRITE_INACTIVE() writePinHigh(SOLENOID_PIN) | ||
| 55 | #else | ||
| 56 | # define SOLENOID_PIN_WRITE_ACTIVE() writePinHigh(SOLENOID_PIN) | ||
| 57 | # define SOLENOID_PIN_WRITE_INACTIVE() writePinLow(SOLENOID_PIN) | ||
| 58 | #endif | ||
| 59 | |||
| 52 | void solenoid_buzz_on(void); | 60 | void solenoid_buzz_on(void); |
| 53 | void solenoid_buzz_off(void); | 61 | void solenoid_buzz_off(void); |
| 54 | void solenoid_set_buzz(int buzz); | 62 | void solenoid_set_buzz(int buzz); |
