Skip to content

Commit

Permalink
[driver] IMU ADIS16470
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Jan 5, 2022
1 parent 5f85979 commit 1057565
Show file tree
Hide file tree
Showing 4 changed files with 426 additions and 12 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,93 +591,95 @@ you specific needs.
<tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ad7280a">AD7280A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ad7928">AD7928</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-adis16470">ADIS16470</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-adns9800">ADNS9800</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ads7843">ADS7843</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ads816x">ADS816X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ams5915">AMS5915</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ams5915">AMS5915</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-apa102">APA102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-block-device-spi-flash">SPI-FLASH</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bme280">BME280</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bmp085">BMP085</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bno055">BNO055</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cat24aa">CAT24AA</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cat24aa">CAT24AA</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-drv832x_spi">DRV832X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1302">DS1302</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1631">DS1631</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds18b20">DS18B20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">ENCODER-INPUT</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">ENCODER-INPUT</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">ENCODER-INPUT-BITBANG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">ENCODER-OUTPUT-BITBANG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft245">FT245</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6X06</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">GPIO-SAMPLER</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc6343">HMC6343</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lan8720a">LAN8720A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3dsh">LIS3DSH</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lp503x">LP503X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ltc2984">LTC2984</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23X17</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941x">MCP7941X</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941x">MCP7941X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12X</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
</tr><tr>
</tr>
</table>
<!--/drivertable-->
Expand Down
233 changes: 233 additions & 0 deletions src/modm/driver/inertial/adis16470.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
// coding: utf-8
/*
* Copyright (c) 2022, Raphael Lehmann
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#ifndef MODM_ADIS16470_HPP
#define MODM_ADIS16470_HPP

#include <array>
#include <optional>
#include <span>
#include <modm/architecture/interface/spi_device.hpp>
#include <modm/architecture/interface/register.hpp>
#include <modm/architecture/interface/gpio.hpp>
#include <modm/processing/resumable.hpp>

namespace modm
{

/// @ingroup modm_driver_adis16470
struct adis16470
{
/// Available registers
enum class
Register : uint8_t
{
DIAG_STAT = 0x02,
X_GYRO_LOW = 0x04,
X_GYRO_OUT = 0x06,
Y_GYRO_LOW = 0x08,
Y_GYRO_OUT = 0x0A,
Z_GYRO_LOW = 0x0C,
Z_GYRO_OUT = 0x0E,
X_ACCL_LOW = 0x10,
X_ACCL_OUT = 0x12,
Y_ACCL_LOW = 0x14,
Y_ACCL_OUT = 0x16,
Z_ACCL_LOW = 0x18,
Z_ACCL_OUT = 0x1A,
TEMP_OUT = 0x1C,
TIME_STAMP = 0x1E,
DATA_CNTR = 0x22,
X_DELTANG_LOW = 0x24,
X_DELTANG_OUT = 0x26,
Y_DELTANG_LOW = 0x28,
Y_DELTANG_OUT = 0x2A,
Z_DELTANG_LOW = 0x2C,
Z_DELTANG_OUT = 0x2E,
X_DELTVEL_LOW = 0x30,
X_DELTVEL_OUT = 0x32,
Y_DELTVEL_LOW = 0x34,
Y_DELTVEL_OUT = 0x36,
Z_DELTVEL_LOW = 0x38,
Z_DELTVEL_OUT = 0x3A,
XG_BIAS_LOW = 0x40,
XG_BIAS_HIGH = 0x42,
YG_BIAS_LOW = 0x44,
YG_BIAS_HIGH = 0x46,
ZG_BIAS_LOW = 0x48,
ZG_BIAS_HIGH = 0x4A,
XA_BIAS_LOW = 0x4C,
XA_BIAS_HIGH = 0x4E,
YA_BIAS_LOW = 0x50,
YA_BIAS_HIGH = 0x52,
ZA_BIAS_LOW = 0x54,
ZA_BIAS_HIGH = 0x56,
FILT_CTRL = 0x5C,
MSC_CTRL = 0x60,
UP_SCALE = 0x62,
DEC_RATE = 0x64,
NULL_CNFG = 0x66,
GLOB_CMD = 0x68,
FIRM_REV = 0x6C,
FIRM_DM = 0x6E,
FIRM_Y = 0x70,
PROD_ID = 0x72,
SERIAL_NUM = 0x74,
USER_SCR1 = 0x76,
USER_SCR2 = 0x78,
USER_SCR3 = 0x7A,
FLSHCNT_LOW = 0x7C,
FLSHCNT_HIGH = 0x7E,
};

enum class
AccessMethod : uint8_t
{
Read = 0b01,
Write = 0b10,
ReadWrite = 0b11,
};

/// Get the allowed register access modes for a given Register
constexpr AccessMethod
getRegisterAccess(Register r)
{
if (r == Register::GLOB_CMD) {
return AccessMethod::Write;
}
if (r <= Register::Z_DELTVEL_OUT) {
return AccessMethod::Read;
}
if ((r >= Register::FIRM_REV) && (r != Register::USER_SCR1) && (r != Register::USER_SCR2) && (r != Register::USER_SCR3)) {
return AccessMethod::Read;
}
return AccessMethod::ReadWrite;
}

/// Status/Error Flag Indicators
/// DIAG_STAT register (address 0x02, 0x03) reset value is 0x0000
enum class
DiagStat : uint16_t
{
// Reserved = Bit8 to Bit15,
ClockError = Bit7, ///< Indicates that the internal data sampling clock does not synchronize with the external clock, which only applies when using scale sync mode.
MemoryFailure = Bit6, ///< Indicates a failure in the flash memory test.
SensorFailure = Bit5, ///< Indicates failure of at least one sensor, at the conclusion of the self test.
StandbyMode = Bit4, ///< Indicates that the voltage across VDD and GND is <2.8 V, which causes data processing to stop.
SpiCommunicationError = Bit3, ///< Indicates that the total number of SCLK cycles is not equal to an integer multiple of 16.
FlashUpdateFailure = Bit2, ///< Indicates that the most recent flash memory update failed.
DataPathOverrun = Bit1, ///< Indicates that one of the data paths have experienced an overrun condition.
// Reserved = Bit0,
};
MODM_FLAGS8(DiagStat);

};

/**
* \ingroup modm_driver_adis16470
* \author Raphael Lehmann
*/
template<class SpiMaster, class Cs>
class Adis16470 : public adis16470,
public modm::SpiDevice<SpiMaster>,
protected modm::NestedResumable<2>
{
public:
Adis16470() = default;

/**
* @brief Initialize
*
* Sets used pins as output.
*
* SPI must be initialized by the user!
* @warning The SPI frequency must not exceed 2 MHz for this chip,
* or 1 MHz with burst mode.
*/
modm::ResumableResult<void>
initialize();

/**
* @brief Read a single register.
*
* @param reg The register to be read
* @return The register value in case of a read access, or std::nullopt if
* an error occured, e.g. if some register access is not permitted.
*/
modm::ResumableResult<std::optional<uint16_t>>
readRegister(Register reg);

/**
* @brief Write a single register.
*
* @param reg The register to be written
* @param value The value to be written to the register.
* @return False in case of any error, e.g. if some register acces is not
* permitted.
*/
modm::ResumableResult<bool>
writeRegister(Register reg, uint16_t value);

/**
* @brief Read a sequence of registers.
* Improves SPI usage efficiency by 100% compared to `accessRegister(...)`.
*
* @param sequence All registers in the std::span will be read and the
* results will be stored in values.
* @param values Results of the read operations
* @return False in case of any error, e.g. if some register access is not
* permitted.
*/
modm::ResumableResult<bool>
readRegisterSequence(std::span<Register> sequence, std::span<uint16_t> values);

/**
* @brief Read all output data registers using burst mode.
*
* In all clock modes, except when operating in scaled sync mode (Register
* MSC_CTRL, Bits[4:2] = 010), the burst read response includes the
* following registers and checksum value:
* DIAG_STAT, X_GYRO_OUT, Y_GYRO_OUT, Z_GYRO_OUT, X_ACCL_OUT, Y_ACCL_OUT,
* Z_ACCL_OUT, TEMP_OUT, DATA_CNTR, and checksum.
*
* When operating in scaled sync mode (Register MSC_CTRL, Bits[4:2] = 010),
* the burst read response includes the following registers and value:
* DIAG_STAT, X_GYRO_OUT, Y_GYRO_OUT, Z_GYRO_OUT, X_ACCL_OUT, Y_ACCL_OUT,
* Z_ACCL_OUT, TEMP_OUT, TIME_STMP, and checksum.
*
* This is useful with DMA accelerated SPI to retrieve the measurement
* data, because it only triggers a single SPI transfer.
*
* @warning The SPI frequency must not exceed 1 MHz for this mode.
*
* @param data Reference to a array of 11 uint16_t entries, the read
* register values are written here.
* data[0] is empty and the last entry (data[10]) contains a checksum which
* has already been checked by this driver.
* @return False in case of a checksum mismatch.
*/
modm::ResumableResult<bool>
readRegisterBurst(std::array<uint16_t, 11>& data);

private:
static constexpr std::size_t bufferSize = 22;
std::array<uint8_t, bufferSize> buffer;
std::size_t i;
uint8_t checksum;
};


} // modm namespace

#include "adis16470_impl.hpp"

#endif // MODM_ADIS16470_HPP
33 changes: 33 additions & 0 deletions src/modm/driver/inertial/adis16470.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2022, Raphael Lehmann
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------


def init(module):
module.name = ":driver:adis16470"
module.description = """\
# ADIS16470 Inertial Measurement Unit
[Datasheet](https://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16470.pdf)
"""

def prepare(module, options):
module.depends(
":architecture:gpio",
":architecture:register",
":architecture:spi.device",
":processing:resumable")
return True

def build(env):
env.outbasepath = "modm/src/modm/driver/inertial"
env.copy("adis16470.hpp")
env.copy("adis16470_impl.hpp")
Loading

0 comments on commit 1057565

Please sign in to comment.