Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST CODE Do not merge] #12678

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions boards/px4/fmu-v5x/init/rc.board_sensors
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ mpu6000 -R 8 -s -T 20602 start
# Internal SPI bus ISM300DLC
ism330dlc start

# Internal SPI bus BMI088 accel
bmi088 -A -R 10 start

# Internal SPI bus BMI088 gyro
bmi088 -G -R 10 start
# Internal SPI bus BMI088
bmi088 -R 10 start

# Possible external compasses
ist8310 -C -b 1 start
Expand Down
1 change: 1 addition & 0 deletions src/drivers/imu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_subdirectory(adis16477)
add_subdirectory(adis16497)
add_subdirectory(bma180)
add_subdirectory(bmi055)
add_subdirectory(bmi088)
add_subdirectory(bmi160)
add_subdirectory(fxas21002c)
add_subdirectory(fxos8701cq)
Expand Down
147 changes: 147 additions & 0 deletions src/drivers/imu/bmi088/BMI088.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/****************************************************************************
*
* Copyright (c) 2019 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/

#include "BMI088.hpp"

BMI088::BMI088(int bus, enum Rotation rotation) :
_accel{bus, PX4_SPIDEV_BMI088_ACC, rotation},
_gyro{bus, PX4_SPIDEV_BMI088_GYR, rotation}
{
}

int
BMI088::init()
{
int ret_accel = _accel.init();

if (ret_accel != PX4_OK) {
return ret_accel;
}

int ret_gyro = _gyro.init();

if (ret_gyro != PX4_OK) {
return ret_gyro;
}

return PX4_OK;
}

static int acc_data_ready_interrupt(int irq, void *context, void *arg)
{
static volatile int acc_count = 0;
acc_count++;
return PX4_OK;
}

static int gyro_data_ready_interrupt(int irq, void *context, void *arg)
{
static volatile int gyro_count = 0;
gyro_count++;
return PX4_OK;
}

bool
BMI088::start()
{

// make sure we are stopped first
stop();

#ifdef GPIO_SPI3_DRDY1_BMI088_INT1_ACCEL
// Setup data ready Interrupt on Falling edge for better noise immunity
px4_arch_gpiosetevent(GPIO_SPI3_DRDY1_BMI088_INT1_ACCEL, false, true, false, &acc_data_ready_interrupt, this);
#endif // GPIO_SPI3_DRDY1_BMI088_INT1_ACCEL

#ifdef GPIO_SPI3_DRDY2_BMI088_INT3_GYRO
// Setup data ready Interrupt on Falling edge for better noise immunity
px4_arch_gpiosetevent(GPIO_SPI3_DRDY2_BMI088_INT3_GYRO, false, true, false, &gyro_data_ready_interrupt, this);
#endif // GPIO_SPI3_DRDY2_BMI088_INT3_GYRO

// start polling at the specified rate
//ScheduleOnInterval(BMI088_GYRO_DEFAULT_RATE - BMI088_TIMER_REDUCTION, 1000);
// make another measurement
Run(false);
Run(true);

return true;
}

bool
BMI088::stop()
{

#ifdef GPIO_SPI3_DRDY1_BMI088_INT1_ACCEL
// Disable data ready callback
px4_arch_gpiosetevent(GPIO_SPI3_DRDY1_BMI088_INT1_ACCEL, false, false, false, nullptr, nullptr);
#endif // GPIO_SPI3_DRDY1_BMI088_INT1_ACCEL

#ifdef GPIO_SPI3_DRDY2_BMI088_INT3_GYRO
// Disable data ready callback
px4_arch_gpiosetevent(GPIO_SPI3_DRDY2_BMI088_INT3_GYRO, false, false, false, nullptr, nullptr);
#endif // GPIO_SPI3_DRDY2_BMI088_INT3_GYRO

//ScheduleClear();

return true;
}

void
BMI088::print_info()
{
_accel.print_info();
_gyro.print_info();
}

void
BMI088::print_registers()
{
_accel.print_registers();
_gyro.print_registers();
}

void
BMI088::Run(bool a)
{


a ? _accel.Run() : _gyro.Run();

// grab temperature from accel and set in gyro

// TODO: at 1 Hz check temperature, health, etc?




}
63 changes: 18 additions & 45 deletions src/drivers/imu/bmi088/BMI088.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2018 PX4 Development Team. All rights reserved.
* Copyright (c) 2019 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -33,64 +33,37 @@

#pragma once

#include <drivers/device/spi.h>
#include <ecl/geo/geo.h>
#include <lib/conversion/rotation.h>
#include <lib/perf/perf_counter.h>
#include <px4_getopt.h>
#include <px4_work_queue/ScheduledWorkItem.hpp>

#define DIR_READ 0x80
#define DIR_WRITE 0x00
#include "BMI088_Accelerometer.hpp"
#include "BMI088_Gyroscope.hpp"

//Soft-reset command Value
#define BMI088_SOFT_RESET 0xB6
using Bosch_BMI088_Accelerometer::BMI088_Accelerometer;
using Bosch_BMI088_Gyroscope::BMI088_Gyroscope;

#define BMI088_BUS_SPEED 10*1000*1000

#define BMI088_TIMER_REDUCTION 200

class BMI088 : public device::SPI
class BMI088
{
public:

protected:

uint8_t _whoami; /** whoami result */

uint8_t _register_wait;
uint64_t _reset_wait;

enum Rotation _rotation;
BMI088(int bus, enum Rotation rotation);
virtual ~BMI088() = default;

uint8_t _checked_next;
int init();

/**
* Read a register from the BMI088
*
* @param The register to read.
* @return The value that was read.
*/
virtual uint8_t read_reg(unsigned reg); // This needs to be declared as virtual, because the
virtual uint16_t read_reg16(unsigned reg);
bool start();
bool stop();

/**
* Write a register in the BMI088
*
* @param reg The register to write.
* @param value The new value to write.
*/
void write_reg(unsigned reg, uint8_t value);
void print_info();
void print_registers();

/* do not allow to copy this class due to pointer data members */
BMI088(const BMI088 &);
BMI088 operator=(const BMI088 &);
void Run(bool a);

public:
private:

BMI088(const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency,
enum Rotation rotation);

virtual ~BMI088() = default;

BMI088_Accelerometer _accel;
BMI088_Gyroscope _gyro;

};
Loading