1#![allow(clippy::missing_safety_doc)]
15
16mod custom;
17mod drive;
18mod dynamic_datagram;
19mod dynamic_link;
20mod result;
21mod sampling_config;
22
23pub use autd3::{controller::Controller, error::AUTDError};
24pub use autd3_driver::{
25 datagram::{Datagram, Gain, GainAsAny, GainFilter, Modulation, STMProps},
26 defined::float,
27 error::AUTDInternalError,
28 firmware_version::FirmwareInfo,
29 geometry::{Device, Geometry, Vector3},
30 link::{LinkSync, LinkSyncBuilder},
31};
32pub use custom::{CustomGain, CustomModulation};
33pub use drive::*;
34pub use dynamic_datagram::{
35 DynamicConfigureDebugOutputIdx, DynamicConfigureForceFan, DynamicConfigureModDelay,
36 DynamicConfigureReadsFPGAInfo, DynamicDatagram, DynamicDatagramPack, DynamicDatagramPack2,
37};
38pub use dynamic_link::DynamicLinkBuilder;
39pub use libc::c_void;
40pub use result::*;
41pub use sampling_config::*;
42
43pub use autd3;
44pub use autd3_driver as driver;
45pub use libc;
46
47pub type ConstPtr = *const c_void;
48pub type L = dyn LinkSync;
49pub type G = dyn Gain;
50pub type M = dyn Modulation;
51pub type Cnt = Controller<Box<L>>;
52
53pub const NUM_TRANS_IN_UNIT: u32 = 249;
54pub const NUM_TRANS_IN_X: u32 = 18;
55pub const NUM_TRANS_IN_Y: u32 = 14;
56pub const TRANS_SPACING_MM: float = 10.16;
57pub const DEVICE_HEIGHT_MM: float = 151.4;
58pub const DEVICE_WIDTH_MM: float = 192.0;
59pub const FPGA_CLK_FREQ: u32 = 20480000;
60pub const ULTRASOUND_FREQUENCY: float = 40000.0;
61
62pub const AUTD3_ERR: i32 = -1;
63pub const AUTD3_TRUE: i32 = 1;
64pub const AUTD3_FALSE: i32 = 0;
65
66#[macro_export]
67macro_rules! cast {
68 ($ptr:expr, $type:ty) => {
69 ($ptr as *const $type).as_ref().unwrap()
70 };
71}
72
73#[macro_export]
74macro_rules! cast_mut {
75 ($ptr:expr, $type:ty) => {
76 ($ptr as *mut $type).as_mut().unwrap()
77 };
78}
79
80#[repr(u8)]
81pub enum GainSTMMode {
82 PhaseIntensityFull = 0,
83 PhaseFull = 1,
84 PhaseHalf = 2,
85}
86
87impl From<GainSTMMode> for autd3::prelude::GainSTMMode {
88 fn from(mode: GainSTMMode) -> Self {
89 match mode {
90 GainSTMMode::PhaseIntensityFull => autd3::prelude::GainSTMMode::PhaseIntensityFull,
91 GainSTMMode::PhaseFull => autd3::prelude::GainSTMMode::PhaseFull,
92 GainSTMMode::PhaseHalf => autd3::prelude::GainSTMMode::PhaseHalf,
93 }
94 }
95}
96
97#[repr(u8)]
98pub enum TimerStrategy {
99 Sleep = 0,
100 BusyWait = 1,
101 NativeTimer = 2,
102}
103
104impl From<TimerStrategy> for autd3::prelude::TimerStrategy {
105 fn from(strategy: TimerStrategy) -> Self {
106 match strategy {
107 TimerStrategy::Sleep => autd3::prelude::TimerStrategy::Sleep,
108 TimerStrategy::NativeTimer => autd3::prelude::TimerStrategy::NativeTimer,
109 TimerStrategy::BusyWait => autd3::prelude::TimerStrategy::BusyWait,
110 }
111 }
112}
113
114#[derive(Debug, Clone, Copy)]
115#[repr(C)]
116pub struct ControllerPtr(pub ConstPtr);
117
118#[derive(Debug, Clone, Copy)]
119#[repr(C)]
120pub struct FirmwareInfoListPtr(pub ConstPtr);
121
122#[derive(Debug, Clone, Copy)]
123#[repr(C)]
124pub struct GroupKVMapPtr(pub ConstPtr);
125
126#[derive(Debug, Clone, Copy)]
127#[repr(C)]
128pub struct GainCalcDrivesMapPtr(pub ConstPtr);
129
130#[derive(Debug, Clone, Copy)]
131#[repr(C)]
132pub struct GeometryPtr(pub ConstPtr);
133
134unsafe impl Send for GeometryPtr {}
135unsafe impl Sync for GeometryPtr {}
136
137#[derive(Debug, Clone, Copy)]
138#[repr(C)]
139pub struct DevicePtr(pub ConstPtr);
140
141#[derive(Debug, Clone, Copy)]
142#[repr(C)]
143pub struct TransducerPtr(pub ConstPtr);
144
145#[derive(Debug, Clone, Copy)]
146#[repr(C)]
147pub struct LinkBuilderPtr(pub ConstPtr);
148
149#[derive(Debug, Clone, Copy)]
150#[repr(C)]
151pub struct LinkPtr(pub ConstPtr);
152
153impl LinkBuilderPtr {
154 pub fn new<B: LinkSyncBuilder + 'static>(builder: B) -> LinkBuilderPtr {
155 Self(Box::into_raw(Box::new(DynamicLinkBuilder::new(builder))) as _)
156 }
157}
158
159#[macro_export]
160macro_rules! take_link {
161 ($ptr:expr, $type:ty) => {
162 Box::from_raw($ptr.0 as *mut Box<L> as *mut Box<$type>)
163 };
164}
165
166#[derive(Debug, Clone, Copy)]
167#[repr(C)]
168pub struct DatagramPtr(pub ConstPtr);
169
170impl DatagramPtr {
171 pub fn new<T: DynamicDatagram>(d: T) -> Self {
172 let d: Box<Box<dyn DynamicDatagram>> = Box::new(Box::new(d));
173 Self(Box::into_raw(d) as _)
174 }
175}
176
177#[derive(Debug, Clone, Copy)]
178#[repr(C)]
179pub struct DatagramSpecialPtr(pub ConstPtr);
180
181impl DatagramSpecialPtr {
182 pub fn new<T: DynamicDatagram>(d: T) -> Self {
183 let d: Box<Box<dyn DynamicDatagram>> = Box::new(Box::new(d));
184 Self(Box::into_raw(d) as _)
185 }
186}
187
188#[derive(Debug, Clone, Copy)]
189#[repr(C)]
190pub struct GainPtr(pub ConstPtr);
191
192impl GainPtr {
193 pub fn new<T: Gain + 'static>(g: T) -> Self {
194 let g: Box<Box<G>> = Box::new(Box::new(g));
195 Self(Box::into_raw(g) as _)
196 }
197}
198
199#[macro_export]
200macro_rules! take_gain {
201 ($ptr:expr, $type:ty) => {
202 Box::from_raw($ptr.0 as *mut Box<G> as *mut Box<$type>)
203 };
204}
205
206#[derive(Debug, Clone, Copy)]
207#[repr(C)]
208pub struct ModulationPtr(pub ConstPtr);
209
210impl ModulationPtr {
211 pub fn new<T: Modulation + 'static>(m: T) -> Self {
212 let m: Box<Box<M>> = Box::new(Box::new(m));
213 Self(Box::into_raw(m) as _)
214 }
215}
216
217#[macro_export]
218macro_rules! take_mod {
219 ($ptr:expr, $type:ty) => {
220 Box::from_raw($ptr.0 as *mut Box<M> as *mut Box<$type>)
221 };
222}
223
224#[derive(Debug, Clone, Copy)]
225#[repr(C)]
226pub struct CachePtr(pub ConstPtr);
227
228#[derive(Debug, Clone, Copy)]
229#[repr(C)]
230pub struct STMPropsPtr(pub ConstPtr);
231
232impl STMPropsPtr {
233 pub fn new(props: STMProps) -> Self {
234 Self(Box::into_raw(Box::new(props)) as _)
235 }
236}
237
238#[derive(Debug, Clone, Copy)]
239#[repr(C)]
240pub struct GroupGainMapPtr(pub ConstPtr);