utl::i2c_i< impl_t > Class Template Reference

Abstract base class for i2c bus. More...

`#include <i2c.h>`

## Public Types

enum | Sequence { Sequence::BYTE =0, Sequence::ACK, Sequence::BYTEnACK }
| I2C transmit/receive sequence. More...
using | type = i2c_i< impl_t >

## Public Member Functions

Get/Set functions
uint32_t | clock () const
void | clock (uint32_t f)
| set clock frequency of the bus More...
User functions
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...

## Protected Member Functions

Object lifetime
| i2c_i ()=default
| Allow constructor from derived only. More...
| ~i2c_i ()=default
| Allow destructor from derived only. More...
| i2c_i (const type &)=delete
| No copies. More...
type & | operator= (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

uint32_t | _clock () const
| clock frequency of the bus [Hz] More...
void | _clock (uint32_t c)
| set clock frequency of the bus [Hz] More...
void | _start ()
| Send start functionality. More...
void | _stop ()
| Send stop functionality. More...
byte_t | _rx_data (bool ack, Sequence seq)
bool | _tx_data (byte_t byte, Sequence seq)

## Detailed Description

### template<typename impl_t>
class utl::i2c_i< impl_t >

Abstract base class for i2c bus.

this class force a common interface for I2C communication protocol implementations using CRTP

Parameters

  impl_t | The CRTP type (the derived/implementation class typename).

Definition at line 43 of file i2c.h.

## Member Typedef Documentation

## type

template<typename impl_t>

using utl::i2c_i< impl_t >::type = i2c_i<impl_t>

Export type as identity meta-function

Definition at line 47 of file i2c.h.

## Member Enumeration Documentation

## Sequence

template<typename impl_t>

enum utl::i2c_i::Sequence

strong

I2C transmit/receive sequence.

Enumerator
BYTE | Only read/write byte [8 clocks].
ACK | Only send/receive ack [1 clock].
BYTEnACK | Read/Write byte and ack [9 clocks].

Definition at line 49 of file i2c.h.

## Constructor & Destructor Documentation

## i2c_i() [1/2]

template<typename impl_t>

utl::i2c_i< impl_t >::i2c_i | ( |  | ) |

protecteddefault

Allow constructor from derived only.

## ~i2c_i()

template<typename impl_t>

utl::i2c_i< impl_t >::~i2c_i | ( |  | ) |

protecteddefault

Allow destructor from derived only.

## i2c_i() [2/2]

template<typename impl_t>

utl::i2c_i< impl_t >::i2c_i | ( | const type & |  | ) |

protecteddelete

No copies.

## Member Function Documentation

## _clock() [1/2]

template<typename impl_t>

uint32_t utl::i2c_i< impl_t >::_clock | ( |  | ) | const

inlineprivate

clock frequency of the bus [Hz]

Definition at line 74 of file i2c.h.

## _clock() [2/2]

template<typename impl_t>

void utl::i2c_i< impl_t >::_clock | ( | uint32_t | c | ) |

inlineprivate

set clock frequency of the bus [Hz]

Definition at line 75 of file i2c.h.

## _CRTP_IMPL()

template<typename impl_t>

utl::i2c_i< impl_t >::_CRTP_IMPL | ( | impl_t |  | ) |

private

## _rx_data()

template<typename impl_t>

byte_t utl::i2c_i< impl_t >::_rx_data | ( | bool | ack,
|  | Sequence | seq
| ) |  |

inlineprivate

Definition at line 78 of file i2c.h.

## _start()

template<typename impl_t>

void utl::i2c_i< impl_t >::_start | ( |  | ) |

inlineprivate

Send start functionality.

Definition at line 76 of file i2c.h.

## _stop()

template<typename impl_t>

void utl::i2c_i< impl_t >::_stop | ( |  | ) |

inlineprivate

Send stop functionality.

Definition at line 77 of file i2c.h.

## _tx_data()

template<typename impl_t>

bool utl::i2c_i< impl_t >::_tx_data | ( | byte_t | byte,
|  | Sequence | seq
| ) |  |

inlineprivate

Definition at line 79 of file i2c.h.

## clock() [1/2]

template<typename impl_t>

uint32_t utl::i2c_i< impl_t >::clock | ( |  | ) | const

inline

Returns
  clock frequency of the bus

Definition at line 87 of file i2c.h.

## clock() [2/2]

template<typename impl_t>

void utl::i2c_i< impl_t >::clock | ( | uint32_t | f | ) |

inline

set clock frequency of the bus

Definition at line 88 of file i2c.h.

## operator=()

template<typename impl_t>

type& utl::i2c_i< impl_t >::operator= | ( | const type & |  | ) |

protecteddelete

## rx_data()

template<typename impl_t>

byte_t utl::i2c_i< impl_t >::rx_data | ( | bool | ack,
|  | Sequence | seq = `Sequence::BYTEnACK`
| ) |  |

inline

Receive a byte from the i2c bus.

Parameters

  ack

  Optional ack bit.
  - 1 ACK the reception
  - 0 Don't ACK the reception.

  seq

  The 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 111 of file i2c.h.

## start()

template<typename impl_t>

void utl::i2c_i< impl_t >::start | ( |  | ) |

inline

Send start functionality.

Definition at line 96 of file i2c.h.

## stop()

template<typename impl_t>

void utl::i2c_i< impl_t >::stop | ( |  | ) |

inline

Send stop functionality.

Definition at line 97 of file i2c.h.

## tx_data()

template<typename impl_t>

bool utl::i2c_i< impl_t >::tx_data | ( | byte_t | byte,
|  | Sequence | seq = `Sequence::BYTEnACK`
| ) |  |

inline

Transmit a byte to the i2c bus.

Parameters

  byte | The byte to send.

  seq

  The 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 127 of file i2c.h.

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

- include/utl/com/i2c.h