Library for TI's DRV 2605
DRV2605.h@2:08f047da9397, 2017-11-20 (annotated)
- Committer:
- takuhachisu
- Date:
- Mon Nov 20 07:06:21 2017 +0000
- Revision:
- 2:08f047da9397
- Parent:
- 1:0747096351be
Modified the name of function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takuhachisu | 0:d47ac72f4048 | 1 | #ifndef DRV2605_H |
takuhachisu | 0:d47ac72f4048 | 2 | #define DRV2605_H |
takuhachisu | 0:d47ac72f4048 | 3 | |
takuhachisu | 0:d47ac72f4048 | 4 | #include "mbed.h" |
takuhachisu | 0:d47ac72f4048 | 5 | |
takuhachisu | 0:d47ac72f4048 | 6 | // DRV2605 Slave Address |
takuhachisu | 0:d47ac72f4048 | 7 | #define DRV2605_SLAVE_ADDR 0x5A |
takuhachisu | 0:d47ac72f4048 | 8 | |
takuhachisu | 0:d47ac72f4048 | 9 | // DRV2605 Registers |
takuhachisu | 0:d47ac72f4048 | 10 | #define STATUS 0x00 |
takuhachisu | 0:d47ac72f4048 | 11 | #define MODE 0x01 |
takuhachisu | 0:d47ac72f4048 | 12 | #define REAL_TIME_PLAYBACK 0x02 |
takuhachisu | 0:d47ac72f4048 | 13 | #define LIBRARY_SELECTION 0x03 |
takuhachisu | 0:d47ac72f4048 | 14 | #define WAVEFORM_SEQUENCER_1 0x04 |
takuhachisu | 0:d47ac72f4048 | 15 | #define WAVEFORM_SEQUENCER_2 0x05 |
takuhachisu | 0:d47ac72f4048 | 16 | #define WAVEFORM_SEQUENCER_3 0x06 |
takuhachisu | 0:d47ac72f4048 | 17 | #define WAVEFORM_SEQUENCER_4 0x07 |
takuhachisu | 0:d47ac72f4048 | 18 | #define WAVEFORM_SEQUENCER_5 0x08 |
takuhachisu | 0:d47ac72f4048 | 19 | #define WAVEFORM_SEQUENCER_6 0x09 |
takuhachisu | 0:d47ac72f4048 | 20 | #define WAVEFORM_SEQUENCER_7 0x0A |
takuhachisu | 0:d47ac72f4048 | 21 | #define WAVEFORM_SEQUENCER_8 0x0B |
takuhachisu | 0:d47ac72f4048 | 22 | #define GO 0x0C |
takuhachisu | 0:d47ac72f4048 | 23 | #define OVERDRIVE_TIME_OFFSET 0x0D |
takuhachisu | 0:d47ac72f4048 | 24 | #define POSITIVE_SUSTAIN_TIME_OFFSET 0x0E |
takuhachisu | 0:d47ac72f4048 | 25 | #define NEGATIVE_SUSTAIN_TIME_OFFSET 0x0F |
takuhachisu | 0:d47ac72f4048 | 26 | #define BRAKE_TIME_OFFSET 0x10 |
takuhachisu | 0:d47ac72f4048 | 27 | #define AUDIO_TO_VIBE_CONTROL 0x11 |
takuhachisu | 0:d47ac72f4048 | 28 | #define AUDIO_TO_VIBE_MINIMUM_INPUT_LEVEL 0x12 |
takuhachisu | 0:d47ac72f4048 | 29 | #define AUDIO_TO_VIBE_MAXIMUM_INPUT_LEVEL 0x13 |
takuhachisu | 0:d47ac72f4048 | 30 | #define AUDIO_TO_VIBE_MINIMUM_OUPUT_DRIVE 0x14 |
takuhachisu | 0:d47ac72f4048 | 31 | #define AUDIO_TO_VIBE_MAXIMUM_OUTPUT_DRIVE 0x15 |
takuhachisu | 0:d47ac72f4048 | 32 | #define RATED_VOLTAGE 0x16 |
takuhachisu | 0:d47ac72f4048 | 33 | #define OVERDRIVE_CLAMP_VOLTAGE 0x17 |
takuhachisu | 0:d47ac72f4048 | 34 | #define AUTO_CALIBRATION_COMPENSATION_RESULT 0x18 |
takuhachisu | 0:d47ac72f4048 | 35 | #define AUTO_CALIBRATION_BACK_EMF_RESULT 0x19 |
takuhachisu | 0:d47ac72f4048 | 36 | #define FEEDBACK_CONTROL 0x1A |
takuhachisu | 1:0747096351be | 37 | #define CONTROL1 0x1B |
takuhachisu | 0:d47ac72f4048 | 38 | #define CONTROL2 0x1C |
takuhachisu | 0:d47ac72f4048 | 39 | #define CONTROL3 0x1D |
takuhachisu | 0:d47ac72f4048 | 40 | #define CONTROL4 0x1E |
takuhachisu | 0:d47ac72f4048 | 41 | #define CONTROL5 0x1F |
takuhachisu | 0:d47ac72f4048 | 42 | #define LRA_OPEN_LOOP_PERIOD 0x20 |
takuhachisu | 0:d47ac72f4048 | 43 | #define VBAT_VOLTAGE_MONITOR 0x21 |
takuhachisu | 0:d47ac72f4048 | 44 | #define LRA_RESONANCE_PERIOD 0x22 |
takuhachisu | 0:d47ac72f4048 | 45 | |
takuhachisu | 0:d47ac72f4048 | 46 | // Modes defines the possible modes of the DRV2605L (Register Addr: 0x01) |
takuhachisu | 0:d47ac72f4048 | 47 | #define Mode_INTERNAL_TRIG 0x00 // Waveforms fired by Setting GO bit in Register 0x0C |
takuhachisu | 0:d47ac72f4048 | 48 | #define Mode_EXTERNAL_EDGE 0x01 // Rising Edge on IN/TRIG pin set GO Bit. |
takuhachisu | 0:d47ac72f4048 | 49 | #define Mode_EXTERNAL_LEVEL 0x02 // GO bit follows state of edge on IN/TRIG pin. |
takuhachisu | 0:d47ac72f4048 | 50 | #define Mode_PWM_ANALOG 0x03 // PWM or Analog Signal accepted at IN/TRIG pin. |
takuhachisu | 0:d47ac72f4048 | 51 | #define Mode_AUDIO_TO_VIBE 0x04 // An AC-coupled audio signal is accepted at the IN/TRIG pin. |
takuhachisu | 0:d47ac72f4048 | 52 | #define Mode_RTP 0x05 // Real- Time Playback |
takuhachisu | 0:d47ac72f4048 | 53 | #define Mode_DIAG 0x06 // Set to perform actuator diagnostics |
takuhachisu | 0:d47ac72f4048 | 54 | #define Mode_AUTO_CAL 0x07 // Set to perform auto calibration of device for actuator |
takuhachisu | 0:d47ac72f4048 | 55 | #define Mode_STANDBY 0x40 // Set Device to Software Standby (Low- Power Mode) |
takuhachisu | 0:d47ac72f4048 | 56 | #define Mode_RESET 0x80 // Reset Device (equivalent of power cycling the device) |
takuhachisu | 0:d47ac72f4048 | 57 | |
takuhachisu | 0:d47ac72f4048 | 58 | // FeedBack_Controls Fields Bitmasks (Register Addr: 0x1A) |
takuhachisu | 0:d47ac72f4048 | 59 | |
takuhachisu | 0:d47ac72f4048 | 60 | // ROM Waveform Library Selections |
takuhachisu | 0:d47ac72f4048 | 61 | #define LibraryEMPTY 0x00 |
takuhachisu | 0:d47ac72f4048 | 62 | #define LibraryA 0x01 |
takuhachisu | 0:d47ac72f4048 | 63 | #define LibraryB 0x02 |
takuhachisu | 0:d47ac72f4048 | 64 | #define LibraryC 0x03 |
takuhachisu | 0:d47ac72f4048 | 65 | #define LibraryD 0x04 |
takuhachisu | 0:d47ac72f4048 | 66 | #define LibraryE 0x05 |
takuhachisu | 0:d47ac72f4048 | 67 | #define LibraryLRA 0x06 |
takuhachisu | 0:d47ac72f4048 | 68 | #define LibraryF 0x07 |
takuhachisu | 0:d47ac72f4048 | 69 | |
takuhachisu | 0:d47ac72f4048 | 70 | /** Library for the TI DRV2605 |
takuhachisu | 0:d47ac72f4048 | 71 | * |
takuhachisu | 0:d47ac72f4048 | 72 | */ |
takuhachisu | 0:d47ac72f4048 | 73 | |
takuhachisu | 0:d47ac72f4048 | 74 | class DRV2605 |
takuhachisu | 0:d47ac72f4048 | 75 | { |
takuhachisu | 0:d47ac72f4048 | 76 | |
takuhachisu | 0:d47ac72f4048 | 77 | public: |
takuhachisu | 1:0747096351be | 78 | // FeedBack_Controls Fields Bitmasks |
takuhachisu | 1:0747096351be | 79 | enum ActuatorType {ERM = 0, LRA = 0x80}; |
takuhachisu | 1:0747096351be | 80 | enum BrakeFactor {x1 = 0x00, x2 = 0x10, x3 = 0x20, x4 = 0x30, x6 = 0x40, x8 = 0x50, x16 = 0x60, DISABLE = 0x70}; |
takuhachisu | 1:0747096351be | 81 | enum LoopGain {LOW = 0x00, MEDIUM = 0x04, HIGH = 0x08, VERYHIGH = 0x0C}; |
takuhachisu | 1:0747096351be | 82 | |
takuhachisu | 1:0747096351be | 83 | // Control2 Fields Bitmasks |
takuhachisu | 1:0747096351be | 84 | enum SampleTime {us150 = 0x00, us200 = 0x10, us250 = 0x20, us300 = 0x30}; |
takuhachisu | 1:0747096351be | 85 | |
takuhachisu | 1:0747096351be | 86 | // Control4 Fields Bitmasks |
takuhachisu | 1:0747096351be | 87 | enum AutoCalTime {ms150_350 = 0x00, ms250_450 = 0x10, ms500_700 = 0x20, ms1000_1200 = 0x30}; |
takuhachisu | 1:0747096351be | 88 | |
takuhachisu | 0:d47ac72f4048 | 89 | /** |
takuhachisu | 0:d47ac72f4048 | 90 | * Create a DRV2605 object |
takuhachisu | 0:d47ac72f4048 | 91 | * |
takuhachisu | 0:d47ac72f4048 | 92 | * @param &i2c pointer of I2C object |
takuhachisu | 1:0747096351be | 93 | * @param at actuator type |
takuhachisu | 1:0747096351be | 94 | * @param bf brake factor |
takuhachisu | 1:0747096351be | 95 | * @param lg loop gain |
takuhachisu | 1:0747096351be | 96 | * @param rv rated voltage |
takuhachisu | 1:0747096351be | 97 | * @param ocv overdirve clamp voltage |
takuhachisu | 1:0747096351be | 98 | * @param act auto caliblration time |
takuhachisu | 1:0747096351be | 99 | * @param dt drive time |
takuhachisu | 1:0747096351be | 100 | * @param st sample time |
takuhachisu | 1:0747096351be | 101 | * @param bt braking time |
takuhachisu | 1:0747096351be | 102 | * @param it current dissipation time |
takuhachisu | 0:d47ac72f4048 | 103 | */ |
takuhachisu | 1:0747096351be | 104 | DRV2605(I2C &i2c, ActuatorType at = ERM, BrakeFactor bf = x4, |
takuhachisu | 1:0747096351be | 105 | LoopGain lg = MEDIUM, uint8_t rv = 0x3F, uint8_t ocv = 0x89, |
takuhachisu | 1:0747096351be | 106 | AutoCalTime act = ms500_700, uint8_t dt = 0x13, |
takuhachisu | 1:0747096351be | 107 | SampleTime st = us200, uint8_t bt = 2, uint8_t it = 2); |
takuhachisu | 0:d47ac72f4048 | 108 | |
takuhachisu | 0:d47ac72f4048 | 109 | /** |
takuhachisu | 1:0747096351be | 110 | * Write value to register |
takuhachisu | 0:d47ac72f4048 | 111 | * |
takuhachisu | 1:0747096351be | 112 | * @param reg Register to write |
takuhachisu | 1:0747096351be | 113 | * @param value Value to write to the register |
takuhachisu | 0:d47ac72f4048 | 114 | */ |
takuhachisu | 0:d47ac72f4048 | 115 | void i2cWriteByte(char reg, char value); |
takuhachisu | 0:d47ac72f4048 | 116 | |
takuhachisu | 0:d47ac72f4048 | 117 | /** |
takuhachisu | 1:0747096351be | 118 | * Read value from register |
takuhachisu | 1:0747096351be | 119 | * |
takuhachisu | 1:0747096351be | 120 | * @param reg Register to read |
takuhachisu | 1:0747096351be | 121 | * @return Value |
takuhachisu | 0:d47ac72f4048 | 122 | */ |
takuhachisu | 0:d47ac72f4048 | 123 | uint8_t i2cReadByte(char reg); |
takuhachisu | 0:d47ac72f4048 | 124 | |
takuhachisu | 0:d47ac72f4048 | 125 | /** |
takuhachisu | 1:0747096351be | 126 | * Set the device into specified mode |
takuhachisu | 1:0747096351be | 127 | * |
takuhachisu | 1:0747096351be | 128 | * @param mode Mode to set |
takuhachisu | 0:d47ac72f4048 | 129 | */ |
takuhachisu | 1:0747096351be | 130 | void mode(uint8_t mode); |
takuhachisu | 0:d47ac72f4048 | 131 | |
takuhachisu | 0:d47ac72f4048 | 132 | /** |
takuhachisu | 1:0747096351be | 133 | * Runs diagnostics |
takuhachisu | 0:d47ac72f4048 | 134 | * |
takuhachisu | 1:0747096351be | 135 | * @return Results of the diagnostics |
takuhachisu | 0:d47ac72f4048 | 136 | */ |
takuhachisu | 0:d47ac72f4048 | 137 | uint8_t diagnostics(); |
takuhachisu | 1:0747096351be | 138 | |
takuhachisu | 1:0747096351be | 139 | /** |
takuhachisu | 1:0747096351be | 140 | * Select the input data interpretation for RTP |
takuhachisu | 1:0747096351be | 141 | * |
takuhachisu | 1:0747096351be | 142 | * @param isSigned true: singed(-127~127), false: unsigned (0~255) |
takuhachisu | 1:0747096351be | 143 | */ |
takuhachisu | 1:0747096351be | 144 | void dataFormatRTP(bool isSigned); |
takuhachisu | 1:0747096351be | 145 | |
takuhachisu | 0:d47ac72f4048 | 146 | /** |
takuhachisu | 0:d47ac72f4048 | 147 | * Set ROM Library |
takuhachisu | 0:d47ac72f4048 | 148 | * |
takuhachisu | 1:0747096351be | 149 | * Note: This should be called before setWaveform function |
takuhachisu | 0:d47ac72f4048 | 150 | * @param lib Set library (see library's macro) |
takuhachisu | 0:d47ac72f4048 | 151 | */ |
takuhachisu | 1:0747096351be | 152 | void setLibrary(uint8_t lib); |
takuhachisu | 0:d47ac72f4048 | 153 | |
takuhachisu | 0:d47ac72f4048 | 154 | /** |
takuhachisu | 1:0747096351be | 155 | * Set single waveform from ROM Library |
takuhachisu | 0:d47ac72f4048 | 156 | * |
takuhachisu | 1:0747096351be | 157 | * Note: This should be called after setLibrary function |
takuhachisu | 1:0747096351be | 158 | * @param effect The Waveform Effect Library Index value to play (1 to 123) |
takuhachisu | 0:d47ac72f4048 | 159 | */ |
takuhachisu | 0:d47ac72f4048 | 160 | void setWaveform(int effect); |
takuhachisu | 0:d47ac72f4048 | 161 | |
takuhachisu | 0:d47ac72f4048 | 162 | /** |
takuhachisu | 1:0747096351be | 163 | * Set waveform Sequence |
takuhachisu | 0:d47ac72f4048 | 164 | * |
takuhachisu | 1:0747096351be | 165 | * Note: This should be called after setLibrary function |
takuhachisu | 1:0747096351be | 166 | * @param effect1... effect8 The Waveform Effect Library Index value to play |
takuhachisu | 1:0747096351be | 167 | * (1 to 123): 0 = Stop Condition; 1- 123 = Waveform Index |
takuhachisu | 0:d47ac72f4048 | 168 | */ |
takuhachisu | 0:d47ac72f4048 | 169 | void setWaveformSequence(int effect1 = 0, int effect2 = 0, |
takuhachisu | 1:0747096351be | 170 | int effect3 = 0, int effect4 = 0, |
takuhachisu | 1:0747096351be | 171 | int effect5 = 0, int effect6 = 0, |
takuhachisu | 1:0747096351be | 172 | int effect7 = 0, int effect8 = 0); |
takuhachisu | 0:d47ac72f4048 | 173 | |
takuhachisu | 0:d47ac72f4048 | 174 | /** |
takuhachisu | 0:d47ac72f4048 | 175 | * Plays the currently loaded waveform or waveform sequence. |
takuhachisu | 0:d47ac72f4048 | 176 | */ |
takuhachisu | 0:d47ac72f4048 | 177 | void play(); |
takuhachisu | 1:0747096351be | 178 | |
takuhachisu | 0:d47ac72f4048 | 179 | /** |
takuhachisu | 0:d47ac72f4048 | 180 | * Stops the currently loaded waveform or waveform sequence. |
takuhachisu | 0:d47ac72f4048 | 181 | */ |
takuhachisu | 0:d47ac72f4048 | 182 | void stop(); |
takuhachisu | 0:d47ac72f4048 | 183 | |
takuhachisu | 0:d47ac72f4048 | 184 | /** |
takuhachisu | 0:d47ac72f4048 | 185 | * Real time play back |
takuhachisu | 0:d47ac72f4048 | 186 | * |
takuhachisu | 0:d47ac72f4048 | 187 | * @param rtp intensity of the vibration (0 - 255) |
takuhachisu | 0:d47ac72f4048 | 188 | */ |
takuhachisu | 1:0747096351be | 189 | void playRtp(uint8_t rtp); |
takuhachisu | 0:d47ac72f4048 | 190 | |
takuhachisu | 0:d47ac72f4048 | 191 | /** |
takuhachisu | 0:d47ac72f4048 | 192 | * Battery voltage monitor |
takuhachisu | 0:d47ac72f4048 | 193 | * |
takuhachisu | 0:d47ac72f4048 | 194 | * @return battery voltage |
takuhachisu | 0:d47ac72f4048 | 195 | */ |
takuhachisu | 2:08f047da9397 | 196 | float batteryVoltage(void); |
takuhachisu | 0:d47ac72f4048 | 197 | |
takuhachisu | 0:d47ac72f4048 | 198 | private: |
takuhachisu | 0:d47ac72f4048 | 199 | I2C *_i2c; |
takuhachisu | 0:d47ac72f4048 | 200 | }; |
takuhachisu | 0:d47ac72f4048 | 201 | |
takuhachisu | 0:d47ac72f4048 | 202 | #endif |