42 #include <px4_platform_common/px4_config.h> 43 #include <px4_platform_common/getopt.h> 46 #include <board_config.h> 80 #if defined(PX4_SPIDEV_ICM_20948) && defined(PX4_SPI_BUS_1) 85 # if defined(PX4_I2C_BUS_EXPANSION) 91 #define NUM_BUS_OPTIONS (sizeof(bus_options)/sizeof(bus_options[0])) 114 PX4_ERR(
"bus %u not started", (
unsigned)busid);
124 PX4_INFO(
"Bus probed: %d", bus.
busid);
126 if (bus.
dev !=
nullptr) {
127 PX4_ERR(
"SPI %d not available", bus.
busid);
131 device::Device *
interface = bus.interface_constructor(bus.busnum, bus.address);
133 if (interface ==
nullptr) {
134 PX4_WARN(
"no device on bus %u", (
unsigned)bus.busid);
138 if (interface->init() !=
OK) {
140 PX4_WARN(
"no device on bus %u", (
unsigned)bus.busid);
156 bus.dev =
new ICM20948(interface, mag_interface, rotation);
158 if (bus.dev ==
nullptr) {
161 if (mag_interface !=
nullptr) {
162 delete mag_interface;
168 if (
OK != bus.dev->init()) {
176 if (bus.dev !=
nullptr) {
181 PX4_ERR(
"driver start failed");
195 bool started =
false;
210 if (started) {
break; }
221 if (bus !=
nullptr && bus->
dev !=
nullptr) {
227 PX4_WARN(
"already stopped.");
241 if (bus !=
nullptr && bus->
dev !=
nullptr) {
242 PX4_WARN(
"driver not running");
254 PX4_INFO(
"missing command: try 'start', 'stop', 'info'");
255 PX4_INFO(
"options:");
256 PX4_INFO(
" -X (i2c external bus)");
257 PX4_INFO(
" -I (i2c internal bus)");
258 PX4_INFO(
" -s (spi internal bus)");
259 PX4_INFO(
" -S (spi external bus)");
260 PX4_INFO(
" -t (spi internal bus, 2nd instance)");
261 PX4_INFO(
" -R rotation");
273 const char *myoptarg =
nullptr;
278 while ((ch = px4_getopt(argc, argv,
"XISstMR:", &myoptind, &myoptarg)) != EOF) {
285 rotation = (
enum Rotation)atoi(myoptarg);
293 if (myoptind >= argc) {
297 const char *verb = argv[myoptind];
302 if (!strcmp(verb,
"start")) {
306 if (!strcmp(verb,
"stop")) {
313 if (!strcmp(verb,
"info")) {
int usage()
Prints info about the driver argument usage.
#define PX4_I2C_EXT_ICM20948_1
Local functions in support of the shell command.
bool start_bus(icm20948_bus_option &bus, enum Rotation rotation)
start driver for a specific bus option
High-resolution timer with callouts and timekeeping.
device::Device * AK09916_I2C_interface(int bus)
int start(enum ICM20948_BUS busid, enum Rotation rotation)
Start the driver.
Definition of commonly used conversions.
Rotation
Enum for board and external compass rotations.
device::Device * ICM20948_SPI_interface(int bus, uint32_t cs)
ICM20948_constructor interface_constructor
int info(enum ICM20948_BUS busid)
Print a little info about the driver.
device::Device * ICM20948_I2C_interface(int bus, uint32_t address)
device::Device *(* ICM20948_constructor)(int, uint32_t)
Fundamental base class for all physical drivers (I2C, SPI).
int stop(enum ICM20948_BUS busid)
struct icm20948::icm20948_bus_option bus_options[]
void print_info()
Diagnostics - print some basic information about the driver.
icm20948_bus_option * find_bus(enum ICM20948_BUS busid)
find a bus structure for a busid
__EXPORT int icm20948_main(int argc, char *argv[])
driver 'main' command
Performance measuring tools.