11#ifndef M5_UNIT_COMPONENT_ADAPTER_HPP
12#define M5_UNIT_COMPONENT_ADAPTER_HPP
32 explicit Adapter(
const uint8_t addr);
33 Adapter(TwoWire& wire,
const uint8_t addr);
34 Adapter(m5::hal::bus::Bus* bus,
const uint8_t addr);
35 Adapter(m5::hal::bus::Bus& bus,
const uint8_t addr) :
Adapter(&bus, addr)
49 inline uint8_t address()
const
51 return _impl->address();
54 inline uint32_t clock()
const
56 return _impl->clock();
58 inline void setClock(
const uint32_t clock)
60 return _impl->setClock(clock);
76 m5::hal::error::error_t
generalCall(
const uint8_t* data,
const size_t len);
83 return _impl->readWithTransaction(data, len);
86 inline m5::hal::error::error_t
writeWithTransaction(
const uint8_t* data,
const size_t len,
const bool stop =
true)
88 return _impl->writeWithTransaction(data, len, stop);
91 inline m5::hal::error::error_t
writeWithTransaction(
const uint8_t reg,
const uint8_t* data,
const size_t len,
92 const bool stop =
true)
94 return _impl->writeWithTransaction(reg, data, len, stop);
97 inline m5::hal::error::error_t
writeWithTransaction(
const uint16_t reg,
const uint8_t* data,
const size_t len,
98 const bool stop =
true)
100 return _impl->writeWithTransaction(reg, data, len, stop);
110 return _impl->begin();
116 void pinMode(uint8_t pin, uint8_t mode)
118 _impl->pinMode(pin, mode);
120 void digitalWrite(uint8_t pin, uint8_t val)
122 _impl->digitalWrite(pin, val);
132 explicit Impl(
const uint8_t addr) : _addr(addr)
135 Impl(
const uint8_t addr,
const uint32_t clock) : _addr(addr), _clock(clock)
139 virtual ~Impl() =
default;
141 inline uint8_t address()
const
145 inline uint32_t clock()
const
149 inline void setClock(
const uint32_t clock)
153 virtual int16_t scl()
const
157 virtual int16_t sda()
const
170 virtual void pinMode(uint8_t pin, uint8_t mode)
173 virtual void digitalWrite(uint8_t pin, uint8_t val)
177 virtual Impl* duplicate(
const uint8_t addr)
179 return new Impl(addr, _clock);
182 virtual m5::hal::error::error_t readWithTransaction(uint8_t*,
const size_t)
184 return m5::hal::error::error_t::UNKNOWN_ERROR;
186 virtual m5::hal::error::error_t writeWithTransaction(
const uint8_t*,
const size_t,
const bool)
188 return m5::hal::error::error_t::UNKNOWN_ERROR;
190 virtual m5::hal::error::error_t writeWithTransaction(
const uint8_t,
const uint8_t*,
const size_t,
const bool)
192 return m5::hal::error::error_t::UNKNOWN_ERROR;
194 virtual m5::hal::error::error_t writeWithTransaction(
const uint16_t,
const uint8_t*,
const size_t,
const bool)
196 return m5::hal::error::error_t::UNKNOWN_ERROR;
199 virtual m5::hal::error::error_t generalCall(
const uint8_t*,
const size_t)
201 return m5::hal::error::error_t::UNKNOWN_ERROR;
206 uint32_t _clock{100000};
211 std::unique_ptr<Impl> _impl{};
212 gpio::pin_backup_t _backupSCL{-1}, _backupSDA{-1};
Adapters to treat M5HAL and TwoWire in the same way.
Definition adapter.hpp:28
m5::hal::error::error_t writeWithTransaction(const uint8_t reg, const uint8_t *data, const size_t len, const bool stop=true)
Writeing data with transactions (reg8)*/.
Definition adapter.hpp:91
m5::hal::error::error_t writeWithTransaction(const uint8_t *data, const size_t len, const bool stop=true)
Writeing data with transactions */.
Definition adapter.hpp:86
Adapter * duplicate(const uint8_t addr)
Dupicate adapter.
Definition adapter.cpp:363
m5::hal::error::error_t readWithTransaction(uint8_t *data, const size_t len)
Reading data with transactions.
Definition adapter.hpp:81
m5::hal::error::error_t generalCall(const uint8_t *data, const size_t len)
write to address zero (general call)
Definition adapter.cpp:377
m5::hal::error::error_t writeWithTransaction(const uint16_t reg, const uint8_t *data, const size_t len, const bool stop=true)
Writeing data with transactions (reg16) */.
Definition adapter.hpp:97
Top level namespace of M5stack.
Definition test_helper.hpp:18
PIN settings save/restore.