TLE92466ED Driver 0.1.0-dev
Modern C++20 driver for Infineon TLE92466ED Six-Channel Low-Side Solenoid Driver
Loading...
Searching...
No Matches
esp32_tle92466ed_bus.hpp
Go to the documentation of this file.
1
13#pragma once
14
15#include "tle92466ed_spi_interface.hpp"
17#include "driver/spi_master.h"
18#include "driver/gpio.h"
19#include "esp_timer.h"
20#include "esp_log.h"
21#include <memory>
22#include <cstdarg>
23#include <span>
24#include "freertos/FreeRTOS.h"
25#include "freertos/task.h"
26#include "tle92466ed_registers.hpp"
27
28using namespace tle92466ed;
29
30namespace {
31 [[nodiscard]] constexpr inline uint32_t byte_swap_32(uint32_t value) noexcept {
32 return ((value & 0xFF000000U) >> 24) |
33 ((value & 0x00FF0000U) >> 8) |
34 ((value & 0x0000FF00U) << 8) |
35 ((value & 0x000000FFU) << 24);
36 }
37}
38
46class Esp32Tle92466edSpiBus : public tle92466ed::SpiInterface<Esp32Tle92466edSpiBus> {
47public:
48 // Make base class Log method accessible
49 using SpiInterface<Esp32Tle92466edSpiBus>::Log;
53 struct SPIConfig {
54 spi_host_device_t host = SPI2_HOST;
55 int16_t miso_pin = 2;
56 int16_t mosi_pin = 7;
57 int16_t sclk_pin = 6;
58 int16_t cs_pin = 10;
59 int16_t resn_pin = -1;
60 int16_t en_pin = -1;
61 int16_t faultn_pin = -1;
62 int16_t drv0_pin = -1;
63 int16_t drv1_pin = -1;
64 uint32_t frequency = 1000000;
65 uint8_t mode = 1;
66 uint8_t queue_size = 1;
67 uint8_t cs_ena_pretrans = 1;
68 uint8_t cs_ena_posttrans = 1;
69 };
70
75
80 explicit Esp32Tle92466edSpiBus(const SPIConfig& config) noexcept : config_(config) {
81 ESP_LOGI(TAG, "Esp32Tle92466edSpiBus created with SPI config:");
82 ESP_LOGI(TAG, " Host: %d", static_cast<int>(config_.host));
83 ESP_LOGI(TAG, " MISO: GPIO%d", config_.miso_pin);
84 ESP_LOGI(TAG, " MOSI: GPIO%d", config_.mosi_pin);
85 ESP_LOGI(TAG, " SCLK: GPIO%d", config_.sclk_pin);
86 ESP_LOGI(TAG, " CS: GPIO%d", config_.cs_pin);
87 ESP_LOGI(TAG, " Frequency: %d Hz", config_.frequency);
88 const char* mode_desc;
89 switch (config_.mode) {
90 case 0: mode_desc = "CPOL=0, CPHA=0"; break;
91 case 1: mode_desc = "CPOL=0, CPHA=1"; break;
92 case 2: mode_desc = "CPOL=1, CPHA=0"; break;
93 case 3: mode_desc = "CPOL=1, CPHA=1"; break;
94 default: mode_desc = "Invalid"; break;
95 }
96 ESP_LOGI(TAG, " Mode: %d (%s)", config_.mode, mode_desc);
97 if (config_.resn_pin >= 0) ESP_LOGI(TAG, " RESN: GPIO%d", config_.resn_pin);
98 if (config_.en_pin >= 0) ESP_LOGI(TAG, " EN: GPIO%d", config_.en_pin);
99 if (config_.faultn_pin >= 0) ESP_LOGI(TAG, " FAULTN: GPIO%d", config_.faultn_pin);
100 if (config_.drv0_pin >= 0) ESP_LOGI(TAG, " DRV0: GPIO%d", config_.drv0_pin);
101 if (config_.drv1_pin >= 0) ESP_LOGI(TAG, " DRV1: GPIO%d", config_.drv1_pin);
102 }
103
110 if (spi_device_ != nullptr) {
111 spi_bus_remove_device(spi_device_);
112 spi_device_ = nullptr;
113 }
114
115 if (initialized_) {
116 spi_bus_free(config_.host);
117 initialized_ = false;
118 }
119 }
120
125 auto Init() noexcept -> CommResult<void> {
126 if (initialized_) {
127 ESP_LOGW(TAG, "CommInterface already initialized");
128 return {};
129 }
130 ESP_LOGI(TAG, "Initializing Esp32Tle92466edSpiBus...");
131 if (auto result = initializeGPIO(); !result) {
132 ESP_LOGE(TAG, "Failed to initialize GPIO pins");
133 return tle::unexpected(result.error());
134 }
135 if (auto result = initializeSPI(); !result) {
136 ESP_LOGE(TAG, "Failed to initialize SPI bus");
137 return tle::unexpected(result.error());
138 }
139 if (auto result = addSPIDevice(); !result) {
140 ESP_LOGE(TAG, "Failed to add SPI device");
141 spi_bus_free(config_.host);
142 return tle::unexpected(result.error());
143 }
144 initialized_ = true;
145 ESP_LOGI(TAG, "Esp32Tle92466edSpiBus initialized successfully");
146 return {};
147 }
148
153 auto Deinit() noexcept -> CommResult<void> {
154 if (!initialized_) {
155 ESP_LOGW(TAG, "CommInterface not initialized");
156 return {};
157 }
158 ESP_LOGI(TAG, "Deinitializing Esp32Tle92466edSpiBus...");
159 if (spi_device_ != nullptr) {
160 spi_bus_remove_device(spi_device_);
161 spi_device_ = nullptr;
162 }
163 spi_bus_free(config_.host);
164 initialized_ = false;
165 ESP_LOGI(TAG, "Esp32Tle92466edSpiBus deinitialized successfully");
166 return {};
167 }
168
174 auto Transfer32(uint32_t tx_data) noexcept -> CommResult<uint32_t> {
175 if (!initialized_) {
176 ESP_LOGE(TAG, "CommInterface not initialized");
177 return tle::unexpected(CommError::HardwareNotReady);
178 }
179 uint32_t tx_data_swapped = byte_swap_32(tx_data);
180 uint32_t rx_data_raw = 0;
181 spi_transaction_t trans = {};
182 trans.length = 32;
183 trans.tx_buffer = &tx_data_swapped;
184 trans.rx_buffer = &rx_data_raw;
185
186#if ESP32_TLE_COMM_ENABLE_DETAILED_SPI_LOGGING
187 uint8_t* tx_bytes_orig = reinterpret_cast<uint8_t*>(&tx_data);
188 uint8_t* tx_bytes_swapped = reinterpret_cast<uint8_t*>(&tx_data_swapped);
189 uint8_t crc_tx = tx_bytes_orig[3];
190 uint8_t addr_byte = tx_bytes_orig[2];
191 uint8_t data_high = tx_bytes_orig[1];
192 uint8_t data_low = tx_bytes_orig[0];
193 uint8_t address_upper = (addr_byte >> 1) & 0x7F;
194 bool is_write = (addr_byte & 0x01) != 0;
195 uint16_t data_16bit = (static_cast<uint16_t>(data_high) << 8) | data_low;
196 ESP_LOGI(TAG, "SPI TX Frame: 0x%08X | Swapped: 0x%08X", tx_data, tx_data_swapped);
197 SPIFrame tx_frame_for_crc;
198 tx_frame_for_crc.word = tx_data;
199 uint8_t tx_crc_received = tx_frame_for_crc.tx_fields.crc;
200 tx_frame_for_crc.tx_fields.crc = 0;
201 uint8_t tx_crc_calculated = CalculateFrameCrc(tx_frame_for_crc);
202 bool tx_crc_match = (tx_crc_received == tx_crc_calculated);
203 ESP_LOGI(TAG, " CRC=0x%02X calc=0x%02X %s | Addr=0x%02X %s | Data=0x%04X",
204 tx_crc_received, tx_crc_calculated, tx_crc_match ? "OK" : "MISMATCH",
205 address_upper, is_write ? "W" : "R", data_16bit);
206#endif
207 esp_err_t ret = spi_device_transmit(spi_device_, &trans);
208 if (ret != ESP_OK) {
209 ESP_LOGE(TAG, "SPI transfer failed: %s", esp_err_to_name(ret));
210 return tle::unexpected(CommError::TransferError);
211 }
212 uint32_t rx_data = byte_swap_32(rx_data_raw);
213#if ESP32_TLE_COMM_ENABLE_DETAILED_SPI_LOGGING
214 SPIFrame rx_frame;
215 rx_frame.word = rx_data;
216 uint8_t reply_mode = rx_frame.rx_common.reply_mode;
217 const char* reply_mode_str;
218 switch (reply_mode) {
219 case 0x00: reply_mode_str = "16-bit Reply"; break;
220 case 0x01: reply_mode_str = "22-bit Reply"; break;
221 case 0x02: reply_mode_str = "Critical Fault"; break;
222 default: reply_mode_str = "Unknown"; break;
223 }
224 ESP_LOGI(TAG, "SPI RX Frame: 0x%08X (raw: 0x%08X) | %s", rx_data, rx_data_raw, reply_mode_str);
225 if (reply_mode != 0x02) {
226 bool rx_crc_valid = VerifyFrameCrc(rx_frame);
227 ESP_LOGI(TAG, " CRC %s", rx_crc_valid ? "OK" : "MISMATCH");
228 }
229 if (reply_mode == 0x00) {
230 ESP_LOGI(TAG, " Status=0x%02X RW=%d Data=0x%04X",
231 rx_frame.rx_16bit.status, rx_frame.rx_16bit.rw_echo, rx_frame.rx_16bit.data);
232 } else if (reply_mode == 0x01) {
233 ESP_LOGI(TAG, " 22-bit Data=0x%06X", rx_frame.rx_22bit.data);
234 } else if (reply_mode == 0x02) {
235 auto fault_flags = CriticalFaultFlags::Extract(rx_frame);
236 ESP_LOGI(TAG, " Faults: 1V5=%d 2V5=%d BG=%d CLK_SLOW=%d CLK_FAST=%d",
237 fault_flags.supply_1v5_ok, fault_flags.supply_2v5_ok,
238 fault_flags.adc_bandgap_ok, fault_flags.clk_too_slow, fault_flags.clk_too_fast);
239 }
240#endif
241 return rx_data;
242 }
243
250 auto TransferMulti(std::span<const uint32_t> tx_data,
251 std::span<uint32_t> rx_data) noexcept -> CommResult<void> {
252 if (!initialized_) {
253 ESP_LOGE(TAG, "CommInterface not initialized");
254 return tle::unexpected(CommError::HardwareNotReady);
255 }
256 if (tx_data.size() != rx_data.size()) {
257 ESP_LOGE(TAG, "Buffer size mismatch: tx=%zu, rx=%zu", tx_data.size(), rx_data.size());
258 return tle::unexpected(CommError::InvalidParameter);
259 }
260 for (size_t i = 0; i < tx_data.size(); ++i) {
261 if (auto result = Transfer32(tx_data[i]); !result) {
262 return tle::unexpected(result.error());
263 } else {
264 rx_data[i] = *result;
265 }
266 }
267 return {};
268 }
269
275 auto Delay(uint32_t microseconds) noexcept -> CommResult<void> {
276 if (microseconds == 0) return {};
277 if (microseconds < 1000) {
278 int64_t start_time = esp_timer_get_time();
279 while ((esp_timer_get_time() - start_time) < microseconds) {}
280 } else {
281 vTaskDelay(pdMS_TO_TICKS(microseconds / 1000));
282 uint32_t remaining_us = microseconds % 1000;
283 if (remaining_us > 0) {
284 int64_t start_time = esp_timer_get_time();
285 while ((esp_timer_get_time() - start_time) < remaining_us) {}
286 }
287 }
288 return {};
289 }
290
296 auto Configure(const tle92466ed::SPIConfig& config) noexcept -> CommResult<void> {
297 ESP_LOGW(TAG, "SPI configuration update requested - not fully implemented");
298 return {};
299 }
300
305 bool IsReady() const noexcept {
306 return initialized_ && (spi_device_ != nullptr);
307 }
308
313 CommError GetLastError() const noexcept {
314 return last_error_;
315 }
316
321 auto ClearErrors() noexcept -> CommResult<void> {
322 last_error_ = CommError::None;
323 return {};
324 }
325
330 auto getConfig() const noexcept -> const SPIConfig& { return config_; }
331
342 auto GpioSet(CtrlPin pin, GpioSignal signal) noexcept -> CommResult<void> {
343 if (!IsReady()) {
344 last_error_ = CommError::HardwareNotReady;
345 return tle::unexpected(CommError::HardwareNotReady);
346 }
347 int gpio_pin = -1;
348 switch (pin) {
349 case CtrlPin::RESN: gpio_pin = config_.resn_pin; break;
350 case CtrlPin::EN: gpio_pin = config_.en_pin; break;
351 case CtrlPin::FAULTN:
352 last_error_ = CommError::InvalidParameter;
353 return tle::unexpected(CommError::InvalidParameter);
354 }
355 if (gpio_pin < 0) {
356 ESP_LOGE(TAG, "GPIO pin not configured for %s", pin == CtrlPin::RESN ? "RESN" : "EN");
357 last_error_ = CommError::InvalidParameter;
358 return tle::unexpected(CommError::InvalidParameter);
359 }
360 // Map GpioSignal to physical level based on pin active-level:
361 // RESN: active-low → ACTIVE=0, INACTIVE=1
362 // EN: active-high → ACTIVE=1, INACTIVE=0
363 int gpio_level;
364 switch (pin) {
365 case CtrlPin::RESN:
366 gpio_level = (signal == GpioSignal::ACTIVE) ? 0 : 1; // Active-low
367 break;
368 case CtrlPin::EN:
369 gpio_level = (signal == GpioSignal::ACTIVE) ? 1 : 0; // Active-high
370 break;
371 default:
372 return tle::unexpected(CommError::InvalidParameter);
373 }
374 esp_err_t ret = gpio_set_level(static_cast<gpio_num_t>(gpio_pin), gpio_level);
375 if (ret != ESP_OK) {
376 ESP_LOGE(TAG, "Failed to set GPIO%d level: %s", gpio_pin, esp_err_to_name(ret));
377 last_error_ = CommError::BusError;
378 return tle::unexpected(CommError::BusError);
379 }
380 ESP_LOGD(TAG, "Set %s pin (GPIO%d) to %s",
381 pin == CtrlPin::RESN ? "RESN" : "EN", gpio_pin,
382 signal == GpioSignal::ACTIVE ? "ACTIVE" : "INACTIVE");
383 return {};
384 }
385
394 auto GpioRead(CtrlPin pin) noexcept -> CommResult<GpioSignal> {
395 if (!IsReady()) {
396 last_error_ = CommError::HardwareNotReady;
397 return tle::unexpected(CommError::HardwareNotReady);
398 }
399 if (pin != CtrlPin::FAULTN) {
400 last_error_ = CommError::InvalidParameter;
401 return tle::unexpected(CommError::InvalidParameter);
402 }
403 int gpio_pin = config_.faultn_pin;
404 if (gpio_pin < 0) {
405 ESP_LOGE(TAG, "FAULTN GPIO pin not configured");
406 last_error_ = CommError::InvalidParameter;
407 return tle::unexpected(CommError::InvalidParameter);
408 }
409 int gpio_level = gpio_get_level(static_cast<gpio_num_t>(gpio_pin));
410 // FAULTN is active-low: physical 0 = fault active
411 GpioSignal signal = (gpio_level == 0) ? GpioSignal::ACTIVE : GpioSignal::INACTIVE;
412 ESP_LOGD(TAG, "Read FAULTN pin (GPIO%d): %s", gpio_pin,
413 signal == GpioSignal::ACTIVE ? "FAULT" : "NO FAULT");
414 return signal;
415 }
416
424 void Log(LogLevel level, const char* tag, const char* format, va_list args) noexcept {
425 esp_log_level_t esp_level;
426 switch (level) {
427 case LogLevel::Error: esp_level = ESP_LOG_ERROR; break;
428 case LogLevel::Warn: esp_level = ESP_LOG_WARN; break;
429 case LogLevel::Info: esp_level = ESP_LOG_INFO; break;
430 case LogLevel::Debug: esp_level = ESP_LOG_DEBUG; break;
431 case LogLevel::Verbose: esp_level = ESP_LOG_VERBOSE; break;
432 default: esp_level = ESP_LOG_INFO; break;
433 }
434 esp_log_writev(esp_level, tag, format, args);
435 }
436
441 auto isInitialized() const noexcept -> bool { return initialized_; }
442
443private:
445 spi_device_handle_t spi_device_ = nullptr;
446 bool initialized_ = false;
447 CommError last_error_ = CommError::None;
448
449 static constexpr const char* TAG = "Esp32TleComm";
450
455 auto initializeGPIO() noexcept -> CommResult<void> {
456 auto configure_output_pin = [this](int16_t pin, const char* name, int initial_level) -> CommResult<void> {
457 if (pin < 0) return {};
458 gpio_config_t cfg = {
459 .pin_bit_mask = (1ULL << pin),
460 .mode = GPIO_MODE_OUTPUT,
461 .pull_up_en = GPIO_PULLUP_DISABLE,
462 .pull_down_en = GPIO_PULLDOWN_DISABLE,
463 .intr_type = GPIO_INTR_DISABLE
464 };
465 if (gpio_config(&cfg) != ESP_OK) {
466 ESP_LOGE(TAG, "Failed to configure %s pin (GPIO%d)", name, pin);
467 return tle::unexpected(CommError::HardwareNotReady);
468 }
469 gpio_set_level(static_cast<gpio_num_t>(pin), initial_level);
470 ESP_LOGI(TAG, "%s pin (GPIO%d) initialized, level=%d", name, pin, initial_level);
471 return {};
472 };
473 if (auto r = configure_output_pin(config_.resn_pin, "RESN", 0); !r) return r;
474 if (auto r = configure_output_pin(config_.en_pin, "EN", 0); !r) return r;
475 if (auto r = configure_output_pin(config_.drv0_pin, "DRV0", 0); !r) return r;
476 if (auto r = configure_output_pin(config_.drv1_pin, "DRV1", 0); !r) return r;
477 if (config_.faultn_pin >= 0) {
478 gpio_config_t cfg = {
479 .pin_bit_mask = (1ULL << config_.faultn_pin),
480 .mode = GPIO_MODE_INPUT,
481 .pull_up_en = GPIO_PULLUP_ENABLE,
482 .pull_down_en = GPIO_PULLDOWN_DISABLE,
483 .intr_type = GPIO_INTR_DISABLE
484 };
485 if (gpio_config(&cfg) != ESP_OK) {
486 ESP_LOGE(TAG, "Failed to configure FAULTN pin (GPIO%d)", config_.faultn_pin);
487 return tle::unexpected(CommError::HardwareNotReady);
488 }
489 ESP_LOGI(TAG, "FAULTN pin (GPIO%d) initialized as input", config_.faultn_pin);
490 }
491 return {};
492 }
493
498 auto initializeSPI() noexcept -> CommResult<void> {
499 spi_bus_config_t bus_config = {
500 .mosi_io_num = config_.mosi_pin,
501 .miso_io_num = config_.miso_pin,
502 .sclk_io_num = config_.sclk_pin,
503 .quadwp_io_num = -1,
504 .quadhd_io_num = -1,
505 .data4_io_num = -1,
506 .data5_io_num = -1,
507 .data6_io_num = -1,
508 .data7_io_num = -1,
509 .max_transfer_sz = 32,
510 .flags = SPICOMMON_BUSFLAG_MASTER
511 };
512 esp_err_t ret = spi_bus_initialize(config_.host, &bus_config, SPI_DMA_DISABLED);
513 if (ret != ESP_OK) {
514 ESP_LOGE(TAG, "SPI bus initialization failed: %s", esp_err_to_name(ret));
515 return tle::unexpected(CommError::HardwareNotReady);
516 }
517 ESP_LOGI(TAG, "SPI bus initialized successfully");
518 return {};
519 }
520
525 auto addSPIDevice() noexcept -> CommResult<void> {
526 uint8_t spi_mode = static_cast<uint8_t>(config_.mode);
527 if (spi_mode > 3) {
528 ESP_LOGE(TAG, "Invalid SPI mode %d, using Mode 1", spi_mode);
529 spi_mode = 1;
530 }
531 spi_device_interface_config_t dev_config = {};
532 dev_config.command_bits = 0;
533 dev_config.address_bits = 0;
534 dev_config.dummy_bits = 0;
535 dev_config.mode = spi_mode;
536 dev_config.clock_source = SPI_CLK_SRC_DEFAULT;
537 dev_config.duty_cycle_pos = 128;
538 dev_config.cs_ena_pretrans = config_.cs_ena_pretrans;
539 dev_config.cs_ena_posttrans = config_.cs_ena_posttrans;
540 dev_config.clock_speed_hz = config_.frequency;
541 dev_config.input_delay_ns = 0;
542 dev_config.spics_io_num = config_.cs_pin;
543 dev_config.flags = 0;
544 dev_config.queue_size = config_.queue_size;
545 dev_config.pre_cb = nullptr;
546 dev_config.post_cb = nullptr;
547 esp_err_t ret = spi_bus_add_device(config_.host, &dev_config, &spi_device_);
548 if (ret != ESP_OK) {
549 ESP_LOGE(TAG, "Failed to add SPI device: %s", esp_err_to_name(ret));
550 return tle::unexpected(CommError::HardwareNotReady);
551 }
552 ESP_LOGI(TAG, "SPI device added successfully with Mode %d", spi_mode);
553 return {};
554 }
555};
556
565inline auto CreateEsp32Tle92466edSpiBus() noexcept -> std::unique_ptr<Esp32Tle92466edSpiBus> {
566 using namespace TLE92466ED_TestConfig;
568 config.host = SPI2_HOST;
569 config.miso_pin = SPIPins::MISO;
570 config.mosi_pin = SPIPins::MOSI;
571 config.sclk_pin = SPIPins::SCLK;
572 config.cs_pin = SPIPins::CS;
573 config.resn_pin = ControlPins::RESN;
574 config.en_pin = ControlPins::EN;
575 config.faultn_pin = ControlPins::FAULTN;
576 config.drv0_pin = ControlPins::DRV0;
577 config.drv1_pin = ControlPins::DRV1;
578 config.frequency = SPIParams::FREQUENCY;
579 config.mode = SPIParams::MODE;
580 config.queue_size = SPIParams::QUEUE_SIZE;
581 config.cs_ena_pretrans = SPIParams::CS_ENA_PRETRANS;
582 config.cs_ena_posttrans = SPIParams::CS_ENA_POSTTRANS;
583 auto interface = std::make_unique<Esp32Tle92466edSpiBus>(config);
584 if (auto result = interface->Init(); !result) {
585 ESP_LOGE("TLE_Factory", "Failed to initialize CommInterface");
586 return nullptr;
587 }
588 return interface;
589}
590
ESP32 implementation of the TLE92466ED CommInterface.
Definition esp32_tle92466ed_bus.hpp:46
bool initialized_
Initialization state.
Definition esp32_tle92466ed_bus.hpp:446
CommError last_error_
Last error that occurred.
Definition esp32_tle92466ed_bus.hpp:447
Esp32Tle92466edSpiBus(const SPIConfig &config) noexcept
Constructor with custom SPI configuration.
Definition esp32_tle92466ed_bus.hpp:80
CommError GetLastError() const noexcept
Get the last error that occurred.
Definition esp32_tle92466ed_bus.hpp:313
auto initializeSPI() noexcept -> CommResult< void >
Initialize SPI bus.
Definition esp32_tle92466ed_bus.hpp:498
auto Init() noexcept -> CommResult< void >
Initialize the CommInterface (must be called before use)
Definition esp32_tle92466ed_bus.hpp:125
auto GpioRead(CtrlPin pin) noexcept -> CommResult< GpioSignal >
Read GPIO control pin signal.
Definition esp32_tle92466ed_bus.hpp:394
void Log(LogLevel level, const char *tag, const char *format, va_list args) noexcept
Log a message with specified severity level and tag (ESP_LOG implementation)
Definition esp32_tle92466ed_bus.hpp:424
auto Configure(const tle92466ed::SPIConfig &config) noexcept -> CommResult< void >
Configure SPI parameters.
Definition esp32_tle92466ed_bus.hpp:296
auto Deinit() noexcept -> CommResult< void >
Deinitialize the CommInterface.
Definition esp32_tle92466ed_bus.hpp:153
static constexpr const char * TAG
Logging tag.
Definition esp32_tle92466ed_bus.hpp:449
Esp32Tle92466edSpiBus()
Constructor with default SPI configuration.
Definition esp32_tle92466ed_bus.hpp:74
bool IsReady() const noexcept
Check if hardware is ready for communication.
Definition esp32_tle92466ed_bus.hpp:305
auto getConfig() const noexcept -> const SPIConfig &
Get the current SPI configuration.
Definition esp32_tle92466ed_bus.hpp:330
auto GpioSet(CtrlPin pin, GpioSignal signal) noexcept -> CommResult< void >
Set GPIO control pin signal.
Definition esp32_tle92466ed_bus.hpp:342
~Esp32Tle92466edSpiBus() noexcept
Destructor - cleans up SPI resources.
Definition esp32_tle92466ed_bus.hpp:109
SPIConfig config_
SPI configuration.
Definition esp32_tle92466ed_bus.hpp:444
auto Transfer32(uint32_t tx_data) noexcept -> CommResult< uint32_t >
Transfer 32-bit data via SPI (full-duplex)
Definition esp32_tle92466ed_bus.hpp:174
spi_device_handle_t spi_device_
SPI device handle.
Definition esp32_tle92466ed_bus.hpp:445
auto TransferMulti(std::span< const uint32_t > tx_data, std::span< uint32_t > rx_data) noexcept -> CommResult< void >
Transfer multiple 32-bit words via SPI.
Definition esp32_tle92466ed_bus.hpp:250
auto isInitialized() const noexcept -> bool
Check if CommInterface is initialized.
Definition esp32_tle92466ed_bus.hpp:441
auto initializeGPIO() noexcept -> CommResult< void >
Initialize GPIO pins (RESN, EN, FAULTN)
Definition esp32_tle92466ed_bus.hpp:455
auto Delay(uint32_t microseconds) noexcept -> CommResult< void >
Delay for specified duration.
Definition esp32_tle92466ed_bus.hpp:275
auto addSPIDevice() noexcept -> CommResult< void >
Add SPI device to the bus.
Definition esp32_tle92466ed_bus.hpp:525
auto ClearErrors() noexcept -> CommResult< void >
Clear any pending errors.
Definition esp32_tle92466ed_bus.hpp:321
auto CreateEsp32Tle92466edSpiBus() noexcept -> std::unique_ptr< Esp32Tle92466edSpiBus >
Create a configured Esp32Tle92466edSpiBus instance for TLE92466ED.
Definition esp32_tle92466ed_bus.hpp:565
Definition esp32_tle92466ed_test_config.hpp:39
constexpr uint32_t byte_swap_32(uint32_t value) noexcept
Definition esp32_tle92466ed_bus.hpp:31
SPI configuration structure for ESP32.
Definition esp32_tle92466ed_bus.hpp:53
int16_t faultn_pin
FAULTN pin (active low, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:61
int16_t mosi_pin
MOSI pin (GPIO7, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:56
int16_t resn_pin
RESN pin (active low, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:59
uint8_t cs_ena_posttrans
CS held N clock cycles after transaction.
Definition esp32_tle92466ed_bus.hpp:68
int16_t drv1_pin
DRV1 pin (external drive control, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:63
int16_t cs_pin
CS pin (GPIO10, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:58
int16_t en_pin
EN pin (active high, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:60
int16_t drv0_pin
DRV0 pin (external drive control, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:62
uint8_t queue_size
Transaction queue size.
Definition esp32_tle92466ed_bus.hpp:66
uint8_t mode
SPI mode (1 = CPOL=0, CPHA=1)
Definition esp32_tle92466ed_bus.hpp:65
uint32_t frequency
SPI frequency (1MHz)
Definition esp32_tle92466ed_bus.hpp:64
spi_host_device_t host
SPI host (SPI2_HOST for ESP32-C6)
Definition esp32_tle92466ed_bus.hpp:54
uint8_t cs_ena_pretrans
CS asserted N clock cycles before transaction.
Definition esp32_tle92466ed_bus.hpp:67
int16_t sclk_pin
SCLK pin (GPIO6, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:57
int16_t miso_pin
MISO pin (GPIO2, -1 = not configured)
Definition esp32_tle92466ed_bus.hpp:55