SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
I2CDeviceWithHal.hpp
Go to the documentation of this file.
1
30#pragma once
31#include "DeviceBeginCommon.hpp"
32
34{
35public:
36#if defined(ARDUINO)
46 bool begin(TwoWire &wire, uint8_t addr, int sda = -1, int scl = -1)
47 {
48 return beginLifecycle(addr, COMM_I2C, addr, [&]() {
49 return beginCommon<SensorCommI2C, HalArduino>(comm, hal, wire, addr, sda, scl);
50 });
51 }
52
53#elif defined(ESP_PLATFORM)
54#if defined(SENSORLIB_USE_I2C_LEGACY)
63 bool begin(i2c_port_t port, uint8_t addr, int sda = -1, int scl = -1)
64 {
65 return beginLifecycle(addr, COMM_I2C, addr, [&]() {
66 return beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, port, addr, sda, scl);
67 });
68 }
69#else
76 bool begin(i2c_master_bus_handle_t handle, uint8_t addr)
77 {
78 return beginLifecycle(addr, COMM_I2C, addr, [&]() {
79 return beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, handle, addr);
80 });
81 }
82#endif //SENSORLIB_USE_I2C_LEGACY
83#endif //ARDUINO
93 bool begin(SensorCommCustom::CustomCallback cb,
95 uint8_t addr)
96 {
97 return beginLifecycle(addr, COMM_CUSTOM, addr, [&]() {
98 return beginCommCustomCallback<SensorCommCustom, SensorCommCustomHal>(
99 COMM_CUSTOM, cb, hal_cb, addr, comm, hal);
100 });
101 }
102protected:
107 bool ensureValid() const override
108 {
109 if (!comm || !hal) return false;
110 return true;
111 }
112};
@license MIT License
@ COMM_CUSTOM
@ COMM_I2C
std::unique_ptr< SensorCommBase > comm
bool beginLifecycle(uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm)
std::unique_ptr< SensorHal > hal
bool ensureValid() const override
Ensure the communication interface is valid.
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
uint32_t(*)(Operation op, void *param1, void *param2) CustomHalCallback