Skip to content
Discussion options

You must be logged in to vote

The trick is to define a context attribute on the enum. Elsewhere I've done:

// MI v2.0, 5.1.1, Figure 77, SFREQ
#[derive(Debug, Clone, Copy, DekuRead, DekuWrite, Eq, PartialEq, PartialOrd)]
#[deku(
    bits = "bits.0",
    id_type = "u8",
    ctx = "endian: Endian, bits: BitSize",
    endian = "endian"
)]
#[repr(u8)]
enum SmbusFrequency {
    Reserved = 0x00,
    Freq100Khz = 0x01,
    Freq400Khz = 0x02,
    Freq1Mhz = 0x03,
}

// MI v2.0, 5.1.1, Figure 77
#[derive(Debug, DekuWrite, PartialEq)]
#[deku(endian = "little")]
struct GetSmbusI2cFrequencyResponse {
    status: ResponseStatus,
    #[deku(bits = "4", pad_bits_before = "4", pad_bytes_after = "2")]
    sfreq: SmbusFrequency,
}

So y…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DidingasLushis
Comment options

Answer selected by DidingasLushis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants