Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRV2605L Continuous Haptic Feedback Support #6461

Merged
merged 12 commits into from
Sep 19, 2019
7 changes: 7 additions & 0 deletions docs/feature_haptic_feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Not all keycodes below will work depending on which haptic mechanism you have ch
|`HPT_BUZ` | Toggle solenoid buzz on/off |
|`HPT_MODI` | Go to next DRV2605L waveform |
|`HPT_MODD` | Go to previous DRV2605L waveform |
|`HPT_CONT` | Toggle continuous haptic mode on/off |
|`HPT_CONI` | Increase DRV2605L continous haptic strength |
|`HPT_COND` | Decrease DRV2605L continous haptic strength |
|`HPT_DWLI` | Increase Solenoid dwell time |
|`HPT_DWLD` | Decrease Solenoid dwell time |

Expand Down Expand Up @@ -145,3 +148,7 @@ If haptic feedback is enabled, the keyboard will vibrate to a specific sqeuence
#define DRV_MODE_DEFAULT *sequence name or number*
```
This will set what sequence HPT_RST will set as the active mode. If not defined, mode will be set to 1 when HPT_RST is pressed.

### DRV2605L Continuous Haptic Mode

This mode sets continuous haptic feedback with the option to increase or decrease strength.
13 changes: 13 additions & 0 deletions drivers/haptic/DRV2605L.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ void DRV_init(void)
DRV_write(DRV_GO, 0x01);
}

void DRV_rtp_init(void)
{
DRV_write(DRV_GO, 0x00);
DRV_write(DRV_RTP_INPUT, 20); //20 is the lowest value I've found where haptics can still be felt.
DRV_write(DRV_MODE, 0x05);
DRV_write(DRV_GO, 0x01);
}

void DRV_amplitude(uint8_t amplitude)
{
DRV_write(DRV_RTP_INPUT, amplitude);
}

void DRV_pulse(uint8_t sequence)
{
DRV_write(DRV_GO, 0x00);
Expand Down
2 changes: 2 additions & 0 deletions drivers/haptic/DRV2605L.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ void DRV_init(void);
void DRV_write(const uint8_t drv_register, const uint8_t settings);
uint8_t DRV_read(const uint8_t regaddress);
void DRV_pulse(const uint8_t sequence);
void DRV_rtp_init(void);
void DRV_amplitude(const uint8_t amplitude);

typedef enum DRV_EFFECT{
clear_sequence = 0,
Expand Down
60 changes: 60 additions & 0 deletions drivers/haptic/haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ void haptic_set_mode(uint8_t mode) {
xprintf("haptic_config.mode = %u\n", haptic_config.mode);
}

void haptic_set_amplitude(uint8_t amp) {
haptic_config.amplitude = amp;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude);
#ifdef DRV2605L
DRV_amplitude(amp);
#endif
}

void haptic_set_buzz(uint8_t buzz) {
haptic_config.buzz = buzz;
eeconfig_update_haptic(haptic_config.raw);
Expand Down Expand Up @@ -202,6 +211,53 @@ uint8_t haptic_get_dwell(void) {
return haptic_config.dwell;
}

void haptic_enable_continuous(void) {
haptic_config.cont = 1;
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
eeconfig_update_haptic(haptic_config.raw);
#ifdef DRV2605L
DRV_rtp_init();
#endif
}

void haptic_disable_continuous(void) {
haptic_config.cont = 0;
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
eeconfig_update_haptic(haptic_config.raw);
#ifdef DRV2605L
DRV_write(DRV_MODE,0x00);
#endif
}

void haptic_toggle_continuous(void) {
#ifdef DRV2605L
if (haptic_config.cont) {
haptic_disable_continuous();
} else {
haptic_enable_continuous();
}
eeconfig_update_haptic(haptic_config.raw);
#endif
}


void haptic_cont_increase(void) {
uint8_t amp = haptic_config.amplitude + 10;
if (haptic_config.amplitude >= 120) {
amp = 120;
}
haptic_set_amplitude(amp);
}

void haptic_cont_decrease(void) {
uint8_t amp = haptic_config.amplitude - 10;
if (haptic_config.amplitude < 20) {
amp = 20;
}
haptic_set_amplitude(amp);
}


void haptic_play(void) {
#ifdef DRV2605L
uint8_t play_eff = 0;
Expand All @@ -224,6 +280,10 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) {
if (keycode == HPT_MODD && record->event.pressed) { haptic_mode_decrease(); }
if (keycode == HPT_DWLI && record->event.pressed) { haptic_dwell_increase(); }
if (keycode == HPT_DWLD && record->event.pressed) { haptic_dwell_decrease(); }
if (keycode == HPT_CONT && record->event.pressed) { haptic_toggle_continuous(); }
if (keycode == HPT_CONI && record->event.pressed) { haptic_cont_increase(); }
if (keycode == HPT_COND && record->event.pressed) { haptic_cont_decrease(); }

if (haptic_config.enable) {
if ( record->event.pressed ) {
// keypress
Expand Down
10 changes: 9 additions & 1 deletion drivers/haptic/haptic.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ typedef union {
uint8_t mode :7;
bool buzz :1;
uint8_t dwell :7;
uint16_t reserved :16;
bool cont :1;
uint8_t amplitude :8;
uint16_t reserved :7;
};
} haptic_config_t;

Expand All @@ -65,13 +67,19 @@ void haptic_mode(uint8_t mode);
void haptic_reset(void);
void haptic_set_feedback(uint8_t feedback);
void haptic_set_mode(uint8_t mode);
void haptic_set_amplitude(uint8_t amp);
void haptic_set_dwell(uint8_t dwell);
void haptic_set_buzz(uint8_t buzz);
void haptic_buzz_toggle(void);
uint8_t haptic_get_mode(void);
uint8_t haptic_get_feedback(void);
void haptic_dwell_increase(void);
void haptic_dwell_decrease(void);
void haptic_toggle_continuous(void);
void haptic_cont_increase(void);
void haptic_cont_decrease(void);



void haptic_play(void);
void haptic_shutdown(void);
Expand Down
3 changes: 3 additions & 0 deletions quantum/quantum_keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ enum quantum_keycodes {
HPT_BUZ,
HPT_MODI,
HPT_MODD,
HPT_CONT,
HPT_CONI,
HPT_COND,
HPT_DWLI,
HPT_DWLD,

Expand Down