aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/feature_haptic_feedback.md7
-rw-r--r--drivers/haptic/DRV2605L.c11
-rw-r--r--drivers/haptic/DRV2605L.h2
-rw-r--r--drivers/haptic/haptic.c67
-rw-r--r--drivers/haptic/haptic.h17
-rw-r--r--quantum/quantum_keycodes.h3
6 files changed, 101 insertions, 6 deletions
diff --git a/docs/feature_haptic_feedback.md b/docs/feature_haptic_feedback.md
index 85fd43964..acd156a27 100644
--- a/docs/feature_haptic_feedback.md
+++ b/docs/feature_haptic_feedback.md
@@ -29,6 +29,9 @@ Not all keycodes below will work depending on which haptic mechanism you have ch
29|`HPT_BUZ` | Toggle solenoid buzz on/off | 29|`HPT_BUZ` | Toggle solenoid buzz on/off |
30|`HPT_MODI` | Go to next DRV2605L waveform | 30|`HPT_MODI` | Go to next DRV2605L waveform |
31|`HPT_MODD` | Go to previous DRV2605L waveform | 31|`HPT_MODD` | Go to previous DRV2605L waveform |
32|`HPT_CONT` | Toggle continuous haptic mode on/off |
33|`HPT_CONI` | Increase DRV2605L continous haptic strength |
34|`HPT_COND` | Decrease DRV2605L continous haptic strength |
32|`HPT_DWLI` | Increase Solenoid dwell time | 35|`HPT_DWLI` | Increase Solenoid dwell time |
33|`HPT_DWLD` | Decrease Solenoid dwell time | 36|`HPT_DWLD` | Decrease Solenoid dwell time |
34 37
@@ -145,3 +148,7 @@ If haptic feedback is enabled, the keyboard will vibrate to a specific sqeuence
145#define DRV_MODE_DEFAULT *sequence name or number* 148#define DRV_MODE_DEFAULT *sequence name or number*
146``` 149```
147This 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. 150This 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.
151
152### DRV2605L Continuous Haptic Mode
153
154This mode sets continuous haptic feedback with the option to increase or decrease strength. \ No newline at end of file
diff --git a/drivers/haptic/DRV2605L.c b/drivers/haptic/DRV2605L.c
index f74c96525..728554b01 100644
--- a/drivers/haptic/DRV2605L.c
+++ b/drivers/haptic/DRV2605L.c
@@ -114,6 +114,17 @@ void DRV_init(void) {
114 DRV_write(DRV_GO, 0x01); 114 DRV_write(DRV_GO, 0x01);
115} 115}
116 116
117void DRV_rtp_init(void) {
118 DRV_write(DRV_GO, 0x00);
119 DRV_write(DRV_RTP_INPUT, 20); //20 is the lowest value I've found where haptics can still be felt.
120 DRV_write(DRV_MODE, 0x05);
121 DRV_write(DRV_GO, 0x01);
122}
123
124void DRV_amplitude(uint8_t amplitude) {
125 DRV_write(DRV_RTP_INPUT, amplitude);
126}
127
117void DRV_pulse(uint8_t sequence) { 128void DRV_pulse(uint8_t sequence) {
118 DRV_write(DRV_GO, 0x00); 129 DRV_write(DRV_GO, 0x00);
119 DRV_write(DRV_WAVEFORM_SEQ_1, sequence); 130 DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
diff --git a/drivers/haptic/DRV2605L.h b/drivers/haptic/DRV2605L.h
index f550b859f..535c77765 100644
--- a/drivers/haptic/DRV2605L.h
+++ b/drivers/haptic/DRV2605L.h
@@ -170,6 +170,8 @@
170void DRV_init(void); 170void DRV_init(void);
171void DRV_write(const uint8_t drv_register, const uint8_t settings); 171void DRV_write(const uint8_t drv_register, const uint8_t settings);
172uint8_t DRV_read(const uint8_t regaddress); 172uint8_t DRV_read(const uint8_t regaddress);
173void DRV_rtp_init(void);
174void DRV_amplitude(const uint8_t amplitude);
173void DRV_pulse(const uint8_t sequence); 175void DRV_pulse(const uint8_t sequence);
174 176
175typedef enum DRV_EFFECT { 177typedef enum DRV_EFFECT {
diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c
index ded6d8a44..989970bee 100644
--- a/drivers/haptic/haptic.c
+++ b/drivers/haptic/haptic.c
@@ -168,6 +168,15 @@ void haptic_set_mode(uint8_t mode) {
168 xprintf("haptic_config.mode = %u\n", haptic_config.mode); 168 xprintf("haptic_config.mode = %u\n", haptic_config.mode);
169} 169}
170 170
171void haptic_set_amplitude(uint8_t amp) {
172 haptic_config.amplitude = amp;
173 eeconfig_update_haptic(haptic_config.raw);
174 xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude);
175 #ifdef DRV2605L
176 DRV_amplitude(amp);
177 #endif
178}
179
171void haptic_set_buzz(uint8_t buzz) { 180void haptic_set_buzz(uint8_t buzz) {
172 haptic_config.buzz = buzz; 181 haptic_config.buzz = buzz;
173 eeconfig_update_haptic(haptic_config.raw); 182 eeconfig_update_haptic(haptic_config.raw);
@@ -201,6 +210,53 @@ uint8_t haptic_get_dwell(void) {
201 return haptic_config.dwell; 210 return haptic_config.dwell;
202} 211}
203 212
213void haptic_enable_continuous(void) {
214 haptic_config.cont = 1;
215 xprintf("haptic_config.cont = %u\n", haptic_config.cont);
216 eeconfig_update_haptic(haptic_config.raw);
217 #ifdef DRV2605L
218 DRV_rtp_init();
219 #endif
220}
221
222void haptic_disable_continuous(void) {
223 haptic_config.cont = 0;
224 xprintf("haptic_config.cont = %u\n", haptic_config.cont);
225 eeconfig_update_haptic(haptic_config.raw);
226 #ifdef DRV2605L
227 DRV_write(DRV_MODE,0x00);
228 #endif
229}
230
231void haptic_toggle_continuous(void) {
232#ifdef DRV2605L
233if (haptic_config.cont) {
234 haptic_disable_continuous();
235 } else {
236 haptic_enable_continuous();
237 }
238 eeconfig_update_haptic(haptic_config.raw);
239#endif
240}
241
242
243void haptic_cont_increase(void) {
244 uint8_t amp = haptic_config.amplitude + 10;
245 if (haptic_config.amplitude >= 120) {
246 amp = 120;
247 }
248 haptic_set_amplitude(amp);
249}
250
251void haptic_cont_decrease(void) {
252 uint8_t amp = haptic_config.amplitude - 10;
253 if (haptic_config.amplitude < 20) {
254 amp = 20;
255 }
256 haptic_set_amplitude(amp);
257}
258
259
204void haptic_play(void) { 260void haptic_play(void) {
205#ifdef DRV2605L 261#ifdef DRV2605L
206 uint8_t play_eff = 0; 262 uint8_t play_eff = 0;
@@ -213,6 +269,7 @@ void haptic_play(void) {
213} 269}
214 270
215bool process_haptic(uint16_t keycode, keyrecord_t *record) { 271bool process_haptic(uint16_t keycode, keyrecord_t *record) {
272
216 if (keycode == HPT_ON && record->event.pressed) { 273 if (keycode == HPT_ON && record->event.pressed) {
217 haptic_enable(); 274 haptic_enable();
218 } 275 }
@@ -243,6 +300,16 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) {
243 if (keycode == HPT_DWLD && record->event.pressed) { 300 if (keycode == HPT_DWLD && record->event.pressed) {
244 haptic_dwell_decrease(); 301 haptic_dwell_decrease();
245 } 302 }
303 if (keycode == HPT_CONT && record->event.pressed) {
304 haptic_toggle_continuous();
305 }
306 if (keycode == HPT_CONI && record->event.pressed) {
307 haptic_cont_increase();
308 }
309 if (keycode == HPT_COND && record->event.pressed) {
310 haptic_cont_decrease();
311 }
312
246 if (haptic_config.enable) { 313 if (haptic_config.enable) {
247 if (record->event.pressed) { 314 if (record->event.pressed) {
248 // keypress 315 // keypress
diff --git a/drivers/haptic/haptic.h b/drivers/haptic/haptic.h
index 8135d0d43..2f6eb31fc 100644
--- a/drivers/haptic/haptic.h
+++ b/drivers/haptic/haptic.h
@@ -34,12 +34,14 @@
34typedef union { 34typedef union {
35 uint32_t raw; 35 uint32_t raw;
36 struct { 36 struct {
37 bool enable : 1; 37 bool enable :1;
38 uint8_t feedback : 2; 38 uint8_t feedback :2;
39 uint8_t mode : 7; 39 uint8_t mode :7;
40 bool buzz : 1; 40 bool buzz :1;
41 uint8_t dwell : 7; 41 uint8_t dwell :7;
42 uint16_t reserved : 16; 42 bool cont :1;
43 uint8_t amplitude :8;
44 uint16_t reserved :7;
43 }; 45 };
44} haptic_config_t; 46} haptic_config_t;
45 47
@@ -71,6 +73,9 @@ uint8_t haptic_get_mode(void);
71uint8_t haptic_get_feedback(void); 73uint8_t haptic_get_feedback(void);
72void haptic_dwell_increase(void); 74void haptic_dwell_increase(void);
73void haptic_dwell_decrease(void); 75void haptic_dwell_decrease(void);
76void haptic_toggle_continuous(void);
77void haptic_cont_increase(void);
78void haptic_cont_decrease(void);
74 79
75void haptic_play(void); 80void haptic_play(void);
76void haptic_shutdown(void); 81void haptic_shutdown(void);
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index f5dca02e6..af984a7cd 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -473,6 +473,9 @@ enum quantum_keycodes {
473 HPT_BUZ, 473 HPT_BUZ,
474 HPT_MODI, 474 HPT_MODI,
475 HPT_MODD, 475 HPT_MODD,
476 HPT_CONT,
477 HPT_CONI,
478 HPT_COND,
476 HPT_DWLI, 479 HPT_DWLI,
477 HPT_DWLD, 480 HPT_DWLD,
478 481