Skip to content

Commit

Permalink
Async client (FactbirdHQ#142)
Browse files Browse the repository at this point in the history
* Move blocking parts to blocking module

* Fix compile error in blocking client

* Use Frame type using bincode in favor of custom Encoded

* Add async client

* Move buffers to shared

* Async should not be a default feature

* Fix compile error

* Formatting

* Let Ingress be shared between blocking and async

* Add some docs to async client trait

* Forward defmt feature to embedded-io

* Remove old async client trait (now moved to mod)

* Let ingress expose its buffer

* Remove overflow error

* Add async ingress advance

* Migrate all timing/delay/timeout handling to embassy-time

* Run GH actions tests with std feature flag, to enable time-driver

* Add missing start_cooldown_timer to blocking client

* Remove unused embedded-hal dependency

* Add compile checks on buffer capacities

* Remove embedded-time

* Let tests run with cargo --test

* Revert "Run GH actions tests with std feature flag, to enable time-driver"

This reverts commit b52355c.

* Formatting

* Add example test on why we need double buffer capacity

* Fix ingress regression for processing available bytes in buffer

* Add write() convenience function to AtatIngress

* Fix digest buffer slice

* Let timeouts in config be Duration

* Let error response be a warning - it may be deliberate

* Add std example based on tokio

* Move examples to seperate workspace member, and add embassy async example

* Fix clippy recommendations

* Use nightly toolchain in most of CI

* Add thumbv6 feature in CI

* Update readme with async feature and new examples

---------

Co-authored-by: Mathias <mk@blackbird.online>
  • Loading branch information
rmja and MathiasKoch authored Mar 25, 2023
1 parent ec094e1 commit 70283be
Show file tree
Hide file tree
Showing 36 changed files with 1,725 additions and 1,846 deletions.
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ rustflags = [
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
"-C", "link-arg=-nmagic",
]

[target.thumbv6m-none-eabi]
runner = "probe-run --chip RP2040"
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",

# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
"-C", "link-arg=-nmagic",
]
27 changes: 12 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
toolchain: nightly
override: true
components: clippy

Expand All @@ -92,7 +92,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
target: ["x86_64-unknown-linux-gnu", "thumbv7em-none-eabihf"]
target: ["x86_64-unknown-linux-gnu", "thumbv6m-none-eabi"]
features:
[
"",
Expand All @@ -107,11 +107,8 @@ jobs:
- target: "x86_64-unknown-linux-gnu"
features: "derive, log"
std: ", std"
- target: "x86_64-unknown-linux-gnu"
features: "derive, defmt"
std: ", std"
- target: "thumbv7em-none-eabihf"
examples: "--examples"
- target: "thumbv6m-none-eabi"
thumb: ", thumbv6"
steps:
- name: Checkout source code
uses: actions/checkout@v2
Expand All @@ -120,15 +117,15 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: thumbv7em-none-eabihf
toolchain: nightly
target: thumbv6m-none-eabi
override: true

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all --target '${{ matrix.target }}' --features '${{ matrix.features }}${{ matrix.std }}' ${{ matrix.examples }}
args: --all --target '${{ matrix.target }}' --features '${{ matrix.features }}${{ matrix.thumb }}${{ matrix.std }}'

test:
name: Test
Expand All @@ -140,14 +137,14 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: thumbv7em-none-eabihf
toolchain: nightly
target: thumbv6m-none-eabi
override: true
- name: Library tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all
args: --all --features std

grcov:
name: Coverage
Expand All @@ -161,7 +158,7 @@ jobs:
with:
profile: minimal
toolchain: nightly
target: thumbv7em-none-eabihf
target: thumbv6m-none-eabi
override: true

- name: Install grcov
Expand All @@ -178,7 +175,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --lib --no-fail-fast
args: --lib --no-fail-fast --features std
env:
CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=unwind -Zpanic_abort_tests"
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// "can't find crate for `test`" when the default compilation target is a no_std target
// with these changes RA will call `cargo check --bins` on save
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
"rust-analyzer.cargo.features": ["async", "thumbv6"],
"rust-analyzer.diagnostics.disabled": [
"unresolved-import"
]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["serde_at", "atat_derive", "atat"]
members = ["serde_at", "atat_derive", "atat", "examples"]


# cargo build/run
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

`#![no_std]` crate for parsing AT commands ([Hayes command set](https://en.wikipedia.org/wiki/Hayes_command_set))

A driver support crate for AT-command based serial modules, using the [embedded-hal] traits.

[embedded-hal]: https://crates.io/crates/embedded-hal
A driver support crate for AT-command based serial modules.

## AT Best practices

Expand Down Expand Up @@ -44,14 +42,14 @@ This crate attempts to work from these AT best practices:
## Examples

The crate has examples for usage with [cortex-m-rt] and [cortex-m-rtic] crates.
The crate has examples for usage with [embassy] for `#![no_std]` and [tokio] for `std`.

The samples can be built using `cargo build --example cortex-m-rt --target thumbv7em-none-eabihf` and `cargo build --example rtic --target thumbv7em-none-eabihf`.
The samples can be built using `cargo +nightly run --bin embassy --features embedded --target thumbv6m-none-eabi` and `cargo +nightly run --example std-tokio --features std`.

Furthermore I have used the crate to build initial WIP drivers for uBlox cellular modules ([ublox-cellular-rs]) and uBlox short-range modules ([ublox-short-range-rs])
Furthermore the crate has been used to build initial drivers for U-Blox cellular modules ([ublox-cellular-rs]) and U-Blox short-range modules ([ublox-short-range-rs])

[cortex-m-rt]: https://crates.io/crates/cortex-m-rt
[cortex-m-rtic]: https://crates.io/crates/cortex-m-rtic
[embassy]: https://crates.io/crates/embassy-executor
[tokio]: https://crates.io/crates/tokio
[ublox-short-range-rs]: https://github.com/BlackbirdHQ/ublox-short-range-rs
[ublox-cellular-rs]: https://github.com/BlackbirdHQ/ublox-cellular-rs

Expand Down Expand Up @@ -100,10 +98,11 @@ The following dependent crates provide platform-agnostic device drivers built on
- `log`: Disabled by default. Enable log statements on various log levels to aid debugging. Powered by `log`.
- `defmt`: Disabled by default. Enable defmt log statements on various log levels to aid debugging. Powered by `defmt`.
- `custom-error-messages`: Disabled by default. Allows errors to contain custom error messages up to 64 characters, parsed by `AtDigest::custom_error`.
- `async`: Enable the async interfaces on both `Ingress` and `Client`.

## Chat / Getting Help

If you have questions on the development of AT-AT or want to write a driver
If you have questions on the development of ATAT or want to write a driver
based on it, feel free to join our matrix room at `#atat:matrix.org`!

## License
Expand Down
46 changes: 19 additions & 27 deletions atat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ maintenance = { status = "actively-developed" }
[lib]
name = "atat"

[[example]]
name = "rtic"
required-features = ["defmt"]

[[example]]
name = "cortex-m-rt"
required-features = ["defmt"]

[dependencies]
embedded-hal-nb = { version = "=1.0.0-alpha.1" }
fugit = "0.3.3"
fugit-timer = "0.1.2"
bincode = { version = "2.0.0-rc.2", default-features = false, features = [
"derive",
] }
embedded-io = "0.4"
futures = { version = "0.3", default-features = false, optional = true }
embassy-time = "0.1.0"
heapless = { version = "^0.7", features = ["serde"] }
bbqueue = "0.5"
bbqueue = { git = "https://github.com/jamesmunns/bbqueue", rev = "refs/pull/95/head" }
serde_at = { path = "../serde_at", version = "^0.18.0", optional = true }
atat_derive = { path = "../atat_derive", version = "^0.18.0", optional = true }
serde_bytes = { version = "0.11.5", default-features = false, optional = true }
Expand All @@ -41,24 +36,21 @@ nom = { version = "^7.1", default-features = false }
log = { version = "^0.4", default-features = false, optional = true }
defmt = { version = "^0.3", optional = true }

[dev-dependencies]
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.1"
cortex-m-rtic = "1.0.0"
defmt-rtt = "0.3.1"
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
dwt-systick-monotonic = "1.0.0"
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", rev = "99284b8", features = [
"stm32l475vg",
"unstable-traits",
"unstable-pac",
] }

[features]
default = ["derive", "bytes"]
defmt = ["dep:defmt", "embedded-io/defmt"]
derive = ["atat_derive", "serde_at"]
bytes = ["heapless-bytes", "serde_bytes"]
custom-error-messages = []

bytes = ["heapless-bytes", "serde_bytes"]
async = ["embedded-io/async", "futures"]

thumbv6 = ["bbqueue/thumbv6"]

std = ["serde_at/std", "nom/std"]
std = [
"serde_at/std",
"nom/std",
"embassy-time/std",
"embedded-io/std",
"embedded-io/tokio",
]
66 changes: 0 additions & 66 deletions atat/examples/common/timer.rs

This file was deleted.

Loading

0 comments on commit 70283be

Please sign in to comment.