From 2cee371bf125a6ec541dd7c5a809573facc7c456 Mon Sep 17 00:00:00 2001 From: ishtob Date: Sat, 16 Feb 2019 21:39:30 -0500 Subject: 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 --- drivers/haptic/DRV2605L.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'drivers/haptic/DRV2605L.c') diff --git a/drivers/haptic/DRV2605L.c b/drivers/haptic/DRV2605L.c index 97ca292b9b..215e6be3e7 100644 --- a/drivers/haptic/DRV2605L.c +++ b/drivers/haptic/DRV2605L.c @@ -21,7 +21,7 @@ #include -uint8_t DRV2605L_transfer_buffer[20]; +uint8_t DRV2605L_transfer_buffer[2]; uint8_t DRV2605L_tx_register[0]; uint8_t DRV2605L_read_buffer[0]; uint8_t DRV2605L_read_register; @@ -34,6 +34,11 @@ void DRV_write(uint8_t drv_register, uint8_t settings) { } uint8_t DRV_read(uint8_t regaddress) { +#ifdef __AVR__ + i2c_readReg(DRV2605L_BASE_ADDRESS << 1, + regaddress, DRV2605L_read_buffer, 1, 100); + DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0]; +#else DRV2605L_tx_register[0] = regaddress; if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1, DRV2605L_tx_register, 1, @@ -42,14 +47,13 @@ uint8_t DRV_read(uint8_t regaddress) { printf("err reading reg \n"); } DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0]; +#endif return DRV2605L_read_register; } void DRV_init(void) { i2c_init(); - i2c_start(DRV2605L_BASE_ADDRESS); - /* 0x07 sets DRV2605 into calibration mode */ DRV_write(DRV_MODE,0x07); @@ -104,21 +108,17 @@ void DRV_init(void) C4_SET.Bits.C4_AUTO_CAL_TIME = AUTO_CAL_TIME; DRV_write(DRV_CTRL_4, (uint8_t) C4_SET.Byte); DRV_write(DRV_LIB_SELECTION,LIB_SELECTION); - //start autocalibration + DRV_write(DRV_GO, 0x01); /* 0x00 sets DRV2605 out of standby and to use internal trigger * 0x01 sets DRV2605 out of standby and to use external trigger */ DRV_write(DRV_MODE,0x00); - - /* 0x06: LRA library */ - DRV_write(DRV_WAVEFORM_SEQ_1, 0x01); - - /* 0xB9: LRA, 4x brake factor, medium gain, 7.5x back EMF - * 0x39: ERM, 4x brake factor, medium gain, 1.365x back EMF */ - - /* TODO: setup auto-calibration as part of initiation */ +//Play greeting sequence + DRV_write(DRV_GO, 0x00); + DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING); + DRV_write(DRV_GO, 0x01); } void DRV_pulse(uint8_t sequence) -- cgit v1.2.3