30#ifndef COMPONENT_HANDLER_TLE92466ED_HANDLER_H_
31#define COMPONENT_HANDLER_TLE92466ED_HANDLER_H_
39#include "core/hf-core-drivers/external/hf-tle92466ed-driver/inc/tle92466ed.hpp"
40#include "core/hf-core-drivers/external/hf-tle92466ed-driver/inc/tle92466ed_spi_interface.hpp"
41#include "base/BaseSpi.h"
42#include "base/BaseGpio.h"
72 BaseGpio* faultn =
nullptr)
noexcept;
84 tle92466ed::CommResult<void>
Init()
noexcept;
87 tle92466ed::CommResult<void>
Deinit()
noexcept;
95 tle92466ed::CommResult<uint32_t>
Transfer32(uint32_t tx_data)
noexcept;
106 tle92466ed::CommResult<void>
TransferMulti(std::span<const uint32_t> tx_data,
107 std::span<uint32_t> rx_data)
noexcept;
114 tle92466ed::CommResult<void>
TransferMulti(std::span<const uint32_t> tx_data,
115 std::span<uint32_t> rx_data,
116 uint32_t gap_us)
noexcept;
119 tle92466ed::CommResult<void>
Delay(uint32_t microseconds)
noexcept;
122 tle92466ed::CommResult<void>
Configure(
const tle92466ed::SPIConfig& config)
noexcept;
125 [[nodiscard]]
bool IsReady()
const noexcept;
128 [[nodiscard]] tle92466ed::CommError
GetLastError()
const noexcept;
131 tle92466ed::CommResult<void>
ClearErrors()
noexcept;
138 tle92466ed::CommResult<void>
GpioSet(tle92466ed::CtrlPin pin,
139 tle92466ed::GpioSignal signal)
noexcept;
145 tle92466ed::CommResult<tle92466ed::GpioSignal>
GpioRead(tle92466ed::CtrlPin pin)
noexcept;
148 void Log(tle92466ed::LogLevel level,
const char* tag,
149 const char* format, va_list args)
noexcept;
217 BaseGpio* faultn =
nullptr) noexcept;
241 tle92466ed::DriverResult<
void>
Initialize(
bool perform_hardware_reset = true) noexcept;
262 tle92466ed::DriverResult<
void>
Initialize(const tle92466ed::GlobalConfig& config) noexcept;
284 tle92466ed::DriverResult<void>
ConfigureChannel(uint8_t channel,
const tle92466ed::ChannelConfig& config)
noexcept;
290 tle92466ed::DriverResult<void>
EnableChannel(uint8_t channel)
noexcept;
296 tle92466ed::DriverResult<void>
DisableChannel(uint8_t channel)
noexcept;
309 tle92466ed::DriverResult<
void>
SetChannelCurrent(uint8_t channel, uint16_t current_ma) noexcept;
316 tle92466ed::DriverResult<
void>
SetChannelCurrentUa(uint8_t channel, uint32_t current_ua) noexcept;
325 uint8_t channel,
bool parallel_mode = false) noexcept;
334 tle92466ed::DriverResult<
void>
ConfigurePwmRaw(uint8_t channel, uint8_t mantissa,
335 uint8_t exponent,
bool low_freq_range = false) noexcept;
403 tle92466ed::DriverResult<
void>
GetStatus(tle92466ed::DeviceStatus& status) noexcept;
411 tle92466ed::DriverResult<
void>
GetChannelDiagnostics(uint8_t channel, tle92466ed::ChannelDiagnostics& diag) noexcept;
417 tle92466ed::DriverResult<
void>
GetFaultReport(tle92466ed::FaultReport& report) noexcept;
420 tle92466ed::DriverResult<
void>
ClearFaults() noexcept;
426 [[nodiscard]]
bool HasFault() noexcept;
436 tle92466ed::DriverResult<
void>
KickWatchdog(uint16_t reload_value = 1000) noexcept;
488 std::span<uint32_t> rx,
489 uint32_t gap_us = 0U)
noexcept {
490 MutexLockGuard lock(
mutex_);
494 return comm_->TransferMulti(tx, rx, gap_us).has_value();
511 template <
typename Fn>
513 MutexLockGuard lock(
mutex_);
514 return std::forward<Fn>(fn)();
540 template <
typename Fn>
542 using R = std::invoke_result_t<Fn, DriverType&>;
543 if constexpr (std::is_void_v<R>) {
544 MutexLockGuard lock(
mutex_);
574 tle92466ed::DriverResult<
void>
InitializeLocked(
bool perform_hardware_reset) noexcept;
578 template <typename T>
580 template <
typename T>
590 template <
typename Fn>
592 using R = std::invoke_result_t<Fn, DriverType&>;
593 static_assert(!std::is_void_v<R>,
"withDriver requires non-void return");
594 MutexLockGuard lock(
mutex_);
597 return R{tle::unexpected(tle92466ed::DriverError::NotInitialized)};
606 std::unique_ptr<HalSpiTle92466edComm>
comm_;
CRTP SPI communication adapter for TLE92466ED using BaseSpi and BaseGpio.
Definition Tle92466edHandler.h:62
tle92466ed::CommResult< void > TransferMulti(std::span< const uint32_t > tx_data, std::span< uint32_t > rx_data) noexcept
Pipelined multi-frame SPI transfer under one SPI2 bus lock.
Definition Tle92466edHandler.cpp:135
tle92466ed::CommResult< tle92466ed::GpioSignal > GpioRead(tle92466ed::CtrlPin pin) noexcept
Read RESN, EN, or FAULTN logical state.
Definition Tle92466edHandler.cpp:281
uint32_t LastRxWordFirst() const noexcept
RX word from the FIRST frame of the last TransferMulti chain.
Definition Tle92466edHandler.h:162
uint32_t last_rx_first_
Definition Tle92466edHandler.h:174
BaseGpio & resn_
Definition Tle92466edHandler.h:168
tle92466ed::CommError last_error_
Definition Tle92466edHandler.h:172
tle92466ed::CommResult< void > Deinit() noexcept
Mark adapter deinitialized; does not change GPIO or SPI state.
Definition Tle92466edHandler.cpp:93
tle92466ed::CommResult< void > Init() noexcept
Reset pulse, assert EN, then SPI identity / fault clear.
Definition Tle92466edHandler.cpp:47
tle92466ed::CommResult< void > GpioSet(tle92466ed::CtrlPin pin, tle92466ed::GpioSignal signal) noexcept
Drive RESN, EN, or FAULTN via configured BaseGpio active levels.
Definition Tle92466edHandler.cpp:240
bool initialized_
Definition Tle92466edHandler.h:171
uint32_t LastRxWord() const noexcept
Last 32-bit SPI RX word (bring-up / WrongDeviceID diagnostics).
Definition Tle92466edHandler.h:152
BaseGpio * faultn_
Definition Tle92466edHandler.h:170
tle92466ed::CommResult< uint32_t > Transfer32(uint32_t tx_data) noexcept
Single 32-bit SPI frame (Mode 1, MSB first).
Definition Tle92466edHandler.cpp:99
tle92466ed::CommError GetLastError() const noexcept
Last comm-layer error from Transfer32 or GPIO helpers.
Definition Tle92466edHandler.cpp:231
bool IsReady() const noexcept
True after Init succeeded (GPIO polarity parked, SPI ready).
Definition Tle92466edHandler.cpp:227
tle92466ed::CommResult< void > Configure(const tle92466ed::SPIConfig &config) noexcept
No-op; BaseSpi is pre-configured for Mode 1 / 32-bit frames.
Definition Tle92466edHandler.cpp:221
tle92466ed::CommResult< void > Delay(uint32_t microseconds) noexcept
Busy-wait delay in microseconds (datasheet timing gaps).
Definition Tle92466edHandler.cpp:216
BaseSpi & spi_
Definition Tle92466edHandler.h:167
BaseGpio & en_
Definition Tle92466edHandler.h:169
void Log(tle92466ed::LogLevel level, const char *tag, const char *format, va_list args) noexcept
Route driver log lines to the HAL Logger.
Definition Tle92466edHandler.cpp:316
uint32_t last_rx_
Definition Tle92466edHandler.h:173
tle92466ed::CommResult< void > ClearErrors() noexcept
Clear last_error_; does not clear chip fault registers.
Definition Tle92466edHandler.cpp:235
Unified handler for TLE92466ED six-channel solenoid driver.
Definition Tle92466edHandler.h:197
uint32_t LastSpiRxWord() const noexcept
Last SPI RX word from HalSpiTle92466edComm (init / WrongDeviceID diag).
Definition Tle92466edHandler.h:458
tle92466ed::DriverResult< void > GetStatus(tle92466ed::DeviceStatus &status) noexcept
Read global device status (mode, rail voltages, OT flags, …).
Definition Tle92466edHandler.cpp:556
std::unique_ptr< DriverType > driver_
Definition Tle92466edHandler.h:607
uint32_t GetIcVersion() noexcept
Read IC version register (ICVID).
Definition Tle92466edHandler.cpp:615
tle92466ed::DriverResult< void > EnterConfigMode() noexcept
Enter config mode so register writes are accepted.
Definition Tle92466edHandler.cpp:544
bool EnsureInitialized() noexcept
Lazy-init entrypoint: initialize on first use if needed.
Definition Tle92466edHandler.cpp:381
tle92466ed::DriverResult< void > KickWatchdog(uint16_t reload_value=1000) noexcept
Reload the SPI watchdog (must be kicked periodically in mission mode).
Definition Tle92466edHandler.cpp:600
tle92466ed::DriverResult< void > EnableAllChannels() noexcept
Set CH_CTRL enable for every channel.
Definition Tle92466edHandler.cpp:472
tle92466ed::DriverResult< void > EnableChannel(uint8_t channel) noexcept
Enable a channel in CH_CTRL (requires EnableOutputStage for load current).
Definition Tle92466edHandler.cpp:456
tle92466ed::Driver< HalSpiTle92466edComm > DriverType
Driver type alias (tle92466ed::Driver bound to HalSpiTle92466edComm).
Definition Tle92466edHandler.h:200
tle92466ed::DriverResult< void > DisableChannel(uint8_t channel) noexcept
Disable a channel in CH_CTRL.
Definition Tle92466edHandler.cpp:464
tle92466ed::DriverResult< void > GetChannelDiagnostics(uint8_t channel, tle92466ed::ChannelDiagnostics &diag) noexcept
Read per-channel diagnostics (faults, FB_I_AVG, duty cycle, …).
Definition Tle92466edHandler.cpp:565
tle92466ed::DriverResult< uint16_t > GetChannelCurrentSetpoint(uint8_t channel, bool parallel_mode=false) noexcept
Read back programmed current setpoint for SW-HAL-01 verification.
Definition Tle92466edHandler.cpp:500
bool RawSpiChain(std::span< const uint32_t > tx, std::span< uint32_t > rx, uint32_t gap_us=0U) noexcept
Clock tx out as one bus-ownership chain and capture every reply.
Definition Tle92466edHandler.h:487
uint32_t GetChipId() noexcept
Read combined chip ID words for identity checks.
Definition Tle92466edHandler.cpp:606
tle92466ed::DriverResult< void > SetChannelCurrent(uint8_t channel, uint16_t current_ma) noexcept
Set channel current setpoint.
Definition Tle92466edHandler.cpp:484
uint32_t LastSpiRxWordFirst() const noexcept
RX word from the first frame of the last pipelined SPI chain.
Definition Tle92466edHandler.h:466
bool EnsureInitializedLocked() noexcept
Definition Tle92466edHandler.cpp:421
bool IsMissionMode() noexcept
true when the device is in mission (non-config) mode.
Definition Tle92466edHandler.cpp:550
tle92466ed::DriverResult< void > DisableOutputStage() noexcept
Drive the chip's EN pin LOW to gate off the output stage. SPI access remains functional; only the low...
Definition Tle92466edHandler.cpp:531
bool initialized_
Definition Tle92466edHandler.h:604
std::unique_ptr< HalSpiTle92466edComm > comm_
Definition Tle92466edHandler.h:606
tle92466ed::DriverResult< void > Deinitialize() noexcept
Disable all channels and tear down driver_.
Definition Tle92466edHandler.cpp:433
tle92466ed::DriverResult< void > InitializeLocked(bool perform_hardware_reset) noexcept
Initialize while mutex_ is already held.
Definition Tle92466edHandler.cpp:354
tle92466ed::DriverResult< void > ConfigurePwmRaw(uint8_t channel, uint8_t mantissa, uint8_t exponent, bool low_freq_range=false) noexcept
Configure raw TP_MANT / TP_EXP PWM period fields.
Definition Tle92466edHandler.cpp:509
tle92466ed::DriverResult< void > ClearFaults() noexcept
Clear latched fault registers after the fault condition is removed.
Definition Tle92466edHandler.cpp:586
bool HasFault() noexcept
Check if any fault is present.
Definition Tle92466edHandler.cpp:592
tle92466ed::DriverResult< void > ConfigureChannel(uint8_t channel, const tle92466ed::ChannelConfig &config) noexcept
Configure a channel (PWM, dither, current limit, …).
Definition Tle92466edHandler.cpp:447
tle92466ed::DriverResult< void > DisableAllChannels() noexcept
Clear CH_CTRL enable for every channel.
Definition Tle92466edHandler.cpp:478
auto WithLock(Fn &&fn) noexcept
Run fn (no arguments) while mutex_ is held.
Definition Tle92466edHandler.h:512
tle92466ed::DriverResult< void > Initialize(bool perform_hardware_reset=true) noexcept
Initialize driver (hardware reset + SPI init + config mode).
Definition Tle92466edHandler.cpp:348
tle92466ed::DriverResult< void > EnableFeedbackUpdates() noexcept
Clear the FB_FRZ register so the chip updates FB_DC / FB_I_AVG / FB_VBAT on every channel.
Definition Tle92466edHandler.cpp:537
auto WithDriver(Fn &&fn) noexcept
Run fn against the raw driver with mutex_ held.
Definition Tle92466edHandler.h:541
DriverType * GetDriver() noexcept
Get the underlying driver for advanced operations.
Definition Tle92466edHandler.cpp:623
static constexpr uint8_t kNumChannels
Number of solenoid channels (0–5); only CH5 is populated on this board.
Definition Tle92466edHandler.h:203
tle92466ed::DriverResult< void > EnableOutputStage() noexcept
Drive the chip's hardware EN pin HIGH so the output stage can deliver current to the load.
Definition Tle92466edHandler.cpp:525
bool IsInitialized() const noexcept
true after a successful Initialize or lazy EnsureInitialized.
Definition Tle92466edHandler.h:272
tle92466ed::DriverResult< void > EnterMissionMode() noexcept
Enter mission mode after configuration (required before driving loads).
Definition Tle92466edHandler.cpp:519
auto withDriver(Fn &&fn) noexcept
Execute a lambda with a locked, initialized driver.
Definition Tle92466edHandler.h:591
RtosMutex mutex_
Definition Tle92466edHandler.h:605
tle92466ed::DriverResult< void > SetChannelCurrentUa(uint8_t channel, uint32_t current_ua) noexcept
Set channel ICC setpoint in microamperes (15-bit TARGET resolution, ~61 µA LSB).
Definition Tle92466edHandler.cpp:492
void DumpDiagnostics() noexcept
Log device status, per-channel diagnostics, and chip ID to Logger.
Definition Tle92466edHandler.cpp:639
tle92466ed::DriverResult< void > GetFaultReport(tle92466ed::FaultReport &report) noexcept
Aggregate fault snapshot across device and all channels.
Definition Tle92466edHandler.cpp:577
Type trait to detect tle92466ed::DriverResult<T> types.
Definition Tle92466edHandler.h:579