Skip to content

File I2cController.cpp

FileList > fw > rbcx-coprocessor > src > I2cController.cpp

Go to the source code of this file.

  • #include "I2cController.hpp"
  • #include "Bsp.hpp"
  • #include "MpuController.hpp"
  • #include "OledController.hpp"
  • #include "utils/Debug.hpp"
  • #include "utils/MutexWrapper.hpp"
  • #include "utils/QueueWrapper.hpp"
  • #include "utils/TaskWrapper.hpp"
  • #include "timers.h"
  • #include <mutex>

Public Attributes

Type Name
I2C_HandleTypeDef I2Cdev_hi2c
uint16_t I2Cdev_readTimeout = = I2CDEV_DEFAULT_READ_TIMEOUT
EventGroupHandle_t i2cEventGroup
TaskHandle_t i2cTaskHandle

Public Static Attributes

Type Name
xTaskHandle i2cCallingTask
StaticEventGroup_t i2cEventBuffer
MutexWrapper i2cMutex
QueueWrapper< CoprocReq_I2cReq, 16 > i2cQueue
TaskWrapper< 1024 > i2cTask

Public Functions

Type Name
__weak void HAL_I2C_ErrorCallback (I2C_HandleTypeDef * hi2c)
__weak void HAL_I2C_MasterRxCpltCallback (I2C_HandleTypeDef * hi2c)
__weak void HAL_I2C_MasterTxCpltCallback (I2C_HandleTypeDef * hi2c)
__weak void HAL_I2C_MemRxCpltCallback (I2C_HandleTypeDef * hi2c)
__weak void HAL_I2C_MemTxCpltCallback (I2C_HandleTypeDef * hi2c)
void I2C1_ER_IRQHandler ()
void I2C1_EV_IRQHandler ()
uint8_t I2Cdev_IsDeviceReady (uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
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_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 * pData)
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 i2cNotify ()
void i2cReset ()
uint8_t i2cWait (HAL_StatusTypeDef beginStatus, uint32_t tout)
uint8_t i2cWrap (F fun, uint32_t Timeout)

Public Attributes Documentation

variable I2Cdev_hi2c

I2C_HandleTypeDef I2Cdev_hi2c;

variable I2Cdev_readTimeout

uint16_t I2Cdev_readTimeout;

Default timeout value for read operations. Set this to 0 to disable timeout detection.

variable i2cEventGroup

EventGroupHandle_t i2cEventGroup;

variable i2cTaskHandle

TaskHandle_t i2cTaskHandle;

Public Static Attributes Documentation

variable i2cCallingTask

xTaskHandle i2cCallingTask;

variable i2cEventBuffer

StaticEventGroup_t i2cEventBuffer;

variable i2cMutex

MutexWrapper i2cMutex;

variable i2cQueue

QueueWrapper<CoprocReq_I2cReq, 16> i2cQueue;

variable i2cTask

TaskWrapper<1024> i2cTask;

Public Functions Documentation

function HAL_I2C_ErrorCallback

__weak void HAL_I2C_ErrorCallback (
    I2C_HandleTypeDef * hi2c
) 

function HAL_I2C_MasterRxCpltCallback

__weak void HAL_I2C_MasterRxCpltCallback (
    I2C_HandleTypeDef * hi2c
) 

function HAL_I2C_MasterTxCpltCallback

__weak void HAL_I2C_MasterTxCpltCallback (
    I2C_HandleTypeDef * hi2c
) 

function HAL_I2C_MemRxCpltCallback

__weak void HAL_I2C_MemRxCpltCallback (
    I2C_HandleTypeDef * hi2c
) 

function HAL_I2C_MemTxCpltCallback

__weak void HAL_I2C_MemTxCpltCallback (
    I2C_HandleTypeDef * hi2c
) 

function I2C1_ER_IRQHandler

void I2C1_ER_IRQHandler () 

function I2C1_EV_IRQHandler

void I2C1_EV_IRQHandler () 

function I2Cdev_IsDeviceReady

uint8_t I2Cdev_IsDeviceReady (
    uint16_t DevAddress,
    uint32_t Trials,
    uint32_t Timeout
) 

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_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 * pData
) 

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 i2cNotify

void i2cNotify () 

function i2cReset

void i2cReset () 

function i2cWait

uint8_t i2cWait (
    HAL_StatusTypeDef beginStatus,
    uint32_t tout
) 

function i2cWrap

template<typename F typename F>
uint8_t i2cWrap (
    F fun,
    uint32_t Timeout
) 

The documentation for this class was generated from the following file fw/rbcx-coprocessor/src/I2cController.cpp