renamed example to examples
This commit is contained in:
8
examples/rp2040_embassy/.cargo/config.toml
Normal file
8
examples/rp2040_embassy/.cargo/config.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
runner = "picotool load --update --verify --execute -t elf"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "debug"
|
||||
1
examples/rp2040_embassy/.gitignore
vendored
Normal file
1
examples/rp2040_embassy/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
1437
examples/rp2040_embassy/Cargo.lock
generated
Normal file
1437
examples/rp2040_embassy/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
examples/rp2040_embassy/Cargo.toml
Normal file
23
examples/rp2040_embassy/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "rp2040_embassy"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
embassy-embedded-hal = { version = "0.5.0" }
|
||||
embassy-sync = { version = "0.7.2", features = ["log"] }
|
||||
embassy-executor = { version = "0.9.1" , features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "log"] }
|
||||
embassy-time = { version = "0.5.0", features = ["log"] }
|
||||
embassy-rp = { version = "0.9.0" , features = ["log", "time-driver", "critical-section-impl", "rp2040"] }
|
||||
embassy-futures = { version = "0.1.2" }
|
||||
embassy-usb-logger = { version = "0.5.1" }
|
||||
embassy-usb = { version = "0.5.1", features = ["log"] }
|
||||
|
||||
cortex-m = { version = "0.7.7", features = ["inline-asm"] }
|
||||
cortex-m-rt = "0.7.5"
|
||||
critical-section = "1.2.0"
|
||||
heapless = "0.9.2"
|
||||
|
||||
log = "0.4"
|
||||
|
||||
mmc56x3 = { path = "../../" }
|
||||
21
examples/rp2040_embassy/build.rs
Normal file
21
examples/rp2040_embassy/build.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
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());
|
||||
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
|
||||
}
|
||||
5
examples/rp2040_embassy/memory.x
Normal file
5
examples/rp2040_embassy/memory.x
Normal file
@@ -0,0 +1,5 @@
|
||||
MEMORY {
|
||||
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
|
||||
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 264K
|
||||
}
|
||||
83
examples/rp2040_embassy/src/main.rs
Normal file
83
examples/rp2040_embassy/src/main.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::{
|
||||
bind_interrupts,
|
||||
i2c::{self, I2c},
|
||||
peripherals::{self, USB},
|
||||
usb::Driver,
|
||||
};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use log::{error, info};
|
||||
use mmc56x3::MMC56X3;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
embassy_rp::rom_data::reset_to_usb_boot(0, 0);
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
USBCTRL_IRQ => embassy_rp::usb::InterruptHandler<USB>;
|
||||
I2C0_IRQ => i2c::InterruptHandler<peripherals::I2C0>;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn logger_task(driver: Driver<'static, USB>) {
|
||||
embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver);
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
|
||||
let driver = Driver::new(p.USB, Irqs);
|
||||
spawner.must_spawn(logger_task(driver));
|
||||
|
||||
let sda = p.PIN_4;
|
||||
let scl = p.PIN_5;
|
||||
|
||||
let i2c = I2c::new_blocking(p.I2C0, scl, sda, i2c::Config::default());
|
||||
|
||||
let mut device = MMC56X3::new(i2c, Delay);
|
||||
if let Err(e) = device.init() {
|
||||
error!("Failed to init {:?}", e);
|
||||
reboot().await;
|
||||
};
|
||||
|
||||
if let Err(e) = device.set_data_rate(mmc56x3::DataRate::Max1000Hz) {
|
||||
error!("Failed to set data rate {:?}", e);
|
||||
reboot().await;
|
||||
}
|
||||
|
||||
if let Err(e) = device.set_continuous_mode(true) {
|
||||
error!("Failed to set_continuous_mode {:?}", e);
|
||||
reboot().await;
|
||||
}
|
||||
|
||||
for _ in 0..200 {
|
||||
Timer::after_millis(50).await;
|
||||
|
||||
// let result = device.read_temperature().await;
|
||||
// info!("T: {:?}", result);
|
||||
// device
|
||||
// .trigger_messurement()
|
||||
// .await
|
||||
// .expect("Failed to trigger trigger_messurement");
|
||||
|
||||
match device.read_messurement() {
|
||||
Ok(d) => info!("Got: {:?}", d),
|
||||
Err(e) => error!("Error: {:?}", e),
|
||||
}
|
||||
}
|
||||
|
||||
reboot().await;
|
||||
}
|
||||
|
||||
async fn reboot() {
|
||||
info!("Doing cold boot");
|
||||
Timer::after_secs(1).await;
|
||||
embassy_rp::rom_data::reset_to_usb_boot(0, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user