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

Abstract class for character device on I2C. More...

#include <I2C.hpp>

Inheritance diagram for __EXPORT::I2C:
Collaboration diagram for __EXPORT::I2C:

Public Member Functions

 I2C (const I2C &)=delete
 
I2Coperator= (const I2C &)=delete
 
 I2C (I2C &&)=delete
 
I2Coperator= (I2C &&)=delete
 
virtual int init () override
 
 I2C (const I2C &)=delete
 
I2Coperator= (const I2C &)=delete
 
 I2C (I2C &&)=delete
 
I2Coperator= (I2C &&)=delete
 
virtual int init () override
 
 I2C (const I2C &)=delete
 
I2Coperator= (const I2C &)=delete
 
 I2C (I2C &&)=delete
 
I2Coperator= (I2C &&)=delete
 
virtual int init () override
 

Static Public Member Functions

static int set_bus_clock (unsigned bus, unsigned clock_hz)
 

Static Public Attributes

static unsigned int _bus_clocks [BOARD_NUMBER_I2C_BUSES] = BOARD_I2C_BUS_CLOCK_INIT
 

Protected Member Functions

 I2C (const char *name, const char *devname, const int bus, const uint16_t address, const uint32_t frequency)
 @ Constructor More...
 
virtual ~I2C ()
 
virtual int probe ()
 Check for the presence of the device on the bus. More...
 
int transfer (const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
 Perform an I2C transaction to the device. More...
 
virtual bool external () const override
 
 I2C (const char *name, const char *devname, const int bus, const uint16_t address, const uint32_t frequency)
 @ Constructor More...
 
virtual ~I2C ()
 
virtual int probe ()
 Check for the presence of the device on the bus. More...
 
int transfer (const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
 Perform an I2C transaction to the device. More...
 
virtual bool external () const override
 
 I2C (const char *name, const char *devname, const int bus, const uint16_t address, const uint32_t frequency)
 @ Constructor More...
 
virtual ~I2C ()
 
virtual int probe ()
 Check for the presence of the device on the bus. More...
 
int transfer (const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
 Perform an I2C transaction to the device. More...
 
virtual bool external () const override
 

Protected Attributes

uint8_t _retries {0}
 The number of times a read or write operation will be retried on error. More...
 

Private Attributes

uint32_t _frequency {0}
 
px4_i2c_dev_t * _dev {nullptr}
 
int _fd {-1}
 

Detailed Description

Abstract class for character device on I2C.

Definition at line 57 of file I2C.hpp.

Constructor & Destructor Documentation

◆ I2C() [1/9]

__EXPORT::I2C::I2C ( const I2C )
delete

◆ I2C() [2/9]

__EXPORT::I2C::I2C ( I2C &&  )
delete

◆ I2C() [3/9]

__EXPORT::I2C::I2C ( const char *  name,
const char *  devname,
const int  bus,
const uint16_t  address,
const uint32_t  frequency 
)
protected

@ Constructor

Parameters
nameDriver name
devnameDevice node name
busI2C bus on which the device lives
addressI2C bus address, or zero if set_address will be used
frequencyI2C bus frequency for the device (currently not used)

◆ ~I2C() [1/3]

virtual __EXPORT::I2C::~I2C ( )
protectedvirtual

◆ I2C() [4/9]

__EXPORT::I2C::I2C ( const I2C )
delete

◆ I2C() [5/9]

__EXPORT::I2C::I2C ( I2C &&  )
delete

◆ I2C() [6/9]

__EXPORT::I2C::I2C ( const char *  name,
const char *  devname,
const int  bus,
const uint16_t  address,
const uint32_t  frequency 
)
protected

@ Constructor

Parameters
nameDriver name
devnameDevice node name
busI2C bus on which the device lives
addressI2C bus address, or zero if set_address will be used
frequencyI2C bus frequency for the device (currently not used)

◆ ~I2C() [2/3]

virtual __EXPORT::I2C::~I2C ( )
protectedvirtual

◆ I2C() [7/9]

__EXPORT::I2C::I2C ( const I2C )
delete

◆ I2C() [8/9]

__EXPORT::I2C::I2C ( I2C &&  )
delete

◆ I2C() [9/9]

I2C::I2C ( const char *  name,
const char *  devname,
const int  bus,
const uint16_t  address,
const uint32_t  frequency 
)
protected

@ Constructor

Parameters
nameDriver name
devnameDevice node name
busI2C bus on which the device lives
addressI2C bus address, or zero if set_address will be used
frequencyI2C bus frequency for the device (currently not used)

Definition at line 54 of file I2C.cpp.

References DEVICE_DEBUG.

◆ ~I2C() [3/3]

I2C::~I2C ( )
protectedvirtual

Definition at line 67 of file I2C.cpp.

References _dev.

Member Function Documentation

◆ external() [1/3]

virtual bool __EXPORT::I2C::external ( ) const
inlineoverrideprotectedvirtual

Definition at line 109 of file I2C.hpp.

◆ external() [2/3]

virtual bool __EXPORT::I2C::external ( ) const
inlineoverrideprotectedvirtual

Definition at line 109 of file I2C.hpp.

References _fd.

◆ external() [3/3]

virtual bool __EXPORT::I2C::external ( ) const
inlineoverrideprotectedvirtual

Definition at line 112 of file I2C.hpp.

◆ init() [1/3]

virtual int __EXPORT::I2C::init ( )
overridevirtual

Referenced by set_bus_clock().

Here is the caller graph for this function:

◆ init() [2/3]

virtual int __EXPORT::I2C::init ( )
overridevirtual

◆ init() [3/3]

virtual int __EXPORT::I2C::init ( )
overridevirtual

◆ operator=() [1/6]

I2C& __EXPORT::I2C::operator= ( const I2C )
delete

◆ operator=() [2/6]

I2C& __EXPORT::I2C::operator= ( const I2C )
delete

◆ operator=() [3/6]

I2C& __EXPORT::I2C::operator= ( const I2C )
delete

◆ operator=() [4/6]

I2C& __EXPORT::I2C::operator= ( I2C &&  )
delete

◆ operator=() [5/6]

I2C& __EXPORT::I2C::operator= ( I2C &&  )
delete

◆ operator=() [6/6]

I2C& __EXPORT::I2C::operator= ( I2C &&  )
delete

◆ probe() [1/3]

virtual int __EXPORT::I2C::probe ( )
inlineprotectedvirtual

Check for the presence of the device on the bus.

Definition at line 93 of file I2C.hpp.

References send().

Here is the call graph for this function:

◆ probe() [2/3]

virtual int __EXPORT::I2C::probe ( )
inlineprotectedvirtual

Check for the presence of the device on the bus.

Definition at line 93 of file I2C.hpp.

References send().

Here is the call graph for this function:

◆ probe() [3/3]

virtual int __EXPORT::I2C::probe ( )
inlineprotectedvirtual

Check for the presence of the device on the bus.

Definition at line 96 of file I2C.hpp.

References send().

Referenced by set_bus_clock().

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

◆ set_bus_clock()

int I2C::set_bus_clock ( unsigned  bus,
unsigned  clock_hz 
)
static

Definition at line 76 of file I2C.cpp.

References _bus_clocks, _dev, _frequency, DEVICE_DEBUG, DEVICE_LOG, init(), ToneAlarmInterface::init(), OK, and probe().

Here is the call graph for this function:

◆ transfer() [1/3]

int __EXPORT::I2C::transfer ( const uint8_t *  send,
const unsigned  send_len,
uint8_t *  recv,
const unsigned  recv_len 
)
protected

Perform an I2C transaction to the device.

At least one of send_len and recv_len must be non-zero.

Parameters
sendPointer to bytes to send.
send_lenNumber of bytes to send.
recvPointer to buffer for bytes received.
recv_lenNumber of bytes to receive.
Returns
OK if the transfer was successful, -errno otherwise.

◆ transfer() [2/3]

int I2C::transfer ( const uint8_t *  send,
const unsigned  send_len,
uint8_t *  recv,
const unsigned  recv_len 
)
protected

Perform an I2C transaction to the device.

At least one of send_len and recv_len must be non-zero.

Parameters
sendPointer to bytes to send.
send_lenNumber of bytes to send.
recvPointer to buffer for bytes received.
recv_lenNumber of bytes to receive.
Returns
OK if the transfer was successful, -errno otherwise.

Definition at line 170 of file I2C.cpp.

References _bus_clocks, _dev, _retries, DEVICE_DEBUG, and send().

Here is the call graph for this function:

◆ transfer() [3/3]

int __EXPORT::I2C::transfer ( const uint8_t *  send,
const unsigned  send_len,
uint8_t *  recv,
const unsigned  recv_len 
)
protected

Perform an I2C transaction to the device.

At least one of send_len and recv_len must be non-zero.

Parameters
sendPointer to bytes to send.
send_lenNumber of bytes to send.
recvPointer to buffer for bytes received.
recv_lenNumber of bytes to receive.
Returns
OK if the transfer was successful, -errno otherwise.

Member Data Documentation

◆ _bus_clocks

unsigned int I2C::_bus_clocks = BOARD_I2C_BUS_CLOCK_INIT
static

Definition at line 72 of file I2C.hpp.

Referenced by set_bus_clock(), and transfer().

◆ _dev

px4_i2c_dev_t* __EXPORT::I2C::_dev {nullptr}
private

Definition at line 116 of file I2C.hpp.

Referenced by set_bus_clock(), transfer(), and ~I2C().

◆ _fd

int __EXPORT::I2C::_fd {-1}
private

Definition at line 112 of file I2C.hpp.

◆ _frequency

uint32_t __EXPORT::I2C::_frequency {0}
private

Definition at line 115 of file I2C.hpp.

Referenced by set_bus_clock().

◆ _retries

uint8_t __EXPORT::I2C::_retries {0}
protected

The number of times a read or write operation will be retried on error.

Definition at line 79 of file I2C.hpp.

Referenced by transfer().


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