spiritlevel 0.2.0

TMDS link bring-up for HDMI sources: clock ratio, scrambling and sink configuration
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
//! The sync driver: [`TmdsLink`] runs the procedures over a [`TmdsScdc`], a `TmdsPhy`, a
//! `Clock` and a `Delay`, with an optional [`Cancel`] flag.

use core::future::Future;
use core::pin::pin;
use core::task::{Context, Poll, Waker};
use core::time::Duration;

use hdmi_hal::cancel::{Cancel, NoCancel};
use hdmi_hal::phy::{TmdsPhy, TmdsPhyConfig, TmdsVideo};
use hdmi_hal::time::{Clock, Delay, Timestamp};

use crate::config::{BringUpConfig, SinkPresence, TearDownConfig};
use crate::error::UpdateError;
use crate::event::TmdsEvent;
use crate::outcome::{
    BringUpError, BringUpOutcome, ReconnectCheck, RestoreError, Restored, TearDownError, TornDown,
};
use crate::params::TmdsLinkParams;
use crate::procedure::{self, TmdsIo};
use crate::scdc::TmdsScdc;
use crate::types::{ScramblingStatus, SinkTmdsConfig, SinkTmdsFacts, TmdsConfigReading};

/// What a tear-down returns, over the parts' error types.
type TearDownResult<S, P> = Result<
    TornDown<<S as TmdsScdc>::Error>,
    TearDownError<<S as TmdsScdc>::Error, <P as TmdsPhy>::Error>,
>;

/// What a bring-up returns, over the parts' error types.
type BringUpResult<S, P> = Result<
    BringUpOutcome<<S as TmdsScdc>::Error, <P as TmdsPhy>::Error>,
    BringUpError<<S as TmdsScdc>::Error, <P as TmdsPhy>::Error>,
>;

/// What a quick restore returns, over the parts' error types.
type RestoreResult<S, P> = Result<
    Restored<<S as TmdsScdc>::Error>,
    RestoreError<<S as TmdsScdc>::Error, <P as TmdsPhy>::Error>,
>;

/// The TMDS procedures over sync parts: the sink's SCDC, the PHY, a clock and a delay, and a
/// cancel flag ([`NoCancel`] unless [`with_cancel`](Self::with_cancel) gives one).
///
/// Each procedure runs to completion before it returns: the parts' calls complete at once,
/// and the delay blocks. One clock-and-delay value can serve as both: implement `Clock` and
/// `Delay` for a reference to it, and pass the reference twice.
#[derive(Debug)]
pub struct TmdsLink<S, P, K, D, X = NoCancel> {
    scdc: S,
    phy: P,
    clock: K,
    delay: D,
    cancel: X,
}

impl<S: TmdsScdc, P: TmdsPhy, K: Clock, D: Delay> TmdsLink<S, P, K, D, NoCancel> {
    /// The driver over its parts, never cancelled.
    pub fn new(scdc: S, phy: P, clock: K, delay: D) -> Self {
        Self {
            scdc,
            phy,
            clock,
            delay,
            cancel: NoCancel,
        }
    }
}

impl<S: TmdsScdc, P: TmdsPhy, K: Clock, D: Delay, X: Cancel> TmdsLink<S, P, K, D, X> {
    /// The same driver with `cancel` as its cancel flag.
    pub fn with_cancel<X2: Cancel>(self, cancel: X2) -> TmdsLink<S, P, K, D, X2> {
        TmdsLink {
            scdc: self.scdc,
            phy: self.phy,
            clock: self.clock,
            delay: self.delay,
            cancel,
        }
    }

    /// The parts back.
    pub fn into_parts(self) -> (S, P, K, D, X) {
        (self.scdc, self.phy, self.clock, self.delay, self.cancel)
    }

    /// The SCDC client.
    pub fn scdc(&self) -> &S {
        &self.scdc
    }

    /// The SCDC client, mutably: between procedures, for reads of the caller's own.
    pub fn scdc_mut(&mut self) -> &mut S {
        &mut self.scdc
    }

    /// The PHY.
    pub fn phy(&self) -> &P {
        &self.phy
    }

    /// The PHY, mutably: between procedures, to power it on or off, read its capabilities, or
    /// drive it in another mode.
    pub fn phy_mut(&mut self) -> &mut P {
        &mut self.phy
    }

    /// The clock the procedures stamp their events from, so a caller can stamp its own on
    /// the same timebase.
    pub fn clock(&self) -> &K {
        &self.clock
    }

    /// Stops the TMDS link `link` describes; see [`procedure::tear_down`].
    ///
    /// # Errors
    ///
    /// [`TearDownError`] when a PHY step failed; every step was still attempted.
    pub fn tear_down(
        &mut self,
        link: &TmdsLinkParams,
        config: &TearDownConfig,
        presence: SinkPresence,
    ) -> TearDownResult<S, P> {
        self.tear_down_with_events(link, config, presence, &mut |_| {})
    }

    /// [`tear_down`](Self::tear_down), calling `record` with each event.
    ///
    /// # Errors
    ///
    /// As [`tear_down`](Self::tear_down).
    pub fn tear_down_with_events(
        &mut self,
        link: &TmdsLinkParams,
        config: &TearDownConfig,
        presence: SinkPresence,
        record: &mut impl FnMut(TmdsEvent),
    ) -> TearDownResult<S, P> {
        block_on(procedure::tear_down(
            &mut SyncIo(self),
            link,
            config,
            presence,
            record,
        ))
    }
}

impl<S: TmdsScdc, P: TmdsPhy, K: Clock, D: Delay, X: Cancel> TmdsLink<S, P, K, D, X> {
    /// Brings up the TMDS link `link` describes, carrying `video`; see
    /// [`procedure::bring_up`].
    ///
    /// # Errors
    ///
    /// [`BringUpError`] when a step failed in a way that stops the bring-up.
    pub fn bring_up(
        &mut self,
        link: &TmdsLinkParams,
        video: TmdsVideo,
        config: &BringUpConfig,
    ) -> BringUpResult<S, P> {
        self.bring_up_with_events(link, video, config, &mut |_| {})
    }

    /// [`bring_up`](Self::bring_up), calling `record` with each event.
    ///
    /// # Errors
    ///
    /// As [`bring_up`](Self::bring_up).
    pub fn bring_up_with_events(
        &mut self,
        link: &TmdsLinkParams,
        video: TmdsVideo,
        config: &BringUpConfig,
        record: &mut impl FnMut(TmdsEvent),
    ) -> BringUpResult<S, P> {
        block_on(procedure::bring_up(
            &mut SyncIo(self),
            link,
            video,
            config,
            record,
        ))
    }

    /// Checks whether the sink still holds the `TMDS_Config` `link` needs; see
    /// [`procedure::check_reconnect`].
    pub fn check_reconnect(
        &mut self,
        link: &TmdsLinkParams,
        current_sink: SinkTmdsFacts,
    ) -> ReconnectCheck<S::Error> {
        self.check_reconnect_with_events(link, current_sink, &mut |_| {})
    }

    /// [`check_reconnect`](Self::check_reconnect), calling `record` with each event.
    pub fn check_reconnect_with_events(
        &mut self,
        link: &TmdsLinkParams,
        current_sink: SinkTmdsFacts,
        record: &mut impl FnMut(TmdsEvent),
    ) -> ReconnectCheck<S::Error> {
        block_on(procedure::check_reconnect(
            &mut SyncIo(self),
            link,
            current_sink,
            record,
        ))
    }

    /// Restores the sink's `TMDS_Config` on the running link; see
    /// [`procedure::quick_restore`].
    ///
    /// # Errors
    ///
    /// [`RestoreError`] when the sink's write or the scrambler call failed in a way that
    /// stops it.
    pub fn quick_restore(
        &mut self,
        link: &TmdsLinkParams,
        config: &BringUpConfig,
    ) -> RestoreResult<S, P> {
        self.quick_restore_with_events(link, config, &mut |_| {})
    }

    /// [`quick_restore`](Self::quick_restore), calling `record` with each event.
    ///
    /// # Errors
    ///
    /// As [`quick_restore`](Self::quick_restore).
    pub fn quick_restore_with_events(
        &mut self,
        link: &TmdsLinkParams,
        config: &BringUpConfig,
        record: &mut impl FnMut(TmdsEvent),
    ) -> RestoreResult<S, P> {
        block_on(procedure::quick_restore(
            &mut SyncIo(self),
            link,
            config,
            record,
        ))
    }
}

/// Polls `future` once: the sync parts' calls complete at once, so it is ready.
fn block_on<T>(future: impl Future<Output = T>) -> T {
    let mut future = pin!(future);
    match future
        .as_mut()
        .poll(&mut Context::from_waker(Waker::noop()))
    {
        Poll::Ready(output) => output,
        Poll::Pending => unreachable!("spiritlevel's sync driver waited on I/O"),
    }
}

/// [`TmdsIo`] over a [`TmdsLink`]'s parts: each operation is the sync call itself.
struct SyncIo<'a, S, P, K, D, X>(&'a mut TmdsLink<S, P, K, D, X>);

impl<S: TmdsScdc, P: TmdsPhy, K: Clock, D: Delay, X: Cancel> TmdsIo for SyncIo<'_, S, P, K, D, X> {
    type ScdcError = S::Error;
    type PhyError = P::Error;

    async fn write_tmds_config(&mut self, config: SinkTmdsConfig) -> Result<(), S::Error> {
        self.0.scdc.write_tmds_config(config)
    }

    async fn update_tmds_config(
        &mut self,
        config: SinkTmdsConfig,
    ) -> Result<(), UpdateError<S::Error>> {
        self.0.scdc.update_tmds_config(config)
    }

    async fn read_tmds_config(&mut self) -> Result<TmdsConfigReading, S::Error> {
        self.0.scdc.read_tmds_config()
    }

    async fn read_scrambling_status(&mut self) -> Result<ScramblingStatus, S::Error> {
        self.0.scdc.read_scrambling_status()
    }

    async fn read_sink_version(&mut self) -> Result<u8, S::Error> {
        self.0.scdc.read_sink_version()
    }

    async fn write_source_version(&mut self, version: u8) -> Result<(), S::Error> {
        self.0.scdc.write_source_version(version)
    }

    async fn clear_frl_rate(&mut self) -> Result<(), S::Error> {
        self.0.scdc.clear_frl_rate()
    }

    async fn clear_flt_update(&mut self) -> Result<bool, UpdateError<S::Error>> {
        self.0.scdc.clear_flt_update()
    }

    async fn configure(&mut self, config: TmdsPhyConfig) -> Result<(), P::Error> {
        self.0.phy.configure(config)
    }

    async fn set_scrambling(&mut self, enabled: bool) -> Result<(), P::Error> {
        self.0.phy.set_scrambling(enabled)
    }

    async fn start_output(&mut self) -> Result<(), P::Error> {
        self.0.phy.start_output()
    }

    async fn stop_output(&mut self) -> Result<(), P::Error> {
        self.0.phy.stop_output()
    }

    fn now(&self) -> Timestamp {
        self.0.clock.now()
    }

    async fn delay(&mut self, duration: Duration) {
        self.0.delay.delay(duration);
    }

    fn cancelled(&self) -> bool {
        self.0.cancel.is_cancelled()
    }
}

#[cfg(test)]
mod tests {
    use core::cell::Cell;

    use hdmi_hal::ddc::DdcErrorKind;
    use hdmi_hal::phy::TmdsPhyCapabilities;

    use core::sync::atomic::{AtomicBool, Ordering};

    use super::*;
    use crate::outcome::SinkClear;
    use crate::types::{SinkTmdsFacts, SourceTmdsFacts, TmdsPolicy};

    /// The sink's registers that matter here: `TMDS_Config`, the version registers and the
    /// FRL clear's.
    #[derive(Default)]
    struct Sink {
        tmds_config: u8,
        sink_version: u8,
        source_version: u8,
        flt_update: bool,
        frl_clears: u32,
        writes: u32,
    }

    impl TmdsScdc for Sink {
        type Error = DdcErrorKind;

        fn write_tmds_config(&mut self, c: SinkTmdsConfig) -> Result<(), DdcErrorKind> {
            self.writes += 1;
            self.tmds_config =
                u8::from(c.scrambling_enable) | (u8::from(c.high_tmds_clock_ratio) << 1);
            Ok(())
        }

        fn update_tmds_config(
            &mut self,
            c: SinkTmdsConfig,
        ) -> Result<(), UpdateError<DdcErrorKind>> {
            self.write_tmds_config(c).map_err(UpdateError::Write)
        }

        fn read_tmds_config(&mut self) -> Result<TmdsConfigReading, DdcErrorKind> {
            let raw = self.tmds_config;
            Ok(TmdsConfigReading::new(
                SinkTmdsConfig::new(raw & 1 != 0, raw & 2 != 0),
                raw,
            ))
        }

        fn read_scrambling_status(&mut self) -> Result<ScramblingStatus, DdcErrorKind> {
            Ok(ScramblingStatus::new(true, 1))
        }

        fn read_sink_version(&mut self) -> Result<u8, DdcErrorKind> {
            Ok(self.sink_version)
        }

        fn write_source_version(&mut self, version: u8) -> Result<(), DdcErrorKind> {
            self.source_version = version;
            Ok(())
        }

        fn clear_frl_rate(&mut self) -> Result<(), DdcErrorKind> {
            self.frl_clears += 1;
            Ok(())
        }

        fn clear_flt_update(&mut self) -> Result<bool, UpdateError<DdcErrorKind>> {
            Ok(core::mem::take(&mut self.flt_update))
        }
    }

    /// A PHY that tracks whether it transmits and scrambles.
    #[derive(Default)]
    struct Phy {
        output: bool,
        scrambling: bool,
        configured: Option<TmdsPhyConfig>,
    }

    impl TmdsPhy for Phy {
        type Error = ();

        fn capabilities(&self) -> TmdsPhyCapabilities {
            TmdsPhyCapabilities::new(600_000).with_scrambling(true)
        }

        fn configure(&mut self, config: TmdsPhyConfig) -> Result<(), ()> {
            self.configured = Some(config);
            Ok(())
        }

        fn set_scrambling(&mut self, enabled: bool) -> Result<(), ()> {
            self.scrambling = enabled;
            Ok(())
        }

        fn start_output(&mut self) -> Result<(), ()> {
            self.output = true;
            Ok(())
        }

        fn stop_output(&mut self) -> Result<(), ()> {
            self.output = false;
            Ok(())
        }
    }

    /// One time source as both clock and delay, shared by reference.
    #[derive(Default)]
    struct SimTime {
        now: Cell<u64>,
    }

    impl Clock for &SimTime {
        fn now(&self) -> Timestamp {
            Timestamp::from_micros(self.now.get())
        }
    }

    impl Delay for &SimTime {
        fn delay(&mut self, duration: Duration) {
            let micros = u64::try_from(duration.as_micros()).unwrap();
            self.now.set(self.now.get() + micros);
        }
    }

    fn scrambled() -> TmdsLinkParams {
        TmdsLinkParams::choose(
            594_000,
            SinkTmdsFacts::new(true, true, false),
            SourceTmdsFacts::from(&Phy::default().capabilities()),
            TmdsPolicy::DEFAULT,
        )
        .unwrap()
    }

    #[test]
    fn tear_down_runs_over_the_parts() {
        let time = SimTime::default();
        let sink = Sink {
            tmds_config: 0x03,
            ..Sink::default()
        };
        let phy = Phy {
            output: true,
            scrambling: true,
            ..Phy::default()
        };
        let mut link = TmdsLink::new(sink, phy, &time, &time);

        let mut events = 0;
        let result = link.tear_down_with_events(
            &scrambled(),
            &TearDownConfig::DEFAULT.with_clear_sink(true),
            SinkPresence::Present,
            &mut |_| events += 1,
        );
        assert_eq!(
            result,
            Ok(TornDown {
                sink: SinkClear::Cleared
            })
        );
        assert_eq!(events, crate::MAX_TEAR_DOWN_EVENTS);

        let (sink, phy, ..) = link.into_parts();
        assert_eq!(sink.tmds_config, 0);
        assert!(!phy.output && !phy.scrambling);
        assert_eq!(phy.configured, None);
    }

    #[test]
    fn bring_up_runs_over_the_parts() {
        let time = SimTime::default();
        let mut link = TmdsLink::new(Sink::default(), Phy::default(), &time, &time);
        let params = scrambled();
        let video = hdmi_hal::phy::TmdsVideo::new(
            594_000,
            hdmi_hal::ColorBitDepth::Depth8,
            hdmi_hal::ColorFormat::Rgb444,
        );
        let config = BringUpConfig::DEFAULT;
        assert!(matches!(
            link.bring_up(&params, video, &config),
            Ok(BringUpOutcome::Up(_))
        ));
        let mut events = 0;
        assert!(
            link.bring_up_with_events(&params, video, &config, &mut |_| events += 1)
                .is_ok()
        );
        assert!(events > 0 && events <= crate::MAX_BRING_UP_EVENTS);
        let (sink, phy, ..) = link.into_parts();
        assert_eq!(sink.tmds_config, 0x03);
        assert_eq!(sink.source_version, 1);
        assert!(phy.output && phy.scrambling);
        assert_eq!(
            phy.configured.map(|c| c.clock_ratio),
            Some(crate::ClockRatio::Div40)
        );
    }

    #[test]
    fn check_reconnect_runs_over_the_parts() {
        let time = SimTime::default();
        let sink = Sink {
            tmds_config: 0x03,
            ..Sink::default()
        };
        let mut link = TmdsLink::new(sink, Phy::default(), &time, &time);
        let params = scrambled();
        assert_eq!(
            link.check_reconnect(&params, params.sink()),
            ReconnectCheck::Matches
        );
        let mut events = 0;
        let result =
            link.check_reconnect_with_events(&params, SinkTmdsFacts::NONE, &mut |_| events += 1);
        assert_eq!(result, ReconnectCheck::SinkChanged);
        assert_eq!(events, 2);
    }

    #[test]
    fn quick_restore_runs_over_the_parts() {
        let time = SimTime::default();
        let mut link = TmdsLink::new(Sink::default(), Phy::default(), &time, &time);
        let restored = link
            .quick_restore(&scrambled(), &BringUpConfig::DEFAULT)
            .unwrap();
        assert_eq!(restored.check.result, crate::CheckResult::Set);
        let mut events = 0;
        assert!(
            link.quick_restore_with_events(&scrambled(), &BringUpConfig::DEFAULT, &mut |_| {
                events += 1;
            })
            .is_ok()
        );
        assert_eq!(events, crate::MAX_QUICK_RESTORE_EVENTS);
        let (sink, phy, ..) = link.into_parts();
        assert_eq!(sink.tmds_config, 0x03);
        assert!(phy.scrambling);
    }

    #[test]
    fn the_parts_are_reachable_between_procedures() {
        let time = SimTime::default();
        let mut link = TmdsLink::new(Sink::default(), Phy::default(), &time, &time);
        link.scdc_mut().source_version = 7;
        link.phy_mut().output = true;
        assert_eq!(link.scdc().source_version, 7);
        assert!(link.phy().output);
        assert_eq!(link.clock().now(), Timestamp::from_micros(0));
    }

    #[test]
    fn the_plain_form_and_a_cancel_flag() {
        let time = SimTime::default();
        let flag = AtomicBool::new(false);
        let mut link =
            TmdsLink::new(Sink::default(), Phy::default(), &time, &time).with_cancel(&flag);
        assert_eq!(
            link.tear_down(&scrambled(), &TearDownConfig::DEFAULT, SinkPresence::Gone),
            Ok(TornDown {
                sink: SinkClear::NotRequested
            })
        );
        // A flag that is not set lets a bring-up through.
        let video = hdmi_hal::phy::TmdsVideo::new(
            594_000,
            hdmi_hal::ColorBitDepth::Depth8,
            hdmi_hal::ColorFormat::Rgb444,
        );
        assert!(matches!(
            link.bring_up(&scrambled(), video, &BringUpConfig::DEFAULT),
            Ok(BringUpOutcome::Up(_))
        ));
        // Tear-down is the recovery: a set flag does not stop it.
        flag.store(true, Ordering::Relaxed);
        assert!(
            link.tear_down(&scrambled(), &TearDownConfig::DEFAULT, SinkPresence::Gone)
                .is_ok()
        );
        // A bring-up sees it at entry and makes no call.
        let video = hdmi_hal::phy::TmdsVideo::new(
            594_000,
            hdmi_hal::ColorBitDepth::Depth8,
            hdmi_hal::ColorFormat::Rgb444,
        );
        assert!(matches!(
            link.bring_up(&scrambled(), video, &BringUpConfig::DEFAULT),
            Ok(BringUpOutcome::Cancelled {
                at: crate::CancelPoint::Entry,
                cleanup: crate::Cleanup::Skipped,
                ..
            })
        ));
        let (sink, _, _, _, cancel) = link.into_parts();
        // The first bring-up's write; the cancelled one made none.
        assert_eq!(sink.writes, 1);
        assert!(cancel.is_cancelled());
        assert!(!NoCancel.is_cancelled());
    }

    #[test]
    fn the_sync_io_passes_every_call_through() {
        let time = SimTime::default();
        let sink = Sink {
            sink_version: 2,
            flt_update: true,
            ..Sink::default()
        };
        let mut link = TmdsLink::new(sink, Phy::default(), &time, &time);
        let mut io = SyncIo(&mut link);
        let video = hdmi_hal::phy::TmdsVideo::new(
            148_500,
            hdmi_hal::ColorBitDepth::Depth8,
            hdmi_hal::ColorFormat::Rgb444,
        );
        block_on(async {
            io.update_tmds_config(SinkTmdsConfig::new(true, false))
                .await
                .unwrap();
            assert_eq!(io.read_tmds_config().await.unwrap().raw, 1);
            assert!(io.read_scrambling_status().await.unwrap().set);
            assert_eq!(io.read_sink_version().await, Ok(2));
            io.write_source_version(1).await.unwrap();
            io.clear_frl_rate().await.unwrap();
            assert_eq!(io.clear_flt_update().await, Ok(true));
            assert_eq!(io.clear_flt_update().await, Ok(false));
            io.configure(TmdsPhyConfig::new(148_500, crate::ClockRatio::Div10, video))
                .await
                .unwrap();
            io.start_output().await.unwrap();
            let before = io.now();
            io.delay(Duration::from_millis(1)).await;
            assert_eq!(
                io.now().checked_duration_since(before),
                Some(Duration::from_millis(1))
            );
            assert!(!io.cancelled());
        });
        let (sink, phy, ..) = link.into_parts();
        assert_eq!((sink.source_version, sink.frl_clears), (1, 1));
        assert!(phy.output && phy.configured.is_some());
    }
}