mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 16:13:34 +08:00
mpu9250 remove interface IOCTLs
This commit is contained in:
committed by
Lorenz Meier
parent
e164281a2e
commit
b0caea9edc
@@ -37,20 +37,7 @@
|
|||||||
* I2C interface for AK8963
|
* I2C interface for AK8963
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* XXX trim includes */
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <debug.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <arch/board/board.h>
|
|
||||||
|
|
||||||
#include <drivers/device/i2c.h>
|
#include <drivers/device/i2c.h>
|
||||||
#include <drivers/drv_accel.h>
|
#include <drivers/drv_accel.h>
|
||||||
#include <drivers/drv_device.h>
|
#include <drivers/drv_device.h>
|
||||||
@@ -58,9 +45,6 @@
|
|||||||
#include "mpu9250.h"
|
#include "mpu9250.h"
|
||||||
#include "mag.h"
|
#include "mag.h"
|
||||||
|
|
||||||
#include "board_config.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
|
|
||||||
device::Device *AK8963_I2C_interface(int bus, bool external_bus);
|
device::Device *AK8963_I2C_interface(int bus, bool external_bus);
|
||||||
@@ -69,19 +53,16 @@ class AK8963_I2C : public device::I2C
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AK8963_I2C(int bus);
|
AK8963_I2C(int bus);
|
||||||
virtual ~AK8963_I2C() = default;
|
~AK8963_I2C() override = default;
|
||||||
|
|
||||||
virtual int read(unsigned address, void *data, unsigned count);
|
int read(unsigned address, void *data, unsigned count) override;
|
||||||
virtual int write(unsigned address, void *data, unsigned count);
|
int write(unsigned address, void *data, unsigned count) override;
|
||||||
|
|
||||||
virtual int ioctl(unsigned operation, unsigned &arg);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int probe();
|
int probe() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
device::Device *
|
device::Device *
|
||||||
AK8963_I2C_interface(int bus, bool external_bus)
|
AK8963_I2C_interface(int bus, bool external_bus)
|
||||||
{
|
{
|
||||||
@@ -94,25 +75,6 @@ AK8963_I2C::AK8963_I2C(int bus) :
|
|||||||
_device_id.devid_s.devtype = DRV_MAG_DEVTYPE_MPU9250;
|
_device_id.devid_s.devtype = DRV_MAG_DEVTYPE_MPU9250;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
AK8963_I2C::ioctl(unsigned operation, unsigned &arg)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
switch (operation) {
|
|
||||||
case DEVIOCGDEVICEID:
|
|
||||||
return CDev::ioctl(nullptr, operation, arg);
|
|
||||||
|
|
||||||
case MPUIOCGIS_I2C:
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
AK8963_I2C::write(unsigned reg_speed, void *data, unsigned count)
|
AK8963_I2C::write(unsigned reg_speed, void *data, unsigned count)
|
||||||
{
|
{
|
||||||
@@ -134,7 +96,6 @@ AK8963_I2C::read(unsigned reg_speed, void *data, unsigned count)
|
|||||||
return transfer(&cmd, 1, (uint8_t *)data, count);
|
return transfer(&cmd, 1, (uint8_t *)data, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
AK8963_I2C::probe()
|
AK8963_I2C::probe()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -255,8 +255,7 @@ MPU9250::init()
|
|||||||
{
|
{
|
||||||
|
|
||||||
#if defined(USE_I2C)
|
#if defined(USE_I2C)
|
||||||
unsigned dummy;
|
use_i2c(_interface->get_device_bus_type() == Device::DeviceBusType_I2C);
|
||||||
use_i2c(_interface->ioctl(MPUIOCGIS_I2C, dummy));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -37,28 +37,13 @@
|
|||||||
* I2C interface for MPU9250
|
* I2C interface for MPU9250
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* XXX trim includes */
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <debug.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <arch/board/board.h>
|
|
||||||
|
|
||||||
#include <drivers/device/i2c.h>
|
#include <drivers/device/i2c.h>
|
||||||
#include <drivers/drv_accel.h>
|
#include <drivers/drv_accel.h>
|
||||||
#include <drivers/drv_device.h>
|
#include <drivers/drv_device.h>
|
||||||
|
|
||||||
#include "mpu9250.h"
|
#include "mpu9250.h"
|
||||||
|
|
||||||
#include "board_config.h"
|
|
||||||
|
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
|
|
||||||
device::Device *MPU9250_I2C_interface(int bus, uint32_t address, bool external_bus);
|
device::Device *MPU9250_I2C_interface(int bus, uint32_t address, bool external_bus);
|
||||||
@@ -67,15 +52,13 @@ class MPU9250_I2C : public device::I2C
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MPU9250_I2C(int bus, uint32_t address);
|
MPU9250_I2C(int bus, uint32_t address);
|
||||||
virtual ~MPU9250_I2C() = default;
|
~MPU9250_I2C() override = default;
|
||||||
|
|
||||||
virtual int read(unsigned address, void *data, unsigned count);
|
int read(unsigned address, void *data, unsigned count) override;
|
||||||
virtual int write(unsigned address, void *data, unsigned count);
|
int write(unsigned address, void *data, unsigned count) override;
|
||||||
|
|
||||||
virtual int ioctl(unsigned operation, unsigned &arg);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int probe();
|
int probe() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,26 +71,7 @@ MPU9250_I2C_interface(int bus, uint32_t address, bool external_bus)
|
|||||||
MPU9250_I2C::MPU9250_I2C(int bus, uint32_t address) :
|
MPU9250_I2C::MPU9250_I2C(int bus, uint32_t address) :
|
||||||
I2C("MPU9250_I2C", nullptr, bus, address, 400000)
|
I2C("MPU9250_I2C", nullptr, bus, address, 400000)
|
||||||
{
|
{
|
||||||
_device_id.devid_s.devtype = DRV_ACC_DEVTYPE_MPU9250;
|
_device_id.devid_s.devtype = DRV_ACC_DEVTYPE_MPU9250;
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
MPU9250_I2C::ioctl(unsigned operation, unsigned &arg)
|
|
||||||
{
|
|
||||||
int ret = PX4_ERROR;
|
|
||||||
|
|
||||||
switch (operation) {
|
|
||||||
case DEVIOCGDEVICEID:
|
|
||||||
return CDev::ioctl(nullptr, operation, arg);
|
|
||||||
|
|
||||||
case MPUIOCGIS_I2C:
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -42,24 +42,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <debug.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <arch/board/board.h>
|
|
||||||
|
|
||||||
#include <drivers/device/spi.h>
|
#include <drivers/device/spi.h>
|
||||||
#include <drivers/drv_accel.h>
|
#include <drivers/drv_accel.h>
|
||||||
#include <drivers/drv_device.h>
|
#include <drivers/drv_device.h>
|
||||||
|
|
||||||
#include "mpu9250.h"
|
#include "mpu9250.h"
|
||||||
#include <board_config.h>
|
|
||||||
|
|
||||||
#define DIR_READ 0x80
|
#define DIR_READ 0x80
|
||||||
#define DIR_WRITE 0x00
|
#define DIR_WRITE 0x00
|
||||||
@@ -76,27 +63,23 @@
|
|||||||
#define MPU9250_LOW_SPI_BUS_SPEED 1000*1000
|
#define MPU9250_LOW_SPI_BUS_SPEED 1000*1000
|
||||||
#define MPU9250_HIGH_SPI_BUS_SPEED 20*1000*1000
|
#define MPU9250_HIGH_SPI_BUS_SPEED 20*1000*1000
|
||||||
|
|
||||||
|
|
||||||
device::Device *MPU9250_SPI_interface(int bus, uint32_t cs, bool external_bus);
|
device::Device *MPU9250_SPI_interface(int bus, uint32_t cs, bool external_bus);
|
||||||
|
|
||||||
|
|
||||||
class MPU9250_SPI : public device::SPI
|
class MPU9250_SPI : public device::SPI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MPU9250_SPI(int bus, uint32_t device);
|
MPU9250_SPI(int bus, uint32_t device);
|
||||||
virtual ~MPU9250_SPI() = default;
|
~MPU9250_SPI() override = default;
|
||||||
|
|
||||||
virtual int read(unsigned address, void *data, unsigned count);
|
int read(unsigned address, void *data, unsigned count) override;
|
||||||
virtual int write(unsigned address, void *data, unsigned count);
|
int write(unsigned address, void *data, unsigned count) override;
|
||||||
|
|
||||||
virtual int ioctl(unsigned operation, unsigned &arg);
|
|
||||||
protected:
|
protected:
|
||||||
virtual int probe();
|
int probe() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/* Helper to set the desired speed and isolate the register on return */
|
/* Helper to set the desired speed and isolate the register on return */
|
||||||
|
|
||||||
void set_bus_frequency(unsigned ®_speed_reg_out);
|
void set_bus_frequency(unsigned ®_speed_reg_out);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,38 +104,16 @@ MPU9250_SPI_interface(int bus, uint32_t cs, bool external_bus)
|
|||||||
MPU9250_SPI::MPU9250_SPI(int bus, uint32_t device) :
|
MPU9250_SPI::MPU9250_SPI(int bus, uint32_t device) :
|
||||||
SPI("MPU9250", nullptr, bus, device, SPIDEV_MODE3, MPU9250_LOW_SPI_BUS_SPEED)
|
SPI("MPU9250", nullptr, bus, device, SPIDEV_MODE3, MPU9250_LOW_SPI_BUS_SPEED)
|
||||||
{
|
{
|
||||||
_device_id.devid_s.devtype = DRV_ACC_DEVTYPE_MPU9250;
|
_device_id.devid_s.devtype = DRV_ACC_DEVTYPE_MPU9250;
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
MPU9250_SPI::ioctl(unsigned operation, unsigned &arg)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
switch (operation) {
|
|
||||||
case DEVIOCGDEVICEID:
|
|
||||||
return CDev::ioctl(nullptr, operation, arg);
|
|
||||||
|
|
||||||
case MPUIOCGIS_I2C:
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default: {
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MPU9250_SPI::set_bus_frequency(unsigned ®_speed)
|
MPU9250_SPI::set_bus_frequency(unsigned ®_speed)
|
||||||
{
|
{
|
||||||
/* Set the desired speed */
|
/* Set the desired speed */
|
||||||
|
|
||||||
set_frequency(MPU9250_IS_HIGH_SPEED(reg_speed) ? MPU9250_HIGH_SPI_BUS_SPEED : MPU9250_LOW_SPI_BUS_SPEED);
|
set_frequency(MPU9250_IS_HIGH_SPEED(reg_speed) ? MPU9250_HIGH_SPI_BUS_SPEED : MPU9250_LOW_SPI_BUS_SPEED);
|
||||||
|
|
||||||
/* Isoolate the register on return */
|
/* Isoolate the register on return */
|
||||||
|
|
||||||
reg_speed = MPU9250_REG(reg_speed);
|
reg_speed = MPU9250_REG(reg_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,34 +148,25 @@ MPU9250_SPI::read(unsigned reg_speed, void *data, unsigned count)
|
|||||||
|
|
||||||
uint8_t *pbuff = count < sizeof(MPUReport) ? cmd : (uint8_t *) data ;
|
uint8_t *pbuff = count < sizeof(MPUReport) ? cmd : (uint8_t *) data ;
|
||||||
|
|
||||||
|
|
||||||
if (count < sizeof(MPUReport)) {
|
if (count < sizeof(MPUReport)) {
|
||||||
|
|
||||||
/* add command */
|
/* add command */
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bus_frequency(reg_speed);
|
set_bus_frequency(reg_speed);
|
||||||
|
|
||||||
/* Set command */
|
/* Set command */
|
||||||
|
|
||||||
pbuff[0] = reg_speed | DIR_READ ;
|
pbuff[0] = reg_speed | DIR_READ ;
|
||||||
|
|
||||||
/* Transfer the command and get the data */
|
/* Transfer the command and get the data */
|
||||||
|
|
||||||
int ret = transfer(pbuff, pbuff, count);
|
int ret = transfer(pbuff, pbuff, count);
|
||||||
|
|
||||||
if (ret == OK && pbuff == &cmd[0]) {
|
if (ret == OK && pbuff == &cmd[0]) {
|
||||||
|
|
||||||
/* Adjust the count back */
|
/* Adjust the count back */
|
||||||
|
|
||||||
count--;
|
count--;
|
||||||
|
|
||||||
/* Return the data */
|
/* Return the data */
|
||||||
|
|
||||||
memcpy(data, &cmd[1], count);
|
memcpy(data, &cmd[1], count);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user