Macro peripherals::device [−][src]
macro_rules! device { ( $(#[$($device_attr:tt)*])* $device:ident; $($(#[$($periph_attr:tt)*])* $periph:ident @ $base:literal : $type:ty;)* ) => { ... }; }
Expand description
Define a microcontroller and which peripherals it has
It is recommended to have one module per device and thus to invoke this macros in its own module. For an example of the generated types, see the example module.
Usage
The macro begins with the device name.
peripherals::device!{ /// Optional documentation MyMicrocontroller; }
Then each peripheral is described as follow:
peripherals::device!{ MyMicrocontroller; // name base address peripheral type PERIPH @ 0x1234 : MyPeripheral; }
- The name of the peripheral is generaly written in uppercase. It is used to name the marker type for this instance as well as the field (in lowercase) in the device struct.
- The base address (here
0x1234
) is the address of the register at offset0
of the peripheral. That is, each register will be at (base address + register offset). - The peripheral type is a struct defined with the
periph!
macro. You can either import each used peripheral or use absolute or relative paths.