Compare commits
4 commits
b50bc79a25
...
5b29c12d05
Author | SHA1 | Date | |
---|---|---|---|
5b29c12d05 | |||
e46fc9bb00 | |||
71eae62bda | |||
4a7b8b5b45 |
12 changed files with 2222 additions and 10 deletions
1
common/.gitignore
vendored
Normal file
1
common/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target
|
307
common/Cargo.lock
generated
Normal file
307
common/Cargo.lock
generated
Normal file
|
@ -0,0 +1,307 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic-polyfill"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "cobs"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
|
||||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"framed",
|
||||
"nalgebra",
|
||||
"postcard",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc16"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "338089f42c427b86394a5ee60ff321da23a5c89c9d89514c829687b26359fcff"
|
||||
|
||||
[[package]]
|
||||
name = "critical-section"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||
|
||||
[[package]]
|
||||
name = "framed"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"cobs",
|
||||
"crc16",
|
||||
"ref_slice",
|
||||
"serde",
|
||||
"ssmarshal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.7.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f"
|
||||
dependencies = [
|
||||
"atomic-polyfill",
|
||||
"hash32",
|
||||
"rustc_version",
|
||||
"serde",
|
||||
"spin",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nalgebra"
|
||||
version = "0.31.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20bd243ab3dbb395b39ee730402d2e5405e448c75133ec49cc977762c4cba3d1"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"num-complex",
|
||||
"num-rational",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"simba",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
||||
dependencies = [
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "postcard"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "170a2601f67cc9dba8edd8c4870b15f71a6a2dc196daec8c83f72b59dff628a8"
|
||||
dependencies = [
|
||||
"cobs",
|
||||
"heapless",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ref_slice"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4ed1d73fb92eba9b841ba2aef69533a060ccc0d3ec71c90aeda5996d4afb7a9"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
|
||||
dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.217"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.217"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simba"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f3fd720c48c53cace224ae62bef1bbff363a70c68c4802a78b5cc6159618176"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"num-complex",
|
||||
"num-traits",
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ssmarshal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3e6ad23b128192ed337dfa4f1b8099ced0c2bf30d61e551b65fda5916dbb850"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.96"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243"
|
10
common/Cargo.toml
Normal file
10
common/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
nalgebra = { version = "0.31.2", default-features=false, features = ["serde-serialize-no-std"] }
|
||||
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
|
||||
postcard = "1.0.0"
|
||||
framed = {path='/home/andy/programming/framed-rs/framed', default-features=false, features = ["use_nightly"]}
|
38
common/src/lib.rs
Normal file
38
common/src/lib.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
//! Data types shared between the northbridge and southbridge for serial communications
|
||||
#![no_std]
|
||||
|
||||
use nalgebra::Vector3;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum Command {
|
||||
/// Forward, clockwise
|
||||
Twist(f32,f32),
|
||||
Stop,
|
||||
|
||||
/// R, G, B brightness
|
||||
SetLed(Vector3<u8>),
|
||||
|
||||
Enable,
|
||||
FeedWatchdog,
|
||||
Disable,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
enabled: bool,
|
||||
sensor_data: Option<SensorData>,
|
||||
uptime_micros: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum SensorData {
|
||||
/// degrees per second
|
||||
Gyro(Vector3<f32>),
|
||||
/// g
|
||||
Accelerometer(Vector3<f32>),
|
||||
/// mT
|
||||
Magnetometer(Vector3<f32>),
|
||||
/// V
|
||||
BusVoltage(f32),
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
use std::{array::from_ref, net::SocketAddr, result, sync::Arc, thread::{self, sleep}, time::Duration};
|
||||
use std::{array::from_ref, net::SocketAddr, result, sync::Arc, thread::{self}, time::{Duration, SystemTime, UNIX_EPOCH}};
|
||||
|
||||
use battery::Manager;
|
||||
use image::{codecs::jpeg::JpegEncoder, ImageBuffer, Rgb};
|
||||
use nokhwa::{pixel_format::RgbFormat, utils::{ApiBackend, RequestedFormat, RequestedFormatType, Resolution}, Camera};
|
||||
use anyhow::{Context, Ok, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::{io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, net::{TcpListener, TcpStream}, runtime::Runtime, sync::{Notify, RwLock}, task::{JoinHandle, LocalSet}};
|
||||
use tokio::{io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, net::{TcpListener, TcpStream}, runtime::Runtime, sync::{Notify, RwLock}, task::{JoinHandle, LocalSet}, time::sleep};
|
||||
|
||||
fn main() -> Result<()>{
|
||||
let await_frame = Arc::new(Notify::new());
|
||||
|
@ -41,6 +41,7 @@ fn main() -> Result<()>{
|
|||
#[derive(Serialize)]
|
||||
struct Telemetry {
|
||||
battery_level: f32,
|
||||
timestamp: u64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
@ -69,18 +70,22 @@ async fn telemetry_server() -> Result<()>{
|
|||
Ok(())
|
||||
});
|
||||
|
||||
tokio::spawn(async move {
|
||||
let _: JoinHandle<Result<()>> = tokio::spawn(async move {
|
||||
let battery = Manager::new()?.batteries()?.nth(0).context("no battery")??;
|
||||
let full = battery.energy_full();
|
||||
|
||||
let mock = Telemetry { battery_level: (battery.energy()/full).value * 100. } ;
|
||||
loop {
|
||||
let time = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis();
|
||||
let mock = Telemetry { battery_level: (battery.energy()/full).value * 100., timestamp: time as u64 } ;
|
||||
|
||||
let mut send = serde_json::to_vec(&mock).unwrap();
|
||||
let mut send = serde_json::to_vec(&mock)?;
|
||||
send.push(b'\r');
|
||||
send.push(b'\n');
|
||||
|
||||
sender.write_all(&send).await.unwrap();
|
||||
Ok(())
|
||||
sender.write_all(&send).await?;
|
||||
|
||||
sleep(Duration::from_millis(20)).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -106,7 +111,7 @@ async fn camera_manager(await_frame: Arc<Notify>, latest_frame: Arc<RwLock<Vec<u
|
|||
|
||||
let mut encoder = JpegEncoder::new_with_quality(&mut output, 30);
|
||||
|
||||
encoder.encode_image(&frame).unwrap();
|
||||
encoder.encode_image(&frame)?;
|
||||
|
||||
*latest_frame.write().await = output;
|
||||
await_frame.notify_waiters();
|
||||
|
|
5
southbridge/.cargo/config.toml
Normal file
5
southbridge/.cargo/config.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
runner = "elf2uf2-rs --deploy --serial --verbose"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
1716
southbridge/Cargo.lock
generated
Normal file
1716
southbridge/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
30
southbridge/Cargo.toml
Normal file
30
southbridge/Cargo.toml
Normal file
|
@ -0,0 +1,30 @@
|
|||
[package]
|
||||
edition = "2021"
|
||||
name = "southbridge"
|
||||
version = "0.1.0"
|
||||
resolver = "2"
|
||||
|
||||
[dependencies]
|
||||
embedded-hal = "1.0.0"
|
||||
embedded-hal-async = "1.0.0"
|
||||
embedded-io = "0.6.1"
|
||||
embedded-io-async = "0.6.1"
|
||||
embedded-storage = "0.3.1"
|
||||
|
||||
cortex-m-rt = "0.7.3"
|
||||
|
||||
embassy-executor = { version = "0.7", features = ["task-arena-size-1024", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-sync = { version = "0.6" }
|
||||
embassy-time = { version = "0.4" }
|
||||
cortex-m = { version = "0.7.6" }
|
||||
embassy-rp = { version = "0.3", features = ["unstable-pac", "time-driver", "critical-section-impl", "rp2040"] }
|
||||
embassy-usb-logger = "0.4.0"
|
||||
log = "0.4"
|
||||
|
||||
|
||||
framed = {git = "https://git.ank.dev/ank/framed-rs", default-features=false, features = ["use_nightly"]}
|
||||
common = { path = "../common" }
|
||||
mpu6050 = { git = "https://git.ank.dev/ank/mpu6050" }
|
||||
nalgebra = { version = "0.31.2", default-features=false, features = ["serde-serialize-no-std"] }
|
||||
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
|
||||
postcard = "1.0.0"
|
35
southbridge/build.rs
Normal file
35
southbridge/build.rs
Normal file
|
@ -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-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
|
||||
}
|
7
southbridge/memory.x
Normal file
7
southbridge/memory.x
Normal file
|
@ -0,0 +1,7 @@
|
|||
MEMORY
|
||||
{
|
||||
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
|
||||
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 264K
|
||||
}
|
||||
|
10
southbridge/rust-toolchain.toml
Normal file
10
southbridge/rust-toolchain.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Before upgrading check that everything is available on all tier1 targets here:
|
||||
# https://rust-lang.github.io/rustup-components-history
|
||||
[toolchain]
|
||||
channel = "stable"
|
||||
components = [ "rustfmt" ]
|
||||
targets = [
|
||||
"thumbv6m-none-eabi",
|
||||
"thumbv7em-none-eabihf",
|
||||
"riscv32imac-unknown-none-elf",
|
||||
]
|
48
southbridge/src/main.rs
Normal file
48
southbridge/src/main.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::{bind_interrupts, peripherals::USB, pwm::{self, Pwm}, usb::Driver};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use log::{error, info};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
I2C0_IRQ => embassy_rp::i2c::InterruptHandler<embassy_rp::peripherals::I2C0>;
|
||||
USBCTRL_IRQ => embassy_rp::usb::InterruptHandler<USB>;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn logger_task(driver: Driver<'static, USB>) {
|
||||
embassy_usb_logger::run!(1024, log::LevelFilter::Debug, driver);
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic( info: &PanicInfo) -> ! {
|
||||
error!("{}", info);
|
||||
loop { }
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
|
||||
let driver = Driver::new(p.USB, Irqs);
|
||||
spawner.spawn(logger_task(driver)).unwrap();
|
||||
|
||||
let mut drive_conf: pwm::Config = Default::default();
|
||||
drive_conf.divider = 40.into();
|
||||
drive_conf.top = 62500; // 20ms
|
||||
drive_conf.compare_b = 4687; // 1.5ms
|
||||
drive_conf.compare_a = 4687; // 1.5ms
|
||||
let mut drive_pwm = Pwm::new_output_ab(p.PWM_SLICE1, p.PIN_18, p.PIN_19, drive_conf.clone());
|
||||
|
||||
let config = embassy_rp::i2c::Config::default();
|
||||
let bus = embassy_rp::i2c::I2c::new_async(p.I2C0, p.PIN_21, p.PIN_20, Irqs, config);
|
||||
|
||||
loop {
|
||||
info!("Blink");
|
||||
Timer::after(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue