use core::time::Duration;
use hdmi_hal::HdmiForumFrl;
use hdmi_hal::phy::{LanePatterns, LtpPattern};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SinkConfig {
pub(crate) scdc: bool,
pub(crate) sink_version: u8,
pub(crate) owned_scdc_write: OwnedWrite,
pub(crate) scdc_past_end: ScdcPastEnd,
pub(crate) segment_pointer: bool,
pub(crate) past_store: PastStore,
pub(crate) missing_segment: MissingSegment,
pub(crate) block_boundary: BlockBoundary,
pub(crate) scdc_during_hpd_low: DuringHpdLow,
pub(crate) edid_during_hpd_low: DuringHpdLow,
pub(crate) scrambling_lock: Trigger,
pub(crate) strict_lock: bool,
pub(crate) refusal: Refusal,
pub(crate) enable_timeout: Option<Duration>,
pub(crate) hpd_resets: [HpdReset; RegisterGroup::COUNT],
pub(crate) status_update: StatusUpdate,
pub(crate) ced_update: CedUpdate,
pub(crate) ced_read: CedRead,
pub(crate) during_read: DuringRead,
pub(crate) max_frl_rate: Option<HdmiForumFrl>,
pub(crate) ltp_requests: LanePatterns,
pub(crate) lts3_timeout: Option<Duration>,
pub(crate) frl_pass: FrlPass,
pub(crate) max_tmds_rate_khz: Option<u32>,
}
impl SinkConfig {
pub const fn new() -> Self {
Self {
scdc: true,
sink_version: 1,
owned_scdc_write: OwnedWrite::Ignore,
scdc_past_end: ScdcPastEnd::Wrap,
segment_pointer: true,
past_store: PastStore::Fill,
missing_segment: MissingSegment::Nack,
block_boundary: BlockBoundary::Continue,
scdc_during_hpd_low: DuringHpdLow::Answers,
edid_during_hpd_low: DuringHpdLow::Answers,
scrambling_lock: Trigger::After(Duration::from_millis(1)),
strict_lock: false,
refusal: Refusal::NONE,
enable_timeout: Some(Duration::from_millis(100)),
hpd_resets: [HpdReset::OnHpdLow; RegisterGroup::COUNT],
status_update: StatusUpdate::OnChange,
ced_update: CedUpdate::EverySecond { rise: 4 },
ced_read: CedRead::Keep,
during_read: DuringRead::Moving,
max_frl_rate: None,
ltp_requests: LanePatterns {
lane0: Some(LtpPattern::Lfsr0),
lane1: Some(LtpPattern::Lfsr1),
lane2: Some(LtpPattern::Lfsr2),
lane3: Some(LtpPattern::Lfsr3),
},
lts3_timeout: Some(Duration::from_millis(180)),
frl_pass: FrlPass::Patterns,
max_tmds_rate_khz: None,
}
}
#[must_use]
pub const fn without_scdc(self) -> Self {
Self {
scdc: false,
..self
}
}
#[must_use]
pub const fn with_sink_version(self, sink_version: u8) -> Self {
Self {
sink_version,
..self
}
}
#[must_use]
pub const fn with_owned_scdc_writes(self, owned_scdc_write: OwnedWrite) -> Self {
Self {
owned_scdc_write,
..self
}
}
#[must_use]
pub const fn with_scdc_past_end(self, scdc_past_end: ScdcPastEnd) -> Self {
Self {
scdc_past_end,
..self
}
}
#[must_use]
pub const fn without_segment_pointer(self) -> Self {
Self {
segment_pointer: false,
..self
}
}
#[must_use]
pub const fn with_past_store(self, past_store: PastStore) -> Self {
Self { past_store, ..self }
}
#[must_use]
pub const fn with_missing_segment(self, missing_segment: MissingSegment) -> Self {
Self {
missing_segment,
..self
}
}
#[must_use]
pub const fn with_block_boundary(self, block_boundary: BlockBoundary) -> Self {
Self {
block_boundary,
..self
}
}
#[must_use]
pub const fn with_scdc_during_hpd_low(self, scdc_during_hpd_low: DuringHpdLow) -> Self {
Self {
scdc_during_hpd_low,
..self
}
}
#[must_use]
pub const fn with_edid_during_hpd_low(self, edid_during_hpd_low: DuringHpdLow) -> Self {
Self {
edid_during_hpd_low,
..self
}
}
#[must_use]
pub const fn with_scrambling_lock(self, scrambling_lock: Trigger) -> Self {
Self {
scrambling_lock,
..self
}
}
#[must_use]
pub const fn with_strict_lock(self, strict_lock: bool) -> Self {
Self {
strict_lock,
..self
}
}
#[must_use]
pub const fn with_scrambling_refusals(self, refusal: Refusal) -> Self {
Self { refusal, ..self }
}
#[must_use]
pub const fn with_enable_timeout(self, enable_timeout: Option<Duration>) -> Self {
Self {
enable_timeout,
..self
}
}
#[must_use]
pub const fn with_hpd_reset(mut self, group: RegisterGroup, reset: HpdReset) -> Self {
self.hpd_resets[group.index()] = reset;
self
}
#[must_use]
pub const fn with_status_update(self, status_update: StatusUpdate) -> Self {
Self {
status_update,
..self
}
}
#[must_use]
pub const fn with_ced_update(self, ced_update: CedUpdate) -> Self {
Self { ced_update, ..self }
}
#[must_use]
pub const fn with_ced_read(self, ced_read: CedRead) -> Self {
Self { ced_read, ..self }
}
#[must_use]
pub const fn with_during_read(self, during_read: DuringRead) -> Self {
Self {
during_read,
..self
}
}
#[must_use]
pub const fn with_max_frl_rate(self, max_frl_rate: Option<HdmiForumFrl>) -> Self {
Self {
max_frl_rate,
..self
}
}
#[must_use]
pub const fn with_ltp_requests(self, ltp_requests: LanePatterns) -> Self {
Self {
ltp_requests,
..self
}
}
#[must_use]
pub const fn with_lts3_timeout(self, lts3_timeout: Option<Duration>) -> Self {
Self {
lts3_timeout,
..self
}
}
#[must_use]
pub const fn with_frl_pass(self, frl_pass: FrlPass) -> Self {
Self { frl_pass, ..self }
}
#[must_use]
pub const fn with_max_tmds_rate_khz(self, max_tmds_rate_khz: Option<u32>) -> Self {
Self {
max_tmds_rate_khz,
..self
}
}
pub const fn has_scdc(&self) -> bool {
self.scdc
}
pub const fn sink_version(&self) -> u8 {
self.sink_version
}
pub const fn owned_scdc_writes(&self) -> OwnedWrite {
self.owned_scdc_write
}
pub const fn scdc_past_end(&self) -> ScdcPastEnd {
self.scdc_past_end
}
pub const fn has_segment_pointer(&self) -> bool {
self.segment_pointer
}
pub const fn past_store(&self) -> PastStore {
self.past_store
}
pub const fn missing_segment(&self) -> MissingSegment {
self.missing_segment
}
pub const fn block_boundary(&self) -> BlockBoundary {
self.block_boundary
}
pub const fn scrambling_lock(&self) -> Trigger {
self.scrambling_lock
}
pub const fn strict_lock(&self) -> bool {
self.strict_lock
}
pub const fn scrambling_refusals(&self) -> Refusal {
self.refusal
}
pub const fn enable_timeout(&self) -> Option<Duration> {
self.enable_timeout
}
pub const fn hpd_reset(&self, group: RegisterGroup) -> HpdReset {
self.hpd_resets[group.index()]
}
pub const fn scdc_during_hpd_low(&self) -> DuringHpdLow {
self.scdc_during_hpd_low
}
pub const fn edid_during_hpd_low(&self) -> DuringHpdLow {
self.edid_during_hpd_low
}
pub const fn status_update(&self) -> StatusUpdate {
self.status_update
}
pub const fn ced_update(&self) -> CedUpdate {
self.ced_update
}
pub const fn ced_read(&self) -> CedRead {
self.ced_read
}
pub const fn during_read(&self) -> DuringRead {
self.during_read
}
pub const fn max_frl_rate(&self) -> Option<HdmiForumFrl> {
self.max_frl_rate
}
pub const fn ltp_requests(&self) -> LanePatterns {
self.ltp_requests
}
pub const fn lts3_timeout(&self) -> Option<Duration> {
self.lts3_timeout
}
pub const fn frl_pass(&self) -> FrlPass {
self.frl_pass
}
pub const fn max_tmds_rate_khz(&self) -> Option<u32> {
self.max_tmds_rate_khz
}
}
impl Default for SinkConfig {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum OwnedWrite {
Ignore,
Nack,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ScdcPastEnd {
Wrap,
Nack,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum PastStore {
Fill,
Wrap,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum MissingSegment {
Nack,
Ack,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlockBoundary {
Continue,
Wrap,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DuringHpdLow {
Answers,
Silent,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Trigger {
After(Duration),
AfterReads(u32),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct Refusal {
pub kind: RefusalKind,
pub attempts: u32,
}
impl Refusal {
pub const NONE: Self = Self {
kind: RefusalKind::WithholdStatus,
attempts: 0,
};
pub const fn new(kind: RefusalKind, attempts: u32) -> Self {
Self { kind, attempts }
}
}
impl Default for Refusal {
fn default() -> Self {
Self::NONE
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum RefusalKind {
WithholdStatus,
DropEnable,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum StatusUpdate {
OnChange,
Never,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum CedUpdate {
EverySecond {
rise: u16,
},
Never,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum CedRead {
Keep,
ClearOnRead,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DuringRead {
Held,
Moving,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum FrlPass {
Patterns,
Unchecked,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum RegisterGroup {
TmdsConfig,
Status,
SourceVersion,
Config,
ErrorCounters,
}
impl RegisterGroup {
pub const ALL: &'static [Self] = &[
Self::TmdsConfig,
Self::Status,
Self::SourceVersion,
Self::Config,
Self::ErrorCounters,
];
pub(crate) const COUNT: usize = 5;
pub(crate) const fn index(self) -> usize {
match self {
Self::TmdsConfig => 0,
Self::Status => 1,
Self::SourceVersion => 2,
Self::Config => 3,
Self::ErrorCounters => 4,
}
}
pub const fn registers(self) -> &'static [u8] {
match self {
Self::TmdsConfig => &[0x20],
Self::Status => &[0x21, 0x10, 0x11, 0x40, 0x41, 0x42],
Self::SourceVersion => &[0x02],
Self::Config => &[0x30, 0x31],
Self::ErrorCounters => &[
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
],
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum HpdReset {
After(Duration),
OnHpdLow,
OnHpdRise,
Never,
}