|
UUtzinger_DRV8704
0.1.1
Arduino library for the DRV8704 dual H-bridge gate driver
|
Arduino-facing DRV8704 device driver class. More...
#include <drv8704.h>
Public Member Functions | |
| bool | applyConfig (const DRV8704Config &config) |
| Apply a high-level configuration snapshot to the device. More... | |
| bool | begin () |
| Initialize GPIO and SPI state for the device. More... | |
| bool | beginPwmMode (const DRV8704PwmConfig &config=DRV8704PwmConfig()) |
| Enable board-specific PWM generation for the DRV8704 input pins. More... | |
| void | brake (BridgeId bridge) |
| Drive one bridge to brake. More... | |
| DRV8704BridgeState | bridgeState (BridgeId bridge) const |
| Return the stored direction/runtime-state report for one bridge. More... | |
| uint16_t | cachedRegister (uint8_t address) const |
| Return the cached contents of a register. More... | |
| bool | clearFault (FaultBit bit) |
| Clear one fault bit in the STATUS register. More... | |
| bool | clearFaults () |
| Clear all clearable fault bits in the STATUS register. More... | |
| void | coast (BridgeId bridge) |
| Drive one bridge to coast. More... | |
| DRV8704CurrentLimitResult | currentLimitResult () const |
| Return the most recent derived chip-global current-limit settings. More... | |
| DRV8704CurrentPresetConfig | currentModePresetConfig () const |
| Return the preset configuration currently selected for current-limit operation. More... | |
| Direction | direction (BridgeId bridge) const |
| Return the configured high-level direction for one bridge. More... | |
| bool | disableCurrentLimit () |
| Disable the high-level current-limit configuration without forcing a bridge-state change. More... | |
| DRV8704 (const DRV8704Pins &pins, SPIClass &spi=SPI) | |
| Construct a DRV8704 device instance. More... | |
| bool | enableBridgeDriver (bool enabled) |
| Enable or disable the bridge driver through the CTRL register. More... | |
| void | end () |
| End driver operation. More... | |
| void | endPwmMode () |
| Disable platform PWM generation and return bridge inputs to coast. More... | |
| bool | hasFault () |
| Check whether any reported fault bit is active. More... | |
| bool | hasFaultPin () const |
Report whether a dedicated FAULTn pin was provided. More... | |
| DRV8704HealthCheck | healthCheck () |
| Perform a minimal transport/status health check. More... | |
| bool | isCurrentLimitEnabled () const |
| Return whether a high-level current limit is currently configured. More... | |
| bool | isFaultPinActive () const |
Read the state of the optional FAULTn pin. More... | |
| bool | isInitialized () const |
| Report whether the driver completed initialization. More... | |
| bool | isPwmModeEnabled () const |
| Return whether PWM mode is currently active. More... | |
| DRV8704PwmCapability | pwmCapability () const |
| Return the resolved capability of the active PWM backend. More... | |
| uint16_t | readRegister (RegisterAddress address) |
| Read a register by symbolic address. More... | |
| uint16_t | readRegister (uint8_t address) |
| Read a 12-bit register payload from the device. More... | |
| DRV8704Status | readStatus () |
| Read and decode the STATUS register. More... | |
| void | reset () |
| Pulse the reset pin when available. More... | |
| bool | setBlankTime (uint8_t blankTime) |
| Set the current blanking time. More... | |
| void | setBridgeMode (BridgeId bridge, BridgeMode mode) |
| Low-level static bridge helper retained for compatibility. More... | |
| bool | setCurrent (BridgeId bridge, Direction direction, float amps) |
| Compatibility overload retained during the control-model refactor. More... | |
| bool | setCurrent (BridgeId bridge, float amps) |
| Program the chip for current drive on one bridge using the stored direction. More... | |
| bool | setCurrentLimit (float amps) |
| Program the chip-global current limit in amperes without changing bridge state. More... | |
| bool | setCurrentModePreset (CurrentModePreset preset) |
| Select the predefined timing and decay preset used by current mode. More... | |
| bool | setDeadTime (DeadTime deadTime) |
| Set the bridge dead time. More... | |
| bool | setDecayMode (DecayMode mode) |
| Set the decay mode. More... | |
| bool | setDecayTime (uint8_t decayTime) |
| Set the mixed-decay transition time. More... | |
| bool | setDirection (BridgeId bridge, Direction direction) |
| Set the direction used by high-level current-drive and PWM-drive commands. More... | |
| bool | setGateDrive (const GateDriveConfig &gateDrive) |
| Apply the complete DRIVE register configuration. More... | |
| bool | setGateDriveCurrents (GateDriveSinkCurrent iDriveN, GateDriveSourceCurrent iDriveP) |
| Set the gate-drive current fields. More... | |
| bool | setGateDriveTimes (GateDriveTime tDriveN, GateDriveTime tDriveP) |
| Set the gate-drive timing fields. More... | |
| bool | setOcpDeglitch (OcpDeglitch deglitch) |
| Set the overcurrent deglitch interval. More... | |
| bool | setOcpThreshold (OcpThreshold threshold) |
| Set the overcurrent threshold. More... | |
| bool | setOffTime (uint8_t offTime) |
| Set the fixed PWM off time. More... | |
| bool | setPwmFrequency (uint32_t frequencyHz) |
| Update the requested PWM frequency. More... | |
| bool | setSenseGain (SenseGain gain) |
| Set the current-sense amplifier gain. More... | |
| bool | setShuntResistance (BridgeId bridge, float ohms) |
| Set the shunt resistance for one bridge in current mode. More... | |
| bool | setShuntResistance (float ohms) |
| Set one shunt resistance value for both bridges in current mode. More... | |
| bool | setSpeed (BridgeId bridge, Direction direction, float speedPercent) |
| Compatibility overload retained during the control-model refactor. More... | |
| bool | setSpeed (BridgeId bridge, float speedPercent) |
| Apply an open-loop speed command to one bridge using hardware PWM. More... | |
| bool | setTorque (uint8_t torque) |
| Set the torque DAC value. More... | |
| void | sleep () |
| Put the DRV8704 into sleep mode when the sleep pin is available. More... | |
| float | smallestDutyIncrementPercent () const |
| Return the smallest duty-percent step of the active PWM backend. More... | |
| bool | syncRegisterCache () |
| Refresh the local register cache from device reads. More... | |
| bool | updateRegister (RegisterAddress address, uint16_t mask, uint16_t value) |
| Update selected register bits using a symbolic address. More... | |
| bool | updateRegister (uint8_t address, uint16_t mask, uint16_t value) |
| Update selected register bits while preserving other bits. More... | |
| void | wake () |
| Bring the DRV8704 out of sleep mode when the sleep pin is available. More... | |
| bool | writeRegister (RegisterAddress address, uint16_t value) |
| Write a register by symbolic address. More... | |
| bool | writeRegister (uint8_t address, uint16_t value) |
| Write a 12-bit register payload to the device. More... | |
Arduino-facing DRV8704 device driver class.
|
explicit |
Construct a DRV8704 device instance.
| pins | Pin assignment bundle for this device. |
| spi | SPI bus instance to use for transfers. |
| bool DRV8704::applyConfig | ( | const DRV8704Config & | config | ) |
Apply a high-level configuration snapshot to the device.
| config | Desired driver configuration. |
| bool DRV8704::begin | ( | ) |
Initialize GPIO and SPI state for the device.
| bool DRV8704::beginPwmMode | ( | const DRV8704PwmConfig & | config = DRV8704PwmConfig() | ) |
Enable board-specific PWM generation for the DRV8704 input pins.
| config | Requested PWM frequency and duty resolution. |
| void DRV8704::brake | ( | BridgeId | bridge | ) |
Drive one bridge to brake.
| bridge | Bridge selector. |
| DRV8704BridgeState DRV8704::bridgeState | ( | BridgeId | bridge | ) | const |
Return the stored direction/runtime-state report for one bridge.
| bridge | Bridge selector. |
| uint16_t DRV8704::cachedRegister | ( | uint8_t | address | ) | const |
Return the cached contents of a register.
| address | Register address. |
| bool DRV8704::clearFault | ( | FaultBit | bit | ) |
Clear one fault bit in the STATUS register.
| bit | Fault bit selector. |
| bool DRV8704::clearFaults | ( | ) |
Clear all clearable fault bits in the STATUS register.
| void DRV8704::coast | ( | BridgeId | bridge | ) |
Drive one bridge to coast.
| bridge | Bridge selector. |
|
inline |
Return the most recent derived chip-global current-limit settings.
|
inline |
Return the preset configuration currently selected for current-limit operation.
Return the configured high-level direction for one bridge.
| bridge | Bridge selector. |
| bool DRV8704::disableCurrentLimit | ( | ) |
Disable the high-level current-limit configuration without forcing a bridge-state change.
The implementation programs the maximum representable current limit and clears the high-level bookkeeping so future PWM-current-limit commands require a deliberate limit request.
| bool DRV8704::enableBridgeDriver | ( | bool | enabled | ) |
Enable or disable the bridge driver through the CTRL register.
| enabled | True to enable bridge drive. |
| void DRV8704::end | ( | ) |
End driver operation.
| void DRV8704::endPwmMode | ( | ) |
Disable platform PWM generation and return bridge inputs to coast.
| bool DRV8704::hasFault | ( | ) |
Check whether any reported fault bit is active.
|
inline |
Report whether a dedicated FAULTn pin was provided.
| DRV8704HealthCheck DRV8704::healthCheck | ( | ) |
Perform a minimal transport/status health check.
|
inline |
Return whether a high-level current limit is currently configured.
| bool DRV8704::isFaultPinActive | ( | ) | const |
Read the state of the optional FAULTn pin.
|
inline |
Report whether the driver completed initialization.
|
inline |
Return whether PWM mode is currently active.
|
inline |
Return the resolved capability of the active PWM backend.
|
inline |
Read a register by symbolic address.
| address | Register address enum. |
| uint16_t DRV8704::readRegister | ( | uint8_t | address | ) |
Read a 12-bit register payload from the device.
| address | Register address. |
| DRV8704Status DRV8704::readStatus | ( | ) |
Read and decode the STATUS register.
| void DRV8704::reset | ( | ) |
Pulse the reset pin when available.
| bool DRV8704::setBlankTime | ( | uint8_t | blankTime | ) |
Set the current blanking time.
| blankTime | BLANK register TBLANK value. |
| void DRV8704::setBridgeMode | ( | BridgeId | bridge, |
| BridgeMode | mode | ||
| ) |
Low-level static bridge helper retained for compatibility.
| bridge | Bridge selector. |
| mode | Static bridge mode. |
Compatibility overload retained during the control-model refactor.
| bridge | Bridge selector. |
| direction | Desired bridge direction. |
| amps | Requested current in amperes. |
| bool DRV8704::setCurrent | ( | BridgeId | bridge, |
| float | amps | ||
| ) |
Program the chip for current drive on one bridge using the stored direction.
| bridge | Bridge selector. |
| amps | Requested current limit in amperes. |
| bool DRV8704::setCurrentLimit | ( | float | amps | ) |
Program the chip-global current limit in amperes without changing bridge state.
| amps | Requested current limit in amperes. |
| bool DRV8704::setCurrentModePreset | ( | CurrentModePreset | preset | ) |
Select the predefined timing and decay preset used by current mode.
| preset | Preset family to apply. |
| bool DRV8704::setDeadTime | ( | DeadTime | deadTime | ) |
Set the bridge dead time.
| deadTime | Desired dead-time setting. |
| bool DRV8704::setDecayMode | ( | DecayMode | mode | ) |
Set the decay mode.
| mode | Desired decay mode. |
| bool DRV8704::setDecayTime | ( | uint8_t | decayTime | ) |
Set the mixed-decay transition time.
| decayTime | DECAY register TDECAY value. |
Set the direction used by high-level current-drive and PWM-drive commands.
| bridge | Bridge selector. |
| direction | Desired bridge direction. |
| bool DRV8704::setGateDrive | ( | const GateDriveConfig & | gateDrive | ) |
Apply the complete DRIVE register configuration.
| gateDrive | Desired gate-drive configuration. |
| bool DRV8704::setGateDriveCurrents | ( | GateDriveSinkCurrent | iDriveN, |
| GateDriveSourceCurrent | iDriveP | ||
| ) |
Set the gate-drive current fields.
| iDriveN | Sink current selection. |
| iDriveP | Source current selection. |
| bool DRV8704::setGateDriveTimes | ( | GateDriveTime | tDriveN, |
| GateDriveTime | tDriveP | ||
| ) |
Set the gate-drive timing fields.
| tDriveN | Sink timing selection. |
| tDriveP | Source timing selection. |
| bool DRV8704::setOcpDeglitch | ( | OcpDeglitch | deglitch | ) |
Set the overcurrent deglitch interval.
| deglitch | Desired OCP deglitch setting. |
| bool DRV8704::setOcpThreshold | ( | OcpThreshold | threshold | ) |
Set the overcurrent threshold.
| threshold | Desired OCP threshold. |
| bool DRV8704::setOffTime | ( | uint8_t | offTime | ) |
Set the fixed PWM off time.
| offTime | OFF register TOFF value. |
| bool DRV8704::setPwmFrequency | ( | uint32_t | frequencyHz | ) |
Update the requested PWM frequency.
| frequencyHz | Requested PWM frequency in hertz. |
| bool DRV8704::setSenseGain | ( | SenseGain | gain | ) |
Set the current-sense amplifier gain.
| gain | Desired sense amplifier gain. |
| bool DRV8704::setShuntResistance | ( | BridgeId | bridge, |
| float | ohms | ||
| ) |
Set the shunt resistance for one bridge in current mode.
| bridge | Bridge selector. |
| ohms | Sense resistor value in ohms. |
| bool DRV8704::setShuntResistance | ( | float | ohms | ) |
Set one shunt resistance value for both bridges in current mode.
| ohms | Sense resistor value in ohms. |
Compatibility overload retained during the control-model refactor.
| bridge | Bridge selector. |
| direction | Desired bridge direction. |
| speedPercent | Open-loop duty request from 0 to 100 percent. |
| bool DRV8704::setSpeed | ( | BridgeId | bridge, |
| float | speedPercent | ||
| ) |
Apply an open-loop speed command to one bridge using hardware PWM.
| bridge | Bridge selector. |
| speedPercent | Open-loop duty request from 0 to 100 percent. |
This is PWM with current limit. A speed of 0 behaves like coast. A speed of 100 forces a constant-on directional input without PWM toggling. Intermediate values apply hardware PWM using the stored bridge direction.
| bool DRV8704::setTorque | ( | uint8_t | torque | ) |
Set the torque DAC value.
| torque | Torque DAC code. |
| void DRV8704::sleep | ( | ) |
Put the DRV8704 into sleep mode when the sleep pin is available.
|
inline |
Return the smallest duty-percent step of the active PWM backend.
| bool DRV8704::syncRegisterCache | ( | ) |
Refresh the local register cache from device reads.
|
inline |
Update selected register bits using a symbolic address.
| address | Register address enum. |
| mask | Bit mask for fields to update. |
| value | New masked field value. |
| bool DRV8704::updateRegister | ( | uint8_t | address, |
| uint16_t | mask, | ||
| uint16_t | value | ||
| ) |
Update selected register bits while preserving other bits.
| address | Register address. |
| mask | Bit mask for fields to update. |
| value | New masked field value. |
| void DRV8704::wake | ( | ) |
Bring the DRV8704 out of sleep mode when the sleep pin is available.
|
inline |
Write a register by symbolic address.
| address | Register address enum. |
| value | Register payload. |
| bool DRV8704::writeRegister | ( | uint8_t | address, |
| uint16_t | value | ||
| ) |
Write a 12-bit register payload to the device.
| address | Register address. |
| value | Register payload. |