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 /// Set while the device is in its boot loader.
183 BOOT_BIT = 1 << 31;
184 }
185}
186
187bitmask! {
188 /// What a V2IP device's video processor supports, as the device reports it
189 /// in its configuration.
190 ///
191 /// Read-only, and a device's own: it fills the field in only on the frame
192 /// describing itself, and leaves it zero on one it sends to configure
193 /// another device. There is no write path.
194 ///
195 /// Bits are assigned by the video processor and only ever appended, so a
196 /// bit this library has no name for is a later capability rather than an
197 /// error. A device reports no features at all until its processor answers,
198 /// and an older processor answers with none of the optional commands, so an
199 /// empty mask is never reported as a capability set - see
200 /// [`crate::Remote::v2ip_features`], which reports it as unknown instead.
201 V2ipFpgaFeature: u64 {
202 /// Applies a DSCP marking to the streams it sources.
203 SOURCE_DSCP = 1 << 0;
204 /// Reports the audio format arriving at its sink.
205 SINK_AUDIO_FORMAT = 1 << 1;
206 /// Places a tiling window on its sink.
207 SINK_TILING_WINDOW = 1 << 2;
208 /// Reports the state of its sink's overlay.
209 SINK_OVERLAY_STATE = 1 << 3;
210 /// Reports its sink's state.
211 SINK_STATE = 1 << 4;
212 /// Reports information about the stream its sink receives.
213 SINK_STREAM_INFO = 1 << 5;
214 }
215}
216
217bitmask! {
218 /// Capabilities of a single bay.
219 BayFeatures {
220 /// HDMI output.
221 HDMI_OUT = 1 << 0;
222 /// HDMI input.
223 HDMI_IN = 1 << 1;
224 /// Digital audio output.
225 AUDIO_DIG_OUT = 1 << 2;
226 /// Digital audio input.
227 AUDIO_DIG_IN = 1 << 3;
228 /// Analogue audio output.
229 AUDIO_ANA_OUT = 1 << 4;
230 /// Analogue audio input.
231 AUDIO_ANA_IN = 1 << 5;
232 /// Infrared input.
233 IR_IN = 1 << 6;
234 /// Infrared output.
235 IR_OUT = 1 << 7;
236 /// Amplified audio output.
237 AUDIO_AMP_OUT = 1 << 8;
238 /// Remote-control output.
239 RC_OUT = 1 << 9;
240 /// Remote-control input.
241 RC_IN = 1 << 10;
242 /// Dolby decoding.
243 DOLBY = 1 << 11;
244 /// Switches itself off when idle.
245 AUTO_OFF = 1 << 12;
246 /// Is a remote V2IP source.
247 V2IP_SOURCE_REMOTE = 1 << 13;
248 /// Is a remote V2IP sink.
249 V2IP_SINK_REMOTE = 1 << 14;
250 /// Is a local V2IP source.
251 V2IP_SOURCE_LOCAL = 1 << 15;
252 /// Is a local V2IP sink.
253 V2IP_SINK_LOCAL = 1 << 16;
254 }
255}
256
257bitmask! {
258 /// Live status flags of a single bay.
259 ///
260 /// Bits 16-19 and 22-23 are bit-fields rather than flags; read them with
261 /// [`BayStatus::rc_type`] and [`BayStatus::hdcp`].
262 BayStatus {
263 /// The bay reports a fault.
264 FAULT = 1 << 0;
265 /// The bay is hidden from the user interface.
266 HIDDEN = 1 << 1;
267 /// The bay has power.
268 POWERED = 1 << 2;
269 /// A signal is present.
270 SIGNAL_DETECTED = 1 << 3;
271 /// Hot-plug detect is asserted.
272 HPD_DETECTED = 1 << 4;
273 /// The signal is scrambled.
274 SIGNAL_SCRAMBLE = 1 << 5;
275 /// An HDBaseT link is up.
276 HDBT_CONNECTED = 1 << 6;
277 /// A CEC device answered.
278 CEC_DETECTED = 1 << 7;
279 /// The attached device was powered on.
280 POWERED_ON = 1 << 8;
281 /// The attached device was powered off.
282 POWERED_OFF = 1 << 9;
283 /// Audio return over HDMI is active.
284 AUDIO_ARC_HDMI = 1 << 10;
285 /// Audio return over optical is active.
286 AUDIO_ARC_OPTIC = 1 << 11;
287 /// Audio return over analogue is active.
288 AUDIO_ARC_ANALOG = 1 << 12;
289 /// The bay is offline.
290 OFFLINE = 1 << 13;
291 /// The V2IP decoder is disabled.
292 DECODER_DISABLE = 1 << 14;
293 /// The V2IP encoder is disabled.
294 ENCODER_DISABLE = 1 << 15;
295 /// CEC is switched off for this bay.
296 CEC_DISABLED = 1 << 20;
297 /// The V2IP encoder reports an error.
298 ENCODER_ERROR = 1 << 21;
299 }
300}
301
302impl BayStatus {
303 const RC_TYPE_SHIFT: u32 = 16;
304 const RC_TYPE_MASK: u32 = 0xF << Self::RC_TYPE_SHIFT;
305 const HDCP_SHIFT: u32 = 22;
306 const HDCP_MASK: u32 = 0x3 << Self::HDCP_SHIFT;
307
308 /// Extracts the remote-control type carried in bits 16-19.
309 pub const fn rc_type(self) -> RcType {
310 RcType(((self.0 & Self::RC_TYPE_MASK) >> Self::RC_TYPE_SHIFT) as u8)
311 }
312
313 /// Extracts the HDCP version carried in bits 22-23.
314 pub const fn hdcp(self) -> u8 {
315 ((self.0 & Self::HDCP_MASK) >> Self::HDCP_SHIFT) as u8
316 }
317}
318
319bitmask! {
320 /// Media carried by a virtual link.
321 LinkFeature {
322 /// Video over HDMI.
323 VIDEO_HDMI = 1 << 0;
324 /// Audio over optical.
325 AUDIO_OPTICAL = 1 << 1;
326 /// Audio over analogue.
327 AUDIO_ANALOG = 1 << 2;
328 /// Infrared.
329 IR = 1 << 3;
330 /// Remote control.
331 RC = 1 << 4;
332 }
333}
334
335wire_enum! {
336 /// A remote-control action.
337 RcAction: u16 {
338 /// Toggle power.
339 POWER_TOGGLE = 0;
340 /// Power on.
341 POWER_ON = 1;
342 /// Power off.
343 POWER_OFF = 2;
344 /// Volume down.
345 VOLUME_DOWN = 3;
346 /// Volume up.
347 VOLUME_UP = 4;
348 /// Toggle mute.
349 VOLUME_MUTE = 5;
350 }
351}
352
353wire_enum! {
354 /// A remote-control key code (CEC or IR).
355 RcKey: u16 {
356 /// Digit 0.
357 NUM0 = 0;
358 /// Digit 1.
359 NUM1 = 1;
360 /// Digit 2.
361 NUM2 = 2;
362 /// Digit 3.
363 NUM3 = 3;
364 /// Digit 4.
365 NUM4 = 4;
366 /// Digit 5.
367 NUM5 = 5;
368 /// Digit 6.
369 NUM6 = 6;
370 /// Digit 7.
371 NUM7 = 7;
372 /// Digit 8.
373 NUM8 = 8;
374 /// Digit 9.
375 NUM9 = 9;
376 /// Confirm the highlighted item.
377 SELECT = 10;
378 /// Go back one step.
379 BACK = 11;
380 /// Navigate up.
381 UP = 12;
382 /// Navigate down.
383 DOWN = 13;
384 /// Navigate left.
385 LEFT = 14;
386 /// Navigate right.
387 RIGHT = 15;
388 /// Open the main menu.
389 MENU = 16;
390 /// Open the content menu.
391 CONTENT_MENU = 17;
392 /// Next channel.
393 CHANNEL_UP = 18;
394 /// Previous channel.
395 CHANNEL_DOWN = 19;
396 /// Start playback.
397 PLAY = 20;
398 /// Pause playback.
399 PAUSE = 21;
400 /// Stop playback.
401 STOP = 22;
402 /// Start recording.
403 RECORD = 23;
404 /// Fast forward.
405 FAST_FORWARD = 24;
406 /// Rewind.
407 REWIND = 25;
408 /// Red colour key.
409 RED = 26;
410 /// Green colour key.
411 GREEN = 27;
412 /// Yellow colour key.
413 YELLOW = 28;
414 /// Blue colour key.
415 BLUE = 29;
416 /// Open help.
417 HELP = 30;
418 /// Show information.
419 INFORMATION = 31;
420 /// Open teletext.
421 TEXT = 32;
422 /// Open the programme guide.
423 GUIDE = 33;
424 /// Open video on demand.
425 VIDEO_ON_DEMAND = 34;
426 /// Return to the previous channel.
427 PREVIOUS_CHANNEL = 80;
428 /// Toggle 3D mode.
429 MODE_3D = 81;
430 /// Toggle subtitles.
431 SUBTITLE = 82;
432 /// Select an audio track.
433 SOUND_SELECT = 83;
434 /// Select an input.
435 INPUT_SELECT = 84;
436 /// Eject the medium.
437 EJECT = 85;
438 /// Next chapter.
439 NEXT_CHAPTER = 86;
440 /// Previous chapter.
441 PREV_CHAPTER = 87;
442 /// Open interactive services.
443 INTERACTIVE = 128;
444 /// Open search.
445 SEARCH = 129;
446 /// Sky home key.
447 SKY = 130;
448 /// Base of the range carrying a raw CEC user-control code.
449 CUSTOM_CEC = 1280;
450 /// Base of the range carrying a raw Sky key code.
451 CUSTOM_SKY = 2048;
452 }
453}
454
455wire_enum! {
456 /// The remote-control protocol of a connected sink or source.
457 RcType: u8 {
458 /// Infrared.
459 IR = 0;
460 /// HDMI CEC.
461 CEC = 1;
462 /// Sky UK over IP.
463 SKY_UK = 2;
464 /// TiVo.
465 TIVO = 3;
466 /// Kodi.
467 KODI = 4;
468 /// Dish.
469 DISH = 5;
470 /// DirecTV.
471 DIRECTV = 6;
472 /// Another MX Remote device.
473 MX_REMOTE = 7;
474 }
475}
476
477impl fmt::Display for RcType {
478 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
479 let name = match *self {
480 Self::IR => "IR",
481 Self::CEC => "CEC",
482 Self::SKY_UK => "Sky",
483 Self::TIVO => "TiVo",
484 Self::KODI => "Kodi",
485 Self::DISH => "Dish",
486 Self::DIRECTV => "DirecTV",
487 Self::MX_REMOTE => "MX-Remote",
488 _ => "Unknown",
489 };
490 f.write_str(name)
491 }
492}
493
494wire_enum! {
495 /// An EDID preset selectable on an HDMI input.
496 EdidProfile: u16 {
497 /// 1080p with stereo audio.
498 STEREO_1080P = 0;
499 /// A fixed EDID stored on the device.
500 FIXED = 1;
501 /// 4K.
502 UHD_4K = 2;
503 /// 1080p with 5.1 audio.
504 SURROUND51_1080P = 3;
505 /// 720p.
506 HD_720P = 4;
507 /// 1080p with 7.1 audio.
508 SURROUND71_1080P = 5;
509 /// 4K with 7.1 audio.
510 SURROUND71_4K = 6;
511 /// 4K HDR with stereo audio.
512 HDR_STEREO_4K = 7;
513 /// 4K HDR with 7.1 audio.
514 HDR_SURROUND71_4K = 8;
515 /// 4K HDR, audio to the AVR only.
516 HDR_AVR_ONLY_4K = 9;
517 /// The lowest common denominator of the connected sinks.
518 LOWEST_COMMON = 10;
519 /// The lowest common denominator of every sink, connected or not.
520 LOWEST_COMMON_ALL = 11;
521 /// 4K HDR with Dolby Atmos.
522 HDR_ATMOS_4K = 12;
523 /// Copy the EDID of sink 1; the range runs to [`EdidProfile::SINK_32`].
524 SINK_1 = 101;
525 /// Copy the EDID of sink 32; the range starts at [`EdidProfile::SINK_1`].
526 SINK_32 = 132;
527 /// Base of the range carrying a user-supplied EDID.
528 CUSTOM_0 = 500;
529 /// The device reports no profile.
530 UNKNOWN = 0xFFF;
531 }
532}
533
534impl fmt::Display for EdidProfile {
535 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
536 let name = match *self {
537 Self::STEREO_1080P => "1080p stereo",
538 Self::FIXED => "fixed",
539 Self::UHD_4K => "4K",
540 Self::SURROUND51_1080P => "1080p 5.1",
541 Self::HD_720P => "720p",
542 Self::SURROUND71_1080P => "1080p 7.1",
543 Self::SURROUND71_4K => "4K 7.1",
544 Self::HDR_STEREO_4K => "4K HDR Stereo",
545 Self::HDR_SURROUND71_4K => "4K HDR 7.1",
546 Self::HDR_AVR_ONLY_4K => "4K HDR AVR",
547 Self::LOWEST_COMMON => "lowest common denominator",
548 Self::LOWEST_COMMON_ALL => "lowest common denominator (all sinks)",
549 Self::HDR_ATMOS_4K => "4K HDR Dolby Atmos",
550 _ => {
551 if self.0 >= Self::SINK_1.0 && self.0 <= Self::SINK_32.0 {
552 return write!(f, "copy from sink #{}", self.0 - Self::SINK_1.0 + 1);
553 }
554 return write!(f, "custom #{}", self.0);
555 }
556 };
557 f.write_str(name)
558 }
559}
560
561wire_enum! {
562 /// A firmware component.
563 FirmwareType: u8 {
564 /// The component is not known.
565 UNKNOWN = 0;
566 /// The FPGA bitstream.
567 FPGA = 1;
568 /// The Linux system image.
569 LINUX = 2;
570 /// A loadable overlay.
571 LOADING_OVERLAY = 3;
572 }
573}
574
575impl fmt::Display for FirmwareType {
576 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
577 let name = match *self {
578 Self::FPGA => "FPGA",
579 Self::LINUX => "Linux",
580 Self::LOADING_OVERLAY => "Loading Overlay",
581 _ => "Unknown",
582 };
583 f.write_str(name)
584 }
585}
586
587wire_enum! {
588 /// The negotiated speed of a network port.
589 UtpLinkSpeed: u8 {
590 /// The device reports no speed.
591 UNKNOWN = 0;
592 /// 10Mbit/s.
593 SPEED_10M = 1;
594 /// 100Mbit/s.
595 SPEED_100M = 2;
596 /// 200Mbit/s.
597 SPEED_200M = 3;
598 /// 1Gbit/s.
599 SPEED_1G = 4;
600 }
601}
602
603impl fmt::Display for UtpLinkSpeed {
604 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
605 let name = match *self {
606 Self::SPEED_10M => "10Mbit/s",
607 Self::SPEED_100M => "100Mbit/s",
608 Self::SPEED_200M => "200Mbit/s",
609 Self::SPEED_1G => "1Gbit/s",
610 _ => "Unknown",
611 };
612 f.write_str(name)
613 }
614}
615
616wire_enum! {
617 /// The window layout of a multiviewer.
618 MultiviewerViewMode: u8 {
619 /// The device reports no layout.
620 UNKNOWN = 0;
621 /// One full-screen window.
622 SINGLE = 1;
623 /// Picture in picture.
624 PIP = 2;
625 /// Two windows, large.
626 TWO_SCREEN_LARGE = 3;
627 /// Two windows, small.
628 TWO_SCREEN_SMALL = 4;
629 /// Three windows, large.
630 THREE_SCREEN_LARGE = 5;
631 /// Three windows, small.
632 THREE_SCREEN_SMALL = 6;
633 /// Four windows, equal size.
634 FOUR_SCREEN_EQUAL = 7;
635 /// Four windows, small.
636 FOUR_SCREEN_SMALL = 8;
637 }
638}
639
640wire_enum! {
641 /// The corner a multiviewer places its picture-in-picture window in.
642 MultiviewerPipPosition: u8 {
643 /// The device reports no position.
644 UNKNOWN = 0;
645 /// Top left.
646 LEFT_TOP = 1;
647 /// Bottom left.
648 LEFT_BOTTOM = 2;
649 /// Top right.
650 RIGHT_TOP = 3;
651 /// Bottom right.
652 RIGHT_BOTTOM = 4;
653 }
654}
655
656wire_enum! {
657 /// The size of a multiviewer's picture-in-picture window.
658 MultiviewerPipSize: u8 {
659 /// The device reports no size.
660 UNKNOWN = 0;
661 /// Small.
662 SMALL = 1;
663 /// Medium.
664 MEDIUM = 2;
665 /// Large.
666 LARGE = 3;
667 }
668}
669
670wire_enum! {
671 /// The resolution and refresh rate a multiviewer drives its output at.
672 MultiviewerOutputMode: u8 {
673 /// The device reports no output mode.
674 UNKNOWN = 0;
675 /// 4096x2160p60.
676 DCI4K_P60 = 1;
677 /// 4096x2160p50.
678 DCI4K_P50 = 2;
679 /// 3840x2160p60.
680 UHD_P60 = 3;
681 /// 3840x2160p50.
682 UHD_P50 = 4;
683 /// 3840x2160p30.
684 UHD_P30 = 5;
685 /// 3840x2160p25.
686 UHD_P25 = 6;
687 /// 1920x1200p60, reduced blanking.
688 WUXGA_P60_RB = 7;
689 /// 1920x1080p60.
690 HD1080_P60 = 8;
691 /// 1920x1080p50.
692 HD1080_P50 = 9;
693 /// 1360x768p60.
694 WXGA_P60 = 10;
695 /// 1280x800p60.
696 WXGA800_P60 = 11;
697 /// 1280x720p60.
698 HD720_P60 = 12;
699 /// 1280x720p50.
700 HD720_P50 = 13;
701 /// 1024x768p60.
702 XGA_P60 = 14;
703 }
704}
705
706wire_enum! {
707 /// The HDCP version a multiviewer output negotiates.
708 MultiviewerHdcpMode: u8 {
709 /// The device reports no HDCP mode.
710 UNKNOWN = 0;
711 /// HDCP 1.4.
712 V14 = 1;
713 /// HDCP 2.2.
714 V22 = 2;
715 /// Content protection off.
716 OFF = 3;
717 }
718}
719
720wire_enum! {
721 /// The IT-content flag a multiviewer sets on its output.
722 MultiviewerItcMode: u8 {
723 /// The device reports no IT-content mode.
724 UNKNOWN = 0;
725 /// Video content.
726 VIDEO = 1;
727 /// PC content.
728 PC = 2;
729 }
730}
731
732wire_enum! {
733 /// The EDID template a multiviewer presents to its sources.
734 ///
735 /// A template's name is the largest resolution it advertises and the audio
736 /// format it declares support for.
737 MultiviewerEdidTemplate: u8 {
738 /// The device reports no template.
739 EDID_UNKNOWN = 0;
740 /// 4K2K60 4:4:4, stereo 2.0.
741 EDID_4K2K60_444_STEREO = 1;
742 /// 4K2K60 4:4:4, Dolby/DTS 5.1.
743 EDID_4K2K60_444_DOLBY_DTS_51 = 2;
744 /// 4K2K60 4:4:4, HD audio 7.1.
745 EDID_4K2K60_444_HD_AUDIO_71 = 3;
746 /// 4K2K30 4:4:4, stereo 2.0.
747 EDID_4K2K30_444_STEREO = 4;
748 /// 4K2K30 4:4:4, Dolby/DTS 5.1.
749 EDID_4K2K30_444_DOLBY_DTS_51 = 5;
750 /// 4K2K30 4:4:4, HD audio 7.1.
751 EDID_4K2K30_444_HD_AUDIO_71 = 6;
752 /// 1080p, stereo 2.0.
753 EDID_1080P_STEREO = 7;
754 /// 1080p, Dolby/DTS 5.1.
755 EDID_1080P_DOLBY_DTS_51 = 8;
756 /// 1080p, HD audio 7.1.
757 EDID_1080P_HD_AUDIO_71 = 9;
758 /// 1920x1200, stereo 2.0.
759 EDID_1920X1200_STEREO = 10;
760 /// 1680x1050, stereo 2.0.
761 EDID_1680X1050_STEREO = 11;
762 /// 1600x1200, stereo 2.0.
763 EDID_1600X1200_STEREO = 12;
764 /// 1440x900, stereo 2.0.
765 EDID_1440X900_STEREO = 13;
766 /// 1360x768, stereo 2.0.
767 EDID_1360X768_STEREO = 14;
768 /// 1280x1024, stereo 2.0.
769 EDID_1280X1024_STEREO = 15;
770 /// 1024x768, stereo 2.0.
771 EDID_1024X768_STEREO = 16;
772 /// 720p, stereo 2.0.
773 EDID_720P_STEREO = 17;
774 /// Whatever the display connected to the HDMI output presents. The
775 /// template a multiviewer leaves the factory with.
776 EDID_COPY_OUTPUT = 18;
777 /// The EDID loaded onto the device.
778 EDID_CUSTOM = 19;
779 }
780}
781
782wire_enum! {
783 /// The aspect ratio a multiviewer scales its windows to.
784 MultiviewerAspectRatio: u8 {
785 /// The device reports no aspect ratio.
786 UNKNOWN = 0;
787 /// Fill the window.
788 FULL = 1;
789 /// 16:9.
790 RATIO_16_9 = 2;
791 }
792}
793
794wire_enum! {
795 /// A multiviewer setting that is on, off, or not reported.
796 MultiviewerBool: u8 {
797 /// Off.
798 OFF = 0;
799 /// On.
800 ON = 1;
801 /// The device reports no value.
802 UNKNOWN = 0xFF;
803 }
804}
805
806wire_enum! {
807 /// One of a multiviewer's four inputs.
808 ///
809 /// The wire numbers the inputs from zero and this type from one, so that
810 /// zero can mean "not reported" the way it does for every other
811 /// multiviewer setting. So `to_wire` and `from_wire` carry this type's
812 /// numbering rather than the wire's, and neither is the conversion to
813 /// reach for when a raw multiviewer byte is what is in hand.
814 MultiviewerSource: u8 {
815 /// The device reports no source.
816 UNKNOWN = 0;
817 /// Input 1.
818 INPUT_1 = 1;
819 /// Input 2.
820 INPUT_2 = 2;
821 /// Input 3.
822 INPUT_3 = 3;
823 /// Input 4.
824 INPUT_4 = 4;
825 }
826}
827
828impl MultiviewerSource {
829 /// Reads a zero-based wire value, mapping anything past input 4 to
830 /// [`MultiviewerSource::UNKNOWN`].
831 ///
832 /// The firmware spells "not known" as 0xFF, which lands past input 4 and
833 /// so needs no case of its own.
834 pub(crate) const fn from_zero_based(value: u8) -> Self {
835 if value > 3 {
836 Self::UNKNOWN
837 } else {
838 Self(value + 1)
839 }
840 }
841
842 /// The zero-based value the wire carries, or `None` for a source naming no
843 /// input.
844 ///
845 /// A multiviewer reads zero as its first input, so there is no value that
846 /// says "leave this alone": a request that cannot name an input has to be
847 /// refused rather than sent.
848 pub(crate) const fn to_zero_based(self) -> Option<u8> {
849 match self.0 {
850 1..=4 => Some(self.0 - 1),
851 _ => None,
852 }
853 }
854}
855
856impl MultiviewerBool {
857 /// Reads a wire value, mapping anything but 0 and 1 to
858 /// [`MultiviewerBool::UNKNOWN`].
859 pub(crate) const fn from_wire_tristate(value: u8) -> Self {
860 if value > 1 {
861 Self::UNKNOWN
862 } else {
863 Self(value)
864 }
865 }
866}
867
868wire_enum! {
869 /// The colour space a V2IP output scales to.
870 ///
871 /// The field is four bits wide and only these four values are defined. A
872 /// receiver passes the whole nibble to its validator, so a fifth value is
873 /// dropped without a word rather than clamped to one of these.
874 V2ipColourSpace: u8 {
875 /// RGB.
876 RGB = 0;
877 /// YCbCr 4:4:4.
878 YCBCR444 = 1;
879 /// YCbCr 4:2:2.
880 YCBCR422 = 2;
881 /// YCbCr 4:2:0.
882 YCBCR420 = 3;
883 }
884}
885
886wire_enum! {
887 /// The 2-byte `mxr_signal_type` carried in scaling configs and bay signal
888 /// reports.
889 ///
890 /// Byte 0 is the CTA-861 short video descriptor, 0 when the signal is not
891 /// HDMI. Byte 1 packs `color:4` in the low nibble, then `non_int:1` and
892 /// `bpp:3` above it.
893 MxrSignalType: u16 {
894 /// No signal format was reported.
895 NONE = 0;
896 }
897}
898
899/// The bpp index a sender writes when it has no bit depth to report.
900///
901/// It sits outside the four indices that name a real depth, so an unset
902/// format reads differently from every genuine one.
903const SIG_BPP_UNSET: u16 = 5;
904
905impl MxrSignalType {
906 /// The CTA-861 short video descriptor, 0 when the signal is not HDMI.
907 pub const fn svd(self) -> u8 {
908 (self.0 & 0xFF) as u8
909 }
910
911 /// The colour space.
912 pub const fn colour_space(self) -> u8 {
913 ((self.0 >> 8) & 0xF) as u8
914 }
915
916 /// Whether the frame rate carries a 1000/1001 clock.
917 pub const fn is_non_integer(self) -> bool {
918 self.0 & (1 << 12) != 0
919 }
920
921 /// The raw bpp index as carried on the wire. The field is an index, not a
922 /// bit depth; [`MxrSignalType::bpp`] converts it.
923 pub const fn bpp_index(self) -> u8 {
924 ((self.0 >> 13) & 0x7) as u8
925 }
926
927 /// The bit depth the bpp index stands for, `None` when unknown or unset.
928 pub const fn bpp(self) -> Option<u8> {
929 match self.bpp_index() {
930 1 => Some(8),
931 2 => Some(10),
932 3 => Some(12),
933 4 => Some(16),
934 _ => None,
935 }
936 }
937
938 /// Reports whether the word carries a signal format at all.
939 ///
940 /// A bay with nothing configured says so two ways. A sender that zeroes
941 /// the word and stamps the unset bpp index leaves an index no real depth
942 /// uses, and one that writes a plain zero leaves nothing at all. Neither
943 /// is a format, and the svd and colour space beside them are not answers
944 /// either: both read as zero, which is what this word says for "not HDMI"
945 /// and "RGB" when it *is* set.
946 pub const fn is_set(self) -> bool {
947 self.0 != 0 && self.bpp_index() as u16 != SIG_BPP_UNSET
948 }
949
950 /// Builds the word from the fields a scaling write consumes.
951 ///
952 /// `non_int` is left clear: the receiving struct carries the bit, and the
953 /// apply path does not read it.
954 ///
955 /// Building rather than editing is the point. A sink with no mode
956 /// configured reports the word with the unset bpp index in it, so a caller
957 /// that read that word back and filled in an svd would send an index no
958 /// depth uses - which the receiver decodes to zero and rejects without
959 /// answering.
960 pub(crate) const fn from_parts(svd: u8, colour: u8, bpp_index: u8) -> Self {
961 Self((svd as u16) | (((colour & 0xF) as u16) << 8) | (((bpp_index & 0x7) as u16) << 13))
962 }
963
964 /// The bpp index that stands for a bit depth, `None` for a depth no index
965 /// names.
966 ///
967 /// Only the three depths a V2IP output stage accepts are here. Index 4
968 /// names 16bpp, which [`MxrSignalType::bpp`] reads back from a device, but
969 /// the output stage refuses it - so offering it as something to write would
970 /// send a frame that is decoded cleanly and then dropped in silence.
971 pub(crate) const fn bpp_index_for_depth(depth: u8) -> Option<u8> {
972 match depth {
973 8 => Some(1),
974 10 => Some(2),
975 12 => Some(3),
976 _ => None,
977 }
978 }
979}
980
981impl fmt::Display for MxrSignalType {
982 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
983 if !self.is_set() {
984 return f.write_str("unset");
985 }
986 match self.bpp() {
987 Some(bpp) => write!(
988 f,
989 "svd {}, color {}, {}bpp",
990 self.svd(),
991 self.colour_space(),
992 bpp
993 ),
994 None => write!(f, "svd {}, color {}", self.svd(), self.colour_space()),
995 }
996 }
997}