Skip to content
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

update deps, use fugit_timer::Timer instead of Clocks #113

Merged
merged 1 commit into from
Jan 20, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
"",
"derive",
"derive, log",
"derive, defmt-default",
"derive, defmt",
]
include:
- target: "x86_64-unknown-linux-gnu"
Expand All @@ -108,7 +108,7 @@ jobs:
features: "derive, log"
std: ", std"
- target: "x86_64-unknown-linux-gnu"
features: "derive, defmt-default"
features: "derive, defmt"
std: ", std"
- target: "thumbv7em-none-eabihf"
examples: "--examples"
Expand Down
13 changes: 4 additions & 9 deletions atat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ name = "atat"
maintenance = { status = "actively-developed" }

[dependencies]
embedded-hal = { version = "=1.0.0-alpha.4" }
fugit = "0.3"
embedded-hal = { version = "=1.0.0-alpha.6" }
fugit = "0.3.3"
fugit-timer = "0.1.2"
nb = "^1"
heapless = { version = "^0.7.0", features = ["serde"] }
serde_at = { path = "../serde_at", version = "^0.14.0", optional = true }
Expand All @@ -29,7 +30,7 @@ heapless-bytes = { version = "0.3.0", optional = true }
bbqueue = "0.5"

log = { version = "^0.4", default-features = false, optional = true }
defmt = { version = "^0.2", optional = true }
defmt = { version = "^0.3", optional = true }

[target.thumbv7em-none-eabihf.dev-dependencies]
cortex-m = "0.7.1"
Expand All @@ -49,9 +50,3 @@ bytes = ["heapless-bytes", "serde_bytes"]

std = ["serde_at/std"]

defmt-default = ["defmt"]
defmt-trace = ["defmt"]
defmt-debug = ["defmt"]
defmt-info = ["defmt"]
defmt-warn = ["defmt"]
defmt-error = ["defmt"]
6 changes: 5 additions & 1 deletion atat/examples/cortex-m-rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl<TIM, const TIMER_HZ: u32> Clock<TIMER_HZ> for AtClock<TIM, TIMER_HZ> {
Ok(())
}

fn cancel(&mut self) -> Result<(), Self::Error> {
Ok(())
}

fn wait(&mut self) -> nb::Result<(), Self::Error> {
Ok(())
}
Expand Down Expand Up @@ -138,7 +142,7 @@ fn TIM7() {
fn USART2() {
let ingress = unsafe { INGRESS.as_mut().unwrap() };
let rx = unsafe { RX.as_mut().unwrap() };
if let Ok(d) = nb::block!(rx.try_read()) {
if let Ok(d) = nb::block!(rx.read()) {
ingress.write(&[d]);
}
}
Expand Down
6 changes: 5 additions & 1 deletion atat/examples/rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ impl<TIM, const TIMER_HZ: u32> Clock<TIMER_HZ> for AtClock<TIM, TIMER_HZ> {
Ok(())
}

fn cancel(&mut self) -> Result<(), Self::Error> {
Ok(())
}

fn wait(&mut self) -> nb::Result<(), Self::Error> {
Ok(())
}
Expand Down Expand Up @@ -132,7 +136,7 @@ const APP: () = {
#[task(binds = USART2, priority = 4, resources = [ingress, rx])]
fn serial_irq(ctx: serial_irq::Context) {
let rx = ctx.resources.rx;
if let Ok(d) = nb::block!(rx.try_read()) {
if let Ok(d) = nb::block!(rx.read()) {
ctx.resources.ingress.write(&[d]);
}
}
Expand Down
15 changes: 7 additions & 8 deletions atat/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct ClientBuilder<
const RES_CAPACITY: usize,
const URC_CAPACITY: usize,
> where
Tx: embedded_hal::serial::Write<u8>,
CLK: super::Clock<TIMER_HZ>,
Tx: embedded_hal::serial::nb::Write<u8>,
CLK: fugit_timer::Timer<TIMER_HZ>,
U: UrcMatcher,
D: Digester,
{
Expand Down Expand Up @@ -66,17 +66,16 @@ impl<
URC_CAPACITY,
>
where
Tx: embedded_hal::serial::Write<u8>,
T: super::Clock<TIMER_HZ>,
Tx: embedded_hal::serial::nb::Write<u8>,
T: fugit_timer::Timer<TIMER_HZ>,
{
/// Create a builder for new Atat client instance.
///
/// The `serial_tx` type must implement the `embedded_hal`
/// [`serial::Write<u8>`][serialwrite] trait while the timer must implement
/// the [`Clock`][clock] trait.
/// the [`fugit_timer::Timer`] trait.
///
/// [serialwrite]: ../embedded_hal/serial/trait.Write.html
/// [clock]: trait.Clock.html
pub fn new(serial_tx: Tx, timer: T, config: Config) -> Self {
Self {
serial_tx,
Expand All @@ -99,8 +98,8 @@ impl<
const URC_CAPACITY: usize,
> ClientBuilder<Tx, CLK, U, D, TIMER_HZ, BUF_LEN, RES_CAPACITY, URC_CAPACITY>
where
Tx: embedded_hal::serial::Write<u8>,
CLK: super::Clock<TIMER_HZ>,
Tx: embedded_hal::serial::nb::Write<u8>,
CLK: fugit_timer::Timer<TIMER_HZ>,
U: UrcMatcher,
D: Digester,
{
Expand Down
33 changes: 20 additions & 13 deletions atat/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub struct Client<
const RES_CAPACITY: usize,
const URC_CAPACITY: usize,
> where
Tx: serial::Write<u8>,
CLK: super::Clock<TIMER_HZ>,
Tx: serial::nb::Write<u8>,
CLK: fugit_timer::Timer<TIMER_HZ>,
{
/// Serial writer
tx: Tx,
Expand All @@ -59,8 +59,8 @@ pub struct Client<
impl<Tx, CLK, const TIMER_HZ: u32, const RES_CAPACITY: usize, const URC_CAPACITY: usize>
Client<Tx, CLK, TIMER_HZ, RES_CAPACITY, URC_CAPACITY>
where
Tx: serial::Write<u8>,
CLK: super::Clock<TIMER_HZ>,
Tx: serial::nb::Write<u8>,
CLK: fugit_timer::Timer<TIMER_HZ>,
{
pub fn new(
tx: Tx,
Expand All @@ -85,8 +85,8 @@ where
impl<Tx, CLK, const TIMER_HZ: u32, const RES_CAPACITY: usize, const URC_CAPACITY: usize> AtatClient
for Client<Tx, CLK, TIMER_HZ, RES_CAPACITY, URC_CAPACITY>
where
Tx: serial::Write<u8>,
CLK: super::Clock<TIMER_HZ>,
Tx: serial::nb::Write<u8>,
CLK: fugit_timer::Timer<TIMER_HZ>,
{
fn send<A: AtatCmd<LEN>, const LEN: usize>(
&mut self,
Expand Down Expand Up @@ -114,9 +114,9 @@ where
}

for c in cmd_buf {
nb::block!(self.tx.try_write(c)).map_err(|_e| Error::Write)?;
nb::block!(self.tx.write(c)).map_err(|_e| Error::Write)?;
}
nb::block!(self.tx.try_flush()).map_err(|_e| Error::Write)?;
nb::block!(self.tx.flush()).map_err(|_e| Error::Write)?;
self.state = ClientState::AwaitingResponse;
}

Expand Down Expand Up @@ -255,6 +255,11 @@ mod test {
Ok(())
}

/// Stop timer
fn cancel(&mut self) -> Result<(), Self::Error> {
Ok(())
}

/// Wait until countdown `duration` set with the `fn start` has expired
fn wait(&mut self) -> nb::Result<(), Self::Error> {
Ok(())
Expand All @@ -271,14 +276,16 @@ mod test {
}
}

impl serial::Write<u8> for TxMock {
type Error = ();
impl serial::nb::Write<u8> for TxMock {
type Error = serial::ErrorKind;

fn try_write(&mut self, c: u8) -> nb::Result<(), Self::Error> {
self.s.push(c as char).map_err(nb::Error::Other)
fn write(&mut self, c: u8) -> nb::Result<(), Self::Error> {
self.s
.push(c as char)
.map_err(|_| nb::Error::Other(serial::ErrorKind::Other))
}

fn try_flush(&mut self) -> nb::Result<(), Self::Error> {
fn flush(&mut self) -> nb::Result<(), Self::Error> {
Ok(())
}
}
Expand Down
32 changes: 1 addition & 31 deletions atat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,6 @@
//!
//! - **`derive`** *(enabled by default)* - Re-exports [`atat_derive`] to allow
//! deriving `Atat__` traits.
//! - **`defmt-default`** *(disabled by default)* - Enable log statements at
//! INFO, or TRACE, level and up, to aid debugging. Powered by `defmt`.
//! - **`defmt-trace`** *(disabled by default)* - Enable log statements at TRACE
//! level and up, to aid debugging. Powered by `defmt`.
//! - **`defmt-debug`** *(disabled by default)* - Enable log statements at DEBUG
//! level and up, to aid debugging. Powered by `defmt`.
//! - **`defmt-info`** *(disabled by default)* - Enable log statements at INFO
//! level and up, to aid debugging. Powered by `defmt`.
//! - **`defmt-warn`** *(disabled by default)* - Enable log statements at WARN
//! level and up, to aid debugging. Powered by `defmt`.
//! - **`defmt-error`** *(disabled by default)* - Enable log statements at ERROR
//! level and up, to aid debugging. Powered by `defmt`.

// #![deny(warnings)]
#![allow(clippy::multiple_crate_versions)]
Expand Down Expand Up @@ -274,25 +262,7 @@ pub use queues::{ComQueue, Queues};
pub use traits::{AtatClient, AtatCmd, AtatResp, AtatUrc};
pub use urc_matcher::{DefaultUrcMatcher, UrcMatcher, UrcMatcherResult};

/// For timing `atat` uses [fugit](https://lib.rs/crates/fugit) crate which only provides `Duration` and `Instant` types.
/// It does not provide any clock or timer traits.
/// Therefore `atat` has its own `Clock` trait that provides all timing capabilities that are needed for the library.
/// User must implement this trait for the timer by itself.
pub trait Clock<const TIMER_HZ: u32> {
/// An error that might happen during waiting
type Error;

/// Return current time `Instant`
fn now(&mut self) -> fugit::TimerInstantU32<TIMER_HZ>;

/// Start countdown with a `duration`
fn start(&mut self, duration: fugit::TimerDurationU32<TIMER_HZ>) -> Result<(), Self::Error>;

/// Wait until countdown `duration` has expired.
/// Must return `nb::Error::WouldBlock` if countdown `duration` is not yet over.
/// Must return `OK(())` as soon as countdown `duration` has expired.
fn wait(&mut self) -> nb::Result<(), Self::Error>;
}
pub use fugit_timer::Timer as Clock;

/// Commands that can be sent from the client to the ingress manager, for
/// configuration after initial setup. This is also used for stuff like clearing
Expand Down
2 changes: 1 addition & 1 deletion serde_at/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<'a> Deserializer<'a> {

fn parse_at(&mut self) -> Result<Option<()>> {
// If we find a '+', check if it is an AT command identifier, ending in ':'
if let Some(b'+') = self.parse_whitespace() {
if self.parse_whitespace() == Some(b'+') {
let index = self.index;
loop {
match self.peek() {
Expand Down