rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
682 stars 149 forks source link

accessors everywhere (breaking) #692

Closed burrbull closed 8 months ago

burrbull commented 1 year ago

All register/cluster access through methods. RegisterBlock fields are private

To access register or cluster instead of:

per.reg.write(...)
per.regarray[2].write(...)
per.altreg().write(...)

use

per.reg().write(...)
per.regarray(2).write(...)
per.altreg().write(...)
rust-highfive commented 1 year ago

r? @adamgreig

(rust-highfive has picked a reviewer for you, use r? to override)

duskmoon314 commented 1 year ago

What will it be like after this PR? From the brief intro, I imagine this:

// error
uart.thr.write(...);

// correct
uart.thr().write(...);

Is this the expected behavior?

burrbull commented 1 year ago

Yes

luojia65 commented 1 year ago

Should we keep register blocks public under some feature gate? Rust kernel developers may still reuse this structure when writing drivers, as in this purpose the base address of peripherals are not fixed as bare metal when MMU comes in.

duskmoon314 commented 1 year ago

Should we keep register blocks public under some feature gate? Rust kernel developers may still reuse this structure when writing drivers, as in this purpose the base address of peripherals are not fixed as bare metal when MMU comes in.

It seems this PR only makes the fields private and leaves RegisterBlock as it is. If so, I think there is no problem to use with a virtual address.

burrbull commented 1 year ago

I don't insist on this PR. It is just concept for discuss.

burrbull commented 8 months ago

cc @rust-embedded/tools

burrbull commented 8 months ago

I guess if someone needs a pointer to a field, they can still call as_ptr() on what the accessor returns?

Should be same as before.