Skip to content

Commit

Permalink
add support for embedded-hal=1.0.0-alpha.10 - WIP
Browse files Browse the repository at this point in the history
as this version of embedded-hal has added `SetDutyCycle` as the
equivalent / successor of the old `PwmPin` support for it can now be
added here.

open points:
* wait for a release of stm32f4xx-hal which includes the `SetDutyCycle`
  implementation (PR already merged)
* wait for a release of embedded-hal-mock which includes the
  `SetDutyCycle` implementation (PR currently open)

fixes #3
fixes #8
  • Loading branch information
rursprung committed Jul 6, 2023
1 parent 7fdadeb commit 8bb1990
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 50 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
rust: [1.62.0, stable]
features: ['', '--all-features']
features: ['', '--features defmt', '--no-default-features --features hal_v1', '--no-default-features --features defmt,hal_v1']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -34,6 +34,10 @@ jobs:
run: cargo audit

stm32f4-single-motor-example:
strategy:
fail-fast: false
matrix:
features: ['', '--no-default-features --features hal_v1']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -45,17 +49,17 @@ jobs:
- name: Install flip-link
run: cargo install flip-link
- name: build
run: cargo build
run: cargo build ${{ matrix.features }}
working-directory: examples/stm32f4-single-motor-example
- name: check
run: cargo check
run: cargo check ${{ matrix.features }}
working-directory: examples/stm32f4-single-motor-example
# no tests available for now => no test step as it'd fail otherwise
- name: check formatting
run: cargo fmt --all -- --check
working-directory: examples/stm32f4-single-motor-example
- name: clippy
run: cargo clippy
run: cargo clippy ${{ matrix.features }}
working-directory: examples/stm32f4-single-motor-example
- name: audit
run: cargo audit
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Added
* Support for `embedded-hal` version `1.0.0-alpha.10`. To use this you must disable the default features and instead enable the `hal_v1` feature.

### Changed
* Due to dependency updates the MSRV has been updated from 1.60 to 1.62. This should only be relevant if you use the `defmt` feature, but we now only test with 1.62 and not older releases, so it's not guaranteed to work otherwise.

Expand Down
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ keywords = ["tb6612fng", "driver", "motor", "controller", "embedded-hal-driver"]
license = "MIT OR Apache-2.0"

[dependencies]
embedded-hal = "0.2"
embedded-hal = { version = "0.2", optional = true }
embedded-hal-one = { package = "embedded-hal", version = "=1.0.0-alpha.11", optional = true }

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

[dev-dependencies]
embedded-hal-mock = "0.9"
embedded-hal-mock = { version = "0.9" }
embedded-hal-mock-one = { package = "embedded-hal-mock", git = "https://github.com/rursprung/embedded-hal-mock.git", branch = "add-SetDutyCycle-to-1-alpha-a11" }

[features]
default = ["hal_v02"]
hal_v02 = ["dep:embedded-hal"]
hal_v1 = ["dep:embedded-hal-one"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ 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`

## `embedded-hal`: `v0.2` vs. `v1.0.0-alpha.*`
This crate can be used both with `embedded-hal` `v0.2` versions as well as `v1.0.0` pre-releases.
By default, the `v0.2` support is being compiled, but you can switch to the `v1.0.0` pre-release by disabling the
default features and instead enabling the optional `hal-v1`.

## Optional features
* `defmt`: you can enable the [`defmt`](https://defmt.ferrous-systems.com/) feature to get a `defmt::debug!` call for every speed change.

Expand Down
21 changes: 15 additions & 6 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.

10 changes: 8 additions & 2 deletions examples/stm32f4-single-motor-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"

[features]
default = [ "hal_v02" ]
hal_v02 = [ "tb6612fng/hal_v02" ]
hal_v1 = [ "tb6612fng/hal_v1" ]

[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"] }

stm32f4xx-hal = { version = "0.16.1", features = ["stm32f401", "rtic", "rtic-monotonic"] }
# TODO: switch back to release version once it exists
stm32f4xx-hal = { git = "https://github.com/stm32-rs/stm32f4xx-hal.git", rev = "552a9c5", features = ["stm32f401", "rtic", "rtic-monotonic"] }

defmt = "0.3.5"
defmt-rtt = "0.4"

# use `tb6612fng = "0.1"` in reality; path used here to ensure that the example always compiles against the latest master
tb6612fng = { path = "../.." }
tb6612fng = { path = "../..", default-features = false, features = ["defmt"] }

[profile.release]
codegen-units = 1
Expand Down
2 changes: 2 additions & 0 deletions examples/stm32f4-single-motor-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ to stop (coast, first press), actively brake (second press) and drive again (thi
1. Connect the board via USB
2. Run `cargo run` (the correct chip & target is already defined in `Cargo.toml` and `.cargo/config`)
3. Enjoy your running program :)

To instead compile & run this with `embedded-hal` v1.0.0 pre-release support you can build it with `cargo run --no-default-features --features hal_v1`.
4 changes: 4 additions & 0 deletions examples/stm32f4-single-motor-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ mod app {
.TIM2
.pwm_hz(Channel3::new(gpiob.pb10), 100.kHz(), &clocks)
.split();
#[cfg(feature = "hal_v1")]
let mut motor_pwm = motor_pwm;
#[cfg(feature = "hal_v1")]
motor_pwm.enable();
let mut motor = Motor::new(motor_in1, motor_in2, motor_pwm);
motor.drive_backwards(0).expect("");

Expand Down
Loading

0 comments on commit 8bb1990

Please sign in to comment.