use core::time::Duration;
use hdmi_hal::ddc::DdcErrorKind;
use hdmi_hal::phy::TmdsVideo;
use hdmi_hal::time::Timestamp;
use crate::config::{BringUpConfig, SinkPresence, TearDownConfig};
use crate::outcome::{ReconnectCheck, SinkClear};
use crate::params::TmdsLinkParams;
use crate::types::ClockRatio;
use crate::types::{SinkTmdsConfig, SinkTmdsFacts, TmdsConfigReading};
pub const MAX_BRING_UP_EVENTS: usize =
1 + 2 + 2 + 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + MAX_TEAR_DOWN_EVENTS + 1;
pub const MAX_TEAR_DOWN_EVENTS: usize = 5;
pub const MAX_RECONNECT_CHECK_EVENTS: usize = 3;
pub const MAX_QUICK_RESTORE_EVENTS: usize = 5;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TmdsEvent {
pub at: Timestamp,
pub kind: TmdsEventKind,
}
impl TmdsEvent {
#[must_use]
pub const fn new(at: Timestamp, kind: TmdsEventKind) -> Self {
Self { at, kind }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TmdsEventKind {
#[non_exhaustive]
TearDownStarted {
link: TmdsLinkParams,
config: TearDownConfig,
presence: SinkPresence,
},
#[non_exhaustive]
TmdsConfigWritten {
config: SinkTmdsConfig,
},
#[non_exhaustive]
SinkClearSkipped {
reason: SinkClearSkip,
},
#[non_exhaustive]
ScramblerSet {
enabled: bool,
},
OutputStopped,
#[non_exhaustive]
ScdcStepFailed {
step: TmdsStep,
kind: DdcErrorKind,
ends: bool,
},
#[non_exhaustive]
PhyStepFailed {
step: TmdsStep,
ends: bool,
},
#[non_exhaustive]
BringUpStarted {
link: TmdsLinkParams,
video: TmdsVideo,
config: BringUpConfig,
},
#[non_exhaustive]
TmdsConfigSkipped {
reason: TmdsConfigSkip,
},
#[non_exhaustive]
PhyConfigured {
character_rate_khz: u32,
clock_ratio: ClockRatio,
},
#[non_exhaustive]
WaitSpent {
duration: Duration,
},
#[non_exhaustive]
OutputStarted {
after_write: Option<Duration>,
},
#[non_exhaustive]
DeadlineMissed {
by: Duration,
},
#[non_exhaustive]
ScramblingChecked {
check: crate::outcome::ScramblingCheck<DdcErrorKind>,
},
#[non_exhaustive]
VideoMismatch {
link_rate_khz: u32,
video_rate_khz: Option<u32>,
},
#[non_exhaustive]
BringUpCancelled {
at: CancelPoint,
},
#[non_exhaustive]
BringUpEnded {
failed_at: Option<TmdsStep>,
cancelled: bool,
},
FrlRateCleared,
#[non_exhaustive]
FltUpdateCleared {
was_set: bool,
},
#[non_exhaustive]
FrlClearSkipped {
reason: FrlClearSkip,
},
#[non_exhaustive]
SinkVersionRead {
version: u8,
},
#[non_exhaustive]
SourceVersionWritten {
version: u8,
},
#[non_exhaustive]
SourceVersionSkipped {
reason: SourceVersionSkip,
},
#[non_exhaustive]
ReconnectCheckStarted {
link: TmdsLinkParams,
current_sink: SinkTmdsFacts,
},
#[non_exhaustive]
TmdsConfigRead {
reading: TmdsConfigReading,
},
#[non_exhaustive]
ReconnectCheckEnded {
result: ReconnectCheck<DdcErrorKind>,
},
#[non_exhaustive]
QuickRestoreStarted {
link: TmdsLinkParams,
config: BringUpConfig,
},
#[non_exhaustive]
QuickRestoreEnded {
failed_at: Option<TmdsStep>,
},
#[non_exhaustive]
TearDownEnded {
sink: SinkClear<DdcErrorKind>,
scrambler_failed: bool,
output_failed: bool,
},
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TmdsStep {
ClearFrlRate,
ClearFltUpdate,
SinkVersion,
SourceVersion,
WriteTmdsConfig,
ReadTmdsConfig,
Configure,
SetScrambling,
StartOutput,
StopOutput,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CancelPoint {
Entry,
Step(TmdsStep),
RatioWait,
Check,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TmdsConfigSkip {
NoScdc,
Gate,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FrlClearSkip {
NoScdc,
SinkDeclaresNoFrl,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SourceVersionSkip {
NoScdc,
Never,
NotScrambled,
#[non_exhaustive]
SinkVersion {
version: u8,
},
SinkVersionUnread,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SinkClearSkip {
NotRequested,
NothingToClear,
SinkGone,
}
#[cfg(test)]
mod tests {
use super::*;
fn is_copy<T: Copy>(_: T) {}
#[test]
fn events_are_copy_and_carry_no_error_values() {
let event = TmdsEvent::new(
Timestamp::from_micros(5),
TmdsEventKind::ScdcStepFailed {
step: TmdsStep::WriteTmdsConfig,
kind: DdcErrorKind::Busy,
ends: false,
},
);
is_copy(event);
let copy = event;
assert_eq!(copy, event);
assert_eq!(event.at, Timestamp::from_micros(5));
}
}