Aruna
aruna::driver::I2C_master Class Referenceabstract

#include <I2C_master.h>

Inheritance diagram for aruna::driver::I2C_master:

Public Member Functions

 I2C_master ()
 
 ~I2C_master ()
 
err_t write (uint8_t address, uint8_t reg, uint8_t *data, size_t data_size)
 Write data to the I²C bus. More...
 
err_t write (uint8_t address, uint8_t reg, uint8_t data)
 Write single byte to the I²C bus. More...
 
err_t read (uint8_t address, uint8_t reg, uint8_t *buffer, size_t buffer_size)
 Read data from I²C slave. More...
 
err_t read (uint8_t address, uint8_t reg, uint8_t &buffer)
 Read single byte from I²C slave. More...
 
err_t lock (uint8_t i2c_address)
 
err_t try_lock (uint8_t i2c_address)
 
err_t unlock (uint8_t i2c_address)
 

Private Member Functions

virtual err_t _write (uint8_t address, uint8_t reg, uint8_t *data, size_t data_size)=0
 
virtual err_t _read (uint8_t address, uint8_t reg, uint8_t *buffer, size_t buffer_size)=0
 

Private Attributes

pthread_mutex_t line_busy
 
pthread_mutexattr_t line_busy_attr
 

Detailed Description

Definition at line 12 of file I2C_master.h.

Constructor & Destructor Documentation

◆ I2C_master()

aruna::driver::I2C_master::I2C_master ( )

Definition at line 23 of file I2C_master.cpp.

23  {
24  pthread_mutexattr_init(&line_busy_attr);
25  pthread_mutex_init(&line_busy, &line_busy_attr);
26 }
pthread_mutex_t line_busy
Definition: I2C_master.h:14
pthread_mutexattr_t line_busy_attr
Definition: I2C_master.h:15

◆ ~I2C_master()

aruna::driver::I2C_master::~I2C_master ( )

Definition at line 28 of file I2C_master.cpp.

28  {
29  pthread_mutex_destroy(&line_busy);
30  pthread_mutexattr_destroy(&line_busy_attr);
31 }
pthread_mutex_t line_busy
Definition: I2C_master.h:14
pthread_mutexattr_t line_busy_attr
Definition: I2C_master.h:15

Member Function Documentation

◆ _read()

virtual err_t aruna::driver::I2C_master::_read ( uint8_t  address,
uint8_t  reg,
uint8_t *  buffer,
size_t  buffer_size 
)
privatepure virtual

Implemented in aruna::driver::ESP32_I2C_master.

Here is the caller graph for this function:

◆ _write()

virtual err_t aruna::driver::I2C_master::_write ( uint8_t  address,
uint8_t  reg,
uint8_t *  data,
size_t  data_size 
)
privatepure virtual

Implemented in aruna::driver::ESP32_I2C_master.

Here is the caller graph for this function:

◆ lock()

aruna::err_t aruna::driver::I2C_master::lock ( uint8_t  i2c_address)

Definition at line 41 of file I2C_master.cpp.

41  {
42 // TODO
43  return aruna::err_t::OK;
44 }
Here is the caller graph for this function:

◆ read() [1/2]

aruna::err_t aruna::driver::I2C_master::read ( uint8_t  address,
uint8_t  reg,
uint8_t *  buffer,
size_t  buffer_size 
)

Read data from I²C slave.

Parameters
addressslave address
regregister to write to
bufferbuffer to store read data
buffer_sizeamount of bytes to read.
Returns

Definition at line 7 of file I2C_master.cpp.

7  {
8  pthread_mutex_lock(&line_busy);
9  err_t ret;
10  ret = _read(address, reg, buffer, buffer_size);
11  pthread_mutex_unlock(&line_busy);
12  return ret;
13 }
pthread_mutex_t line_busy
Definition: I2C_master.h:14
virtual err_t _read(uint8_t address, uint8_t reg, uint8_t *buffer, size_t buffer_size)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read() [2/2]

aruna::err_t aruna::driver::I2C_master::read ( uint8_t  address,
uint8_t  reg,
uint8_t &  buffer 
)

Read single byte from I²C slave.

Parameters
addressslave address
regregister to write to
bufferbuffer to store read data
Returns

Definition at line 37 of file I2C_master.cpp.

37  {
38  return read(address, reg, &buffer, 1);
39 }
err_t read(uint8_t address, uint8_t reg, uint8_t *buffer, size_t buffer_size)
Read data from I²C slave.
Definition: I2C_master.cpp:7
Here is the call graph for this function:

◆ try_lock()

aruna::err_t aruna::driver::I2C_master::try_lock ( uint8_t  i2c_address)

Definition at line 46 of file I2C_master.cpp.

46  {
47  // TODO
48  return aruna::err_t::OK;
49 }

◆ unlock()

aruna::err_t aruna::driver::I2C_master::unlock ( uint8_t  i2c_address)

Definition at line 51 of file I2C_master.cpp.

51  {
52  // TODO
53  return aruna::err_t::OK;
54 }
Here is the caller graph for this function:

◆ write() [1/2]

aruna::err_t aruna::driver::I2C_master::write ( uint8_t  address,
uint8_t  reg,
uint8_t *  data,
size_t  data_size 
)

Write data to the I²C bus.

Parameters
addressslave address
regregister to write to
datadata array to be written.
data_sizenumber of bytes in data
Returns

Definition at line 15 of file I2C_master.cpp.

15  {
16  pthread_mutex_lock(&line_busy);
17  err_t ret;
18  ret = _write(address, reg, data, data_size);
19  pthread_mutex_unlock(&line_busy);
20  return ret;
21 }
pthread_mutex_t line_busy
Definition: I2C_master.h:14
virtual err_t _write(uint8_t address, uint8_t reg, uint8_t *data, size_t data_size)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [2/2]

aruna::err_t aruna::driver::I2C_master::write ( uint8_t  address,
uint8_t  reg,
uint8_t  data 
)

Write single byte to the I²C bus.

Parameters
addressslave address
regregister to write to
data8 bits to be written.
Returns

Definition at line 33 of file I2C_master.cpp.

33  {
34  return write(address, reg, &data, 1);
35 }
err_t write(uint8_t address, uint8_t reg, uint8_t *data, size_t data_size)
Write data to the I²C bus.
Definition: I2C_master.cpp:15
Here is the call graph for this function:

Member Data Documentation

◆ line_busy

pthread_mutex_t aruna::driver::I2C_master::line_busy
private

Definition at line 14 of file I2C_master.h.

◆ line_busy_attr

pthread_mutexattr_t aruna::driver::I2C_master::line_busy_attr
private

Definition at line 15 of file I2C_master.h.


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