Skip to content

File I2cController.hpp

FileList > demo-projets > stm32 > include > I2cController.hpp

Go to the source code of this file.

  • #include "rbcx.pb.h"
  • #include <stdint.h>
  • #include <stdlib.h>
  • #include <string.h>
  • #include "stm32f1xx_hal.h"
  • #include "FreeRTOS.h"
  • #include "task.h"
  • #include "event_groups.h"

Public Types

Type Name
enum uint32_t I2cEvents

Public Attributes

Type Name
EventGroupHandle_t i2cEventGroup
TaskHandle_t i2cTaskHandle

Public Functions

Type Name
uint8_t I2Cdev_IsDeviceReady (uint16_t DevAddress, uint32_t Trials=2, uint32_t Timeout=0)
uint8_t I2Cdev_Master_Receive (uint16_t DevAddress, uint8_t * pData, uint16_t Size, uint32_t Timeout)
uint8_t I2Cdev_Master_Transmit (uint16_t DevAddress, uint8_t * pData, uint16_t Size, uint32_t Timeout)
uint8_t I2Cdev_Mem_Read (uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t Size, uint32_t Timeout)
uint8_t I2Cdev_Mem_Write (uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t Size, uint32_t Timeout)
uint8_t I2Cdev_Slave_Receive (uint8_t * pData, uint16_t Size, uint32_t Timeout)
uint8_t I2Cdev_Slave_Transmit (uint8_t * pData, uint16_t Size, uint32_t Timeout)
uint8_t I2Cdev_init ()
uint8_t I2Cdev_readBit (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t * data, uint16_t timeout)
uint8_t I2Cdev_readBitW (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t * data, uint16_t timeout)
uint8_t I2Cdev_readBits (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t * data, uint16_t timeout)
uint8_t I2Cdev_readBitsW (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t * data, uint16_t timeout)
uint8_t I2Cdev_readByte (uint8_t devAddr, uint8_t regAddr, uint8_t * data, uint16_t timeout)
uint8_t I2Cdev_readBytes (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t * data, uint16_t timeout)
uint8_t I2Cdev_readWord (uint8_t devAddr, uint8_t regAddr, uint16_t * data, uint16_t timeout)
uint8_t I2Cdev_readWords (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t * data, uint16_t timeout)
uint8_t I2Cdev_scan ()
uint16_t I2Cdev_writeBit (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data)
uint16_t I2Cdev_writeBitW (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data)
uint16_t I2Cdev_writeBits (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data)
uint16_t I2Cdev_writeBitsW (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data)
uint16_t I2Cdev_writeByte (uint8_t devAddr, uint8_t regAddr, uint8_t data)
uint16_t I2Cdev_writeBytes (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t * data)
uint16_t I2Cdev_writeWord (uint8_t devAddr, uint8_t regAddr, uint16_t data)
uint16_t I2Cdev_writeWords (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t * data)
void i2cDispatch (const CoprocReq_I2cReq & req)
void i2cReset ()

Macros

Type Name
define I2CDEV_DEFAULT_READ_TIMEOUT 10

Public Types Documentation

enum I2cEvents

enum I2cEvents {
    I2C_NONE = 0,
    I2C_MPU_TICK = 1,
    I2C_MESSAGE = 2
};

Public Attributes Documentation

variable i2cEventGroup

EventGroupHandle_t i2cEventGroup;

variable i2cTaskHandle

TaskHandle_t i2cTaskHandle;

Public Functions Documentation

function I2Cdev_IsDeviceReady

uint8_t I2Cdev_IsDeviceReady (
    uint16_t DevAddress,
    uint32_t Trials=2,
    uint32_t Timeout=0
) 

function I2Cdev_Master_Receive

uint8_t I2Cdev_Master_Receive (
    uint16_t DevAddress,
    uint8_t * pData,
    uint16_t Size,
    uint32_t Timeout
) 

function I2Cdev_Master_Transmit

uint8_t I2Cdev_Master_Transmit (
    uint16_t DevAddress,
    uint8_t * pData,
    uint16_t Size,
    uint32_t Timeout
) 

function I2Cdev_Mem_Read

uint8_t I2Cdev_Mem_Read (
    uint16_t DevAddress,
    uint16_t MemAddress,
    uint16_t MemAddSize,
    uint8_t * pData,
    uint16_t Size,
    uint32_t Timeout
) 

function I2Cdev_Mem_Write

uint8_t I2Cdev_Mem_Write (
    uint16_t DevAddress,
    uint16_t MemAddress,
    uint16_t MemAddSize,
    uint8_t * pData,
    uint16_t Size,
    uint32_t Timeout
) 

function I2Cdev_Slave_Receive

uint8_t I2Cdev_Slave_Receive (
    uint8_t * pData,
    uint16_t Size,
    uint32_t Timeout
) 

function I2Cdev_Slave_Transmit

uint8_t I2Cdev_Slave_Transmit (
    uint8_t * pData,
    uint16_t Size,
    uint32_t Timeout
) 

function I2Cdev_init

uint8_t I2Cdev_init () 

function I2Cdev_readBit

uint8_t I2Cdev_readBit (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitNum,
    uint8_t * data,
    uint16_t timeout
) 

Read a single bit from an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to read from
  • bitNum Bit position to read (0-7)
  • data Container for single bit value
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Status of read operation (true = success)

function I2Cdev_readBitW

uint8_t I2Cdev_readBitW (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitNum,
    uint16_t * data,
    uint16_t timeout
) 

Read a single bit from a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to read from
  • bitNum Bit position to read (0-15)
  • data Container for single bit value
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Status of read operation (true = success)

function I2Cdev_readBits

uint8_t I2Cdev_readBits (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitStart,
    uint8_t length,
    uint8_t * data,
    uint16_t timeout
) 

Read multiple bits from an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to read from
  • bitStart First bit position to read (0-7)
  • length Number of bits to read (not more than 8)
  • data Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05)
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Status of read operation (true = success)

function I2Cdev_readBitsW

uint8_t I2Cdev_readBitsW (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitStart,
    uint8_t length,
    uint16_t * data,
    uint16_t timeout
) 

Read multiple bits from a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to read from
  • bitStart First bit position to read (0-15)
  • length Number of bits to read (not more than 16)
  • data Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05)
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Status of read operation (1 = success, 0 = failure, -1 = timeout)

function I2Cdev_readByte

uint8_t I2Cdev_readByte (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t * data,
    uint16_t timeout
) 

Read single byte from an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to read from
  • data Container for byte value read from device
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Status of read operation (true = success)

function I2Cdev_readBytes

uint8_t I2Cdev_readBytes (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t length,
    uint8_t * data,
    uint16_t timeout
) 

Read multiple bytes from an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr First register regAddr to read from
  • length Number of bytes to read
  • data Buffer to store read data in
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Number of bytes read (-1 indicates failure)

function I2Cdev_readWord

uint8_t I2Cdev_readWord (
    uint8_t devAddr,
    uint8_t regAddr,
    uint16_t * data,
    uint16_t timeout
) 

Read single word from a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to read from
  • data Container for word value read from device
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Status of read operation (true = success)

function I2Cdev_readWords

uint8_t I2Cdev_readWords (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t length,
    uint16_t * data,
    uint16_t timeout
) 

Read multiple words from a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr First register regAddr to read from
  • length Number of words to read
  • data Buffer to store read data in
  • timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev_readTimeout)

Returns:

Number of words read (-1 indicates failure)

function I2Cdev_scan

uint8_t I2Cdev_scan () 

function I2Cdev_writeBit

uint16_t I2Cdev_writeBit (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitNum,
    uint8_t data
) 

write a single bit in an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to write to
  • bitNum Bit position to write (0-7)
  • value New bit value to write

Returns:

Status of operation (true = success)

function I2Cdev_writeBitW

uint16_t I2Cdev_writeBitW (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitNum,
    uint16_t data
) 

write a single bit in a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to write to
  • bitNum Bit position to write (0-15)
  • value New bit value to write

Returns:

Status of operation (true = success)

function I2Cdev_writeBits

uint16_t I2Cdev_writeBits (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitStart,
    uint8_t length,
    uint8_t data
) 

Write multiple bits in an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to write to
  • bitStart First bit position to write (0-7)
  • length Number of bits to write (not more than 8)
  • data Right-aligned value to write

Returns:

Status of operation (true = success)

function I2Cdev_writeBitsW

uint16_t I2Cdev_writeBitsW (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t bitStart,
    uint8_t length,
    uint16_t data
) 

Write multiple bits in a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register regAddr to write to
  • bitStart First bit position to write (0-15)
  • length Number of bits to write (not more than 16)
  • data Right-aligned value to write

Returns:

Status of operation (true = success)

function I2Cdev_writeByte

uint16_t I2Cdev_writeByte (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t data
) 

Write single byte to an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register address to write to
  • data New byte value to write

Returns:

Status of operation (true = success)

function I2Cdev_writeBytes

uint16_t I2Cdev_writeBytes (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t length,
    uint8_t * data
) 

Write multiple bytes to an 8-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr First register address to write to
  • length Number of bytes to write
  • data Buffer to copy new data from

Returns:

Status of operation (true = success)

function I2Cdev_writeWord

uint16_t I2Cdev_writeWord (
    uint8_t devAddr,
    uint8_t regAddr,
    uint16_t data
) 

Write single word to a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr Register address to write to
  • data New word value to write

Returns:

Status of operation (true = success)

function I2Cdev_writeWords

uint16_t I2Cdev_writeWords (
    uint8_t devAddr,
    uint8_t regAddr,
    uint8_t length,
    uint16_t * data
) 

Write multiple words to a 16-bit device register.

Parameters:

  • devAddr I2C slave device address
  • regAddr First register address to write to
  • length Number of words to write
  • data Buffer to copy new data from

Returns:

Status of operation (true = success)

function i2cDispatch

void i2cDispatch (
    const CoprocReq_I2cReq & req
) 

function i2cReset

void i2cReset () 

Macro Definition Documentation

define I2CDEV_DEFAULT_READ_TIMEOUT

#define I2CDEV_DEFAULT_READ_TIMEOUT 10

The documentation for this class was generated from the following file demo-projets/stm32/include/I2cController.hpp