Skip to main content

Scdc

Struct Scdc 

Source
pub struct Scdc<T> { /* private fields */ }
Available on crate feature culvert-async only.
Expand description

Async typed client for the HDMI 2.1 SCDC (Status and Control Data Channel) register map.

Scdc<T> wraps an async ScdcTransport and exposes one typed async fn per register group. It holds no protocol state; all sequencing logic belongs in the caller.

§Cancellation

To stop early, check a deadline or cancel signal before each call and stop there, rather than dropping a future mid-flight: no transaction is then cut short, whatever the transport does. If a future is dropped, Scdc<T> itself stays usable (it keeps no state between calls); the transport’s documentation says what a cancelled transfer leaves behind (see ScdcTransport’s “Cancellation”). What a dropped call has done is then unknown, method by method:

  • Writes that set a whole register — write_source_version, write_tmds_config, write_config_0, write_frl_config — may or may not have reached the sink. Repeating one writes the same register contents again. What the write sets off on the sink is another matter: a Config_1 write (write_frl_config) is what starts link training there, so repeating it mid-training may restart the sink’s training. To abandon a training attempt, return the link to TMDS (plumbob-async’s exit_to_tmds) rather than repeating the write.
  • update_tmds_config reads TMDS_Config and writes it back: dropped, it may have written nothing or the new byte. Repeating it reads the byte again and writes the same two bits, keeping the other bits as read then, so it is safe to repeat; to know which happened instead, read the register back (read_tmds_config).
  • clear_update_flags writes 1 to clear, so repeating it can clear a flag the sink set again in the meantime. For CED_Update and RSED_Update that loses at most a hint: any counts stay in the counters, which are read regularly anyway. For a flag you act on, such as FLT_Update or FRL_Start, read Update_0 again (read_update_flags) and clear only what is set, rather than repeating the clear.
  • Reads change nothing on the sink and are read again — except the error counters (read_ced, read_rs_correction), which a sink may clear when they are read: a dropped read of them can lose counts.

§Example

use culvert_async::Scdc;
use hdmi_hal_async::scdc::{ScdcTransport, read_block_bytewise};

struct StubTransport;
impl ScdcTransport for StubTransport {
    type Error = core::convert::Infallible;
    async fn read(&self, _reg: u8) -> Result<u8, Self::Error> { Ok(0) }
    async fn write(&mut self, _reg: u8, _value: u8) -> Result<(), Self::Error> { Ok(()) }
    async fn read_block(&self, reg: u8, buf: &mut [u8]) -> Result<(), Self::Error> {
        read_block_bytewise(self, reg, buf).await
    }
}

let mut scdc = Scdc::new(StubTransport);
let sink_version = scdc.read_sink_version().await.unwrap();
scdc.write_source_version(1).await.unwrap();

Implementations§

Source§

impl<T> Scdc<T>
where T: ScdcTransport,

Source

pub async fn read_ced( &mut self, lanes: HdmiLanes, ) -> Result<CedReading, ScdcError<<T as ScdcTransport>::Error>>

Reads the per-lane character error counts: the ERR_DET block, 0x50–0x58 (lanes 0–2, the checksum at 0x56, lane 3), in one read_block, and checks the checksum.

lanes is the link’s: HdmiLanes::Three for TMDS and 3-lane FRL, Four for 4-lane FRL (rate.lanes()). It decides what the checksum covers and whether lane 3 is read as a count.

Err only for a transport failure. What the read finds wrong is a CedWarning in the CedReading, with the counters decoded either way: a checksum mismatch (most likely a read torn by a counter update), or a count for lane 3 when it is not in use. culvert-async does not read again; whether to is the caller’s decision, and a sink that clears the counters on read returns different counts the second time.

One transaction keeps the transport from splitting the block; whether the sink holds its registers still during it is up to the sink, and a transport that reads a register at a time (read_block_bytewise), or a bus driver that does, splits it anyway. The checksum is the one protection against a torn read that holds on every transport and adapter: it catches most torn reads, not all. CedReading says how the counts behave (saturation, clear on read, resets).

UpdateFlags::ced_update is set by the sink and kept until the source clears it, but it is a hint at most: it has been seen set with every count zero, and a sink may never set it. Read the counters regularly rather than only after the flag, and clear the flag before reading them (clear_update_flags says why).

Source

pub async fn read_rs_correction( &mut self, ) -> Result<Option<RsCorrectionCount>, ScdcError<<T as ScdcTransport>::Error>>

Reads the Reed-Solomon correction count from RS_Correction_L/H (0x59/0x5A).

Returns None if the high byte’s validity bit (bit 7) is not set: unknown, not zero. The count is maintained by the sink in FRL mode.

Both bytes are one read_block: one transaction, so the transport does not split them; whether the sink holds them still during it is up to the sink, and a transport that reads a register at a time (read_block_bytewise), or a bus driver that does, splits them anyway. The count has no checksum, so a torn read cannot be detected: unlike the CED counters, nothing protects it on every adapter.

The count accumulates and saturates at 0x7FFF, so a saturated count means “at least”. A sink may clear it when it is read, so a reading is a running total on some sinks and the count since the previous read on others; a reading lower than the previous one means a reset (clear on read, hot plug, an SCDC clear), and counting starts again from it. Count afresh after retraining, a rate change or a hot plug too.

UpdateFlags::rsed_update is set by the sink and kept until the source clears it, a hint at most, as ced_update is; a sink may never set it. Read the count regularly rather than only after the flag.

Source§

impl<T> Scdc<T>
where T: ScdcTransport,

Source

pub async fn write_frl_config( &mut self, config: FrlConfig, ) -> Result<(), ScdcError<<T as ScdcTransport>::Error>>

Writes FRL training configuration to Config_1 (0x31).

Encodes FRL_Rate into bits[3:0] and FFE_Levels into bits[7:4].

Returns crate::ProtocolError::FfeLevelsOutOfRange without writing anything if the FFE levels exceed FfeLevels::max_for the requested rate.

Source

pub async fn write_config_0( &mut self, config: Config0, ) -> Result<(), ScdcError<<T as ScdcTransport>::Error>>

Writes Config_0 (0x30): RR_Enable (bit 0) and FLT_No_Retrain (bit 1).

Source

pub async fn read_source_test_config( &mut self, ) -> Result<SourceTestConfig, ScdcError<<T as ScdcTransport>::Error>>

Reads Source_Test_Configuration (0x35), written by the sink to instruct the source during compliance testing.

Source

pub async fn read_status_flags( &mut self, ) -> Result<StatusFlags, ScdcError<<T as ScdcTransport>::Error>>

Reads Status_Flags_0 (0x40): clock detection, lane lock, FLT_Ready and DSC decode failure.

Source

pub async fn read_ltp_requests( &mut self, ) -> Result<LtpRequests, ScdcError<<T as ScdcTransport>::Error>>

Reads the per-lane link training pattern requests from Status_Flags_1 (0x41, lanes 0–1) and Status_Flags_2 (0x42, lanes 2–3).

Both registers are one read_block: one transaction, so the transport does not split them; whether the sink holds them still during it is up to the sink, and a transport that reads a register at a time (read_block_bytewise), or a bus driver that does, splits them anyway. They have no checksum, so a torn read cannot be detected.

A value HDMI 2.1 leaves undefined (0x9–0xD) is LtpReq::Reserved, not an error.

Source§

impl<T> Scdc<T>
where T: ScdcTransport,

Source

pub async fn write_tmds_config( &mut self, config: TmdsConfig, ) -> Result<(), ScdcError<<T as ScdcTransport>::Error>>

Writes scrambling configuration to TMDS_Config (0x20).

Sets Scrambling_Enable (bit 0) and TMDS_Bit_Clock_Ratio (bit 1).

Source

pub async fn read_tmds_config( &mut self, ) -> Result<TmdsConfigReading, ScdcError<<T as ScdcTransport>::Error>>

Reads TMDS_Config (0x20): the two bits write_tmds_config sets, and the whole byte.

Source

pub async fn update_tmds_config( &mut self, config: TmdsConfig, ) -> Result<(), ReadModifyWriteError<<T as ScdcTransport>::Error>>

Sets Scrambling_Enable (bit 0) and TMDS_Bit_Clock_Ratio (bit 1) of TMDS_Config (0x20) and keeps its other bits: reads the byte, then writes it back with the two bits from config and every other bit as read.

write_tmds_config writes the whole byte instead, the other bits 0. Two transfers, not one transaction: a failed read writes nothing (ReadModifyWriteError::Read), and a failed write says so (ReadModifyWriteError::Write).

Source

pub async fn read_scrambler_status( &mut self, ) -> Result<ScramblerStatus, ScdcError<<T as ScdcTransport>::Error>>

Reads scrambler acknowledgement from Scrambler_Status (0x21).

Returns ScramblerStatus::scrambling_active set when the sink confirms that TMDS scrambling is active (bit 0).

Source§

impl<T> Scdc<T>
where T: ScdcTransport,

Source

pub async fn read_update_flags( &mut self, ) -> Result<UpdateFlags, ScdcError<<T as ScdcTransport>::Error>>

Reads update flags from Update_0 (0x10).

Source

pub async fn clear_update_flags( &mut self, flags: ClearableUpdateFlags, ) -> Result<(), ScdcError<<T as ScdcTransport>::Error>>

Clears the specified update flags in Update_0 (0x10).

Each flag set to true in flags is cleared (write-1-to-clear). Flags set to false are left unchanged, and so is RR_Test, which the source does not clear (ClearableUpdateFlags has no field for it). To acknowledge every flag just read, pass UpdateFlags::clearable.

Clear only the flags read and acted on: the write touches no other bit, so a flag the sink sets between the read and the clear stays set for the next read. CED_Update and RSED_Update are kept until the source clears them; clear them before reading the counters, so that a flag seen set later was set after that read. Read first and clear after, and a flag set in between is cleared unseen (any counts behind it are not lost: the counters keep them for the next read). Either flag is a hint at most: a set flag does not mean there are counts.

Source§

impl<T> Scdc<T>
where T: ScdcTransport,

Source

pub async fn read_sink_version( &mut self, ) -> Result<u8, ScdcError<<T as ScdcTransport>::Error>>

Reads the sink’s SCDC protocol version from Sink_Version (0x01).

Source

pub async fn write_source_version( &mut self, version: u8, ) -> Result<(), ScdcError<<T as ScdcTransport>::Error>>

Writes the source’s SCDC protocol version to Source_Version (0x02).

Source§

impl<T> Scdc<T>
where T: ScdcTransport,

Source

pub fn new(transport: T) -> Scdc<T>

Creates a new Scdc client wrapping the given async transport.

Source

pub fn into_transport(self) -> T

Consumes the client and returns the underlying transport.

Trait Implementations§

Source§

impl<T: ScdcTransport> TmdsScdc for Scdc<T>

culvert-async’s client, as spiritlevel’s culvert adapter implements the sync trait for culvert’s: update_tmds_config is the client’s read-modify-write, and the bytes read reach TmdsConfigReading::raw and ScramblingStatus::raw.

The plain trait, not the twin: implementing both for one type would conflict with the blanket implementation. Its futures are Send all the same where the compiler can see the transport: in code generic over T: SendScdcTransport that names Scdc<T>, the driver’s futures are Send under the conditions the crate root gives (“Send futures”).

The client has inherent methods named like five of these (read_tmds_config, write_tmds_config, update_tmds_config, read_sink_version, write_source_version), with culvert’s types, and a method call picks those over the trait’s: with TmdsScdc in scope, scdc.read_tmds_config() still returns culvert’s reading. Call the trait’s through the trait, TmdsScdc::read_tmds_config(&mut scdc), as the driver does.

Source§

impl<T: ScdcTransport> TmdsScdc for &mut Scdc<T>

The client lent to the driver, so one client serves the SCDC setup, FRL training, TMDS bring-up and health reads in turn without being moved. Its futures are Send under the same conditions as the client’s.

Auto Trait Implementations§

§

impl<T> Forget for Scdc<T>

§

impl<T> Freeze for Scdc<T>
where T: Freeze,

§

impl<T> Move for Scdc<T>

§

impl<T> RefUnwindSafe for Scdc<T>
where T: RefUnwindSafe,

§

impl<T> Send for Scdc<T>
where T: Send,

§

impl<T> Sync for Scdc<T>
where T: Sync,

§

impl<T> Unpin for Scdc<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Scdc<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Scdc<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.