diff options
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/haptic/DRV2605L.c | 11 | ||||
| -rw-r--r-- | drivers/haptic/DRV2605L.h | 2 | ||||
| -rw-r--r-- | drivers/haptic/haptic.c | 67 | ||||
| -rw-r--r-- | drivers/haptic/haptic.h | 17 |
4 files changed, 91 insertions, 6 deletions
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 | ||
| 117 | void 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 | |||
| 124 | void DRV_amplitude(uint8_t amplitude) { | ||
| 125 | DRV_write(DRV_RTP_INPUT, amplitude); | ||
| 126 | } | ||
| 127 | |||
| 117 | void DRV_pulse(uint8_t sequence) { | 128 | void 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 @@ | |||
| 170 | void DRV_init(void); | 170 | void DRV_init(void); |
| 171 | void DRV_write(const uint8_t drv_register, const uint8_t settings); | 171 | void DRV_write(const uint8_t drv_register, const uint8_t settings); |
| 172 | uint8_t DRV_read(const uint8_t regaddress); | 172 | uint8_t DRV_read(const uint8_t regaddress); |
| 173 | void DRV_rtp_init(void); | ||
| 174 | void DRV_amplitude(const uint8_t amplitude); | ||
| 173 | void DRV_pulse(const uint8_t sequence); | 175 | void DRV_pulse(const uint8_t sequence); |
| 174 | 176 | ||
| 175 | typedef enum DRV_EFFECT { | 177 | typedef 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 | ||
| 171 | void 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 | |||
| 171 | void haptic_set_buzz(uint8_t buzz) { | 180 | void 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 | ||
| 213 | void 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 | |||
| 222 | void 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 | |||
| 231 | void haptic_toggle_continuous(void) { | ||
| 232 | #ifdef DRV2605L | ||
| 233 | if (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 | |||
| 243 | void 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 | |||
| 251 | void 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 | |||
| 204 | void haptic_play(void) { | 260 | void 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 | ||
| 215 | bool process_haptic(uint16_t keycode, keyrecord_t *record) { | 271 | bool 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 @@ | |||
| 34 | typedef union { | 34 | typedef 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); | |||
| 71 | uint8_t haptic_get_feedback(void); | 73 | uint8_t haptic_get_feedback(void); |
| 72 | void haptic_dwell_increase(void); | 74 | void haptic_dwell_increase(void); |
| 73 | void haptic_dwell_decrease(void); | 75 | void haptic_dwell_decrease(void); |
| 76 | void haptic_toggle_continuous(void); | ||
| 77 | void haptic_cont_increase(void); | ||
| 78 | void haptic_cont_decrease(void); | ||
| 74 | 79 | ||
| 75 | void haptic_play(void); | 80 | void haptic_play(void); |
| 76 | void haptic_shutdown(void); | 81 | void haptic_shutdown(void); |
