TLE92466ED Driver 0.1.0-preview
Modern C++23 driver for Infineon TLE92466ED Six-Channel Low-Side Solenoid Driver
Loading...
Searching...
No Matches
TLE92466ED.hpp
Go to the documentation of this file.
1
72#ifndef TLE92466ED_HPP
73#define TLE92466ED_HPP
74
75#include "TLE92466ED_HAL.hpp"
77#include <expected>
78#include <array>
79
80namespace TLE92466ED {
81
102
106template<typename T>
107using DriverResult = std::expected<T, DriverError>;
108
130
135 bool config_mode{true};
136 bool init_done{false};
137 bool any_fault{false};
138
139 // Supply voltage faults
140 bool vbat_uv{false};
141 bool vbat_ov{false};
142 bool vio_uv{false};
143 bool vio_ov{false};
144 bool vdd_uv{false};
145 bool vdd_ov{false};
146
147 // Temperature
148 bool ot_warning{false};
149 bool ot_error{false};
150
151 // Other faults
152 bool clock_fault{false};
153 bool spi_wd_error{false};
154 bool por_event{false};
155 bool reset_event{false};
156
157 // Internal diagnostics
160
161 // Voltage readings
162 uint16_t vbat_voltage{0};
163 uint16_t vio_voltage{0};
164};
165
170 // Error flags
171 bool overcurrent{false};
172 bool short_to_ground{false};
173 bool open_load{false};
174 bool over_temperature{false};
176
177 // Warning flags
178 bool ot_warning{false};
181 bool olsg_warning{false};
182
183 // Measurements
184 uint16_t average_current{0};
185 uint16_t duty_cycle{0};
186 uint16_t min_current{0};
187 uint16_t max_current{0};
188 uint16_t vbat_feedback{0};
189};
190
195 bool crc_enabled{true};
198 bool vio_5v{false};
199 uint8_t vbat_uv_threshold{25};
200 uint8_t vbat_ov_threshold{255};
201 uint16_t spi_watchdog_reload{1000};
202};
203
231class Driver {
232public:
241 explicit Driver(HAL& hal) noexcept : hal_(hal), initialized_(false), mission_mode_(false) {}
242
246 ~Driver() noexcept {
247 if (initialized_) {
248 // Best effort shutdown - ignore errors
249 (void)disable_all_channels();
250 }
251 }
252
253 // Prevent copying
254 Driver(const Driver&) = delete;
255 Driver& operator=(const Driver&) = delete;
256
257 // Delete move operations (contains reference member)
258 Driver(Driver&&) noexcept = delete;
259 Driver& operator=(Driver&&) noexcept = delete;
260
261 //==========================================================================
262 // INITIALIZATION AND MODE CONTROL
263 //==========================================================================
264
283 [[nodiscard]] DriverResult<void> init() noexcept;
284
296 [[nodiscard]] DriverResult<void> enter_mission_mode() noexcept;
297
307 [[nodiscard]] DriverResult<void> enter_config_mode() noexcept;
308
313 [[nodiscard]] bool is_mission_mode() const noexcept {
314 return mission_mode_;
315 }
316
317 //==========================================================================
318 // GLOBAL CONFIGURATION
319 //==========================================================================
320
329 [[nodiscard]] DriverResult<void> configure_global(const GlobalConfig& config) noexcept;
330
337 [[nodiscard]] DriverResult<void> set_crc_enabled(bool enabled) noexcept;
338
346 [[nodiscard]] DriverResult<void> set_vbat_thresholds(uint8_t uv_threshold, uint8_t ov_threshold) noexcept;
347
348 //==========================================================================
349 // CHANNEL CONTROL
350 //==========================================================================
351
360 [[nodiscard]] DriverResult<void> enable_channel(Channel channel, bool enabled) noexcept;
361
368 [[nodiscard]] DriverResult<void> enable_channels(uint8_t channel_mask) noexcept;
369
373 [[nodiscard]] DriverResult<void> enable_all_channels() noexcept;
374
378 [[nodiscard]] DriverResult<void> disable_all_channels() noexcept;
379
388 [[nodiscard]] DriverResult<void> set_channel_mode(Channel channel, ChannelMode mode) noexcept;
389
398 [[nodiscard]] DriverResult<void> set_parallel_operation(ParallelPair pair, bool enabled) noexcept;
399
400 //==========================================================================
401 // CURRENT CONTROL (ICC MODE)
402 //==========================================================================
403
423 [[nodiscard]] DriverResult<void> set_current_setpoint(
424 Channel channel,
425 uint16_t current_ma,
426 bool parallel_mode = false) noexcept;
427
435 [[nodiscard]] DriverResult<uint16_t> get_current_setpoint(
436 Channel channel,
437 bool parallel_mode = false) noexcept;
438
451 [[nodiscard]] DriverResult<void> configure_pwm_period(
452 Channel channel,
453 uint8_t period_mantissa,
454 uint8_t period_exponent,
455 bool low_freq_range = false) noexcept;
456
466 [[nodiscard]] DriverResult<void> configure_dither(
467 Channel channel,
468 uint16_t step_size,
469 uint8_t num_steps,
470 uint8_t flat_steps) noexcept;
471
479 [[nodiscard]] DriverResult<void> configure_channel(
480 Channel channel,
481 const ChannelConfig& config) noexcept;
482
483 //==========================================================================
484 // STATUS AND DIAGNOSTICS
485 //==========================================================================
486
492 [[nodiscard]] DriverResult<DeviceStatus> get_device_status() noexcept;
493
500 [[nodiscard]] DriverResult<ChannelDiagnostics> get_channel_diagnostics(Channel channel) noexcept;
501
509 [[nodiscard]] DriverResult<uint16_t> get_average_current(
510 Channel channel,
511 bool parallel_mode = false) noexcept;
512
519 [[nodiscard]] DriverResult<uint16_t> get_duty_cycle(Channel channel) noexcept;
520
526 [[nodiscard]] DriverResult<uint16_t> get_vbat_voltage() noexcept;
527
533 [[nodiscard]] DriverResult<uint16_t> get_vio_voltage() noexcept;
534
535 //==========================================================================
536 // FAULT MANAGEMENT
537 //==========================================================================
538
547 [[nodiscard]] DriverResult<void> clear_faults() noexcept;
548
554 [[nodiscard]] DriverResult<bool> has_any_fault() noexcept;
555
564 [[nodiscard]] DriverResult<void> software_reset() noexcept;
565
566 //==========================================================================
567 // WATCHDOG MANAGEMENT
568 //==========================================================================
569
580 [[nodiscard]] DriverResult<void> reload_spi_watchdog(uint16_t reload_value) noexcept;
581
582 //==========================================================================
583 // DEVICE INFORMATION
584 //==========================================================================
585
591 [[nodiscard]] DriverResult<uint16_t> get_ic_version() noexcept;
592
598 [[nodiscard]] DriverResult<std::array<uint16_t, 3>> get_chip_id() noexcept;
599
605 [[nodiscard]] DriverResult<bool> verify_device() noexcept;
606
612 [[nodiscard]] bool is_initialized() const noexcept {
613 return initialized_;
614 }
615
616 //==========================================================================
617 // REGISTER ACCESS (Advanced)
618 //==========================================================================
619
628 uint16_t address,
629 bool verify_crc = true) noexcept;
630
639 [[nodiscard]] DriverResult<void> write_register(
640 uint16_t address,
641 uint16_t value,
642 bool verify_crc = true) noexcept;
643
652 [[nodiscard]] DriverResult<void> modify_register(
653 uint16_t address,
654 uint16_t mask,
655 uint16_t value) noexcept;
656
657private:
658 //==========================================================================
659 // PRIVATE METHODS
660 //==========================================================================
661
665 [[nodiscard]] DriverResult<SPIFrame> transfer_frame(const SPIFrame& tx_frame, bool verify_crc = true) noexcept;
666
670 [[nodiscard]] constexpr bool is_valid_channel_internal(Channel channel) const noexcept {
671 return is_valid_channel(channel);
672 }
673
677 [[nodiscard]] DriverResult<void> check_initialized() const noexcept {
678 if (!initialized_) {
679 return std::unexpected(DriverError::NotInitialized);
680 }
681 return {};
682 }
683
687 [[nodiscard]] DriverResult<void> check_mission_mode() const noexcept {
688 if (!mission_mode_) {
689 return std::unexpected(DriverError::WrongMode);
690 }
691 return {};
692 }
693
697 [[nodiscard]] DriverResult<void> check_config_mode() const noexcept {
698 if (mission_mode_) {
699 return std::unexpected(DriverError::WrongMode);
700 }
701 return {};
702 }
703
707 [[nodiscard]] DriverResult<void> apply_default_config() noexcept;
708
712 [[nodiscard]] DriverResult<void> check_spi_status(const SPIFrame& rx_frame) noexcept;
713
719 [[nodiscard]] DriverResult<bool> is_channel_parallel(Channel channel) noexcept;
720
721 //==========================================================================
722 // MEMBER VARIABLES
723 //==========================================================================
724
729 std::array<uint16_t, 6> channel_setpoints_;
730};
731
732} // namespace TLE92466ED
733
734#endif // TLE92466ED_HPP
Hardware Abstraction Layer (HAL) base class for TLE92466ED driver.
Register definitions and bit field mappings for TLE92466ED IC.
Main TLE92466ED driver class.
Definition TLE92466ED.hpp:231
std::array< uint16_t, 6 > channel_setpoints_
Cached current setpoints.
Definition TLE92466ED.hpp:729
bool is_initialized() const noexcept
Check if driver is initialized.
Definition TLE92466ED.hpp:612
DriverResult< SPIFrame > transfer_frame(const SPIFrame &tx_frame, bool verify_crc=true) noexcept
Transfer SPI frame with CRC calculation and verification.
Definition TLE92466ED.cpp:890
DriverResult< void > enable_channel(Channel channel, bool enabled) noexcept
Enable or disable a channel.
Definition TLE92466ED.cpp:216
DriverResult< uint16_t > get_average_current(Channel channel, bool parallel_mode=false) noexcept
Get average current for a channel.
Definition TLE92466ED.cpp:638
DriverResult< uint16_t > get_vio_voltage() noexcept
Get VIO voltage
Definition TLE92466ED.cpp:687
DriverResult< void > configure_dither(Channel channel, uint16_t step_size, uint8_t num_steps, uint8_t flat_steps) noexcept
Configure dither parameters.
Definition TLE92466ED.cpp:396
DriverResult< void > disable_all_channels() noexcept
Disable all channels.
Definition TLE92466ED.cpp:261
DriverResult< std::array< uint16_t, 3 > > get_chip_id() noexcept
Read unique chip ID.
Definition TLE92466ED.cpp:775
DriverResult< void > check_config_mode() const noexcept
Check if in config mode.
Definition TLE92466ED.hpp:697
DriverResult< void > configure_pwm_period(Channel channel, uint8_t period_mantissa, uint8_t period_exponent, bool low_freq_range=false) noexcept
Configure PWM parameters for ICC.
Definition TLE92466ED.cpp:373
DriverResult< ChannelDiagnostics > get_channel_diagnostics(Channel channel) noexcept
Get channel diagnostic information.
Definition TLE92466ED.cpp:575
Driver(HAL &hal) noexcept
Construct driver with HAL interface.
Definition TLE92466ED.hpp:241
DriverResult< void > modify_register(uint16_t address, uint16_t mask, uint16_t value) noexcept
Modify register bits.
Definition TLE92466ED.cpp:868
Driver(const Driver &)=delete
DriverResult< uint16_t > get_ic_version() noexcept
Read IC version and ID.
Definition TLE92466ED.cpp:767
DriverResult< bool > verify_device() noexcept
Verify device ID matches expected value.
Definition TLE92466ED.cpp:803
bool is_mission_mode() const noexcept
Check if in mission mode.
Definition TLE92466ED.hpp:313
DriverResult< void > enable_channels(uint8_t channel_mask) noexcept
Enable or disable multiple channels.
Definition TLE92466ED.cpp:241
DriverResult< void > reload_spi_watchdog(uint16_t reload_value) noexcept
Reload SPI watchdog counter.
Definition TLE92466ED.cpp:755
DriverResult< void > enter_mission_mode() noexcept
Enter Mission Mode (enables channel control)
Definition TLE92466ED.cpp:119
DriverResult< DeviceStatus > get_device_status() noexcept
Get global device status.
Definition TLE92466ED.cpp:517
DriverResult< void > enable_all_channels() noexcept
Enable all channels.
Definition TLE92466ED.cpp:257
DriverResult< void > init() noexcept
Initialize the driver and hardware.
Definition TLE92466ED.cpp:25
DriverResult< void > clear_faults() noexcept
Clear all fault flags.
Definition TLE92466ED.cpp:704
DriverResult< void > check_spi_status(const SPIFrame &rx_frame) noexcept
Parse SPI status from reply frame.
Definition TLE92466ED.cpp:926
DriverResult< void > configure_global(const GlobalConfig &config) noexcept
Configure global device settings.
Definition TLE92466ED.cpp:155
DriverResult< void > set_crc_enabled(bool enabled) noexcept
Enable/disable CRC checking.
Definition TLE92466ED.cpp:193
DriverResult< void > enter_config_mode() noexcept
Enter Config Mode (allows configuration changes)
Definition TLE92466ED.cpp:135
DriverResult< uint16_t > get_vbat_voltage() noexcept
Get VBAT voltage.
Definition TLE92466ED.cpp:672
DriverResult< void > apply_default_config() noexcept
Apply default configuration after initialization.
Definition TLE92466ED.cpp:66
DriverResult< uint16_t > get_duty_cycle(Channel channel) noexcept
Get PWM duty cycle for a channel.
Definition TLE92466ED.cpp:659
DriverResult< void > check_initialized() const noexcept
Check if driver is initialized.
Definition TLE92466ED.hpp:677
HAL & hal_
Hardware abstraction layer.
Definition TLE92466ED.hpp:725
DriverResult< void > check_mission_mode() const noexcept
Check if in mission mode.
Definition TLE92466ED.hpp:687
DriverResult< bool > has_any_fault() noexcept
Check if any fault exists.
Definition TLE92466ED.cpp:727
DriverResult< void > set_parallel_operation(ParallelPair pair, bool enabled) noexcept
Configure channel for parallel operation.
Definition TLE92466ED.cpp:283
DriverResult< bool > is_channel_parallel(Channel channel) noexcept
Check if channel is currently in parallel mode.
Definition TLE92466ED.cpp:945
bool initialized_
Initialization status.
Definition TLE92466ED.hpp:726
bool mission_mode_
Mission mode flag (vs config mode)
Definition TLE92466ED.hpp:727
~Driver() noexcept
Destructor - ensures clean shutdown.
Definition TLE92466ED.hpp:246
DriverResult< void > configure_channel(Channel channel, const ChannelConfig &config) noexcept
Configure channel slew rate and diagnostics.
Definition TLE92466ED.cpp:427
Driver(Driver &&) noexcept=delete
DriverResult< uint16_t > get_current_setpoint(Channel channel, bool parallel_mode=false) noexcept
Get current setpoint for channel.
Definition TLE92466ED.cpp:347
DriverResult< void > set_channel_mode(Channel channel, ChannelMode mode) noexcept
Set channel operation mode.
Definition TLE92466ED.cpp:265
constexpr bool is_valid_channel_internal(Channel channel) const noexcept
Validate channel number.
Definition TLE92466ED.hpp:670
DriverResult< void > set_current_setpoint(Channel channel, uint16_t current_ma, bool parallel_mode=false) noexcept
Set current setpoint for channel.
Definition TLE92466ED.cpp:315
uint16_t channel_enable_cache_
Cached channel enable state.
Definition TLE92466ED.hpp:728
DriverResult< void > set_vbat_thresholds(uint8_t uv_threshold, uint8_t ov_threshold) noexcept
Configure VBAT under/overvoltage thresholds.
Definition TLE92466ED.cpp:203
DriverResult< void > software_reset() noexcept
Software reset of the device.
Definition TLE92466ED.cpp:736
DriverResult< uint16_t > read_register(uint16_t address, bool verify_crc=true) noexcept
Read 16-bit register.
Definition TLE92466ED.cpp:826
DriverResult< void > write_register(uint16_t address, uint16_t value, bool verify_crc=true) noexcept
Write 16-bit register.
Definition TLE92466ED.cpp:848
Driver & operator=(const Driver &)=delete
Abstract Hardware Abstraction Layer (HAL) base class.
Definition TLE92466ED_HAL.hpp:124
Definition TLE92466ED.hpp:80
ChannelMode
Channel operation mode.
Definition TLE92466ED_Registers.hpp:754
@ ICC
Integrated Current Control.
constexpr bool is_valid_channel(Channel ch) noexcept
Validate channel number.
Definition TLE92466ED_Registers.hpp:826
std::expected< T, DriverError > DriverResult
Driver result type using std::expected.
Definition TLE92466ED.hpp:107
DriverError
Driver error codes.
Definition TLE92466ED.hpp:85
@ ConfigurationError
Configuration failed.
@ FaultDetected
Device fault detected.
@ RegisterError
Register read/write error.
@ SPIFrameError
SPI frame error from device.
@ DeviceNotResponding
Device not responding to SPI.
@ TimeoutError
Operation timeout.
@ HardwareError
HAL communication error.
@ InvalidParameter
Invalid parameter value.
@ WrongDeviceID
Incorrect device ID read.
@ CRCError
CRC mismatch in SPI communication.
@ InvalidChannel
Invalid channel number.
@ NotInitialized
Driver not initialized.
@ WriteToReadOnly
Attempted write to read-only register.
@ WrongMode
Operation not allowed in current mode.
Channel
Channel enumeration.
Definition TLE92466ED_Registers.hpp:740
ParallelPair
Parallel operation pairs.
Definition TLE92466ED_Registers.hpp:786
SlewRate
Slew rate enumeration.
Definition TLE92466ED_Registers.hpp:766
@ MEDIUM_2V5_US
2.5 V/µs
DiagCurrent
OFF-state diagnostic current.
Definition TLE92466ED_Registers.hpp:776
Channel configuration structure.
Definition TLE92466ED.hpp:115
SlewRate slew_rate
Output slew rate.
Definition TLE92466ED.hpp:118
bool deep_dither_enabled
Enable deep dither.
Definition TLE92466ED.hpp:125
bool olsg_warning_enabled
Enable OLSG warning.
Definition TLE92466ED.hpp:124
ChannelMode mode
Channel operation mode.
Definition TLE92466ED.hpp:116
uint16_t current_setpoint_ma
Current setpoint in mA (0-2000 or 0-4000)
Definition TLE92466ED.hpp:117
DiagCurrent diag_current
OFF-state diagnostic current.
Definition TLE92466ED.hpp:119
uint8_t dither_flat
Flat period steps.
Definition TLE92466ED.hpp:128
uint8_t pwm_period_exponent
PWM period exponent.
Definition TLE92466ED.hpp:122
uint16_t dither_step_size
Dither amplitude step size.
Definition TLE92466ED.hpp:126
bool auto_limit_disabled
Disable auto-limit feature.
Definition TLE92466ED.hpp:123
uint8_t dither_steps
Number of dither steps.
Definition TLE92466ED.hpp:127
uint8_t open_load_threshold
OL threshold (0=disabled, 1-7 = 1/8 to 7/8)
Definition TLE92466ED.hpp:120
uint16_t pwm_period_mantissa
PWM period mantissa.
Definition TLE92466ED.hpp:121
Channel diagnostic information.
Definition TLE92466ED.hpp:169
bool short_to_ground
Short to ground.
Definition TLE92466ED.hpp:172
uint16_t min_current
Minimum current.
Definition TLE92466ED.hpp:186
uint16_t average_current
Average current (raw value)
Definition TLE92466ED.hpp:184
bool ot_warning
Over-temperature warning.
Definition TLE92466ED.hpp:178
bool current_regulation_warning
Current regulation warning.
Definition TLE92466ED.hpp:179
bool overcurrent
Over-current detected.
Definition TLE92466ED.hpp:171
bool pwm_regulation_warning
PWM regulation warning.
Definition TLE92466ED.hpp:180
uint16_t vbat_feedback
VBAT feedback.
Definition TLE92466ED.hpp:188
uint16_t duty_cycle
PWM duty cycle (raw value)
Definition TLE92466ED.hpp:185
bool open_load_short_ground
Open load or short to ground.
Definition TLE92466ED.hpp:175
uint16_t max_current
Maximum current.
Definition TLE92466ED.hpp:187
bool olsg_warning
OLSG warning.
Definition TLE92466ED.hpp:181
bool open_load
Open load.
Definition TLE92466ED.hpp:173
bool over_temperature
Channel over-temperature.
Definition TLE92466ED.hpp:174
Global device status structure.
Definition TLE92466ED.hpp:134
bool vbat_ov
VBAT overvoltage.
Definition TLE92466ED.hpp:141
bool supply_nok_internal
Internal supply fault.
Definition TLE92466ED.hpp:158
bool clock_fault
Clock fault.
Definition TLE92466ED.hpp:152
uint16_t vbat_voltage
VBAT voltage (raw value)
Definition TLE92466ED.hpp:162
bool vio_ov
VIO overvoltage.
Definition TLE92466ED.hpp:143
uint16_t vio_voltage
VIO voltage (raw value)
Definition TLE92466ED.hpp:163
bool supply_nok_external
External supply fault.
Definition TLE92466ED.hpp:159
bool spi_wd_error
SPI watchdog error.
Definition TLE92466ED.hpp:153
bool reset_event
External reset occurred.
Definition TLE92466ED.hpp:155
bool ot_error
Over-temperature error.
Definition TLE92466ED.hpp:149
bool any_fault
Any fault condition present.
Definition TLE92466ED.hpp:137
bool vbat_uv
VBAT undervoltage.
Definition TLE92466ED.hpp:140
bool por_event
Power-on reset occurred.
Definition TLE92466ED.hpp:154
bool vdd_uv
VDD undervoltage.
Definition TLE92466ED.hpp:144
bool init_done
Initialization complete.
Definition TLE92466ED.hpp:136
bool vio_uv
VIO undervoltage.
Definition TLE92466ED.hpp:142
bool config_mode
In config mode (vs mission mode)
Definition TLE92466ED.hpp:135
bool vdd_ov
VDD overvoltage.
Definition TLE92466ED.hpp:145
bool ot_warning
Over-temperature warning.
Definition TLE92466ED.hpp:148
Global configuration structure.
Definition TLE92466ED.hpp:194
bool spi_watchdog_enabled
Enable SPI watchdog.
Definition TLE92466ED.hpp:196
bool vio_5v
VIO voltage (false=3.3V, true=5.0V)
Definition TLE92466ED.hpp:198
bool crc_enabled
Enable CRC checking.
Definition TLE92466ED.hpp:195
uint16_t spi_watchdog_reload
SPI watchdog reload value.
Definition TLE92466ED.hpp:201
uint8_t vbat_ov_threshold
VBAT OV threshold (0.16208V per LSB)
Definition TLE92466ED.hpp:200
bool clock_watchdog_enabled
Enable clock watchdog.
Definition TLE92466ED.hpp:197
uint8_t vbat_uv_threshold
VBAT UV threshold (0.16208V per LSB)
Definition TLE92466ED.hpp:199
32-bit SPI frame structure for TLE92466ED communication
Definition TLE92466ED_Registers.hpp:68