HardFOC Flux V1 HAL
Unified HAL API for the HardFOC Flux valve-control platform (ESP32-S3)
Loading...
Searching...
No Matches
FluxPlatformBind.h
Go to the documentation of this file.
1
38#ifndef FLUX_BSP_PLATFORM_BIND_H_
39#define FLUX_BSP_PLATFORM_BIND_H_
40
41#include <cstddef>
42#include <cstdint>
43
44#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseAdc.h"
45#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseCan.h"
46#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseGpio.h"
47#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseNvs.h"
48#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseSpi.h"
49#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseTemperature.h"
50#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseUart.h"
51#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseUsbSerialJtag.h"
52
53namespace flux::bsp {
54
55//==============================================================================
56// CAPACITIES — every binding sizes its static storage from these
57//==============================================================================
58
59inline constexpr size_t kMaxGpioSlots = 64;
60inline constexpr size_t kMaxSpiBuses = 2;
61inline constexpr size_t kMaxSpiDevicesPerBus = 4;
62inline constexpr size_t kMaxUartPorts = 3;
63inline constexpr size_t kMaxNvsRegions = 3;
64inline constexpr uint8_t kMaxInternalAdcChannels = 16;
65
66//==============================================================================
67// GPIO
68//==============================================================================
69
71struct GpioSpec {
72 hf_pin_num_t pin;
73 hf_gpio_direction_t direction;
74 hf_gpio_active_state_t active_state;
75 hf_gpio_output_mode_t output_mode;
76 hf_gpio_pull_mode_t pull_mode;
77};
78
85BaseGpio* CreateGpio(size_t slot, const GpioSpec& spec) noexcept;
86
88void DestroyGpio(size_t slot) noexcept;
89
90//==============================================================================
91// MCU ADC AND DIE TEMPERATURE
92//==============================================================================
93
95uint8_t InternalAdcChannelCount() noexcept;
96
103BaseAdc* CreateInternalAdc(uint8_t unit, uint32_t channel_mask) noexcept;
104
106void DestroyInternalAdc() noexcept;
107
109BaseTemperature* CreateDieTemperature() noexcept;
110
112void DestroyDieTemperature() noexcept;
113
114//==============================================================================
115// NVS
116//==============================================================================
117
124BaseNvs& NvsRegion(size_t slot, const char* name_space) noexcept;
125
126//==============================================================================
127// SPI
128//==============================================================================
129
132 uint8_t controller;
133 hf_pin_num_t miso;
134 hf_pin_num_t mosi;
135 hf_pin_num_t sclk;
137 uint32_t timeout_ms;
138};
139
142 hf_pin_num_t cs;
143 uint32_t clock_hz;
144 uint8_t mode;
145};
146
151bool CreateSpiBus(size_t bus, const SpiBusSpec& spec) noexcept;
152
157BaseSpi* CreateSpiDevice(size_t bus, const SpiDeviceSpec& spec) noexcept;
158
160void DestroySpiBus(size_t bus) noexcept;
161
162//==============================================================================
163// CAN
164//==============================================================================
165
167struct CanSpec {
168 hf_pin_num_t tx;
169 hf_pin_num_t rx;
170 uint32_t bitrate;
171};
172
174BaseCan* CreateCan(const CanSpec& spec) noexcept;
175
177void DestroyCan() noexcept;
178
179//==============================================================================
180// UART AND USB SERIAL/JTAG
181//==============================================================================
182
184struct UartSpec {
185 uint8_t port;
186 hf_pin_num_t tx;
187 hf_pin_num_t rx;
188 hf_pin_num_t rts;
189 hf_pin_num_t cts;
190 uint32_t baud;
191 uint16_t tx_buffer_size;
192 uint16_t rx_buffer_size;
193};
194
201BaseUart* CreateUart(const UartSpec& spec, bool* rs485) noexcept;
202
204void DestroyUart(uint8_t port) noexcept;
205
210BaseUsbSerialJtag* AcquireUsbSerialJtag(const hf_usb_serial_jtag_config_t& cfg) noexcept;
211
212//==============================================================================
213// STATUS LED STRIP
214//==============================================================================
215
218 hf_pin_num_t pin;
219 uint8_t channel;
220 uint16_t count;
221};
222
224bool LedStripBegin(const LedStripSpec& spec) noexcept;
225
227void LedStripSetPixel(uint16_t index, uint32_t rgb) noexcept;
228
230void LedStripSetBrightness(uint8_t brightness) noexcept;
231
233bool LedStripShow() noexcept;
234
236void LedStripEnd() noexcept;
237
238//==============================================================================
239// SYSTEM
240//==============================================================================
241
243uint32_t LastResetReason() noexcept;
244
246[[noreturn]] void SystemRestart() noexcept;
247
249uint32_t FreeHeapBytes() noexcept;
250
252uint32_t LargestFreeHeapBlock() noexcept;
253
254} // namespace flux::bsp
255
256#endif // FLUX_BSP_PLATFORM_BIND_H_
Definition FluxPlatformBindEsp32s3.cpp:37
BaseUsbSerialJtag * AcquireUsbSerialJtag(const hf_usb_serial_jtag_config_t &cfg) noexcept
The USB Serial/JTAG controller, initialised. nullptr when the family has none or the feature is compi...
Definition FluxPlatformBindEsp32s3.cpp:261
bool LedStripBegin(const LedStripSpec &spec) noexcept
Create and start the strip.
Definition FluxPlatformBindEsp32s3.cpp:311
bool CreateSpiBus(size_t bus, const SpiBusSpec &spec) noexcept
Create and initialise SPI bus bus.
Definition FluxPlatformBindEsp32s3.cpp:150
BaseAdc * CreateInternalAdc(uint8_t unit, uint32_t channel_mask) noexcept
Create and initialise the MCU ADC unit with the given channels enabled.
Definition FluxPlatformBindEsp32s3.cpp:89
uint32_t LastResetReason() noexcept
Opaque reset cause of the previous boot (family-specific numbering; 0 when unknown).
Definition FluxPlatformBindEsp32s3.cpp:332
constexpr size_t kMaxSpiBuses
SPI controllers in use.
Definition FluxPlatformBind.h:60
uint32_t FreeHeapBytes() noexcept
Free bytes in the default heap (0 when unknown).
Definition FluxPlatformBindEsp32s3.cpp:343
BaseGpio * CreateGpio(size_t slot, const GpioSpec &spec) noexcept
Create the GPIO object for slot. No hardware access until the object is initialised.
Definition FluxPlatformBindEsp32s3.cpp:67
void LedStripEnd() noexcept
Stop the strip and release its peripheral.
Definition FluxPlatformBindEsp32s3.cpp:325
BaseSpi * CreateSpiDevice(size_t bus, const SpiDeviceSpec &spec) noexcept
Add a device to an initialised SPI bus.
Definition FluxPlatformBindEsp32s3.cpp:174
uint8_t InternalAdcChannelCount() noexcept
Number of channels per unit of the MCU ADC (0 when the family has none).
Definition FluxPlatformBindEsp32s3.cpp:85
void DestroyCan() noexcept
Destroy the CAN controller.
Definition FluxPlatformBindEsp32s3.cpp:213
BaseNvs & NvsRegion(size_t slot, const char *name_space) noexcept
The NVS region in slot, created on first call for name_space (no flash access).
Definition FluxPlatformBindEsp32s3.cpp:137
void DestroySpiBus(size_t bus) noexcept
Destroy SPI bus bus and every device on it.
Definition FluxPlatformBindEsp32s3.cpp:190
void LedStripSetPixel(uint16_t index, uint32_t rgb) noexcept
Stage a 0xRRGGBB colour for LED index (sent on LedStripShow).
Definition FluxPlatformBindEsp32s3.cpp:315
void DestroyInternalAdc() noexcept
Destroy the MCU ADC unit.
Definition FluxPlatformBindEsp32s3.cpp:118
bool LedStripShow() noexcept
Send the staged colours.
Definition FluxPlatformBindEsp32s3.cpp:322
uint32_t LargestFreeHeapBlock() noexcept
Largest contiguous free block in the default heap (0 when unknown).
Definition FluxPlatformBindEsp32s3.cpp:347
constexpr size_t kMaxUartPorts
Hardware UART ports.
Definition FluxPlatformBind.h:62
BaseCan * CreateCan(const CanSpec &spec) noexcept
Create the CAN controller (configured, not started). nullptr on failure.
Definition FluxPlatformBindEsp32s3.cpp:201
constexpr size_t kMaxSpiDevicesPerBus
Chip selects per SPI bus.
Definition FluxPlatformBind.h:61
BaseUart * CreateUart(const UartSpec &spec, bool *rs485) noexcept
Create and initialise a UART. When spec.rts >= 0 the port is switched to RS-485 half duplex.
Definition FluxPlatformBindEsp32s3.cpp:221
void DestroyUart(uint8_t port) noexcept
Destroy the UART on port.
Definition FluxPlatformBindEsp32s3.cpp:255
constexpr uint8_t kMaxInternalAdcChannels
Upper bound on MCU ADC channels per unit.
Definition FluxPlatformBind.h:64
void SystemRestart() noexcept
Software reset of the MCU. Does not return.
Definition FluxPlatformBindEsp32s3.cpp:336
void DestroyDieTemperature() noexcept
Destroy the die-temperature sensor.
Definition FluxPlatformBindEsp32s3.cpp:129
constexpr size_t kMaxNvsRegions
NVS namespaces opened by NvsManager.
Definition FluxPlatformBind.h:63
BaseTemperature * CreateDieTemperature() noexcept
Create the MCU die-temperature sensor (not initialised). nullptr if the family has none.
Definition FluxPlatformBindEsp32s3.cpp:122
constexpr size_t kMaxGpioSlots
GPIO objects (one per functional pin index)
Definition FluxPlatformBind.h:59
void LedStripSetBrightness(uint8_t brightness) noexcept
Global brightness 0..255 applied to the next LedStripShow.
Definition FluxPlatformBindEsp32s3.cpp:319
void DestroyGpio(size_t slot) noexcept
Destroy the GPIO object in slot (releases the pin).
Definition FluxPlatformBindEsp32s3.cpp:75
The CAN controller and its pins.
Definition FluxPlatformBind.h:167
hf_pin_num_t rx
RX pin.
Definition FluxPlatformBind.h:169
hf_pin_num_t tx
TX pin.
Definition FluxPlatformBind.h:168
uint32_t bitrate
Nominal bit rate (bit/s)
Definition FluxPlatformBind.h:170
Electrical configuration of one MCU GPIO.
Definition FluxPlatformBind.h:71
hf_gpio_direction_t direction
Direction at creation (applied on first init)
Definition FluxPlatformBind.h:73
hf_gpio_active_state_t active_state
Logical active level.
Definition FluxPlatformBind.h:74
hf_gpio_output_mode_t output_mode
Push-pull or open-drain.
Definition FluxPlatformBind.h:75
hf_pin_num_t pin
MCU pin number.
Definition FluxPlatformBind.h:72
hf_gpio_pull_mode_t pull_mode
Internal pull resistor.
Definition FluxPlatformBind.h:76
An addressable RGB LED strip on one data pin.
Definition FluxPlatformBind.h:217
uint8_t channel
Peripheral channel (RMT on ESP32-S3)
Definition FluxPlatformBind.h:219
hf_pin_num_t pin
Data pin.
Definition FluxPlatformBind.h:218
uint16_t count
LEDs on the strip.
Definition FluxPlatformBind.h:220
One SPI controller and its pins.
Definition FluxPlatformBind.h:131
bool use_iomux
Route through the IO MUX (true) or the GPIO matrix (false)
Definition FluxPlatformBind.h:136
hf_pin_num_t mosi
MOSI pin.
Definition FluxPlatformBind.h:134
uint32_t timeout_ms
Transfer timeout.
Definition FluxPlatformBind.h:137
uint8_t controller
Family controller index (on ESP32-S3: 1 = SPI2_HOST, 2 = SPI3_HOST)
Definition FluxPlatformBind.h:132
hf_pin_num_t miso
MISO pin.
Definition FluxPlatformBind.h:133
hf_pin_num_t sclk
SCLK pin.
Definition FluxPlatformBind.h:135
One chip select on an SPI bus.
Definition FluxPlatformBind.h:141
uint32_t clock_hz
SCLK frequency.
Definition FluxPlatformBind.h:143
hf_pin_num_t cs
Chip-select pin.
Definition FluxPlatformBind.h:142
uint8_t mode
SPI mode 0..3 (CPOL/CPHA)
Definition FluxPlatformBind.h:144
One hardware UART, 8N1, no flow control.
Definition FluxPlatformBind.h:184
uint32_t baud
Baud rate.
Definition FluxPlatformBind.h:190
hf_pin_num_t rx
RX pin (-1 = leave unassigned)
Definition FluxPlatformBind.h:187
uint16_t tx_buffer_size
Driver TX ring size (bytes)
Definition FluxPlatformBind.h:191
uint16_t rx_buffer_size
Driver RX ring size (bytes)
Definition FluxPlatformBind.h:192
hf_pin_num_t rts
RTS / RS-485 DE pin (-1 = plain UART)
Definition FluxPlatformBind.h:188
hf_pin_num_t cts
CTS pin (-1 = none)
Definition FluxPlatformBind.h:189
uint8_t port
Port number below kMaxUartPorts.
Definition FluxPlatformBind.h:185
hf_pin_num_t tx
TX pin (-1 = leave unassigned)
Definition FluxPlatformBind.h:186