Skip to main content

culvert_async/client/
mod.rs

1//! The [`Scdc`] client.
2
3use hdmi_hal_async::scdc::ScdcTransport;
4
5mod ced;
6mod frl;
7mod scrambling;
8mod update;
9mod version;
10
11#[cfg(feature = "plumbob-async")]
12mod plumbob_client;
13
14#[cfg(test)]
15mod test_transport;
16
17/// Async typed client for the HDMI 2.1 SCDC (Status and Control Data Channel) register map.
18///
19/// `Scdc<T>` wraps an async [`ScdcTransport`] and exposes one typed `async fn` per register
20/// group. It holds no protocol state; all sequencing logic belongs in the caller.
21///
22/// # Cancellation
23///
24/// To stop early, check a deadline or cancel signal before each call and stop there,
25/// rather than dropping a future mid-flight: no transaction is then cut short, whatever
26/// the transport does. If a future is dropped, `Scdc<T>` itself stays usable (it keeps no
27/// state between calls); the transport's documentation says what a cancelled transfer
28/// leaves behind (see `ScdcTransport`'s "Cancellation"). What a dropped call has done is
29/// then unknown, method by method:
30///
31/// - **Writes that set a whole register** — `write_source_version`, `write_tmds_config`,
32///   `write_config_0`, `write_frl_config` — may or may not have reached the sink.
33///   Repeating one writes the same register contents again. What the write sets off on
34///   the sink is another matter: a `Config_1` write ([`write_frl_config`]) is what starts
35///   link training there, so repeating it mid-training may restart the sink's training.
36///   To abandon a training attempt, return the link to TMDS (plumbob-async's
37///   `exit_to_tmds`) rather than repeating the write.
38/// - **[`update_tmds_config`]** reads `TMDS_Config` and writes it back: dropped, it may
39///   have written nothing or the new byte. Repeating it reads the byte again and writes
40///   the same two bits, keeping the other bits as read then, so it is safe to repeat; to
41///   know which happened instead, read the register back ([`read_tmds_config`]).
42/// - **`clear_update_flags`** writes 1 to clear, so repeating it can clear a flag the sink
43///   set again in the meantime. For `CED_Update` and `RSED_Update` that loses at most a
44///   hint: any counts stay in the counters, which are read regularly anyway. For a flag
45///   you act on, such as `FLT_Update` or `FRL_Start`, read `Update_0` again
46///   ([`read_update_flags`]) and clear only what is set, rather than repeating the clear.
47/// - **Reads** change nothing on the sink and are read again — except the error counters
48///   ([`read_ced`], [`read_rs_correction`]), which a sink may clear when they are read:
49///   a dropped read of them can lose counts.
50///
51/// [`update_tmds_config`]: Self::update_tmds_config
52/// [`read_tmds_config`]: Self::read_tmds_config
53/// [`read_update_flags`]: Self::read_update_flags
54/// [`write_frl_config`]: Self::write_frl_config
55/// [`read_ced`]: Self::read_ced
56/// [`read_rs_correction`]: Self::read_rs_correction
57///
58/// # Example
59///
60/// ```rust
61/// use culvert_async::Scdc;
62/// use hdmi_hal_async::scdc::{ScdcTransport, read_block_bytewise};
63///
64/// struct StubTransport;
65/// impl ScdcTransport for StubTransport {
66///     type Error = core::convert::Infallible;
67///     async fn read(&self, _reg: u8) -> Result<u8, Self::Error> { Ok(0) }
68///     async fn write(&mut self, _reg: u8, _value: u8) -> Result<(), Self::Error> { Ok(()) }
69///     async fn read_block(&self, reg: u8, buf: &mut [u8]) -> Result<(), Self::Error> {
70///         read_block_bytewise(self, reg, buf).await
71///     }
72/// }
73///
74/// # pollster::block_on(async {
75/// let mut scdc = Scdc::new(StubTransport);
76/// let sink_version = scdc.read_sink_version().await.unwrap();
77/// scdc.write_source_version(1).await.unwrap();
78/// # });
79/// ```
80pub struct Scdc<T> {
81    transport: T,
82}
83
84impl<T: ScdcTransport> Scdc<T> {
85    /// Creates a new `Scdc` client wrapping the given async transport.
86    pub fn new(transport: T) -> Self {
87        Self { transport }
88    }
89
90    /// Consumes the client and returns the underlying transport.
91    pub fn into_transport(self) -> T {
92        self.transport
93    }
94}