Skip to content

Commit 66b214f

Browse files
authored
Merge pull request #61 from rursprung/dependency-updates
update dependencies (primary goal: `defmt` v1.0) & use `defmt` again in lib
2 parents 061a69a + 0d014af commit 66b214f

File tree

7 files changed

+77
-53
lines changed

7 files changed

+77
-53
lines changed

.github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
rust: [1.81.0, stable]
17-
features: ['']
17+
features: ['', '--all-features']
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v4

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
<!-- next-header -->
88
## [Unreleased] - ReleaseDate
99

10+
### Added
11+
12+
* Re-introduced usage of `defmt` (the dependency was still present, only its usage and the `defmt-03` feature were
13+
removed before the previous release)
14+
15+
### Changed
16+
17+
* Updated to `defmt` 1.0 (non-breaking change, backwards compatible with 0.3 through semver trick)
18+
1019
## [1.0.0] - 2024-09-23
1120
### Added
1221

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ license = "MIT OR Apache-2.0"
1212
authors = ["Ralph Ursprung <[email protected]>", "ripytide <[email protected]>"]
1313

1414
[features]
15+
defmt = ["dep:defmt", "embedded-hal/defmt-03"]
1516

1617
[dependencies]
1718
embedded-hal = "1.0"
1819

19-
defmt = { version = "0.3", optional = true }
20+
defmt = { version = "1.0", optional = true }
2021

2122
[dev-dependencies]
2223
embedded-hal-mock = { version = "0.11", default-features = false, features = ["eh1"] }

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See the documentation for usage examples.
2020
* You plan on using a single motor with the standby feature: use `Motor` and control the standby pin manually
2121
* You plan on using a single motor without the standby feature: use `Motor`
2222

23+
## Optional features
24+
* `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.
25+
2326
## Examples
2427
A simple example for the STM32F4 microcontrollers is [available](examples/stm32f4-single-motor-example/README.md).
2528

examples/stm32f4-single-motor-example/Cargo.lock

+48-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/stm32f4-single-motor-example/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ license = "MIT OR Apache-2.0"
77
[dependencies]
88
cortex-m = { version = "0.7", features = ["critical-section-single-core"]}
99
cortex-m-rtic = "1.1.4"
10-
panic-probe = { version = "0.3", features = ["print-defmt"] }
10+
panic-probe = { version = "1.0", features = ["print-defmt"] }
1111

1212
stm32f4xx-hal = { version = "0.22", features = ["stm32f401", "rtic1"] }
1313

14-
defmt = "0.3.10"
15-
defmt-rtt = "0.4"
14+
defmt = "1.0"
15+
defmt-rtt = "1.0"
1616

1717
# use `tb6612fng = "0.1"` in reality; path used here to ensure that the example always compiles against the latest master
1818
tb6612fng = { path = "../.." }

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
//! * You plan on using both motors without the standby feature: use two separate [`Motor`]s
1010
//! * You plan on using a single motor with the standby feature: use [`Motor`] and control the standby pin manually
1111
//! * You plan on using a single motor without the standby feature: use [`Motor`]
12+
//!
13+
//! ## Optional features
14+
//! * `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.
1215
1316
#![forbid(unsafe_code)]
1417
#![deny(warnings)]
@@ -24,6 +27,7 @@ use embedded_hal::pwm::SetDutyCycle;
2427

2528
/// Defines errors which can happen when calling [`Motor::drive()`].
2629
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
30+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2731
pub enum MotorError<IN1Error, IN2Error, PWMError> {
2832
/// An invalid speed has been defined. The speed must be given as a percentage value between 0 and 100 to be valid.
2933
InvalidSpeed,
@@ -68,6 +72,7 @@ impl<
6872

6973
/// Defines errors which can happen when calling [`Tb6612fng::new()`].
7074
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
75+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7176
pub enum Tb6612fngError<STBYError> {
7277
/// An error in setting the initial output of the standby pin
7378
Standby(STBYError),
@@ -93,6 +98,7 @@ impl<STBYError: Debug + Error + 'static> Error for Tb6612fngError<STBYError> {
9398

9499
/// Defines the possible drive commands.
95100
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
101+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
96102
pub enum DriveCommand {
97103
/// Drive forward with the defined speed (in percentage)
98104
Forward(u8),
@@ -109,6 +115,7 @@ pub enum DriveCommand {
109115
/// Use the [`Motor`] struct directly if you only have one motor.
110116
/// See the crate-level comment for further details on when to use what.
111117
#[derive(Debug)]
118+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
112119
pub struct Tb6612fng<MAIN1, MAIN2, MAPWM, MBIN1, MBIN2, MBPWM, STBY> {
113120
/// The first motor, labelled as 'A' on the chip
114121
pub motor_a: Motor<MAIN1, MAIN2, MAPWM>,
@@ -245,6 +252,7 @@ where
245252
/// This is unaware of the standby pin. If you plan on using both motors and the standby feature then use the [`Tb6612fng`] struct instead.
246253
/// See the crate-level comment for further details on when to use what.
247254
#[derive(Debug)]
255+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
248256
pub struct Motor<IN1, IN2, PWM> {
249257
in1: IN1,
250258
in2: IN2,
@@ -350,6 +358,9 @@ where
350358
}
351359
}
352360

361+
#[cfg(feature = "defmt")]
362+
defmt::trace!("driving: {}", drive_command);
363+
353364
self.pwm
354365
.set_duty_cycle_percent(speed)
355366
.map_err(MotorError::PwmError)?;

0 commit comments

Comments
 (0)