From 3883682dcea1af68e10633220f9de074769ebcc0 Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Tue, 8 Apr 2025 09:36:59 +0200 Subject: [PATCH 1/4] update to `defmt` 1.0 `defmt` released v1.0 and used the semver trick (releasing v0.3.100) to make updating to it non-breaking. --- CHANGELOG.md | 3 +++ Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7294d..5e1f2a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Changed + +* Updated to `defmt` 1.0 (non-breaking change, backwards compatible with 0.3 through semver trick) ## [1.0.0] - 2024-09-23 ### Added diff --git a/Cargo.toml b/Cargo.toml index f474c79..65a7cd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ authors = ["Ralph Ursprung ", "ripytide Date: Tue, 8 Apr 2025 09:37:58 +0200 Subject: [PATCH 2/4] example: update to `defmt` v1.0 this was intentionally done in a separate commit to make it clear that the library update is non-breaking. --- .../stm32f4-single-motor-example/Cargo.lock | 20 +++++++++---------- .../stm32f4-single-motor-example/Cargo.toml | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/stm32f4-single-motor-example/Cargo.lock b/examples/stm32f4-single-motor-example/Cargo.lock index c87d962..7ab23ac 100644 --- a/examples/stm32f4-single-motor-example/Cargo.lock +++ b/examples/stm32f4-single-motor-example/Cargo.lock @@ -119,9 +119,9 @@ checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "defmt" -version = "0.3.10" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130" +checksum = "548d977b6da32fa1d1fda2876453da1e7df63ad0304c8b3dae4dbe7b96f39b78" dependencies = [ "bitflags", "defmt-macros", @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "0.4.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6" +checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e" dependencies = [ "defmt-parser", "proc-macro-error2", @@ -142,18 +142,18 @@ dependencies = [ [[package]] name = "defmt-parser" -version = "0.4.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3" +checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ "thiserror", ] [[package]] name = "defmt-rtt" -version = "0.4.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6eca0aae8aa2cf8333200ecbd236274697bc0a394765c858b3d9372eb1abcfa" +checksum = "b2cac3b8a5644a9e02b75085ebad3b6deafdbdbdec04bb25086523828aa4dfd1" dependencies = [ "critical-section", "defmt", @@ -346,9 +346,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "panic-probe" -version = "0.3.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4047d9235d1423d66cc97da7d07eddb54d4f154d6c13805c6d0793956f4f25b0" +checksum = "fd402d00b0fb94c5aee000029204a46884b1262e0c443f166d86d2c0747e1a1a" dependencies = [ "cortex-m", "defmt", diff --git a/examples/stm32f4-single-motor-example/Cargo.toml b/examples/stm32f4-single-motor-example/Cargo.toml index 5ab4f53..093a04a 100644 --- a/examples/stm32f4-single-motor-example/Cargo.toml +++ b/examples/stm32f4-single-motor-example/Cargo.toml @@ -7,12 +7,12 @@ license = "MIT OR Apache-2.0" [dependencies] cortex-m = { version = "0.7", features = ["critical-section-single-core"]} cortex-m-rtic = "1.1.4" -panic-probe = { version = "0.3", features = ["print-defmt"] } +panic-probe = { version = "1.0", features = ["print-defmt"] } stm32f4xx-hal = { version = "0.22", features = ["stm32f401", "rtic1"] } -defmt = "0.3.10" -defmt-rtt = "0.4" +defmt = "1.0" +defmt-rtt = "1.0" # use `tb6612fng = "0.1"` in reality; path used here to ensure that the example always compiles against the latest master tb6612fng = { path = "../.." } From 7c3b229fa7208d6f3b0c8a6ed924902b3db14b1a Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Tue, 8 Apr 2025 09:38:25 +0200 Subject: [PATCH 3/4] example: run `cargo update` --- .../stm32f4-single-motor-example/Cargo.lock | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/examples/stm32f4-single-motor-example/Cargo.lock b/examples/stm32f4-single-motor-example/Cargo.lock index 7ab23ac..c9c3731 100644 --- a/examples/stm32f4-single-motor-example/Cargo.lock +++ b/examples/stm32f4-single-motor-example/Cargo.lock @@ -65,22 +65,22 @@ dependencies = [ [[package]] name = "cortex-m-rt" -version = "0.7.3" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee84e813d593101b1723e13ec38b6ab6abbdbaaa4546553f5395ed274079ddb1" +checksum = "801d4dec46b34c299ccf6b036717ae0fce602faa4f4fe816d9013b9a7c9f5ba6" dependencies = [ "cortex-m-rt-macros", ] [[package]] name = "cortex-m-rt-macros" -version = "0.7.0" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f6f3e36f203cfedbc78b357fb28730aa2c6dc1ab060ee5c2405e843988d3c7" +checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.100", ] [[package]] @@ -137,7 +137,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -161,18 +161,18 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.11" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" dependencies = [ "powerfmt", ] [[package]] name = "document-features" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6969eaabd2421f8a2775cfd2471a2b634372b4a25d41e3bd647b79912850a0" +checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" dependencies = [ "litrs", ] @@ -226,22 +226,22 @@ checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032" [[package]] name = "enumflags2" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d232db7f5956f3f14313dc2f87985c58bd2c695ce124c8cdd984e08e15ac133d" +checksum = "ba2f4b465f5318854c6f8dd686ede6c0a9dc67d4b1ac241cf0eb51521a309147" dependencies = [ "enumflags2_derive", ] [[package]] name = "enumflags2_derive" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" +checksum = "fc4caf64a58d7a6d65ab00639b046ff54399a39f5f2554728895ace4b297cd79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] @@ -356,9 +356,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.9.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" [[package]] name = "powerfmt" @@ -409,23 +409,23 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -475,7 +475,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "semver 1.0.23", + "semver 1.0.26", ] [[package]] @@ -495,9 +495,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "semver-parser" @@ -588,9 +588,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.90" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2", "quote", @@ -617,29 +617,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.100", ] [[package]] name = "time" -version = "0.3.36" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "num-conv", @@ -649,15 +649,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "vcell" From 0d014af9fde931f1ae841684da8400c8d931838a Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Tue, 8 Apr 2025 10:09:09 +0200 Subject: [PATCH 4/4] re-introduce usage of `defmt` i had forgotten to completely remove the dependency in the now reverted commit, thus the optional dependency still created a feature which consuming crates could enable. removing it would be a breaking change. this leaves two options: * remove the `defmt` _dependency_ and add a dummy _feature_ of the same name, issuing a compile warning if it is enabled, eventually removing it in v2.0 if or when that will ever be released * accept the fact that we already have the optional dependency and thus the feature and make use of it this contains a few changes to the reverted commit: * the feature is now called `defmt` rather than `defmt-03` (as that's the name of the implicit feature for the optional dependency) * the `debug` output in `drive` is kept but downgraded to `trace` and slightly reworded (the speed is already present in the command) * the `cfg`-guarded `use` is removed to make the code cleaner This reverts commit d9da807701c366dac882c9c4e1c6ae3f3f0cf353. (with minor adaptations) --- .github/workflows/CI.yml | 2 +- CHANGELOG.md | 6 ++++++ Cargo.toml | 1 + README.md | 3 +++ src/lib.rs | 11 +++++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0635a38..0c677a4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: rust: [1.81.0, stable] - features: [''] + features: ['', '--all-features'] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e1f2a5..5595fb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate + +### Added + +* Re-introduced usage of `defmt` (the dependency was still present, only its usage and the `defmt-03` feature were + removed before the previous release) + ### Changed * Updated to `defmt` 1.0 (non-breaking change, backwards compatible with 0.3 through semver trick) diff --git a/Cargo.toml b/Cargo.toml index 65a7cd3..3d3095d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ license = "MIT OR Apache-2.0" authors = ["Ralph Ursprung ", "ripytide "] [features] +defmt = ["dep:defmt", "embedded-hal/defmt-03"] [dependencies] embedded-hal = "1.0" diff --git a/README.md b/README.md index 08a8acd..a68ddd3 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ See the documentation for usage examples. * You plan on using a single motor with the standby feature: use `Motor` and control the standby pin manually * You plan on using a single motor without the standby feature: use `Motor` +## Optional features +* `defmt`: you can enable this feature to get a `defmt::Format` implementation for all structs & enums in this crate and a `defmt::trace` call for every speed change. + ## Examples A simple example for the STM32F4 microcontrollers is [available](examples/stm32f4-single-motor-example/README.md). diff --git a/src/lib.rs b/src/lib.rs index 4097271..587823b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,9 @@ //! * You plan on using both motors without the standby feature: use two separate [`Motor`]s //! * You plan on using a single motor with the standby feature: use [`Motor`] and control the standby pin manually //! * You plan on using a single motor without the standby feature: use [`Motor`] +//! +//! ## Optional features +//! * `defmt`: you can enable this feature to get a `defmt::Format` implementation for all structs & enums in this crate and a `defmt::trace` call for every speed change. #![forbid(unsafe_code)] #![deny(warnings)] @@ -24,6 +27,7 @@ use embedded_hal::pwm::SetDutyCycle; /// Defines errors which can happen when calling [`Motor::drive()`]. #[derive(PartialEq, Eq, Debug, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum MotorError { /// An invalid speed has been defined. The speed must be given as a percentage value between 0 and 100 to be valid. InvalidSpeed, @@ -68,6 +72,7 @@ impl< /// Defines errors which can happen when calling [`Tb6612fng::new()`]. #[derive(PartialEq, Eq, Debug, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Tb6612fngError { /// An error in setting the initial output of the standby pin Standby(STBYError), @@ -93,6 +98,7 @@ impl Error for Tb6612fngError { /// Defines the possible drive commands. #[derive(PartialEq, Eq, Debug, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum DriveCommand { /// Drive forward with the defined speed (in percentage) Forward(u8), @@ -109,6 +115,7 @@ pub enum DriveCommand { /// Use the [`Motor`] struct directly if you only have one motor. /// See the crate-level comment for further details on when to use what. #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Tb6612fng { /// The first motor, labelled as 'A' on the chip pub motor_a: Motor, @@ -245,6 +252,7 @@ where /// This is unaware of the standby pin. If you plan on using both motors and the standby feature then use the [`Tb6612fng`] struct instead. /// See the crate-level comment for further details on when to use what. #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Motor { in1: IN1, in2: IN2, @@ -350,6 +358,9 @@ where } } + #[cfg(feature = "defmt")] + defmt::trace!("driving: {}", drive_command); + self.pwm .set_duty_cycle_percent(speed) .map_err(MotorError::PwmError)?;