swift-mmio
swift-mmio copied to clipboard
Add `RawRepresentable` conformance to the generated `Read` and `Write` structs
(I originally proposed this change here.)
The raw value of the register can be read/written to by accessing the .raw.storage
property like so:
cr1.modify { cr1 in
cr1.raw.storage |= (1 & CR1.RST.bitMask) << CR1.RST.bitOffset
}
This seems similar to the rawValue
property of the RawRepresentable
protocol. Instead of .raw.storage
, perhaps the generated Read
/Write
structs could conform to RawRepresentable
. It probably doesn’t make a functional difference but it might reduce the ramp-up time for developers who are new to the package.
cr1.modify { cr1 in
cr1.rawValue |= (1 & CR1.RST.bitMask) << CR1.RST.bitOffset
}
(There was a concern about the optionality of the init(rawValue:)
initializer; however, a non-optional initializer can satisfy an optional initializer protocol requirement.)