cleanup and consolidate peripherals macro
This commit is contained in:
		@@ -105,3 +105,42 @@ macro_rules! impl_unborrow {
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! std_peripherals {
 | 
			
		||||
    ($($(#[$cfg:meta])? $name:ident),*$(,)?) => {
 | 
			
		||||
        #[doc = r"All the peripherals"]
 | 
			
		||||
        #[allow(non_snake_case)]
 | 
			
		||||
        pub struct Peripherals {
 | 
			
		||||
            $(
 | 
			
		||||
                $(#[$cfg])?
 | 
			
		||||
                pub $name: pac::$name,
 | 
			
		||||
            )+
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        static mut GLOBAL_CLOCKS: Option<Clocks> = None;
 | 
			
		||||
 | 
			
		||||
        impl Peripherals {
 | 
			
		||||
            pub fn take() -> Option<(Peripherals, Clocks)> {
 | 
			
		||||
                match unsafe {GLOBAL_CLOCKS} {
 | 
			
		||||
                    Some(clocks) => {
 | 
			
		||||
                        let dp = unsafe { pac::Peripherals::steal() };
 | 
			
		||||
                        let peripherals = Peripherals {
 | 
			
		||||
                            $(
 | 
			
		||||
                                $(#[$cfg])?
 | 
			
		||||
                                $name: dp.$name,
 | 
			
		||||
                            )+
 | 
			
		||||
                        };
 | 
			
		||||
 | 
			
		||||
                        Some((peripherals, clocks))
 | 
			
		||||
                    },
 | 
			
		||||
                    None => None,
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            pub unsafe fn set_peripherals(clocks: Clocks) {
 | 
			
		||||
                GLOBAL_CLOCKS.replace(clocks);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user