HardFOC Core
API reference
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
As5047uHandler Class Reference

Unified handler for AS5047U magnetic rotary position sensor. More...

#include <As5047uHandler.h>

Public Member Functions

 As5047uHandler (BaseSpi &spi_interface, const As5047uConfig &config=GetDefaultConfig()) noexcept
 Construct AS5047U handler with SPI interface.
 
 ~As5047uHandler () noexcept=default
 Destructor - automatically handles cleanup.
 
 As5047uHandler (const As5047uHandler &)=delete
 
As5047uHandler & operator= (const As5047uHandler &)=delete
 
 As5047uHandler (As5047uHandler &&)=delete
 
As5047uHandler & operator= (As5047uHandler &&)=delete
 
bool Initialize () noexcept
 Initialize the AS5047U sensor (lazy initialization)
 
bool EnsureInitialized () noexcept
 Ensure the handler is initialized (lazy init entrypoint).
 
bool Deinitialize () noexcept
 Deinitialize the sensor and free resources.
 
bool IsInitialized () const noexcept
 Check if sensor is initialized and ready.
 
bool IsSensorReady () const noexcept
 Check if sensor driver is ready (lazy initialization helper)
 
as5047u::AS5047U< As5047uSpiAdapter > * GetSensor () noexcept
 Get pointer to AS5047U driver for advanced operations.
 
as5047u::AS5047U< As5047uSpiAdapter > * GetDriver () noexcept
 Naming-consistent alias of GetSensor().
 
const as5047u::AS5047U< As5047uSpiAdapter > * GetDriver () const noexcept
 
template<typename Fn >
auto visitDriver (Fn &&fn) noexcept -> decltype(fn(std::declval< as5047u::AS5047U< As5047uSpiAdapter > & >()))
 Visit the underlying AS5047U driver under handler mutex protection.
 
const char * GetDescription () const noexcept
 Get sensor description string.
 
AS5047U_Error GetLastError () const noexcept
 Get last error code.
 
As5047uDiagnostics GetDiagnostics () const noexcept
 Snapshot of the diagnostics cached at the last refresh.
 
bool RefreshDiagnostics () noexcept
 Read ERRFL from the sensor and update the cached diagnostics.
 
void DumpDiagnostics () const noexcept
 Dump comprehensive diagnostics and statistics to log as INFO level. Logs AS5047U sensor status, communication health, and measurement statistics.
 

Static Public Member Functions

static As5047uConfig GetDefaultConfig () noexcept
 Get default sensor configuration.
 

Private Member Functions

bool ValidateSensor () noexcept
 Validate sensor parameters.
 
bool EnsureInitializedLocked () noexcept
 Ensure initialized while mutex is already held.
 
void HandleSensorErrors (uint16_t sensor_errors) noexcept
 Handle sensor errors and update diagnostics.
 
void UpdateDiagnostics () noexcept
 Update cached diagnostics.
 
bool ApplyConfiguration (const As5047uConfig &config) noexcept
 Apply configuration to sensor.
 

Private Attributes

BaseSpi & spi_ref_
 Reference to SPI interface.
 
std::unique_ptr< As5047uSpiAdapter > spi_adapter_
 SPI CRTP adapter.
 
std::unique_ptr< as5047u::AS5047U< As5047uSpiAdapter > > as5047u_sensor_
 AS5047U driver instance.
 
As5047uConfig config_
 Sensor configuration.
 
RtosMutex handler_mutex_
 Thread safety mutex.
 
bool initialized_
 Initialization state.
 
AS5047U_Error last_error_
 Last driver-reported error flags.
 
As5047uDiagnostics diagnostics_
 Cached diagnostics.
 
char description_ [64]
 Sensor description.
 

Detailed Description

Unified handler for AS5047U magnetic rotary position sensor.

This class provides a comprehensive interface for the AS5047U sensor with:

Architecture follows the same excellence as TMC9660Handler and PCAL95555Handler.

Constructor & Destructor Documentation

◆ As5047uHandler() [1/3]

As5047uHandler::As5047uHandler ( BaseSpi &  spi_interface,
const As5047uConfig &  config = GetDefaultConfig() 
)
explicitnoexcept

Construct AS5047U handler with SPI interface.

Parameters
spi_interfaceReference to BaseSpi implementation
configInitial sensor configuration

Note: Lightweight constructor following lazy initialization pattern. Objects are created during Initialize() call.

◆ ~As5047uHandler()

As5047uHandler::~As5047uHandler ( )
defaultnoexcept

Destructor - automatically handles cleanup.

◆ As5047uHandler() [2/3]

As5047uHandler::As5047uHandler ( const As5047uHandler &  )
delete

◆ As5047uHandler() [3/3]

As5047uHandler::As5047uHandler ( As5047uHandler &&  )
delete

Member Function Documentation

◆ ApplyConfiguration()

bool As5047uHandler::ApplyConfiguration ( const As5047uConfig &  config)
privatenoexcept

Apply configuration to sensor.

Parameters
configConfiguration to apply
Returns
True if successful

◆ Deinitialize()

bool As5047uHandler::Deinitialize ( )
noexcept

Deinitialize the sensor and free resources.

Returns
true if successful

◆ DumpDiagnostics()

void As5047uHandler::DumpDiagnostics ( ) const
noexcept

Dump comprehensive diagnostics and statistics to log as INFO level. Logs AS5047U sensor status, communication health, and measurement statistics.

◆ EnsureInitialized()

bool As5047uHandler::EnsureInitialized ( )
noexcept

Ensure the handler is initialized (lazy init entrypoint).

Returns
true if initialized and ready.

◆ EnsureInitializedLocked()

bool As5047uHandler::EnsureInitializedLocked ( )
privatenoexcept

Ensure initialized while mutex is already held.

Returns
True if sensor is ready.

◆ GetDefaultConfig()

As5047uConfig As5047uHandler::GetDefaultConfig ( )
staticnoexcept

Get default sensor configuration.

Returns
Default As5047uConfig structure

◆ GetDescription()

const char * As5047uHandler::GetDescription ( ) const
noexcept

Get sensor description string.

Returns
Description of the sensor

◆ GetDiagnostics()

As5047uDiagnostics As5047uHandler::GetDiagnostics ( ) const
noexcept

Snapshot of the diagnostics cached at the last refresh.

Refreshed by Initialize() and RefreshDiagnostics(); reading this does not touch the bus.

◆ GetDriver() [1/2]

const as5047u::AS5047U< As5047uSpiAdapter > * As5047uHandler::GetDriver ( ) const
noexcept

◆ GetDriver() [2/2]

as5047u::AS5047U< As5047uSpiAdapter > * As5047uHandler::GetDriver ( )
noexcept

Naming-consistent alias of GetSensor().

Warning
Raw pointer — NOT mutex-protected. Prefer visitDriver().

◆ GetLastError()

AS5047U_Error As5047uHandler::GetLastError ( ) const
noexcept

Get last error code.

After a failed Initialize() these are the sticky flags the driver collected during it (link errors include BusError and ReplyCrcError). Initialize() clears the driver's sticky flags; the driver's GetStickyErrorFlags() no longer clears them, call ClearStickyErrorFlags() through visitDriver() for that.

Returns
Last error that occurred

◆ GetSensor()

as5047u::AS5047U< As5047uSpiAdapter > * As5047uHandler::GetSensor ( )
noexcept

Get pointer to AS5047U driver for advanced operations.

Returns
Pointer to AS5047U driver or nullptr if not initialized
Warning
Raw pointer — NOT mutex-protected. Caller is responsible for external synchronization in multi-task environments. Prefer visitDriver() for thread-safe access.

Note: Caller must not delete the returned pointer; lifetime is owned by the handler.

◆ HandleSensorErrors()

void As5047uHandler::HandleSensorErrors ( uint16_t  sensor_errors)
privatenoexcept

Handle sensor errors and update diagnostics.

Parameters
sensor_errorsError flags from sensor

◆ Initialize()

bool As5047uHandler::Initialize ( )
noexcept

Initialize the AS5047U sensor (lazy initialization)

Returns
true if successful, false otherwise

Creates AS5047U driver instance and performs sensor initialization. Safe to call multiple times - subsequent calls return current status.

◆ IsInitialized()

bool As5047uHandler::IsInitialized ( ) const
noexcept

Check if sensor is initialized and ready.

Returns
True if sensor is ready for operations

◆ IsSensorReady()

bool As5047uHandler::IsSensorReady ( ) const
noexcept

Check if sensor driver is ready (lazy initialization helper)

Returns
True if driver instance exists and is ready

◆ operator=() [1/2]

As5047uHandler & As5047uHandler::operator= ( As5047uHandler &&  )
delete

◆ operator=() [2/2]

As5047uHandler & As5047uHandler::operator= ( const As5047uHandler &  )
delete

◆ RefreshDiagnostics()

bool As5047uHandler::RefreshDiagnostics ( )
noexcept

Read ERRFL from the sensor and update the cached diagnostics.

Returns
false if the handler could not be initialized.

◆ UpdateDiagnostics()

void As5047uHandler::UpdateDiagnostics ( )
privatenoexcept

Update cached diagnostics.

◆ ValidateSensor()

bool As5047uHandler::ValidateSensor ( )
privatenoexcept

Validate sensor parameters.

Returns
True if sensor is in valid state

◆ visitDriver()

template<typename Fn >
auto As5047uHandler::visitDriver ( Fn &&  fn) -> decltype(fn(std::declval<as5047u::AS5047U<As5047uSpiAdapter>&>()))
inlinenoexcept

Visit the underlying AS5047U driver under handler mutex protection.

Returns
Callable result or default-constructed value when driver is unavailable.

Member Data Documentation

◆ as5047u_sensor_

std::unique_ptr<as5047u::AS5047U<As5047uSpiAdapter> > As5047uHandler::as5047u_sensor_
private

AS5047U driver instance.

◆ config_

As5047uConfig As5047uHandler::config_
private

Sensor configuration.

◆ description_

char As5047uHandler::description_[64]
private

Sensor description.

◆ diagnostics_

As5047uDiagnostics As5047uHandler::diagnostics_
mutableprivate

Cached diagnostics.

◆ handler_mutex_

RtosMutex As5047uHandler::handler_mutex_
mutableprivate

Thread safety mutex.

◆ initialized_

bool As5047uHandler::initialized_
private

Initialization state.

◆ last_error_

AS5047U_Error As5047uHandler::last_error_
mutableprivate

Last driver-reported error flags.

◆ spi_adapter_

std::unique_ptr<As5047uSpiAdapter> As5047uHandler::spi_adapter_
private

SPI CRTP adapter.

◆ spi_ref_

BaseSpi& As5047uHandler::spi_ref_
private

Reference to SPI interface.


The documentation for this class was generated from the following files: