21 #ifndef _utl_com_i2c_h__ 22 #define _utl_com_i2c_h__ 42 template <
typename impl_t>
74 uint32_t
_clock ()
const {
return impl()._clock (); }
75 void _clock (uint32_t c) { impl()._clock (c); }
77 void _stop() { impl()._stop (); }
160 virtual ~i2c_i () =
default;
168 virtual uint32_t
_clock ()
const = 0;
169 virtual void _clock (uint32_t) = 0;
170 virtual void _start() = 0;
171 virtual void _stop() = 0;
225 #if defined _utl_have_concepts 229 template <
typename T>
230 concept
bool I2c_i = requires (T t,
const T ct,
typename T::Sequence s) {
232 requires not_<std::is_copy_constructible<T>::value>::value;
233 requires not_<std::is_copy_assignable<T>::value>::value;
235 {ct.clock()} -> uint32_t;
236 {t.clock(0)} -> void;
239 {t.rx_data (1, s)} ->
byte_t;
240 {t.tx_data (0, s)} -> bool;
243 namespace i2c_i_details {
246 template <
class _Tp>
using try_cclk_t = decltype (declval<const _Tp>().clock());
247 template <
class _Tp>
using try_clk_t = decltype (declval<_Tp>().clock(declval<uint32_t>()));
248 template <
class _Tp>
using try_start_t = decltype (declval<_Tp>().start());
249 template <
class _Tp>
using try_stop_t = decltype (declval<_Tp>().stop());
251 = decltype (declval<_Tp>().rx_data (declval<bool>(), declval<typename _Tp::Sequence>()));
253 = decltype (declval<_Tp>().tx_data (declval<byte_t>(), declval<typename _Tp::Sequence>()));
256 template <
typename _Tp,
typename =
void>
260 template <
typename _Tp>
263 typename _Tp::Sequence,
287 #endif // _utl_com_i2c_h__
void void_t
void_t type alias
Primary template to catch any non I2C interface types.
void clock(uint32_t f)
set clock frequency of the bus
Abstract base class for i2c bus.
decltype(declval< _Tp >().stop()) try_stop_t
A virtual base class specialization.
decltype(declval< _Tp >().tx_data(declval< byte_t >(), declval< typename _Tp::Sequence >())) try_tx_data_t
decltype(declval< const _Tp >().clock()) try_cclk_t
decltype(declval< _Tp >().rx_data(declval< bool >(), declval< typename _Tp::Sequence >())) try_rx_data_t
i2c_i()=default
Allow constructor from derived only.
void _stop()
Send stop functionality.
~i2c_i()=default
Allow destructor from derived only.
decltype(declval< _Tp >().clock(declval< uint32_t >())) try_clk_t
void _clock(uint32_t c)
set clock frequency of the bus [Hz]
STL's core language concepts.
void stop()
Send stop functionality.
void start()
Send start functionality.
Sequence
I2C transmit/receive sequence.
Only send/receive ack [1 clock].
bool _tx_data(byte_t byte, Sequence seq)
byte_t rx_data(bool ack, Sequence seq=Sequence::BYTEnACK)
Receive a byte from the i2c bus.
type & operator=(const type &)=delete
void clock(uint32_t c)
set clock frequency of the bus [Hz]
byte_t rx_data(bool ack, Sequence seq=Sequence::BYTEnACK)
Receive a byte from the i2c bus.
bool tx_data(byte_t byte, Sequence seq=Sequence::BYTEnACK)
Transmit a byte to the i2c bus.
uint8_t byte_t
8 bits wide
bool tx_data(byte_t byte, Sequence seq=Sequence::BYTEnACK)
Transmit a byte to the i2c bus.
Read/Write byte and ack [9 clocks].
uint32_t _clock() const
clock frequency of the bus [Hz]
Only read/write byte [8 clocks].
void _start()
Send start functionality.
Sequence
I2C transmit/receive sequence.
byte_t _rx_data(bool ack, Sequence seq)
decltype(declval< _Tp >().start()) try_start_t
Implementation detail main forward header.