diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index f58b6d5..cbdf95b 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -48,9 +48,15 @@ jobs: RUSTFLAGS: -D warnings run: cargo test - - name: Build default features + - name: Build in strict mode with default features run: cargo build --release --features strict + - name: Build in strict mode with log feature + run: cargo build --release --features strict,log + + - name: Build in strict mode with defmt feature + run: cargo build --release --features strict,defmt + no_std_builds: name: Build no_std targets runs-on: ubuntu-latest @@ -120,7 +126,7 @@ jobs: uses: Swatinem/rust-cache@v1 - name: Check documentation - run: cargo rustdoc --all-features -- -D warnings + run: cargo rustdoc -- -D warnings clippy: name: Linting @@ -139,4 +145,10 @@ jobs: uses: Swatinem/rust-cache@v1 - name: Clippy - run: cargo clippy --all-targets --all-features -- -D warnings \ No newline at end of file + run: cargo clippy --all-targets -- -D warnings + + - name: Clippy (with log feature) + run: cargo clippy --all-targets --features log -- -D warnings + + - name: Clippy (with defmt feature) + run: cargo clippy --all-targets --features defmt -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 2ce68e8..8daca00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ documentation = "https://docs.rs/esp-at-nal" [dependencies] atat = "0.17.0" embedded-nal = "0.6.0" +defmt = { version = "0.3", optional = true } nb = "1.0.0" fugit = "0.3.6" fugit-timer = "0.1.3" @@ -30,6 +31,7 @@ serialport = { git = "https://github.com/dbrgn/serialport-rs", branch = "embedde [features] default = ["examples"] +defmt = ["dep:defmt", "atat/defmt"] # Fail on warnings strict = [] diff --git a/src/stack.rs b/src/stack.rs index a60a2bc..4219a24 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -124,6 +124,34 @@ pub enum Error { TimerError, } +#[cfg(feature = "defmt")] +impl defmt::Format for Error { + fn format(&self, f: defmt::Formatter) { + match self { + Error::EnablingMultiConnectionsFailed(e) => { + defmt::write!(f, "Error::EnablingMultiConnectionsFailed({})", e) + } + Error::EnablingPassiveSocketModeFailed(e) => { + defmt::write!(f, "Error::EnablingPassiveSocketModeFailed({})", e) + } + Error::ConnectError(e) => defmt::write!(f, "Error::ConnectError({})", e), + Error::TransmissionStartFailed(e) => defmt::write!(f, "Error::TransmissionStartFailed({})", e), + Error::SendFailed(e) => defmt::write!(f, "Error::SendFailed({})", e), + Error::ReceiveFailed(e) => defmt::write!(f, "Error::ReceiveFailed({})", e), + Error::CloseError(e) => defmt::write!(f, "Error::CloseError({})", e), + Error::PartialSend => defmt::write!(f, "Error::PartialSend"), + Error::UnconfirmedSocketState => defmt::write!(f, "Error::UnconfirmedSocketState"), + Error::NoSocketAvailable => defmt::write!(f, "Error::NoSocketAvailable"), + Error::AlreadyConnected => defmt::write!(f, "Error::AlreadyConnected"), + Error::SocketUnconnected => defmt::write!(f, "Error::SocketUnconnected"), + Error::ClosingSocket => defmt::write!(f, "Error::ClosingSocket"), + Error::ReceiveOverflow => defmt::write!(f, "Error::ReceiveOverflow"), + Error::UnexpectedWouldBlock => defmt::write!(f, "Error::UnexpectedWouldBlock"), + Error::TimerError => defmt::write!(f, "Error::TimerError"), + } + } +} + impl, const TIMER_HZ: u32, const TX_SIZE: usize, const RX_SIZE: usize> TcpClientStack for Adapter {