APM:Libraries
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
F4Light::I2CDevice Class Reference

#include <I2CDevice.h>

Inheritance diagram for F4Light::I2CDevice:
[legend]
Collaboration diagram for F4Light::I2CDevice:
[legend]

Public Member Functions

 I2CDevice (uint8_t bus, uint8_t address)
 
 ~I2CDevice ()
 
void set_address (uint8_t address) override
 
void set_retries (uint8_t retries) override
 
bool transfer (const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len) override
 
bool read_registers_multiple (uint8_t first_reg, uint8_t *recv, uint32_t recv_len, uint8_t times)
 
bool set_speed (enum AP_HAL::Device::Speed speed) override
 
F4Light::Semaphoreget_semaphore () override
 
AP_HAL::Device::PeriodicHandle register_periodic_callback (uint32_t period_usec, Device::PeriodicCb proc) override
 
bool adjust_periodic_callback (AP_HAL::Device::PeriodicHandle h, uint32_t period_usec) override
 
bool unregister_callback (PeriodicHandle h) override
 
void register_completion_callback (Handler h)
 
void register_completion_callback (AP_HAL::MemberProc proc)
 
void register_completion_callback (AP_HAL::Proc proc)
 
uint32_t get_error_count ()
 
uint8_t get_last_error ()
 
uint8_t get_last_error_state ()
 
uint8_t get_bus ()
 
uint8_t get_addr ()
 
void do_bus_reset ()
 
- Public Member Functions inherited from AP_HAL::I2CDevice
 I2CDevice ()
 
virtual void set_split_transfers (bool set)
 
- Public Member Functions inherited from AP_HAL::Device
 FUNCTOR_TYPEDEF (PeriodicCb, void)
 
 Device (enum BusType type)
 
enum BusType bus_type (void) const
 
uint8_t bus_num (void) const
 
uint32_t get_bus_id (void) const
 
uint8_t get_bus_address (void) const
 
void set_device_type (uint8_t devtype)
 
virtual ~Device ()
 
bool read_registers (uint8_t first_reg, uint8_t *recv, uint32_t recv_len)
 
bool write_register (uint8_t reg, uint8_t val, bool checked=false)
 
void set_checked_register (uint8_t reg, uint8_t val)
 
bool setup_checked_registers (uint8_t num_regs, uint8_t frequency=10)
 
bool check_next_register (void)
 
bool read (uint8_t *recv, uint32_t recv_len)
 
virtual PeriodicHandle register_periodic_callback (uint32_t period_usec, PeriodicCb)=0
 
virtual bool set_chip_select (bool set)
 
void set_read_flag (uint8_t flag)
 
uint32_t get_bus_id_devtype (uint8_t devtype)
 

Static Public Member Functions

static void lateInit ()
 
static uint8_t get_dev_count ()
 
static F4Light::I2CDeviceget_device (uint8_t i)
 
- Static Public Member Functions inherited from AP_HAL::Device
static uint32_t make_bus_id (enum BusType bus_type, uint8_t bus, uint8_t address, uint8_t devtype)
 
static uint32_t change_bus_id (uint32_t old_id, uint8_t devtype)
 

Private Member Functions

void init ()
 
uint32_t i2c_read (uint8_t addr, const uint8_t *tx_buff, uint8_t txlen, uint8_t *rx_buff, uint8_t rxlen)
 
uint32_t i2c_write (uint8_t addr, const uint8_t *tx_buff, uint8_t len)
 
void isr_ev ()
 
uint32_t wait_stop_done (bool v)
 
void finish_transfer ()
 
void _do_bus_reset ()
 

Private Attributes

uint8_t _bus
 
uint16_t _offs
 
uint8_t _address
 
uint8_t _retries
 
uint32_t _lockup_count
 
bool _initialized
 
uint8_t last_error
 
uint8_t last_error_state
 
bool _slow
 
bool _failed
 
bool need_reset
 
void * _task
 
const i2c_dev_dev
 
Soft_I2Cs_i2c
 
Handler _completion_cb
 
uint8_t _state
 
volatile uint8_t _error
 
uint8_t _addr
 
const uint8_t * _tx_buff
 
uint8_t _tx_len
 
uint8_t * _rx_buff
 
uint8_t _rx_len
 

Static Private Attributes

static F4Light::Semaphore _semaphores [3]
 
static const timer_dev_timers [3]
 
static F4Light::I2CDevicedevices [MAX_I2C_DEVICES]
 
static uint8_t dev_count
 
static bool lateInitDone =false
 

Additional Inherited Members

- Public Types inherited from AP_HAL::Device
enum  BusType { BUS_TYPE_UNKNOWN = 0, BUS_TYPE_I2C = 1, BUS_TYPE_SPI = 2, BUS_TYPE_UAVCAN = 3 }
 
enum  Speed { SPEED_HIGH, SPEED_LOW }
 
typedef void * PeriodicHandle
 
- Protected Member Functions inherited from AP_HAL::Device
void set_device_address (uint8_t address)
 
void set_device_bus (uint8_t bus)
 
- Protected Attributes inherited from AP_HAL::Device
uint8_t _read_flag = 0
 
union DeviceId _bus_id
 

Detailed Description

Definition at line 63 of file I2CDevice.h.

Constructor & Destructor Documentation

◆ I2CDevice()

I2CDevice::I2CDevice ( uint8_t  bus,
uint8_t  address 
)

Definition at line 47 of file I2CDevice.cpp.

◆ ~I2CDevice()

I2CDevice::~I2CDevice ( )
virtual

Reimplemented from AP_HAL::I2CDevice.

Definition at line 66 of file I2CDevice.cpp.

Member Function Documentation

◆ _do_bus_reset()

void I2CDevice::_do_bus_reset ( )
private

Definition at line 384 of file I2CDevice.cpp.

Referenced by do_bus_reset(), init(), register_completion_callback(), and transfer().

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

◆ adjust_periodic_callback()

bool F4Light::I2CDevice::adjust_periodic_callback ( AP_HAL::Device::PeriodicHandle  h,
uint32_t  period_usec 
)
inlineoverridevirtual

Implements AP_HAL::I2CDevice.

Definition at line 106 of file I2CDevice.h.

Here is the call graph for this function:

◆ do_bus_reset()

void I2CDevice::do_bus_reset ( )

Definition at line 377 of file I2CDevice.cpp.

Referenced by transfer().

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

◆ finish_transfer()

void I2CDevice::finish_transfer ( )
private

Definition at line 709 of file I2CDevice.cpp.

Referenced by i2c_read(), i2c_write(), and isr_ev().

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

◆ get_addr()

uint8_t F4Light::I2CDevice::get_addr ( )
inline

Definition at line 129 of file I2CDevice.h.

Referenced by F4Light::Scheduler::_print_stats(), and F4Light::I2CDeviceManager::get_device().

Here is the caller graph for this function:

◆ get_bus()

uint8_t F4Light::I2CDevice::get_bus ( void  )
inline

Definition at line 128 of file I2CDevice.h.

Referenced by F4Light::Scheduler::_print_stats(), and F4Light::I2CDeviceManager::get_device().

Here is the caller graph for this function:

◆ get_dev_count()

static uint8_t F4Light::I2CDevice::get_dev_count ( )
inlinestatic

Definition at line 131 of file I2CDevice.h.

Referenced by F4Light::Scheduler::_print_stats(), and F4Light::I2CDeviceManager::get_device().

Here is the caller graph for this function:

◆ get_device()

static F4Light::I2CDevice* F4Light::I2CDevice::get_device ( uint8_t  i)
inlinestatic

Definition at line 132 of file I2CDevice.h.

Referenced by F4Light::Scheduler::_print_stats(), and F4Light::I2CDeviceManager::get_device().

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

◆ get_error_count()

uint32_t F4Light::I2CDevice::get_error_count ( )
inline

Definition at line 125 of file I2CDevice.h.

Referenced by F4Light::Scheduler::_print_stats().

Here is the caller graph for this function:

◆ get_last_error()

uint8_t F4Light::I2CDevice::get_last_error ( )
inline

Definition at line 126 of file I2CDevice.h.

Referenced by F4Light::Scheduler::_print_stats().

Here is the caller graph for this function:

◆ get_last_error_state()

uint8_t F4Light::I2CDevice::get_last_error_state ( )
inline

Definition at line 127 of file I2CDevice.h.

Referenced by F4Light::Scheduler::_print_stats().

Here is the caller graph for this function:

◆ get_semaphore()

F4Light::Semaphore* F4Light::I2CDevice::get_semaphore ( )
inlineoverridevirtual

Implements AP_HAL::I2CDevice.

Definition at line 96 of file I2CDevice.h.

◆ i2c_read()

uint32_t I2CDevice::i2c_read ( uint8_t  addr,
const uint8_t *  tx_buff,
uint8_t  txlen,
uint8_t *  rx_buff,
uint8_t  rxlen 
)
private

Definition at line 476 of file I2CDevice.cpp.

Referenced by transfer().

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

◆ i2c_write()

uint32_t I2CDevice::i2c_write ( uint8_t  addr,
const uint8_t *  tx_buff,
uint8_t  len 
)
private

Definition at line 431 of file I2CDevice.cpp.

Referenced by transfer().

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

◆ init()

void I2CDevice::init ( void  )
private

Definition at line 75 of file I2CDevice.cpp.

Referenced by transfer(), and wait_stop_done().

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

◆ isr_ev()

void I2CDevice::isr_ev ( )
private

Definition at line 546 of file I2CDevice.cpp.

Referenced by i2c_read(), and i2c_write().

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

◆ lateInit()

void I2CDevice::lateInit ( )
static

Definition at line 42 of file I2CDevice.cpp.

◆ read_registers_multiple()

bool I2CDevice::read_registers_multiple ( uint8_t  first_reg,
uint8_t *  recv,
uint32_t  recv_len,
uint8_t  times 
)
virtual

Implements AP_HAL::I2CDevice.

Definition at line 399 of file I2CDevice.cpp.

Here is the call graph for this function:

◆ register_completion_callback() [1/3]

void I2CDevice::register_completion_callback ( Handler  h)

Definition at line 205 of file I2CDevice.cpp.

Referenced by transfer().

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

◆ register_completion_callback() [2/3]

void F4Light::I2CDevice::register_completion_callback ( AP_HAL::MemberProc  proc)
inlinevirtual

Reimplemented from AP_HAL::Device.

Definition at line 116 of file I2CDevice.h.

◆ register_completion_callback() [3/3]

void F4Light::I2CDevice::register_completion_callback ( AP_HAL::Proc  proc)
inlinevirtual

Reimplemented from AP_HAL::Device.

Definition at line 120 of file I2CDevice.h.

◆ register_periodic_callback()

AP_HAL::Device::PeriodicHandle F4Light::I2CDevice::register_periodic_callback ( uint32_t  period_usec,
Device::PeriodicCb  proc 
)
inlineoverridevirtual

Implements AP_HAL::I2CDevice.

Definition at line 99 of file I2CDevice.h.

Here is the call graph for this function:

◆ set_address()

void F4Light::I2CDevice::set_address ( uint8_t  address)
inlineoverridevirtual

Reimplemented from AP_HAL::Device.

Definition at line 75 of file I2CDevice.h.

◆ set_retries()

void F4Light::I2CDevice::set_retries ( uint8_t  retries)
inlineoverridevirtual

Reimplemented from AP_HAL::Device.

Definition at line 78 of file I2CDevice.h.

◆ set_speed()

bool F4Light::I2CDevice::set_speed ( enum AP_HAL::Device::Speed  speed)
inlineoverridevirtual

Implements AP_HAL::I2CDevice.

Definition at line 93 of file I2CDevice.h.

◆ transfer()

bool I2CDevice::transfer ( const uint8_t *  send,
uint32_t  send_len,
uint8_t *  recv,
uint32_t  recv_len 
)
overridevirtual

Implements AP_HAL::I2CDevice.

Definition at line 217 of file I2CDevice.cpp.

Here is the call graph for this function:

◆ unregister_callback()

bool F4Light::I2CDevice::unregister_callback ( PeriodicHandle  h)
inlineoverridevirtual

Reimplemented from AP_HAL::Device.

Definition at line 112 of file I2CDevice.h.

Here is the call graph for this function:

◆ wait_stop_done()

uint32_t I2CDevice::wait_stop_done ( bool  v)
private

Definition at line 728 of file I2CDevice.cpp.

Referenced by i2c_read(), and i2c_write().

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

Member Data Documentation

◆ _addr

uint8_t F4Light::I2CDevice::_addr
private

Definition at line 172 of file I2CDevice.h.

Referenced by i2c_read(), i2c_write(), and isr_ev().

◆ _address

uint8_t F4Light::I2CDevice::_address
private

Definition at line 147 of file I2CDevice.h.

Referenced by transfer().

◆ _bus

uint8_t F4Light::I2CDevice::_bus
private

Definition at line 145 of file I2CDevice.h.

Referenced by do_bus_reset(), init(), and transfer().

◆ _completion_cb

Handler F4Light::I2CDevice::_completion_cb
private

◆ _dev

const i2c_dev* F4Light::I2CDevice::_dev
private

◆ _error

volatile uint8_t F4Light::I2CDevice::_error
private

Definition at line 171 of file I2CDevice.h.

Referenced by i2c_read(), i2c_write(), and isr_ev().

◆ _failed

bool F4Light::I2CDevice::_failed
private

Definition at line 154 of file I2CDevice.h.

Referenced by _do_bus_reset(), init(), and transfer().

◆ _initialized

bool F4Light::I2CDevice::_initialized
private

Definition at line 150 of file I2CDevice.h.

Referenced by init(), transfer(), and wait_stop_done().

◆ _lockup_count

uint32_t F4Light::I2CDevice::_lockup_count
private

Definition at line 149 of file I2CDevice.h.

Referenced by transfer(), and wait_stop_done().

◆ _offs

uint16_t F4Light::I2CDevice::_offs
private

Definition at line 146 of file I2CDevice.h.

Referenced by init().

◆ _retries

uint8_t F4Light::I2CDevice::_retries
private

Definition at line 148 of file I2CDevice.h.

Referenced by transfer().

◆ _rx_buff

uint8_t* F4Light::I2CDevice::_rx_buff
private

Definition at line 175 of file I2CDevice.h.

Referenced by i2c_read(), and isr_ev().

◆ _rx_len

uint8_t F4Light::I2CDevice::_rx_len
private

Definition at line 176 of file I2CDevice.h.

Referenced by i2c_read(), i2c_write(), and isr_ev().

◆ _semaphores

F4Light::Semaphore I2CDevice::_semaphores
staticprivate

Definition at line 161 of file I2CDevice.h.

Referenced by do_bus_reset().

◆ _slow

bool F4Light::I2CDevice::_slow
private

Definition at line 153 of file I2CDevice.h.

Referenced by init().

◆ _state

uint8_t F4Light::I2CDevice::_state
private

Definition at line 170 of file I2CDevice.h.

Referenced by i2c_read(), i2c_write(), isr_ev(), and transfer().

◆ _task

void* F4Light::I2CDevice::_task
private

Definition at line 156 of file I2CDevice.h.

Referenced by finish_transfer(), i2c_read(), and i2c_write().

◆ _timers

const timer_dev * I2CDevice::_timers
staticprivate
Initial value:

Definition at line 162 of file I2CDevice.h.

Referenced by init().

◆ _tx_buff

const uint8_t* F4Light::I2CDevice::_tx_buff
private

Definition at line 173 of file I2CDevice.h.

Referenced by i2c_read(), i2c_write(), and isr_ev().

◆ _tx_len

uint8_t F4Light::I2CDevice::_tx_len
private

Definition at line 174 of file I2CDevice.h.

Referenced by i2c_read(), i2c_write(), and isr_ev().

◆ dev_count

uint8_t I2CDevice::dev_count
staticprivate

Definition at line 165 of file I2CDevice.h.

Referenced by I2CDevice(), and ~I2CDevice().

◆ devices

I2CDevice * I2CDevice::devices
staticprivate

Definition at line 164 of file I2CDevice.h.

Referenced by I2CDevice(), and ~I2CDevice().

◆ last_error

uint8_t F4Light::I2CDevice::last_error
private

Definition at line 151 of file I2CDevice.h.

Referenced by transfer(), and wait_stop_done().

◆ last_error_state

uint8_t F4Light::I2CDevice::last_error_state
private

Definition at line 152 of file I2CDevice.h.

Referenced by transfer().

◆ lateInitDone

bool I2CDevice::lateInitDone =false
staticprivate

Definition at line 166 of file I2CDevice.h.

Referenced by init(), and lateInit().

◆ need_reset

bool F4Light::I2CDevice::need_reset
private

Definition at line 155 of file I2CDevice.h.

Referenced by _do_bus_reset(), init(), transfer(), and wait_stop_done().

◆ s_i2c

Soft_I2C* F4Light::I2CDevice::s_i2c
private

Definition at line 159 of file I2CDevice.h.

Referenced by init(), and transfer().


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