HardFOC Vortex V1 HAL
Unified HAL API for the HardFOC Vortex motor-control platform (ESP32-C6, TMC9660)
Loading...
Searching...
No Matches
VortexBoardBind.h
Go to the documentation of this file.
1
24#ifndef VORTEX_BOARD_BIND_H_
25#define VORTEX_BOARD_BIND_H_
26
27#include <cstddef>
28#include <cstdint>
29
30#include "base/BaseCan.h"
31#include "base/BaseGpio.h"
32#include "base/BaseI2c.h"
33#include "base/BaseNvs.h"
34#include "base/BaseSpi.h"
35#include "base/BaseTemperature.h"
36#include "base/BaseUart.h"
37#include "core/hf-core-drivers/internal/hf-pincfg/src/hf_functional_pin_config_vortex_v1.hpp"
38
39namespace vortex::bsp {
40
41//==============================================================================
42// Bus specifications (MCU-neutral; the binding maps them to its own driver config)
43//==============================================================================
44
46struct UartSpec {
47 uint8_t port{1};
48 uint32_t baud{115200};
49 int tx_pin{-1};
50 int rx_pin{-1};
51 uint16_t tx_buffer_bytes{256};
52 uint16_t rx_buffer_bytes{512};
53 uint32_t timeout_ms{100};
54};
55
57struct SpiBusSpec {
58 uint8_t host{1};
59 int miso_pin{-1};
60 int mosi_pin{-1};
61 int sclk_pin{-1};
62 uint32_t timeout_ms{1000};
63};
64
67 int cs_pin{-1};
68 uint32_t clock_hz{10'000'000};
69 uint8_t mode{0};
70};
71
73struct I2cBusSpec {
74 uint8_t port{0};
75 int sda_pin{-1};
76 int scl_pin{-1};
77 bool internal_pullups{false};
78};
79
82 uint16_t address{0};
83 uint32_t scl_hz{100'000};
84 uint32_t scl_wait_us{0};
85};
86
88struct CanSpec {
89 int tx_pin{-1};
90 int rx_pin{-1};
91 uint32_t bitrate{500'000};
92};
93
94//==============================================================================
95// UART
96//==============================================================================
97
99BaseUart* UartOpen(const UartSpec& spec) noexcept;
101void UartClose() noexcept;
102
103//==============================================================================
104// SPI
105//==============================================================================
106
108bool SpiOpen(const SpiBusSpec& spec) noexcept;
110int SpiAddDevice(const SpiDeviceSpec& spec) noexcept;
112BaseSpi* SpiDevice(int index) noexcept;
114void SpiClose() noexcept;
115
116//==============================================================================
117// I2C
118//==============================================================================
119
121bool I2cOpen(const I2cBusSpec& spec) noexcept;
123int I2cAddDevice(const I2cDeviceSpec& spec) noexcept;
125BaseI2c* I2cDevice(int index) noexcept;
127bool I2cRemoveDevice(int index) noexcept;
129bool I2cProbe(uint8_t address, uint32_t timeout_ms) noexcept;
136size_t I2cScan(uint8_t* out, size_t max, uint8_t first, uint8_t last, uint32_t timeout_ms) noexcept;
138bool I2cReset() noexcept;
140void I2cClose() noexcept;
141
142//==============================================================================
143// CAN
144//==============================================================================
145
147BaseCan* CanOpen(const CanSpec& spec) noexcept;
149void CanClose() noexcept;
150
151//==============================================================================
152// MCU GPIO (pins of the pin map whose chip is the host MCU)
153//==============================================================================
154
159BaseGpio* McuGpioOpen(HfFunctionalGpioPin pin, hf_gpio_direction_t direction, hf_gpio_active_state_t active,
160 hf_gpio_output_mode_t output_mode, hf_gpio_pull_mode_t pull) noexcept;
162void McuGpioCloseAll() noexcept;
163
164//==============================================================================
165// NVS (three fixed namespaces)
166//==============================================================================
167
169enum class NvsRegion : uint8_t {
170 App = 0,
172 Config,
173 Count
174};
175
177[[nodiscard]] constexpr const char* NvsNamespace(NvsRegion region) noexcept {
178 switch (region) {
179 case NvsRegion::App: return "vortex";
180 case NvsRegion::Calibration: return "vortex_cal";
181 case NvsRegion::Config: return "vortex_cfg";
182 default: return "";
183 }
184}
185
187BaseNvs& Nvs(NvsRegion region) noexcept;
188
189//==============================================================================
190// MCU die temperature
191//==============================================================================
192
194BaseTemperature* McuTemperature() noexcept;
195
196//==============================================================================
197// Time
198//==============================================================================
199
205uint64_t MonotonicMicros() noexcept;
206
207//==============================================================================
208// Status LED (one WS2812 on Vortex V1)
209//==============================================================================
210
212bool StatusLedOpen(int data_pin, uint32_t led_count) noexcept;
220bool StatusLedShow(const uint32_t* rgb, uint32_t count, uint8_t brightness) noexcept;
222void StatusLedClose() noexcept;
223
224} // namespace vortex::bsp
225
226#endif // VORTEX_BOARD_BIND_H_
Definition VortexBoardBindEsp32c6.cpp:32
BaseGpio * McuGpioOpen(HfFunctionalGpioPin pin, hf_gpio_direction_t direction, hf_gpio_active_state_t active, hf_gpio_output_mode_t output_mode, hf_gpio_pull_mode_t pull) noexcept
Create the MCU GPIO for a functional pin (one slot per pin; a second call returns the same object).
Definition VortexBoardBindEsp32c6.cpp:264
uint64_t MonotonicMicros() noexcept
Monotonic microseconds since boot, at the MCU's high-resolution timer (not the RTOS tick).
Definition VortexBoardBindEsp32c6.cpp:317
void I2cClose() noexcept
Remove every device and release the bus (idempotent).
Definition VortexBoardBindEsp32c6.cpp:225
void SpiClose() noexcept
Remove every device and release the bus (idempotent).
Definition VortexBoardBindEsp32c6.cpp:145
bool I2cRemoveDevice(int index) noexcept
Remove one device.
Definition VortexBoardBindEsp32c6.cpp:195
bool I2cProbe(uint8_t address, uint32_t timeout_ms) noexcept
Address-only probe.
Definition VortexBoardBindEsp32c6.cpp:200
BaseNvs & Nvs(NvsRegion region) noexcept
The NVS object of a region. Constructing it touches no hardware; call EnsureInitialized() on it.
Definition VortexBoardBindEsp32c6.cpp:293
void McuGpioCloseAll() noexcept
Destroy every MCU GPIO created by McuGpioOpen(). Pointers handed out become invalid.
Definition VortexBoardBindEsp32c6.cpp:283
bool I2cReset() noexcept
Recover a stuck bus (clock pulses + re-init).
Definition VortexBoardBindEsp32c6.cpp:220
BaseCan * CanOpen(const CanSpec &spec) noexcept
Open the CAN controller.
Definition VortexBoardBindEsp32c6.cpp:231
constexpr const char * NvsNamespace(NvsRegion region) noexcept
Namespace name of a region.
Definition VortexBoardBind.h:177
NvsRegion
The persistent-storage regions of the board.
Definition VortexBoardBind.h:169
@ App
namespace "vortex"
@ Calibration
namespace "vortex_cal"
@ Config
namespace "vortex_cfg"
BaseSpi * SpiDevice(int index) noexcept
The device at index, or nullptr.
Definition VortexBoardBindEsp32c6.cpp:140
int SpiAddDevice(const SpiDeviceSpec &spec) noexcept
Add a chip select.
Definition VortexBoardBindEsp32c6.cpp:128
size_t I2cScan(uint8_t *out, size_t max, uint8_t first, uint8_t last, uint32_t timeout_ms) noexcept
Probe every address in [first, last].
Definition VortexBoardBindEsp32c6.cpp:205
BaseI2c * I2cDevice(int index) noexcept
The device at index, or nullptr.
Definition VortexBoardBindEsp32c6.cpp:190
void CanClose() noexcept
Close the CAN controller (idempotent).
Definition VortexBoardBindEsp32c6.cpp:249
BaseUart * UartOpen(const UartSpec &spec) noexcept
Open the board UART.
Definition VortexBoardBindEsp32c6.cpp:69
bool StatusLedOpen(int data_pin, uint32_t led_count) noexcept
Open the addressable status LED chain on data_pin.
Definition VortexBoardBindEsp32c6.cpp:323
bool SpiOpen(const SpiBusSpec &spec) noexcept
Initialise the SPI bus.
Definition VortexBoardBindEsp32c6.cpp:107
void StatusLedClose() noexcept
Turn the chain off and release it (idempotent).
Definition VortexBoardBindEsp32c6.cpp:360
bool StatusLedShow(const uint32_t *rgb, uint32_t count, uint8_t brightness) noexcept
Latch colours onto the chain.
Definition VortexBoardBindEsp32c6.cpp:345
int I2cAddDevice(const I2cDeviceSpec &spec) noexcept
Add a device.
Definition VortexBoardBindEsp32c6.cpp:174
void UartClose() noexcept
Close the UART opened by UartOpen() (idempotent).
Definition VortexBoardBindEsp32c6.cpp:101
BaseTemperature * McuTemperature() noexcept
The MCU's on-chip temperature sensor (not yet initialised), or nullptr if the MCU has none.
Definition VortexBoardBindEsp32c6.cpp:308
bool I2cOpen(const I2cBusSpec &spec) noexcept
Initialise the I2C bus.
Definition VortexBoardBindEsp32c6.cpp:151
Classic CAN controller.
Definition VortexBoardBind.h:88
uint32_t bitrate
Definition VortexBoardBind.h:91
int tx_pin
Definition VortexBoardBind.h:89
int rx_pin
Definition VortexBoardBind.h:90
I2C master bus.
Definition VortexBoardBind.h:73
int scl_pin
Definition VortexBoardBind.h:76
bool internal_pullups
Definition VortexBoardBind.h:77
uint8_t port
Definition VortexBoardBind.h:74
int sda_pin
Definition VortexBoardBind.h:75
One 7-bit device on the I2C bus.
Definition VortexBoardBind.h:81
uint16_t address
Definition VortexBoardBind.h:82
uint32_t scl_wait_us
Clock-stretch allowance; 0 = driver default.
Definition VortexBoardBind.h:84
uint32_t scl_hz
Definition VortexBoardBind.h:83
SPI master bus (one per board on Vortex: SPI2).
Definition VortexBoardBind.h:57
uint32_t timeout_ms
Definition VortexBoardBind.h:62
int mosi_pin
Definition VortexBoardBind.h:60
uint8_t host
Controller index; 1 is SPI2 on the ESP32-C6.
Definition VortexBoardBind.h:58
int miso_pin
Definition VortexBoardBind.h:59
int sclk_pin
Definition VortexBoardBind.h:61
One chip select on the SPI bus.
Definition VortexBoardBind.h:66
uint8_t mode
SPI mode 0..3 (CPOL/CPHA)
Definition VortexBoardBind.h:69
int cs_pin
Definition VortexBoardBind.h:67
uint32_t clock_hz
Definition VortexBoardBind.h:68
UART port, framing 8N1, no flow control.
Definition VortexBoardBind.h:46
uint16_t rx_buffer_bytes
Definition VortexBoardBind.h:52
uint8_t port
Definition VortexBoardBind.h:47
uint32_t baud
Definition VortexBoardBind.h:48
uint32_t timeout_ms
Definition VortexBoardBind.h:53
int tx_pin
Definition VortexBoardBind.h:49
int rx_pin
Definition VortexBoardBind.h:50
uint16_t tx_buffer_bytes
Definition VortexBoardBind.h:51