aboutsummaryrefslogtreecommitdiff
path: root/drivers/haptic/DRV2605L.c
diff options
context:
space:
mode:
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)