1
0
Fork 0

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.
This commit is contained in:
Purdea Andrei 2021-11-02 07:54:29 +02:00 committed by GitHub
parent 85d94d0c4d
commit 76fb54403c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 115 additions and 11 deletions

View file

@ -17,6 +17,8 @@
#include "haptic.h"
#include "eeconfig.h"
#include "debug.h"
#include "usb_device_state.h"
#include "gpio.h"
#ifdef DRV2605L
# include "DRV2605L.h"
#endif
@ -26,6 +28,29 @@
haptic_config_t haptic_config;
static void update_haptic_enable_gpios(void) {
if (haptic_config.enable && ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state == USB_DEVICE_STATE_CONFIGURED))) {
#if defined(HAPTIC_ENABLE_PIN)
HAPTIC_ENABLE_PIN_WRITE_ACTIVE();
#endif
#if defined(HAPTIC_ENABLE_STATUS_LED)
HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE();
#endif
} else {
#if defined(HAPTIC_ENABLE_PIN)
HAPTIC_ENABLE_PIN_WRITE_INACTIVE();
#endif
#if defined(HAPTIC_ENABLE_STATUS_LED)
HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE();
#endif
}
}
static void set_haptic_config_enable(bool enabled) {
haptic_config.enable = enabled;
update_haptic_enable_gpios();
}
void haptic_init(void) {
if (!eeconfig_is_enabled()) {
eeconfig_init();
@ -44,6 +69,10 @@ void haptic_init(void) {
// or the previous firmware didn't have solenoid enabled,
// and the current one has solenoid enabled.
haptic_reset();
} else {
// Haptic configuration has been loaded through the "raw" union item.
// This is to execute any side effects of the configuration.
set_haptic_config_enable(haptic_config.enable);
}
#ifdef SOLENOID_ENABLE
solenoid_setup();
@ -54,6 +83,12 @@ void haptic_init(void) {
dprintf("DRV2605 driver initialized\n");
#endif
eeconfig_debug_haptic();
#ifdef HAPTIC_ENABLE_PIN
setPinOutput(HAPTIC_ENABLE_PIN);
#endif
#ifdef HAPTIC_ENABLE_STATUS_LED
setPinOutput(HAPTIC_ENABLE_STATUS_LED);
#endif
}
void haptic_task(void) {
@ -69,13 +104,13 @@ void eeconfig_debug_haptic(void) {
}
void haptic_enable(void) {
haptic_config.enable = 1;
set_haptic_config_enable(true);
xprintf("haptic_config.enable = %u\n", haptic_config.enable);
eeconfig_update_haptic(haptic_config.raw);
}
void haptic_disable(void) {
haptic_config.enable = 0;
set_haptic_config_enable(false);
xprintf("haptic_config.enable = %u\n", haptic_config.enable);
eeconfig_update_haptic(haptic_config.raw);
}
@ -157,7 +192,7 @@ void haptic_dwell_decrease(void) {
}
void haptic_reset(void) {
haptic_config.enable = true;
set_haptic_config_enable(true);
uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT;
haptic_config.feedback = feedback;
#ifdef DRV2605L
@ -293,3 +328,13 @@ void haptic_shutdown(void) {
solenoid_shutdown();
#endif
}
void haptic_notify_usb_device_state_change(void) {
update_haptic_enable_gpios();
#if defined(HAPTIC_ENABLE_PIN)
setPinOutput(HAPTIC_ENABLE_PIN);
#endif
#if defined(HAPTIC_ENABLE_STATUS_LED)
setPinOutput(HAPTIC_ENABLE_STATUS_LED);
#endif
}