41 #include <px4_platform_common/px4_config.h> 43 #include <sys/types.h> 52 #include <arch/board/board.h> 60 #include "board_config.h" 62 #define QMC5883L_ADDRESS 0x0D 72 virtual int read(
unsigned address,
void *
data,
unsigned count);
73 virtual int write(
unsigned address,
void *data,
unsigned count);
75 virtual int ioctl(
unsigned operation,
unsigned &arg);
104 case DEVIOCGDEVICEID:
105 return CDev::ioctl(
nullptr, operation, arg);
117 uint8_t
data[2] = {0, 0};
120 read(0x00, &data[0], 1);
121 read(0x00, &data[0], 1);
122 read(0x00, &data[0], 1);
126 bool read_valid =
false;
127 bool id_valid =
false;
129 for (
unsigned i = 0; i < _retries; i++) {
141 if (read_valid && id_valid) {
154 DEVICE_DEBUG(
"ID byte mismatch (%02x,%02x)", data[0], data[1]);
165 if (
sizeof(buf) < (count + 1)) {
170 memcpy(&buf[1], data, count);
172 return transfer(&buf[0], count + 1,
nullptr, 0);
178 uint8_t cmd = address;
179 return transfer(&cmd, 1, (uint8_t *)data, count);
#define MAGIOCGEXTERNAL
determine if mag is external or onboard
virtual int ioctl(unsigned operation, unsigned &arg)
Shared defines for the qmc5883 driver.
Generic device / sensor interface.
virtual int read(unsigned address, void *data, unsigned count)
virtual int write(unsigned address, void *data, unsigned count)
#define DRV_MAG_DEVTYPE_QMC5883
device::Device * QMC5883_I2C_interface(int bus)
virtual ~QMC5883_I2C()=default
Fundamental base class for all physical drivers (I2C, SPI).
#define DEVICE_DEBUG(FMT,...)
Base class for devices connected via I2C.