77 if (*g_dev_acc_ptr !=
nullptr)
80 errx(0,
"bmi055 accel sensor already started");
85 #if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_BMI) 86 *g_dev_acc_ptr =
new BMI055_accel(PX4_SPI_BUS_EXT, path_accel, PX4_SPIDEV_EXT_BMI, rotation);
88 errx(0,
"External SPI not available");
92 *g_dev_acc_ptr =
new BMI055_accel(PX4_SPI_BUS_SENSORS, path_accel, PX4_SPIDEV_BMI055_ACC, rotation);
95 if (*g_dev_acc_ptr ==
nullptr) {
99 if (
OK != (*g_dev_acc_ptr)->init()) {
104 (*g_dev_acc_ptr)->start();
109 if (*g_dev_gyr_ptr !=
nullptr) {
110 errx(0,
"bmi055 gyro sensor already started");
115 #if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_BMI) 116 *g_dev_ptr =
new BMI055_gyro(PX4_SPI_BUS_EXT, path_gyro, PX4_SPIDEV_EXT_BMI, rotation);
118 errx(0,
"External SPI not available");
122 *g_dev_gyr_ptr =
new BMI055_gyro(PX4_SPI_BUS_SENSORS, path_gyro, PX4_SPIDEV_BMI055_GYR, rotation);
125 if (*g_dev_gyr_ptr ==
nullptr) {
129 if (
OK != (*g_dev_gyr_ptr)->init()) {
134 (*g_dev_gyr_ptr)->start();
141 if (*g_dev_acc_ptr !=
nullptr) {
142 delete (*g_dev_acc_ptr);
143 *g_dev_acc_ptr =
nullptr;
146 PX4_WARN(
"No BMI055 accel found");
151 if (*g_dev_gyr_ptr !=
nullptr) {
152 delete (*g_dev_gyr_ptr);
153 *g_dev_gyr_ptr =
nullptr;
156 PX4_WARN(
"No BMI055 gyro found");
167 if (*g_dev_acc_ptr !=
nullptr) {
168 delete *g_dev_acc_ptr;
169 *g_dev_acc_ptr =
nullptr;
173 warnx(
"bmi055 accel sensor already stopped.");
178 if (*g_dev_gyr_ptr !=
nullptr) {
179 delete *g_dev_gyr_ptr;
180 *g_dev_gyr_ptr =
nullptr;
184 warnx(
"bmi055 gyro sensor already stopped.");
202 if (*g_dev_acc_ptr ==
nullptr) {
203 errx(1,
"bmi055 accel driver not running");
206 printf(
"state @ %p\n", *g_dev_acc_ptr);
207 (*g_dev_acc_ptr)->print_info();
211 if (*g_dev_gyr_ptr ==
nullptr) {
212 errx(1,
"bmi055 gyro driver not running");
215 printf(
"state @ %p\n", *g_dev_gyr_ptr);
216 (*g_dev_gyr_ptr)->print_info();
232 if (*g_dev_acc_ptr ==
nullptr) {
233 errx(1,
"bmi055 accel driver not running");
236 printf(
"regdump @ %p\n", *g_dev_acc_ptr);
237 (*g_dev_acc_ptr)->print_registers();
241 if (*g_dev_gyr_ptr ==
nullptr) {
242 errx(1,
"bmi055 gyro driver not running");
245 printf(
"regdump @ %p\n", *g_dev_gyr_ptr);
246 (*g_dev_gyr_ptr)->print_registers();
262 if (*g_dev_acc_ptr ==
nullptr) {
263 errx(1,
"bmi055 accel driver not running");
266 (*g_dev_acc_ptr)->test_error();
270 if (*g_dev_gyr_ptr ==
nullptr) {
271 errx(1,
"bmi055 gyro driver not running");
274 (*g_dev_gyr_ptr)->test_error();
283 warnx(
"missing command: try 'start', 'info', 'stop', 'regdump', 'testerror'");
285 warnx(
" -X (external bus)");
286 warnx(
" -R rotation");
287 warnx(
" -A (Enable Accelerometer)");
288 warnx(
" -G (Enable Gyroscope)");
295 uint32_t frequency,
enum Rotation rotation):
296 SPI(name, devname, bus, device, mode, frequency),
308 uint8_t cmd[2] = { (uint8_t)(reg |
DIR_READ), 0};
310 transfer(cmd, cmd,
sizeof(cmd));
318 uint8_t cmd[3] = { (uint8_t)(reg |
DIR_READ), 0, 0 };
320 transfer(cmd, cmd,
sizeof(cmd));
322 return (uint16_t)(cmd[1] << 8) | cmd[2];
333 transfer(cmd,
nullptr,
sizeof(cmd));
339 bool external_bus =
false;
344 const char *myoptarg = NULL;
347 while ((ch = px4_getopt(argc, argv,
"XR:AG", &myoptind, &myoptarg)) != EOF) {
354 rotation = (
enum Rotation)atoi(myoptarg);
371 const char *verb = argv[myoptind];
381 if (!strcmp(verb,
"start")) {
388 if (!strcmp(verb,
"stop")) {
395 if (!strcmp(verb,
"info")) {
402 if (!strcmp(verb,
"regdump")) {
406 if (!strcmp(verb,
"testerror")) {
BMI055_gyro * g_gyr_dev_ext
void usage()
Prints info about the driver argument usage.
void regdump(bool, enum sensor_type)
Dump the register information.
void testerror(bool, enum sensor_type)
deliberately produce an error to test recovery
#define BMI055_DEVICE_PATH_ACCEL_EXT
void info(bool, enum sensor_type)
Print a little info about the driver.
Namespace encapsulating all device framework classes, functions and data.
void write_reg(unsigned reg, uint8_t value)
Write a register in the BMI055.
uint8_t read_reg(unsigned reg)
Read a register from the BMI055.
Rotation
Enum for board and external compass rotations.
uint16_t read_reg16(unsigned reg)
void start(bool, enum Rotation, enum sensor_type)
Start the driver.
#define BMI055_DEVICE_PATH_ACCEL
BMI055_gyro * g_gyr_dev_int
#define BMI055_DEVICE_PATH_GYRO
void stop(bool, enum sensor_type)
#define BMI055_DEVICE_PATH_GYRO_EXT
__EXPORT int bmi055_main(int argc, char *argv[])
driver 'main' command
BMI055_accel * g_acc_dev_ext
BMI055_accel * g_acc_dev_int