APM:Libraries
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
AP_HAL::Device Class Referenceabstract

#include <Device.h>

Inheritance diagram for AP_HAL::Device:
[legend]
Collaboration diagram for AP_HAL::Device:
[legend]

Classes

struct  checkreg
 
union  DeviceId
 
struct  DeviceStructure
 

Public Types

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
 

Public Member Functions

 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 ()
 
virtual void set_address (uint8_t address)
 
virtual bool set_speed (Speed speed)=0
 
virtual bool transfer (const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len)=0
 
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 AP_HAL::Semaphoreget_semaphore ()=0
 
virtual PeriodicHandle register_periodic_callback (uint32_t period_usec, PeriodicCb)=0
 
virtual bool adjust_periodic_callback (PeriodicHandle h, uint32_t period_usec)=0
 
virtual bool unregister_callback (PeriodicHandle h)
 
virtual void register_completion_callback (AP_HAL::MemberProc proc)
 
virtual void register_completion_callback (AP_HAL::Proc proc)
 
virtual bool set_chip_select (bool set)
 
void set_read_flag (uint8_t flag)
 
uint32_t get_bus_id_devtype (uint8_t devtype)
 
virtual void set_retries (uint8_t retries)
 

Static Public Member Functions

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)
 

Protected Member Functions

void set_device_address (uint8_t address)
 
void set_device_bus (uint8_t bus)
 

Protected Attributes

uint8_t _read_flag = 0
 
union DeviceId _bus_id
 

Private Attributes

struct {
   uint8_t   n_allocated
 
   uint8_t   n_set
 
   uint8_t   next
 
   uint8_t   frequency
 
   uint8_t   counter
 
   struct checkreg *   regs
 
_checked
 

Detailed Description

Definition at line 27 of file Device.h.

Member Typedef Documentation

◆ PeriodicHandle

Definition at line 42 of file Device.h.

Member Enumeration Documentation

◆ BusType

Enumerator
BUS_TYPE_UNKNOWN 
BUS_TYPE_I2C 
BUS_TYPE_SPI 
BUS_TYPE_UAVCAN 

Definition at line 29 of file Device.h.

◆ Speed

Enumerator
SPEED_HIGH 
SPEED_LOW 

Definition at line 36 of file Device.h.

Constructor & Destructor Documentation

◆ Device()

AP_HAL::Device::Device ( enum BusType  type)
inline

Definition at line 44 of file Device.h.

◆ ~Device()

virtual AP_HAL::Device::~Device ( )
inlinevirtual

Definition at line 75 of file Device.h.

Member Function Documentation

◆ adjust_periodic_callback()

virtual bool AP_HAL::Device::adjust_periodic_callback ( PeriodicHandle  h,
uint32_t  period_usec 
)
pure virtual

Implemented in F4Light::SPIDevice, F4Light::I2CDevice, ChibiOS::SPIDevice, PX4::SPIDevice, VRBRAIN::SPIDevice, ChibiOS::I2CDevice, Empty::I2CDevice, Linux::I2CDevice, AP_HAL::SPIDevice, PX4::I2CDevice, VRBRAIN::I2CDevice, AP_HAL::I2CDevice, and Linux::SPIDevice.

Referenced by read(), and AP_Compass_IST8310::timer().

Here is the caller graph for this function:

◆ bus_num()

uint8_t AP_HAL::Device::bus_num ( void  ) const
inline

Definition at line 55 of file Device.h.

Referenced by AP_Baro_MS56XX::_init(), AP_Baro_KellerLD::_init(), VRBRAIN::DeviceBus::bus_thread(), PX4::DeviceBus::bus_thread(), AP_Compass_IST8310::init(), AP_Compass_QMC5883L::init(), and ChibiOS::DeviceBus::register_periodic_callback().

Here is the caller graph for this function:

◆ bus_type()

enum BusType AP_HAL::Device::bus_type ( void  ) const
inline

◆ change_bus_id()

static uint32_t AP_HAL::Device::change_bus_id ( uint32_t  old_id,
uint8_t  devtype 
)
inlinestatic

return a new bus ID for the same bus connection but a new device type. This is used for auxillary bus connections

Definition at line 245 of file Device.h.

Referenced by get_bus_id_devtype(), and AuxiliaryBus::set_device_type().

Here is the caller graph for this function:

◆ check_next_register()

bool AP_HAL::Device::check_next_register ( void  )

check next register value for correctness. Return false if value is incorrect or register checking has not been setup

Definition at line 85 of file Device.cpp.

Referenced by AP_InertialSensor_LSM9DS1::_poll_data(), AP_InertialSensor_LSM9DS0::_poll_data(), AP_InertialSensor_Invensense::_read_fifo(), AP_Compass_BMM150::_update(), AP_RangeFinder_PulsedLightLRF::timer(), AP_Compass_LIS3MDL::timer(), AP_Compass_AK09916::timer(), and write_register().

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

◆ FUNCTOR_TYPEDEF()

AP_HAL::Device::FUNCTOR_TYPEDEF ( PeriodicCb  ,
void   
)

◆ get_bus_address()

uint8_t AP_HAL::Device::get_bus_address ( void  ) const
inline

Definition at line 65 of file Device.h.

Referenced by AP_Baro_LPS2XH::_imu_i2c_init(), AP_Baro_MS56XX::_init(), AP_Baro_KellerLD::_init(), AP_Baro_ICM20789::imu_i2c_init(), AP_Compass_IST8310::init(), and AP_Compass_QMC5883L::init().

Here is the caller graph for this function:

◆ get_bus_id()

uint32_t AP_HAL::Device::get_bus_id ( void  ) const
inline

◆ get_bus_id_devtype()

uint32_t AP_HAL::Device::get_bus_id_devtype ( uint8_t  devtype)
inline

return bus ID with a new devtype

Definition at line 255 of file Device.h.

Referenced by AP_InertialSensor_LSM9DS0::start(), AP_InertialSensor_LSM9DS1::start(), AP_InertialSensor_L3G4200D::start(), AP_InertialSensor_BMI160::start(), AP_InertialSensor_RST::start(), and AP_InertialSensor_Invensense::start().

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

◆ get_semaphore()

virtual AP_HAL::Semaphore* AP_HAL::Device::get_semaphore ( )
pure virtual

◆ make_bus_id()

static uint32_t AP_HAL::Device::make_bus_id ( enum BusType  bus_type,
uint8_t  bus,
uint8_t  address,
uint8_t  devtype 
)
inlinestatic

make a bus id given bus type, bus number, bus address and device type This is for use by devices that do not use one of the standard HAL Device types, such as UAVCAN devices

Definition at line 232 of file Device.h.

Referenced by Compass::_have_driver().

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

◆ read()

bool AP_HAL::Device::read ( uint8_t *  recv,
uint32_t  recv_len 
)
inline

Wrapper function over transfer() to read a sequence of bytes from device. No value is written, differently from the read_registers() method and hence doesn't include the read flag set by set_read_flag()

Definition at line 156 of file Device.h.

Referenced by AP_RangeFinder_LightWareI2C::get_reading().

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

◆ read_registers()

bool AP_HAL::Device::read_registers ( uint8_t  first_reg,
uint8_t *  recv,
uint32_t  recv_len 
)
inline

Wrapper function over transfer() to read recv_len registers, starting by first_reg, into the array pointed by recv. The read flag passed to set_read_flag(uint8_t) is ORed with first_reg before performing the transfer.

Return: true on a successful transfer, false on failure.

Definition at line 113 of file Device.h.

Referenced by AP_InertialSensor_L3G4200D::_accumulate(), AP_Compass_LSM303D::_block_read(), AP_Compass_LSM9DS1::_block_read(), AP_InertialSensor_Invensense::_block_read(), AP_InertialSensor_BMI160::_check_err_reg(), AP_Baro_LPS2XH::_check_whoami(), AP_Compass_QMC5883L::_check_whoami(), AP_Compass_QMC5883L::_dump_registers(), Linux::RCOutput_Bebop::_get_info(), AP_Compass_MAG3110::_hardware_init(), AP_InertialSensor_BMI160::_hardware_init(), AP_Baro_LPS2XH::_imu_i2c_init(), AP_Baro_BMP085::_init(), AP_Baro_BMP280::_init(), AP_InertialSensor_RST::_init_accel(), AP_InertialSensor_RST::_init_gyro(), AP_InertialSensor_L3G4200D::_init_sensor(), AP_Compass_BMM150::_load_trim_values(), AP_InertialSensor_BMI160::_read_fifo(), AP_Baro_BMP085::_read_pressure(), AP_Compass_MAG3110::_read_sample(), AP_Baro_BMP085::_read_temp(), AP_Compass_LSM303D::_register_read(), AP_Compass_LSM9DS1::_register_read(), AP_InertialSensor_LSM9DS1::_register_read(), AP_InertialSensor_Invensense::_register_read(), AP_InertialSensor_LSM9DS0::_register_read_g(), AP_InertialSensor_LSM9DS0::_register_read_xm(), AP_Baro_BMP280::_timer(), AP_ADC_ADS1115::_update(), AP_Compass_BMM150::_update(), AP_Baro_LPS2XH::_update_pressure(), AP_Baro_LPS2XH::_update_temperature(), AP_InertialSensor_RST::accel_measure(), AP_AK8963_BusDriver_HALDevice::block_read(), AP_RangeFinder_VL53L0X::check_id(), check_next_register(), AP_InertialSensor_RST::gyro_measure(), GCS_MAVLINK::handle_device_op_read(), AP_Baro_ICM20789::imu_i2c_init(), AP_Baro_ICM20789::imu_spi_init(), AP_RAMTRON::init(), AP_Baro_DPS280::init(), AP_Baro_FBM320::init(), AP_RangeFinder_VL53L0X::init(), AP_RangeFinder_TeraRangerI2C::init(), AP_RangeFinder_PulsedLightLRF::init(), AP_Compass_BMM150::init(), AP_Compass_IST8310::init(), AP_Compass_LIS3MDL::init(), AP_Compass_MMC3416::init(), AP_Compass_AK09916::init(), AP_Airspeed_MS5525::read_adc(), AP_BattMonitor_SMBus_Solo::read_block(), AP_BattMonitor_SMBus_Maxell::read_block(), AP_Baro_FBM320::read_calibration(), AP_Baro_DPS280::read_calibration(), read_calibration_data(), Linux::RCOutput_Bebop::read_obs_data(), AP_Airspeed_MS5525::read_prom(), AP_RangeFinder_VL53L0X::read_register(), F4Light::I2CDevice::read_registers_multiple(), AP_BattMonitor_SMBus::read_word(), Radio_CC2500::ReadFifo(), Radio_CC2500::ReadReg(), Radio_CC2500::ReadRegisterMulti(), AP_AK8963_BusDriver_HALDevice::register_read(), AP_OpticalFlow_PX4Flow::scan_buses(), AP_BoardConfig::spi_check_register(), AP_Baro_DPS280::timer(), AP_Baro_FBM320::timer(), AP_RangeFinder_PulsedLightLRF::timer(), AP_OpticalFlow_PX4Flow::timer(), AP_Compass_IST8310::timer(), AP_Compass_QMC5883L::timer(), AP_Compass_LIS3MDL::timer(), AP_Compass_MMC3416::timer(), and AP_Compass_AK09916::timer().

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

◆ register_completion_callback() [1/2]

virtual void AP_HAL::Device::register_completion_callback ( AP_HAL::MemberProc  proc)
inlinevirtual

Reimplemented in F4Light::SPIDevice, and F4Light::I2CDevice.

Definition at line 206 of file Device.h.

◆ register_completion_callback() [2/2]

virtual void AP_HAL::Device::register_completion_callback ( AP_HAL::Proc  proc)
inlinevirtual

Reimplemented in F4Light::SPIDevice, and F4Light::I2CDevice.

Definition at line 207 of file Device.h.

◆ register_periodic_callback()

virtual PeriodicHandle AP_HAL::Device::register_periodic_callback ( uint32_t  period_usec,
PeriodicCb   
)
pure virtual

◆ set_address()

virtual void AP_HAL::Device::set_address ( uint8_t  address)
inlinevirtual

Reimplemented in F4Light::I2CDevice, ChibiOS::I2CDevice, Linux::I2CDevice, PX4::I2CDevice, VRBRAIN::I2CDevice, and Empty::I2CDevice.

Definition at line 85 of file Device.h.

Referenced by AP_Baro_LPS2XH::_imu_i2c_init(), and AP_Baro_ICM20789::imu_i2c_init().

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

◆ set_checked_register()

void AP_HAL::Device::set_checked_register ( uint8_t  reg,
uint8_t  val 
)

set a value for a checked register

Definition at line 60 of file Device.cpp.

Referenced by write_register().

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

◆ set_chip_select()

virtual bool AP_HAL::Device::set_chip_select ( bool  set)
inlinevirtual

Reimplemented in ChibiOS::SPIDevice, PX4::SPIDevice, and VRBRAIN::SPIDevice.

Definition at line 214 of file Device.h.

Referenced by AP_InertialSensor_Invensense::_read_fifo(), AP_OpticalFlow_Pixart::motion_burst(), AP_RAMTRON::read(), AP_OpticalFlow_Pixart::reg_read(), AP_OpticalFlow_Pixart::reg_write(), sdcard_stop(), AP_OpticalFlow_Pixart::srom_download(), and AP_RAMTRON::write().

Here is the caller graph for this function:

◆ set_device_address()

void AP_HAL::Device::set_device_address ( uint8_t  address)
inlineprotected

Definition at line 286 of file Device.h.

Referenced by PX4::I2CDevice::I2CDevice(), VRBRAIN::I2CDevice::I2CDevice(), Linux::I2CDevice::I2CDevice(), ChibiOS::I2CDevice::I2CDevice(), Linux::SPIDevice::SPIDevice(), VRBRAIN::SPIDevice::SPIDevice(), PX4::SPIDevice::SPIDevice(), and ChibiOS::SPIDevice::SPIDevice().

Here is the caller graph for this function:

◆ set_device_bus()

void AP_HAL::Device::set_device_bus ( uint8_t  bus)
inlineprotected

Definition at line 291 of file Device.h.

Referenced by PX4::I2CDevice::I2CDevice(), VRBRAIN::I2CDevice::I2CDevice(), Linux::I2CDevice::I2CDevice(), ChibiOS::I2CDevice::I2CDevice(), Linux::SPIDevice::SPIDevice(), VRBRAIN::SPIDevice::SPIDevice(), PX4::SPIDevice::SPIDevice(), and ChibiOS::SPIDevice::SPIDevice().

Here is the caller graph for this function:

◆ set_device_type()

void AP_HAL::Device::set_device_type ( uint8_t  devtype)
inline

Definition at line 70 of file Device.h.

Referenced by AP_Compass_LSM303D::init(), AP_Compass_LSM9DS1::init(), AP_Compass_MAG3110::init(), AP_Compass_BMM150::init(), AP_Compass_IST8310::init(), AP_Compass_QMC5883L::init(), AP_Compass_LIS3MDL::init(), AP_Compass_MMC3416::init(), and AP_Compass_AK09916::init().

Here is the caller graph for this function:

◆ set_read_flag()

void AP_HAL::Device::set_read_flag ( uint8_t  flag)
inline

Some devices connected on the I2C or SPI bus require a bit to be set on the register address in order to perform a read operation. This sets a flag to be used by read_registers(). The flag's default value is zero.

Definition at line 221 of file Device.h.

Referenced by AP_InertialSensor_LSM9DS1::_hardware_init(), AP_InertialSensor_LSM9DS0::_hardware_init(), AP_Baro_LPS2XH::_init(), AP_InertialSensor_BMI160::_init(), AP_InertialSensor_RST::_init_accel(), AP_InertialSensor_RST::_init_gyro(), AP_Baro_ICM20789::imu_spi_init(), AP_Compass_LIS3MDL::init(), AP_InertialSensor_Invensense::probe(), and AP_BoardConfig::spi_check_register().

Here is the caller graph for this function:

◆ set_retries()

virtual void AP_HAL::Device::set_retries ( uint8_t  retries)
inlinevirtual

◆ set_speed()

virtual bool AP_HAL::Device::set_speed ( Speed  speed)
pure virtual

◆ setup_checked_registers()

bool AP_HAL::Device::setup_checked_registers ( uint8_t  num_regs,
uint8_t  frequency = 10 
)

setup for register value checking. Frequency is how often to check registers. If set to 10 then every 10th call to check_next_register will check a register

Definition at line 39 of file Device.cpp.

Referenced by AP_InertialSensor_LSM9DS0::_hardware_init(), AP_InertialSensor_Invensense::_hardware_init(), AP_RangeFinder_PulsedLightLRF::init(), AP_Compass_BMM150::init(), AP_Compass_LIS3MDL::init(), AP_Compass_AK09916::init(), and write_register().

Here is the caller graph for this function:

◆ transfer()

virtual bool AP_HAL::Device::transfer ( const uint8_t *  send,
uint32_t  send_len,
uint8_t *  recv,
uint32_t  recv_len 
)
pure virtual

◆ unregister_callback()

virtual bool AP_HAL::Device::unregister_callback ( PeriodicHandle  h)
inlinevirtual

Reimplemented in F4Light::SPIDevice, and F4Light::I2CDevice.

Definition at line 198 of file Device.h.

◆ write_register()

bool AP_HAL::Device::write_register ( uint8_t  reg,
uint8_t  val,
bool  checked = false 
)
inline

Wrapper function over transfer() to write a byte to the register reg. The transfer is done by sending reg and val in that order.

Return: true on a successful transfer, false on failure.

Definition at line 125 of file Device.h.

Referenced by AP_Baro_BMP085::_cmd_read_pressure(), AP_Baro_BMP085::_cmd_read_temp(), AP_InertialSensor_BMI160::_configure_accel(), AP_InertialSensor_BMI160::_configure_fifo(), AP_InertialSensor_BMI160::_configure_gyro(), AP_InertialSensor_BMI160::_configure_int1_pin(), AP_InertialSensor_LSM9DS1::_fifo_reset(), AP_Compass_MAG3110::_hardware_init(), AP_InertialSensor_BMI160::_hardware_init(), AP_Baro_LPS2XH::_imu_i2c_init(), AP_Baro_BMP280::_init(), AP_Baro_LPS2XH::_init(), AP_InertialSensor_RST::_init_accel(), AP_InertialSensor_RST::_init_gyro(), AP_InertialSensor_L3G4200D::_init_sensor(), Linux::RCOutput_Bebop::_play_sound(), AP_InertialSensor_BMI160::_read_fifo(), AP_Compass_LSM303D::_register_write(), AP_Compass_LSM9DS1::_register_write(), AP_InertialSensor_LSM9DS1::_register_write(), AP_InertialSensor_Invensense::_register_write(), AP_InertialSensor_LSM9DS0::_register_write_g(), AP_InertialSensor_LSM9DS0::_register_write_xm(), Linux::RCOutput_Bebop::_toggle_gpio(), AP_Compass_BMM150::_update(), check_next_register(), GCS_MAVLINK::handle_device_op_write(), ToshibaLED_I2C::hw_init(), AP_Baro_ICM20789::imu_i2c_init(), AP_Baro_ICM20789::imu_spi_init(), AP_Baro_DPS280::init(), AP_Baro_FBM320::init(), AP_RangeFinder_PulsedLightLRF::init(), AP_Compass_BMM150::init(), AP_Compass_IST8310::init(), AP_Compass_QMC5883L::init(), AP_Compass_LIS3MDL::init(), AP_Compass_MMC3416::init(), AP_Compass_AK09916::init(), AP_AK8963_BusDriver_HALDevice::register_write(), Linux::RCOutput_PCA9685::set_freq(), AP_Compass_IST8310::start_conversion(), AP_Baro_FBM320::timer(), AP_RangeFinder_PulsedLightLRF::timer(), AP_Compass_MMC3416::timer(), AP_RangeFinder_VL53L0X::write_register(), Radio_CC2500::WriteReg(), and Radio_CC2500::WriteRegCheck().

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

Member Data Documentation

◆ _bus_id

union DeviceId AP_HAL::Device::_bus_id
protected

◆ _checked

struct { ... } AP_HAL::Device::_checked

◆ _read_flag

uint8_t AP_HAL::Device::_read_flag = 0
protected

◆ counter

uint8_t AP_HAL::Device::counter

Definition at line 306 of file Device.h.

◆ frequency

uint8_t AP_HAL::Device::frequency

Definition at line 305 of file Device.h.

Referenced by setup_checked_registers(), and write_register().

◆ n_allocated

uint8_t AP_HAL::Device::n_allocated

Definition at line 302 of file Device.h.

◆ n_set

uint8_t AP_HAL::Device::n_set

Definition at line 303 of file Device.h.

◆ next

uint8_t AP_HAL::Device::next

Definition at line 304 of file Device.h.

◆ regs

struct checkreg* AP_HAL::Device::regs

Definition at line 307 of file Device.h.

Referenced by set_checked_register().


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