Class I2C

Class Documentation

class I2C

I2C class.

Represents I2C/Smbus bus on the linux device.

Public Functions

explicit I2C(const char *fileName)

Construct a new I2C object.

Opens given file and save result value to the file descriptor attribute.

Parameters:

fileName – File name to open.

void selectDevice(std::uint8_t address)

Select device on the I2C bus with given address.

Parameters:

address – Address of the device on the I2C bus.

std::int32_t readByte()

Read a single byte from the device without specifying register.

Returns:

Single byte read from device.

std::int32_t readByteData(std::uint8_t reg)

Read a single byte from the given register.

Parameters:

reg – Register address value.

Returns:

Single byte read from giver register.

std::int32_t readWordData(std::uint16_t reg)

Read two bytes (word length) from the given register.

Parameters:

reg – Register address value.

Returns:

Read value from the given register.

std::int32_t writeByte(std::uint8_t val)

Send a single byte to the device.

This function is the opposite of the readByte().

See also

readByte()

Parameters:

val – Value to write to the device.

Returns:

0 on success, otherwise -1.

std::int32_t writeByteData(std::uint8_t reg, std::uint8_t val)

Write a single byte to the designated register.

This function is the opposite to the readByteData().

See also

readByteData()

Parameters:
  • reg – Register address value.

  • val – Value to be written to the designed register.

Returns:

0 on success, otherwise -1.

std::int32_t writeWordData(std::uint8_t reg, std::uint16_t val)

Write two bytes (word length) to the designed register.

This function is the opposite to the writeWordData().

See also

writeWordData()

Parameters:
  • reg – Register address value.

  • val – Value to be written to the designed register.

Returns:

0 on success, otherwise -1.

~I2C()

Destroy the I2C object.