Re: [TECH TOPIC] Rust for Linux

Andrew Lunn
2021-07-19T15:48:29Z

> For instance, the driver developer could write something like this
> right in the Rust source code:
>
> memory_map!(
> 0x0042 simple_value 2 value(u16)
> 0x0044 some_flags 2 flags(..., FLAG1, FLAG2)
> 0x0046 custom_type 1 value(MyCustomType)
> 0x0047 across_bits 2 [
> 0..2 other_flags flags(FOO, BAR),
> 2..4 _ unused,
> 4..31 temp value(Temperature),
> ]
> );
>
> And then simply call:
>
> driver.map.read_temp()
>
> and it would automatically perform the shifting, masking, unit
> conversions, etc. to get the raw sensor data into a value in proper
> Kelvin.

Hi Miguel

Can you express endianness here as well? There are often cases where
the hardware is always big endian independent of the CPU
endianness. Some of the readl/writel macros handle this, adding a swap
when the two don't match.

Andrew