Skip to content

Commit 8bb1990

Browse files
committed
add support for embedded-hal=1.0.0-alpha.10 - WIP
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
1 parent 7fdadeb commit 8bb1990

File tree

9 files changed

+171
-50
lines changed

9 files changed

+171
-50
lines changed

.github/workflows/CI.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
rust: [1.62.0, stable]
14-
features: ['', '--all-features']
14+
features: ['', '--features defmt', '--no-default-features --features hal_v1', '--no-default-features --features defmt,hal_v1']
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v3
@@ -34,6 +34,10 @@ jobs:
3434
run: cargo audit
3535

3636
stm32f4-single-motor-example:
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
features: ['', '--no-default-features --features hal_v1']
3741
runs-on: ubuntu-latest
3842
steps:
3943
- uses: actions/checkout@v3
@@ -45,17 +49,17 @@ jobs:
4549
- name: Install flip-link
4650
run: cargo install flip-link
4751
- name: build
48-
run: cargo build
52+
run: cargo build ${{ matrix.features }}
4953
working-directory: examples/stm32f4-single-motor-example
5054
- name: check
51-
run: cargo check
55+
run: cargo check ${{ matrix.features }}
5256
working-directory: examples/stm32f4-single-motor-example
5357
# no tests available for now => no test step as it'd fail otherwise
5458
- name: check formatting
5559
run: cargo fmt --all -- --check
5660
working-directory: examples/stm32f4-single-motor-example
5761
- name: clippy
58-
run: cargo clippy
62+
run: cargo clippy ${{ matrix.features }}
5963
working-directory: examples/stm32f4-single-motor-example
6064
- name: audit
6165
run: cargo audit

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
<!-- next-header -->
88
## [Unreleased] - ReleaseDate
9+
### Added
10+
* 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.
11+
912
### Changed
1013
* 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.
1114

Cargo.toml

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ keywords = ["tb6612fng", "driver", "motor", "controller", "embedded-hal-driver"]
1111
license = "MIT OR Apache-2.0"
1212

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

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

1819
[dev-dependencies]
19-
embedded-hal-mock = "0.9"
20+
embedded-hal-mock = { version = "0.9" }
21+
embedded-hal-mock-one = { package = "embedded-hal-mock", git = "https://github.com/rursprung/embedded-hal-mock.git", branch = "add-SetDutyCycle-to-1-alpha-a11" }
22+
23+
[features]
24+
default = ["hal_v02"]
25+
hal_v02 = ["dep:embedded-hal"]
26+
hal_v1 = ["dep:embedded-hal-one"]

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ 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+
## `embedded-hal`: `v0.2` vs. `v1.0.0-alpha.*`
24+
This crate can be used both with `embedded-hal` `v0.2` versions as well as `v1.0.0` pre-releases.
25+
By default, the `v0.2` support is being compiled, but you can switch to the `v1.0.0` pre-release by disabling the
26+
default features and instead enabling the optional `hal-v1`.
27+
2328
## Optional features
2429
* `defmt`: you can enable the [`defmt`](https://defmt.ferrous-systems.com/) feature to get a `defmt::debug!` call for every speed change.
2530

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

+15-6
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

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66

7+
[features]
8+
default = [ "hal_v02" ]
9+
hal_v02 = [ "tb6612fng/hal_v02" ]
10+
hal_v1 = [ "tb6612fng/hal_v1" ]
11+
712
[dependencies]
813
cortex-m = { version = "0.7", features = ["critical-section-single-core"]}
914
cortex-m-rtic = "1.1.4"
1015
panic-probe = { version = "0.3", features = ["print-defmt"] }
1116

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

1420
defmt = "0.3.5"
1521
defmt-rtt = "0.4"
1622

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

2026
[profile.release]
2127
codegen-units = 1

examples/stm32f4-single-motor-example/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ to stop (coast, first press), actively brake (second press) and drive again (thi
2929
1. Connect the board via USB
3030
2. Run `cargo run` (the correct chip & target is already defined in `Cargo.toml` and `.cargo/config`)
3131
3. Enjoy your running program :)
32+
33+
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`.

examples/stm32f4-single-motor-example/src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ mod app {
5151
.TIM2
5252
.pwm_hz(Channel3::new(gpiob.pb10), 100.kHz(), &clocks)
5353
.split();
54+
#[cfg(feature = "hal_v1")]
55+
let mut motor_pwm = motor_pwm;
56+
#[cfg(feature = "hal_v1")]
57+
motor_pwm.enable();
5458
let mut motor = Motor::new(motor_in1, motor_in2, motor_pwm);
5559
motor.drive_backwards(0).expect("");
5660

0 commit comments

Comments
 (0)