SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
SPIDeviceWithHal.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(SPIClass &spi, uint8_t csPin, int mosi = -1, int miso = -1, int sck = -1)
47 {
48 return beginLifecycle(0, COMM_SPI, COMM_SPI, [&]() {
49 return beginCommon<SensorCommSPI, HalArduino>(comm, hal, spi, csPin, mosi, miso, sck);
50 });
51 }
52#elif defined(ESP_PLATFORM)
59 bool begin(spi_host_device_t host, spi_device_handle_t handle,
60 uint8_t csPin, int mosi = -1, int miso = -1, int sck = -1)
61 {
62 return beginLifecycle(0, COMM_SPI, COMM_SPI, [&]() {
63 return beginCommon<SensorCommSPI, HalEspIDF>(comm, hal, host, handle, csPin, mosi, miso, sck);
64 });
65 }
66#endif
77 {
78 return beginLifecycle(0, COMM_CUSTOM, COMM_CUSTOM, [&]() {
79 return beginCommCustomCallback<SensorCommCustom, SensorCommCustomHal>(
80 COMM_CUSTOM, callback, hal_callback, 0x00, comm, hal);
81 });
82 }
83
84protected:
89 bool ensureValid() const override
90 {
91 if (!comm || !hal) return false;
92 return true;
93 }
94};
@license MIT License
@ COMM_CUSTOM
@ COMM_SPI
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 callback, SensorCommCustomHal::CustomHalCallback hal_callback)
Initialize the sensor using custom callback interface.
uint32_t(*)(Operation op, void *param1, void *param2) CustomHalCallback
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)