I2CWrapper

Class that helps communicating over I2C.

Inherits the following classes: I2C

Protected Attributes

Type

Name

uint8_t

Public Functions

Type

Name

I2CWrapper (PinName sda, PinName scl, uint8_t address)

int

write_reg (uint8_t reg, uint8_t val)

int

write_reg (uint8_t reg, uint8_t * val, uint16_t size)

int

read_reg (uint8_t reg, uint8_t * val)

int

read_reg (uint8_t reg, uint8_t * val, uint16_t size)

int

write_bit (uint8_t reg, uint8_t bit, bool val)

int

read_bit (uint8_t reg, uint8_t bit, bool * val)

int

Protected Attributes Documentation

variable _address

uint8_t I2CWrapper::_address;

Public Functions Documentation

function I2CWrapper

I2CWrapper::I2CWrapper (
    PinName sda,
    PinName scl,
    uint8_t address
)

I2CWrapper constructor

Parameters:

  • sda I2C SDA pin

  • scl I2C SCL pin

  • address I2C address of device

Returns:

0 on success, non-0 on fail

function write_reg

int I2CWrapper::write_reg (
    uint8_t reg,
    uint8_t val
)

Write value to register.

Parameters:

  • reg register to write in

  • val value to write

Returns:

0 on success, non-0 on fail

function write_reg

int I2CWrapper::write_reg (
    uint8_t reg,
    uint8_t * val,
    uint16_t size
)

Write multiple values to registers.

Parameters:

  • reg device register to start from

  • val pointer to array with values to write

  • size number of bytes to write

Returns:

0 on success, non-0 on fail

function read_reg

int I2CWrapper::read_reg (
    uint8_t reg,
    uint8_t * val
)

Read register.

Parameters:

  • reg register to read

  • val pointer to the byte to read data in to

Returns:

0 on success, non-0 on fail

function read_reg

int I2CWrapper::read_reg (
    uint8_t reg,
    uint8_t * val,
    uint16_t size
)

Read multiple registers.

Parameters:

  • reg register to start reading from

  • val pointer to the byte array to read data in to

  • size mumber of bytes to read

Returns:

0 on success, non-0 on fail

function write_bit

int I2CWrapper::write_bit (
    uint8_t reg,
    uint8_t bit,
    bool val
)

Write bit of the register.

Parameters:

  • reg register to write in

  • bit bit to write (0 - 7)

  • val value to write (1/0)

Returns:

0 on success, non-0 on fail

function read_bit

int I2CWrapper::read_bit (
    uint8_t reg,
    uint8_t bit,
    bool * val
)

Read bit of the register

Parameters:

  • reg register to read from

  • bit bit to read (0 - 7)

  • *val pointer to the bit to read data in

Returns:

0 on success, non-0 on fail

int I2CWrapper::search ()

Try all addresses on I2C bus and print results to stdio.

The documentation for this class was generated from the following file: D:/w/hw-libs/\_libs\_/libraries/I2CWrapper.h

Last updated