HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
BasePwm.h File Reference

Abstract base class for PWM implementations in the HardFOC system. More...

#include "HardwareTypes.h"
#include <cstdint>
#include <string_view>
Include dependency graph for BasePwm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hf_pwm_statistics_t
 PWM statistics information. More...
 
struct  hf_pwm_diagnostics_t
 PWM diagnostics information. More...
 
class  BasePwm
 Abstract base class for PWM implementations. More...
 

Macros

#define HF_PWM_ERR_LIST(X)
 HardFOC PWM error codes.
 
#define X(name, value, description)   name = value,
 
#define X(NAME, VALUE, DESC)
 

Typedefs

using hf_pwm_period_callback_t = void (*)(hf_channel_id_t channel_id, void* user_data)
 Callback for PWM period complete events.
 
using hf_pwm_fault_callback_t
 Callback for PWM fault/error events.
 

Enumerations

enum class  hf_pwm_err_t : hf_u32_t {
  X , PWM_SUCCESS = 0 , PWM_ERR_FAILURE = 1 , PWM_ERR_NOT_INITIALIZED = 2 ,
  PWM_ERR_ALREADY_INITIALIZED = 3 , PWM_ERR_INVALID_PARAMETER = 4 , PWM_ERR_NULL_POINTER = 5 , PWM_ERR_OUT_OF_MEMORY = 6 ,
  PWM_ERR_INVALID_CHANNEL = 7 , PWM_ERR_CHANNEL_BUSY = 8 , PWM_ERR_CHANNEL_NOT_AVAILABLE = 9 , PWM_ERR_INSUFFICIENT_CHANNELS = 10 ,
  PWM_ERR_INVALID_FREQUENCY = 11 , PWM_ERR_FREQUENCY_TOO_HIGH = 12 , PWM_ERR_FREQUENCY_TOO_LOW = 13 , PWM_ERR_RESOLUTION_NOT_SUPPORTED = 14 ,
  PWM_ERR_INVALID_DUTY_CYCLE = 15 , PWM_ERR_DUTY_OUT_OF_RANGE = 16 , PWM_ERR_HARDWARE_FAULT = 17 , PWM_ERR_TIMER_CONFLICT = 18 ,
  PWM_ERR_PIN_CONFLICT = 19 , PWM_ERR_COMMUNICATION_TIMEOUT = 20 , PWM_ERR_COMMUNICATION_FAILURE = 21 , PWM_ERR_DEVICE_NOT_RESPONDING = 22 ,
  PWM_ERR_INVALID_DEVICE_ID = 23 , PWM_ERR_UNSUPPORTED_OPERATION = 24 , PWM_ERR_UNKNOWN = 25 , PWM_ERR_COUNT
}
 

Functions

constexpr std::string_view HfPwmErrToString (hf_pwm_err_t err) noexcept
 Convert PWM error code to string view.
 

Detailed Description

Abstract base class for PWM implementations in the HardFOC system.

This header-only file defines the abstract base class for PWM generation that provides a consistent API across different PWM implementations. Concrete implementations for various platforms inherit from this class.

Author
Nebiyu Tadesse
Date
2025
Note
This is a header-only abstract base class following the same pattern as BaseCan/BaseAdc.
Users should program against this interface, not specific implementations.

Macro Definition Documentation

◆ X [1/2]

#define X ( NAME,
VALUE,
DESC )
Value:
case hf_pwm_err_t::NAME: \
return DESC;

◆ X [2/2]

#define X ( name,
value,
description )   name = value,

Typedef Documentation

◆ hf_pwm_fault_callback_t

Initial value:
void (*)(hf_channel_id_t channel_id, hf_pwm_err_t error, void* user_data)
hf_pwm_err_t
Definition BasePwm.h:76
hf_u32_t hf_channel_id_t
Platform-agnostic channel identifier type.
Definition HardwareTypes.h:163

Callback for PWM fault/error events.

Parameters
channel_idChannel that encountered fault
errorError that occurred
user_dataUser-provided data

◆ hf_pwm_period_callback_t

using hf_pwm_period_callback_t = void (*)(hf_channel_id_t channel_id, void* user_data)

Callback for PWM period complete events.

Parameters
channel_idChannel that completed a period
user_dataUser-provided data

Enumeration Type Documentation

◆ hf_pwm_err_t

enum class hf_pwm_err_t : hf_u32_t
strong
Enumerator
PWM_SUCCESS 
PWM_ERR_FAILURE 
PWM_ERR_NOT_INITIALIZED 
PWM_ERR_ALREADY_INITIALIZED 
PWM_ERR_INVALID_PARAMETER 
PWM_ERR_NULL_POINTER 
PWM_ERR_OUT_OF_MEMORY 
PWM_ERR_INVALID_CHANNEL 
PWM_ERR_CHANNEL_BUSY 
PWM_ERR_CHANNEL_NOT_AVAILABLE 
PWM_ERR_INSUFFICIENT_CHANNELS 
PWM_ERR_INVALID_FREQUENCY 
PWM_ERR_FREQUENCY_TOO_HIGH 
PWM_ERR_FREQUENCY_TOO_LOW 
PWM_ERR_RESOLUTION_NOT_SUPPORTED 
PWM_ERR_INVALID_DUTY_CYCLE 
PWM_ERR_DUTY_OUT_OF_RANGE 
PWM_ERR_HARDWARE_FAULT 
PWM_ERR_TIMER_CONFLICT 
PWM_ERR_PIN_CONFLICT 
PWM_ERR_COMMUNICATION_TIMEOUT 
PWM_ERR_COMMUNICATION_FAILURE 
PWM_ERR_DEVICE_NOT_RESPONDING 
PWM_ERR_INVALID_DEVICE_ID 
PWM_ERR_UNSUPPORTED_OPERATION 
PWM_ERR_UNKNOWN 
PWM_ERR_COUNT 

Function Documentation

◆ HfPwmErrToString()

constexpr std::string_view HfPwmErrToString ( hf_pwm_err_t err)
constexprnoexcept

Convert PWM error code to string view.

Parameters
errThe error code to convert
Returns
String view of the error description