diondokter / device-driver

A toolkit to create better Rust device drivers, faster
https://diondokter.github.io/device-driver/
Apache License 2.0
96 stars 4 forks source link

Bit modify operations #15

Open Szpadel opened 2 years ago

Szpadel commented 2 years ago

I'm looking into implementing driver for mcp2515, and I'm trying to create nice SPI registers abstraction.

The issue is that for many operations (eg. marking irq as acknowledged) require use of "Bit Modify" operations (to prevent race conditions, eg when device receive message between read and write operation to registers).

This require executing bit modify operation with bit mask (what bits we want to set) and new value (bits outside bit mask are ignored).

The issue that I'm having is how to create register, set some bit fields there, and then get mask for modified fields.