12#ifndef M5_UNIT_COMPONENT_ADAPTER_HPP
13#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();
53 inline uint32_t clock()
const
55 return _impl->clock();
57 inline void setClock(
const uint32_t clock)
59 return _impl->setClock(clock);
65 m5::hal::error::error_t
generalCall(
const uint8_t* data,
const size_t len);
72 return _impl->readWithTransaction(data, len);
75 inline m5::hal::error::error_t
writeWithTransaction(
const uint8_t* data,
const size_t len,
const bool stop =
true)
77 return _impl->writeWithTransaction(data, len, stop);
80 inline m5::hal::error::error_t
writeWithTransaction(
const uint8_t reg,
const uint8_t* data,
const size_t len,
81 const bool stop =
true)
83 return _impl->writeWithTransaction(reg, data, len, stop);
86 inline m5::hal::error::error_t
writeWithTransaction(
const uint16_t reg,
const uint8_t* data,
const size_t len,
87 const bool stop =
true)
89 return _impl->writeWithTransaction(reg, data, len, stop);
97 explicit Impl(
const uint8_t addr) : _addr(addr)
100 Impl(
const uint8_t addr,
const uint32_t clock) : _addr(addr), _clock(clock)
104 virtual ~Impl() =
default;
106 inline uint8_t address()
const
110 inline uint32_t clock()
const
114 inline void setClock(
const uint32_t clock)
119 virtual Impl* duplicate(
const uint8_t addr)
121 return new Impl(addr, _clock);
124 virtual m5::hal::error::error_t readWithTransaction(uint8_t*,
const size_t)
126 return m5::hal::error::error_t::UNKNOWN_ERROR;
128 virtual m5::hal::error::error_t writeWithTransaction(
const uint8_t*,
const size_t,
const bool)
130 return m5::hal::error::error_t::UNKNOWN_ERROR;
132 virtual m5::hal::error::error_t writeWithTransaction(
const uint8_t,
const uint8_t*,
const size_t,
const bool)
134 return m5::hal::error::error_t::UNKNOWN_ERROR;
136 virtual m5::hal::error::error_t writeWithTransaction(
const uint16_t,
const uint8_t*,
const size_t,
const bool)
138 return m5::hal::error::error_t::UNKNOWN_ERROR;
141 virtual m5::hal::error::error_t generalCall(
const uint8_t*,
const size_t)
143 return m5::hal::error::error_t::UNKNOWN_ERROR;
148 uint32_t _clock{100000};
153 std::unique_ptr<Impl> _impl{};
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:80
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:75
Adapter * duplicate(const uint8_t addr)
Dupicate adapter.
Definition adapter.cpp:300
m5::hal::error::error_t readWithTransaction(uint8_t *data, const size_t len)
Reading data with transactions.
Definition adapter.hpp:70
m5::hal::error::error_t generalCall(const uint8_t *data, const size_t len)
write to address zero (general call)
Definition adapter.cpp:314
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:86
Top level namespace of M5stack.
Definition test_helper.hpp:18