|
|
|
@ -33,187 +33,98 @@
@@ -33,187 +33,98 @@
|
|
|
|
|
|
|
|
|
|
#include "FXAS21002C.hpp" |
|
|
|
|
|
|
|
|
|
extern "C" { __EXPORT int fxas21002c_main(int argc, char *argv[]); } |
|
|
|
|
#include <px4_platform_common/getopt.h> |
|
|
|
|
#include <px4_platform_common/module.h> |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Local functions in support of the shell command. |
|
|
|
|
*/ |
|
|
|
|
namespace fxas21002c |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
FXAS21002C *g_dev; |
|
|
|
|
|
|
|
|
|
void start(bool external_bus, enum Rotation rotation); |
|
|
|
|
void info(); |
|
|
|
|
void regdump(); |
|
|
|
|
void usage(); |
|
|
|
|
void test_error(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Start the driver. |
|
|
|
|
* |
|
|
|
|
* This function call only returns once the driver is |
|
|
|
|
* up and running or failed to detect the sensor. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
start(bool external_bus, enum Rotation rotation) |
|
|
|
|
FXAS21002C::print_usage() |
|
|
|
|
{ |
|
|
|
|
if (g_dev != nullptr) { |
|
|
|
|
PX4_INFO("already started"); |
|
|
|
|
exit(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* create the driver */ |
|
|
|
|
if (external_bus) { |
|
|
|
|
#if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_GYRO) |
|
|
|
|
g_dev = new FXAS21002C(PX4_SPI_BUS_EXT, PX4_SPIDEV_EXT_GYRO, rotation); |
|
|
|
|
#else |
|
|
|
|
PX4_ERR("External SPI not available"); |
|
|
|
|
exit(0); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
g_dev = new FXAS21002C(PX4_SPI_BUS_SENSORS, PX4_SPIDEV_GYRO, rotation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (g_dev == nullptr) { |
|
|
|
|
PX4_ERR("failed instantiating FXAS21002C obj"); |
|
|
|
|
goto fail; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (OK != g_dev->init()) { |
|
|
|
|
goto fail; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
fail: |
|
|
|
|
|
|
|
|
|
if (g_dev != nullptr) { |
|
|
|
|
delete g_dev; |
|
|
|
|
g_dev = nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
errx(1, "driver start failed"); |
|
|
|
|
PRINT_MODULE_USAGE_NAME("fxas21002c", "driver"); |
|
|
|
|
PRINT_MODULE_USAGE_SUBCATEGORY("imu"); |
|
|
|
|
PRINT_MODULE_USAGE_COMMAND("start"); |
|
|
|
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(false, true); |
|
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('R', 0, 0, 35, "Rotation", true); |
|
|
|
|
PRINT_MODULE_USAGE_COMMAND("regdump"); |
|
|
|
|
PRINT_MODULE_USAGE_COMMAND("testerror"); |
|
|
|
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print a little info about the driver. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
info() |
|
|
|
|
I2CSPIDriverBase *FXAS21002C::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator, |
|
|
|
|
int runtime_instance) |
|
|
|
|
{ |
|
|
|
|
if (g_dev == nullptr) { |
|
|
|
|
PX4_ERR("driver not running\n"); |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("state @ %p\n", g_dev); |
|
|
|
|
g_dev->print_info(); |
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
} |
|
|
|
|
FXAS21002C *instance = new FXAS21002C(iterator.configuredBusOption(), iterator.bus(), iterator.devid(), cli.rotation, |
|
|
|
|
cli.bus_frequency, cli.spi_mode); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* dump registers from device |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
regdump() |
|
|
|
|
{ |
|
|
|
|
if (g_dev == nullptr) { |
|
|
|
|
PX4_ERR("driver not running\n"); |
|
|
|
|
exit(1); |
|
|
|
|
if (!instance) { |
|
|
|
|
PX4_ERR("alloc failed"); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("regdump @ %p\n", g_dev); |
|
|
|
|
g_dev->print_registers(); |
|
|
|
|
if (OK != instance->init()) { |
|
|
|
|
delete instance; |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
return instance; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* trigger an error |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
test_error() |
|
|
|
|
void FXAS21002C::custom_method(const BusCLIArguments &cli) |
|
|
|
|
{ |
|
|
|
|
if (g_dev == nullptr) { |
|
|
|
|
PX4_ERR("driver not running\n"); |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
g_dev->test_error(); |
|
|
|
|
switch (cli.custom1) { |
|
|
|
|
case 0: print_registers(); break; |
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
} |
|
|
|
|
case 1: test_error(); break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
usage() |
|
|
|
|
{ |
|
|
|
|
PX4_INFO("missing command: try 'start', 'info', 'testerror' or 'regdump'"); |
|
|
|
|
PX4_INFO("options:"); |
|
|
|
|
PX4_INFO(" -X (external bus)"); |
|
|
|
|
PX4_INFO(" -R rotation"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
fxas21002c_main(int argc, char *argv[]) |
|
|
|
|
extern "C" int fxas21002c_main(int argc, char *argv[]) |
|
|
|
|
{ |
|
|
|
|
bool external_bus = false; |
|
|
|
|
enum Rotation rotation = ROTATION_NONE; |
|
|
|
|
|
|
|
|
|
int ch = 0; |
|
|
|
|
int myoptind = 1; |
|
|
|
|
const char *myoptarg = NULL; |
|
|
|
|
int ch; |
|
|
|
|
using ThisDriver = FXAS21002C; |
|
|
|
|
BusCLIArguments cli{false, true}; |
|
|
|
|
cli.default_spi_frequency = 2 * 1000 * 1000; |
|
|
|
|
cli.spi_mode = SPIDEV_MODE0; |
|
|
|
|
|
|
|
|
|
while ((ch = px4_getopt(argc, argv, "XR:", &myoptind, &myoptarg)) != EOF) { |
|
|
|
|
while ((ch = cli.getopt(argc, argv, "R:")) != EOF) { |
|
|
|
|
switch (ch) { |
|
|
|
|
case 'X': |
|
|
|
|
external_bus = true; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'R': |
|
|
|
|
rotation = (enum Rotation)atoi(myoptarg); |
|
|
|
|
cli.rotation = (enum Rotation)atoi(cli.optarg()); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
fxas21002c::usage(); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char *verb = argv[myoptind]; |
|
|
|
|
const char *verb = cli.optarg(); |
|
|
|
|
|
|
|
|
|
if (!verb) { |
|
|
|
|
ThisDriver::print_usage(); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Start/load the driver. |
|
|
|
|
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_GYR_DEVTYPE_FXAS2100C); |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(verb, "start")) { |
|
|
|
|
fxas21002c::start(external_bus, rotation); |
|
|
|
|
return ThisDriver::module_start(cli, iterator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!strcmp(verb, "stop")) { |
|
|
|
|
return ThisDriver::module_stop(iterator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Print driver information. |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(verb, "info")) { |
|
|
|
|
fxas21002c::info(); |
|
|
|
|
if (!strcmp(verb, "status")) { |
|
|
|
|
return ThisDriver::module_status(iterator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* dump device registers |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(verb, "regdump")) { |
|
|
|
|
fxas21002c::regdump(); |
|
|
|
|
cli.custom1 = 0; |
|
|
|
|
return ThisDriver::module_custom_method(cli, iterator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* trigger an error |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(verb, "testerror")) { |
|
|
|
|
fxas21002c::test_error(); |
|
|
|
|
cli.custom1 = 1; |
|
|
|
|
return ThisDriver::module_custom_method(cli, iterator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PX4_WARN("unrecognized command, try 'start', 'info', 'testerror' or 'regdump'"); |
|
|
|
|
ThisDriver::print_usage(); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|