Skip to main content

ScdcTransport

Trait ScdcTransport 

Source
pub trait ScdcTransport {
    type Error: DdcError;

    // Required methods
    async fn read(&self, reg: u8) -> Result<u8, Self::Error>;
    async fn write(&mut self, reg: u8, value: u8) -> Result<(), Self::Error>;
    async fn read_block(
        &self,
        reg: u8,
        buf: &mut [u8],
    ) -> Result<(), Self::Error>;
}
Available on crate feature culvert-async only.
Expand description

The async transport Scdc<T> is generic over, re-exported from hdmi-hal-async. Async raw register access to the SCDC register map over DDC/I²C.

This is the async counterpart to hdmi_hal::scdc::ScdcTransport, with the same contract, restated here, and two clauses only async code needs: calls made at the same time from one task (in read_block’s “One transaction”) and Cancellation.

SCDC is a bidirectional channel used for FRL link training initiation, scrambling control, and CED (Character Error Detection) reporting. Any code that needs to touch the SCDC register map does so through this trait.

The trait operates at the raw register level: a one-byte address and a one-byte value. Typed register wrappers, named constants, and multi-register sequences belong in the protocol crate, not here.

Every method is required. A transport that can read several registers in one DDC/I²C transaction implements read_block with that transaction; one that cannot implements it with read_block_bytewise, so the choice is visible in its code. Here, a bus that can read only one register per transaction:

use core::convert::Infallible;
use hdmi_hal_async::scdc::{ScdcTransport, read_block_bytewise};

/// A bus whose controller reads one register per transaction.
struct OneRegisterBus {
    registers: [u8; 256], // stands in for the sink
}

impl ScdcTransport for OneRegisterBus {
    type Error = Infallible;

    async fn read(&self, reg: u8) -> Result<u8, Infallible> {
        Ok(self.registers[reg as usize])
    }

    async fn write(&mut self, reg: u8, value: u8) -> Result<(), Infallible> {
        self.registers[reg as usize] = value;
        Ok(())
    }

    /// One register at a time: not one transaction.
    async fn read_block(&self, reg: u8, buf: &mut [u8]) -> Result<(), Infallible> {
        read_block_bytewise(self, reg, buf).await
    }
}

A simulated sink, a register array that holds still while it is read, conforms with a plain copy of its registers into buf instead.

§Errors

After any method returns an error, an implementation should leave the transport usable for the next call, recovering the bus itself if a transfer failed midway (for example a held data line after a NACK). One that cannot says so in its documentation: what an error leaves behind, and how to recover (for example, by constructing the transport again).

§Cancellation

Any of these futures may be dropped before it completes, for example by a deadline in the caller. What a dropped call has done is then unknown:

  • a dropped read returns no value, and whether its transaction reached the bus is unknown;
  • after a dropped read_block, the contents of buf are unspecified;
  • after a dropped write, the write may or may not have reached the sink, so a caller that needs to know reads the register back.

An implementation should leave the transport usable for the next call, recovering the bus itself if the transfer was cut short (for example by clearing a held bus before the next transaction). One that cannot must say so in its documentation: what a cancelled call leaves behind, and how to recover (for example, by constructing the transport again).

A caller that needs to stop early can avoid the question: check the 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.

Required Associated Types§

Source

type Error: DdcError

Error type returned by transport operations, classified by DdcError::kind (implemented for Infallible, () and DdcErrorKind). Over a DdcBus, ScdcOverDdc is the transport.

Required Methods§

Source

async fn read(&self, reg: u8) -> Result<u8, Self::Error>

Read a single byte from the given SCDC register address.

Source

async fn write(&mut self, reg: u8, value: u8) -> Result<(), Self::Error>

Write a single byte to the given SCDC register address.

Source

async fn read_block(&self, reg: u8, buf: &mut [u8]) -> Result<(), Self::Error>

Read consecutive SCDC registers, starting at reg, into buf.

Related registers, such as the status flags or the character error counters, are read together, in one transaction, so that the transport does not split them; whether the sink keeps them consistent during that transaction is the sink’s (see “No snapshot promised”). The contract:

  • What it reads. buf[i] is register reg + i.
  • One transaction. The whole buffer is read as one combined transfer to the layer below — on the DDC bus, the register offset written, a repeated START, buf.len() bytes read, STOP — or an error is returned. An implementation never splits the read into several transfers, and never falls back to one register at a time. Where the layer below is an OS bus driver, the transfer is handed to it whole; a driver known to split it on the wire is named in the transport’s documentation, as the bytewise exception is. Calls made at the same time through shared references do not interleave on the bus. That includes calls polled together from one task (join!), which reach even a transport that is not Sync: an implementation serializes them, waiting for the bus, and never panics (a RefCell borrowed across an .await would); one that cannot serialize returns an error for the second call instead, and says so. read_block_bytewise is the one exception to the first two rules, and a transport that uses it says so.
  • No snapshot promised. One transaction does not mean the sink returns a consistent snapshot: whether it holds its registers still during a read is up to the sink.
  • Length limit. An implementation may have a maximum length, if it documents it, of at least 16 bytes; a longer buffer is an error, not split. A caller that needs a longer read splits it itself — parts of up to 16 bytes fit every conforming transport — knowing the parts are separate transactions.
  • Empty buffer. Ok, with no bus activity.
  • On error, the contents of buf are unspecified (see the trait’s “Errors” for the transport itself).
  • Past 0xFF. The caller does not read past register 0xFF. If it does, the result is unspecified, but the call returns, Ok or an error, and never panics: read_block_bytewise wraps to 0x00; a real burst read leaves it to the sink.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§