From 76fb54403ccd3ebaf1ca49c5172335e3593c5c5c Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Tue, 2 Nov 2021 07:54:29 +0200 Subject: 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. --- drivers/haptic/solenoid.c | 16 ++++++++++------ drivers/haptic/solenoid.h | 8 ++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c index 25cf344655..7a09940f78 100644 --- a/drivers/haptic/solenoid.c +++ b/drivers/haptic/solenoid.c @@ -19,6 +19,7 @@ #include "solenoid.h" #include "haptic.h" #include "gpio.h" +#include "usb_device_state.h" bool solenoid_on = false; bool solenoid_buzzing = false; @@ -36,7 +37,7 @@ void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); } void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; } void solenoid_stop(void) { - writePinLow(SOLENOID_PIN); + SOLENOID_PIN_WRITE_INACTIVE(); solenoid_on = false; solenoid_buzzing = false; } @@ -48,7 +49,7 @@ void solenoid_fire(void) { solenoid_on = true; solenoid_buzzing = true; solenoid_start = timer_read(); - writePinHigh(SOLENOID_PIN); + SOLENOID_PIN_WRITE_ACTIVE(); } void solenoid_check(void) { @@ -69,20 +70,23 @@ void solenoid_check(void) { if ((elapsed % (SOLENOID_BUZZ_ACTUATED + SOLENOID_BUZZ_NONACTUATED)) < SOLENOID_BUZZ_ACTUATED) { if (!solenoid_buzzing) { solenoid_buzzing = true; - writePinHigh(SOLENOID_PIN); + SOLENOID_PIN_WRITE_ACTIVE(); } } else { if (solenoid_buzzing) { solenoid_buzzing = false; - writePinLow(SOLENOID_PIN); + SOLENOID_PIN_WRITE_INACTIVE(); } } } } void solenoid_setup(void) { + SOLENOID_PIN_WRITE_INACTIVE(); setPinOutput(SOLENOID_PIN); - solenoid_fire(); + if ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state == USB_DEVICE_STATE_CONFIGURED)) { + solenoid_fire(); + } } -void solenoid_shutdown(void) { writePinLow(SOLENOID_PIN); } +void solenoid_shutdown(void) { SOLENOID_PIN_WRITE_INACTIVE(); } diff --git a/drivers/haptic/solenoid.h b/drivers/haptic/solenoid.h index f2a3bc4c30..653148154f 100644 --- a/drivers/haptic/solenoid.h +++ b/drivers/haptic/solenoid.h @@ -49,6 +49,14 @@ # error SOLENOID_PIN not defined #endif +#ifdef SOLENOID_PIN_ACTIVE_LOW +# define SOLENOID_PIN_WRITE_ACTIVE() writePinLow(SOLENOID_PIN) +# define SOLENOID_PIN_WRITE_INACTIVE() writePinHigh(SOLENOID_PIN) +#else +# define SOLENOID_PIN_WRITE_ACTIVE() writePinHigh(SOLENOID_PIN) +# define SOLENOID_PIN_WRITE_INACTIVE() writePinLow(SOLENOID_PIN) +#endif + void solenoid_buzz_on(void); void solenoid_buzz_off(void); void solenoid_set_buzz(int buzz); -- cgit v1.2.3