Skip to content
Open
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
24 changes: 22 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
**/*.rs.bk
.#*
# Generated by Cargo
/target/
**/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# Backup files
**/*.rs.bk
*~
.#*

# IDE files
.idea/
.vscode/
*.swp
*.swo

# macOS specific files
.DS_Store

# Windows specific files
Thumbs.db
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
[package]
authors = ["Roma Sokolov", "Alexander Zhuravlev", "Jorge Aparicio <jorge@japaric.io>"]
authors = [
"Roma Sokolov",
"Alexander Zhuravlev",
"Jorge Aparicio <jorge@japaric.io>",
]
name = "mpu9250"
version = "0.25.0"
version = "0.30.0"
description = "no_std driver for the MPU9250 & onboard AK8963 (accelerometer + gyroscope + magnetometer IMU)"
keywords = ["arm", "cortex-m", "stm32", "hal"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/copterust/mpu9250"
edition = "2024"

[dependencies]
embedded-hal = "0.2.3"
bitflags = "1.0"
# embedded-hal = "0.2.3"
embedded-hal = "1.0.0"
bitflags = "2.8.0"
libm = { version = "0.2.1", optional = true }

[dev-dependencies]
linux-embedded-hal = "0.3"
linux-embedded-hal = "0.4.0"

[features]
# Enable the I2C MPU interface. This disables the SPI interface. All function
Expand Down
5 changes: 5 additions & 0 deletions examples/legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Examples - Old Style

This folder contains the original examples from before the transition to embedded-hal 1.0. They have been preserved here as a reference but have not been updated to work with the current version of the library.

These examples are provided for historical reference only. For up-to-date examples that work with the current version of the library, please refer to the main examples directory.
File renamed without changes.
28 changes: 13 additions & 15 deletions examples/bbblue_dmp.rs → examples/legacy/bbblue_dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ extern crate mpu9250;

use std::io::{self, Write};

use hal::sysfs_gpio;
use hal::Delay;
use hal::I2cdev;
use hal::sysfs_gpio;
use mpu9250::DMP_FIRMWARE;
use mpu9250::{Error, Mpu9250};

Expand All @@ -30,27 +30,25 @@ fn main() {
let mut stdout = stdout.lock();
writeln!(&mut stdout, " Normalized quaternion").unwrap();

let mut mpu9250 =
Mpu9250::dmp_default(i2c, &mut Delay, &DMP_FIRMWARE).expect("unable to load firmware");
let mut mpu9250 = Mpu9250::dmp_default(i2c, &mut Delay, &DMP_FIRMWARE)
.expect("unable to load firmware");

loop {
match event.poll(1000).unwrap() {
Some(_) =>
match mpu9250.dmp_all::<[f32; 3], [f64; 4]>() {
Ok(measure) => {
write!(&mut stdout,
"\r{:?}",
measure).unwrap();
stdout.flush().unwrap();
},
Err(Error::DmpDataNotReady) => (),
Err(_) => (),
Some(_) => match mpu9250.dmp_all::<[f32; 3], [f64; 4]>() {
Ok(measure) => {
write!(&mut stdout, "\r{:?}", measure).unwrap();
stdout.flush().unwrap();
},
Err(Error::DmpDataNotReady) => (),
Err(_) => (),
},
None => {
write!(&mut stdout, "\nTimeout\n").unwrap();
mpu9250.reset_fifo(&mut Delay).unwrap();
}
},
}
}
}).unwrap();
})
.unwrap();
}
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/rp235x/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# pick one of the following options by uncommenting it
# runner = "elf2uf2-rs -d" #and then flash manually
# runner = "picotool load -u -v -x -t elf"
runner = "probe-rs run --chip RP235x --protocol swd --speed 16000 --probe 2e8a:000c:E6633861A3543E38"

[build]
target = "thumbv8m.main-none-eabihf"

[env]
DEFMT_LOG = "debug"
40 changes: 40 additions & 0 deletions examples/rp235x/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "examples"
version = "0.1.0"
edition = "2024"

[[example]]
name = "basic"
path = "src/basic.rs"

[dependencies]
embassy-rp = { version = "0.3.1", features = [
"defmt",
"unstable-pac",
"time-driver",
"critical-section-impl",
"rp235xa",
] }
embassy-embedded-hal = { version = "0.3.0", features = ["defmt"] }
embassy-sync = { version = "0.6.2", features = ["defmt"] }
embassy-executor = { version = "0.7.0", features = [
"task-arena-size-98304",
"arch-cortex-m",
"executor-thread",
"executor-interrupt",
"defmt",
] }
embassy-time = { version = "0.4.0", features = [
"defmt",
"defmt-timestamp-uptime",
] }
embassy-futures = { version = "0.1.1" }
defmt = "0.3"
defmt-rtt = "0.4"
cortex-m-rt = "0.7.5"
critical-section = "1.2.0"
panic-probe = { version = "0.3", features = ["print-defmt"] }
num-traits = { version = "0.2", default-features = false }
libm = "0.2.1"

mpu9250 = { path = "../..", features = ["i2c", "dmp"] }
28 changes: 28 additions & 0 deletions examples/rp235x/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# MPU6050-DMP Examples

This directory contains examples demonstrating use of the MPU9250 sensor.

## Examples

### [Basic](src/basic.rs)

Basic example showing how to:

- Initialize the sensor with I2C
- Perform sensor calibration
- Read accelerometer, gyroscope and temperature data

## Building and Running

1. Connect your MPU6050 to a Raspberry Pi Pico 2:
- SDA -> GP16
- SCL -> GP17
- VCC -> 3.3V
- GND -> GND

2. Build and flash an example:

```bash
# For the basic example
cargo run --example basic
```
35 changes: 35 additions & 0 deletions examples/rp235x/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());

// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");

println!("cargo:rustc-link-arg=--nmagic");
println!("cargo:rustc-link-arg=-Tlink.x");
println!("cargo:rustc-link-arg=-Tdefmt.x");
}
74 changes: 74 additions & 0 deletions examples/rp235x/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
MEMORY {
/*
* The RP2350 has either external or internal flash.
*
* 2 MiB is a safe default here, although a Pico 2 has 4 MiB.
*/
FLASH : ORIGIN = 0x10000000, LENGTH = 2048K
/*
* RAM consists of 8 banks, SRAM0-SRAM7, with a striped mapping.
* This is usually good for performance, as it distributes load on
* those banks evenly.
*/
RAM : ORIGIN = 0x20000000, LENGTH = 512K
/*
* RAM banks 8 and 9 use a direct mapping. They can be used to have
* memory areas dedicated for some specific job, improving predictability
* of access times.
* Example: Separate stacks for core0 and core1.
*/
SRAM4 : ORIGIN = 0x20080000, LENGTH = 4K
SRAM5 : ORIGIN = 0x20081000, LENGTH = 4K
}

SECTIONS {
/* ### Boot ROM info
*
* Goes after .vector_table, to keep it in the first 4K of flash
* where the Boot ROM (and picotool) can find it
*/
.start_block : ALIGN(4)
{
__start_block_addr = .;
KEEP(*(.start_block));
} > FLASH

} INSERT AFTER .vector_table;

/* move .text to start /after/ the boot info */
_stext = ADDR(.start_block) + SIZEOF(.start_block);

SECTIONS {
/* ### Picotool 'Binary Info' Entries
*
* Picotool looks through this block (as we have pointers to it in our
* header) to find interesting information.
*/
.bi_entries : ALIGN(4)
{
/* We put this in the header */
__bi_entries_start = .;
/* Here are the entries */
KEEP(*(.bi_entries));
/* Keep this block a nice round size */
. = ALIGN(4);
/* We put this in the header */
__bi_entries_end = .;
} > FLASH
} INSERT AFTER .text;

SECTIONS {
/* ### Boot ROM extra info
*
* Goes after everything in our program, so it can contain a signature.
*/
.end_block : ALIGN(4)
{
__end_block_addr = .;
KEEP(*(.end_block));
} > FLASH

} INSERT AFTER .uninit;

PROVIDE(start_to_end = __end_block_addr - __start_block_addr);
PROVIDE(end_to_start = __start_block_addr - __end_block_addr);
Loading