Skip to content

Commit

Permalink
new InvenSense icm20948 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed Apr 1, 2020
1 parent 02f4ad6 commit f2e50ef
Show file tree
Hide file tree
Showing 12 changed files with 2,131 additions and 7 deletions.
2 changes: 1 addition & 1 deletion boards/mro/ctrl-zero-f7/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ px4_add_board(
#imu # all available imu drivers
imu/bmi088
imu/mpu6000
imu/icm20948
imu/invensense/icm20948
irlock
lights/blinkm
lights/rgbled
Expand Down
6 changes: 3 additions & 3 deletions boards/mro/ctrl-zero-f7/init/rc.board_sensors
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ adc start
# Internal ICM-20602
mpu6000 -R 10 -s -T 20602 start

# Internal ICM-20689
#icm20689 -s -R 10 start

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

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

# Internal ICM-20948
icm20948 -s -R 2 start

# Interal DPS310 (barometer)
dps310 -s start

Expand Down
3 changes: 1 addition & 2 deletions boards/mro/ctrl-zero-f7/src/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
initSPIBus(SPI::Bus::SPI1, {
initSPIDevice(DRV_IMU_DEVTYPE_ICM20602, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
// ICM-20948
initSPIDevice(DRV_DEVTYPE_UNUSED, SPI::CS{GPIO::PortE, GPIO::Pin15}, SPI::DRDY{GPIO::PortE, GPIO::Pin12}),
initSPIDevice(DRV_IMU_DEVTYPE_ICM20948, SPI::CS{GPIO::PortE, GPIO::Pin15}, SPI::DRDY{GPIO::PortE, GPIO::Pin12}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(SPI::Bus::SPI2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10}),
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/drv_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define DRV_MAG_DEVTYPE_RM3100 0x07
#define DRV_MAG_DEVTYPE_QMC5883 0x08
#define DRV_MAG_DEVTYPE_AK09916 0x09
#define DRV_IMU_DEVTYPE_ICM20948 0x0A

#define DRV_MAG_DEVTYPE_IST8308 0x0B

#define DRV_IMU_DEVTYPE_LSM303D 0x11
Expand All @@ -78,6 +78,7 @@
#define DRV_GYR_DEVTYPE_BMI160 0x25
#define DRV_IMU_DEVTYPE_ICM42688P 0x26
#define DRV_IMU_DEVTYPE_ICM40609D 0x27
#define DRV_IMU_DEVTYPE_ICM20948 0x28

#define DRV_RNG_DEVTYPE_MB12XX 0x31
#define DRV_RNG_DEVTYPE_LL40LS 0x32
Expand Down
105 changes: 105 additions & 0 deletions src/drivers/imu/invensense/icm20948/AKM_AK09916_registers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/****************************************************************************
*
* 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.
*
****************************************************************************/

/**
* @file AKM_AK09916_registers.hpp
*
* Asahi Kasei Microdevices (AKM) AK09916 registers.
*
*/

#pragma once

#include <cstdint>

namespace AKM_AK09916
{

// TODO: move to a central header
static constexpr uint8_t Bit0 = (1 << 0);
static constexpr uint8_t Bit1 = (1 << 1);
static constexpr uint8_t Bit2 = (1 << 2);
static constexpr uint8_t Bit3 = (1 << 3);
static constexpr uint8_t Bit4 = (1 << 4);
static constexpr uint8_t Bit5 = (1 << 5);
static constexpr uint8_t Bit6 = (1 << 6);
static constexpr uint8_t Bit7 = (1 << 7);

static constexpr uint32_t I2C_SPEED = 400 * 1000; // 400 kHz I2C serial interface
static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0b0001100;

static constexpr uint8_t WHOAMI = 0x09;

enum class Register : uint8_t {
WIA = 0x01, // Device ID

ST1 = 0x10, // Status 1
HXL = 0x11,
HXH = 0x12,
HYL = 0x13,
HYH = 0x14,
HZL = 0x15,
HZH = 0x16,

ST2 = 0x18, // Status 2

CNTL2 = 0x31, // Control 2
CNTL3 = 0x32, // Control 3
};

// ST1
enum ST1_BIT : uint8_t {
DOR = Bit1, // Data overrun
DRDY = Bit0, // Data is ready
};

// ST2
enum ST2_BIT : uint8_t {
BITM = Bit4, // Output bit setting (mirror)
HOFL = Bit3, // Magnetic sensor overflow
};

// CNTL2
enum CNTL2_BIT : uint8_t {
MODE1 = Bit1, // Continuous measurement mode 1 (10Hz)
MODE2 = Bit2, // Continuous measurement mode 2 (20Hz)
MODE3 = Bit2 | Bit1, // Continuous measurement mode 3 (50Hz)
MODE4 = Bit3, // Continuous measurement mode 4 (100Hz)
};

// CNTL3
enum CNTL3_BIT : uint8_t {
SRST = Bit0,
};

} // namespace AKM_AK09916
51 changes: 51 additions & 0 deletions src/drivers/imu/invensense/icm20948/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
############################################################################
#
# 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.
#
############################################################################
px4_add_module(
MODULE drivers__imu__icm20948
MAIN icm20948
COMPILE_FLAGS
-DDEBUG_BUILD
SRCS
AKM_AK09916_registers.hpp
ICM20948.cpp
ICM20948.hpp
ICM20948_AK09916.cpp
ICM20948_AK09916.hpp
icm20948_main.cpp
InvenSense_ICM20948_registers.hpp
DEPENDS
px4_work_queue
drivers_accelerometer
drivers_gyroscope
drivers_magnetometer
)
Loading

0 comments on commit f2e50ef

Please sign in to comment.