drone-core icon indicating copy to clipboard operation
drone-core copied to clipboard

Allow using #[cfg(...)] attributes on register fields

Open jeandudey opened this issue 4 years ago • 0 comments

Small non-breaking change to the reg! macro. It now allows the usage of #[cfg(...)] attributes on register fields. This is particularly useful for https://github.com/drone-os/drone-cortexm/pull/5 as it allows to restrict the STKALIGN field to a read-only field on Cortex-M7 CPUs.

Also, I've got another usage for this, adding the IC and DC fields to SCB_CCR which is present on some Cortex-M7 (optionally).

For example:

reg! {
    /// Configuration and control register.
    pub SCB CCR => {
        address => 0xE000_ED14;
        size => 0x20;
        reset => 0x0000_0200;
        traits => { RReg WReg };
        fields => {
            #[cfg(not(cortexm_core = "cortexm7_r0p1"))]
            /// Force exception stacking start in double word aligned address.
            STKALIGN => { offset => 9; width => 1; traits => { RRRegField WWRegField } }
            #[cfg(cortexm_core = "cortexm7_r0p1")]
            /// Force exception stacking start in double word aligned address.
            STKALIGN => { ... }
            ...
        };
}

jeandudey avatar Jul 21 '21 14:07 jeandudey