TLE92466ED Driver 0.1.0-preview
Modern C++23 driver for Infineon TLE92466ED Six-Channel Low-Side Solenoid Driver
Loading...
Searching...
No Matches
ESP32C6_HAL.hpp
Go to the documentation of this file.
1
13#pragma once
14
15#include "TLE92466ED_HAL.hpp"
16#include "TLE92466ED_Config.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
30class ESP32C6_HAL : public TLE92466ED_HAL {
31public:
35 struct SPIConfig {
36 spi_host_device_t host = SPI2_HOST;
37 int miso_pin = 2;
38 int mosi_pin = 7;
39 int sclk_pin = 6;
40 int cs_pin = 10;
41 int frequency = 1000000;
42 int mode = 0;
43 int queue_size = 1;
44 };
45
50
55 explicit ESP32C6_HAL(const SPIConfig& config);
56
60 ~ESP32C6_HAL() override;
61
66 auto initialize() noexcept -> std::expected<void, HALError>;
67
74 auto spiTransfer(std::span<const uint8_t> txData,
75 std::span<uint8_t> rxData) noexcept
76 -> std::expected<void, HALError> override;
77
82 void delayMicroseconds(uint32_t us) noexcept override;
83
88 auto getConfig() const noexcept -> const SPIConfig& { return config_; }
89
94 auto isInitialized() const noexcept -> bool { return initialized_; }
95
96private:
98 spi_device_handle_t spi_device_ = nullptr;
99 bool initialized_ = false;
100
101 static constexpr const char* TAG = "ESP32C6_HAL";
102
107 auto initializeSPI() noexcept -> std::expected<void, HALError>;
108
113 auto addSPIDevice() noexcept -> std::expected<void, HALError>;
114};
115
122inline auto createTLE92466ED_HAL() -> std::unique_ptr<ESP32C6_HAL> {
123 using namespace TLE92466ED_Config;
124
126
127 // Configuration from TLE92466ED_Config.hpp
128 config.host = SPI2_HOST;
129 config.miso_pin = SPIPins::MISO;
130 config.mosi_pin = SPIPins::MOSI;
131 config.sclk_pin = SPIPins::SCLK;
132 config.cs_pin = SPIPins::CS;
133 config.frequency = SPIParams::FREQUENCY;
134 config.mode = SPIParams::MODE;
135 config.queue_size = SPIParams::QUEUE_SIZE;
136
137 return std::make_unique<ESP32C6_HAL>(config);
138}
auto createTLE92466ED_HAL() -> std::unique_ptr< ESP32C6_HAL >
Create a configured ESP32C6_HAL instance for TLE92466ED.
Definition ESP32C6_HAL.hpp:122
Hardware configuration for TLE92466ED driver on ESP32-C6.
Hardware Abstraction Layer (HAL) base class for TLE92466ED driver.
ESP32-C6 implementation of the TLE92466ED HAL interface.
Definition ESP32C6_HAL.hpp:30
auto getConfig() const noexcept -> const SPIConfig &
Get the current SPI configuration.
Definition ESP32C6_HAL.hpp:88
static constexpr const char * TAG
Logging tag.
Definition ESP32C6_HAL.hpp:101
auto addSPIDevice() noexcept -> std::expected< void, HALError >
Add SPI device to the bus.
Definition ESP32C6_HAL.cpp:92
~ESP32C6_HAL() override
Destructor - cleans up SPI resources.
Definition ESP32C6_HAL.cpp:25
bool initialized_
Initialization state.
Definition ESP32C6_HAL.hpp:99
void delayMicroseconds(uint32_t us) noexcept override
Microsecond delay implementation.
Definition ESP32C6_HAL.cpp:155
auto initialize() noexcept -> std::expected< void, HALError >
Initialize the HAL (must be called before use)
Definition ESP32C6_HAL.cpp:39
auto isInitialized() const noexcept -> bool
Check if HAL is initialized.
Definition ESP32C6_HAL.hpp:94
SPIConfig config_
SPI configuration.
Definition ESP32C6_HAL.hpp:97
spi_device_handle_t spi_device_
SPI device handle.
Definition ESP32C6_HAL.hpp:98
auto spiTransfer(std::span< const uint8_t > txData, std::span< uint8_t > rxData) noexcept -> std::expected< void, HALError > override
Perform SPI transfer (32-bit frames for TLE92466ED)
Definition ESP32C6_HAL.cpp:121
auto initializeSPI() noexcept -> std::expected< void, HALError >
Initialize SPI bus.
Definition ESP32C6_HAL.cpp:65
ESP32C6_HAL()
Constructor with default SPI configuration.
Definition ESP32C6_HAL.hpp:49
Definition TLE92466ED_Config.hpp:17
SPI configuration structure for ESP32-C6.
Definition ESP32C6_HAL.hpp:35
int miso_pin
MISO pin (GPIO2)
Definition ESP32C6_HAL.hpp:37
int frequency
SPI frequency (1MHz)
Definition ESP32C6_HAL.hpp:41
int mode
SPI mode (0 = CPOL=0, CPHA=0)
Definition ESP32C6_HAL.hpp:42
int mosi_pin
MOSI pin (GPIO7)
Definition ESP32C6_HAL.hpp:38
spi_host_device_t host
SPI host (SPI2_HOST for ESP32-C6)
Definition ESP32C6_HAL.hpp:36
int sclk_pin
SCLK pin (GPIO6)
Definition ESP32C6_HAL.hpp:39
int queue_size
Transaction queue size.
Definition ESP32C6_HAL.hpp:43
int cs_pin
CS pin (GPIO10)
Definition ESP32C6_HAL.hpp:40