PX4 Firmware
PX4 Autopilot Software http://px4.io
SMBus Class Reference

#include <SMBus.hpp>

Inheritance diagram for SMBus:
Collaboration diagram for SMBus:

Public Member Functions

 SMBus (int bus_num, uint16_t address)
 
 ~SMBus () override=default
 
int block_write (const uint8_t cmd_code, void *data, uint8_t byte_count, bool use_pec)
 Sends a block write command. More...
 
int block_read (const uint8_t cmd_code, void *data, const uint8_t length, bool use_pec)
 Sends a block read command. More...
 
int read_word (const uint8_t cmd_code, uint16_t &data)
 Sends a read word command. More...
 
int write_word (const uint8_t cmd_code, uint16_t data)
 Sends a write word command. More...
 
uint8_t get_pec (uint8_t *buffer, uint8_t length)
 Calculates the PEC from the data. More...
 

Detailed Description

Definition at line 47 of file SMBus.hpp.

Constructor & Destructor Documentation

◆ SMBus()

SMBus::SMBus ( int  bus_num,
uint16_t  address 
)

Definition at line 48 of file SMBus.cpp.

◆ ~SMBus()

SMBus::~SMBus ( )
overridedefault

Member Function Documentation

◆ block_read()

int SMBus::block_read ( const uint8_t  cmd_code,
void *  data,
const uint8_t  length,
bool  use_pec 
)

Sends a block read command.

Parameters
cmd_codeThe command code.
dataThe returned data.
lengthThe number of bytes being read
Returns
Returns PX4_OK on success, -errno on failure.

Definition at line 93 of file SMBus.cpp.

References get_pec().

Referenced by BATT_SMBUS::dataflash_read(), BATT_SMBUS::manufacturer_name(), and BATT_SMBUS::manufacturer_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_write()

int SMBus::block_write ( const uint8_t  cmd_code,
void *  data,
uint8_t  byte_count,
bool  use_pec 
)

Sends a block write command.

Parameters
cmd_codeThe command code.
dataThe data to be written.
lengthThe number of bytes being written.
Returns
Returns PX4_OK on success, -errno on failure.

Definition at line 120 of file SMBus.cpp.

References get_pec().

Referenced by BATT_SMBUS::dataflash_read(), BATT_SMBUS::dataflash_write(), BATT_SMBUS::manufacturer_read(), and BATT_SMBUS::manufacturer_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_pec()

uint8_t SMBus::get_pec ( uint8_t *  buffer,
uint8_t  length 
)

Calculates the PEC from the data.

Parameters
bufferThe buffer that stores the data to perform the CRC over.
lengthThe number of bytes being written.
Returns
Returns PX4_OK on success, -errno on failure.

Definition at line 151 of file SMBus.cpp.

References SMBUS_PEC_POLYNOMIAL.

Referenced by block_read(), block_write(), read_word(), and write_word().

Here is the caller graph for this function:

◆ read_word()

int SMBus::read_word ( const uint8_t  cmd_code,
uint16_t &  data 
)

Sends a read word command.

Parameters
cmd_codeThe command code.
dataThe 2 bytes of returned data plus a 1 byte CRC if used.
Returns
Returns PX4_OK on success, -errno on failure.

Definition at line 53 of file SMBus.cpp.

References get_pec().

Referenced by BATT_SMBUS::get_cell_voltages(), BATT_SMBUS::get_serial_number(), BATT_SMBUS::get_startup_info(), BATT_SMBUS::manufacture_date(), and BATT_SMBUS::Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_word()

int SMBus::write_word ( const uint8_t  cmd_code,
uint16_t  data 
)

Sends a write word command.

Parameters
cmd_codeThe command code.
dataThe 2 bytes of data to be transfered.
Returns
Returns PX4_OK on success, -errno on failure.

Definition at line 77 of file SMBus.cpp.

References get_pec().

Referenced by BATT_SMBUS::unseal().

Here is the call graph for this function:
Here is the caller graph for this function:

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