55 # if defined(PX4_I2C_BUS_ONBOARD) 58 # if defined(PX4_I2C_BUS_EXPANSION) 61 # if defined(PX4_I2C_BUS_EXPANSION1) 64 # if defined(PX4_I2C_BUS_EXPANSION2) 71 #if defined(PX4_SPI_BUS_EXT) 74 #if defined(PX4_SPIDEV_ICM_20602) && defined(PX4_SPI_BUS_SENSORS) 77 #if defined(PX4_SPIDEV_ICM_20602) && defined(PX4_SPI_BUS_SENSORS1) 80 #if defined(PX4_SPIDEV_ICM_20602) && defined(PX4_SPI_BUS_1) 83 #ifdef PX4_SPIDEV_ICM_20608 86 #ifdef PX4_SPIDEV_ICM_20689 89 #if defined(PX4_SPI_BUS_EXTERNAL) 95 #define NUM_BUS_OPTIONS (sizeof(bus_options)/sizeof(bus_options[0])) 106 #ifndef CONSTRAINED_FLASH 123 errx(1,
"bus %u not started", (
unsigned)busid);
132 if (bus.
dev !=
nullptr) {
133 warnx(
"%s SPI not available", bus.
external ?
"External" :
"Internal");
137 device::Device *
interface = bus.interface_constructor(bus.busnum, device_type, bus.external);
139 if (interface ==
nullptr) {
140 warnx(
"failed creating interface for bus #%u (SPI%u)", (
unsigned)bus.busid, (
unsigned)bus.busnum);
144 if (interface->init() !=
OK) {
146 warnx(
"no device on bus #%u (SPI%u)", (
unsigned)bus.busid, (
unsigned)bus.busnum);
150 bus.dev =
new MPU6000(interface, rotation, device_type);
152 if (bus.dev ==
nullptr) {
157 if (
OK != bus.dev->init()) {
169 if (bus.dev !=
nullptr) {
186 bool started =
false;
207 exit(started ? 0 : 1);
215 if (bus.
dev !=
nullptr) {
221 warnx(
"already stopped.");
235 if (bus.
dev ==
nullptr) {
236 errx(1,
"driver not running");
252 if (bus.
dev ==
nullptr) {
253 errx(1,
"driver not running");
269 if (bus.
dev ==
nullptr) {
270 errx(1,
"driver not running");
273 printf(
"regdump @ %p\n", bus.
dev);
288 if (bus.
dev ==
nullptr) {
289 errx(1,
"driver not running");
297 #ifndef CONSTRAINED_FLASH 307 if (bus.
dev ==
nullptr) {
308 errx(1,
"driver not running");
320 warnx(
"missing command: try 'start', 'info', 'stop',\n'reset', 'regdump', 'testerror'" 321 #ifndef CONSTRAINED_FLASH
326 warnx(
" -X external I2C bus");
327 warnx(
" -I internal I2C bus");
328 warnx(
" -S external SPI bus");
329 warnx(
" -s internal SPI bus");
330 warnx(
" -Z external1 SPI bus");
331 warnx(
" -z internal2 SPI bus");
332 warnx(
" -T 6000|20608|20602 (default 6000)");
333 warnx(
" -R rotation");
346 const char *myoptarg =
nullptr;
352 while ((ch = px4_getopt(argc, argv,
"T:XISsZzR:a:", &myoptind, &myoptarg)) != EOF) {
379 device_type = atoi(myoptarg);
383 rotation = (
enum Rotation)atoi(myoptarg);
392 if (myoptind >= argc) {
397 const char *verb = argv[myoptind];
402 if (!strcmp(verb,
"start")) {
406 if (!strcmp(verb,
"stop")) {
413 if (!strcmp(verb,
"reset")) {
420 if (!strcmp(verb,
"info") || !strcmp(verb,
"status")) {
427 if (!strcmp(verb,
"regdump")) {
431 #ifndef CONSTRAINED_FLASH 433 if (!strcmp(verb,
"factorytest")) {
439 if (!strcmp(verb,
"testerror")) {
device::Device * MPU6000_SPI_interface(int bus, int device_type, bool external_bus)
device::Device *(* MPU6000_constructor)(int, int, bool)
void start(enum MPU6000_BUS busid, enum Rotation rotation, int device_type)
Start the driver.
int factory_self_test()
Test behaviour against factory offsets.
void usage()
Prints info about the driver argument usage.
__EXPORT int mpu6000_main(int argc, char *argv[])
driver 'main' command
Local functions in support of the shell command.
static struct mpu6000_bus_option & find_bus(enum MPU6000_BUS busid)
find a bus structure for a busid
void info(enum MPU6000_BUS busid)
Print a little info about the driver.
bool start_bus(struct mpu6000_bus_option &bus, enum Rotation rotation, int device_type)
start driver for a specific bus option
Rotation
Enum for board and external compass rotations.
void regdump(enum MPU6000_BUS busid)
Dump the register information.
struct mpu6000::mpu6000_bus_option bus_options[]
void testerror(enum MPU6000_BUS busid)
deliberately produce an error to test recovery
device::Device * MPU6000_I2C_interface(int bus, int device_type, bool external_bus)
Fundamental base class for all physical drivers (I2C, SPI).
void reset(enum MPU6000_BUS busid)
Reset the driver.
void print_info()
Diagnostics - print some basic information about the driver.
MPU_DEVICE_TYPE device_type
void factorytest(enum MPU6000_BUS busid)
Dump the register information.
void stop(enum MPU6000_BUS busid)
MPU6000_constructor interface_constructor