autd3_driver/datagram/
debug.rs1use std::convert::Infallible;
2
3use crate::firmware::{
4 fpga::{DebugType, GPIOOut},
5 operation::DebugSettingOp,
6};
7
8use crate::datagram::*;
9use derive_more::Debug;
10
11#[derive(Debug)]
26pub struct DebugSettings<F: Fn(&Device, GPIOOut) -> DebugType + Send + Sync> {
27 #[debug(ignore)]
28 f: F,
29}
30
31impl<F: Fn(&Device, GPIOOut) -> DebugType + Send + Sync> DebugSettings<F> {
32 #[must_use]
34 pub const fn new(f: F) -> Self {
35 Self { f }
36 }
37}
38
39pub struct DebugSettingOpGenerator<F: Fn(&Device, GPIOOut) -> DebugType + Send + Sync> {
40 f: F,
41}
42
43impl<F: Fn(&Device, GPIOOut) -> DebugType + Send + Sync> OperationGenerator
44 for DebugSettingOpGenerator<F>
45{
46 type O1 = DebugSettingOp;
47 type O2 = NullOp;
48
49 fn generate(&mut self, device: &Device) -> (Self::O1, Self::O2) {
50 (
51 Self::O1::new(
52 [GPIOOut::O0, GPIOOut::O1, GPIOOut::O2, GPIOOut::O3]
53 .map(|gpio| (self.f)(device, gpio).into()),
54 ),
55 Self::O2 {},
56 )
57 }
58}
59
60impl<F: Fn(&Device, GPIOOut) -> DebugType + Send + Sync> Datagram for DebugSettings<F> {
61 type G = DebugSettingOpGenerator<F>;
62 type Error = Infallible;
63
64 fn operation_generator(self, _: &Geometry, _: bool) -> Result<Self::G, Self::Error> {
65 Ok(DebugSettingOpGenerator { f: self.f })
66 }
67}