Skip to main content

matter_kit/clusters/generated/
keypad_input.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Keypad Input — cluster 0x0509.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Keypad Input (cluster `0x0509`, revision 1).
10//!
11//! 2 identifiers, 3 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0509;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "KEYPADINPUT";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Supports UP, DOWN, LEFT, RIGHT, SELECT, BACK, EXIT, MENU
42    ///
43    /// Code `NV`, bit 0.
44    pub const NAVIGATION_KEY_CODES: u32 = 1 << 0;
45    /// Supports CEC keys 0x0A (Settings) and 0x09 (Home)
46    ///
47    /// Code `LK`, bit 1.
48    pub const LOCATION_KEYS: u32 = 1 << 1;
49    /// Supports numeric input 0..9
50    ///
51    /// Code `NK`, bit 2.
52    pub const NUMBER_KEYS: u32 = 1 << 2;
53}
54
55/// Every feature bit, with its conformance.
56pub const FEATURES: &[Feature] = &[
57    Feature {
58        bit: 0,
59        code: "NV",
60        name: "NavigationKeyCodes",
61        conform: Conform::OPTIONAL,
62    },
63    Feature {
64        bit: 1,
65        code: "LK",
66        name: "LocationKeys",
67        conform: Conform::OPTIONAL,
68    },
69    Feature {
70        bit: 2,
71        code: "NK",
72        name: "NumberKeys",
73        conform: Conform::OPTIONAL,
74    },
75];
76
77/// The command ids.
78pub mod command {
79    use crate::im::CommandId;
80
81    /// `SendKey`.
82    pub const SEND_KEY: CommandId = 0x00;
83    /// `SendKeyResponse`.
84    pub const SEND_KEY_RESPONSE: CommandId = 0x01;
85}
86
87/// `CecKeyCodeEnum`.
88#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
89#[repr(u8)]
90pub enum CecKeyCodeEnum {
91    /// `Select`.
92    Select = 0,
93    /// `Up`.
94    Up = 1,
95    /// `Down`.
96    Down = 2,
97    /// `Left`.
98    Left = 3,
99    /// `Right`.
100    Right = 4,
101    /// `RightUp`.
102    RightUp = 5,
103    /// `RightDown`.
104    RightDown = 6,
105    /// `LeftUp`.
106    LeftUp = 7,
107    /// `LeftDown`.
108    LeftDown = 8,
109    /// `RootMenu`.
110    RootMenu = 9,
111    /// `SetupMenu`.
112    SetupMenu = 10,
113    /// `ContentsMenu`.
114    ContentsMenu = 11,
115    /// `FavoriteMenu`.
116    FavoriteMenu = 12,
117    /// `Exit`.
118    Exit = 13,
119    /// `MediaTopMenu`.
120    MediaTopMenu = 16,
121    /// `MediaContextSensitiveMenu`.
122    MediaContextSensitiveMenu = 17,
123    /// `NumberEntryMode`.
124    NumberEntryMode = 29,
125    /// `Number11`.
126    Number11 = 30,
127    /// `Number12`.
128    Number12 = 31,
129    /// `Number0OrNumber10`.
130    Number0OrNumber10 = 32,
131    /// `Numbers1`.
132    Numbers1 = 33,
133    /// `Numbers2`.
134    Numbers2 = 34,
135    /// `Numbers3`.
136    Numbers3 = 35,
137    /// `Numbers4`.
138    Numbers4 = 36,
139    /// `Numbers5`.
140    Numbers5 = 37,
141    /// `Numbers6`.
142    Numbers6 = 38,
143    /// `Numbers7`.
144    Numbers7 = 39,
145    /// `Numbers8`.
146    Numbers8 = 40,
147    /// `Numbers9`.
148    Numbers9 = 41,
149    /// `Dot`.
150    Dot = 42,
151    /// `Enter`.
152    Enter = 43,
153    /// `Clear`.
154    Clear = 44,
155    /// `NextFavorite`.
156    NextFavorite = 47,
157    /// `ChannelUp`.
158    ChannelUp = 48,
159    /// `ChannelDown`.
160    ChannelDown = 49,
161    /// `PreviousChannel`.
162    PreviousChannel = 50,
163    /// `SoundSelect`.
164    SoundSelect = 51,
165    /// `InputSelect`.
166    InputSelect = 52,
167    /// `DisplayInformation`.
168    DisplayInformation = 53,
169    /// `Help`.
170    Help = 54,
171    /// `PageUp`.
172    PageUp = 55,
173    /// `PageDown`.
174    PageDown = 56,
175    /// `Power`.
176    Power = 64,
177    /// `VolumeUp`.
178    VolumeUp = 65,
179    /// `VolumeDown`.
180    VolumeDown = 66,
181    /// `Mute`.
182    Mute = 67,
183    /// `Play`.
184    Play = 68,
185    /// `Stop`.
186    Stop = 69,
187    /// `Pause`.
188    Pause = 70,
189    /// `Record`.
190    Record = 71,
191    /// `Rewind`.
192    Rewind = 72,
193    /// `FastForward`.
194    FastForward = 73,
195    /// `Eject`.
196    Eject = 74,
197    /// `Forward`.
198    Forward = 75,
199    /// `Backward`.
200    Backward = 76,
201    /// `StopRecord`.
202    StopRecord = 77,
203    /// `PauseRecord`.
204    PauseRecord = 78,
205    /// `Reserved`.
206    Reserved = 79,
207    /// `Angle`.
208    Angle = 80,
209    /// `SubPicture`.
210    SubPicture = 81,
211    /// `VideoOnDemand`.
212    VideoOnDemand = 82,
213    /// `ElectronicProgramGuide`.
214    ElectronicProgramGuide = 83,
215    /// `TimerProgramming`.
216    TimerProgramming = 84,
217    /// `InitialConfiguration`.
218    InitialConfiguration = 85,
219    /// `SelectBroadcastType`.
220    SelectBroadcastType = 86,
221    /// `SelectSoundPresentation`.
222    SelectSoundPresentation = 87,
223    /// `PlayFunction`.
224    PlayFunction = 96,
225    /// `PausePlayFunction`.
226    PausePlayFunction = 97,
227    /// `RecordFunction`.
228    RecordFunction = 98,
229    /// `PauseRecordFunction`.
230    PauseRecordFunction = 99,
231    /// `StopFunction`.
232    StopFunction = 100,
233    /// `MuteFunction`.
234    MuteFunction = 101,
235    /// `RestoreVolumeFunction`.
236    RestoreVolumeFunction = 102,
237    /// `TuneFunction`.
238    TuneFunction = 103,
239    /// `SelectMediaFunction`.
240    SelectMediaFunction = 104,
241    /// `SelectAvInputFunction`.
242    SelectAvInputFunction = 105,
243    /// `SelectAudioInputFunction`.
244    SelectAudioInputFunction = 106,
245    /// `PowerToggleFunction`.
246    PowerToggleFunction = 107,
247    /// `PowerOffFunction`.
248    PowerOffFunction = 108,
249    /// `PowerOnFunction`.
250    PowerOnFunction = 109,
251    /// `F1Blue`.
252    F1Blue = 113,
253    /// `F2Red`.
254    F2Red = 114,
255    /// `F3Green`.
256    F3Green = 115,
257    /// `F4Yellow`.
258    F4Yellow = 116,
259    /// `F5`.
260    F5 = 117,
261    /// `Data`.
262    Data = 118,
263}
264
265impl CecKeyCodeEnum {
266    /// Reads a wire value, or `None` for one this revision does not define.
267    #[must_use]
268    pub const fn from_value(value: u8) -> Option<Self> {
269        match value {
270            0 => Some(Self::Select),
271            1 => Some(Self::Up),
272            2 => Some(Self::Down),
273            3 => Some(Self::Left),
274            4 => Some(Self::Right),
275            5 => Some(Self::RightUp),
276            6 => Some(Self::RightDown),
277            7 => Some(Self::LeftUp),
278            8 => Some(Self::LeftDown),
279            9 => Some(Self::RootMenu),
280            10 => Some(Self::SetupMenu),
281            11 => Some(Self::ContentsMenu),
282            12 => Some(Self::FavoriteMenu),
283            13 => Some(Self::Exit),
284            16 => Some(Self::MediaTopMenu),
285            17 => Some(Self::MediaContextSensitiveMenu),
286            29 => Some(Self::NumberEntryMode),
287            30 => Some(Self::Number11),
288            31 => Some(Self::Number12),
289            32 => Some(Self::Number0OrNumber10),
290            33 => Some(Self::Numbers1),
291            34 => Some(Self::Numbers2),
292            35 => Some(Self::Numbers3),
293            36 => Some(Self::Numbers4),
294            37 => Some(Self::Numbers5),
295            38 => Some(Self::Numbers6),
296            39 => Some(Self::Numbers7),
297            40 => Some(Self::Numbers8),
298            41 => Some(Self::Numbers9),
299            42 => Some(Self::Dot),
300            43 => Some(Self::Enter),
301            44 => Some(Self::Clear),
302            47 => Some(Self::NextFavorite),
303            48 => Some(Self::ChannelUp),
304            49 => Some(Self::ChannelDown),
305            50 => Some(Self::PreviousChannel),
306            51 => Some(Self::SoundSelect),
307            52 => Some(Self::InputSelect),
308            53 => Some(Self::DisplayInformation),
309            54 => Some(Self::Help),
310            55 => Some(Self::PageUp),
311            56 => Some(Self::PageDown),
312            64 => Some(Self::Power),
313            65 => Some(Self::VolumeUp),
314            66 => Some(Self::VolumeDown),
315            67 => Some(Self::Mute),
316            68 => Some(Self::Play),
317            69 => Some(Self::Stop),
318            70 => Some(Self::Pause),
319            71 => Some(Self::Record),
320            72 => Some(Self::Rewind),
321            73 => Some(Self::FastForward),
322            74 => Some(Self::Eject),
323            75 => Some(Self::Forward),
324            76 => Some(Self::Backward),
325            77 => Some(Self::StopRecord),
326            78 => Some(Self::PauseRecord),
327            79 => Some(Self::Reserved),
328            80 => Some(Self::Angle),
329            81 => Some(Self::SubPicture),
330            82 => Some(Self::VideoOnDemand),
331            83 => Some(Self::ElectronicProgramGuide),
332            84 => Some(Self::TimerProgramming),
333            85 => Some(Self::InitialConfiguration),
334            86 => Some(Self::SelectBroadcastType),
335            87 => Some(Self::SelectSoundPresentation),
336            96 => Some(Self::PlayFunction),
337            97 => Some(Self::PausePlayFunction),
338            98 => Some(Self::RecordFunction),
339            99 => Some(Self::PauseRecordFunction),
340            100 => Some(Self::StopFunction),
341            101 => Some(Self::MuteFunction),
342            102 => Some(Self::RestoreVolumeFunction),
343            103 => Some(Self::TuneFunction),
344            104 => Some(Self::SelectMediaFunction),
345            105 => Some(Self::SelectAvInputFunction),
346            106 => Some(Self::SelectAudioInputFunction),
347            107 => Some(Self::PowerToggleFunction),
348            108 => Some(Self::PowerOffFunction),
349            109 => Some(Self::PowerOnFunction),
350            113 => Some(Self::F1Blue),
351            114 => Some(Self::F2Red),
352            115 => Some(Self::F3Green),
353            116 => Some(Self::F4Yellow),
354            117 => Some(Self::F5),
355            118 => Some(Self::Data),
356            _ => None,
357        }
358    }
359
360    /// Its wire value.
361    #[must_use]
362    pub const fn value(self) -> u8 {
363        self as u8
364    }
365}
366
367impl ToTlv for CecKeyCodeEnum {
368    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
369        self.value().to_tlv(w, tag)
370    }
371}
372
373impl<'a> FromTlv<'a> for CecKeyCodeEnum {
374    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
375        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
376        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
377    }
378}
379
380/// `StatusEnum`.
381#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
382#[repr(u8)]
383pub enum StatusEnum {
384    /// Succeeded
385    Success = 0,
386    /// Key code is not supported.
387    UnsupportedKey = 1,
388    /// Requested key code is invalid in the context of the responder's current state.
389    InvalidKeyInCurrentState = 2,
390}
391
392impl StatusEnum {
393    /// Reads a wire value, or `None` for one this revision does not define.
394    #[must_use]
395    pub const fn from_value(value: u8) -> Option<Self> {
396        match value {
397            0 => Some(Self::Success),
398            1 => Some(Self::UnsupportedKey),
399            2 => Some(Self::InvalidKeyInCurrentState),
400            _ => None,
401        }
402    }
403
404    /// Its wire value.
405    #[must_use]
406    pub const fn value(self) -> u8 {
407        self as u8
408    }
409}
410
411impl ToTlv for StatusEnum {
412    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
413        self.value().to_tlv(w, tag)
414    }
415}
416
417impl<'a> FromTlv<'a> for StatusEnum {
418    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
419        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
420        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
421    }
422}
423
424/// The fields of `SendKey` (command `0x00`).
425#[derive(Debug, Clone, Copy, PartialEq)]
426pub struct SendKeyFields {
427    /// `KeyCode`, field 0.
428    pub key_code: CecKeyCodeEnum,
429}
430
431impl ToTlv for SendKeyFields {
432    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
433        w.start_structure(tag)?;
434        self.key_code.to_tlv(w, Tag::Context(0))?;
435        w.end_container()
436    }
437}
438
439impl<'a> FromTlv<'a> for SendKeyFields {
440    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
441        if element.value.container() != Some(ContainerKind::Structure) {
442            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
443        }
444        let mut key_code = None;
445        loop {
446            let Some(field) = reader.next_element()? else {
447                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
448            };
449            if field.value == Value::EndOfContainer {
450                break;
451            }
452            match field.tag.context() {
453                Some(0) => key_code = Some(<CecKeyCodeEnum>::from_tlv(reader, &field)?),
454                // A field this revision does not define. §7.19.2: a receiver
455                // ignores what it does not know rather than refusing the whole
456                // structure, which is what lets a newer peer talk to an older one.
457                _ => reader.skip_value(&field)?,
458            }
459        }
460        Ok(Self {
461            key_code: key_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
462        })
463    }
464}
465
466/// The fields of `SendKeyResponse` (command `0x01`).
467#[derive(Debug, Clone, Copy, PartialEq)]
468pub struct SendKeyResponseFields {
469    /// `Status`, field 0.
470    pub status: StatusEnum,
471}
472
473impl ToTlv for SendKeyResponseFields {
474    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
475        w.start_structure(tag)?;
476        self.status.to_tlv(w, Tag::Context(0))?;
477        w.end_container()
478    }
479}
480
481impl<'a> FromTlv<'a> for SendKeyResponseFields {
482    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
483        if element.value.container() != Some(ContainerKind::Structure) {
484            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
485        }
486        let mut status = None;
487        loop {
488            let Some(field) = reader.next_element()? else {
489                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
490            };
491            if field.value == Value::EndOfContainer {
492                break;
493            }
494            match field.tag.context() {
495                Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
496                // A field this revision does not define. §7.19.2: a receiver
497                // ignores what it does not know rather than refusing the whole
498                // structure, which is what lets a newer peer talk to an older one.
499                _ => reader.skip_value(&field)?,
500            }
501        }
502        Ok(Self {
503            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
504        })
505    }
506}
507
508/// Every attribute the specification defines, with its conformance.
509pub const ATTRIBUTES: &[Attribute] = &[];
510
511/// Every command, with its conformance.
512pub const COMMANDS: &[Command] = &[
513    Command {
514        id: 0x00,
515        name: "SendKey",
516        to_server: true,
517        response: Some(0x01),
518        access: Access::invoke(Privilege::Operate),
519        conform: Conform::MANDATORY,
520    },
521    Command {
522        id: 0x01,
523        name: "SendKeyResponse",
524        to_server: false,
525        response: None,
526        access: Access::invoke(Privilege::Operate),
527        conform: Conform::MANDATORY,
528    },
529];
530
531/// Every event, with its conformance.
532pub const EVENTS: &[Event] = &[];
533
534/// The whole cluster, as the specification defines it.
535pub const CLUSTER: Cluster = Cluster {
536    id: ID,
537    name: "Keypad Input",
538    revision: REVISION,
539    pics: "KEYPADINPUT",
540    derived_from: None,
541    features: FEATURES,
542    attributes: ATTRIBUTES,
543    commands: COMMANDS,
544    events: EVENTS,
545};