dsvensson / cc1101

A platform agnostic driver to interface with the CC1101 (Sub-1GHz RF Transceiver)
Apache License 2.0
30 stars 16 forks source link

(read|modify|write)_register should take/return typed structures rather than u8 #10

Open dsvensson opened 6 years ago

dsvensson commented 6 years ago

The following code:

        self.modify_register(config::Register::MDMCFG2, |r| {
            MDMCFG2(r).modify().sync_mode(mode.value()).bits()
        })?;

... should ideally not mention MDMCFG2 in the body, nor modify():

        self.modify_register(config::Register::MDMCFG2, |r| {
            r.sync_mode(mode.value()).bits()
        })?;

And similarily, calling self.read_register(config::Register.:MDMCFG2) should return a MDMCFG2 rather than an u8.

Can probably be fixed by introducing some good traits. Figure out how.

dsvensson commented 6 years ago

This probably requires some broader macro that replaces the per-register-type enum with macro expansion as there's not really a good link between the register value wrappers and the register address enums.