TLE92466ED Driver 0.1.0-preview
Modern C++23 driver for Infineon TLE92466ED Six-Channel Low-Side Solenoid Driver
Loading...
Searching...
No Matches
TLE92466ED_HAL.hpp
Go to the documentation of this file.
1
25#ifndef TLE92466ED_HAL_HPP
26#define TLE92466ED_HAL_HPP
27
28#include <cstdint>
29#include <concepts>
30#include <span>
31#include <expected>
32
33namespace TLE92466ED {
34
53
61template<typename T>
62using HALResult = std::expected<T, HALError>;
63
69struct SPIConfig {
70 uint32_t frequency{1'000'000};
71 uint8_t mode{0};
72 uint8_t bits_per_word{8};
73 bool msb_first{true};
74 uint32_t timeout_ms{100};
75};
76
124class HAL {
125public:
129 virtual ~HAL() = default;
130
144 [[nodiscard]] virtual HALResult<void> init() noexcept = 0;
145
155 [[nodiscard]] virtual HALResult<void> deinit() noexcept = 0;
156
183 [[nodiscard]] virtual HALResult<uint32_t> transfer32(uint32_t tx_data) noexcept = 0;
184
201 [[nodiscard]] virtual HALResult<void> transfer_multi(
202 std::span<const uint32_t> tx_data,
203 std::span<uint32_t> rx_data) noexcept = 0;
204
217 [[nodiscard]] virtual HALResult<void> chip_select() noexcept = 0;
218
229 [[nodiscard]] virtual HALResult<void> chip_deselect() noexcept = 0;
230
245 [[nodiscard]] virtual HALResult<void> delay(uint32_t microseconds) noexcept = 0;
246
264 [[nodiscard]] virtual HALResult<void> configure(const SPIConfig& config) noexcept = 0;
265
275 [[nodiscard]] virtual bool is_ready() const noexcept = 0;
276
286 [[nodiscard]] virtual HALError get_last_error() const noexcept = 0;
287
297 [[nodiscard]] virtual HALResult<void> clear_errors() noexcept = 0;
298
299protected:
306 HAL() = default;
307
311 HAL(const HAL&) = delete;
312 HAL& operator=(const HAL&) = delete;
313
317 HAL(HAL&&) noexcept = default;
318 HAL& operator=(HAL&&) noexcept = default;
319};
320
331template<typename T>
332concept HALInterface = std::is_base_of_v<HAL, T> && requires(T hal, uint32_t data, SPIConfig cfg) {
333 { hal.init() } -> std::same_as<HALResult<void>>;
334 { hal.transfer32(data) } -> std::same_as<HALResult<uint32_t>>;
335 { hal.chip_select() } -> std::same_as<HALResult<void>>;
336 { hal.chip_deselect() } -> std::same_as<HALResult<void>>;
337 { hal.is_ready() } -> std::same_as<bool>;
338 { hal.configure(cfg) } -> std::same_as<HALResult<void>>;
339};
340
341} // namespace TLE92466ED
342
343#endif // TLE92466ED_HAL_HPP
Abstract Hardware Abstraction Layer (HAL) base class.
Definition TLE92466ED_HAL.hpp:124
HAL()=default
Protected constructor to prevent direct instantiation.
virtual HALResult< void > transfer_multi(std::span< const uint32_t > tx_data, std::span< uint32_t > rx_data) noexcept=0
Transfer multiple 32-bit words via SPI.
virtual HALError get_last_error() const noexcept=0
Get the last error that occurred.
virtual HALResult< void > clear_errors() noexcept=0
Clear any pending errors.
virtual HALResult< uint32_t > transfer32(uint32_t tx_data) noexcept=0
Transfer 32-bit data via SPI (full-duplex)
virtual HALResult< void > delay(uint32_t microseconds) noexcept=0
Delay for specified duration.
virtual ~HAL()=default
Virtual destructor for polymorphic behavior.
virtual HALResult< void > deinit() noexcept=0
Deinitialize the hardware interface.
virtual HALResult< void > init() noexcept=0
Initialize the hardware interface.
virtual HALResult< void > configure(const SPIConfig &config) noexcept=0
Configure SPI parameters.
virtual HALResult< void > chip_select() noexcept=0
Assert (activate) chip select.
virtual bool is_ready() const noexcept=0
Check if hardware is ready for communication.
virtual HALResult< void > chip_deselect() noexcept=0
Deassert (deactivate) chip select.
Concept to verify a type implements the HAL interface.
Definition TLE92466ED_HAL.hpp:332
Definition TLE92466ED.hpp:80
@ InvalidParameter
Invalid parameter value.
@ CRCError
CRC mismatch in SPI communication.
HALError
Error codes for HAL operations.
Definition TLE92466ED_HAL.hpp:41
@ BusError
SPI bus communication error.
@ HardwareNotReady
Hardware not initialized or ready.
@ BufferOverflow
Buffer size exceeded.
@ ChipselectError
Chip select control failed.
@ TransferError
Data transfer failed.
@ UnknownError
Unknown error occurred.
@ Timeout
Operation timed out.
std::expected< T, HALError > HALResult
Result type for HAL operations using std::expected (C++23)
Definition TLE92466ED_HAL.hpp:62
SPI transaction configuration.
Definition TLE92466ED_HAL.hpp:69
uint8_t bits_per_word
Bits per word (8-bit, transfer 4 bytes for 32-bit frame)
Definition TLE92466ED_HAL.hpp:72
uint32_t frequency
SPI clock frequency in Hz (max 10 MHz for TLE92466ED)
Definition TLE92466ED_HAL.hpp:70
bool msb_first
MSB first transmission.
Definition TLE92466ED_HAL.hpp:73
uint32_t timeout_ms
Transaction timeout in milliseconds.
Definition TLE92466ED_HAL.hpp:74
uint8_t mode
SPI mode (CPOL=0, CPHA=0 for TLE92466ED)
Definition TLE92466ED_HAL.hpp:71