diff options
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/haptic/DRV2605L.c | 12 | ||||
| -rw-r--r-- | drivers/haptic/haptic.c | 85 | ||||
| -rw-r--r-- | drivers/haptic/haptic.h | 16 |
3 files changed, 54 insertions, 59 deletions
diff --git a/drivers/haptic/DRV2605L.c b/drivers/haptic/DRV2605L.c index 728554b01..c40731913 100644 --- a/drivers/haptic/DRV2605L.c +++ b/drivers/haptic/DRV2605L.c | |||
| @@ -115,15 +115,13 @@ void DRV_init(void) { | |||
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | void DRV_rtp_init(void) { | 117 | void DRV_rtp_init(void) { |
| 118 | DRV_write(DRV_GO, 0x00); | 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. | 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); | 120 | DRV_write(DRV_MODE, 0x05); |
| 121 | DRV_write(DRV_GO, 0x01); | 121 | DRV_write(DRV_GO, 0x01); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | void DRV_amplitude(uint8_t amplitude) { | 124 | void DRV_amplitude(uint8_t amplitude) { DRV_write(DRV_RTP_INPUT, amplitude); } |
| 125 | DRV_write(DRV_RTP_INPUT, amplitude); | ||
| 126 | } | ||
| 127 | 125 | ||
| 128 | void DRV_pulse(uint8_t sequence) { | 126 | void DRV_pulse(uint8_t sequence) { |
| 129 | DRV_write(DRV_GO, 0x00); | 127 | DRV_write(DRV_GO, 0x00); |
diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index 989970bee..2ce279b75 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c | |||
| @@ -169,12 +169,12 @@ void haptic_set_mode(uint8_t mode) { | |||
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | void haptic_set_amplitude(uint8_t amp) { | 171 | void haptic_set_amplitude(uint8_t amp) { |
| 172 | haptic_config.amplitude = amp; | 172 | haptic_config.amplitude = amp; |
| 173 | eeconfig_update_haptic(haptic_config.raw); | 173 | eeconfig_update_haptic(haptic_config.raw); |
| 174 | xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude); | 174 | xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude); |
| 175 | #ifdef DRV2605L | 175 | #ifdef DRV2605L |
| 176 | DRV_amplitude(amp); | 176 | DRV_amplitude(amp); |
| 177 | #endif | 177 | #endif |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | void haptic_set_buzz(uint8_t buzz) { | 180 | void haptic_set_buzz(uint8_t buzz) { |
| @@ -211,52 +211,50 @@ uint8_t haptic_get_dwell(void) { | |||
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | void haptic_enable_continuous(void) { | 213 | void haptic_enable_continuous(void) { |
| 214 | haptic_config.cont = 1; | 214 | haptic_config.cont = 1; |
| 215 | xprintf("haptic_config.cont = %u\n", haptic_config.cont); | 215 | xprintf("haptic_config.cont = %u\n", haptic_config.cont); |
| 216 | eeconfig_update_haptic(haptic_config.raw); | 216 | eeconfig_update_haptic(haptic_config.raw); |
| 217 | #ifdef DRV2605L | 217 | #ifdef DRV2605L |
| 218 | DRV_rtp_init(); | 218 | DRV_rtp_init(); |
| 219 | #endif | 219 | #endif |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | void haptic_disable_continuous(void) { | 222 | void haptic_disable_continuous(void) { |
| 223 | haptic_config.cont = 0; | 223 | haptic_config.cont = 0; |
| 224 | xprintf("haptic_config.cont = %u\n", haptic_config.cont); | 224 | xprintf("haptic_config.cont = %u\n", haptic_config.cont); |
| 225 | eeconfig_update_haptic(haptic_config.raw); | 225 | eeconfig_update_haptic(haptic_config.raw); |
| 226 | #ifdef DRV2605L | 226 | #ifdef DRV2605L |
| 227 | DRV_write(DRV_MODE,0x00); | 227 | DRV_write(DRV_MODE, 0x00); |
| 228 | #endif | 228 | #endif |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | void haptic_toggle_continuous(void) { | 231 | void haptic_toggle_continuous(void) { |
| 232 | #ifdef DRV2605L | 232 | #ifdef DRV2605L |
| 233 | if (haptic_config.cont) { | 233 | if (haptic_config.cont) { |
| 234 | haptic_disable_continuous(); | 234 | haptic_disable_continuous(); |
| 235 | } else { | 235 | } else { |
| 236 | haptic_enable_continuous(); | 236 | haptic_enable_continuous(); |
| 237 | } | 237 | } |
| 238 | eeconfig_update_haptic(haptic_config.raw); | 238 | eeconfig_update_haptic(haptic_config.raw); |
| 239 | #endif | 239 | #endif |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | |||
| 243 | void haptic_cont_increase(void) { | 242 | void haptic_cont_increase(void) { |
| 244 | uint8_t amp = haptic_config.amplitude + 10; | 243 | uint8_t amp = haptic_config.amplitude + 10; |
| 245 | if (haptic_config.amplitude >= 120) { | 244 | if (haptic_config.amplitude >= 120) { |
| 246 | amp = 120; | 245 | amp = 120; |
| 247 | } | 246 | } |
| 248 | haptic_set_amplitude(amp); | 247 | haptic_set_amplitude(amp); |
| 249 | } | 248 | } |
| 250 | 249 | ||
| 251 | void haptic_cont_decrease(void) { | 250 | void haptic_cont_decrease(void) { |
| 252 | uint8_t amp = haptic_config.amplitude - 10; | 251 | uint8_t amp = haptic_config.amplitude - 10; |
| 253 | if (haptic_config.amplitude < 20) { | 252 | if (haptic_config.amplitude < 20) { |
| 254 | amp = 20; | 253 | amp = 20; |
| 255 | } | 254 | } |
| 256 | haptic_set_amplitude(amp); | 255 | haptic_set_amplitude(amp); |
| 257 | } | 256 | } |
| 258 | 257 | ||
| 259 | |||
| 260 | void haptic_play(void) { | 258 | void haptic_play(void) { |
| 261 | #ifdef DRV2605L | 259 | #ifdef DRV2605L |
| 262 | uint8_t play_eff = 0; | 260 | uint8_t play_eff = 0; |
| @@ -269,7 +267,6 @@ void haptic_play(void) { | |||
| 269 | } | 267 | } |
| 270 | 268 | ||
| 271 | bool process_haptic(uint16_t keycode, keyrecord_t *record) { | 269 | bool process_haptic(uint16_t keycode, keyrecord_t *record) { |
| 272 | |||
| 273 | if (keycode == HPT_ON && record->event.pressed) { | 270 | if (keycode == HPT_ON && record->event.pressed) { |
| 274 | haptic_enable(); | 271 | haptic_enable(); |
| 275 | } | 272 | } |
| @@ -300,16 +297,16 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) { | |||
| 300 | if (keycode == HPT_DWLD && record->event.pressed) { | 297 | if (keycode == HPT_DWLD && record->event.pressed) { |
| 301 | haptic_dwell_decrease(); | 298 | haptic_dwell_decrease(); |
| 302 | } | 299 | } |
| 303 | if (keycode == HPT_CONT && record->event.pressed) { | 300 | if (keycode == HPT_CONT && record->event.pressed) { |
| 304 | haptic_toggle_continuous(); | 301 | haptic_toggle_continuous(); |
| 305 | } | 302 | } |
| 306 | if (keycode == HPT_CONI && record->event.pressed) { | 303 | if (keycode == HPT_CONI && record->event.pressed) { |
| 307 | haptic_cont_increase(); | 304 | haptic_cont_increase(); |
| 308 | } | 305 | } |
| 309 | if (keycode == HPT_COND && record->event.pressed) { | 306 | if (keycode == HPT_COND && record->event.pressed) { |
| 310 | haptic_cont_decrease(); | 307 | haptic_cont_decrease(); |
| 311 | } | 308 | } |
| 312 | 309 | ||
| 313 | if (haptic_config.enable) { | 310 | if (haptic_config.enable) { |
| 314 | if (record->event.pressed) { | 311 | if (record->event.pressed) { |
| 315 | // keypress | 312 | // keypress |
diff --git a/drivers/haptic/haptic.h b/drivers/haptic/haptic.h index 2f6eb31fc..5d3bd1c31 100644 --- a/drivers/haptic/haptic.h +++ b/drivers/haptic/haptic.h | |||
| @@ -34,14 +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 | bool cont :1; | 42 | bool cont : 1; |
| 43 | uint8_t amplitude :8; | 43 | uint8_t amplitude : 8; |
| 44 | uint16_t reserved :7; | 44 | uint16_t reserved : 7; |
| 45 | }; | 45 | }; |
| 46 | } haptic_config_t; | 46 | } haptic_config_t; |
| 47 | 47 | ||
