aboutsummaryrefslogtreecommitdiff
path: root/drivers/haptic/DRV2605L.c
diff options
context:
space:
mode:
authorishtob <ishtob@gmail.com>2019-02-16 21:39:30 -0500
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-02-16 18:39:30 -0800
commit2cee371bf125a6ec541dd7c5a809573facc7c456 (patch)
tree7bb6c074b759843d531eee67d65d91618bd79732 /drivers/haptic/DRV2605L.c
parenta7a647b7f6d707e9c952461beeca1f3637039d36 (diff)
downloadqmk_firmware-2cee371bf125a6ec541dd7c5a809573facc7c456.tar.gz
qmk_firmware-2cee371bf125a6ec541dd7c5a809573facc7c456.zip
Haptic feedback generalized - DRV2605 and solenoids (#4939)
* initial work to add eeprom to haptic feedback and decouple the feedback process from keyboards * Haptic feedback enhancements: on/off toggle working, feedback order working todo: -work on modes switching -get modes switching to save to eeprom * haptic enhancement - eeprom and modes added * Added set and get functions for haptic feedback * initial implementation of solenoids under haptic feedback * changed eeprom to 32 bits to reserve blocks for future features * start documentation of haptic feedback * change keycode per comment from reviewers * typo fixes * added eeprom for solenoid configs * added solenoid and docs * Add/fix default parameters configs, improve docs * more doc cleanup * add in solenoid buzz toggle, clean up doc * some fixes for error in compiling solenoid * fix a chibios specific i2c read function and added one for AVR controllers in DRV2605L.c * fixes for avr side issues * update keymap * fix keymap compile error * fix bugs found during solenoid testing * set pin that is not powered during bootloader * added warning about certain pins on the MCU may trip solenoid during DFU/bootloader
Diffstat (limited to 'drivers/haptic/DRV2605L.c')
-rw-r--r--drivers/haptic/DRV2605L.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/drivers/haptic/DRV2605L.c b/drivers/haptic/DRV2605L.c
index 97ca292b9..215e6be3e 100644
--- a/drivers/haptic/DRV2605L.c
+++ b/drivers/haptic/DRV2605L.c
@@ -21,7 +21,7 @@
21#include <math.h> 21#include <math.h>
22 22
23 23
24uint8_t DRV2605L_transfer_buffer[20]; 24uint8_t DRV2605L_transfer_buffer[2];
25uint8_t DRV2605L_tx_register[0]; 25uint8_t DRV2605L_tx_register[0];
26uint8_t DRV2605L_read_buffer[0]; 26uint8_t DRV2605L_read_buffer[0];
27uint8_t DRV2605L_read_register; 27uint8_t DRV2605L_read_register;
@@ -34,6 +34,11 @@ void DRV_write(uint8_t drv_register, uint8_t settings) {
34} 34}
35 35
36uint8_t DRV_read(uint8_t regaddress) { 36uint8_t DRV_read(uint8_t regaddress) {
37#ifdef __AVR__
38 i2c_readReg(DRV2605L_BASE_ADDRESS << 1,
39 regaddress, DRV2605L_read_buffer, 1, 100);
40 DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
41#else
37 DRV2605L_tx_register[0] = regaddress; 42 DRV2605L_tx_register[0] = regaddress;
38 if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1, 43 if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1,
39 DRV2605L_tx_register, 1, 44 DRV2605L_tx_register, 1,
@@ -42,14 +47,13 @@ uint8_t DRV_read(uint8_t regaddress) {
42 printf("err reading reg \n"); 47 printf("err reading reg \n");
43 } 48 }
44 DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0]; 49 DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
50#endif
45return DRV2605L_read_register; 51return DRV2605L_read_register;
46} 52}
47 53
48void DRV_init(void) 54void DRV_init(void)
49{ 55{
50 i2c_init(); 56 i2c_init();
51 i2c_start(DRV2605L_BASE_ADDRESS);
52
53 /* 0x07 sets DRV2605 into calibration mode */ 57 /* 0x07 sets DRV2605 into calibration mode */
54 DRV_write(DRV_MODE,0x07); 58 DRV_write(DRV_MODE,0x07);
55 59
@@ -104,21 +108,17 @@ void DRV_init(void)
104 C4_SET.Bits.C4_AUTO_CAL_TIME = AUTO_CAL_TIME; 108 C4_SET.Bits.C4_AUTO_CAL_TIME = AUTO_CAL_TIME;
105 DRV_write(DRV_CTRL_4, (uint8_t) C4_SET.Byte); 109 DRV_write(DRV_CTRL_4, (uint8_t) C4_SET.Byte);
106 DRV_write(DRV_LIB_SELECTION,LIB_SELECTION); 110 DRV_write(DRV_LIB_SELECTION,LIB_SELECTION);
107 //start autocalibration 111
108 DRV_write(DRV_GO, 0x01); 112 DRV_write(DRV_GO, 0x01);
109 113
110 /* 0x00 sets DRV2605 out of standby and to use internal trigger 114 /* 0x00 sets DRV2605 out of standby and to use internal trigger
111 * 0x01 sets DRV2605 out of standby and to use external trigger */ 115 * 0x01 sets DRV2605 out of standby and to use external trigger */
112 DRV_write(DRV_MODE,0x00); 116 DRV_write(DRV_MODE,0x00);
113
114 /* 0x06: LRA library */
115 DRV_write(DRV_WAVEFORM_SEQ_1, 0x01);
116
117 /* 0xB9: LRA, 4x brake factor, medium gain, 7.5x back EMF
118 * 0x39: ERM, 4x brake factor, medium gain, 1.365x back EMF */
119
120 /* TODO: setup auto-calibration as part of initiation */
121 117
118//Play greeting sequence
119 DRV_write(DRV_GO, 0x00);
120 DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING);
121 DRV_write(DRV_GO, 0x01);
122} 122}
123 123
124void DRV_pulse(uint8_t sequence) 124void DRV_pulse(uint8_t sequence)