|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Driver for the TI DRV2605/DRV2604 haptic motor controller. More...
#include <HapticDriver_DRV2605.hpp>
Public Member Functions | |
| HapticDriver_DRV2605 () | |
| Construct an uninitialized driver instance. | |
| ~HapticDriver_DRV2605 () override | |
| Destructor. | |
| void | end () override |
| Deinitialize the driver and release resources. | |
| bool | isReady () const override |
| Check if the driver is initialized and ready. | |
| const char * | getChipName () const override |
| Get the chip name. | |
| bool | run () override |
| Start haptic playback. | |
| bool | stop () override |
| Stop haptic playback immediately. | |
| bool | isPlaying () const override |
| Check if haptic is currently playing. | |
| HapticStatus | getStatus () const override |
| Get current playback status. | |
| void | emergencyStop () override |
| Emergency stop - stops all vibration immediately. | |
| bool | setGain (uint8_t gain) override |
| Set the gain/amplitude. | |
| uint8_t | getGain () const override |
| Get the current gain value. | |
| bool | playEffect (HapticEffectId effect) override |
| Play a haptic effect. | |
| bool | playEffectAsync (HapticEffectId effect) override |
| Play a haptic effect (non-blocking). | |
| void | continuousVibration (uint32_t duration_ms, bool blocking=true) override |
| Play a continuous vibration for specified duration. | |
| void | vibrationUpdate () override |
| Update vibration state (for non-blocking mode). | |
| bool | setSequence (uint8_t slot, HapticEffectId effect) override |
| Set a waveform in the sequence. | |
| bool | clearSequence () override |
| Clear the waveform sequence. | |
| bool | playSequence () override |
| Play the waveform sequence. | |
| HapticCapabilities | getCapabilities () const override |
| Get device capabilities. | |
| uint8_t | getChipID () const override |
| Get the chip ID. | |
| HapticActuatorType | getActuatorType () const override |
| Get the actuator type. | |
| bool | setActuatorType (HapticActuatorType type) override |
| Set the actuator type. | |
| bool | setMode (HapticMode mode) override |
| Set the operating mode. | |
| HapticMode | getMode () const override |
| Get the current operating mode. | |
| bool | setRealtimeValue (uint8_t value) override |
| Set RTP (real-time playback) value. | |
| bool | calibrate () override |
| Perform auto-calibration. | |
| bool | needsCalibration () const override |
| Check if calibration is needed. | |
| uint32_t | getF0 () const override |
| Get the measured resonant frequency (F0). | |
| uint32_t | getVbat () override |
| Get the battery voltage. | |
| void | setWaveform (uint8_t slot, uint8_t w) |
| Set a waveform entry in the playback sequence table. | |
| void | selectLibrary (uint8_t lib) |
| Select the ROM waveform library. | |
| bool | isDone () const |
| Check if playback is done. | |
| void | trigger () |
| Trigger a single playback cycle. | |
| uint8_t | getRealtimeValue () const |
| Get the current RTP value. | |
| void | setRatedVoltage (uint8_t value) |
| Set the rated voltage for auto-calibration. | |
| void | setOverdriveClamp (uint8_t value) |
| Set the overdrive clamp voltage for auto-calibration. | |
| int | autoCal () |
| Perform auto-calibration and return compensation result. | |
| void | setAutoBrake (bool enable) |
| Enable/disable automatic braking. | |
| void | setOverdriveTime (uint8_t cycles) |
| Set the number of overdrive cycles. | |
| void | setBrakeTime (uint8_t time) |
| Set the brake time offset. | |
| void | setRtpOverdrive (bool enable) |
| Enable/disable RTP overdrive. | |
| void | setERMLRA (bool erm) |
| Enable/disable ERM/LRA mode. | |
| void | setCtrl4 (uint8_t value) |
| Set the control4 register value. | |
| uint8_t | getLRAFrequency () const |
| Read the LRA resonance period (for LRA calibration). | |
Public Member Functions inherited from HapticBase | |
| virtual | ~HapticBase ()=default |
Public Member Functions inherited from I2CDeviceWithHal | |
| bool | begin (SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr) |
| Initialize the sensor using custom callback interface. | |
Public Member Functions inherited from DeviceBeginCommon | |
| virtual | ~DeviceBeginCommon () |
| uint8_t | getAddress () const |
| uint8_t | getInterface () const |
Public Member Functions inherited from SensorCommWrapper | |
| SensorCommWrapper ()=default | |
| int | readReg (uint8_t reg) const |
| int | readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const |
| int | readBuff (uint8_t *buf, size_t len) const |
| int | writeReg (uint8_t reg, uint8_t val) |
| int | writeRegBuff (uint8_t reg, uint8_t *buf, size_t len) |
| int | writeBuff (uint8_t *buf, size_t len) |
| int | writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len) |
| bool | setRegBit (uint8_t reg, uint8_t bit) |
| bool | clrRegBit (uint8_t reg, uint8_t bit) |
| bool | getRegBit (uint8_t reg, uint8_t bit) |
| int | updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted) |
| void | setAddress (uint8_t address) |
| void | setAck (bool enable) |
Public Member Functions inherited from SensorCommInterface | |
| virtual | ~SensorCommInterface ()=default |
Additional Inherited Members | |
Protected Member Functions inherited from HapticBase | |
| HapticBase (const char *name) | |
| Constructor for derived classes. | |
| void | setReady (bool ready) |
| Set ready state. | |
Protected Member Functions inherited from I2CDeviceWithHal | |
| bool | ensureValid () const override |
| Ensure the communication interface is valid. | |
Protected Member Functions inherited from DeviceBeginCommon | |
| DeviceBeginCommon ()=default | |
| virtual SensorCommBase * | getComm () const override |
| virtual void | beforeBegin () |
| virtual void | afterCommReady () |
| virtual void | onBeginFail () |
| bool | fail () |
| void | clearCommState () |
| template<typename CreateComm > | |
| bool | beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm) |
Protected Attributes inherited from HapticBase | |
| const char * | _chipName |
| bool | _isReady |
Protected Attributes inherited from DeviceBeginCommon | |
| std::unique_ptr< SensorCommBase > | comm |
| std::unique_ptr< SensorHal > | hal |
| std::unique_ptr< SensorCommStatic > | staticComm |
| uint8_t | _addr = 0 |
| uint8_t | _iface = COMM_CUSTOM |
Driver for the TI DRV2605/DRV2604 haptic motor controller.
This driver provides a complete interface for controlling the DRV2605/DRV2604 haptic motor driver IC via I2C. It inherits from HapticBase to provide a unified interface across different haptic drivers.
Definition at line 115 of file HapticDriver_DRV2605.hpp.
| HapticDriver_DRV2605::HapticDriver_DRV2605 | ( | ) |
Construct an uninitialized driver instance.
Definition at line 37 of file HapticDriver_DRV2605.cpp.
References i.
|
override |
Destructor.
Deinitializes communication backend if created.
Definition at line 49 of file HapticDriver_DRV2605.cpp.
References end().
| int HapticDriver_DRV2605::autoCal | ( | ) |
Perform auto-calibration and return compensation result.
Runs the full auto-calibration sequence and returns the compensation value stored in the AUTOCALCOMP register.
Definition at line 338 of file HapticDriver_DRV2605.cpp.
References AUTO_CALIBRATE, DeviceBeginCommon::hal, INTERNAL_TRIGGER, isDone(), SensorCommWrapper::readReg(), run(), and setMode().
Referenced by calibrate().
|
overridevirtual |
Perform auto-calibration.
Runs the built-in auto-calibration sequence.
Reimplemented from HapticBase.
Definition at line 274 of file HapticDriver_DRV2605.cpp.
References autoCal().
Referenced by loop(), testAutoDemo(), and testCalibration().
|
overridevirtual |
Clear the waveform sequence.
Reimplemented from HapticBase.
Definition at line 153 of file HapticDriver_DRV2605.cpp.
References i, and setWaveform().
Referenced by testSetSequence().
|
overridevirtual |
Play a continuous vibration for specified duration.
| duration_ms | Ignored. |
| blocking | Ignored. |
Reimplemented from HapticBase.
Definition at line 135 of file HapticDriver_DRV2605.cpp.
|
overridevirtual |
Emergency stop - stops all vibration immediately.
Reimplemented from HapticBase.
Definition at line 98 of file HapticDriver_DRV2605.cpp.
References stop().
|
overridevirtual |
Deinitialize the driver and release resources.
Reimplemented from HapticBase.
Definition at line 54 of file HapticDriver_DRV2605.cpp.
References HapticBase::setReady(), and stop().
Referenced by ~HapticDriver_DRV2605().
|
overridevirtual |
Get the actuator type.
Implements HapticBase.
Definition at line 191 of file HapticDriver_DRV2605.cpp.
Referenced by loop(), setup(), testActuatorType(), and testInit().
|
overridevirtual |
Get device capabilities.
Supported: RTP, Sequence, AutoCalibration, BreakEffect, Overdrive Unsupported: F0Calibration, VbatCompensation, ContinuousMode
Implements HapticBase.
Definition at line 167 of file HapticDriver_DRV2605.cpp.
References HapticCapabilities::hasAutoCalibration, HapticCapabilities::hasBreakEffect, HapticCapabilities::hasContinuousMode, HapticCapabilities::hasF0Calibration, HapticCapabilities::hasOverdrive, HapticCapabilities::hasRTP, HapticCapabilities::hasSequence, HapticCapabilities::hasVbatCompensation, HapticCapabilities::maxDurationMs, HapticCapabilities::maxEffectCount, and HapticCapabilities::maxSequenceLength.
Referenced by testCapabilities().
|
overridevirtual |
Get the chip ID.
Implements HapticBase.
Definition at line 184 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg().
Referenced by setup(), and testInit().
|
overridevirtual |
Get the chip name.
Implements HapticBase.
Definition at line 65 of file HapticDriver_DRV2605.cpp.
Referenced by setup(), and testInit().
|
overridevirtual |
Get the measured resonant frequency (F0).
Reimplemented from HapticBase.
Definition at line 285 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg().
Referenced by testF0().
|
overridevirtual |
Get the current gain value.
Implements HapticBase.
Definition at line 114 of file HapticDriver_DRV2605.cpp.
| uint8_t HapticDriver_DRV2605::getLRAFrequency | ( | ) | const |
Read the LRA resonance period (for LRA calibration).
Definition at line 409 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg().
|
overridevirtual |
Get the current operating mode.
Reimplemented from HapticBase.
Definition at line 251 of file HapticDriver_DRV2605.cpp.
References INTERNAL_TRIGGER, SensorCommWrapper::readReg(), and STANDBY.
Referenced by setup(), testInit(), and testModes().
| uint8_t HapticDriver_DRV2605::getRealtimeValue | ( | ) | const |
Get the current RTP value.
Definition at line 268 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg().
|
overridevirtual |
Get current playback status.
Implements HapticBase.
Definition at line 90 of file HapticDriver_DRV2605.cpp.
References HapticBase::_isReady, ERROR, IDLE, isPlaying(), PLAYING, and STANDBY.
Referenced by testStatus().
|
overridevirtual |
Get the battery voltage.
Reimplemented from HapticBase.
Definition at line 296 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg().
Referenced by loop(), setup(), and testInit().
| bool HapticDriver_DRV2605::isDone | ( | ) | const |
Check if playback is done.
Definition at line 317 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg().
Referenced by autoCal().
|
overridevirtual |
Check if haptic is currently playing.
Implements HapticBase.
Definition at line 84 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg().
Referenced by getStatus(), and testStop().
|
overridevirtual |
Check if the driver is initialized and ready.
Implements HapticBase.
Definition at line 60 of file HapticDriver_DRV2605.cpp.
References HapticBase::_isReady.
|
overridevirtual |
Check if calibration is needed.
Reimplemented from HapticBase.
Definition at line 280 of file HapticDriver_DRV2605.cpp.
|
overridevirtual |
Play a haptic effect.
Plays a ROM waveform effect with blocking (waits for completion).
| effect | Effect ID (1-117 based on selected library). |
Implements HapticBase.
Definition at line 121 of file HapticDriver_DRV2605.cpp.
References HapticBase::_isReady, run(), and setWaveform().
Referenced by loop(), playEffectAsync(), testAutoDemo(), testLibrarySelection(), testPlayEffect(), testPlayEffectRange(), and testStop().
|
overridevirtual |
Play a haptic effect (non-blocking).
| effect | Effect ID to play. |
Reimplemented from HapticBase.
Definition at line 130 of file HapticDriver_DRV2605.cpp.
References playEffect().
|
overridevirtual |
Play the waveform sequence.
Reimplemented from HapticBase.
Definition at line 162 of file HapticDriver_DRV2605.cpp.
References run().
Referenced by testSetSequence().
|
overridevirtual |
Start haptic playback.
Implements HapticBase.
Definition at line 70 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
Referenced by autoCal(), playEffect(), playSequence(), and trigger().
| void HapticDriver_DRV2605::selectLibrary | ( | uint8_t | lib | ) |
Select the ROM waveform library.
Different libraries contain different sets of built-in effects.
| lib | Library selection:
|
Definition at line 311 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
Referenced by loop(), and testLibrarySelection().
|
overridevirtual |
Set the actuator type.
Automatically selects the appropriate ROM library:
| type | Actuator type to set (ERM or LRA). |
Implements HapticBase.
Definition at line 196 of file HapticDriver_DRV2605.cpp.
References ERM, SensorCommWrapper::updateBits(), and SensorCommWrapper::writeReg().
Referenced by loop(), setERMLRA(), and testActuatorType().
| void HapticDriver_DRV2605::setAutoBrake | ( | bool | enable | ) |
Enable/disable automatic braking.
When enabled, the chip automatically applies braking after each waveform effect.
| enable | true to enable, false to disable. |
Definition at line 362 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().
| void HapticDriver_DRV2605::setBrakeTime | ( | uint8_t | time | ) |
Set the brake time offset.
Controls the braking period after each waveform.
| time | Brake time offset value (0-255). |
Definition at line 380 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
| void HapticDriver_DRV2605::setCtrl4 | ( | uint8_t | value | ) |
Set the control4 register value.
| value | Control4 register value. |
Definition at line 404 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
| void HapticDriver_DRV2605::setERMLRA | ( | bool | erm | ) |
Enable/disable ERM/LRA mode.
| erm | true for ERM, false for LRA. |
Definition at line 398 of file HapticDriver_DRV2605.cpp.
References ERM, LRA, and setActuatorType().
|
overridevirtual |
Set the gain/amplitude.
| gain | Ignored. |
Implements HapticBase.
Definition at line 103 of file HapticDriver_DRV2605.cpp.
|
overridevirtual |
Set the operating mode.
| mode | Mode to set:
|
Reimplemented from HapticBase.
Definition at line 210 of file HapticDriver_DRV2605.cpp.
References AUDIO_TO_VIBE, AUTO_CALIBRATE, DIAGNOSTICS, EXT_TRIGGER_EDGE, EXT_TRIGGER_LEVEL, INTERNAL_TRIGGER, PWM_ANALOG, REAL_TIME_PLAYBACK, STANDBY, and SensorCommWrapper::writeReg().
Referenced by autoCal(), loop(), testModes(), testNormalMode(), testRTP(), and testStandby().
| void HapticDriver_DRV2605::setOverdriveClamp | ( | uint8_t | value | ) |
Set the overdrive clamp voltage for auto-calibration.
This value controls the maximum voltage during auto-calibration.
| value | Overdrive clamp voltage value. |
Definition at line 333 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
| void HapticDriver_DRV2605::setOverdriveTime | ( | uint8_t | cycles | ) |
Set the number of overdrive cycles.
Controls how long the overdrive period lasts at the beginning of each waveform.
| cycles | Number of overdrive cycles (0-255). |
Definition at line 375 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
| void HapticDriver_DRV2605::setRatedVoltage | ( | uint8_t | value | ) |
Set the rated voltage for auto-calibration.
This value should match the rated voltage of your actuator.
| value | Rated voltage value (register value). |
Definition at line 328 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
|
overridevirtual |
Set RTP (real-time playback) value.
Provides direct amplitude control in RTP mode.
| value | RTP drive value (0x00 to 0xFF). |
Reimplemented from HapticBase.
Definition at line 263 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
| void HapticDriver_DRV2605::setRtpOverdrive | ( | bool | enable | ) |
Enable/disable RTP overdrive.
When enabled, RTP mode uses overdrive to reach the target amplitude faster.
| enable | true to enable, false to disable. |
Definition at line 385 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().
|
overridevirtual |
Set a waveform in the sequence.
| slot | Sequence slot index (0 to 7). |
| effect | Effect ID to play at this slot. |
Reimplemented from HapticBase.
Definition at line 145 of file HapticDriver_DRV2605.cpp.
References setWaveform().
Referenced by testSetSequence().
| void HapticDriver_DRV2605::setWaveform | ( | uint8_t | slot, |
| uint8_t | w | ||
| ) |
Set a waveform entry in the playback sequence table.
Playback starts at slot 0 and continues sequentially until a value of 0 is encountered, or slot 7 is reached.
| slot | Sequence slot index (0..7). |
| w | Waveform index in the device ROM library (0 = end). |
Definition at line 306 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
Referenced by clearSequence(), playEffect(), and setSequence().
|
overridevirtual |
Stop haptic playback immediately.
Implements HapticBase.
Definition at line 79 of file HapticDriver_DRV2605.cpp.
References SensorCommWrapper::writeReg().
Referenced by emergencyStop(), end(), loop(), testAutoDemo(), testRTP(), and testStop().
| void HapticDriver_DRV2605::trigger | ( | ) |
Trigger a single playback cycle.
Sets the GO bit to start playback of the waveform sequence. Equivalent to run().
Definition at line 323 of file HapticDriver_DRV2605.cpp.
References run().
|
overridevirtual |
Update vibration state (for non-blocking mode).
Reimplemented from HapticBase.
Definition at line 141 of file HapticDriver_DRV2605.cpp.