SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
HapticDriver_AW86224 Class Reference

AW86224/86225 Haptic Driver Class. More...

#include <HapticDriver_AW86224.hpp>

Inheritance diagram for HapticDriver_AW86224:
[legend]

Public Types

enum class  PlayMode : uint8_t {
  STANDBY = 0 , RAM = 1 , RAM_LOOP = 2 , CONT = 3 ,
  RTP = 4
}
 Playback mode enumeration. More...
 
enum class  SramSize : uint8_t { SRAM_1K = 0 , SRAM_2K = 1 , SRAM_3K = 2 }
 SRAM size selection. More...
 
enum class  ChipID : uint8_t { AW86223 = 1 , AW86224 = 2 , AW86225 = 3 , AW86214 = 4 }
 Chip ID enumeration. More...
 
enum class  PwmMode : uint8_t { PWM_48K = 0 , PWM_24K = 1 , PWM_12K = 2 }
 PWM mode selection. More...
 

Public Member Functions

 HapticDriver_AW86224 ()
 Default constructor.
 
void setPins (uint8_t resetPin, uint8_t intPin)
 setPins
 
void end () override
 Deinitialize the haptic 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.
 
bool setGain (uint8_t gain) override
 Set the gain/amplitude (0x00 to 0xFF).
 
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.
 
uint8_t getChipID () const override
 Get the chip ID.
 
HapticCapabilities getCapabilities () const override
 Get device capabilities.
 
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.
 
bool setMode (HapticMode mode) override
 Set the operating mode.
 
HapticMode getMode () const override
 Get the current operating mode.
 
HapticActuatorType getActuatorType () const override
 Get the actuator type.
 
bool setActuatorType (HapticActuatorType type) override
 Set the actuator type.
 
bool setRealtimeValue (uint8_t value) override
 Set RTP (real-time playback) value.
 
void softReset ()
 Perform soft reset.
 
void shortVibration (uint8_t index, uint8_t gain=0x80, uint8_t loop=1)
 Play a short vibration effect.
 
void longVibration (uint8_t index, uint8_t gain=0x80, uint32_t duration_ms=1000, bool blocking=true)
 Play a long continuous vibration effect.
 
void stopVibration ()
 Stop any ongoing vibration.
 
void setWaveSeq (uint8_t wav, uint8_t seq)
 Update vibration state (for non-blocking mode)
 
void setWaveLoop (uint8_t wav, uint8_t loop)
 Set waveform loop count.
 
void setPlayMode (PlayMode mode)
 Set playback mode.
 
void setTrimLRA (uint8_t val)
 Set LRA frequency trim value.
 
void setRtpData (uint8_t *data, uint32_t len)
 Set RTP waveform data.
 
bool playRtp (const uint8_t *data, uint32_t len, uint8_t gain=0x80)
 Play RTP (Real-Time Playback) waveform.
 
bool loadRamData (const uint8_t *data, uint32_t len)
 Load RAM waveform data.
 
uint8_t getRamNum () const
 Get number of loaded waveforms.
 
bool isRamInit () const
 Check if RAM is initialized.
 
uint32_t getVbatValue () const
 Get current voltage reading.
 
PlayMode getPlayMode () const
 Get current play mode.
 
int8_t getF0CaliData () const
 Get F0 calibration data.
 
uint32_t getLraValue () const
 Get LRA resistance.
 
void setF0Pre (uint32_t val)
 Set expected F0 (resonant frequency)
 
uint32_t getF0Pre () const
 
void setLraVrms (uint32_t val)
 Set LRA rated voltage.
 
uint32_t getLraVrms () const
 
void setContBrkTime (uint8_t val)
 Set continuous mode break time.
 
uint8_t getContBrkTime () const
 
void setContBrkGain (uint8_t val)
 Set continuous mode break gain.
 
uint8_t getContBrkGain () const
 
void setContDrv1Lvl (uint8_t val)
 Set continuous mode drive level 1.
 
uint8_t getContDrv1Lvl () const
 
void setContDrv1Time (uint8_t val)
 Set continuous mode drive time 1.
 
uint8_t getContDrv1Time () const
 
void setContDrv2Time (uint8_t val)
 Set continuous mode drive time 2.
 
uint8_t getContDrv2Time () const
 
void setContTrackMargin (uint8_t val)
 Set continuous mode track margin.
 
uint8_t getContTrackMargin () const
 
void setD2sGain (uint8_t val)
 Set D2S gain (digital to simulation gain)
 
uint8_t getD2sGain () const
 
void setPwmcfg4Prtime (uint8_t val)
 Set protection time.
 
uint8_t getPwmcfg4Prtime () const
 
void setPwmcfg3Prlvl (uint8_t val)
 Set protection level.
 
uint8_t getPwmcfg3Prlvl () const
 
void setAutoBrkEnabled (bool val)
 Enable/disable auto break.
 
bool getAutoBrkEnabled () const
 
void setF0CaliPercent (uint8_t val)
 Set F0 calibration tolerance percentage.
 
uint8_t getF0CaliPercent () const
 
bool isVibrating () const
 Check if vibration is currently active (alias for isPlaying)
 
- Public Member Functions inherited from HapticBase
virtual ~HapticBase ()=default
 
virtual void emergencyStop ()
 Emergency stop - stops all vibration immediately.
 
- 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 SensorCommBasegetComm () 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< SensorCommBasecomm
 
std::unique_ptr< SensorHalhal
 
std::unique_ptr< SensorCommStaticstaticComm
 
uint8_t _addr = 0
 
uint8_t _iface = COMM_CUSTOM
 

Detailed Description

AW86224/86225 Haptic Driver Class.

This class provides a complete interface for controlling the AW86224/86225 haptic motor driver. It inherits from HapticBase and I2CDeviceWithHal to provide standardized haptic control and I2C communication.

Vibration Modes:
  • STANDBY: Low power standby mode, no vibration
  • RAM: Single play of RAM waveform
  • RAM_LOOP: Continuous loop playback of RAM waveform
  • CONT: Continuous mode using F0 tracking
  • RTP: Real-time playback mode for custom waveforms
Calibration:
The driver performs F0 (resonant frequency) calibration automatically during initialization. This ensures optimal vibration performance across different motor characteristics.
Thread Safety:
When using non-blocking vibration modes, ensure vibrationUpdate() is called regularly in your main loop to maintain proper timing.

Definition at line 69 of file HapticDriver_AW86224.hpp.

Member Enumeration Documentation

◆ ChipID

enum class HapticDriver_AW86224::ChipID : uint8_t
strong

Chip ID enumeration.

Identifies the connected AWinic haptic chip model.

Enumerator
AW86223 

AW86223 chip.

AW86224 

AW86224 chip.

AW86225 

AW86225 chip.

AW86214 

AW86214 chip.

Definition at line 102 of file HapticDriver_AW86224.hpp.

◆ PlayMode

enum class HapticDriver_AW86224::PlayMode : uint8_t
strong

Playback mode enumeration.

Defines the operating mode of the haptic driver.

Enumerator
STANDBY 

Standby mode, minimal power consumption.

RAM 

RAM playback mode, single play.

RAM_LOOP 

RAM loop mode, continuous playback.

CONT 

Continuous mode with F0 tracking.

RTP 

Real-time playback mode.

Definition at line 78 of file HapticDriver_AW86224.hpp.

◆ PwmMode

enum class HapticDriver_AW86224::PwmMode : uint8_t
strong

PWM mode selection.

Defines the PWM sampling rate for waveform playback.

Enumerator
PWM_48K 

48kHz PWM rate

PWM_24K 

24kHz PWM rate

PWM_12K 

12kHz PWM rate (default)

Definition at line 114 of file HapticDriver_AW86224.hpp.

◆ SramSize

enum class HapticDriver_AW86224::SramSize : uint8_t
strong

SRAM size selection.

Configures the internal SRAM size for waveform storage.

Enumerator
SRAM_1K 

1KB SRAM

SRAM_2K 

2KB SRAM

SRAM_3K 

3KB SRAM

Definition at line 91 of file HapticDriver_AW86224.hpp.

Constructor & Destructor Documentation

◆ HapticDriver_AW86224()

HapticDriver_AW86224::HapticDriver_AW86224 ( )

Default constructor.

Initializes the driver with default parameters. Call begin() before use.

Definition at line 40 of file HapticDriver_AW86224.cpp.

Member Function Documentation

◆ calibrate()

bool HapticDriver_AW86224::calibrate ( )
overridevirtual

Perform auto-calibration.

Returns
true if successful, false otherwise.

Reimplemented from HapticBase.

Definition at line 204 of file HapticDriver_AW86224.cpp.

References HapticBase::_isReady.

◆ clearSequence()

bool HapticDriver_AW86224::clearSequence ( )
overridevirtual

Clear the waveform sequence.

Returns
true if successful, false otherwise.

Reimplemented from HapticBase.

Definition at line 189 of file HapticDriver_AW86224.cpp.

References i, and setWaveSeq().

Referenced by testSetSequence().

◆ continuousVibration()

void HapticDriver_AW86224::continuousVibration ( uint32_t  duration_ms,
bool  blocking = true 
)
overridevirtual

Play a continuous vibration for specified duration.

Default implementation uses playEffect() in a loop. Subclasses should override for optimized continuous mode.

Parameters
duration_msDuration in milliseconds.
blockingIf true, blocks until vibration completes.

Reimplemented from HapticBase.

Definition at line 164 of file HapticDriver_AW86224.cpp.

References longVibration().

Referenced by testAutoDemo(), testContinuousVibration(), and testStop().

◆ end()

void HapticDriver_AW86224::end ( )
overridevirtual

Deinitialize the haptic driver and release resources.

Reimplemented from HapticBase.

Definition at line 71 of file HapticDriver_AW86224.cpp.

References HapticBase::setReady(), and stop().

◆ getActuatorType()

HapticActuatorType HapticDriver_AW86224::getActuatorType ( ) const
overridevirtual

Get the actuator type.

Returns
Current actuator type (ERM or LRA).

Implements HapticBase.

Definition at line 860 of file HapticDriver_AW86224.cpp.

References LRA.

Referenced by testInit().

◆ getAutoBrkEnabled()

bool HapticDriver_AW86224::getAutoBrkEnabled ( ) const
inline

Definition at line 644 of file HapticDriver_AW86224.hpp.

◆ getCapabilities()

◆ getChipID()

uint8_t HapticDriver_AW86224::getChipID ( ) const
overridevirtual

Get the chip ID.

Returns
Chip identifier value.

Implements HapticBase.

Definition at line 924 of file HapticDriver_AW86224.cpp.

Referenced by testInit().

◆ getChipName()

const char * HapticDriver_AW86224::getChipName ( ) const
overridevirtual

Get the chip name.

Returns
Null-terminated string with chip name.

Implements HapticBase.

Definition at line 82 of file HapticDriver_AW86224.cpp.

References AW86214, AW86223, and AW86224.

Referenced by testInit().

◆ getContBrkGain()

uint8_t HapticDriver_AW86224::getContBrkGain ( ) const
inline

Definition at line 540 of file HapticDriver_AW86224.hpp.

◆ getContBrkTime()

uint8_t HapticDriver_AW86224::getContBrkTime ( ) const
inline

Definition at line 527 of file HapticDriver_AW86224.hpp.

◆ getContDrv1Lvl()

uint8_t HapticDriver_AW86224::getContDrv1Lvl ( ) const
inline

Definition at line 553 of file HapticDriver_AW86224.hpp.

◆ getContDrv1Time()

uint8_t HapticDriver_AW86224::getContDrv1Time ( ) const
inline

Definition at line 566 of file HapticDriver_AW86224.hpp.

◆ getContDrv2Time()

uint8_t HapticDriver_AW86224::getContDrv2Time ( ) const
inline

Definition at line 579 of file HapticDriver_AW86224.hpp.

◆ getContTrackMargin()

uint8_t HapticDriver_AW86224::getContTrackMargin ( ) const
inline

Definition at line 592 of file HapticDriver_AW86224.hpp.

◆ getD2sGain()

uint8_t HapticDriver_AW86224::getD2sGain ( ) const
inline

Definition at line 605 of file HapticDriver_AW86224.hpp.

◆ getF0()

uint32_t HapticDriver_AW86224::getF0 ( ) const
overridevirtual

Get the measured resonant frequency (F0).

Returns
F0 in Hz, or 0 if not available.

Reimplemented from HapticBase.

Definition at line 913 of file HapticDriver_AW86224.cpp.

Referenced by loop(), and testInit().

◆ getF0CaliData()

int8_t HapticDriver_AW86224::getF0CaliData ( ) const
inline

Get F0 calibration data.

Returns
Calibration value

Definition at line 475 of file HapticDriver_AW86224.hpp.

Referenced by testInit().

◆ getF0CaliPercent()

uint8_t HapticDriver_AW86224::getF0CaliPercent ( ) const
inline

Definition at line 657 of file HapticDriver_AW86224.hpp.

◆ getF0Pre()

uint32_t HapticDriver_AW86224::getF0Pre ( ) const
inline

Definition at line 501 of file HapticDriver_AW86224.hpp.

◆ getGain()

uint8_t HapticDriver_AW86224::getGain ( ) const
overridevirtual

Get the current gain value.

Returns
Current gain (0x00 to 0xFF), or 0 if unsupported.

Implements HapticBase.

Definition at line 131 of file HapticDriver_AW86224.cpp.

◆ getLraValue()

uint32_t HapticDriver_AW86224::getLraValue ( ) const
inline

Get LRA resistance.

Returns
LRA value

Definition at line 484 of file HapticDriver_AW86224.hpp.

◆ getLraVrms()

uint32_t HapticDriver_AW86224::getLraVrms ( ) const
inline

Definition at line 514 of file HapticDriver_AW86224.hpp.

◆ getMode()

HapticMode HapticDriver_AW86224::getMode ( ) const
overridevirtual

Get the current operating mode.

Returns
Current HapticMode.

Reimplemented from HapticBase.

Definition at line 883 of file HapticDriver_AW86224.cpp.

References AUTO_CALIBRATE, CONT, INTERNAL_TRIGGER, REAL_TIME_PLAYBACK, RTP, STANDBY, and STANDBY.

◆ getPlayMode()

PlayMode HapticDriver_AW86224::getPlayMode ( ) const
inline

Get current play mode.

Returns
PlayMode enum value

Definition at line 466 of file HapticDriver_AW86224.hpp.

◆ getPwmcfg3Prlvl()

uint8_t HapticDriver_AW86224::getPwmcfg3Prlvl ( ) const
inline

Definition at line 631 of file HapticDriver_AW86224.hpp.

◆ getPwmcfg4Prtime()

uint8_t HapticDriver_AW86224::getPwmcfg4Prtime ( ) const
inline

Definition at line 618 of file HapticDriver_AW86224.hpp.

◆ getRamNum()

uint8_t HapticDriver_AW86224::getRamNum ( ) const
inline

Get number of loaded waveforms.

Returns
Waveform count

Definition at line 439 of file HapticDriver_AW86224.hpp.

Referenced by loop(), testAutoDemo(), testInit(), testPlayEffectAll(), and testWaveformSwitching().

◆ getStatus()

HapticStatus HapticDriver_AW86224::getStatus ( ) const
overridevirtual

Get current playback status.

Returns
Current HapticStatus.

Implements HapticBase.

Definition at line 116 of file HapticDriver_AW86224.cpp.

References HapticBase::_isReady, ERROR, IDLE, isPlaying(), PLAYING, STANDBY, and STANDBY.

Referenced by testStatus().

◆ getVbat()

uint32_t HapticDriver_AW86224::getVbat ( )
overridevirtual

Get the battery voltage.

Returns
Voltage in mV, or 0 if unsupported.

Reimplemented from HapticBase.

Definition at line 907 of file HapticDriver_AW86224.cpp.

Referenced by loop(), and testInit().

◆ getVbatValue()

uint32_t HapticDriver_AW86224::getVbatValue ( ) const
inline

Get current voltage reading.

Returns
Voltage in millivolts

Definition at line 457 of file HapticDriver_AW86224.hpp.

◆ isPlaying()

bool HapticDriver_AW86224::isPlaying ( ) const
overridevirtual

Check if haptic is currently playing.

Returns
true if playing, false otherwise.

Implements HapticBase.

Definition at line 124 of file HapticDriver_AW86224.cpp.

References STANDBY.

Referenced by getStatus(), isVibrating(), longVibration(), loop(), playEffectAsync(), shortVibration(), testAutoDemo(), testStop(), testWaveformSwitching(), and vibrationUpdate().

◆ isRamInit()

bool HapticDriver_AW86224::isRamInit ( ) const
inline

Check if RAM is initialized.

Returns
true if RAM data is loaded

Definition at line 448 of file HapticDriver_AW86224.hpp.

◆ isReady()

bool HapticDriver_AW86224::isReady ( ) const
overridevirtual

Check if the driver is initialized and ready.

Returns
true if ready, false otherwise.

Implements HapticBase.

Definition at line 77 of file HapticDriver_AW86224.cpp.

References HapticBase::_isReady.

◆ isVibrating()

bool HapticDriver_AW86224::isVibrating ( ) const
inline

Check if vibration is currently active (alias for isPlaying)

Returns
true if vibration is running, false otherwise

Definition at line 666 of file HapticDriver_AW86224.hpp.

References isPlaying().

◆ loadRamData()

bool HapticDriver_AW86224::loadRamData ( const uint8_t *  data,
uint32_t  len 
)

Load RAM waveform data.

Loads pre-compiled waveform data into the haptic chip's RAM.

Parameters
[in]dataPointer to RAM data array
[in]lenLength of RAM data
Returns
true if successful

Definition at line 767 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, i, and SensorCommWrapper::writeRegBuff().

◆ longVibration()

void HapticDriver_AW86224::longVibration ( uint8_t  index,
uint8_t  gain = 0x80,
uint32_t  duration_ms = 1000,
bool  blocking = true 
)

Play a long continuous vibration effect.

Plays a continuous vibration effect for the specified duration. Supports both blocking and non-blocking modes.

Parameters
[in]indexWaveform index (1-4)
[in]gainVibration intensity (0x00-0xFF)
[in]duration_msDuration in milliseconds
[in]blockingtrue = wait for completion (blocking), false = return immediately (non-blocking)
Blocking Mode Example:
// Wait 2 seconds for vibration to complete
haptic.longVibration(2, 0x80, 2000, true);
// Vibration finished, continue with other code
HapticDriver_AW86224 haptic
void longVibration(uint8_t index, uint8_t gain=0x80, uint32_t duration_ms=1000, bool blocking=true)
Play a long continuous vibration effect.
Non-Blocking Mode Example:
// Start vibration, return immediately
haptic.longVibration(2, 0x80, 5000, false);
// Do other work while vibrating
while (haptic.isPlaying()) {
// Your code here
}
bool isPlaying() const override
Check if haptic is currently playing.
void vibrationUpdate() override
Update vibration state (for non-blocking mode).
Note
In non-blocking mode, call vibrationUpdate() regularly in your loop. If a new vibration is started while one is running, the previous vibration will be stopped automatically.

Definition at line 570 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, isPlaying(), RAM_LOOP, run(), setGain(), setTrimLRA(), softReset(), and stop().

Referenced by continuousVibration(), loop(), testAutoDemo(), testLongVibrationBlocking(), testLongVibrationNonBlocking(), and testWaveformSwitching().

◆ needsCalibration()

bool HapticDriver_AW86224::needsCalibration ( ) const
overridevirtual

Check if calibration is needed.

Returns
true if calibration is required, false otherwise.

Reimplemented from HapticBase.

Definition at line 212 of file HapticDriver_AW86224.cpp.

◆ playEffect()

bool HapticDriver_AW86224::playEffect ( HapticEffectId  effect)
overridevirtual

Play a haptic effect.

This is a blocking call - it returns only after the effect completes. For chips that don't support blocking, use playEffectAsync() instead.

Parameters
effectEffect ID to play (chip-specific mapping).
Returns
true if successful, false otherwise.

Implements HapticBase.

Definition at line 136 of file HapticDriver_AW86224.cpp.

References shortVibration().

Referenced by testAutoDemo(), testPlayEffect(), and testPlayEffectAll().

◆ playEffectAsync()

bool HapticDriver_AW86224::playEffectAsync ( HapticEffectId  effect)
overridevirtual

Play a haptic effect (non-blocking).

Returns immediately; use isPlaying() or vibrationUpdate() to check status.

Parameters
effectEffect ID to play.
Returns
true if started successfully, false otherwise.

Reimplemented from HapticBase.

Definition at line 143 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, isPlaying(), RAM, run(), setGain(), setTrimLRA(), setWaveLoop(), setWaveSeq(), softReset(), and stop().

◆ playRtp()

bool HapticDriver_AW86224::playRtp ( const uint8_t *  data,
uint32_t  len,
uint8_t  gain = 0x80 
)

Play RTP (Real-Time Playback) waveform.

Plays a custom waveform in RTP mode.

Parameters
[in]dataWaveform data buffer
[in]lenData length in bytes
[in]gainPlayback gain (0x00-0xFF)
Returns
true if successful
Example:
uint8_t sineWave[] = {0x00, 0x40, 0x80, 0xC0, 0xFF, ...};
haptic.playRtp(sineWave, sizeof(sineWave), 0x80);
delay(1000);
void stopVibration()
Stop any ongoing vibration.
bool playRtp(const uint8_t *data, uint32_t len, uint8_t gain=0x80)
Play RTP (Real-Time Playback) waveform.

Definition at line 653 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, PWM_24K, RTP, run(), setGain(), setTrimLRA(), SensorCommWrapper::updateBits(), SensorCommWrapper::writeReg(), and SensorCommWrapper::writeRegBuff().

◆ playSequence()

bool HapticDriver_AW86224::playSequence ( )
overridevirtual

Play the waveform sequence.

Returns
true if successful, false otherwise.

Reimplemented from HapticBase.

Definition at line 197 of file HapticDriver_AW86224.cpp.

References RAM, and run().

Referenced by testSetSequence().

◆ run()

bool HapticDriver_AW86224::run ( )
overridevirtual

Start haptic playback.

Returns
true if successful, false otherwise.

Implements HapticBase.

Definition at line 527 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, and SensorCommWrapper::writeReg().

Referenced by longVibration(), playEffectAsync(), playRtp(), playSequence(), shortVibration(), and vibrationUpdate().

◆ setActuatorType()

bool HapticDriver_AW86224::setActuatorType ( HapticActuatorType  type)
overridevirtual

Set the actuator type.

Parameters
typeActuator type to set (ERM or LRA).
Returns
true if successful, false otherwise.

Implements HapticBase.

Definition at line 854 of file HapticDriver_AW86224.cpp.

◆ setAutoBrkEnabled()

void HapticDriver_AW86224::setAutoBrkEnabled ( bool  val)
inline

Enable/disable auto break.

Parameters
[in]valtrue = enabled, false = disabled

Definition at line 640 of file HapticDriver_AW86224.hpp.

◆ setContBrkGain()

void HapticDriver_AW86224::setContBrkGain ( uint8_t  val)
inline

Set continuous mode break gain.

Parameters
[in]valBreak gain value (0x00-0xFF)

Definition at line 536 of file HapticDriver_AW86224.hpp.

◆ setContBrkTime()

void HapticDriver_AW86224::setContBrkTime ( uint8_t  val)
inline

Set continuous mode break time.

Parameters
[in]valBreak time value (0x00-0xFF)

Definition at line 523 of file HapticDriver_AW86224.hpp.

◆ setContDrv1Lvl()

void HapticDriver_AW86224::setContDrv1Lvl ( uint8_t  val)
inline

Set continuous mode drive level 1.

Parameters
[in]valDrive level (0x00-0x7F)

Definition at line 549 of file HapticDriver_AW86224.hpp.

◆ setContDrv1Time()

void HapticDriver_AW86224::setContDrv1Time ( uint8_t  val)
inline

Set continuous mode drive time 1.

Parameters
[in]valDrive time value (0x00-0xFF)

Definition at line 562 of file HapticDriver_AW86224.hpp.

◆ setContDrv2Time()

void HapticDriver_AW86224::setContDrv2Time ( uint8_t  val)
inline

Set continuous mode drive time 2.

Parameters
[in]valDrive time value (0x00-0xFF)

Definition at line 575 of file HapticDriver_AW86224.hpp.

◆ setContTrackMargin()

void HapticDriver_AW86224::setContTrackMargin ( uint8_t  val)
inline

Set continuous mode track margin.

Parameters
[in]valMargin value (0x00-0xFF)

Definition at line 588 of file HapticDriver_AW86224.hpp.

◆ setD2sGain()

void HapticDriver_AW86224::setD2sGain ( uint8_t  val)
inline

Set D2S gain (digital to simulation gain)

Parameters
[in]valGain value (0x00-0x07)

Definition at line 601 of file HapticDriver_AW86224.hpp.

◆ setF0CaliPercent()

void HapticDriver_AW86224::setF0CaliPercent ( uint8_t  val)
inline

Set F0 calibration tolerance percentage.

Parameters
[in]valPercentage (default: 7)

Definition at line 653 of file HapticDriver_AW86224.hpp.

◆ setF0Pre()

void HapticDriver_AW86224::setF0Pre ( uint32_t  val)
inline

Set expected F0 (resonant frequency)

Parameters
[in]valF0 in Hz (default: 1700)

Definition at line 497 of file HapticDriver_AW86224.hpp.

◆ setGain()

bool HapticDriver_AW86224::setGain ( uint8_t  gain)
overridevirtual

Set the gain/amplitude (0x00 to 0xFF).

Parameters
gainGain value.
Returns
true if successful, false otherwise.

Implements HapticBase.

Definition at line 520 of file HapticDriver_AW86224.cpp.

References SensorCommWrapper::writeReg().

Referenced by longVibration(), playEffectAsync(), playRtp(), setRealtimeValue(), shortVibration(), and testContinuousVibration().

◆ setLraVrms()

void HapticDriver_AW86224::setLraVrms ( uint32_t  val)
inline

Set LRA rated voltage.

Parameters
[in]valVoltage in mV (default: 1000)

Definition at line 510 of file HapticDriver_AW86224.hpp.

◆ setMode()

bool HapticDriver_AW86224::setMode ( HapticMode  mode)
overridevirtual

Set the operating mode.

Parameters
modeMode to set.
Returns
true if successful, false otherwise.

Reimplemented from HapticBase.

Definition at line 865 of file HapticDriver_AW86224.cpp.

References INTERNAL_TRIGGER, RAM, REAL_TIME_PLAYBACK, RTP, and STANDBY.

◆ setPins()

void HapticDriver_AW86224::setPins ( uint8_t  resetPin,
uint8_t  intPin 
)

setPins

Note
Sets the reset and interrupt pins for the haptic driver. No support for interrupt pins has been added; they are currently reserved for use as a general interface.
Parameters
[in]resetPinThe GPIO pin number for the reset pin.
[in]intPinThe GPIO pin number for the interrupt pin.
Return values
None

Definition at line 65 of file HapticDriver_AW86224.cpp.

◆ setPlayMode()

void HapticDriver_AW86224::setPlayMode ( PlayMode  mode)

Set playback mode.

Parameters
[in]modePlayback mode (see PlayMode enum)

Definition at line 515 of file HapticDriver_AW86224.cpp.

◆ setPwmcfg3Prlvl()

void HapticDriver_AW86224::setPwmcfg3Prlvl ( uint8_t  val)
inline

Set protection level.

Parameters
[in]valLevel value

Definition at line 627 of file HapticDriver_AW86224.hpp.

◆ setPwmcfg4Prtime()

void HapticDriver_AW86224::setPwmcfg4Prtime ( uint8_t  val)
inline

Set protection time.

Parameters
[in]valTime value

Definition at line 614 of file HapticDriver_AW86224.hpp.

◆ setRealtimeValue()

bool HapticDriver_AW86224::setRealtimeValue ( uint8_t  value)
overridevirtual

Set RTP (real-time playback) value.

Only meaningful when in REAL_TIME_PLAYBACK mode.

Parameters
valueRTP drive value (0x00 to 0xFF).
Returns
true if successful, false otherwise.

Reimplemented from HapticBase.

Definition at line 898 of file HapticDriver_AW86224.cpp.

References RTP, and setGain().

◆ setRtpData()

void HapticDriver_AW86224::setRtpData ( uint8_t *  data,
uint32_t  len 
)

Set RTP waveform data.

Loads waveform data for RTP mode playback.

Parameters
[in]dataPointer to waveform data buffer
[in]lenLength of data in bytes

Definition at line 648 of file HapticDriver_AW86224.cpp.

References SensorCommWrapper::writeRegBuff().

◆ setSequence()

bool HapticDriver_AW86224::setSequence ( uint8_t  slot,
HapticEffectId  effect 
)
overridevirtual

Set a waveform in the sequence.

Parameters
slotSequence slot index (0 to maxSequenceLength-1).
effectEffect ID to play at this slot.
Returns
true if successful, false otherwise.

Reimplemented from HapticBase.

Definition at line 182 of file HapticDriver_AW86224.cpp.

References setWaveSeq().

Referenced by testSetSequence().

◆ setTrimLRA()

void HapticDriver_AW86224::setTrimLRA ( uint8_t  val)

Set LRA frequency trim value.

Used after F0 calibration to optimize vibration.

Parameters
[in]valTrim value from calibration (typically 0x00-0x3F)

Definition at line 417 of file HapticDriver_AW86224.cpp.

References SensorCommWrapper::updateBits().

Referenced by longVibration(), playEffectAsync(), playRtp(), and shortVibration().

◆ setWaveLoop()

void HapticDriver_AW86224::setWaveLoop ( uint8_t  wav,
uint8_t  loop 
)

Set waveform loop count.

Configures how many times a waveform repeats before advancing.

Parameters
[in]wavWave slot (0-7)
[in]loopLoop count (0-15, where 15 = infinite)
Example:
haptic.setWaveLoop(0, 15); // Infinite loop for slot 0
haptic.setWaveLoop(1, 0); // No loop for slot 1
void setWaveLoop(uint8_t wav, uint8_t loop)
Set waveform loop count.

Definition at line 614 of file HapticDriver_AW86224.cpp.

References loop(), and SensorCommWrapper::updateBits().

Referenced by playEffectAsync(), and shortVibration().

◆ setWaveSeq()

void HapticDriver_AW86224::setWaveSeq ( uint8_t  wav,
uint8_t  seq 
)

Update vibration state (for non-blocking mode)

Must be called regularly when using non-blocking vibration modes. This function:

  • Checks if the vibration duration has elapsed
  • Auto-restarts playback if it stops prematurely
  • Stops the vibration when duration is complete
Usage:
void loop() {
if (haptic.isPlaying()) {
}
// Other loop code...
}
void loop()
Note
Call this at least every 10-50ms for smooth vibration.

Set waveform sequence

Configures which waveform is played for each sequencer slot.

Parameters
[in]wavWave slot (0-7)
[in]seqWaveform index to play (0-15)
Example:
haptic.setWaveSeq(0, 2); // Slot 0 plays waveform 2
haptic.setWaveSeq(1, 0); // Slot 1 plays waveform 0 (wait)
void setWaveSeq(uint8_t wav, uint8_t seq)
Update vibration state (for non-blocking mode)

Definition at line 609 of file HapticDriver_AW86224.cpp.

References SensorCommWrapper::writeReg().

Referenced by clearSequence(), playEffectAsync(), setSequence(), and shortVibration().

◆ shortVibration()

void HapticDriver_AW86224::shortVibration ( uint8_t  index,
uint8_t  gain = 0x80,
uint8_t  loop = 1 
)

Play a short vibration effect.

Plays a short haptic effect using a RAM waveform with specified loop count. This is a blocking call that waits for the effect to complete.

Parameters
[in]indexWaveform index (1-4, based on loaded RAM data)
[in]gainVibration intensity (0x00-0xFF, default 0x80)
[in]loopNumber of repetitions (1-16, default 1)
Example:
// Short click
haptic.shortVibration(1, 0x80, 1);
// Double buzz
haptic.shortVibration(2, 0xA0, 2);
// Maximum intensity click
haptic.shortVibration(1, 0xFF, 1);
void shortVibration(uint8_t index, uint8_t gain=0x80, uint8_t loop=1)
Play a short vibration effect.

Definition at line 544 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, isPlaying(), loop(), RAM, run(), setGain(), setTrimLRA(), setWaveLoop(), setWaveSeq(), softReset(), and stop().

Referenced by playEffect(), testAutoDemo(), testIntensitySweep(), testShortVibration(), testShortVibrationGain(), and testShortVibrationLoop().

◆ softReset()

void HapticDriver_AW86224::softReset ( )

Perform soft reset.

Resets the chip to default state via software command. This clears any residual configuration from previous operations.

Definition at line 918 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, and SensorCommWrapper::writeReg().

Referenced by longVibration(), playEffectAsync(), and shortVibration().

◆ stop()

bool HapticDriver_AW86224::stop ( )
overridevirtual

Stop haptic playback immediately.

Returns
true if successful, false otherwise.

Implements HapticBase.

Definition at line 537 of file HapticDriver_AW86224.cpp.

Referenced by end(), longVibration(), playEffectAsync(), shortVibration(), stopVibration(), testAutoDemo(), testStop(), testWaveformSwitching(), and vibrationUpdate().

◆ stopVibration()

void HapticDriver_AW86224::stopVibration ( )

Stop any ongoing vibration.

Immediately stops vibration and enters standby mode. Works for both blocking and non-blocking modes.

Example:
haptic.longVibration(2, 0x80, 10000, false); // Start long vibration
// ...
haptic.stopVibration(); // Immediate stop
}
virtual void emergencyStop()
Emergency stop - stops all vibration immediately.

Definition at line 604 of file HapticDriver_AW86224.cpp.

References stop().

◆ vibrationUpdate()

void HapticDriver_AW86224::vibrationUpdate ( )
overridevirtual

Update vibration state (for non-blocking mode).

Call this periodically in your main loop when using non-blocking vibration functions. Default implementation does nothing.

Reimplemented from HapticBase.

Definition at line 170 of file HapticDriver_AW86224.cpp.

References DeviceBeginCommon::hal, isPlaying(), run(), and stop().

Referenced by loop().


The documentation for this class was generated from the following files: