I2C Piezo Haptic Driver with Integrated Boost Converter and Digital Front End
drv2665.h@0:b85fd3fdfcfa, 2016-05-25 (annotated)
- Committer:
- akashvibhute
- Date:
- Wed May 25 03:17:20 2016 +0000
- Revision:
- 0:b85fd3fdfcfa
- Child:
- 1:e2c726c628dc
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:b85fd3fdfcfa | 1 | /** DRV2665 library |
akashvibhute | 0:b85fd3fdfcfa | 2 | * |
akashvibhute | 0:b85fd3fdfcfa | 3 | * @author Akash Vibhute |
akashvibhute | 0:b85fd3fdfcfa | 4 | * @author < akash . roboticist [at] gmail . com > |
akashvibhute | 0:b85fd3fdfcfa | 5 | * @version 0.1 |
akashvibhute | 0:b85fd3fdfcfa | 6 | * @date May/24/2016 |
akashvibhute | 0:b85fd3fdfcfa | 7 | * |
akashvibhute | 0:b85fd3fdfcfa | 8 | * @section LICENSE |
akashvibhute | 0:b85fd3fdfcfa | 9 | * |
akashvibhute | 0:b85fd3fdfcfa | 10 | * Copyright (c) 2015 Akash Vibhute |
akashvibhute | 0:b85fd3fdfcfa | 11 | * |
akashvibhute | 0:b85fd3fdfcfa | 12 | * Licensed under the Apache License, Version 2.0 (the "License"); |
akashvibhute | 0:b85fd3fdfcfa | 13 | * you may not use this file except in compliance with the License. |
akashvibhute | 0:b85fd3fdfcfa | 14 | * You may obtain a copy of the License at |
akashvibhute | 0:b85fd3fdfcfa | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
akashvibhute | 0:b85fd3fdfcfa | 16 | * |
akashvibhute | 0:b85fd3fdfcfa | 17 | * Unless required by applicable law or agreed to in writing, software |
akashvibhute | 0:b85fd3fdfcfa | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
akashvibhute | 0:b85fd3fdfcfa | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
akashvibhute | 0:b85fd3fdfcfa | 20 | * See the License for the specific language governing permissions and |
akashvibhute | 0:b85fd3fdfcfa | 21 | * limitations under the License. |
akashvibhute | 0:b85fd3fdfcfa | 22 | * |
akashvibhute | 0:b85fd3fdfcfa | 23 | * The above copyright notice and this permission notice shall be included in |
akashvibhute | 0:b85fd3fdfcfa | 24 | * all copies or substantial portions of the Software. |
akashvibhute | 0:b85fd3fdfcfa | 25 | */ |
akashvibhute | 0:b85fd3fdfcfa | 26 | |
akashvibhute | 0:b85fd3fdfcfa | 27 | /* Contol registers */ |
akashvibhute | 0:b85fd3fdfcfa | 28 | #define DRV2665_STATUS 0x00 |
akashvibhute | 0:b85fd3fdfcfa | 29 | #define DRV2665_CTRL_1 0x01 |
akashvibhute | 0:b85fd3fdfcfa | 30 | #define DRV2665_CTRL_2 0x02 |
akashvibhute | 0:b85fd3fdfcfa | 31 | #define DRV2665_FIFO 0x0b |
akashvibhute | 0:b85fd3fdfcfa | 32 | |
akashvibhute | 0:b85fd3fdfcfa | 33 | /* Status Register */ |
akashvibhute | 0:b85fd3fdfcfa | 34 | #define DRV2665_FIFO_FULL 0x00 |
akashvibhute | 0:b85fd3fdfcfa | 35 | #define DRV2665_FIFO_EMPTY 0x02 |
akashvibhute | 0:b85fd3fdfcfa | 36 | |
akashvibhute | 0:b85fd3fdfcfa | 37 | /* Control 1 Register */ |
akashvibhute | 0:b85fd3fdfcfa | 38 | #define DRV2665_25_VPP_GAIN 0x00 |
akashvibhute | 0:b85fd3fdfcfa | 39 | #define DRV2665_50_VPP_GAIN 0x01 |
akashvibhute | 0:b85fd3fdfcfa | 40 | #define DRV2665_75_VPP_GAIN 0x02 |
akashvibhute | 0:b85fd3fdfcfa | 41 | #define DRV2665_100_VPP_GAIN 0x03 |
akashvibhute | 0:b85fd3fdfcfa | 42 | #define DRV2665_DIGITAL_IN 0x00 |
akashvibhute | 0:b85fd3fdfcfa | 43 | #define DRV2665_ANALOG_IN 0x04 |
akashvibhute | 0:b85fd3fdfcfa | 44 | |
akashvibhute | 0:b85fd3fdfcfa | 45 | #define DRV2665_GAIN_RD_MASK 0x03 |
akashvibhute | 0:b85fd3fdfcfa | 46 | #define DRV2665_IN_RD_MASK 0x04 |
akashvibhute | 0:b85fd3fdfcfa | 47 | #define DRV2665_CHIPID_RD_MASK 0x78 |
akashvibhute | 0:b85fd3fdfcfa | 48 | |
akashvibhute | 0:b85fd3fdfcfa | 49 | |
akashvibhute | 0:b85fd3fdfcfa | 50 | /* Control 2 Register */ |
akashvibhute | 0:b85fd3fdfcfa | 51 | #define DRV2665_BOOST_EN 0x02 |
akashvibhute | 0:b85fd3fdfcfa | 52 | #define DRV2665_STANDBY 0x40 |
akashvibhute | 0:b85fd3fdfcfa | 53 | #define DRV2665_DEV_RST 0x80 |
akashvibhute | 0:b85fd3fdfcfa | 54 | #define DRV2665_5_MS_IDLE_TOUT 0x00 |
akashvibhute | 0:b85fd3fdfcfa | 55 | #define DRV2665_10_MS_IDLE_TOUT 0x04 |
akashvibhute | 0:b85fd3fdfcfa | 56 | #define DRV2665_15_MS_IDLE_TOUT 0x08 |
akashvibhute | 0:b85fd3fdfcfa | 57 | #define DRV2665_20_MS_IDLE_TOUT 0x0c |
akashvibhute | 0:b85fd3fdfcfa | 58 | |
akashvibhute | 0:b85fd3fdfcfa | 59 | #define DRV2665_I2C_ADDRESS 0x59 |
akashvibhute | 0:b85fd3fdfcfa | 60 | |
akashvibhute | 0:b85fd3fdfcfa | 61 | #ifndef DRV2665_H |
akashvibhute | 0:b85fd3fdfcfa | 62 | #define DRV2665_H |
akashvibhute | 0:b85fd3fdfcfa | 63 | |
akashvibhute | 0:b85fd3fdfcfa | 64 | #include "mbed.h" |
akashvibhute | 0:b85fd3fdfcfa | 65 | |
akashvibhute | 0:b85fd3fdfcfa | 66 | /** DRV2665_DIGITAL class |
akashvibhute | 0:b85fd3fdfcfa | 67 | * |
akashvibhute | 0:b85fd3fdfcfa | 68 | * @section DESCRIPTION |
akashvibhute | 0:b85fd3fdfcfa | 69 | * DRV2665: Piezo Haptic Driver with Integrated Boost Converter and Digital Front End |
akashvibhute | 0:b85fd3fdfcfa | 70 | * The DRV2665 device is a piezo haptic driver with |
akashvibhute | 0:b85fd3fdfcfa | 71 | * integrated 105-V boost switch, integrated power |
akashvibhute | 0:b85fd3fdfcfa | 72 | * diode, integrated fully-differential amplifier, and |
akashvibhute | 0:b85fd3fdfcfa | 73 | * integrated digital front end. This versatile device is |
akashvibhute | 0:b85fd3fdfcfa | 74 | * capable of driving both high-voltage and low-voltage |
akashvibhute | 0:b85fd3fdfcfa | 75 | * piezo haptic actuators. The input signal can be driven |
akashvibhute | 0:b85fd3fdfcfa | 76 | * as haptic packets over the I2C port or through the |
akashvibhute | 0:b85fd3fdfcfa | 77 | * analog inputs |
akashvibhute | 0:b85fd3fdfcfa | 78 | * |
akashvibhute | 0:b85fd3fdfcfa | 79 | * The digital interface of the DRV2665 device is |
akashvibhute | 0:b85fd3fdfcfa | 80 | * available through an I2C compatible bus. A digital |
akashvibhute | 0:b85fd3fdfcfa | 81 | * interface relieves the costly processor burden of the |
akashvibhute | 0:b85fd3fdfcfa | 82 | * PWM generation or additional analog channel |
akashvibhute | 0:b85fd3fdfcfa | 83 | * requirements in the host system. Any writes to the |
akashvibhute | 0:b85fd3fdfcfa | 84 | * internal first-in, first-out buffer (FIFO) will |
akashvibhute | 0:b85fd3fdfcfa | 85 | * automatically wake up the device and begin playing |
akashvibhute | 0:b85fd3fdfcfa | 86 | * the waveform after the 2 ms internal start-up |
akashvibhute | 0:b85fd3fdfcfa | 87 | * procedure. When the data flow stops or the FIFO |
akashvibhute | 0:b85fd3fdfcfa | 88 | * under-runs, the DRV2665 device will automatically |
akashvibhute | 0:b85fd3fdfcfa | 89 | * enter a pop-less shutdown procedure. |
akashvibhute | 0:b85fd3fdfcfa | 90 | * |
akashvibhute | 0:b85fd3fdfcfa | 91 | * The boost voltage is set using two external resistors, |
akashvibhute | 0:b85fd3fdfcfa | 92 | * and the boost current limit is programmable through |
akashvibhute | 0:b85fd3fdfcfa | 93 | * the REXT resistor. A typical start-up time of 2 ms |
akashvibhute | 0:b85fd3fdfcfa | 94 | * makes the DRV2665 device an ideal piezo driver for |
akashvibhute | 0:b85fd3fdfcfa | 95 | * fast haptic responses. Thermal overload protection |
akashvibhute | 0:b85fd3fdfcfa | 96 | * prevents the device from being damaged when |
akashvibhute | 0:b85fd3fdfcfa | 97 | * overdriven. |
akashvibhute | 0:b85fd3fdfcfa | 98 | * |
akashvibhute | 0:b85fd3fdfcfa | 99 | * Datasheet for DRV2665 can be found at: |
akashvibhute | 0:b85fd3fdfcfa | 100 | * http://www.ti.com/lit/gpn/drv2665 |
akashvibhute | 0:b85fd3fdfcfa | 101 | * |
akashvibhute | 0:b85fd3fdfcfa | 102 | * Example: |
akashvibhute | 0:b85fd3fdfcfa | 103 | * @code |
akashvibhute | 0:b85fd3fdfcfa | 104 | * #include "mbed.h" |
akashvibhute | 0:b85fd3fdfcfa | 105 | * #include "DRV2665.h" |
akashvibhute | 0:b85fd3fdfcfa | 106 | * |
akashvibhute | 0:b85fd3fdfcfa | 107 | * DRV2665_DIGITAL piezo(I2C_SDA, I2C_SCL); // DRV2665 digital mode object |
akashvibhute | 0:b85fd3fdfcfa | 108 | * |
akashvibhute | 0:b85fd3fdfcfa | 109 | * int main() |
akashvibhute | 0:b85fd3fdfcfa | 110 | * { |
akashvibhute | 0:b85fd3fdfcfa | 111 | * piezo.init(DRV2665_100_VPP_GAIN, DRV2665_5_MS_IDLE_TOUT); // set output level to 100Vpp and idle timeout to 5ms |
akashvibhute | 0:b85fd3fdfcfa | 112 | * |
akashvibhute | 0:b85fd3fdfcfa | 113 | * while(1) { |
akashvibhute | 0:b85fd3fdfcfa | 114 | * |
akashvibhute | 0:b85fd3fdfcfa | 115 | * piezo.outputSine(8000); // outputs 8khz sine waveform at selected voltage level |
akashvibhute | 0:b85fd3fdfcfa | 116 | * |
akashvibhute | 0:b85fd3fdfcfa | 117 | * wait_ms(1); |
akashvibhute | 0:b85fd3fdfcfa | 118 | * } |
akashvibhute | 0:b85fd3fdfcfa | 119 | * } |
akashvibhute | 0:b85fd3fdfcfa | 120 | * @endcode |
akashvibhute | 0:b85fd3fdfcfa | 121 | */ |
akashvibhute | 0:b85fd3fdfcfa | 122 | |
akashvibhute | 0:b85fd3fdfcfa | 123 | class DRV2665_DIGITAL |
akashvibhute | 0:b85fd3fdfcfa | 124 | { |
akashvibhute | 0:b85fd3fdfcfa | 125 | public: |
akashvibhute | 0:b85fd3fdfcfa | 126 | |
akashvibhute | 0:b85fd3fdfcfa | 127 | /** Create a DRV2665_DIGITAL instance connected to specified I2C pins with specified address |
akashvibhute | 0:b85fd3fdfcfa | 128 | * |
akashvibhute | 0:b85fd3fdfcfa | 129 | * @param sda I2C-bus SDA pin |
akashvibhute | 0:b85fd3fdfcfa | 130 | * @param scl I2C-bus SCL pin |
akashvibhute | 0:b85fd3fdfcfa | 131 | */ |
akashvibhute | 0:b85fd3fdfcfa | 132 | DRV2665_DIGITAL( PinName sda, PinName scl ); |
akashvibhute | 0:b85fd3fdfcfa | 133 | |
akashvibhute | 0:b85fd3fdfcfa | 134 | /** Initializing DRV2665 in digital mode |
akashvibhute | 0:b85fd3fdfcfa | 135 | * |
akashvibhute | 0:b85fd3fdfcfa | 136 | * Switch to commended downstream I2C channel |
akashvibhute | 0:b85fd3fdfcfa | 137 | * |
akashvibhute | 0:b85fd3fdfcfa | 138 | * @param output_gain sets the output voltage level |
akashvibhute | 0:b85fd3fdfcfa | 139 | * @param idle_timeout sets the idle timeout in ms |
akashvibhute | 0:b85fd3fdfcfa | 140 | */ |
akashvibhute | 0:b85fd3fdfcfa | 141 | void init(uint8_t output_gain, uint8_t idle_timeout); |
akashvibhute | 0:b85fd3fdfcfa | 142 | |
akashvibhute | 0:b85fd3fdfcfa | 143 | /** Reset DRV2665 |
akashvibhute | 0:b85fd3fdfcfa | 144 | * |
akashvibhute | 0:b85fd3fdfcfa | 145 | * Reset piezo driver |
akashvibhute | 0:b85fd3fdfcfa | 146 | */ |
akashvibhute | 0:b85fd3fdfcfa | 147 | void reset(); |
akashvibhute | 0:b85fd3fdfcfa | 148 | |
akashvibhute | 0:b85fd3fdfcfa | 149 | /** Output waveform |
akashvibhute | 0:b85fd3fdfcfa | 150 | * |
akashvibhute | 0:b85fd3fdfcfa | 151 | * Writes custom output waveform to FIFO (100 bytes max), which is played back at 8kHz |
akashvibhute | 0:b85fd3fdfcfa | 152 | * @param waveform[] contains the waveform values |
akashvibhute | 0:b85fd3fdfcfa | 153 | * @param length tells the function how many values makeup the wave |
akashvibhute | 0:b85fd3fdfcfa | 154 | */ |
akashvibhute | 0:b85fd3fdfcfa | 155 | void outputWave(int8_t waveform[], uint8_t length); |
akashvibhute | 0:b85fd3fdfcfa | 156 | |
akashvibhute | 0:b85fd3fdfcfa | 157 | |
akashvibhute | 0:b85fd3fdfcfa | 158 | /** Output sine |
akashvibhute | 0:b85fd3fdfcfa | 159 | * |
akashvibhute | 0:b85fd3fdfcfa | 160 | * Writes sinewave values to FIFO buffer |
akashvibhute | 0:b85fd3fdfcfa | 161 | * @param hz contains the frequency in hz of the waveform |
akashvibhute | 0:b85fd3fdfcfa | 162 | */ |
akashvibhute | 0:b85fd3fdfcfa | 163 | void outputSine(uint16_t hz); |
akashvibhute | 0:b85fd3fdfcfa | 164 | |
akashvibhute | 0:b85fd3fdfcfa | 165 | /** Check FIFO status |
akashvibhute | 0:b85fd3fdfcfa | 166 | * |
akashvibhute | 0:b85fd3fdfcfa | 167 | * returns the status of the FIFO buffer, false -> FIFO is full, true otherwise |
akashvibhute | 0:b85fd3fdfcfa | 168 | */ |
akashvibhute | 0:b85fd3fdfcfa | 169 | bool fifo_check(); |
akashvibhute | 0:b85fd3fdfcfa | 170 | |
akashvibhute | 0:b85fd3fdfcfa | 171 | /** Override boot converter |
akashvibhute | 0:b85fd3fdfcfa | 172 | * |
akashvibhute | 0:b85fd3fdfcfa | 173 | * To override boot converter to be enabled indefinitely (-> true) or controlled by device logic (-> false) |
akashvibhute | 0:b85fd3fdfcfa | 174 | */ |
akashvibhute | 0:b85fd3fdfcfa | 175 | void en_override(bool en); |
akashvibhute | 0:b85fd3fdfcfa | 176 | |
akashvibhute | 0:b85fd3fdfcfa | 177 | private: |
akashvibhute | 0:b85fd3fdfcfa | 178 | I2C i2c_; |
akashvibhute | 0:b85fd3fdfcfa | 179 | uint8_t i2c_addr; |
akashvibhute | 0:b85fd3fdfcfa | 180 | |
akashvibhute | 0:b85fd3fdfcfa | 181 | //Internal functions |
akashvibhute | 0:b85fd3fdfcfa | 182 | uint8_t read(char reg); |
akashvibhute | 0:b85fd3fdfcfa | 183 | void write(char reg, uint8_t data); |
akashvibhute | 0:b85fd3fdfcfa | 184 | }; |
akashvibhute | 0:b85fd3fdfcfa | 185 | |
akashvibhute | 0:b85fd3fdfcfa | 186 | #endif // DRV2665 |