Skip to main content

mx_remote/wire/
enums.rs

1// Author: Lars Op den Kamp (lars@opdenkamp-it.nl)
2// Copyright (c) 2026 Op den Kamp IT Solutions
3
4//! Wire enumerations and bitmasks.
5//!
6//! Each type is a newtype over the integer that travels on the wire, with
7//! named constants rather than a closed set of variants. A value this library
8//! has no name for reaches the caller as it arrived: zero is a valid value for
9//! most of these, so a confidently wrong reading is worse than an unrecognised
10//! one.
11
12use core::fmt;
13use core::ops::{BitAnd, BitOr, BitOrAssign};
14
15/// Declares a bitmask newtype with the given named bit constants.
16///
17/// The representation defaults to `u32`; give it explicitly as `Name: u64` for
18/// a mask whose wire field is wider.
19macro_rules! bitmask {
20    (
21        $(#[$meta:meta])*
22        $name:ident { $( $(#[$cmeta:meta])* $cname:ident = $value:expr; )* }
23    ) => {
24        bitmask! {
25            $(#[$meta])*
26            $name: u32 { $( $(#[$cmeta])* $cname = $value; )* }
27        }
28    };
29    (
30        $(#[$meta:meta])*
31        $name:ident: $repr:ty { $( $(#[$cmeta:meta])* $cname:ident = $value:expr; )* }
32    ) => {
33        $(#[$meta])*
34        #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
35        pub struct $name($repr);
36
37        impl $name {
38            /// No bits set.
39            pub const NONE: Self = Self(0);
40
41            $( $(#[$cmeta])* pub const $cname: Self = Self($value); )*
42
43            /// Wraps a raw wire value, including bits this library has no name for.
44            pub const fn from_bits(bits: $repr) -> Self {
45                Self(bits)
46            }
47
48            /// Returns the raw wire value.
49            pub const fn bits(self) -> $repr {
50                self.0
51            }
52
53            /// Reports whether every bit in `other` is set.
54            pub const fn has(self, other: Self) -> bool {
55                self.0 & other.0 == other.0
56            }
57
58            /// Reports whether no bit is set.
59            pub const fn is_empty(self) -> bool {
60                self.0 == 0
61            }
62        }
63
64        impl BitOr for $name {
65            type Output = Self;
66            fn bitor(self, rhs: Self) -> Self {
67                Self(self.0 | rhs.0)
68            }
69        }
70
71        impl BitOrAssign for $name {
72            fn bitor_assign(&mut self, rhs: Self) {
73                self.0 |= rhs.0;
74            }
75        }
76
77        impl BitAnd for $name {
78            type Output = Self;
79            fn bitand(self, rhs: Self) -> Self {
80                Self(self.0 & rhs.0)
81            }
82        }
83
84        impl fmt::Display for $name {
85            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86                // Two hex digits per byte of the wire field, plus "0x".
87                write!(
88                    f,
89                    "{:#0width$x}",
90                    self.0,
91                    width = core::mem::size_of::<$repr>() * 2 + 2
92                )
93            }
94        }
95    };
96}
97
98/// Declares an enumeration newtype over `$repr` with the given named constants.
99macro_rules! wire_enum {
100    (
101        $(#[$meta:meta])*
102        $name:ident: $repr:ty { $( $(#[$cmeta:meta])* $cname:ident = $value:expr; )* }
103    ) => {
104        $(#[$meta])*
105        #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
106        pub struct $name($repr);
107
108        impl $name {
109            $( $(#[$cmeta])* pub const $cname: Self = Self($value); )*
110
111            /// Wraps a raw wire value, including one this library has no name for.
112            pub const fn from_wire(value: $repr) -> Self {
113                Self(value)
114            }
115
116            /// Returns the raw wire value.
117            pub const fn to_wire(self) -> $repr {
118                self.0
119            }
120        }
121    };
122}
123
124bitmask! {
125    /// Capabilities a device reports in its hello frame.
126    DeviceFeature {
127        /// Receives infrared.
128        IR_RX = 1 << 0;
129        /// Transmits infrared.
130        IR_TX = 1 << 1;
131        /// Speaks CEC.
132        CEC = 1 << 2;
133        /// Acts as a V2IP stream source.
134        V2IP_SOURCE = 1 << 3;
135        /// Acts as a V2IP stream sink.
136        V2IP_SINK = 1 << 4;
137        /// Routes video.
138        VIDEO_ROUTING = 1 << 5;
139        /// Routes audio.
140        AUDIO_ROUTING = 1 << 6;
141        /// Controls volume.
142        VOLUME_CONTROL = 1 << 7;
143        /// Supports audio return.
144        AUDIO_RETURN = 1 << 8;
145        /// Passes remote-control commands through.
146        REMOTE_CONTROL = 1 << 9;
147        /// Installer setup has been completed.
148        SETUP_COMPLETED = 1 << 10;
149        /// Is the master of its mesh.
150        MESH_MASTER = 1 << 11;
151        /// Has a notification pending.
152        STATUS_NOTIFY = 1 << 12;
153        /// Has a warning pending.
154        STATUS_WARNING = 1 << 13;
155        /// Has an error pending.
156        STATUS_ERROR = 1 << 14;
157        /// Is about to reboot.
158        STATUS_REBOOT = 1 << 15;
159        /// Is a member of a mesh.
160        MESH_MEMBER = 1 << 16;
161        /// Is an audio amplifier.
162        AUDIO_AMPLIFIER = 1 << 17;
163        /// Is still booting.
164        BOOTING = 1 << 18;
165        /// Is a management client rather than a device.
166        MANAGER = 1 << 19;
167        /// Is in power-save mode.
168        STATUS_POWER_SAVE = 1 << 20;
169        /// Supports meshing.
170        MESH = 1 << 21;
171        /// Is a multiviewer.
172        MULTIVIEWER = 1 << 22;
173        /// Has crashed since it last booted.
174        STATUS_CRASHED = 1 << 23;
175        /// Supports video walls.
176        VIDEO_WALL = 1 << 24;
177        /// Initialises the configuration it broadcasts.
178        ///
179        /// Firmware without this bit sends a device configuration built over
180        /// uninitialised memory, so fields it did not mean to write carry junk.
181        CONFIG_INITIALISED = 1 << 25;
182        /// Receives one or more peers only by broadcast, because its multicast
183        /// receive path is faulty.
184        STATUS_MCAST_FAULT = 1 << 26;
185        /// Powers its video processor down in power save. A device without it
186        /// refuses to enter power save.
187        POWER_SAVE = 1 << 27;
188        /// Tags its uplink by the VLAN configuration it reports, and takes one
189        /// written to it.
190        VLAN = 1 << 28;
191        /// Copies the overlay settings and logos of another unit when asked.
192        OSD_SYNC = 1 << 29;
193        /// Is downloading or installing a firmware or video processor
194        /// upgrade. [`STATUS_REBOOT`](Self::STATUS_REBOOT) follows when it
195        /// reboots to complete it.
196        STATUS_UPGRADING = 1 << 30;
197        /// Flips on every reboot, so a peer that sees it change knows the device restarted.
198        BOOT_BIT = 1 << 31;
199    }
200}
201
202bitmask! {
203    /// What a V2IP device's video processor supports, as the device reports it
204    /// in its configuration.
205    ///
206    /// Read-only, and a device's own: it fills the field in only on the frame
207    /// describing itself, and leaves it zero on one it sends to configure
208    /// another device. There is no write path.
209    ///
210    /// Bits are assigned by the video processor and only ever appended, so a
211    /// bit this library has no name for is a later capability rather than an
212    /// error. A device reports no features at all until its processor answers,
213    /// and an older processor answers with none of the optional commands, so an
214    /// empty mask is never reported as a capability set - see
215    /// [`crate::Remote::v2ip_features`], which reports it as unknown instead.
216    V2ipFpgaFeature: u64 {
217        /// Applies a DSCP marking to the streams it sources.
218        SOURCE_DSCP = 1 << 0;
219        /// Reports the audio format arriving at its sink.
220        SINK_AUDIO_FORMAT = 1 << 1;
221        /// Places a tiling window on its sink.
222        SINK_TILING_WINDOW = 1 << 2;
223        /// Reports the state of its sink's overlay.
224        SINK_OVERLAY_STATE = 1 << 3;
225        /// Reports its sink's state.
226        SINK_STATE = 1 << 4;
227        /// Reports information about the stream its sink receives.
228        SINK_STREAM_INFO = 1 << 5;
229        /// Draws a test pattern, tone and lip-sync flash on its sink's output.
230        SINK_TEST_PATTERN = 1 << 8;
231    }
232}
233
234bitmask! {
235    /// The device settings a V2IP configuration can carry, each on its own bit.
236    ///
237    /// The same bits serve as the settings a frame carries and as the values
238    /// of the on/off ones among them. `IR_PROFILE` to `POWER_SAVE_SCHEDULE`
239    /// carry a value elsewhere in the block and have no on/off value of their
240    /// own.
241    ///
242    /// A device reports every setting it has, so one it never reports is one
243    /// it does not have.
244    V2ipDeviceSetting {
245        /// Disables the decoder while the display is off.
246        SINK_CHECK_POWER = 1 << 0;
247        /// Disables the HDMI output while there is no signal.
248        SINK_OFF_NO_SIGNAL = 1 << 1;
249        /// Sends infrared modulated.
250        IR_TX_MODULATED = 1 << 2;
251        /// Lights the status LED.
252        STATUS_LED = 1 << 3;
253        /// Lights the network port LEDs.
254        NETWORK_LED = 1 << 4;
255        /// Runs the fan in quiet mode.
256        FAN_QUIET = 1 << 5;
257        /// Accepts CEC combo keys.
258        CEC_COMBO_KEYS = 1 << 6;
259        /// Accepts CEC combo keys for the device's own input.
260        CEC_COMBO_INPUT = 1 << 7;
261        /// The infrared profile of the device's global infrared port.
262        IR_PROFILE = 1 << 8;
263        /// The infrared profile of the output's infrared port.
264        IR_PROFILE_SINK = 1 << 9;
265        /// The infrared profiles stored on the device. Reported by the device
266        /// itself and never written.
267        IR_PROFILES = 1 << 10;
268        /// The minutes a device stays idle before it powers down by itself.
269        AUTO_POWER_SAVE = 1 << 11;
270        /// The daily windows in which the device powers down.
271        POWER_SAVE_SCHEDULE = 1 << 12;
272        /// The device's clock has been set, on/off. Reported by the device
273        /// itself and never written.
274        CLOCK_SET = 1 << 13;
275        /// The PTP mode the device runs.
276        PTP_MODE = 1 << 14;
277        /// The PTP domain the device runs in.
278        PTP_DOMAIN = 1 << 15;
279        /// The priority1 the device announces as a PTP grandmaster.
280        PTP_PRIORITY1 = 1 << 16;
281        /// Sends the source's audio as an AES67 flow, where the source allows.
282        AES67 = 1 << 17;
283        /// The power save level the device powers down to.
284        POWER_SAVE_LEVEL = 1 << 18;
285        /// The interval between the device's PTP announce messages.
286        PTP_ANNOUNCE = 1 << 19;
287        /// The interval between the device's PTP sync messages.
288        PTP_SYNC = 1 << 20;
289        /// The interval between the device's PTP delay requests.
290        PTP_DELAY_REQ = 1 << 21;
291        /// The announce intervals before the device drops a silent PTP master.
292        PTP_ANNOUNCE_TIMEOUT = 1 << 22;
293        /// The DSCP of the device's PTP messages.
294        PTP_DSCP = 1 << 23;
295        /// The minutes after which the device forgets a SAP announcement it
296        /// heard.
297        SAP_EXPIRE = 1 << 24;
298        /// Listens for SAP announcements.
299        SAP_LISTEN = 1 << 25;
300        /// Sends SAP announcements.
301        SAP_ANNOUNCE = 1 << 26;
302        /// The seconds between the device's SAP announcements.
303        SAP_INTERVAL = 1 << 27;
304        /// Never powers down by itself: automatic power save and the power
305        /// save schedule leave the device running, and switching this on
306        /// wakes a device either has powered down. A power save request
307        /// still powers it down. Writing
308        /// [`POWER_SAVE_LEVEL`](Self::POWER_SAVE_LEVEL) switches it off.
309        POWER_SAVE_DISABLED = 1 << 28;
310        /// The TTL of the device's streams, video, audio and ancillary
311        /// alike. Reported only by a device with an encoder.
312        STREAM_TTL = 1 << 29;
313    }
314}
315
316wire_enum! {
317    /// How far a V2IP device powers down in power save, each level saving more
318    /// than the one before.
319    V2ipPowerSaveLevel: u8 {
320        /// No level.
321        NONE = 0;
322        /// Part of the video processing powers down.
323        REDUCED = 1;
324        /// All of the video processing powers down.
325        LOW = 2;
326        /// Everything but the network powers down.
327        OFF = 3;
328    }
329}
330
331bitmask! {
332    /// What a unit offers at one power save level.
333    UnitPowerSave: u8 {
334        /// The unit can power down to this level.
335        SUPPORTED = 1 << 0;
336        /// A signal on the HDMI input wakes the unit.
337        INPUT_WAKE = 1 << 1;
338        /// The display powering on wakes the unit, and the unit can power it
339        /// on.
340        OUTPUT_WAKE = 1 << 2;
341    }
342}
343
344wire_enum! {
345    /// How a V2IP device takes part in PTP.
346    V2ipPtpMode: u8 {
347        /// No PTP.
348        OFF = 0;
349        /// Follows a grandmaster, and never becomes one.
350        FOLLOWER = 1;
351        /// Follows a grandmaster, or becomes one when there is none.
352        AUTO = 2;
353    }
354}
355
356wire_enum! {
357    /// The test pattern a V2IP sink draws on its output.
358    V2ipTestPattern: u8 {
359        /// No pattern.
360        OFF = 0;
361        /// Colour bars.
362        BARS = 1;
363        /// One flat colour, the one the test card carries.
364        FLAT = 2;
365        /// A ramp.
366        RAMP = 3;
367        /// A grid.
368        GRID = 4;
369        /// A strip.
370        STRIP = 5;
371        /// A test card.
372        CARD = 6;
373    }
374}
375
376wire_enum! {
377    /// The test tone a V2IP sink plays on its output.
378    V2ipToneMode: u8 {
379        /// No tone.
380        OFF = 0;
381        /// A continuous tone.
382        CONTINUOUS = 1;
383        /// A channel ident.
384        IDENT = 2;
385        /// A line-up tone, which needs two channels or more.
386        LINEUP = 3;
387        /// A beep on each lip-sync mark.
388        BEEP = 4;
389    }
390}
391
392bitmask! {
393    /// What a V2IP sink reports about its test card.
394    V2ipTestcardFlag: u8 {
395        /// The sink can draw the test card.
396        SUPPORTED = 1 << 0;
397        /// The output shows the pattern.
398        SHOWING = 1 << 1;
399        /// The tone plays on the output.
400        PLAYING = 1 << 2;
401        /// A pattern change has yet to reach the video processor.
402        PATTERN_PENDING = 1 << 3;
403        /// A tone change has yet to reach the video processor.
404        TONE_PENDING = 1 << 4;
405        /// A lip-sync change has yet to reach the video processor.
406        SYNC_PENDING = 1 << 5;
407    }
408}
409
410bitmask! {
411    /// The flags of what a V2IP output plays from a session description.
412    V2ipSdpFlag: u8 {
413        /// The output plays a stream from a description.
414        ACTIVE = 1 << 0;
415        /// And nothing else, as no video is routed to it.
416        AUDIO_ONLY = 1 << 1;
417        /// The clock mode and state hold the video processor's answer.
418        CLOCK = 1 << 2;
419    }
420}
421
422wire_enum! {
423    /// The sample encoding of a stream a V2IP output plays from a description.
424    V2ipSdpEncoding: u8 {
425        /// None.
426        NONE = 0;
427        /// 16-bit linear PCM.
428        L16 = 1;
429        /// 24-bit linear PCM.
430        L24 = 2;
431        /// AM824.
432        AM824 = 3;
433    }
434}
435
436wire_enum! {
437    /// Where a described stream's media clock comes from.
438    V2ipSdpMediaClock: u8 {
439        /// None given.
440        NONE = 0;
441        /// Direct, at an offset from the reference clock.
442        DIRECT = 1;
443        /// The sender's.
444        SENDER = 2;
445    }
446}
447
448wire_enum! {
449    /// The reference clock a described stream names.
450    V2ipSdpRefClock: u8 {
451        /// None given.
452        NONE = 0;
453        /// PTP.
454        PTP = 1;
455        /// A traceable clock.
456        TRACEABLE = 2;
457        /// The sender's local MAC.
458        LOCAL_MAC = 3;
459    }
460}
461
462wire_enum! {
463    /// What a V2IP output's video processor times a described stream by.
464    V2ipSdpClockMode: u8 {
465        /// Arrival.
466        ARRIVAL = 0;
467        /// PTP.
468        PTP = 1;
469        /// The sender.
470        SENDER = 2;
471    }
472}
473
474wire_enum! {
475    /// How far a V2IP output's video processor has got with a described
476    /// stream's timing.
477    V2ipSdpClockState: u8 {
478        /// Idle.
479        IDLE = 0;
480        /// Running its servo.
481        SERVO = 1;
482        /// Aligning.
483        ALIGNING = 2;
484        /// Timed.
485        TIMED = 3;
486        /// Parked.
487        PARKED = 4;
488        /// Playing untimed.
489        UNTIMED = 5;
490        /// The timing is not supported.
491        UNSUPPORTED = 6;
492    }
493}
494
495bitmask! {
496    /// The flags of a unit's status report.
497    UnitFlag {
498        /// A changed setting takes effect after a reboot.
499        REBOOT_REQUIRED = 1 << 0;
500        /// A newer video processor image is available.
501        FPGA_UPGRADE = 1 << 1;
502        /// The IP configuration comes from DHCP.
503        DHCP = 1 << 2;
504        /// The IP configuration was changed through the mesh, and is reverted
505        /// unless the mesh controller confirms it in time.
506        NET_PENDING = 1 << 3;
507        /// The fan runs in quiet mode.
508        FAN_QUIET = 1 << 4;
509        /// Powered by an external supply rather than PoE.
510        EXTERNAL_PSU = 1 << 5;
511        /// The video processor runs with its IP configured. Without it the
512        /// encoder and decoder health carry nothing.
513        FPGA_CONFIGURED = 1 << 6;
514        /// The encoder is enabled.
515        ENCODER_ACTIVE = 1 << 7;
516        /// The decoder is enabled.
517        DECODER_ACTIVE = 1 << 8;
518        /// The decoder disables itself without a display.
519        AUTO_DISABLE = 1 << 9;
520        /// The decoder disabled itself without a display.
521        AUTO_DISABLE_ACTIVE = 1 << 10;
522        /// The HDMI output switches off without a signal.
523        OFF_NO_SIGNAL = 1 << 11;
524        /// The HDMI output switched off without a signal.
525        OFF_NO_SIGNAL_ACTIVE = 1 << 12;
526        /// Display power is checked before the decoder is enabled.
527        POWER_CHECK = 1 << 13;
528        /// The boot count is reported.
529        BOOT_COUNT = 1 << 14;
530        /// The fan speed is reported.
531        FAN_SPEED = 1 << 15;
532    }
533}
534
535wire_enum! {
536    /// What a unit command asks of its unit.
537    UnitCommandKind: u8 {
538        /// Clear the current system status.
539        CLEAR_STATUS = 0;
540        /// Upgrade the video processor to the latest image.
541        FPGA_UPGRADE = 1;
542        /// Change the IP configuration.
543        NET_CONFIG = 2;
544        /// Keep a pending IP configuration.
545        NET_CONFIRM = 3;
546    }
547}
548
549bitmask! {
550    /// The flags of a unit command.
551    UnitCommandFlag: u8 {
552        /// With [`UnitCommandKind::FPGA_UPGRADE`]: flash the image even if it
553        /// is running already.
554        FORCE = 1 << 0;
555        /// With [`UnitCommandKind::NET_CONFIG`]: use DHCP, ignoring the
556        /// addresses.
557        DHCP = 1 << 1;
558    }
559}
560
561bitmask! {
562    /// The flags of a V2IP device's PTP state.
563    V2ipPtpFlag: u8 {
564        /// The device runs PTP and the block holds its state. A block without
565        /// it holds nothing: the device has no PTP, or is in power save.
566        VALID = 1 << 0;
567        /// The device locked to a master since its PTP started, so its mesh
568        /// holds a time.
569        FOLLOWED = 1 << 1;
570    }
571}
572
573wire_enum! {
574    /// How far a V2IP device's PTP clock has locked to its master.
575    V2ipPtpLock: u8 {
576        /// Not locked.
577        UNLOCKED = 0;
578        /// Locking.
579        LOCKING = 1;
580        /// Locked.
581        LOCKED = 2;
582    }
583}
584
585bitmask! {
586    /// The flags of a V2IP device's VLAN configuration.
587    V2ipVlanFlag: u16 {
588        /// The block carries a configuration. A block without it carries
589        /// nothing, whatever its other bytes hold.
590        VALID = 1 << 0;
591        /// Untagged frames arriving on the uplink are dropped instead of
592        /// reaching the device.
593        TRUNK = 1 << 1;
594        /// Reported by the device: the configuration is applied, and reverted
595        /// unless the mesh controller confirms it. Never written.
596        PENDING = 1 << 2;
597        /// Sent by the mesh controller: a pending configuration it heard, which
598        /// the device then keeps.
599        CONFIRM = 1 << 3;
600        /// Reported by the device: it has an SFP port. Never written.
601        HAS_SFP = 1 << 4;
602    }
603}
604
605impl V2ipDeviceSetting {
606    /// The settings that are on or off, as opposed to carrying a value, and
607    /// that can be written.
608    pub const SWITCHES: Self = Self(
609        0xFF | Self::AES67.0
610            | Self::SAP_LISTEN.0
611            | Self::SAP_ANNOUNCE.0
612            | Self::POWER_SAVE_DISABLED.0,
613    );
614
615    /// The settings only a device reports about itself, which no write
616    /// carries.
617    pub const REPORTED_ONLY: Self = Self(Self::IR_PROFILES.0 | Self::CLOCK_SET.0);
618
619    /// The PTP settings.
620    pub const PTP_SETTINGS: Self =
621        Self(Self::PTP_MODE.0 | Self::PTP_DOMAIN.0 | Self::PTP_PRIORITY1.0);
622
623    /// The PTP message settings.
624    pub const PTP_MESSAGES: Self = Self(
625        Self::PTP_ANNOUNCE.0
626            | Self::PTP_SYNC.0
627            | Self::PTP_DELAY_REQ.0
628            | Self::PTP_ANNOUNCE_TIMEOUT.0
629            | Self::PTP_DSCP.0,
630    );
631
632    /// The settings whose values a frame carries in a block of their own
633    /// behind the rest, [`V2ipPtpMessages`](crate::V2ipPtpMessages): the PTP
634    /// message settings, the two SAP values and the stream TTL.
635    pub const SETTINGS_BLOCK: Self =
636        Self(Self::PTP_MESSAGES.0 | Self::SAP_EXPIRE.0 | Self::SAP_INTERVAL.0 | Self::STREAM_TTL.0);
637
638    /// These bits with every bit of `other` cleared.
639    pub(crate) const fn without(self, other: Self) -> Self {
640        Self(self.0 & !other.0)
641    }
642}
643
644bitmask! {
645    /// Capabilities of a single bay.
646    BayFeatures {
647        /// HDMI output.
648        HDMI_OUT = 1 << 0;
649        /// HDMI input.
650        HDMI_IN = 1 << 1;
651        /// Digital audio output.
652        AUDIO_DIG_OUT = 1 << 2;
653        /// Digital audio input.
654        AUDIO_DIG_IN = 1 << 3;
655        /// Analogue audio output.
656        AUDIO_ANA_OUT = 1 << 4;
657        /// Analogue audio input.
658        AUDIO_ANA_IN = 1 << 5;
659        /// Infrared input.
660        IR_IN = 1 << 6;
661        /// Infrared output.
662        IR_OUT = 1 << 7;
663        /// Amplified audio output.
664        AUDIO_AMP_OUT = 1 << 8;
665        /// Remote-control output.
666        RC_OUT = 1 << 9;
667        /// Remote-control input.
668        RC_IN = 1 << 10;
669        /// Dolby decoding.
670        DOLBY = 1 << 11;
671        /// Switches itself off when idle.
672        AUTO_OFF = 1 << 12;
673        /// Is a remote V2IP source.
674        V2IP_SOURCE_REMOTE = 1 << 13;
675        /// Is a remote V2IP sink.
676        V2IP_SINK_REMOTE = 1 << 14;
677        /// Is a local V2IP source.
678        V2IP_SOURCE_LOCAL = 1 << 15;
679        /// Is a local V2IP sink.
680        V2IP_SINK_LOCAL = 1 << 16;
681    }
682}
683
684bitmask! {
685    /// Live status flags of a single bay.
686    ///
687    /// Bits 16-19 and 22-23 are bit-fields rather than flags; read them with
688    /// [`BayStatus::rc_type`] and [`BayStatus::hdcp`].
689    BayStatus {
690        /// The bay reports a fault.
691        FAULT = 1 << 0;
692        /// The bay is hidden from the user interface.
693        HIDDEN = 1 << 1;
694        /// The amplifier zone the bay drives is powered on.
695        POWERED = 1 << 2;
696        /// A signal is present.
697        SIGNAL_DETECTED = 1 << 3;
698        /// Hot-plug detect is asserted.
699        HPD_DETECTED = 1 << 4;
700        /// The signal is scrambled.
701        SIGNAL_SCRAMBLE = 1 << 5;
702        /// An HDBaseT link is up.
703        HDBT_CONNECTED = 1 << 6;
704        /// A CEC device answered.
705        CEC_DETECTED = 1 << 7;
706        /// The attached device was powered on.
707        POWERED_ON = 1 << 8;
708        /// The attached device was powered off.
709        POWERED_OFF = 1 << 9;
710        /// Audio return over HDMI is active.
711        AUDIO_ARC_HDMI = 1 << 10;
712        /// Audio return over optical is active.
713        AUDIO_ARC_OPTIC = 1 << 11;
714        /// Audio return over analogue is active.
715        AUDIO_ARC_ANALOG = 1 << 12;
716        /// The bay is offline.
717        OFFLINE = 1 << 13;
718        /// The V2IP decoder is disabled.
719        DECODER_DISABLE = 1 << 14;
720        /// The V2IP encoder is disabled.
721        ENCODER_DISABLE = 1 << 15;
722        /// CEC is switched off for this bay.
723        CEC_DISABLED = 1 << 20;
724        /// The V2IP encoder reports an error.
725        ENCODER_ERROR = 1 << 21;
726        /// The bay's name was generated - a default, or taken from CEC or the
727        /// EDID - rather than set by a user. A device that predates this bit
728        /// never sets it, so a clear bit does not prove a user set the name.
729        AUTO_NAME = 1 << 24;
730    }
731}
732
733impl BayStatus {
734    const RC_TYPE_SHIFT: u32 = 16;
735    const RC_TYPE_MASK: u32 = 0xF << Self::RC_TYPE_SHIFT;
736    const HDCP_SHIFT: u32 = 22;
737    const HDCP_MASK: u32 = 0x3 << Self::HDCP_SHIFT;
738
739    /// Extracts the remote-control type carried in bits 16-19.
740    pub const fn rc_type(self) -> RcType {
741        RcType(((self.0 & Self::RC_TYPE_MASK) >> Self::RC_TYPE_SHIFT) as u8)
742    }
743
744    /// Extracts the HDCP version carried in bits 22-23.
745    pub const fn hdcp(self) -> u8 {
746        ((self.0 & Self::HDCP_MASK) >> Self::HDCP_SHIFT) as u8
747    }
748}
749
750bitmask! {
751    /// Media carried by a virtual link.
752    LinkFeature {
753        /// Video over HDMI.
754        VIDEO_HDMI = 1 << 0;
755        /// Audio over optical.
756        AUDIO_OPTICAL = 1 << 1;
757        /// Audio over analogue.
758        AUDIO_ANALOG = 1 << 2;
759        /// Infrared.
760        IR = 1 << 3;
761        /// Remote control.
762        RC = 1 << 4;
763    }
764}
765
766wire_enum! {
767    /// A remote-control action.
768    RcAction: u16 {
769        /// Toggle power.
770        POWER_TOGGLE = 0;
771        /// Power on.
772        POWER_ON = 1;
773        /// Power off.
774        POWER_OFF = 2;
775        /// Volume up.
776        VOLUME_UP = 3;
777        /// Volume down.
778        VOLUME_DOWN = 4;
779        /// Toggle mute.
780        VOLUME_MUTE = 5;
781    }
782}
783
784wire_enum! {
785    /// A remote-control key code (CEC or IR).
786    RcKey: u16 {
787        /// Digit 0.
788        NUM0 = 0;
789        /// Digit 1.
790        NUM1 = 1;
791        /// Digit 2.
792        NUM2 = 2;
793        /// Digit 3.
794        NUM3 = 3;
795        /// Digit 4.
796        NUM4 = 4;
797        /// Digit 5.
798        NUM5 = 5;
799        /// Digit 6.
800        NUM6 = 6;
801        /// Digit 7.
802        NUM7 = 7;
803        /// Digit 8.
804        NUM8 = 8;
805        /// Digit 9.
806        NUM9 = 9;
807        /// Confirm the highlighted item.
808        SELECT = 10;
809        /// Go back one step.
810        BACK = 11;
811        /// Navigate up.
812        UP = 12;
813        /// Navigate down.
814        DOWN = 13;
815        /// Navigate left.
816        LEFT = 14;
817        /// Navigate right.
818        RIGHT = 15;
819        /// Open the main menu.
820        MENU = 16;
821        /// Open the content menu.
822        CONTENT_MENU = 17;
823        /// Next channel.
824        CHANNEL_UP = 18;
825        /// Previous channel.
826        CHANNEL_DOWN = 19;
827        /// Start playback.
828        PLAY = 20;
829        /// Pause playback.
830        PAUSE = 21;
831        /// Stop playback.
832        STOP = 22;
833        /// Start recording.
834        RECORD = 23;
835        /// Fast forward.
836        FAST_FORWARD = 24;
837        /// Rewind.
838        REWIND = 25;
839        /// Red colour key.
840        RED = 26;
841        /// Green colour key.
842        GREEN = 27;
843        /// Yellow colour key.
844        YELLOW = 28;
845        /// Blue colour key.
846        BLUE = 29;
847        /// Open help.
848        HELP = 30;
849        /// Show information.
850        INFORMATION = 31;
851        /// Open teletext.
852        TEXT = 32;
853        /// Open the programme guide.
854        GUIDE = 33;
855        /// Open video on demand.
856        VIDEO_ON_DEMAND = 34;
857        /// Return to the previous channel.
858        PREVIOUS_CHANNEL = 80;
859        /// Toggle 3D mode.
860        MODE_3D = 81;
861        /// Toggle subtitles.
862        SUBTITLE = 82;
863        /// Select an audio track.
864        SOUND_SELECT = 83;
865        /// Select an input.
866        INPUT_SELECT = 84;
867        /// Eject the medium.
868        EJECT = 85;
869        /// Next chapter.
870        NEXT_CHAPTER = 86;
871        /// Previous chapter.
872        PREV_CHAPTER = 87;
873        /// Open interactive services.
874        INTERACTIVE = 128;
875        /// Open search.
876        SEARCH = 129;
877        /// Sky home key.
878        SKY = 130;
879        /// Base of the range carrying a raw CEC user-control code.
880        CUSTOM_CEC = 1280;
881        /// Base of the range carrying a raw Sky key code.
882        CUSTOM_SKY = 2048;
883    }
884}
885
886wire_enum! {
887    /// The remote-control protocol of a connected sink or source.
888    RcType: u8 {
889        /// Infrared.
890        IR = 0;
891        /// HDMI CEC.
892        CEC = 1;
893        /// Sky UK over IP.
894        SKY_UK = 2;
895        /// TiVo.
896        TIVO = 3;
897        /// Kodi.
898        KODI = 4;
899        /// Dish.
900        DISH = 5;
901        /// DirecTV.
902        DIRECTV = 6;
903        /// Another MX Remote device.
904        MX_REMOTE = 7;
905        /// Routed inside the device itself.
906        INTERNAL = 8;
907    }
908}
909
910impl fmt::Display for RcType {
911    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
912        let name = match *self {
913            Self::IR => "IR",
914            Self::CEC => "CEC",
915            Self::SKY_UK => "Sky",
916            Self::TIVO => "TiVo",
917            Self::KODI => "Kodi",
918            Self::DISH => "Dish",
919            Self::DIRECTV => "DirecTV",
920            Self::MX_REMOTE => "MX-Remote",
921            Self::INTERNAL => "Internal",
922            _ => "Unknown",
923        };
924        f.write_str(name)
925    }
926}
927
928wire_enum! {
929    /// An EDID preset selectable on an HDMI input.
930    EdidProfile: u16 {
931        /// 1080p with stereo audio.
932        STEREO_1080P = 0;
933        /// A fixed EDID stored on the device.
934        FIXED = 1;
935        /// 4K.
936        UHD_4K = 2;
937        /// 1080p with 5.1 audio.
938        SURROUND51_1080P = 3;
939        /// 720p.
940        HD_720P = 4;
941        /// 1080p with 7.1 audio.
942        SURROUND71_1080P = 5;
943        /// 4K with 7.1 audio.
944        SURROUND71_4K = 6;
945        /// 4K HDR with stereo audio.
946        HDR_STEREO_4K = 7;
947        /// 4K HDR with 7.1 audio.
948        HDR_SURROUND71_4K = 8;
949        /// 4K HDR, audio to the AVR only.
950        HDR_AVR_ONLY_4K = 9;
951        /// The lowest common denominator of the connected sinks.
952        LOWEST_COMMON = 10;
953        /// The lowest common denominator of every sink, connected or not.
954        LOWEST_COMMON_ALL = 11;
955        /// 4K HDR with Dolby Atmos.
956        HDR_ATMOS_4K = 12;
957        /// Copy the EDID of sink 1; the range runs to [`EdidProfile::SINK_32`].
958        SINK_1 = 101;
959        /// Copy the EDID of sink 32; the range starts at [`EdidProfile::SINK_1`].
960        SINK_32 = 132;
961        /// Base of the range carrying a user-supplied EDID.
962        CUSTOM_0 = 500;
963        /// The device reports no profile.
964        UNKNOWN = 0xFFF;
965    }
966}
967
968impl fmt::Display for EdidProfile {
969    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
970        let name = match *self {
971            Self::STEREO_1080P => "1080p stereo",
972            Self::FIXED => "fixed",
973            Self::UHD_4K => "4K",
974            Self::SURROUND51_1080P => "1080p 5.1",
975            Self::HD_720P => "720p",
976            Self::SURROUND71_1080P => "1080p 7.1",
977            Self::SURROUND71_4K => "4K 7.1",
978            Self::HDR_STEREO_4K => "4K HDR Stereo",
979            Self::HDR_SURROUND71_4K => "4K HDR 7.1",
980            Self::HDR_AVR_ONLY_4K => "4K HDR AVR",
981            Self::LOWEST_COMMON => "lowest common denominator",
982            Self::LOWEST_COMMON_ALL => "lowest common denominator (all sinks)",
983            Self::HDR_ATMOS_4K => "4K HDR Dolby Atmos",
984            _ => {
985                if self.0 >= Self::SINK_1.0 && self.0 <= Self::SINK_32.0 {
986                    return write!(f, "copy from sink #{}", self.0 - Self::SINK_1.0 + 1);
987                }
988                return write!(f, "custom #{}", self.0);
989            }
990        };
991        f.write_str(name)
992    }
993}
994
995wire_enum! {
996    /// A firmware component.
997    FirmwareType: u8 {
998        /// The unit's own firmware.
999        MCU = 0;
1000        /// The video processor's FPGA image.
1001        FPGA = 1;
1002        /// The video processor's RTOS image.
1003        RTOS = 2;
1004        /// The video processor's loader image.
1005        LOADER = 3;
1006        /// The unit's bootloader.
1007        BOOTLOADER = 4;
1008    }
1009}
1010
1011impl fmt::Display for FirmwareType {
1012    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1013        let name = match *self {
1014            Self::MCU => "MCU",
1015            Self::FPGA => "FPGA",
1016            Self::RTOS => "RTOS",
1017            Self::LOADER => "Loader",
1018            Self::BOOTLOADER => "Bootloader",
1019            _ => return write!(f, "firmware #{}", self.0),
1020        };
1021        f.write_str(name)
1022    }
1023}
1024
1025wire_enum! {
1026    /// The negotiated speed of a network port.
1027    UtpLinkSpeed: u8 {
1028        /// The device reports no speed.
1029        UNKNOWN = 0;
1030        /// 10Mbit/s.
1031        SPEED_10M = 1;
1032        /// 100Mbit/s.
1033        SPEED_100M = 2;
1034        /// 200Mbit/s.
1035        SPEED_200M = 3;
1036        /// 1Gbit/s.
1037        SPEED_1G = 4;
1038    }
1039}
1040
1041impl fmt::Display for UtpLinkSpeed {
1042    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1043        let name = match *self {
1044            Self::SPEED_10M => "10Mbit/s",
1045            Self::SPEED_100M => "100Mbit/s",
1046            Self::SPEED_200M => "200Mbit/s",
1047            Self::SPEED_1G => "1Gbit/s",
1048            _ => "Unknown",
1049        };
1050        f.write_str(name)
1051    }
1052}
1053
1054wire_enum! {
1055    /// The window layout of a multiviewer.
1056    MultiviewerViewMode: u8 {
1057        /// The device reports no layout.
1058        UNKNOWN = 0;
1059        /// One full-screen window.
1060        SINGLE = 1;
1061        /// Picture in picture.
1062        PIP = 2;
1063        /// Two windows, large.
1064        TWO_SCREEN_LARGE = 3;
1065        /// Two windows, small.
1066        TWO_SCREEN_SMALL = 4;
1067        /// Three windows, large.
1068        THREE_SCREEN_LARGE = 5;
1069        /// Three windows, small.
1070        THREE_SCREEN_SMALL = 6;
1071        /// Four windows, equal size.
1072        FOUR_SCREEN_EQUAL = 7;
1073        /// Four windows, small.
1074        FOUR_SCREEN_SMALL = 8;
1075    }
1076}
1077
1078wire_enum! {
1079    /// The corner a multiviewer places its picture-in-picture window in.
1080    MultiviewerPipPosition: u8 {
1081        /// The device reports no position.
1082        UNKNOWN = 0;
1083        /// Top left.
1084        LEFT_TOP = 1;
1085        /// Bottom left.
1086        LEFT_BOTTOM = 2;
1087        /// Top right.
1088        RIGHT_TOP = 3;
1089        /// Bottom right.
1090        RIGHT_BOTTOM = 4;
1091    }
1092}
1093
1094wire_enum! {
1095    /// The size of a multiviewer's picture-in-picture window.
1096    MultiviewerPipSize: u8 {
1097        /// The device reports no size.
1098        UNKNOWN = 0;
1099        /// Small.
1100        SMALL = 1;
1101        /// Medium.
1102        MEDIUM = 2;
1103        /// Large.
1104        LARGE = 3;
1105    }
1106}
1107
1108wire_enum! {
1109    /// The resolution and refresh rate a multiviewer drives its output at.
1110    MultiviewerOutputMode: u8 {
1111        /// The device reports no output mode.
1112        UNKNOWN = 0;
1113        /// 4096x2160p60.
1114        DCI4K_P60 = 1;
1115        /// 4096x2160p50.
1116        DCI4K_P50 = 2;
1117        /// 3840x2160p60.
1118        UHD_P60 = 3;
1119        /// 3840x2160p50.
1120        UHD_P50 = 4;
1121        /// 3840x2160p30.
1122        UHD_P30 = 5;
1123        /// 3840x2160p25.
1124        UHD_P25 = 6;
1125        /// 1920x1200p60, reduced blanking.
1126        WUXGA_P60_RB = 7;
1127        /// 1920x1080p60.
1128        HD1080_P60 = 8;
1129        /// 1920x1080p50.
1130        HD1080_P50 = 9;
1131        /// 1360x768p60.
1132        WXGA_P60 = 10;
1133        /// 1280x800p60.
1134        WXGA800_P60 = 11;
1135        /// 1280x720p60.
1136        HD720_P60 = 12;
1137        /// 1280x720p50.
1138        HD720_P50 = 13;
1139        /// 1024x768p60.
1140        XGA_P60 = 14;
1141    }
1142}
1143
1144wire_enum! {
1145    /// The HDCP version a multiviewer output negotiates.
1146    MultiviewerHdcpMode: u8 {
1147        /// The device reports no HDCP mode.
1148        UNKNOWN = 0;
1149        /// HDCP 1.4.
1150        V14 = 1;
1151        /// HDCP 2.2.
1152        V22 = 2;
1153        /// Content protection off.
1154        OFF = 3;
1155    }
1156}
1157
1158wire_enum! {
1159    /// The IT-content flag a multiviewer sets on its output.
1160    MultiviewerItcMode: u8 {
1161        /// The device reports no IT-content mode.
1162        UNKNOWN = 0;
1163        /// Video content.
1164        VIDEO = 1;
1165        /// PC content.
1166        PC = 2;
1167    }
1168}
1169
1170wire_enum! {
1171    /// The EDID template a multiviewer presents to its sources.
1172    ///
1173    /// A template's name is the largest resolution it advertises and the audio
1174    /// format it declares support for.
1175    MultiviewerEdidTemplate: u8 {
1176        /// The device reports no template.
1177        EDID_UNKNOWN = 0;
1178        /// 4K2K60 4:4:4, stereo 2.0.
1179        EDID_4K2K60_444_STEREO = 1;
1180        /// 4K2K60 4:4:4, Dolby/DTS 5.1.
1181        EDID_4K2K60_444_DOLBY_DTS_51 = 2;
1182        /// 4K2K60 4:4:4, HD audio 7.1.
1183        EDID_4K2K60_444_HD_AUDIO_71 = 3;
1184        /// 4K2K30 4:4:4, stereo 2.0.
1185        EDID_4K2K30_444_STEREO = 4;
1186        /// 4K2K30 4:4:4, Dolby/DTS 5.1.
1187        EDID_4K2K30_444_DOLBY_DTS_51 = 5;
1188        /// 4K2K30 4:4:4, HD audio 7.1.
1189        EDID_4K2K30_444_HD_AUDIO_71 = 6;
1190        /// 1080p, stereo 2.0.
1191        EDID_1080P_STEREO = 7;
1192        /// 1080p, Dolby/DTS 5.1.
1193        EDID_1080P_DOLBY_DTS_51 = 8;
1194        /// 1080p, HD audio 7.1.
1195        EDID_1080P_HD_AUDIO_71 = 9;
1196        /// 1920x1200, stereo 2.0.
1197        EDID_1920X1200_STEREO = 10;
1198        /// 1680x1050, stereo 2.0.
1199        EDID_1680X1050_STEREO = 11;
1200        /// 1600x1200, stereo 2.0.
1201        EDID_1600X1200_STEREO = 12;
1202        /// 1440x900, stereo 2.0.
1203        EDID_1440X900_STEREO = 13;
1204        /// 1360x768, stereo 2.0.
1205        EDID_1360X768_STEREO = 14;
1206        /// 1280x1024, stereo 2.0.
1207        EDID_1280X1024_STEREO = 15;
1208        /// 1024x768, stereo 2.0.
1209        EDID_1024X768_STEREO = 16;
1210        /// 720p, stereo 2.0.
1211        EDID_720P_STEREO = 17;
1212        /// Whatever the display connected to the HDMI output presents. The
1213        /// template a multiviewer leaves the factory with.
1214        EDID_COPY_OUTPUT = 18;
1215        /// The EDID loaded onto the device.
1216        EDID_CUSTOM = 19;
1217    }
1218}
1219
1220wire_enum! {
1221    /// The aspect ratio a multiviewer scales its windows to.
1222    MultiviewerAspectRatio: u8 {
1223        /// The device reports no aspect ratio.
1224        UNKNOWN = 0;
1225        /// Fill the window.
1226        FULL = 1;
1227        /// 16:9.
1228        RATIO_16_9 = 2;
1229    }
1230}
1231
1232wire_enum! {
1233    /// A multiviewer setting that is on, off, or not reported.
1234    MultiviewerBool: u8 {
1235        /// Off.
1236        OFF = 0;
1237        /// On.
1238        ON = 1;
1239        /// The device reports no value.
1240        UNKNOWN = 0xFF;
1241    }
1242}
1243
1244wire_enum! {
1245    /// One of a multiviewer's four inputs.
1246    ///
1247    /// The wire numbers the inputs from zero and this type from one, so that
1248    /// zero can mean "not reported" the way it does for every other
1249    /// multiviewer setting. So `to_wire` and `from_wire` carry this type's
1250    /// numbering rather than the wire's, and neither is the conversion to
1251    /// reach for when a raw multiviewer byte is what is in hand.
1252    MultiviewerSource: u8 {
1253        /// The device reports no source.
1254        UNKNOWN = 0;
1255        /// Input 1.
1256        INPUT_1 = 1;
1257        /// Input 2.
1258        INPUT_2 = 2;
1259        /// Input 3.
1260        INPUT_3 = 3;
1261        /// Input 4.
1262        INPUT_4 = 4;
1263    }
1264}
1265
1266impl MultiviewerSource {
1267    /// Reads a zero-based wire value, mapping anything past input 4 to
1268    /// [`MultiviewerSource::UNKNOWN`].
1269    ///
1270    /// The firmware spells "not known" as 0xFF, which lands past input 4 and
1271    /// so needs no case of its own.
1272    pub(crate) const fn from_zero_based(value: u8) -> Self {
1273        if value > 3 {
1274            Self::UNKNOWN
1275        } else {
1276            Self(value + 1)
1277        }
1278    }
1279
1280    /// The zero-based value the wire carries, or `None` for a source naming no
1281    /// input.
1282    ///
1283    /// A multiviewer reads zero as its first input, so there is no value that
1284    /// says "leave this alone": a request that cannot name an input has to be
1285    /// refused rather than sent.
1286    pub(crate) const fn to_zero_based(self) -> Option<u8> {
1287        match self.0 {
1288            1..=4 => Some(self.0 - 1),
1289            _ => None,
1290        }
1291    }
1292}
1293
1294impl MultiviewerBool {
1295    /// Reads a wire value, mapping anything but 0 and 1 to
1296    /// [`MultiviewerBool::UNKNOWN`].
1297    pub(crate) const fn from_wire_tristate(value: u8) -> Self {
1298        if value > 1 {
1299            Self::UNKNOWN
1300        } else {
1301            Self(value)
1302        }
1303    }
1304}
1305
1306wire_enum! {
1307    /// The colour space a V2IP output scales to.
1308    ///
1309    /// The field is four bits wide and only these four values are defined. A
1310    /// receiver passes the whole nibble to its validator, so a fifth value is
1311    /// dropped without a word rather than clamped to one of these.
1312    V2ipColourSpace: u8 {
1313        /// RGB.
1314        RGB = 0;
1315        /// YCbCr 4:4:4.
1316        YCBCR444 = 1;
1317        /// YCbCr 4:2:2.
1318        YCBCR422 = 2;
1319        /// YCbCr 4:2:0.
1320        YCBCR420 = 3;
1321    }
1322}
1323
1324wire_enum! {
1325    /// The 2-byte `mxr_signal_type` carried in scaling configs and bay signal
1326    /// reports.
1327    ///
1328    /// Byte 0 is the CTA-861 short video descriptor, 0 when the signal is not
1329    /// HDMI. Byte 1 packs `color:4` in the low nibble, then `non_int:1` and
1330    /// `bpp:3` above it.
1331    MxrSignalType: u16 {
1332        /// No signal format was reported.
1333        NONE = 0;
1334    }
1335}
1336
1337/// The bpp index a sender writes when it has no bit depth to report.
1338///
1339/// It sits outside the four indices that name a real depth, so an unset
1340/// format reads differently from every genuine one.
1341const SIG_BPP_UNSET: u16 = 5;
1342
1343impl MxrSignalType {
1344    /// The CTA-861 short video descriptor, 0 when the signal is not HDMI.
1345    pub const fn svd(self) -> u8 {
1346        (self.0 & 0xFF) as u8
1347    }
1348
1349    /// The colour space.
1350    pub const fn colour_space(self) -> u8 {
1351        ((self.0 >> 8) & 0xF) as u8
1352    }
1353
1354    /// Whether the frame rate carries a 1000/1001 clock.
1355    pub const fn is_non_integer(self) -> bool {
1356        self.0 & (1 << 12) != 0
1357    }
1358
1359    /// The raw bpp index as carried on the wire. The field is an index, not a
1360    /// bit depth; [`MxrSignalType::bpp`] converts it.
1361    pub const fn bpp_index(self) -> u8 {
1362        ((self.0 >> 13) & 0x7) as u8
1363    }
1364
1365    /// The bit depth the bpp index stands for, `None` when unknown or unset.
1366    pub const fn bpp(self) -> Option<u8> {
1367        match self.bpp_index() {
1368            1 => Some(8),
1369            2 => Some(10),
1370            3 => Some(12),
1371            4 => Some(16),
1372            _ => None,
1373        }
1374    }
1375
1376    /// Reports whether the word carries a signal format at all.
1377    ///
1378    /// A bay with nothing configured says so two ways. A sender that zeroes
1379    /// the word and stamps the unset bpp index leaves an index no real depth
1380    /// uses, and one that writes a plain zero leaves nothing at all. Neither
1381    /// is a format, and the svd and colour space beside them are not answers
1382    /// either: both read as zero, which is what this word says for "not HDMI"
1383    /// and "RGB" when it *is* set.
1384    pub const fn is_set(self) -> bool {
1385        self.0 != 0 && self.bpp_index() as u16 != SIG_BPP_UNSET
1386    }
1387
1388    /// Builds the word from the fields a scaling write consumes.
1389    ///
1390    /// `non_int` is left clear: the receiving struct carries the bit, and the
1391    /// apply path does not read it.
1392    ///
1393    /// Building rather than editing is the point. A sink with no mode
1394    /// configured reports the word with the unset bpp index in it, so a caller
1395    /// that read that word back and filled in an svd would send an index no
1396    /// depth uses - which the receiver decodes to zero and rejects without
1397    /// answering.
1398    pub(crate) const fn from_parts(svd: u8, colour: u8, bpp_index: u8) -> Self {
1399        Self((svd as u16) | (((colour & 0xF) as u16) << 8) | (((bpp_index & 0x7) as u16) << 13))
1400    }
1401
1402    /// The bpp index that stands for a bit depth, `None` for a depth no index
1403    /// names.
1404    ///
1405    /// Only the three depths a V2IP output stage accepts are here. Index 4
1406    /// names 16bpp, which [`MxrSignalType::bpp`] reads back from a device, but
1407    /// the output stage refuses it - so offering it as something to write would
1408    /// send a frame that is decoded cleanly and then dropped in silence.
1409    pub(crate) const fn bpp_index_for_depth(depth: u8) -> Option<u8> {
1410        match depth {
1411            8 => Some(1),
1412            10 => Some(2),
1413            12 => Some(3),
1414            _ => None,
1415        }
1416    }
1417}
1418
1419impl fmt::Display for MxrSignalType {
1420    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1421        if !self.is_set() {
1422            return f.write_str("unset");
1423        }
1424        match self.bpp() {
1425            Some(bpp) => write!(
1426                f,
1427                "svd {}, color {}, {}bpp",
1428                self.svd(),
1429                self.colour_space(),
1430                bpp
1431            ),
1432            None => write!(f, "svd {}, color {}", self.svd(), self.colour_space()),
1433        }
1434    }
1435}
1436
1437bitmask! {
1438    /// The kinds of overlay setting an overlay sync copies.
1439    OsdSyncWhat: u8 {
1440        /// Captions.
1441        CAPTIONS = 1 << 0;
1442        /// Which logo is shown, and where.
1443        LOGO = 1 << 1;
1444        /// Background colours.
1445        BACKGROUNDS = 1 << 2;
1446        /// The logo images in the four slots.
1447        LOGO_SLOTS = 1 << 3;
1448    }
1449}
1450
1451wire_enum! {
1452    /// How far a unit has got with taking an overlay sync.
1453    OsdSyncState: u8 {
1454        /// Taking it.
1455        TAKING = 0;
1456        /// Every setting written and committed.
1457        DONE = 1;
1458        /// Failed, for the reason the report gives.
1459        FAILED = 2;
1460        /// Kept for later, as the unit's video processor is off in power
1461        /// save.
1462        DEFERRED = 3;
1463    }
1464}
1465
1466wire_enum! {
1467    /// The output size an overlay setting applies at.
1468    OsdSyncSize: u8 {
1469        /// Large outputs, which every value but `SMALL` also means.
1470        LARGE = 1;
1471        /// Small outputs.
1472        SMALL = 2;
1473    }
1474}
1475
1476wire_enum! {
1477    /// How a caption's lines are aligned.
1478    OsdCaptionAlign: u8 {
1479        /// To the left.
1480        LEFT = 0;
1481        /// Centred.
1482        CENTRE = 1;
1483        /// To the right.
1484        RIGHT = 2;
1485        /// The layout's default.
1486        DEFAULT = 0xFF;
1487    }
1488}
1489
1490wire_enum! {
1491    /// How a caption's text is read.
1492    OsdCaptionFormat: u8 {
1493        /// As plain text.
1494        PLAIN = 0;
1495        /// As Markdown.
1496        MARKDOWN = 1;
1497        /// The layout's default.
1498        DEFAULT = 0xFF;
1499    }
1500}
1501
1502bitmask! {
1503    /// The caption fields an overlay setting gives. A field left out keeps
1504    /// what the unit has.
1505    OsdCaptionField: u16 {
1506        /// The font.
1507        FONT = 1 << 0;
1508        /// The size.
1509        SIZE = 1 << 1;
1510        /// The horizontal position.
1511        X = 1 << 2;
1512        /// The vertical position.
1513        Y = 1 << 3;
1514        /// The alignment.
1515        ALIGN = 1 << 4;
1516        /// The format.
1517        FORMAT = 1 << 5;
1518        /// The colour.
1519        COLOUR = 1 << 6;
1520        /// The wrap width.
1521        WRAP = 1 << 7;
1522        /// The text.
1523        TEXT = 1 << 8;
1524    }
1525}
1526
1527bitmask! {
1528    /// The logo fields an overlay setting gives. A field left out keeps what
1529    /// the unit has.
1530    OsdLogoField: u16 {
1531        /// Which logo.
1532        LOGO = 1 << 0;
1533        /// The horizontal position.
1534        X = 1 << 1;
1535        /// The vertical position.
1536        Y = 1 << 2;
1537    }
1538}