autd3_core/lib.rs
1#![no_std]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3#![warn(missing_docs)]
4#![warn(rustdoc::missing_crate_level_docs)]
5#![warn(rustdoc::unescaped_backticks)]
6
7//! Core traits and types for AUTD3.
8
9extern crate alloc;
10#[cfg(feature = "std")]
11extern crate std;
12
13#[cfg_attr(docsrs, doc(cfg(feature = "acoustics")))]
14#[cfg(feature = "acoustics")]
15/// Utilities for acoustics.
16pub mod acoustics;
17#[cfg_attr(docsrs, doc(cfg(feature = "common")))]
18#[cfg(feature = "common")]
19/// Common constants and types.
20pub mod common;
21#[cfg_attr(docsrs, doc(cfg(feature = "datagram")))]
22#[cfg(feature = "datagram")]
23/// Core traits for Datagram.
24pub mod datagram;
25#[cfg_attr(docsrs, doc(cfg(feature = "environment")))]
26#[cfg(feature = "environment")]
27#[doc(hidden)]
28pub mod environment;
29#[cfg_attr(docsrs, doc(cfg(feature = "ethercat")))]
30#[cfg(feature = "ethercat")]
31/// Definitions for EtherCAT.
32pub mod ethercat;
33#[cfg_attr(docsrs, doc(cfg(feature = "firmware")))]
34#[cfg(feature = "firmware")]
35/// Firmware related modules.
36pub mod firmware;
37#[cfg_attr(docsrs, doc(cfg(feature = "gain")))]
38#[cfg(feature = "gain")]
39/// Core traits for Gain.
40pub mod gain;
41#[cfg_attr(docsrs, doc(cfg(feature = "geometry")))]
42#[cfg(feature = "geometry")]
43/// Geometry related modules.
44pub mod geometry;
45#[cfg_attr(docsrs, doc(cfg(feature = "link")))]
46#[cfg(feature = "link")]
47/// A interface to the device.
48pub mod link;
49#[cfg_attr(docsrs, doc(cfg(feature = "modulation")))]
50#[cfg(feature = "modulation")]
51/// Core traits for Modulation.
52pub mod modulation;
53#[cfg_attr(docsrs, doc(cfg(feature = "sleep")))]
54#[cfg(feature = "sleep")]
55#[doc(hidden)]
56pub mod sleep;
57#[cfg_attr(docsrs, doc(cfg(feature = "utils")))]
58#[cfg(feature = "utils")]
59#[doc(hidden)]
60pub mod utils;
61
62/// Utilities for user-common [`Gain`] and [`Modulation`].
63///
64/// # Example
65///
66/// The following example shows how to define a custom [`Gain`] that generates a single focal point.
67///
68/// ```
69/// use autd3_core::derive::*;
70/// use autd3_core::geometry::Point3;
71/// use autd3_core::common::rad;
72///
73/// #[derive(Gain, Debug)]
74/// pub struct FocalPoint {
75/// pos: Point3,
76/// }
77///
78/// #[derive(Clone, Copy)]
79/// pub struct Impl {
80/// pos: Point3,
81/// wavenumber: f32,
82/// }
83///
84/// impl<'a> GainCalculator<'a> for Impl {
85/// fn calc(&self, tr: &'a Transducer) -> Drive {
86/// Drive {
87/// phase: Phase::from(-(self.pos - tr.position()).norm() * self.wavenumber * rad),
88/// intensity: Intensity::MAX,
89/// }
90/// }
91/// }
92///
93/// impl<'a> GainCalculatorGenerator<'a> for Impl {
94/// type Calculator = Self;
95///
96/// fn generate(&mut self, _: &'a Device) -> Self::Calculator {
97/// *self
98/// }
99/// }
100///
101/// impl<'a> Gain<'a> for FocalPoint {
102/// type G = Impl;
103///
104/// fn init(
105/// self,
106/// _geometry: &'a Geometry,
107/// env: &Environment,
108/// _filter: &TransducerMask ,
109/// ) -> Result<Self::G, GainError> {
110/// Ok(Impl {
111/// pos: self.pos,
112/// wavenumber: env.wavenumber(),
113/// })
114/// }
115/// }
116/// ```
117///
118/// The following example shows how to define a modulation that outputs the maximum value only for a moment.
119///
120/// ```
121/// use autd3_core::common::kHz;
122/// use autd3_core::derive::*;
123///
124/// #[derive(Modulation, Debug)]
125/// pub struct Burst {
126/// }
127///
128/// impl Burst {
129/// pub fn new() -> Self {
130/// Self {}
131/// }
132/// }
133///
134/// impl Modulation for Burst {
135/// fn calc(self, _limits: &FirmwareLimits) -> Result<Vec<u8>, ModulationError> {
136/// Ok((0..4000)
137/// .map(|i| if i == 3999 { u8::MAX } else { u8::MIN })
138/// .collect())
139/// }
140///
141/// fn sampling_config(&self) -> SamplingConfig {
142/// SamplingConfig::new(4. * kHz)
143/// }
144/// }
145/// ```
146///
147/// [`Gain`]: crate::gain::Gain
148/// [`Modulation`]: crate::modulation::Modulation
149#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
150#[cfg(feature = "derive")]
151pub mod derive {
152 #[cfg(any(feature = "gain", feature = "modulation"))]
153 mod common {
154 pub use crate::{
155 datagram::{DatagramOption, DeviceMask, Inspectable, InspectionResult, internal},
156 environment::Environment,
157 firmware::{FirmwareLimits, Segment, transition_mode},
158 geometry::Geometry,
159 };
160 }
161 #[cfg(any(feature = "gain", feature = "modulation"))]
162 pub use common::*;
163
164 #[cfg(feature = "gain")]
165 mod gain {
166 pub use crate::{
167 datagram::DatagramS,
168 firmware::{Drive, Intensity, Phase},
169 gain::{
170 DeviceTransducerMask, Gain, GainCalculator, GainCalculatorGenerator, GainError,
171 GainInspectionResult, GainOperationGenerator, TransducerMask,
172 },
173 geometry::{Device, Transducer},
174 };
175 pub use autd3_derive::Gain;
176 }
177 #[cfg(feature = "gain")]
178 pub use gain::*;
179
180 #[cfg(feature = "modulation")]
181 mod modulation {
182 pub use crate::datagram::{Datagram, DatagramL};
183 pub use crate::firmware::{SamplingConfig, SamplingConfigError};
184 pub use crate::modulation::{
185 Modulation, ModulationError, ModulationInspectionResult, ModulationOperationGenerator,
186 };
187 pub use autd3_derive::Modulation;
188 }
189 #[cfg(feature = "modulation")]
190 pub use modulation::*;
191}