SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
SensorCommBase.hpp File Reference

@license MIT License More...

#include "SensorLib.h"
#include <memory>
#include "SensorErrorMixin.hpp"
Include dependency graph for SensorCommBase.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CommParamsBase
 Abstract base for all communication parameter objects. More...
 
class  I2CParam
 I2C communication parameters. More...
 
class  SPISettings
 Emulation of Arduino's SPISettings class. More...
 
class  SPIParam
 SPI communication parameters. More...
 
class  SensorCommBase
 Abstract base class for low‑level sensor communication. More...
 
class  SensorHalCustom
 Customisation point for low‑level GPIO callbacks. More...
 
class  SensorHal
 Abstract hardware abstraction layer. More...
 

Macros

#define SPI_MODE0   0
 CPOL = 0, CPHA = 0.
 
#define SPI_MODE1   1
 CPOL = 0, CPHA = 1.
 
#define SPI_MODE2   2
 CPOL = 1, CPHA = 0.
 
#define SPI_MODE3   3
 CPOL = 1, CPHA = 1.
 
#define SPI_LSB   0
 Least significant bit first.
 
#define SPI_MSB   1
 Most significant bit first.
 

Functions

template<typename T , size_t N>
constexpr size_t arraySize (const T(&arr)[N])
 Returns the number of elements in a C‑style array at compile time.
 

Detailed Description

@license MIT License

Copyright (c) 2025 lewis he

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
Lewis He (lewis.nosp@m.he@o.nosp@m.utloo.nosp@m.k.co.nosp@m.m)
Date
2025-01-18
Note
This header provides utility functions and base classes for sensor communication and hardware abstraction.

It includes:

  • A fallback std::make_unique for C++11.
  • A compile-time array size helper.
  • Base parameter classes for I2C and SPI settings.
  • Abstract interface for sensor communication (SensorCommBase).
  • Hardware abstraction layers (SensorHalCustom and SensorHal).

Definition in file SensorCommBase.hpp.

Macro Definition Documentation

◆ SPI_LSB

#define SPI_LSB   0

Least significant bit first.

Definition at line 159 of file SensorCommBase.hpp.

◆ SPI_MODE0

#define SPI_MODE0   0

CPOL = 0, CPHA = 0.

Definition at line 154 of file SensorCommBase.hpp.

◆ SPI_MODE1

#define SPI_MODE1   1

CPOL = 0, CPHA = 1.

Definition at line 155 of file SensorCommBase.hpp.

◆ SPI_MODE2

#define SPI_MODE2   2

CPOL = 1, CPHA = 0.

Definition at line 156 of file SensorCommBase.hpp.

◆ SPI_MODE3

#define SPI_MODE3   3

CPOL = 1, CPHA = 1.

Definition at line 157 of file SensorCommBase.hpp.

◆ SPI_MSB

#define SPI_MSB   1

Most significant bit first.

Definition at line 160 of file SensorCommBase.hpp.

Function Documentation

◆ arraySize()

template<typename T , size_t N>
constexpr size_t arraySize ( const T(&)  arr[N])
constexpr

Returns the number of elements in a C‑style array at compile time.

Template Parameters
TElement type.
NArray size (deduced).
Parameters
arrReference to the array.
Returns
constexpr size_t Number of elements (N).

Definition at line 78 of file SensorCommBase.hpp.

Referenced by GaugeBQ27220::getChipID(), GaugeBQ27220::getFirmwareVersion(), GaugeBQ27220::getHardwareVersion(), and TouchDrvCHSC5816::sleep().