22 #ifndef __utl_com_i2c_bb_h__ 23 #define __utl_com_i2c_bb_h__ 46 template <
typename impl_t>
69 :
usec_ {1000000/(2*clk)} { }
85 bool SDA (
SDAMode mode,
bool st) {
return impl().SDA (mode, st); }
86 void SCL (uint8_t st) { impl().SCL (st); }
87 void delay (uint32_t usec) { impl().delay(usec); }
114 template <
typename impl_t>
117 SDA (SDAMode::OUTPUT, 1);
120 SDA (SDAMode::OUTPUT, 0);
130 template <
typename impl_t>
133 SDA (SDAMode::OUTPUT, 0);
137 SDA (SDAMode::OUTPUT, 1);
153 template <
typename impl_t>
158 SDA (SDAMode::INPUT, 0);
160 if (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {
162 for (
int i=8 ; i!=0 ; --i) {
166 byte |= SDA (SDAMode::INPUT, 0);
171 if (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {
172 SDA (SDAMode::OUTPUT, !ack);
176 SDA (SDAMode::OUTPUT, 0);
193 template <
typename impl_t>
198 SDA (SDAMode::OUTPUT, 0);
200 if (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {
202 for (
int i=8 ; i!=0 ; --i) {
204 SDA (SDAMode::OUTPUT, byte & 0x80);
212 if (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {
214 SDA (SDAMode::INPUT, 0);
217 ack = !SDA (SDAMode::INPUT, 0);
220 SDA (SDAMode::OUTPUT, 0);
251 :
usec_ {1000000/(2*clk)} { }
267 virtual
void SCL (
bool st) =0;
268 virtual
void delay (uint32_t usec) =0;
336 if (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {
338 for (
int i=8 ; i!=0 ; --i) {
347 if (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {
375 if (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {
377 for (
int i=8 ; i!=0 ; --i) {
387 if (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {
403 #endif // #ifndef __utl_com_i2c_bb_h__ typename i2c_i< type >::Sequence Sequence
void _start()
Send start functionality.
Abstract base class for i2c bus.
bool SDA(SDAMode mode, bool st)
SDAMode
SDA pin direction enumerator.
A virtual base class specialization.
byte_t _rx_data(bool ack, Sequence seq)
Receive a byte from the i2c bus.
void _clock(uint32_t c) final
set clock frequency of the bus [Hz]
void _stop()
Send stop functionality.
bool _tx_data(byte_t byte, Sequence seq)
Transmit a byte to the i2c bus.
SDAMode
SDA pin direction enumerator.
STL's core language concepts.
i2c_bb_i(uint32_t clk) noexcept
Constructor.
Sequence
I2C transmit/receive sequence.
A virtual base class interface specialization. Using the private virtual interface we provide the int...
A bit banking implementation of i2c bus inherited from i2c_i base class.
uint8_t byte_t
8 bits wide
void delay(uint32_t usec)
Sequence
I2C transmit/receive sequence.
~i2c_bb_i() noexcept=default
A default destructor, allow destructor from derived only.
Implementation detail main forward header.
void SCL(uint8_t st)
Implementers's scl pin function.
An Abstract base class interface for the i2c bus.