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

Add minimal BNO055 driver #191

Merged
merged 3 commits into from
Jul 11, 2019
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
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,53 +168,54 @@ can easily configure them for you specific needs.
</tr><tr>
<td align="center">BME280</td>
<td align="center">BMP085</td>
<td align="center">BNO055</td>
<td align="center">DRV832X</td>
<td align="center">DS1302</td>
<td align="center">DS1631</td>
<td align="center">DS18B20</td>
</tr><tr>
<td align="center">DS18B20</td>
<td align="center">EA-DOG</td>
<td align="center">FT245</td>
<td align="center">FT6X06</td>
<td align="center">HCLAx</td>
<td align="center">HD44780</td>
<td align="center">HMC58x</td>
</tr><tr>
<td align="center">HMC58x</td>
<td align="center">HMC6343</td>
<td align="center">I2C-EEPROM</td>
<td align="center">ITG3200</td>
<td align="center">L3GD20</td>
<td align="center">LAWICEL</td>
<td align="center">LIS302DL</td>
</tr><tr>
<td align="center">LIS302DL</td>
<td align="center">LIS3DSH</td>
<td align="center">LM75</td>
<td align="center">LSM303A</td>
<td align="center">LTC2984</td>
<td align="center">MAX6966</td>
<td align="center">MAX7219</td>
</tr><tr>
<td align="center">MAX7219</td>
<td align="center">MCP23X17</td>
<td align="center">MCP2515</td>
<td align="center">NOKIA5110</td>
<td align="center">NRF24</td>
<td align="center">TFT-DISPLAY</td>
<td align="center">PAT9125EL</td>
</tr><tr>
<td align="center">PAT9125EL</td>
<td align="center">PCA8574</td>
<td align="center">PCA9535</td>
<td align="center">PCA9548A</td>
<td align="center">PCA9685</td>
<td align="center">SIEMENS-S65</td>
<td align="center">SIEMENS-S75</td>
</tr><tr>
<td align="center">SIEMENS-S75</td>
<td align="center">SSD1306</td>
<td align="center">TCS3414</td>
<td align="center">TCS3472</td>
<td align="center">TMP102</td>
<td align="center">TMP175</td>
<td align="center">VL53L0</td>
</tr><tr>
<td align="center">VL53L0</td>
<td align="center">VL6180</td>
<td align="center">WS2812</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ make gdb

## Interesting Examples

We have a lot of examples, <!--examplecount-->189<!--/examplecount--> to be
We have a lot of examples, <!--examplecount-->190<!--/examplecount--> to be
exact, but here are some of our favorite examples for our supported development
boards:

Expand Down
120 changes: 120 additions & 0 deletions examples/nucleo_f411re/imu_bno055/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// coding: utf-8
/*
* Copyright (c) 2019, Niklas Hauser
*
* 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/processing.hpp>
#include <modm/driver/inertial/bno055.hpp>
#include <modm/debug.hpp>
using namespace modm::literals;

// Set the log level
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::DEBUG

/**
* Example to demonstrate a MODM driver for imu sensor VL53L0X
*
* This example uses I2cMaster1 of STM32F401
*
* SDA PB9
* SCL PB8
*
* GND and +3V are connected to the sensor.
*/

using namespace Board;

using MyI2cMaster = I2cMaster1;
// using MyI2cMaster = BitBangI2cMaster<Board::D15, Board::D14>;

modm::bno055::Data data;
modm::Bno055<MyI2cMaster> imu(data);

class ThreadOne : public modm::pt::Protothread
{
public:
bool
update()
{
PT_BEGIN();

MODM_LOG_DEBUG << "Ping the device from ThreadOne" << modm::endl;

// ping the device until it responds
while (true)
{
// we wait until the device started
if (PT_CALL(imu.ping())) {
break;
}
PT_WAIT_UNTIL(timer.execute());
}

MODM_LOG_DEBUG << "Device responded" << modm::endl;

while (true)
{
if (PT_CALL(imu.configure())) {
break;
}

PT_WAIT_UNTIL(timer.execute());
}

MODM_LOG_DEBUG << "Device configured" << modm::endl;

while (true)
{
PT_WAIT_UNTIL(timer.execute());
PT_CALL(imu.readData());
MODM_LOG_INFO << (int)imu.getData().heading() << modm::endl;
}

PT_END();
}

private:
modm::ShortPeriodicTimer timer{100};
};

ThreadOne one;

// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
LedD13::setOutput();

// Board::D13::setOutput(modm::Gpio::Low);
MyI2cMaster::connect<Board::D15::Scl, Board::D14::Sda>();
MyI2cMaster::initialize<Board::SystemClock, 400_kHz>();

MODM_LOG_INFO << "\n\nWelcome to BNO055 demo!\n\n" << modm::endl;

modm::ShortPeriodicTimer tmr(500);

// Board::D15::setOutput();

while (1)
{
one.update();
if(tmr.execute()) {
LedD13::toggle();
// Board::D15::toggle();
}

}

return 0;
}
15 changes: 15 additions & 0 deletions examples/nucleo_f411re/imu_bno055/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<library>
<extends>modm:nucleo-f411re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f411re/bno055</option>
</options>
<modules>
<module>modm:debug</module>
<module>modm:driver:bno055</module>
<module>modm:platform:gpio</module>
<module>modm:platform:i2c:1</module>
<module>modm:platform:i2c.bitbang</module>
<module>modm:processing:protothread</module>
<module>modm:build:scons</module>
</modules>
</library>
19 changes: 19 additions & 0 deletions src/modm/architecture/interface/register.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,25 @@ constexpr ::modm::Flags<Enum> operator^(Enum const &a, Enum const &b) { return :
#define MODM_TYPE_FLAGS(Parent) \
MODM_INTERNAL_FLAGS(Parent,)

/**
* @details
* This macro creates a `Config_t` type out of the `Parent` and `Config` enum.
* The mask is taken from a `Parent::Config_Mask` field containing the ORed bits
* of the configuration.
*
* @note This macro does not allow using the configuration position.
* Please use the `modm::Configuration` class manually in that case.
*
* @param Parent a Flags Enum
* @param Config a Config Enum
*
* @ingroup modm_architecture_register
* @hideinitializer
*/
#define MODM_FLAGS_CONFIG(Parent, Config) \
using MODM_CONCAT(Config, _t) = \
::modm::Configuration< MODM_CONCAT(Parent, _t), Config, \
MODM_CONCAT(Parent, _t)::UnderlyingType(MODM_CONCAT(Parent::Config, _Mask)) >

/// @cond
#define MODM_INT_TYPE_FLAGS(Parent) \
Expand Down
Loading