use hdmi_hal::HdmiForumFrl;
use hdmi_hal::phy::{EqParams, FrlOutput, LanePatterns, TmdsClockRatio, TxFfeLevel};
pub(crate) const RATIO_40_ABOVE_KHZ: u32 = 340_000;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Line {
Off,
Tmds {
character_rate_khz: u32,
ratio: TmdsClockRatio,
scrambled: bool,
},
#[non_exhaustive]
Frl {
rate: HdmiForumFrl,
patterns: LanePatterns,
output: FrlOutput,
equalization: Option<EqParams>,
},
}
impl Line {
pub const fn frl(rate: HdmiForumFrl) -> Self {
Self::frl_with(
rate,
LanePatterns {
lane0: None,
lane1: None,
lane2: None,
lane3: None,
},
FrlOutput::GapOnly,
)
}
pub const fn frl_with(rate: HdmiForumFrl, patterns: LanePatterns, output: FrlOutput) -> Self {
Self::Frl {
rate,
patterns,
output,
equalization: None,
}
}
#[must_use]
pub const fn with_equalization(self, equalization: EqParams) -> Self {
match self {
Self::Frl {
rate,
patterns,
output,
..
} => Self::Frl {
rate,
patterns,
output,
equalization: Some(equalization),
},
other => other,
}
}
}
impl Default for Line {
fn default() -> Self {
Self::Off
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct ErrorRates {
pub lane0: u32,
pub lane1: u32,
pub lane2: u32,
pub lane3: u32,
pub rs_corrections: u32,
}
impl ErrorRates {
pub const NONE: Self = Self {
lane0: 0,
lane1: 0,
lane2: 0,
lane3: 0,
rs_corrections: 0,
};
pub const fn all(per_second: u32) -> Self {
Self {
lane0: per_second,
lane1: per_second,
lane2: per_second,
lane3: per_second,
rs_corrections: 0,
}
}
#[must_use]
pub const fn with_lane0(self, per_second: u32) -> Self {
Self {
lane0: per_second,
..self
}
}
#[must_use]
pub const fn with_lane1(self, per_second: u32) -> Self {
Self {
lane1: per_second,
..self
}
}
#[must_use]
pub const fn with_lane2(self, per_second: u32) -> Self {
Self {
lane2: per_second,
..self
}
}
#[must_use]
pub const fn with_lane3(self, per_second: u32) -> Self {
Self {
lane3: per_second,
..self
}
}
#[must_use]
pub const fn with_rs_corrections(self, per_second: u32) -> Self {
Self {
rs_corrections: per_second,
..self
}
}
pub(crate) const fn lanes(self) -> [u32; 4] {
[self.lane0, self.lane1, self.lane2, self.lane3]
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct LaneLimits {
pub max_rate: Option<HdmiForumFrl>,
pub min_tx_ffe: TxFfeLevel,
}
impl LaneLimits {
pub const NONE: Self = Self {
max_rate: None,
min_tx_ffe: match TxFfeLevel::new(0) {
Some(level) => level,
None => unreachable!(),
},
};
#[must_use]
pub const fn with_max_rate(self, max_rate: Option<HdmiForumFrl>) -> Self {
Self { max_rate, ..self }
}
#[must_use]
pub const fn with_min_tx_ffe(self, min_tx_ffe: TxFfeLevel) -> Self {
Self { min_tx_ffe, ..self }
}
}
impl Default for LaneLimits {
fn default() -> Self {
Self::NONE
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct LinkLanes {
pub lane0: LaneLimits,
pub lane1: LaneLimits,
pub lane2: LaneLimits,
pub lane3: LaneLimits,
}
impl LinkLanes {
pub const NONE: Self = Self::all(LaneLimits::NONE);
pub const fn all(limits: LaneLimits) -> Self {
Self {
lane0: limits,
lane1: limits,
lane2: limits,
lane3: limits,
}
}
pub(crate) const fn lanes(self) -> [LaneLimits; 4] {
[self.lane0, self.lane1, self.lane2, self.lane3]
}
}