uTL
micro Template library
utl::i2c_bb_i< impl_t > Class Template Reference

A bit banking implementation of i2c bus inherited from i2c_i base class. More...

#include <i2c_bb.h>

Inheritance diagram for utl::i2c_bb_i< impl_t >:
utl::i2c_i< i2c_bb_i< impl_t > >

Public Types

enum  SDAMode { SDAMode::INPUT =0, SDAMode::OUTPUT }
 SDA pin direction enumerator. More...
 
using type = i2c_bb_i< impl_t >
 Export type as identity meta-function. More...
 
using Sequence = typename i2c_i< type >::Sequence
 
- Public Types inherited from utl::i2c_i< i2c_bb_i< impl_t > >
enum  Sequence
 I2C transmit/receive sequence. More...
 
using type = i2c_i< i2c_bb_i< impl_t > >
 

Protected Member Functions

Object lifetime
 ~i2c_bb_i () noexcept=default
 A default destructor, allow destructor from derived only. More...
 
 i2c_bb_i (uint32_t clk) noexcept
 A default constructor. More...
 
- Protected Member Functions inherited from utl::i2c_i< i2c_bb_i< impl_t > >
 i2c_i ()=default
 Allow constructor from derived only. More...
 
 i2c_i (const type &)=delete
 No copies. More...
 
 ~i2c_i ()=default
 Allow destructor from derived only. More...
 
typeoperator= (const type &)=delete
 

Private Member Functions

 _CRTP_IMPL (impl_t)
 
Implementation requirements
Note
In order for the implementation to have the following as private members it also need to declare this class as friend
bool SDA (SDAMode mode, bool st)
 
void SCL (uint8_t st)
 Implementers's scl pin function. More...
 
void delay (uint32_t usec)
 

Private Attributes

friend i2c_i< i2c_bb_i< impl_t > >
 

Implementation of base requirements

uint32_t usec_
 
uint32_t _clock () const
 
void _clock (uint32_t c)
 
void _start ()
 Send start functionality. More...
 
void _stop ()
 Send stop functionality. More...
 
byte_t _rx_data (bool ack, Sequence seq)
 Receive a byte from the i2c bus. More...
 
bool _tx_data (byte_t byte, Sequence seq)
 Transmit a byte to the i2c bus. More...
 

Additional Inherited Members

- Public Member Functions inherited from utl::i2c_i< i2c_bb_i< impl_t > >
uint32_t clock () const
 
void clock (uint32_t f)
 set clock frequency of the bus More...
 
void start ()
 Send start functionality. More...
 
void stop ()
 Send stop functionality. More...
 
byte_t rx_data (bool ack, Sequence seq=Sequence::BYTEnACK)
 Receive a byte from the i2c bus. More...
 
bool tx_data (byte_t byte, Sequence seq=Sequence::BYTEnACK)
 Transmit a byte to the i2c bus. More...
 

Detailed Description

template<typename impl_t>
class utl::i2c_bb_i< impl_t >

A bit banking implementation of i2c bus inherited from i2c_i base class.

See also
i2c_i

I2C bit banking interface template class providing an I2C using bit banking using CRTP.

Parameters
impl_tThe CRTP type (the derived/implementation class typename).

Definition at line 47 of file i2c_bb.h.

Member Typedef Documentation

◆ Sequence

template<typename impl_t >
using utl::i2c_bb_i< impl_t >::Sequence = typename i2c_i<type>::Sequence

Definition at line 53 of file i2c_bb.h.

◆ type

template<typename impl_t >
using utl::i2c_bb_i< impl_t >::type = i2c_bb_i<impl_t>

Export type as identity meta-function.

Definition at line 52 of file i2c_bb.h.

Member Enumeration Documentation

◆ SDAMode

template<typename impl_t >
enum utl::i2c_bb_i::SDAMode
strong

SDA pin direction enumerator.

Enumerator
INPUT 
OUTPUT 

Definition at line 55 of file i2c_bb.h.

Constructor & Destructor Documentation

◆ ~i2c_bb_i()

template<typename impl_t >
utl::i2c_bb_i< impl_t >::~i2c_bb_i ( )
protecteddefaultnoexcept

A default destructor, allow destructor from derived only.

◆ i2c_bb_i()

template<typename impl_t >
utl::i2c_bb_i< impl_t >::i2c_bb_i ( uint32_t  clk)
inlineprotectednoexcept

A default constructor.

Definition at line 68 of file i2c_bb.h.

Member Function Documentation

◆ _clock() [1/2]

template<typename impl_t >
uint32_t utl::i2c_bb_i< impl_t >::_clock ( ) const
inlineprivate

Definition at line 95 of file i2c_bb.h.

◆ _clock() [2/2]

template<typename impl_t >
void utl::i2c_bb_i< impl_t >::_clock ( uint32_t  c)
inlineprivate

Definition at line 96 of file i2c_bb.h.

◆ _CRTP_IMPL()

template<typename impl_t >
utl::i2c_bb_i< impl_t >::_CRTP_IMPL ( impl_t  )
private

◆ _rx_data()

template<typename impl_t >
byte_t utl::i2c_bb_i< impl_t >::_rx_data ( bool  ack,
Sequence  seq 
)
private

Receive a byte from the i2c bus.

Parameters
ackOptional ack bit.
  • 1 ACK the reception
  • 0 Don't ACK the reception.
seqThe operation sequence to execute
  • Sequence::BYTE Receive only the byte, do not send ack clock
  • Sequence::ACK Send only the ack bit
  • Sequence::BYTEnACK Receive the byte and send the ack bit
Returns
The byte received.

Definition at line 154 of file i2c_bb.h.

◆ _start()

template<typename impl_t >
void utl::i2c_bb_i< impl_t >::_start ( void  )
private

Send start functionality.

Send a START bit to the bus.

Returns
none

Definition at line 115 of file i2c_bb.h.

◆ _stop()

template<typename impl_t >
void utl::i2c_bb_i< impl_t >::_stop ( void  )
private

Send stop functionality.

Send a START bit to the bus.

Returns
none

Definition at line 131 of file i2c_bb.h.

◆ _tx_data()

template<typename impl_t >
bool utl::i2c_bb_i< impl_t >::_tx_data ( byte_t  byte,
Sequence  seq 
)
private

Transmit a byte to the i2c bus.

Parameters
byteThe byte to send.
seqThe operation sequence to execute
  • Sequence::BYTE Transmit only the byte, do not read ack bit
  • Sequence::ACK Read only the ack bit
  • Sequence::BYTEnACK Transmit the byte and read the ack bit
Returns
Slave's ACK bit
  • false Slave didn't ACK
  • true Slave did ACK

Definition at line 194 of file i2c_bb.h.

◆ delay()

template<typename impl_t >
void utl::i2c_bb_i< impl_t >::delay ( uint32_t  usec)
inlineprivate

Implementers's usec delay function

Definition at line 87 of file i2c_bb.h.

◆ SCL()

template<typename impl_t >
void utl::i2c_bb_i< impl_t >::SCL ( uint8_t  st)
inlineprivate

Implementers's scl pin function.

Definition at line 86 of file i2c_bb.h.

◆ SDA()

template<typename impl_t >
bool utl::i2c_bb_i< impl_t >::SDA ( SDAMode  mode,
bool  st 
)
inlineprivate

Implementers's sda pin function

Parameters
stIn SDA_OUTPUT mode, selects the pin output state
Returns
In SDA_INPUT mode return the pin input state

Definition at line 85 of file i2c_bb.h.

Member Data Documentation

◆ i2c_i< i2c_bb_i< impl_t > >

template<typename impl_t >
friend utl::i2c_bb_i< impl_t >::i2c_i< i2c_bb_i< impl_t > >
private

Definition at line 49 of file i2c_bb.h.

◆ usec_

template<typename impl_t >
uint32_t utl::i2c_bb_i< impl_t >::usec_
private

half period of I2C bus

Definition at line 102 of file i2c_bb.h.


The documentation for this class was generated from the following file: