HardFOC Core
API reference
Loading...
Searching...
No Matches
Pf1550Handler.h
Go to the documentation of this file.
1
19#ifndef COMPONENT_HANDLER_PF1550_HANDLER_H_
20#define COMPONENT_HANDLER_PF1550_HANDLER_H_
21
22#include <cstdint>
23#include <memory>
24#include <span>
25
26#include "RtosMutex.h"
27#include "base/BaseGpio.h"
28#include "base/BaseI2c.h"
29
30#include "core/hf-core-drivers/external/hf-pf1550-driver/inc/pf1550.hpp"
31
40class HalPf1550Comm : public pf1550::BusInterface<HalPf1550Comm> {
41public:
42 HalPf1550Comm(BaseI2c& i2c, BaseGpio* standby_gpio, BaseGpio* usb_vbus_en_gpio,
43 BaseGpio* usb_otg_en_gpio) noexcept;
44
46 bool Write(uint8_t addr, uint8_t reg, const uint8_t* data, size_t len) noexcept;
48 bool Read(uint8_t addr, uint8_t reg, uint8_t* data, size_t len) noexcept;
50 bool EnsureInitialized() noexcept;
52 void GpioSet(pf1550::CtrlPin pin, pf1550::GpioSignal signal) noexcept;
54 void DelayUs(uint32_t us) noexcept;
55
56private:
57 BaseI2c& i2c_;
58 BaseGpio* standby_gpio_;
61 mutable RtosMutex i2c_mutex_;
62};
63
83public:
85 using Pf1550Driver = pf1550::PF1550<HalPf1550Comm>;
86
94 Pf1550Handler(BaseI2c& i2c, BaseGpio* standby_gpio = nullptr,
95 BaseGpio* usb_vbus_en_gpio = nullptr,
96 BaseGpio* usb_otg_en_gpio = nullptr) noexcept;
97
98 Pf1550Handler(const Pf1550Handler&) = delete;
99 Pf1550Handler& operator=(const Pf1550Handler&) = delete;
100
102 bool EnsureInitialized() noexcept;
104 bool IsInitialized() const noexcept { return initialized_; }
105
110 bool ApplyProfile(std::span<const pf1550::profiles::RegisterWrite> profile) noexcept;
111
117 bool ApplyPortentaH7Profile() noexcept;
123 bool ApplyPortentaH7CarrierProfile() noexcept;
124
126 bool SetPowerMode(pf1550::PowerMode mode) noexcept;
128 bool SetUsbRails(bool vbus_en, bool otg_en) noexcept;
130 bool ReadPmicStatus(uint8_t& status) noexcept;
131
132 // --- Diagnostics surface ----------------------------------------------
133
140 bool RefreshDiagnosticSnapshot() noexcept;
147 bool RefreshStatusSnapshot() noexcept;
148
153 bool ReadDiagnosticSnapshot(pf1550::DiagnosticSnapshot& out) noexcept;
154
162 bool RunPowerSelfTest(pf1550::SelfTestResult& out) noexcept;
163
165 bool ClearLatchedFaults() noexcept;
166
171 bool HasMcuAffectingFault() noexcept;
172
174 Pf1550Driver* GetDriver() noexcept;
176 const Pf1550Driver* GetDriver() const noexcept;
177
178private:
179 bool ensureInitializedLocked() noexcept;
180
181 BaseI2c& i2c_;
182 BaseGpio* standby_gpio_;
185 std::unique_ptr<HalPf1550Comm> comm_;
186 std::unique_ptr<Pf1550Driver> driver_;
188 pf1550::DiagnosticSnapshot cached_snapshot_;
190 mutable RtosMutex handler_mutex_;
191};
192
193#endif // COMPONENT_HANDLER_PF1550_HANDLER_H_
CRTP pf1550::BusInterface adapter mapping driver calls onto BaseI2c + optional BaseGpio strap pins.
Definition Pf1550Handler.h:40
bool Read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) noexcept
Repeated-start read of len bytes from register reg.
Definition Pf1550Handler.cpp:52
void GpioSet(pf1550::CtrlPin pin, pf1550::GpioSignal signal) noexcept
Drive a CtrlPin strap GPIO Active/Inactive.
Definition Pf1550Handler.cpp:62
BaseGpio * usb_vbus_en_gpio_
Definition Pf1550Handler.h:59
bool EnsureInitialized() noexcept
Idempotently bring up the underlying I²C peripheral.
Definition Pf1550Handler.cpp:60
BaseI2c & i2c_
Definition Pf1550Handler.h:57
bool Write(uint8_t addr, uint8_t reg, const uint8_t *data, size_t len) noexcept
Write len data bytes after register pointer reg.
Definition Pf1550Handler.cpp:36
BaseGpio * usb_otg_en_gpio_
Definition Pf1550Handler.h:60
void DelayUs(uint32_t us) noexcept
Coarse µs-precision delay used between profile writes.
Definition Pf1550Handler.cpp:78
BaseGpio * standby_gpio_
Definition Pf1550Handler.h:58
RtosMutex i2c_mutex_
Definition Pf1550Handler.h:61
Thread-safe PF1550 PMIC HAL handler.
Definition Pf1550Handler.h:82
BaseI2c & i2c_
Definition Pf1550Handler.h:181
bool ensureInitializedLocked() noexcept
Definition Pf1550Handler.cpp:96
bool SetUsbRails(bool vbus_en, bool otg_en) noexcept
Drive USB_VBUS_EN / USB_OTG_EN straps.
Definition Pf1550Handler.cpp:152
std::unique_ptr< HalPf1550Comm > comm_
Definition Pf1550Handler.h:185
BaseGpio * usb_vbus_en_gpio_
Definition Pf1550Handler.h:183
bool RunPowerSelfTest(pf1550::SelfTestResult &out) noexcept
Run boot-time self-test (uses internal snapshot path).
Definition Pf1550Handler.cpp:195
bool initialized_
Definition Pf1550Handler.h:187
bool RefreshStatusSnapshot() noexcept
Refresh the status part of the cached snapshot only (driver RefreshStatusSnapshot); identity and rail...
Definition Pf1550Handler.cpp:177
bool SetPowerMode(pf1550::PowerMode mode) noexcept
Drive STANDBY strap to RUN or STANDBY.
Definition Pf1550Handler.cpp:144
bool have_full_snapshot_
cached_snapshot_ holds a successful full read
Definition Pf1550Handler.h:189
bool IsInitialized() const noexcept
Has EnsureInitialized ever succeeded?
Definition Pf1550Handler.h:104
pf1550::DiagnosticSnapshot cached_snapshot_
Definition Pf1550Handler.h:188
BaseGpio * usb_otg_en_gpio_
Definition Pf1550Handler.h:184
bool HasMcuAffectingFault() noexcept
Convenience: are any currently-latched faults of severity kCritical or kMcuKill?
Definition Pf1550Handler.cpp:216
bool RefreshDiagnosticSnapshot() noexcept
Refresh the cached snapshot by re-reading the PMIC.
Definition Pf1550Handler.cpp:168
bool EnsureInitialized() noexcept
Idempotent — verify DEVICE_ID and prime the bus adapter.
Definition Pf1550Handler.cpp:114
bool ApplyPortentaH7Profile() noexcept
Driver-named Arduino Portenta H7 eval sequence (legacy VFR order).
Definition Pf1550Handler.cpp:128
bool ApplyPortentaH7CarrierProfile() noexcept
Driver-named Portenta-H7-on-carrier eval sequence (SW1-first).
Definition Pf1550Handler.cpp:136
bool ReadPmicStatus(uint8_t &status) noexcept
Read STATE_INFO (0x67).
Definition Pf1550Handler.cpp:160
Pf1550Driver * GetDriver() noexcept
Expose raw driver (advanced use only — does not lock).
Definition Pf1550Handler.cpp:226
bool ReadDiagnosticSnapshot(pf1550::DiagnosticSnapshot &out) noexcept
Copy the cached snapshot out (zero-copy not provided to keep the API thread-safe).
Definition Pf1550Handler.cpp:189
pf1550::PF1550< HalPf1550Comm > Pf1550Driver
Alias for the templated driver type.
Definition Pf1550Handler.h:85
RtosMutex handler_mutex_
Definition Pf1550Handler.h:190
bool ApplyProfile(std::span< const pf1550::profiles::RegisterWrite > profile) noexcept
Apply an ordered register-write sequence.
Definition Pf1550Handler.cpp:119
std::unique_ptr< Pf1550Driver > driver_
Definition Pf1550Handler.h:186
BaseGpio * standby_gpio_
Definition Pf1550Handler.h:182
bool ClearLatchedFaults() noexcept
Clear every RW1C latched fault status register.
Definition Pf1550Handler.cpp:208