diff --git a/Cargo.lock b/Cargo.lock index a8012df2c19d6979cc897d20231de7526b23de5e..0f7e101dcc5b5b8abf24c76ae7c8dade0638dcf0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,13 +53,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "common" -version = "0.1.0" -dependencies = [ - "embassy-stm32", -] - [[package]] name = "cortex-m" version = "0.7.7" @@ -138,7 +131,6 @@ dependencies = [ name = "dc-motor-driver-hat" version = "0.3.0" dependencies = [ - "common", "cortex-m", "cortex-m-rt", "critical-section", @@ -153,6 +145,7 @@ dependencies = [ "i2c2-target", "panic-probe", "semver 1.0.23", + "support", ] [[package]] @@ -730,6 +723,17 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "support" +version = "0.1.0" +dependencies = [ + "defmt", + "embassy-executor", + "embassy-stm32", + "embassy-sync", + "embassy-time", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/Cargo.toml b/Cargo.toml index f52579b3e238e43b441cb8cfc69ea3534f9dba3d..ddf2b49d17938f19838377b84bb78337568ff90d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [ "common","controller", "i2c2-target"] +members = ["controller", "i2c2-target", "support"] exclude = ["pid"] resolver = "2" diff --git a/common/Cargo.toml b/common/Cargo.toml deleted file mode 100644 index 1a0b871ac69dbcd988e7a064331f8c6c29703b03..0000000000000000000000000000000000000000 --- a/common/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "common" -version = "0.1.0" -edition = "2021" - -[dependencies] -embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", features = ["unstable-pac"] } diff --git a/controller/Cargo.toml b/controller/Cargo.toml index 6cbabeb10deda133549cd8794c7958969284e05b..5f214378071594f573fb67b2463171429648cb42 100644 --- a/controller/Cargo.toml +++ b/controller/Cargo.toml @@ -5,7 +5,6 @@ authors = ["Samuel Tardieu <sam@rfc1149.net>"] edition = "2021" [dependencies] -common = { version = "0.1.0", path = "../common" } cortex-m = { version = "0.7.7", features = ["critical-section-single-core", "inline-asm"] } cortex-m-rt = "0.7.3" critical-section = "1.1.2" @@ -19,6 +18,7 @@ futures = { version = "0.3.30", default-features = false } heapless = "0.8.0" i2c2-target = { path = "../i2c2-target" } panic-probe = { version = "0.3.2", features = ["print-defmt"] } +support = { version = "0.1.0", path = "../support" } [lints.clippy] pedantic = "deny" diff --git a/controller/src/chip.rs b/controller/src/chip.rs deleted file mode 100644 index a7bef6f87991ae255d035f5632d5fb10c68bd2e5..0000000000000000000000000000000000000000 --- a/controller/src/chip.rs +++ /dev/null @@ -1,21 +0,0 @@ -pub fn identify() { - let (density, rev) = common::mcu_kind(); - let flash_size = common::flash_size(); - defmt::info!( - "Device type: {}, revision: {} – flash size: {}kB", - density, - rev, - flash_size - ); - - if let Some((identity_code, continuation_code, device)) = common::identity() { - defmt::info!( - "device = {} (identity code = {:#04x}, continuation code = {:#04x})", - device, - identity_code, - continuation_code - ); - } else { - defmt::info!("no identity and continuation codes"); - } -} diff --git a/controller/src/logic/mod.rs b/controller/src/logic/mod.rs index 7416d82e2432c0d83a5fd4526f648a675c76d099..f690aa30bc7eb6518974dca16c0d02431ad6011f 100644 --- a/controller/src/logic/mod.rs +++ b/controller/src/logic/mod.rs @@ -156,7 +156,7 @@ fn process_command( cortex_m::peripheral::SCB::sys_reset(); } [CMD_DEVICE_ID] => { - for &b in common::device_id() { + for &b in support::device_id() { response.push(b).unwrap(); } } diff --git a/controller/src/main.rs b/controller/src/main.rs index e65651c782a4f739872494b4f58a3352e27f9a4e..945546284420713b41d02b41b55e88a68f4c3313 100644 --- a/controller/src/main.rs +++ b/controller/src/main.rs @@ -13,12 +13,10 @@ use embassy_stm32::{ Config, }; use panic_probe as _; +use support::{blinker, power}; -pub mod blinker; -mod chip; mod encoders; mod logic; -mod power; mod tb6612fng; #[derive(Clone, Copy, Debug)] @@ -88,7 +86,7 @@ async fn main(spawner: Spawner) { defmt::Debug2Format(&reset_cause), ); - chip::identify(); + support::identify(); spawner .spawn(blinker::blink(p.PB15, blink_pattern(reset_cause))) diff --git a/support/Cargo.toml b/support/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..520c41487a657cc9e13b44c1f12087db870f01a8 --- /dev/null +++ b/support/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "support" +version = "0.1.0" +edition = "2021" + +[dependencies] +defmt = "0.3.8" +embassy-executor = { git = "https://github.com/embassy-rs/embassy", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", features = ["unstable-pac"] } +embassy-sync = { git = "https://github.com/embassy-rs/embassy", features = ["defmt"] } +embassy-time = { git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } diff --git a/controller/src/blinker.rs b/support/src/blinker.rs similarity index 100% rename from controller/src/blinker.rs rename to support/src/blinker.rs diff --git a/common/src/lib.rs b/support/src/lib.rs similarity index 73% rename from common/src/lib.rs rename to support/src/lib.rs index 5a145a9d0353be065678eb372df3066ab8761549..1ab4f8bd46254430f891875d26bb45b2494bdf50 100644 --- a/common/src/lib.rs +++ b/support/src/lib.rs @@ -2,6 +2,9 @@ use embassy_stm32::pac; +pub mod blinker; +pub mod power; + pub fn mcu_kind() -> (&'static str, &'static str) { let dbgmcu = pac::DBGMCU.idcode().read(); match (dbgmcu.dev_id(), dbgmcu.rev_id()) { @@ -46,3 +49,25 @@ pub fn identity() -> Option<(u32, u32, &'static str)> { pub fn device_id() -> &'static [u8; 8] { unsafe { &*(0x1fff_f7e8 as *const [u8; 8]) } } + +pub fn identify() { + let (density, rev) = mcu_kind(); + let flash_size = flash_size(); + defmt::info!( + "Device type: {}, revision: {} – flash size: {}kB", + density, + rev, + flash_size + ); + + if let Some((identity_code, continuation_code, device)) = identity() { + defmt::info!( + "device = {} (identity code = {:#04x}, continuation code = {:#04x})", + device, + identity_code, + continuation_code + ); + } else { + defmt::info!("no identity and continuation codes"); + } +} diff --git a/controller/src/power.rs b/support/src/power.rs similarity index 100% rename from controller/src/power.rs rename to support/src/power.rs