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

[driver] IMU ADIS16470 #805

Merged
merged 3 commits into from
Jan 24, 2022
Merged
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
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,93 +633,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
143 changes: 143 additions & 0 deletions examples/nucleo_f429zi/imu_adis16470/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* 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/.
*/
// ----------------------------------------------------------------------------

#include <modm/board.hpp>
#include <modm/platform/spi/spi_master_1.hpp>
#include <modm/driver/inertial/adis16470.hpp>
#include <optional>

using namespace Board;

using SpiMaster = SpiMaster1;
using Mosi = GpioB5;
using Miso = GpioB4;
using Sck = GpioB3;
using Cs = GpioA4;
using Dr = GpioB9;
using Rst = GpioB8;

using Adis16470 = modm::Adis16470<SpiMaster, Cs>;

Adis16470 imu{};

int
main()
{
Board::initialize();
Leds::setOutput();

MODM_LOG_INFO << "ADIS16470 IMU demo on Nucleo-F429ZI\n" << modm::endl;

SpiMaster::initialize<Board::SystemClock, 650_kHz>();
SpiMaster::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>();

Rst::setOutput();
Dr::setInput(Gpio::InputType::PullUp);

// Reset ADS816x chip
Rst::reset();
modm::delay(10ms);
Rst::set();

// Wait start-up time
modm::delay(252ms);

MODM_LOG_INFO << "Initializing IMU..." << modm::endl;
RF_CALL_BLOCKING(imu.initialize());

// Software reset
RF_CALL_BLOCKING(imu.writeGlobCmd(modm::adis16470::GlobCmd::SoftwareReset));
// Wait start-up time after reset
modm::delay(252ms);

// Trigger self test
RF_CALL_BLOCKING(imu.writeGlobCmd(modm::adis16470::GlobCmd::SensorSelfTest));
// Wait for self test to complete
modm::delay(14ms);

modm::adis16470::DiagStat_t diagStat = RF_CALL_BLOCKING(imu.readDiagStat());
MODM_LOG_INFO << "Reading DIAG_STAT register = " << diagStat << modm::endl;

modm::delay(1ms);
auto result = RF_CALL_BLOCKING(imu.readRegister(modm::adis16470::Register::PROD_ID));
if (result.has_value()) {
MODM_LOG_INFO << "ADIS16470 product id = " << *result << " (should be 16470==0x4056)" << modm::endl;
}
else {
MODM_LOG_INFO << "Unable to reag PROD_ID register" << modm::endl;
}

modm::adis16470::MscCtrl_t mscCtrl = RF_CALL_BLOCKING(imu.readMscCtrl());
MODM_LOG_INFO << "Reading MSC_CTRL register = " << mscCtrl << modm::endl;

RF_CALL_BLOCKING(imu.setDataOutputFrequency<10_Hz>());

RF_CALL_BLOCKING(imu.writeRegister(modm::adis16470::Register::FILT_CTRL, 8)); // N_B = 2^8 = 64

mscCtrl = modm::adis16470::MscCtrl::DrPolarity | modm::adis16470::MscCtrl::PointOfPercussionAlign;
MODM_LOG_INFO << "Writing MSC_CTRL register = " << mscCtrl << modm::endl;
RF_CALL_BLOCKING(imu.writeMscCtrl(mscCtrl));

diagStat = RF_CALL_BLOCKING(imu.readDiagStat());
MODM_LOG_INFO << "Reading DIAG_STAT register = " << diagStat << modm::endl;

mscCtrl = RF_CALL_BLOCKING(imu.readMscCtrl());
MODM_LOG_INFO << "Reading MSC_CTRL register = " << mscCtrl << modm::endl;

// Writing and reading USER_SCR1 register
std::optional<uint16_t> scr1 = RF_CALL_BLOCKING(imu.readRegister(modm::adis16470::Register::USER_SCR1));
if (scr1.has_value()) {
MODM_LOG_INFO << "Reading USER_SCR1 register = " << *scr1 << modm::endl;
}
else {
MODM_LOG_INFO << "Unable to USER_SCR1 register." << modm::endl;
}
MODM_LOG_INFO << "Writing USER_SCR1 register = 42" << modm::endl;
RF_CALL_BLOCKING(imu.writeRegister(modm::adis16470::Register::USER_SCR1, 42));
scr1 = RF_CALL_BLOCKING(imu.readRegister(modm::adis16470::Register::USER_SCR1));
if (scr1.has_value()) {
MODM_LOG_INFO << "Reading USER_SCR1 register = " << *scr1 << modm::endl;
}
else {
MODM_LOG_INFO << "Unable to USER_SCR1 register." << modm::endl;
}

std::array<uint16_t, 11> data;

while (true)
{
MODM_LOG_INFO.printf("\nIMU data: ");

while (!Dr::read()) {}
while (Dr::read()) {}

if( !RF_CALL_BLOCKING(imu.readRegisterBurst(data))) {
MODM_LOG_INFO.printf("checksum mismatch! ");
Board::LedRed::toggle();
}

// print data anyways
MODM_LOG_INFO.printf("DIAG_STAT=%05u, ", data[1]);
MODM_LOG_INFO.printf("X_GYRO_OUT=%+05i, ", static_cast<int16_t>(data[2]));
MODM_LOG_INFO.printf("Y_GYRO_OUT=%+05i, ", static_cast<int16_t>(data[3]));
MODM_LOG_INFO.printf("Z_GYRO_OUT=%+05i, ", static_cast<int16_t>(data[4]));
MODM_LOG_INFO.printf("X_ACCL_OUT=%+05i, ", static_cast<int16_t>(data[5]));
MODM_LOG_INFO.printf("Y_ACCL_OUT=%+05i, ", static_cast<int16_t>(data[6]));
MODM_LOG_INFO.printf("Z_ACCL_OUT=%+05i, ", static_cast<int16_t>(data[7]));
MODM_LOG_INFO.printf("TEMP_OUT=%+05i (1/10 C), ", data[8]);
MODM_LOG_INFO.printf("DATA_CNTR=%05u, ", data[9]);
MODM_LOG_INFO.printf("checksum=%05u", data[10]);

Board::LedGreen::toggle();
}

return 0;
}
11 changes: 11 additions & 0 deletions examples/nucleo_f429zi/imu_adis16470/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:nucleo-f429zi</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f429zi/imu_adis16470</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:spi:1</module>
<module>modm:driver:adis16470</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion src/modm/architecture/interface/register.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ struct FlagsGroup<T> : public Register<typename T::UnderlyingType>
* the meanings [Div1, Div2, Div4, Div8].
*
* The Configuration class belongs to a specific Flags class and connects a
* corresponding Sascha Schade enum with a specific mask and bit position.
* corresponding strongly typed enum with a specific mask and bit position.
* This means that the Configuration class will mask and shift the values whenever
* needed.
* However, shifting is only done when the Position template parameter is non-zero.
Expand Down
71 changes: 71 additions & 0 deletions src/modm/driver/inertial/adis16470.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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/.
*/
// ----------------------------------------------------------------------------

#include "adis16470.hpp"

modm::IOStream&
modm::operator << (modm::IOStream& os, const adis16470::DiagStat_t& c) {
os << "DiagStat(";
if(c & adis16470::DiagStat::ClockError)
os << "ClockError ";
if(c & adis16470::DiagStat::MemoryFailure)
os << "MemoryFailure ";
if(c & adis16470::DiagStat::SensorFailure)
os << "SensorFailure ";
if(c & adis16470::DiagStat::StandbyMode)
os << "StandbyMode ";
if(c & adis16470::DiagStat::SpiCommunicationError)
os << "SpiCommunicationError ";
if(c & adis16470::DiagStat::FlashUpdateFailure)
os << "FlashUpdateFailure ";
if(c & adis16470::DiagStat::DataPathOverrun)
os << "DataPathOverrun ";
os << ")";
return os;
}

modm::IOStream&
modm::operator << (modm::IOStream& os, const adis16470::MscCtrl_t& c) {
os << "MscCtrl(";
if(c & adis16470::MscCtrl::LinearGCompensationGyro)
os << "LinearGCompensationGyro ";
if(c & adis16470::MscCtrl::PointOfPercussionAlign)
os << "PointOfPercussionAlign ";
os << "SyncFunction=";
switch (adis16470::SyncFunction_t::get(c))
{
case adis16470::SyncFunction::PulseSync:
os << "PulseSync ";
break;
case adis16470::SyncFunction::OutputSync:
os << "OutputSync ";
break;
case adis16470::SyncFunction::ScaledSync:
os << "ScaledSync ";
break;
case adis16470::SyncFunction::DirectSync:
os << "DirectSync ";
break;
case adis16470::SyncFunction::InternalClock:
os << "InternalClock ";
break;
default:
os << "? ";
break;
}
if(c & adis16470::MscCtrl::SyncPolarity)
os << "SyncPolarity ";
if(c & adis16470::MscCtrl::DrPolarity)
os << "DrPolarity ";
os << ")";
return os;
}
Loading