aboutsummaryrefslogtreecommitdiff
path: root/drivers/haptic/haptic.c
diff options
context:
space:
mode:
authorMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-09-19 09:42:33 -0700
committerDrashna Jaelre <drashna@live.com>2019-09-19 09:42:33 -0700
commit911b8915cc89c040db3c6075a1a547003b0ab37f (patch)
treefe7afcae351fd3a5e9bce4ea25ef406f6382f1d7 /drivers/haptic/haptic.c
parent7a5a2591ebc797d9670366a45396afed48c5fc6f (diff)
downloadqmk_firmware-911b8915cc89c040db3c6075a1a547003b0ab37f.tar.gz
qmk_firmware-911b8915cc89c040db3c6075a1a547003b0ab37f.zip
DRV2605L Continuous Haptic Feedback Support (#6461)
* provide means to turn on RTP mode and set the amplitude * new keycode HPT_CONT to turn RTP off/on * introduce new keycodes HPT_CONI, and HPT_COND for Haptic Continuous Increase and Decrease * support for continuous mode amplitude increase and decrease * code cleanup * update docs to reference new keycodes and functionality * don't touch the keymaps * add function prototypes * add proper guards * cleanup guards * remove extra reserved
Diffstat (limited to 'drivers/haptic/haptic.c')
-rw-r--r--drivers/haptic/haptic.c67
1 files changed, 67 insertions, 0 deletions
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