HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
As5047uHandler Class Reference

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

#include <As5047uHandler.h>

Collaboration diagram for As5047uHandler:
[legend]

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
 
As5047uHandleroperator= (const As5047uHandler &)=delete
 
 As5047uHandler (As5047uHandler &&)=delete
 
As5047uHandleroperator= (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.
 
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< As5047uSpiAdapterspi_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:

  • Lazy initialization pattern for optimal memory usage
  • Shared pointer management for safe cross-component sharing
  • Complete exception-free design for embedded reliability
  • Thread-safe operations with mutex protection
  • CRTP adapter integration with BaseSpi
  • High-level sensor abstraction
  • Advanced AS5047U features and diagnostics

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
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:

◆ EnsureInitialized()

bool As5047uHandler::EnsureInitialized ( )
noexcept

Ensure the handler is initialized (lazy init entrypoint).

Returns
true if initialized and ready.
Here is the call graph for this function:

◆ EnsureInitializedLocked()

bool As5047uHandler::EnsureInitializedLocked ( )
privatenoexcept

Ensure initialized while mutex is already held.

Returns
True if sensor is ready.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

◆ GetDriver() [1/2]

const as5047u::AS5047U< As5047uSpiAdapter > * As5047uHandler::GetDriver ( ) const
noexcept
Here is the call graph for this function:

◆ GetDriver() [2/2]

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

Naming-consistent alias of GetSensor().

Warning
Raw pointer — NOT mutex-protected. Prefer visitDriver().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLastError()

AS5047U_Error As5047uHandler::GetLastError ( ) const
noexcept

Get last error code.

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleSensorErrors()

void As5047uHandler::HandleSensorErrors ( uint16_t sensor_errors)
privatenoexcept

Handle sensor errors and update diagnostics.

Parameters
sensor_errorsError flags from sensor
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsInitialized()

bool As5047uHandler::IsInitialized ( ) const
noexcept

Check if sensor is initialized and ready.

Returns
True if sensor is ready for operations
Here is the caller graph for this function:

◆ 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

◆ UpdateDiagnostics()

void As5047uHandler::UpdateDiagnostics ( )
privatenoexcept

Update cached diagnostics.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ValidateSensor()

bool As5047uHandler::ValidateSensor ( )
privatenoexcept

Validate sensor parameters.

Returns
True if sensor is in valid state
Here is the call graph for this function:

◆ 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.
Here is the call graph for this function:

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: