Skip to content

update dependencies (primary goal: defmt v1.0) & use defmt again in lib #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- next-header -->
## [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)

## [1.0.0] - 2024-09-23
### Added

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ license = "MIT OR Apache-2.0"
authors = ["Ralph Ursprung <[email protected]>", "ripytide <[email protected]>"]

[features]
defmt = ["dep:defmt", "embedded-hal/defmt-03"]

[dependencies]
embedded-hal = "1.0"

defmt = { version = "0.3", optional = true }
defmt = { version = "1.0", optional = true }

[dev-dependencies]
embedded-hal-mock = { version = "0.11", default-features = false, features = ["eh1"] }
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
96 changes: 48 additions & 48 deletions examples/stm32f4-single-motor-example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/stm32f4-single-motor-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../.." }
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<IN1Error, IN2Error, PWMError> {
/// An invalid speed has been defined. The speed must be given as a percentage value between 0 and 100 to be valid.
InvalidSpeed,
Expand Down Expand Up @@ -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<STBYError> {
/// An error in setting the initial output of the standby pin
Standby(STBYError),
Expand All @@ -93,6 +98,7 @@ impl<STBYError: Debug + Error + 'static> Error for Tb6612fngError<STBYError> {

/// 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),
Expand All @@ -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<MAIN1, MAIN2, MAPWM, MBIN1, MBIN2, MBPWM, STBY> {
/// The first motor, labelled as 'A' on the chip
pub motor_a: Motor<MAIN1, MAIN2, MAPWM>,
Expand Down Expand Up @@ -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, IN2, PWM> {
in1: IN1,
in2: IN2,
Expand Down Expand Up @@ -350,6 +358,9 @@ where
}
}

#[cfg(feature = "defmt")]
defmt::trace!("driving: {}", drive_command);

self.pwm
.set_duty_cycle_percent(speed)
.map_err(MotorError::PwmError)?;
Expand Down