Skip to main content

autd3_cpu_wire/
lib.rs

1//! Shared wire-protocol contract between the
2//! [AUTD3](https://hapislab.org/en/airborne-ultrasound-tactile-display) CPU firmware and its
3//! clients: command opcodes, error codes, frame layout, and payload types.
4//!
5//! `no_std`, and the single source of truth for both sides. Application code should use the
6//! re-exports from [`autd3-rs`](https://docs.rs/autd3-rs) rather than depend on this crate.
7//!
8//! See the [documentation site](https://shinolab.github.io/autd3-sdk/en/).
9
10#![no_std]
11
12#[macro_export]
13macro_rules! wire_enum {
14    ($vis:vis enum $name:ident { $($variant:ident = $value:expr,)+ }) => {
15        #[derive(Clone, Copy, PartialEq, Eq, Debug)]
16        #[repr(u8)]
17        #[non_exhaustive]
18        $vis enum $name {
19            $($variant = $value,)+
20        }
21
22        impl $name {
23            $vis const ALL: &'static [Self] = &[$(Self::$variant,)+];
24
25            #[must_use]
26            $vis const fn from_u8(value: u8) -> Option<Self> {
27                $(if value == $value {
28                    return Some(Self::$variant);
29                })+
30                None
31            }
32
33            #[must_use]
34            $vis const fn as_u8(self) -> u8 {
35                self as u8
36            }
37        }
38
39        impl ::core::convert::TryFrom<u8> for $name {
40            type Error = u8;
41
42            fn try_from(value: u8) -> ::core::result::Result<Self, u8> {
43                Self::from_u8(value).ok_or(value)
44            }
45        }
46    };
47}
48
49mod cmd;
50mod error;
51mod frame;
52pub mod layout;
53mod mode;
54pub mod params;
55pub mod payload;
56mod telemetry;
57
58pub use cmd::Cmd;
59pub use error::{Error, describe_device_error};
60pub use frame::{DEVICE_TO_HOST_BYTES, HOST_TO_DEVICE_BYTES, PAYLOAD_BYTES};
61pub use mode::Mode;
62pub use telemetry::Telemetry;