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 OneIP stream source.
134        V2IP_SOURCE = 1 << 3;
135        /// Acts as a OneIP 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 OneIP 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 OneIP 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        /// Connects to the cloud service. A device that does not report it
314        /// connects regardless.
315        CLOUD = 1 << 30;
316        /// The angle the device's HDMI output is turned by. Reported only by
317        /// a device with an HDMI output.
318        SINK_ROTATION = 1 << 31;
319    }
320}
321
322wire_enum! {
323    /// How far a OneIP device powers down in power save, each level saving more
324    /// than the one before.
325    V2ipPowerSaveLevel: u8 {
326        /// No level.
327        NONE = 0;
328        /// Part of the video processing powers down.
329        REDUCED = 1;
330        /// All of the video processing powers down.
331        LOW = 2;
332        /// Everything but the network powers down.
333        OFF = 3;
334    }
335}
336
337bitmask! {
338    /// What a unit offers at one power save level.
339    UnitPowerSave: u8 {
340        /// The unit can power down to this level.
341        SUPPORTED = 1 << 0;
342        /// A signal on the HDMI input wakes the unit.
343        INPUT_WAKE = 1 << 1;
344        /// The display powering on wakes the unit, and the unit can power it
345        /// on.
346        OUTPUT_WAKE = 1 << 2;
347    }
348}
349
350wire_enum! {
351    /// How a OneIP device takes part in PTP.
352    V2ipPtpMode: u8 {
353        /// No PTP.
354        OFF = 0;
355        /// Follows a grandmaster, and never becomes one.
356        FOLLOWER = 1;
357        /// Follows a grandmaster, or becomes one when there is none.
358        AUTO = 2;
359    }
360}
361
362wire_enum! {
363    /// The test pattern a OneIP sink draws on its output.
364    V2ipTestPattern: u8 {
365        /// No pattern.
366        OFF = 0;
367        /// Colour bars.
368        BARS = 1;
369        /// One flat colour, the one the test card carries.
370        FLAT = 2;
371        /// A ramp.
372        RAMP = 3;
373        /// A grid.
374        GRID = 4;
375        /// A strip.
376        STRIP = 5;
377        /// A test card.
378        CARD = 6;
379    }
380}
381
382wire_enum! {
383    /// The test tone a OneIP sink plays on its output.
384    V2ipToneMode: u8 {
385        /// No tone.
386        OFF = 0;
387        /// A continuous tone.
388        CONTINUOUS = 1;
389        /// A channel ident.
390        IDENT = 2;
391        /// A line-up tone, which needs two channels or more.
392        LINEUP = 3;
393        /// A beep on each lip-sync mark.
394        BEEP = 4;
395    }
396}
397
398bitmask! {
399    /// What a OneIP sink reports about its test card.
400    V2ipTestcardFlag: u8 {
401        /// The sink can draw the test card.
402        SUPPORTED = 1 << 0;
403        /// The output shows the pattern.
404        SHOWING = 1 << 1;
405        /// The tone plays on the output.
406        PLAYING = 1 << 2;
407        /// A pattern change has yet to reach the video processor.
408        PATTERN_PENDING = 1 << 3;
409        /// A tone change has yet to reach the video processor.
410        TONE_PENDING = 1 << 4;
411        /// A lip-sync change has yet to reach the video processor.
412        SYNC_PENDING = 1 << 5;
413    }
414}
415
416bitmask! {
417    /// The flags of what a OneIP output plays from a session description.
418    V2ipSdpFlag: u8 {
419        /// The output plays a stream from a description.
420        ACTIVE = 1 << 0;
421        /// And nothing else, as no video is routed to it.
422        AUDIO_ONLY = 1 << 1;
423        /// The clock mode and state hold the video processor's answer.
424        CLOCK = 1 << 2;
425    }
426}
427
428wire_enum! {
429    /// The sample encoding of a stream a OneIP output plays from a description.
430    V2ipSdpEncoding: u8 {
431        /// None.
432        NONE = 0;
433        /// 16-bit linear PCM.
434        L16 = 1;
435        /// 24-bit linear PCM.
436        L24 = 2;
437        /// AM824.
438        AM824 = 3;
439    }
440}
441
442wire_enum! {
443    /// Where a described stream's media clock comes from.
444    V2ipSdpMediaClock: u8 {
445        /// None given.
446        NONE = 0;
447        /// Direct, at an offset from the reference clock.
448        DIRECT = 1;
449        /// The sender's.
450        SENDER = 2;
451    }
452}
453
454wire_enum! {
455    /// The reference clock a described stream names.
456    V2ipSdpRefClock: u8 {
457        /// None given.
458        NONE = 0;
459        /// PTP.
460        PTP = 1;
461        /// A traceable clock.
462        TRACEABLE = 2;
463        /// The sender's local MAC.
464        LOCAL_MAC = 3;
465    }
466}
467
468wire_enum! {
469    /// What a OneIP output's video processor times a described stream by.
470    V2ipSdpClockMode: u8 {
471        /// Arrival.
472        ARRIVAL = 0;
473        /// PTP.
474        PTP = 1;
475        /// The sender.
476        SENDER = 2;
477    }
478}
479
480wire_enum! {
481    /// How far a OneIP output's video processor has got with a described
482    /// stream's timing.
483    V2ipSdpClockState: u8 {
484        /// Idle.
485        IDLE = 0;
486        /// Running its servo.
487        SERVO = 1;
488        /// Aligning.
489        ALIGNING = 2;
490        /// Timed.
491        TIMED = 3;
492        /// Parked.
493        PARKED = 4;
494        /// Playing untimed.
495        UNTIMED = 5;
496        /// The timing is not supported.
497        UNSUPPORTED = 6;
498    }
499}
500
501bitmask! {
502    /// The flags of a unit's status report.
503    UnitFlag {
504        /// A changed setting takes effect after a reboot.
505        REBOOT_REQUIRED = 1 << 0;
506        /// A newer video processor image is available.
507        FPGA_UPGRADE = 1 << 1;
508        /// The IP configuration comes from DHCP.
509        DHCP = 1 << 2;
510        /// The IP configuration was changed through the mesh, and is reverted
511        /// unless the mesh controller confirms it in time.
512        NET_PENDING = 1 << 3;
513        /// The fan runs in quiet mode.
514        FAN_QUIET = 1 << 4;
515        /// Powered by an external supply rather than PoE.
516        EXTERNAL_PSU = 1 << 5;
517        /// The video processor runs with its IP configured. Without it the
518        /// encoder and decoder health carry nothing.
519        FPGA_CONFIGURED = 1 << 6;
520        /// The encoder is enabled.
521        ENCODER_ACTIVE = 1 << 7;
522        /// The decoder is enabled.
523        DECODER_ACTIVE = 1 << 8;
524        /// The decoder disables itself without a display.
525        AUTO_DISABLE = 1 << 9;
526        /// The decoder disabled itself without a display.
527        AUTO_DISABLE_ACTIVE = 1 << 10;
528        /// The HDMI output switches off without a signal.
529        OFF_NO_SIGNAL = 1 << 11;
530        /// The HDMI output switched off without a signal.
531        OFF_NO_SIGNAL_ACTIVE = 1 << 12;
532        /// Display power is checked before the decoder is enabled.
533        POWER_CHECK = 1 << 13;
534        /// The boot count is reported.
535        BOOT_COUNT = 1 << 14;
536        /// The fan speed is reported.
537        FAN_SPEED = 1 << 15;
538    }
539}
540
541wire_enum! {
542    /// What a unit command asks of its unit.
543    UnitCommandKind: u8 {
544        /// Clear the current system status.
545        CLEAR_STATUS = 0;
546        /// Upgrade the video processor to the latest image.
547        FPGA_UPGRADE = 1;
548        /// Change the IP configuration.
549        NET_CONFIG = 2;
550        /// Keep a pending IP configuration.
551        NET_CONFIRM = 3;
552    }
553}
554
555bitmask! {
556    /// The flags of a unit command.
557    UnitCommandFlag: u8 {
558        /// With [`UnitCommandKind::FPGA_UPGRADE`]: flash the image even if it
559        /// is running already.
560        FORCE = 1 << 0;
561        /// With [`UnitCommandKind::NET_CONFIG`]: use DHCP, ignoring the
562        /// addresses.
563        DHCP = 1 << 1;
564    }
565}
566
567bitmask! {
568    /// The flags of a OneIP device's PTP state.
569    V2ipPtpFlag: u8 {
570        /// The device runs PTP and the block holds its state. A block without
571        /// it holds nothing: the device has no PTP, or is in power save.
572        VALID = 1 << 0;
573        /// The device locked to a master since its PTP started, so its mesh
574        /// holds a time.
575        FOLLOWED = 1 << 1;
576    }
577}
578
579wire_enum! {
580    /// How far a OneIP device's PTP clock has locked to its master.
581    V2ipPtpLock: u8 {
582        /// Not locked.
583        UNLOCKED = 0;
584        /// Locking.
585        LOCKING = 1;
586        /// Locked.
587        LOCKED = 2;
588    }
589}
590
591bitmask! {
592    /// The flags of a OneIP device's VLAN configuration.
593    V2ipVlanFlag: u16 {
594        /// The block carries a configuration. A block without it carries
595        /// nothing, whatever its other bytes hold.
596        VALID = 1 << 0;
597        /// Untagged frames arriving on the uplink are dropped instead of
598        /// reaching the device.
599        TRUNK = 1 << 1;
600        /// Reported by the device: the configuration is applied, and reverted
601        /// unless the mesh controller confirms it. Never written.
602        PENDING = 1 << 2;
603        /// Sent by the mesh controller: a pending configuration it heard, which
604        /// the device then keeps.
605        CONFIRM = 1 << 3;
606        /// Reported by the device: it has an SFP port. Never written.
607        HAS_SFP = 1 << 4;
608    }
609}
610
611impl V2ipDeviceSetting {
612    /// The settings that are on or off, as opposed to carrying a value, and
613    /// that can be written.
614    pub const SWITCHES: Self = Self(
615        0xFF | Self::AES67.0
616            | Self::SAP_LISTEN.0
617            | Self::SAP_ANNOUNCE.0
618            | Self::POWER_SAVE_DISABLED.0
619            | Self::CLOUD.0,
620    );
621
622    /// The settings only a device reports about itself, which no write
623    /// carries.
624    pub const REPORTED_ONLY: Self = Self(Self::IR_PROFILES.0 | Self::CLOCK_SET.0);
625
626    /// The PTP settings.
627    pub const PTP_SETTINGS: Self =
628        Self(Self::PTP_MODE.0 | Self::PTP_DOMAIN.0 | Self::PTP_PRIORITY1.0);
629
630    /// The PTP message settings.
631    pub const PTP_MESSAGES: Self = Self(
632        Self::PTP_ANNOUNCE.0
633            | Self::PTP_SYNC.0
634            | Self::PTP_DELAY_REQ.0
635            | Self::PTP_ANNOUNCE_TIMEOUT.0
636            | Self::PTP_DSCP.0,
637    );
638
639    /// The settings whose values a frame carries in a block of their own
640    /// behind the rest, [`V2ipPtpMessages`](crate::V2ipPtpMessages): the PTP
641    /// message settings, the two SAP values, the stream TTL and the output's
642    /// rotation.
643    pub const SETTINGS_BLOCK: Self = Self(
644        Self::PTP_MESSAGES.0
645            | Self::SAP_EXPIRE.0
646            | Self::SAP_INTERVAL.0
647            | Self::STREAM_TTL.0
648            | Self::SINK_ROTATION.0,
649    );
650
651    /// These bits with every bit of `other` cleared.
652    pub(crate) const fn without(self, other: Self) -> Self {
653        Self(self.0 & !other.0)
654    }
655}
656
657bitmask! {
658    /// Capabilities of a single bay.
659    BayFeatures {
660        /// HDMI output.
661        HDMI_OUT = 1 << 0;
662        /// HDMI input.
663        HDMI_IN = 1 << 1;
664        /// Digital audio output.
665        AUDIO_DIG_OUT = 1 << 2;
666        /// Digital audio input.
667        AUDIO_DIG_IN = 1 << 3;
668        /// Analogue audio output.
669        AUDIO_ANA_OUT = 1 << 4;
670        /// Analogue audio input.
671        AUDIO_ANA_IN = 1 << 5;
672        /// Infrared input.
673        IR_IN = 1 << 6;
674        /// Infrared output.
675        IR_OUT = 1 << 7;
676        /// Amplified audio output.
677        AUDIO_AMP_OUT = 1 << 8;
678        /// Remote-control output.
679        RC_OUT = 1 << 9;
680        /// Remote-control input.
681        RC_IN = 1 << 10;
682        /// Dolby decoding.
683        DOLBY = 1 << 11;
684        /// Switches itself off when idle.
685        AUTO_OFF = 1 << 12;
686        /// Is a remote OneIP source.
687        V2IP_SOURCE_REMOTE = 1 << 13;
688        /// Is a remote OneIP sink.
689        V2IP_SINK_REMOTE = 1 << 14;
690        /// Is a local OneIP source.
691        V2IP_SOURCE_LOCAL = 1 << 15;
692        /// Is a local OneIP sink.
693        V2IP_SINK_LOCAL = 1 << 16;
694    }
695}
696
697bitmask! {
698    /// Live status flags of a single bay.
699    ///
700    /// Bits 16-19 and 22-23 are bit-fields rather than flags; read them with
701    /// [`BayStatus::rc_type`] and [`BayStatus::hdcp`].
702    BayStatus {
703        /// The bay reports a fault.
704        FAULT = 1 << 0;
705        /// The bay is hidden from the user interface.
706        HIDDEN = 1 << 1;
707        /// The amplifier zone the bay drives is powered on.
708        POWERED = 1 << 2;
709        /// A signal is present.
710        SIGNAL_DETECTED = 1 << 3;
711        /// Hot-plug detect is asserted.
712        HPD_DETECTED = 1 << 4;
713        /// The signal is scrambled.
714        SIGNAL_SCRAMBLE = 1 << 5;
715        /// An HDBaseT link is up.
716        HDBT_CONNECTED = 1 << 6;
717        /// A CEC device answered.
718        CEC_DETECTED = 1 << 7;
719        /// The attached device was powered on.
720        POWERED_ON = 1 << 8;
721        /// The attached device was powered off.
722        POWERED_OFF = 1 << 9;
723        /// Audio return over HDMI is active.
724        AUDIO_ARC_HDMI = 1 << 10;
725        /// Audio return over optical is active.
726        AUDIO_ARC_OPTIC = 1 << 11;
727        /// Audio return over analogue is active.
728        AUDIO_ARC_ANALOG = 1 << 12;
729        /// The bay is offline.
730        OFFLINE = 1 << 13;
731        /// The OneIP decoder is disabled.
732        DECODER_DISABLE = 1 << 14;
733        /// The OneIP encoder is disabled.
734        ENCODER_DISABLE = 1 << 15;
735        /// CEC is switched off for this bay.
736        CEC_DISABLED = 1 << 20;
737        /// The OneIP encoder reports an error.
738        ENCODER_ERROR = 1 << 21;
739        /// The bay's name was generated - a default, or taken from CEC or the
740        /// EDID - rather than set by a user. A device that predates this bit
741        /// never sets it, so a clear bit does not prove a user set the name.
742        AUTO_NAME = 1 << 24;
743    }
744}
745
746impl BayStatus {
747    const RC_TYPE_SHIFT: u32 = 16;
748    const RC_TYPE_MASK: u32 = 0xF << Self::RC_TYPE_SHIFT;
749    const HDCP_SHIFT: u32 = 22;
750    const HDCP_MASK: u32 = 0x3 << Self::HDCP_SHIFT;
751
752    /// Extracts the remote-control type carried in bits 16-19.
753    pub const fn rc_type(self) -> RcType {
754        RcType(((self.0 & Self::RC_TYPE_MASK) >> Self::RC_TYPE_SHIFT) as u8)
755    }
756
757    /// Extracts the HDCP version carried in bits 22-23.
758    pub const fn hdcp(self) -> u8 {
759        ((self.0 & Self::HDCP_MASK) >> Self::HDCP_SHIFT) as u8
760    }
761}
762
763bitmask! {
764    /// Media carried by a virtual link.
765    LinkFeature {
766        /// Video over HDMI.
767        VIDEO_HDMI = 1 << 0;
768        /// Audio over optical.
769        AUDIO_OPTICAL = 1 << 1;
770        /// Audio over analogue.
771        AUDIO_ANALOG = 1 << 2;
772        /// Infrared.
773        IR = 1 << 3;
774        /// Remote control.
775        RC = 1 << 4;
776    }
777}
778
779wire_enum! {
780    /// A remote-control action.
781    RcAction: u16 {
782        /// Toggle power.
783        POWER_TOGGLE = 0;
784        /// Power on.
785        POWER_ON = 1;
786        /// Power off.
787        POWER_OFF = 2;
788        /// Volume up.
789        VOLUME_UP = 3;
790        /// Volume down.
791        VOLUME_DOWN = 4;
792        /// Toggle mute.
793        VOLUME_MUTE = 5;
794    }
795}
796
797wire_enum! {
798    /// A remote-control key code (CEC or IR).
799    RcKey: u16 {
800        /// Digit 0.
801        NUM0 = 0;
802        /// Digit 1.
803        NUM1 = 1;
804        /// Digit 2.
805        NUM2 = 2;
806        /// Digit 3.
807        NUM3 = 3;
808        /// Digit 4.
809        NUM4 = 4;
810        /// Digit 5.
811        NUM5 = 5;
812        /// Digit 6.
813        NUM6 = 6;
814        /// Digit 7.
815        NUM7 = 7;
816        /// Digit 8.
817        NUM8 = 8;
818        /// Digit 9.
819        NUM9 = 9;
820        /// Confirm the highlighted item.
821        SELECT = 10;
822        /// Go back one step.
823        BACK = 11;
824        /// Navigate up.
825        UP = 12;
826        /// Navigate down.
827        DOWN = 13;
828        /// Navigate left.
829        LEFT = 14;
830        /// Navigate right.
831        RIGHT = 15;
832        /// Open the main menu.
833        MENU = 16;
834        /// Open the content menu.
835        CONTENT_MENU = 17;
836        /// Next channel.
837        CHANNEL_UP = 18;
838        /// Previous channel.
839        CHANNEL_DOWN = 19;
840        /// Start playback.
841        PLAY = 20;
842        /// Pause playback.
843        PAUSE = 21;
844        /// Stop playback.
845        STOP = 22;
846        /// Start recording.
847        RECORD = 23;
848        /// Fast forward.
849        FAST_FORWARD = 24;
850        /// Rewind.
851        REWIND = 25;
852        /// Red colour key.
853        RED = 26;
854        /// Green colour key.
855        GREEN = 27;
856        /// Yellow colour key.
857        YELLOW = 28;
858        /// Blue colour key.
859        BLUE = 29;
860        /// Open help.
861        HELP = 30;
862        /// Show information.
863        INFORMATION = 31;
864        /// Open teletext.
865        TEXT = 32;
866        /// Open the programme guide.
867        GUIDE = 33;
868        /// Open video on demand.
869        VIDEO_ON_DEMAND = 34;
870        /// Return to the previous channel.
871        PREVIOUS_CHANNEL = 80;
872        /// Toggle 3D mode.
873        MODE_3D = 81;
874        /// Toggle subtitles.
875        SUBTITLE = 82;
876        /// Select an audio track.
877        SOUND_SELECT = 83;
878        /// Select an input.
879        INPUT_SELECT = 84;
880        /// Eject the medium.
881        EJECT = 85;
882        /// Next chapter.
883        NEXT_CHAPTER = 86;
884        /// Previous chapter.
885        PREV_CHAPTER = 87;
886        /// Open interactive services.
887        INTERACTIVE = 128;
888        /// Open search.
889        SEARCH = 129;
890        /// Sky home key.
891        SKY = 130;
892        /// Base of the range carrying a raw CEC user-control code.
893        CUSTOM_CEC = 1280;
894        /// Base of the range carrying a raw Sky key code.
895        CUSTOM_SKY = 2048;
896    }
897}
898
899wire_enum! {
900    /// The remote-control protocol of a connected sink or source.
901    RcType: u8 {
902        /// Infrared.
903        IR = 0;
904        /// HDMI CEC.
905        CEC = 1;
906        /// Sky UK over IP.
907        SKY_UK = 2;
908        /// TiVo.
909        TIVO = 3;
910        /// Kodi.
911        KODI = 4;
912        /// Dish.
913        DISH = 5;
914        /// DirecTV.
915        DIRECTV = 6;
916        /// Another MX Remote device.
917        MX_REMOTE = 7;
918        /// Routed inside the device itself.
919        INTERNAL = 8;
920    }
921}
922
923impl fmt::Display for RcType {
924    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
925        let name = match *self {
926            Self::IR => "IR",
927            Self::CEC => "CEC",
928            Self::SKY_UK => "Sky",
929            Self::TIVO => "TiVo",
930            Self::KODI => "Kodi",
931            Self::DISH => "Dish",
932            Self::DIRECTV => "DirecTV",
933            Self::MX_REMOTE => "MX-Remote",
934            Self::INTERNAL => "Internal",
935            _ => "Unknown",
936        };
937        f.write_str(name)
938    }
939}
940
941wire_enum! {
942    /// An EDID preset selectable on an HDMI input.
943    EdidProfile: u16 {
944        /// 1080p with stereo audio.
945        STEREO_1080P = 0;
946        /// A fixed EDID stored on the device.
947        FIXED = 1;
948        /// 4K.
949        UHD_4K = 2;
950        /// 1080p with 5.1 audio.
951        SURROUND51_1080P = 3;
952        /// 720p.
953        HD_720P = 4;
954        /// 1080p with 7.1 audio.
955        SURROUND71_1080P = 5;
956        /// 4K with 7.1 audio.
957        SURROUND71_4K = 6;
958        /// 4K HDR with stereo audio.
959        HDR_STEREO_4K = 7;
960        /// 4K HDR with 7.1 audio.
961        HDR_SURROUND71_4K = 8;
962        /// 4K HDR, audio to the AVR only.
963        HDR_AVR_ONLY_4K = 9;
964        /// The lowest common denominator of the connected sinks.
965        LOWEST_COMMON = 10;
966        /// The lowest common denominator of every sink, connected or not.
967        LOWEST_COMMON_ALL = 11;
968        /// 4K HDR with Dolby Atmos.
969        HDR_ATMOS_4K = 12;
970        /// Copy the EDID of sink 1; the range runs to [`EdidProfile::SINK_32`].
971        SINK_1 = 101;
972        /// Copy the EDID of sink 32; the range starts at [`EdidProfile::SINK_1`].
973        SINK_32 = 132;
974        /// Base of the range carrying a user-supplied EDID.
975        CUSTOM_0 = 500;
976        /// The device reports no profile.
977        UNKNOWN = 0xFFF;
978    }
979}
980
981impl fmt::Display for EdidProfile {
982    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
983        let name = match *self {
984            Self::STEREO_1080P => "1080p stereo",
985            Self::FIXED => "fixed",
986            Self::UHD_4K => "4K",
987            Self::SURROUND51_1080P => "1080p 5.1",
988            Self::HD_720P => "720p",
989            Self::SURROUND71_1080P => "1080p 7.1",
990            Self::SURROUND71_4K => "4K 7.1",
991            Self::HDR_STEREO_4K => "4K HDR Stereo",
992            Self::HDR_SURROUND71_4K => "4K HDR 7.1",
993            Self::HDR_AVR_ONLY_4K => "4K HDR AVR",
994            Self::LOWEST_COMMON => "lowest common denominator",
995            Self::LOWEST_COMMON_ALL => "lowest common denominator (all sinks)",
996            Self::HDR_ATMOS_4K => "4K HDR Dolby Atmos",
997            _ => {
998                if self.0 >= Self::SINK_1.0 && self.0 <= Self::SINK_32.0 {
999                    return write!(f, "copy from sink #{}", self.0 - Self::SINK_1.0 + 1);
1000                }
1001                return write!(f, "custom #{}", self.0);
1002            }
1003        };
1004        f.write_str(name)
1005    }
1006}
1007
1008wire_enum! {
1009    /// A firmware component.
1010    FirmwareType: u8 {
1011        /// The unit's own firmware.
1012        MCU = 0;
1013        /// The video processor's FPGA image.
1014        FPGA = 1;
1015        /// The video processor's RTOS image.
1016        RTOS = 2;
1017        /// The video processor's loader image.
1018        LOADER = 3;
1019        /// The unit's bootloader.
1020        BOOTLOADER = 4;
1021    }
1022}
1023
1024impl fmt::Display for FirmwareType {
1025    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1026        let name = match *self {
1027            Self::MCU => "MCU",
1028            Self::FPGA => "FPGA",
1029            Self::RTOS => "RTOS",
1030            Self::LOADER => "Loader",
1031            Self::BOOTLOADER => "Bootloader",
1032            _ => return write!(f, "firmware #{}", self.0),
1033        };
1034        f.write_str(name)
1035    }
1036}
1037
1038wire_enum! {
1039    /// The negotiated speed of a network port.
1040    UtpLinkSpeed: u8 {
1041        /// The device reports no speed.
1042        UNKNOWN = 0;
1043        /// 10Mbit/s.
1044        SPEED_10M = 1;
1045        /// 100Mbit/s.
1046        SPEED_100M = 2;
1047        /// 200Mbit/s.
1048        SPEED_200M = 3;
1049        /// 1Gbit/s.
1050        SPEED_1G = 4;
1051    }
1052}
1053
1054impl fmt::Display for UtpLinkSpeed {
1055    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1056        let name = match *self {
1057            Self::SPEED_10M => "10Mbit/s",
1058            Self::SPEED_100M => "100Mbit/s",
1059            Self::SPEED_200M => "200Mbit/s",
1060            Self::SPEED_1G => "1Gbit/s",
1061            _ => "Unknown",
1062        };
1063        f.write_str(name)
1064    }
1065}
1066
1067wire_enum! {
1068    /// The window layout of a multiviewer.
1069    MultiviewerViewMode: u8 {
1070        /// The device reports no layout.
1071        UNKNOWN = 0;
1072        /// One full-screen window.
1073        SINGLE = 1;
1074        /// Picture in picture.
1075        PIP = 2;
1076        /// Two windows, large.
1077        TWO_SCREEN_LARGE = 3;
1078        /// Two windows, small.
1079        TWO_SCREEN_SMALL = 4;
1080        /// Three windows, large.
1081        THREE_SCREEN_LARGE = 5;
1082        /// Three windows, small.
1083        THREE_SCREEN_SMALL = 6;
1084        /// Four windows, equal size.
1085        FOUR_SCREEN_EQUAL = 7;
1086        /// Four windows, small.
1087        FOUR_SCREEN_SMALL = 8;
1088    }
1089}
1090
1091wire_enum! {
1092    /// The corner a multiviewer places its picture-in-picture window in.
1093    MultiviewerPipPosition: u8 {
1094        /// The device reports no position.
1095        UNKNOWN = 0;
1096        /// Top left.
1097        LEFT_TOP = 1;
1098        /// Bottom left.
1099        LEFT_BOTTOM = 2;
1100        /// Top right.
1101        RIGHT_TOP = 3;
1102        /// Bottom right.
1103        RIGHT_BOTTOM = 4;
1104    }
1105}
1106
1107wire_enum! {
1108    /// The size of a multiviewer's picture-in-picture window.
1109    MultiviewerPipSize: u8 {
1110        /// The device reports no size.
1111        UNKNOWN = 0;
1112        /// Small.
1113        SMALL = 1;
1114        /// Medium.
1115        MEDIUM = 2;
1116        /// Large.
1117        LARGE = 3;
1118    }
1119}
1120
1121wire_enum! {
1122    /// The resolution and refresh rate a multiviewer drives its output at.
1123    MultiviewerOutputMode: u8 {
1124        /// The device reports no output mode.
1125        UNKNOWN = 0;
1126        /// 4096x2160p60.
1127        DCI4K_P60 = 1;
1128        /// 4096x2160p50.
1129        DCI4K_P50 = 2;
1130        /// 3840x2160p60.
1131        UHD_P60 = 3;
1132        /// 3840x2160p50.
1133        UHD_P50 = 4;
1134        /// 3840x2160p30.
1135        UHD_P30 = 5;
1136        /// 3840x2160p25.
1137        UHD_P25 = 6;
1138        /// 1920x1200p60, reduced blanking.
1139        WUXGA_P60_RB = 7;
1140        /// 1920x1080p60.
1141        HD1080_P60 = 8;
1142        /// 1920x1080p50.
1143        HD1080_P50 = 9;
1144        /// 1360x768p60.
1145        WXGA_P60 = 10;
1146        /// 1280x800p60.
1147        WXGA800_P60 = 11;
1148        /// 1280x720p60.
1149        HD720_P60 = 12;
1150        /// 1280x720p50.
1151        HD720_P50 = 13;
1152        /// 1024x768p60.
1153        XGA_P60 = 14;
1154    }
1155}
1156
1157wire_enum! {
1158    /// The HDCP version a multiviewer output negotiates.
1159    MultiviewerHdcpMode: u8 {
1160        /// The device reports no HDCP mode.
1161        UNKNOWN = 0;
1162        /// HDCP 1.4.
1163        V14 = 1;
1164        /// HDCP 2.2.
1165        V22 = 2;
1166        /// Content protection off.
1167        OFF = 3;
1168    }
1169}
1170
1171wire_enum! {
1172    /// The IT-content flag a multiviewer sets on its output.
1173    MultiviewerItcMode: u8 {
1174        /// The device reports no IT-content mode.
1175        UNKNOWN = 0;
1176        /// Video content.
1177        VIDEO = 1;
1178        /// PC content.
1179        PC = 2;
1180    }
1181}
1182
1183wire_enum! {
1184    /// The EDID template a multiviewer presents to its sources.
1185    ///
1186    /// A template's name is the largest resolution it advertises and the audio
1187    /// format it declares support for.
1188    MultiviewerEdidTemplate: u8 {
1189        /// The device reports no template.
1190        EDID_UNKNOWN = 0;
1191        /// 4K2K60 4:4:4, stereo 2.0.
1192        EDID_4K2K60_444_STEREO = 1;
1193        /// 4K2K60 4:4:4, Dolby/DTS 5.1.
1194        EDID_4K2K60_444_DOLBY_DTS_51 = 2;
1195        /// 4K2K60 4:4:4, HD audio 7.1.
1196        EDID_4K2K60_444_HD_AUDIO_71 = 3;
1197        /// 4K2K30 4:4:4, stereo 2.0.
1198        EDID_4K2K30_444_STEREO = 4;
1199        /// 4K2K30 4:4:4, Dolby/DTS 5.1.
1200        EDID_4K2K30_444_DOLBY_DTS_51 = 5;
1201        /// 4K2K30 4:4:4, HD audio 7.1.
1202        EDID_4K2K30_444_HD_AUDIO_71 = 6;
1203        /// 1080p, stereo 2.0.
1204        EDID_1080P_STEREO = 7;
1205        /// 1080p, Dolby/DTS 5.1.
1206        EDID_1080P_DOLBY_DTS_51 = 8;
1207        /// 1080p, HD audio 7.1.
1208        EDID_1080P_HD_AUDIO_71 = 9;
1209        /// 1920x1200, stereo 2.0.
1210        EDID_1920X1200_STEREO = 10;
1211        /// 1680x1050, stereo 2.0.
1212        EDID_1680X1050_STEREO = 11;
1213        /// 1600x1200, stereo 2.0.
1214        EDID_1600X1200_STEREO = 12;
1215        /// 1440x900, stereo 2.0.
1216        EDID_1440X900_STEREO = 13;
1217        /// 1360x768, stereo 2.0.
1218        EDID_1360X768_STEREO = 14;
1219        /// 1280x1024, stereo 2.0.
1220        EDID_1280X1024_STEREO = 15;
1221        /// 1024x768, stereo 2.0.
1222        EDID_1024X768_STEREO = 16;
1223        /// 720p, stereo 2.0.
1224        EDID_720P_STEREO = 17;
1225        /// Whatever the display connected to the HDMI output presents. The
1226        /// template a multiviewer leaves the factory with.
1227        EDID_COPY_OUTPUT = 18;
1228        /// The EDID loaded onto the device.
1229        EDID_CUSTOM = 19;
1230    }
1231}
1232
1233wire_enum! {
1234    /// The aspect ratio a multiviewer scales its windows to.
1235    MultiviewerAspectRatio: u8 {
1236        /// The device reports no aspect ratio.
1237        UNKNOWN = 0;
1238        /// Fill the window.
1239        FULL = 1;
1240        /// 16:9.
1241        RATIO_16_9 = 2;
1242    }
1243}
1244
1245wire_enum! {
1246    /// A multiviewer setting that is on, off, or not reported.
1247    MultiviewerBool: u8 {
1248        /// Off.
1249        OFF = 0;
1250        /// On.
1251        ON = 1;
1252        /// The device reports no value.
1253        UNKNOWN = 0xFF;
1254    }
1255}
1256
1257wire_enum! {
1258    /// One of a multiviewer's four inputs.
1259    ///
1260    /// The wire numbers the inputs from zero and this type from one, so that
1261    /// zero can mean "not reported" the way it does for every other
1262    /// multiviewer setting. So `to_wire` and `from_wire` carry this type's
1263    /// numbering rather than the wire's, and neither is the conversion to
1264    /// reach for when a raw multiviewer byte is what is in hand.
1265    MultiviewerSource: u8 {
1266        /// The device reports no source.
1267        UNKNOWN = 0;
1268        /// Input 1.
1269        INPUT_1 = 1;
1270        /// Input 2.
1271        INPUT_2 = 2;
1272        /// Input 3.
1273        INPUT_3 = 3;
1274        /// Input 4.
1275        INPUT_4 = 4;
1276    }
1277}
1278
1279impl MultiviewerSource {
1280    /// Reads a zero-based wire value, mapping anything past input 4 to
1281    /// [`MultiviewerSource::UNKNOWN`].
1282    ///
1283    /// The firmware spells "not known" as 0xFF, which lands past input 4 and
1284    /// so needs no case of its own.
1285    pub(crate) const fn from_zero_based(value: u8) -> Self {
1286        if value > 3 {
1287            Self::UNKNOWN
1288        } else {
1289            Self(value + 1)
1290        }
1291    }
1292
1293    /// The zero-based value the wire carries, or `None` for a source naming no
1294    /// input.
1295    ///
1296    /// A multiviewer reads zero as its first input, so there is no value that
1297    /// says "leave this alone": a request that cannot name an input has to be
1298    /// refused rather than sent.
1299    pub(crate) const fn to_zero_based(self) -> Option<u8> {
1300        match self.0 {
1301            1..=4 => Some(self.0 - 1),
1302            _ => None,
1303        }
1304    }
1305}
1306
1307impl MultiviewerBool {
1308    /// Reads a wire value, mapping anything but 0 and 1 to
1309    /// [`MultiviewerBool::UNKNOWN`].
1310    pub(crate) const fn from_wire_tristate(value: u8) -> Self {
1311        if value > 1 {
1312            Self::UNKNOWN
1313        } else {
1314            Self(value)
1315        }
1316    }
1317}
1318
1319wire_enum! {
1320    /// The colour space a OneIP output scales to.
1321    ///
1322    /// The field is four bits wide and only these four values are defined. A
1323    /// receiver passes the whole nibble to its validator, so a fifth value is
1324    /// dropped without a word rather than clamped to one of these.
1325    V2ipColourSpace: u8 {
1326        /// RGB.
1327        RGB = 0;
1328        /// YCbCr 4:4:4.
1329        YCBCR444 = 1;
1330        /// YCbCr 4:2:2.
1331        YCBCR422 = 2;
1332        /// YCbCr 4:2:0.
1333        YCBCR420 = 3;
1334    }
1335}
1336
1337wire_enum! {
1338    /// The 2-byte `mxr_signal_type` carried in scaling configs and bay signal
1339    /// reports.
1340    ///
1341    /// Byte 0 is the CTA-861 short video descriptor, 0 when the signal is not
1342    /// HDMI. Byte 1 packs `color:4` in the low nibble, then `non_int:1` and
1343    /// `bpp:3` above it.
1344    MxrSignalType: u16 {
1345        /// No signal format was reported.
1346        NONE = 0;
1347    }
1348}
1349
1350/// The bpp index a sender writes when it has no bit depth to report.
1351///
1352/// It sits outside the four indices that name a real depth, so an unset
1353/// format reads differently from every genuine one.
1354const SIG_BPP_UNSET: u16 = 5;
1355
1356impl MxrSignalType {
1357    /// The CTA-861 short video descriptor, 0 when the signal is not HDMI.
1358    pub const fn svd(self) -> u8 {
1359        (self.0 & 0xFF) as u8
1360    }
1361
1362    /// The colour space.
1363    pub const fn colour_space(self) -> u8 {
1364        ((self.0 >> 8) & 0xF) as u8
1365    }
1366
1367    /// Whether the frame rate carries a 1000/1001 clock.
1368    pub const fn is_non_integer(self) -> bool {
1369        self.0 & (1 << 12) != 0
1370    }
1371
1372    /// The raw bpp index as carried on the wire. The field is an index, not a
1373    /// bit depth; [`MxrSignalType::bpp`] converts it.
1374    pub const fn bpp_index(self) -> u8 {
1375        ((self.0 >> 13) & 0x7) as u8
1376    }
1377
1378    /// The bit depth the bpp index stands for, `None` when unknown or unset.
1379    pub const fn bpp(self) -> Option<u8> {
1380        match self.bpp_index() {
1381            1 => Some(8),
1382            2 => Some(10),
1383            3 => Some(12),
1384            4 => Some(16),
1385            _ => None,
1386        }
1387    }
1388
1389    /// Reports whether the word carries a signal format at all.
1390    ///
1391    /// A bay with nothing configured says so two ways. A sender that zeroes
1392    /// the word and stamps the unset bpp index leaves an index no real depth
1393    /// uses, and one that writes a plain zero leaves nothing at all. Neither
1394    /// is a format, and the svd and colour space beside them are not answers
1395    /// either: both read as zero, which is what this word says for "not HDMI"
1396    /// and "RGB" when it *is* set.
1397    pub const fn is_set(self) -> bool {
1398        self.0 != 0 && self.bpp_index() as u16 != SIG_BPP_UNSET
1399    }
1400
1401    /// Builds the word from the fields a scaling write consumes.
1402    ///
1403    /// `non_int` is left clear: the receiving struct carries the bit, and the
1404    /// apply path does not read it.
1405    ///
1406    /// Building rather than editing is the point. A sink with no mode
1407    /// configured reports the word with the unset bpp index in it, so a caller
1408    /// that read that word back and filled in an svd would send an index no
1409    /// depth uses - which the receiver decodes to zero and rejects without
1410    /// answering.
1411    pub(crate) const fn from_parts(svd: u8, colour: u8, bpp_index: u8) -> Self {
1412        Self((svd as u16) | (((colour & 0xF) as u16) << 8) | (((bpp_index & 0x7) as u16) << 13))
1413    }
1414
1415    /// The bpp index that stands for a bit depth, `None` for a depth no index
1416    /// names.
1417    ///
1418    /// Only the three depths a OneIP output stage accepts are here. Index 4
1419    /// names 16bpp, which [`MxrSignalType::bpp`] reads back from a device, but
1420    /// the output stage refuses it - so offering it as something to write would
1421    /// send a frame that is decoded cleanly and then dropped in silence.
1422    pub(crate) const fn bpp_index_for_depth(depth: u8) -> Option<u8> {
1423        match depth {
1424            8 => Some(1),
1425            10 => Some(2),
1426            12 => Some(3),
1427            _ => None,
1428        }
1429    }
1430}
1431
1432impl fmt::Display for MxrSignalType {
1433    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1434        if !self.is_set() {
1435            return f.write_str("unset");
1436        }
1437        match self.bpp() {
1438            Some(bpp) => write!(
1439                f,
1440                "svd {}, color {}, {}bpp",
1441                self.svd(),
1442                self.colour_space(),
1443                bpp
1444            ),
1445            None => write!(f, "svd {}, color {}", self.svd(), self.colour_space()),
1446        }
1447    }
1448}
1449
1450bitmask! {
1451    /// The kinds of overlay setting an overlay sync copies.
1452    OsdSyncWhat: u8 {
1453        /// Captions.
1454        CAPTIONS = 1 << 0;
1455        /// Which logo is shown, and where.
1456        LOGO = 1 << 1;
1457        /// Background colours.
1458        BACKGROUNDS = 1 << 2;
1459        /// The logo images in the four slots.
1460        LOGO_SLOTS = 1 << 3;
1461    }
1462}
1463
1464bitmask! {
1465    /// What a unit says of the message on its output.
1466    OsdMessageFlag: u8 {
1467        /// A message is set. In a write: show it, rather than take it down.
1468        SET = 1 << 0;
1469        /// The output shows it, rather than another message ahead of it.
1470        SHOWN = 1 << 1;
1471        /// The unit's video processor composes the message layer.
1472        SUPPORTED = 1 << 2;
1473        /// The unit did not take the write it answers, and reports the
1474        /// message it kept.
1475        REFUSED = 1 << 3;
1476    }
1477}
1478
1479wire_enum! {
1480    /// Where a message stands against the unit's own messages: its upgrade,
1481    /// Locate Device and encrypted source messages.
1482    OsdMessagePriority: u8 {
1483        /// After them.
1484        LOW = 0;
1485        /// Between them.
1486        NORMAL = 1;
1487        /// Before them.
1488        TOP = 2;
1489    }
1490}
1491
1492wire_enum! {
1493    /// How far a unit has got with taking an overlay sync.
1494    OsdSyncState: u8 {
1495        /// Taking it.
1496        TAKING = 0;
1497        /// Every setting written and committed.
1498        DONE = 1;
1499        /// Failed, for the reason the report gives.
1500        FAILED = 2;
1501        /// Kept for later, as the unit's video processor is off in power
1502        /// save.
1503        DEFERRED = 3;
1504    }
1505}
1506
1507wire_enum! {
1508    /// The output size an overlay setting applies at.
1509    OsdSyncSize: u8 {
1510        /// Large outputs, which every value but `SMALL` also means.
1511        LARGE = 1;
1512        /// Small outputs.
1513        SMALL = 2;
1514    }
1515}
1516
1517wire_enum! {
1518    /// How a caption's lines are aligned.
1519    OsdCaptionAlign: u8 {
1520        /// To the left.
1521        LEFT = 0;
1522        /// Centred.
1523        CENTRE = 1;
1524        /// To the right.
1525        RIGHT = 2;
1526        /// The layout's default.
1527        DEFAULT = 0xFF;
1528    }
1529}
1530
1531wire_enum! {
1532    /// How a caption's text is read.
1533    OsdCaptionFormat: u8 {
1534        /// As plain text.
1535        PLAIN = 0;
1536        /// As Markdown.
1537        MARKDOWN = 1;
1538        /// The layout's default.
1539        DEFAULT = 0xFF;
1540    }
1541}
1542
1543bitmask! {
1544    /// The caption fields an overlay setting gives. A field left out keeps
1545    /// what the unit has.
1546    OsdCaptionField: u16 {
1547        /// The font.
1548        FONT = 1 << 0;
1549        /// The size.
1550        SIZE = 1 << 1;
1551        /// The horizontal position.
1552        X = 1 << 2;
1553        /// The vertical position.
1554        Y = 1 << 3;
1555        /// The alignment.
1556        ALIGN = 1 << 4;
1557        /// The format.
1558        FORMAT = 1 << 5;
1559        /// The colour.
1560        COLOUR = 1 << 6;
1561        /// The wrap width.
1562        WRAP = 1 << 7;
1563        /// The text.
1564        TEXT = 1 << 8;
1565    }
1566}
1567
1568bitmask! {
1569    /// The logo fields an overlay setting gives. A field left out keeps what
1570    /// the unit has.
1571    OsdLogoField: u16 {
1572        /// Which logo.
1573        LOGO = 1 << 0;
1574        /// The horizontal position.
1575        X = 1 << 1;
1576        /// The vertical position.
1577        Y = 1 << 2;
1578    }
1579}