We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6ab6f94 commit 61fe2acCopy full SHA for 61fe2ac
1 file changed
src/lib.rs
@@ -274,3 +274,24 @@ pub use crate::devices::attiny85;
274
pub use crate::devices::attiny861;
275
#[cfg(feature = "attiny88")]
276
pub use crate::devices::attiny88;
277
+
278
+/// Safely retrieve an instance of the device's `struct Peripherals` once.
279
+///
280
+/// This macro can only be used once in the whole program.
281
+/// Multiple uses will result in a linker abort.
282
+#[macro_export]
283
+macro_rules! peripherals {
284
+ ($device_name: ident) => {
285
+ {
286
287
+ #[no_mangle]
288
+ #[link_section=".__peripherals_usage_restriction__"]
289
+ #[export_name="__ERROR__avr_device__peripherals__macro_must_only_be_used_once__"]
290
+ static _x: () = ();
291
+ }
292
+ unsafe {
293
+ avr_device::$device_name::Peripherals::steal()
294
295
296
297
+}
0 commit comments