I2C_device_Arduino 1.2.0
An I²C utility class for Arduino
Loading...
Searching...
No Matches
I2C_device Class Reference

#include <I2C_device.h>

Inheritance diagram for I2C_device:
test_LM75B

Public Member Functions

 I2C_device (uint8_t i2c_address, bool repeated_start_enable=true)
 I2C_device (TwoWire &wire, uint8_t i2c_address, bool repeated_start_enable=true)
 ~I2C_device ()
void repeated_start_enable (bool en=true)
bool ping (void)
int tx (const uint8_t *data, uint16_t size, bool stop=true)
int rx (uint8_t *data, uint16_t size, bool stop=true)
virtual int reg_w (uint8_t reg_adr, const uint8_t *data, uint16_t size, bool stop=true)
virtual int reg_w (uint8_t reg_adr, uint8_t data, bool stop=true)
virtual int reg_r (uint8_t reg_adr, uint8_t *data, uint16_t size, bool stop=true)
virtual uint8_t reg_r (uint8_t reg_adr, bool stop=true)
void write_r8 (uint8_t reg, uint8_t val, bool stop=true)
void write_r16 (uint8_t reg, uint16_t val, bool stop=true)
uint8_t read_r8 (uint8_t reg, bool stop=true)
uint16_t read_r16 (uint8_t reg, bool stop=true)
void bit_op8 (uint8_t reg, uint8_t mask, uint8_t value)
void bit_op16 (uint8_t reg, uint16_t mask, uint16_t value)

Static Public Member Functions

static bool ping (uint8_t addr)
static void scan (TwoWire &target_i2c=Wire, uint8_t stop=128)

Protected Member Functions

void txrx (const uint8_t *w_data, uint8_t *r_data, uint16_t size)

Protected Attributes

uint8_t i2c_addr
SPISettings spi_setting

Private Attributes

TwoWire & i2c
bool rs_dis

Detailed Description

I2C device abstracting class

This class provides common methods for all I2C devices

Author
Tedd OKANO

Released under the MIT License

Definition at line 19 of file I2C_device.h.

Constructor & Destructor Documentation

◆ I2C_device() [1/2]

I2C_device::I2C_device ( uint8_t i2c_address,
bool repeated_start_enable = true )

Create an I2C_device instance with specified address

Parameters
i2c_addressI2C-bus address
repeated_start_enablerepeated-START-condition enable between write and read transaction for register reading. Default: true

Definition at line 3 of file I2C_device.cpp.

Referenced by test_LM75B::test_LM75B(), and test_LM75B::test_LM75B().

◆ I2C_device() [2/2]

I2C_device::I2C_device ( TwoWire & wire,
uint8_t i2c_address,
bool repeated_start_enable = true )

Create an I2C_device instance with specified address

Parameters
wireTwoWire instance
i2c_addressI2C-bus address
repeated_start_enablerepeated-START-condition enable between write and read transaction for register reading. Default: true

Definition at line 7 of file I2C_device.cpp.

◆ ~I2C_device()

I2C_device::~I2C_device ( )

Destructor of I2C_device

Definition at line 11 of file I2C_device.cpp.

Member Function Documentation

◆ bit_op16()

void I2C_device::bit_op16 ( uint8_t reg,
uint16_t mask,
uint16_t value )

Register overwriting with bit-mask, 16 bit

Register can be updated by bit level

Parameters
regregister index/address/pointer
maskbit-mask to protect overwriting
valuevalue to overwrite

Definition at line 165 of file I2C_device.cpp.

◆ bit_op8()

void I2C_device::bit_op8 ( uint8_t reg,
uint8_t mask,
uint8_t value )

Register overwriting with bit-mask, 8 bit

Register can be updated by bit level

Parameters
regregister index/address/pointer
maskbit-mask to protect overwriting
valuevalue to overwrite

Definition at line 155 of file I2C_device.cpp.

◆ ping() [1/2]

bool I2C_device::ping ( uint8_t addr)
static

ping (class method)

Parameters
addrtarget address
Returns
true, if ACKed

◆ ping() [2/2]

bool I2C_device::ping ( void )

Ping the device

Returns
true when ACK

Definition at line 20 of file I2C_device.cpp.

◆ read_r16()

uint16_t I2C_device::read_r16 ( uint8_t reg,
bool stop = true )

Register read, 16 bit

This 16 bit access may not be common but it's useful for sensor devices

Parameters
regregister index/address/pointer
stopoption: generating STOP-condition after transaction. Default: true
Returns
data value

Definition at line 146 of file I2C_device.cpp.

Referenced by bit_op16(), and test_LM75B::read().

◆ read_r8()

uint8_t I2C_device::read_r8 ( uint8_t reg,
bool stop = true )

Register read, 8 bit

Parameters
regregister index/address/pointer
stopoption: generating STOP-condition after transaction. Default: true
Returns
data value

Definition at line 141 of file I2C_device.cpp.

Referenced by bit_op8(), and test_LM75B::os_mode().

◆ reg_r() [1/2]

uint8_t I2C_device::reg_r ( uint8_t reg_adr,
bool stop = true )
virtual

Single register read

Parameters
reg_adrregister index/address/pointer
stopoption: generating STOP-condition after transaction. Default: true
Returns
read data value

Definition at line 117 of file I2C_device.cpp.

◆ reg_r() [2/2]

int I2C_device::reg_r ( uint8_t reg_adr,
uint8_t * data,
uint16_t size,
bool stop = true )
virtual

Multiple register read

Parameters
reg_adrregister index/address/pointer
datapointer to data buffer
sizedata size
stopoption: generating STOP-condition after transaction. Default: true
Returns
transferred data size

Definition at line 111 of file I2C_device.cpp.

Referenced by read_r16(), and read_r8().

◆ reg_w() [1/2]

int I2C_device::reg_w ( uint8_t reg_adr,
const uint8_t * data,
uint16_t size,
bool stop = true )
virtual

Multiple register write

Parameters
reg_adrregister index/address/pointer
datapointer to data buffer
sizedata size
stopoption: generating STOP-condition after transaction. Default: true
Returns
transferred data size

Definition at line 90 of file I2C_device.cpp.

Referenced by write_r16(), and write_r8().

◆ reg_w() [2/2]

int I2C_device::reg_w ( uint8_t reg_adr,
uint8_t data,
bool stop = true )
virtual

Single register write

Parameters
reg_adrregister index/address/pointer
datadata value
stopoption: generating STOP-condition after transaction. Default: true
Returns
transferred data size

Definition at line 101 of file I2C_device.cpp.

◆ repeated_start_enable()

void I2C_device::repeated_start_enable ( bool en = true)

repeated-START-condition enable

Parameters
enrepeated-START-condition enable between write and read transaction for register reading. Default: true

Definition at line 15 of file I2C_device.cpp.

Referenced by I2C_device(), and I2C_device().

◆ rx()

int I2C_device::rx ( uint8_t * data,
uint16_t size,
bool stop = true )

Receive data

Parameters
datapointer to data buffer
sizedata size
stopoption: generating STOP-condition after transaction. Default: true
Returns
transferred data size

Definition at line 75 of file I2C_device.cpp.

Referenced by reg_r(), and reg_r().

◆ scan()

void I2C_device::scan ( TwoWire & target_i2c = Wire,
uint8_t stop = 128 )
static

scan (class method)

Parameters
target_i2cTwoWire instance to scan. Default: Wire
stopscan stop address (exclusive). Default: 128

Definition at line 26 of file I2C_device.cpp.

◆ tx()

int I2C_device::tx ( const uint8_t * data,
uint16_t size,
bool stop = true )

Send data

Parameters
datapointer to data buffer
sizedata size
stopoption: generating STOP-condition after transaction. Default: true
Returns
transferred data size or error code in negative number: -1=data too long, -2=NACK for address, -3=NACK for data, -4=Other error, -5=Time out

Definition at line 63 of file I2C_device.cpp.

Referenced by reg_r(), reg_r(), reg_w(), and reg_w().

◆ txrx()

void I2C_device::txrx ( const uint8_t * w_data,
uint8_t * r_data,
uint16_t size )
protected

Definition at line 175 of file I2C_device.cpp.

◆ write_r16()

void I2C_device::write_r16 ( uint8_t reg,
uint16_t val,
bool stop = true )

Register write, 16 bit

This 16 bit access may not be common but it's useful for sensor devices

Parameters
regregister index/address/pointer
valdata value
stopoption: generating STOP-condition after transaction. Default: true

Definition at line 131 of file I2C_device.cpp.

Referenced by bit_op16(), and test_LM75B::thresholds().

◆ write_r8()

void I2C_device::write_r8 ( uint8_t reg,
uint8_t val,
bool stop = true )

Register write, 8 bit

Parameters
regregister index/address/pointer
valdata value
stopoption: generating STOP-condition after transaction. Default: true

Definition at line 126 of file I2C_device.cpp.

Referenced by bit_op8(), and test_LM75B::os_mode().

Member Data Documentation

◆ i2c

TwoWire& I2C_device::i2c
private

Definition at line 184 of file I2C_device.h.

Referenced by I2C_device(), I2C_device(), ping(), rx(), and tx().

◆ i2c_addr

uint8_t I2C_device::i2c_addr
protected

Definition at line 180 of file I2C_device.h.

Referenced by I2C_device(), I2C_device(), ping(), rx(), and tx().

◆ rs_dis

bool I2C_device::rs_dis
private

Definition at line 185 of file I2C_device.h.

Referenced by I2C_device(), I2C_device(), repeated_start_enable(), rx(), and tx().

◆ spi_setting

SPISettings I2C_device::spi_setting
protected

Definition at line 181 of file I2C_device.h.

Referenced by txrx().


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