34 #include <px4_platform_common/px4_config.h> 35 #include <px4_platform_common/getopt.h> 61 # if defined(PX4_I2C_BUS_ONBOARD) && defined(PX4_I2C_OBDEV_MPU9250) 64 # if defined(PX4_I2C_BUS_EXPANSION) && defined(PX4_I2C_OBDEV_MPU9250) 67 # if defined(PX4_I2C_BUS_EXPANSION1) && defined(PX4_I2C_OBDEV_MPU9250) 70 # if defined(PX4_I2C_BUS_EXPANSION2) && defined(PX4_I2C_OBDEV_MPU9250) 74 #if defined(PX4_SPI_BUS_SENSORS) && defined(PX4_SPIDEV_MPU) 77 #if defined(PX4_SPI_BUS_SENSORS) && defined(PX4_SPIDEV_MPU2) 80 #if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_MPU) 90 busid == bus_option.busid) && bus_option.dev !=
nullptr) {
101 device::Device *
interface = bus.interface_constructor(bus.busnum, bus.address);
103 if ((interface ==
nullptr) || (interface->init() != PX4_OK)) {
104 PX4_WARN(
"no device on bus %u", (
unsigned)bus.busid);
122 if (dev ==
nullptr || (dev->
init() != PX4_OK)) {
123 PX4_ERR(
"driver start failed");
126 delete mag_interface;
138 if (bus_option.dev !=
nullptr) {
140 PX4_WARN(
"already started");
161 if (bus !=
nullptr && bus->
dev !=
nullptr) {
166 PX4_WARN(
"driver not running");
177 if (bus !=
nullptr && bus->
dev !=
nullptr) {
182 PX4_WARN(
"driver not running");
188 PX4_INFO(
"missing command: try 'start', 'stop', 'status'");
189 PX4_INFO(
"options:");
190 PX4_INFO(
" -X (i2c external bus)");
191 PX4_INFO(
" -I (i2c internal bus)");
192 PX4_INFO(
" -s (spi internal bus)");
193 PX4_INFO(
" -S (spi external bus)");
194 PX4_INFO(
" -t (spi internal bus, 2nd instance)");
195 PX4_INFO(
" -R rotation");
206 const char *myoptarg =
nullptr;
211 while ((ch = px4_getopt(argc, argv,
"XISstMR:", &myoptind, &myoptarg)) != EOF) {
234 rotation = (
enum Rotation)atoi(myoptarg);
242 if (myoptind >= argc) {
246 const char *verb = argv[myoptind];
248 if (!strcmp(verb,
"start")) {
251 }
else if (!strcmp(verb,
"stop")) {
254 }
else if (!strcmp(verb,
"status")) {
int mpu9250_main(int argc, char *argv[])
static int stop(MPU9250_BUS busid)
void usage(const char *reason)
Print the correct usage.
device::Device * AK8963_I2C_interface(int bus)
static bool start_bus(mpu9250_bus_option &bus, enum Rotation rotation)
void print_info()
Diagnostics - print some basic information about the driver.
MPU9250_constructor interface_constructor
device::Device * MPU9250_I2C_interface(int bus, uint32_t address)
device::Device * MPU9250_SPI_interface(int bus, uint32_t cs)
Rotation
Enum for board and external compass rotations.
static int start(MPU9250_BUS busid, enum Rotation rotation)
static int status(MPU9250_BUS busid)
Fundamental base class for all physical drivers (I2C, SPI).
static struct mpu9250_bus_option * find_bus(MPU9250_BUS busid)
device::Device *(* MPU9250_constructor)(int, uint32_t)
struct mpu9250::mpu9250_bus_option bus_options[]