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

Abstract base class for I2C device implementations in the HardFOC system. More...

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

Go to the source code of this file.

Classes

struct  hf_i2c_statistics_t
 I2C operation statistics. More...
 
struct  hf_i2c_diagnostics_t
 I2C diagnostic information. More...
 
class  BaseI2c
 Abstract base class for I2C device implementations. More...
 

Macros

#define HF_I2C_ERR_LIST(X)
 HardFOC I2C error codes.
 
#define X(NAME, VALUE, DESC)   NAME = VALUE,
 
#define X(NAME, VALUE, DESC)
 

Enumerations

enum class  hf_i2c_err_t : hf_u8_t {
  X , I2C_SUCCESS = 0 , I2C_ERR_FAILURE = 1 , I2C_ERR_NOT_INITIALIZED = 2 ,
  I2C_ERR_ALREADY_INITIALIZED = 3 , I2C_ERR_INVALID_PARAMETER = 4 , I2C_ERR_NULL_POINTER = 5 , I2C_ERR_OUT_OF_MEMORY = 6 ,
  I2C_ERR_BUS_BUSY = 7 , I2C_ERR_BUS_ERROR = 8 , I2C_ERR_BUS_ARBITRATION_LOST = 9 , I2C_ERR_BUS_NOT_AVAILABLE = 10 ,
  I2C_ERR_BUS_TIMEOUT = 11 , I2C_ERR_DEVICE_NOT_FOUND = 12 , I2C_ERR_DEVICE_NACK = 13 , I2C_ERR_DEVICE_NOT_RESPONDING = 14 ,
  I2C_ERR_INVALID_ADDRESS = 15 , I2C_ERR_DATA_TOO_LONG = 16 , I2C_ERR_READ_FAILURE = 17 , I2C_ERR_WRITE_FAILURE = 18 ,
  I2C_ERR_TIMEOUT = 19 , I2C_ERR_HARDWARE_FAULT = 20 , I2C_ERR_COMMUNICATION_FAILURE = 21 , I2C_ERR_VOLTAGE_OUT_OF_RANGE = 22 ,
  I2C_ERR_CLOCK_STRETCH_TIMEOUT = 23 , I2C_ERR_INVALID_CONFIGURATION = 24 , I2C_ERR_UNSUPPORTED_OPERATION = 25 , I2C_ERR_INVALID_CLOCK_SPEED = 26 ,
  I2C_ERR_PIN_CONFIGURATION_ERROR = 27 , I2C_ERR_SYSTEM_ERROR = 28 , I2C_ERR_PERMISSION_DENIED = 29 , I2C_ERR_OPERATION_ABORTED = 30 ,
  I2C_ERR_INVALID_STATE = 31 , I2C_ERR_UNKNOWN = 32
}
 

Functions

constexpr std::string_view HfI2CErrToString (hf_i2c_err_t err) noexcept
 Convert hf_i2c_err_t to human-readable string.
 

Detailed Description

Abstract base class for I2C device implementations in the HardFOC system.

This header-only file defines the abstract base class for I2C device communication that provides a consistent API across different I2C controller implementations. Concrete implementations for various microcontrollers inherit from this class. Each BaseI2c instance represents a single I2C device with a pre-configured address.

Author
Nebiyu Tadesse
Date
2025
Note
This is a header-only abstract base class following the same pattern as BaseCan.
Users should program against this interface, not specific implementations.
Each BaseI2c instance represents a specific I2C device, not the I2C bus itself.

Macro Definition Documentation

◆ X [1/2]

#define X ( NAME,
VALUE,
DESC )   NAME = VALUE,

◆ X [2/2]

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

Enumeration Type Documentation

◆ hf_i2c_err_t

enum class hf_i2c_err_t : hf_u8_t
strong
Enumerator
I2C_SUCCESS 
I2C_ERR_FAILURE 
I2C_ERR_NOT_INITIALIZED 
I2C_ERR_ALREADY_INITIALIZED 
I2C_ERR_INVALID_PARAMETER 
I2C_ERR_NULL_POINTER 
I2C_ERR_OUT_OF_MEMORY 
I2C_ERR_BUS_BUSY 
I2C_ERR_BUS_ERROR 
I2C_ERR_BUS_ARBITRATION_LOST 
I2C_ERR_BUS_NOT_AVAILABLE 
I2C_ERR_BUS_TIMEOUT 
I2C_ERR_DEVICE_NOT_FOUND 
I2C_ERR_DEVICE_NACK 
I2C_ERR_DEVICE_NOT_RESPONDING 
I2C_ERR_INVALID_ADDRESS 
I2C_ERR_DATA_TOO_LONG 
I2C_ERR_READ_FAILURE 
I2C_ERR_WRITE_FAILURE 
I2C_ERR_TIMEOUT 
I2C_ERR_HARDWARE_FAULT 
I2C_ERR_COMMUNICATION_FAILURE 
I2C_ERR_VOLTAGE_OUT_OF_RANGE 
I2C_ERR_CLOCK_STRETCH_TIMEOUT 
I2C_ERR_INVALID_CONFIGURATION 
I2C_ERR_UNSUPPORTED_OPERATION 
I2C_ERR_INVALID_CLOCK_SPEED 
I2C_ERR_PIN_CONFIGURATION_ERROR 
I2C_ERR_SYSTEM_ERROR 
I2C_ERR_PERMISSION_DENIED 
I2C_ERR_OPERATION_ABORTED 
I2C_ERR_INVALID_STATE 
I2C_ERR_UNKNOWN 

Function Documentation

◆ HfI2CErrToString()

constexpr std::string_view HfI2CErrToString ( hf_i2c_err_t err)
constexprnoexcept

Convert hf_i2c_err_t to human-readable string.

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