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/// - **`clear_update_flags`** writes 1 to clear, so repeating it can clear a flag the sink
39/// set again in the meantime. For `CED_Update` and `RSED_Update` that loses at most a
40/// hint: any counts stay in the counters, which are read regularly anyway. For a flag
41/// you act on, such as `FLT_Update` or `FRL_Start`, read `Update_0` again
42/// ([`read_update_flags`]) and clear only what is set, rather than repeating the clear.
43/// - **Reads** change nothing on the sink and are read again — except the error counters
44/// ([`read_ced`], [`read_rs_correction`]), which a sink may clear when they are read:
45/// a dropped read of them can lose counts.
46///
47/// [`read_update_flags`]: Self::read_update_flags
48/// [`write_frl_config`]: Self::write_frl_config
49/// [`read_ced`]: Self::read_ced
50/// [`read_rs_correction`]: Self::read_rs_correction
51///
52/// # Example
53///
54/// ```rust
55/// use culvert_async::Scdc;
56/// use hdmi_hal_async::scdc::{ScdcTransport, read_block_bytewise};
57///
58/// struct StubTransport;
59/// impl ScdcTransport for StubTransport {
60/// type Error = core::convert::Infallible;
61/// async fn read(&self, _reg: u8) -> Result<u8, Self::Error> { Ok(0) }
62/// async fn write(&mut self, _reg: u8, _value: u8) -> Result<(), Self::Error> { Ok(()) }
63/// async fn read_block(&self, reg: u8, buf: &mut [u8]) -> Result<(), Self::Error> {
64/// read_block_bytewise(self, reg, buf).await
65/// }
66/// }
67///
68/// # pollster::block_on(async {
69/// let mut scdc = Scdc::new(StubTransport);
70/// let sink_version = scdc.read_sink_version().await.unwrap();
71/// scdc.write_source_version(1).await.unwrap();
72/// # });
73/// ```
74pub struct Scdc<T> {
75 transport: T,
76}
77
78impl<T: ScdcTransport> Scdc<T> {
79 /// Creates a new `Scdc` client wrapping the given async transport.
80 pub fn new(transport: T) -> Self {
81 Self { transport }
82 }
83
84 /// Consumes the client and returns the underlying transport.
85 pub fn into_transport(self) -> T {
86 self.transport
87 }
88}