Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DRV2605.h
00001 #ifndef DRV2605_H 00002 #define DRV2605_H 00003 00004 #include "mbed.h" 00005 00006 // DRV2605 Slave Address 00007 #define DRV2605_SLAVE_ADDR 0x5A 00008 00009 // DRV2605 Registers 00010 #define STATUS 0x00 00011 #define MODE 0x01 00012 #define REAL_TIME_PLAYBACK 0x02 00013 #define LIBRARY_SELECTION 0x03 00014 #define WAVEFORM_SEQUENCER_1 0x04 00015 #define WAVEFORM_SEQUENCER_2 0x05 00016 #define WAVEFORM_SEQUENCER_3 0x06 00017 #define WAVEFORM_SEQUENCER_4 0x07 00018 #define WAVEFORM_SEQUENCER_5 0x08 00019 #define WAVEFORM_SEQUENCER_6 0x09 00020 #define WAVEFORM_SEQUENCER_7 0x0A 00021 #define WAVEFORM_SEQUENCER_8 0x0B 00022 #define GO 0x0C 00023 #define OVERDRIVE_TIME_OFFSET 0x0D 00024 #define POSITIVE_SUSTAIN_TIME_OFFSET 0x0E 00025 #define NEGATIVE_SUSTAIN_TIME_OFFSET 0x0F 00026 #define BRAKE_TIME_OFFSET 0x10 00027 #define AUDIO_TO_VIBE_CONTROL 0x11 00028 #define AUDIO_TO_VIBE_MINIMUM_INPUT_LEVEL 0x12 00029 #define AUDIO_TO_VIBE_MAXIMUM_INPUT_LEVEL 0x13 00030 #define AUDIO_TO_VIBE_MINIMUM_OUPUT_DRIVE 0x14 00031 #define AUDIO_TO_VIBE_MAXIMUM_OUTPUT_DRIVE 0x15 00032 #define RATED_VOLTAGE 0x16 00033 #define OVERDRIVE_CLAMP_VOLTAGE 0x17 00034 #define AUTO_CALIBRATION_COMPENSATION_RESULT 0x18 00035 #define AUTO_CALIBRATION_BACK_EMF_RESULT 0x19 00036 #define FEEDBACK_CONTROL 0x1A 00037 #define CONTROL1 0x1B 00038 #define CONTROL2 0x1C 00039 #define CONTROL3 0x1D 00040 #define CONTROL4 0x1E 00041 #define CONTROL5 0x1F 00042 #define LRA_OPEN_LOOP_PERIOD 0x20 00043 #define VBAT_VOLTAGE_MONITOR 0x21 00044 #define LRA_RESONANCE_PERIOD 0x22 00045 00046 // Modes defines the possible modes of the DRV2605L (Register Addr: 0x01) 00047 #define Mode_INTERNAL_TRIG 0x00 // Waveforms fired by Setting GO bit in Register 0x0C 00048 #define Mode_EXTERNAL_EDGE 0x01 // Rising Edge on IN/TRIG pin set GO Bit. 00049 #define Mode_EXTERNAL_LEVEL 0x02 // GO bit follows state of edge on IN/TRIG pin. 00050 #define Mode_PWM_ANALOG 0x03 // PWM or Analog Signal accepted at IN/TRIG pin. 00051 #define Mode_AUDIO_TO_VIBE 0x04 // An AC-coupled audio signal is accepted at the IN/TRIG pin. 00052 #define Mode_RTP 0x05 // Real- Time Playback 00053 #define Mode_DIAG 0x06 // Set to perform actuator diagnostics 00054 #define Mode_AUTO_CAL 0x07 // Set to perform auto calibration of device for actuator 00055 #define Mode_STANDBY 0x40 // Set Device to Software Standby (Low- Power Mode) 00056 #define Mode_RESET 0x80 // Reset Device (equivalent of power cycling the device) 00057 00058 // FeedBack_Controls Fields Bitmasks (Register Addr: 0x1A) 00059 00060 // ROM Waveform Library Selections 00061 #define LibraryEMPTY 0x00 00062 #define LibraryA 0x01 00063 #define LibraryB 0x02 00064 #define LibraryC 0x03 00065 #define LibraryD 0x04 00066 #define LibraryE 0x05 00067 #define LibraryLRA 0x06 00068 #define LibraryF 0x07 00069 00070 /** Library for the TI DRV2605 00071 * 00072 */ 00073 00074 class DRV2605 00075 { 00076 00077 public: 00078 // FeedBack_Controls Fields Bitmasks 00079 enum ActuatorType {ERM = 0, LRA = 0x80}; 00080 enum BrakeFactor {x1 = 0x00, x2 = 0x10, x3 = 0x20, x4 = 0x30, x6 = 0x40, x8 = 0x50, x16 = 0x60, DISABLE = 0x70}; 00081 enum LoopGain {LOW = 0x00, MEDIUM = 0x04, HIGH = 0x08, VERYHIGH = 0x0C}; 00082 00083 // Control2 Fields Bitmasks 00084 enum SampleTime {us150 = 0x00, us200 = 0x10, us250 = 0x20, us300 = 0x30}; 00085 00086 // Control4 Fields Bitmasks 00087 enum AutoCalTime {ms150_350 = 0x00, ms250_450 = 0x10, ms500_700 = 0x20, ms1000_1200 = 0x30}; 00088 00089 /** 00090 * Create a DRV2605 object 00091 * 00092 * @param &i2c pointer of I2C object 00093 * @param at actuator type 00094 * @param bf brake factor 00095 * @param lg loop gain 00096 * @param rv rated voltage 00097 * @param ocv overdirve clamp voltage 00098 * @param act auto caliblration time 00099 * @param dt drive time 00100 * @param st sample time 00101 * @param bt braking time 00102 * @param it current dissipation time 00103 */ 00104 DRV2605(I2C &i2c, ActuatorType at = ERM, BrakeFactor bf = x4, 00105 LoopGain lg = MEDIUM, uint8_t rv = 0x3F, uint8_t ocv = 0x89, 00106 AutoCalTime act = ms500_700, uint8_t dt = 0x13, 00107 SampleTime st = us200, uint8_t bt = 2, uint8_t it = 2); 00108 00109 /** 00110 * Write value to register 00111 * 00112 * @param reg Register to write 00113 * @param value Value to write to the register 00114 */ 00115 void i2cWriteByte(char reg, char value); 00116 00117 /** 00118 * Read value from register 00119 * 00120 * @param reg Register to read 00121 * @return Value 00122 */ 00123 uint8_t i2cReadByte(char reg); 00124 00125 /** 00126 * Set the device into specified mode 00127 * 00128 * @param mode Mode to set 00129 */ 00130 void mode(uint8_t mode); 00131 00132 /** 00133 * Runs diagnostics 00134 * 00135 * @return Results of the diagnostics 00136 */ 00137 uint8_t diagnostics(); 00138 00139 /** 00140 * Select the input data interpretation for RTP 00141 * 00142 * @param isSigned true: singed(-127~127), false: unsigned (0~255) 00143 */ 00144 void dataFormatRTP(bool isSigned); 00145 00146 /** 00147 * Set ROM Library 00148 * 00149 * Note: This should be called before setWaveform function 00150 * @param lib Set library (see library's macro) 00151 */ 00152 void setLibrary(uint8_t lib); 00153 00154 /** 00155 * Set single waveform from ROM Library 00156 * 00157 * Note: This should be called after setLibrary function 00158 * @param effect The Waveform Effect Library Index value to play (1 to 123) 00159 */ 00160 void setWaveform(int effect); 00161 00162 /** 00163 * Set waveform Sequence 00164 * 00165 * Note: This should be called after setLibrary function 00166 * @param effect1... effect8 The Waveform Effect Library Index value to play 00167 * (1 to 123): 0 = Stop Condition; 1- 123 = Waveform Index 00168 */ 00169 void setWaveformSequence(int effect1 = 0, int effect2 = 0, 00170 int effect3 = 0, int effect4 = 0, 00171 int effect5 = 0, int effect6 = 0, 00172 int effect7 = 0, int effect8 = 0); 00173 00174 /** 00175 * Plays the currently loaded waveform or waveform sequence. 00176 */ 00177 void play(); 00178 00179 /** 00180 * Stops the currently loaded waveform or waveform sequence. 00181 */ 00182 void stop(); 00183 00184 /** 00185 * Real time play back 00186 * 00187 * @param rtp intensity of the vibration (0 - 255) 00188 */ 00189 void playRtp(uint8_t rtp); 00190 00191 /** 00192 * Battery voltage monitor 00193 * 00194 * @return battery voltage 00195 */ 00196 float batteryVoltage(void); 00197 00198 private: 00199 I2C *_i2c; 00200 }; 00201 00202 #endif
Generated on Tue Jul 19 2022 15:54:23 by
1.7.2