78 if (*g_dev_acc_ptr !=
nullptr)
81 errx(0,
"bmi088 accel sensor already started");
86 #if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_BMI) 87 *g_dev_acc_ptr =
new BMI088_accel(PX4_SPI_BUS_EXT, path_accel, PX4_SPIDEV_EXT_BMI, rotation);
89 errx(0,
"External SPI not available");
93 *g_dev_acc_ptr =
new BMI088_accel(PX4_SPI_BUS_SENSORS3, path_accel, PX4_SPIDEV_BMI088_ACC, rotation);
96 if (*g_dev_acc_ptr ==
nullptr) {
100 if (
OK != (*g_dev_acc_ptr)->init()) {
105 (*g_dev_acc_ptr)->start();
110 if (*g_dev_gyr_ptr !=
nullptr) {
111 errx(0,
"bmi088 gyro sensor already started");
116 #if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_BMI) 117 *g_dev_ptr =
new BMI088_gyro(PX4_SPI_BUS_EXT, path_gyro, PX4_SPIDEV_EXT_BMI, rotation);
119 errx(0,
"External SPI not available");
123 *g_dev_gyr_ptr =
new BMI088_gyro(PX4_SPI_BUS_SENSORS3, path_gyro, PX4_SPIDEV_BMI088_GYR, rotation);
126 if (*g_dev_gyr_ptr ==
nullptr) {
130 if (
OK != (*g_dev_gyr_ptr)->init()) {
135 (*g_dev_gyr_ptr)->start();
142 if (*g_dev_acc_ptr !=
nullptr) {
143 delete (*g_dev_acc_ptr);
144 *g_dev_acc_ptr =
nullptr;
147 PX4_WARN(
"No BMI088 accel found");
152 if (*g_dev_gyr_ptr !=
nullptr) {
153 delete (*g_dev_gyr_ptr);
154 *g_dev_gyr_ptr =
nullptr;
157 PX4_WARN(
"No BMI088 gyro found");
168 if (*g_dev_acc_ptr !=
nullptr) {
169 delete *g_dev_acc_ptr;
170 *g_dev_acc_ptr =
nullptr;
174 warnx(
"bmi088 accel sensor already stopped.");
179 if (*g_dev_gyr_ptr !=
nullptr) {
180 delete *g_dev_gyr_ptr;
181 *g_dev_gyr_ptr =
nullptr;
185 warnx(
"bmi088 gyro sensor already stopped.");
203 if (*g_dev_acc_ptr ==
nullptr) {
204 errx(1,
"bmi088 accel driver not running");
207 printf(
"state @ %p\n", *g_dev_acc_ptr);
208 (*g_dev_acc_ptr)->print_info();
212 if (*g_dev_gyr_ptr ==
nullptr) {
213 errx(1,
"bmi088 gyro driver not running");
216 printf(
"state @ %p\n", *g_dev_gyr_ptr);
217 (*g_dev_gyr_ptr)->print_info();
233 if (*g_dev_acc_ptr ==
nullptr) {
234 errx(1,
"bmi088 accel driver not running");
237 printf(
"regdump @ %p\n", *g_dev_acc_ptr);
238 (*g_dev_acc_ptr)->print_registers();
242 if (*g_dev_gyr_ptr ==
nullptr) {
243 errx(1,
"bmi088 gyro driver not running");
246 printf(
"regdump @ %p\n", *g_dev_gyr_ptr);
247 (*g_dev_gyr_ptr)->print_registers();
263 if (*g_dev_acc_ptr ==
nullptr) {
264 errx(1,
"bmi088 accel driver not running");
267 (*g_dev_acc_ptr)->test_error();
271 if (*g_dev_gyr_ptr ==
nullptr) {
272 errx(1,
"bmi088 gyro driver not running");
275 (*g_dev_gyr_ptr)->test_error();
284 warnx(
"missing command: try 'start', 'info', 'stop', 'regdump', 'testerror'");
286 warnx(
" -X (external bus)");
287 warnx(
" -R rotation");
288 warnx(
" -A (Enable Accelerometer)");
289 warnx(
" -G (Enable Gyroscope)");
296 uint32_t frequency,
enum Rotation rotation):
297 SPI(name, devname, bus, device, mode, frequency),
309 uint8_t cmd[2] = { (uint8_t)(reg |
DIR_READ), 0};
311 transfer(cmd, cmd,
sizeof(cmd));
319 uint8_t cmd[3] = { (uint8_t)(reg |
DIR_READ), 0, 0 };
321 transfer(cmd, cmd,
sizeof(cmd));
323 return (uint16_t)(cmd[1] << 8) | cmd[2];
334 transfer(cmd,
nullptr,
sizeof(cmd));
340 bool external_bus =
false;
345 const char *myoptarg = NULL;
348 while ((ch = px4_getopt(argc, argv,
"XR:AG", &myoptind, &myoptarg)) != EOF) {
355 rotation = (
enum Rotation)atoi(myoptarg);
372 const char *verb = argv[myoptind];
382 if (!strcmp(verb,
"start")) {
389 if (!strcmp(verb,
"stop")) {
396 if (!strcmp(verb,
"info")) {
403 if (!strcmp(verb,
"regdump")) {
407 if (!strcmp(verb,
"testerror")) {
void testerror(bool, enum sensor_type)
deliberately produce an error to test recovery
virtual uint8_t read_reg(unsigned reg)
Read a register from the BMI088.
#define BMI088_DEVICE_PATH_GYRO_EXT
BMI088_accel * g_acc_dev_int
void stop(bool, enum sensor_type)
Namespace encapsulating all device framework classes, functions and data.
void start(bool, enum Rotation, enum sensor_type)
Start the driver.
BMI088_gyro * g_gyr_dev_ext
void usage()
Prints info about the driver argument usage.
BMI088_accel * g_acc_dev_ext
virtual uint16_t read_reg16(unsigned reg)
Rotation
Enum for board and external compass rotations.
void info(bool, enum sensor_type)
Print a little info about the driver.
void regdump(bool, enum sensor_type)
Dump the register information.
#define BMI088_DEVICE_PATH_ACCEL
BMI088_gyro * g_gyr_dev_int
#define BMI088_DEVICE_PATH_GYRO
#define BMI088_DEVICE_PATH_ACCEL_EXT
__EXPORT int bmi088_main(int argc, char *argv[])
driver 'main' command
void write_reg(unsigned reg, uint8_t value)
Write a register in the BMI088.