extras: move peripherals from nrf to extras
This commit is contained in:
		@@ -3,6 +3,7 @@
 | 
			
		||||
// This mod MUST go first, so that the others see its macros.
 | 
			
		||||
pub(crate) mod fmt;
 | 
			
		||||
 | 
			
		||||
mod macros;
 | 
			
		||||
pub mod peripheral;
 | 
			
		||||
pub mod ring_buffer;
 | 
			
		||||
pub mod usb;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										45
									
								
								embassy-extras/src/macros.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								embassy-extras/src/macros.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! peripherals {
 | 
			
		||||
    ($($(#[$cfg:meta])? $name:ident: $type:ident),*$(,)?) => {
 | 
			
		||||
        $(
 | 
			
		||||
            $(#[$cfg])?
 | 
			
		||||
            #[allow(non_camel_case_types)]
 | 
			
		||||
            pub struct $type { _private: () }
 | 
			
		||||
 | 
			
		||||
            $(#[$cfg])?
 | 
			
		||||
            impl embassy::util::PeripheralBorrow for $type {
 | 
			
		||||
                type Target = $type;
 | 
			
		||||
                unsafe fn unborrow(self) -> $type {
 | 
			
		||||
                    self
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $(#[$cfg])?
 | 
			
		||||
            impl embassy::util::PeripheralBorrow for &mut $type {
 | 
			
		||||
                type Target = $type;
 | 
			
		||||
                unsafe fn unborrow(self) -> $type {
 | 
			
		||||
                    ::core::ptr::read(self)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        )*
 | 
			
		||||
 | 
			
		||||
        pub struct Peripherals {
 | 
			
		||||
            $(
 | 
			
		||||
                $(#[$cfg])?
 | 
			
		||||
                pub $name: $type,
 | 
			
		||||
            )*
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        impl Peripherals {
 | 
			
		||||
            pub unsafe fn steal() -> Self {
 | 
			
		||||
                Self {
 | 
			
		||||
                    $(
 | 
			
		||||
                        $(#[$cfg])?
 | 
			
		||||
                        $name: $type { _private: () },
 | 
			
		||||
                    )*
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
@@ -1,51 +1,4 @@
 | 
			
		||||
use embassy::util::PeripheralBorrow;
 | 
			
		||||
 | 
			
		||||
macro_rules! peripherals {
 | 
			
		||||
    ($($(#[$cfg:meta])? $name:ident: $type:ident),*$(,)?) => {
 | 
			
		||||
        $(
 | 
			
		||||
            $(#[$cfg])?
 | 
			
		||||
            #[allow(non_camel_case_types)]
 | 
			
		||||
            pub struct $type { _private: () }
 | 
			
		||||
 | 
			
		||||
            $(#[$cfg])?
 | 
			
		||||
            impl PeripheralBorrow for $type {
 | 
			
		||||
                type Target = $type;
 | 
			
		||||
                unsafe fn unborrow(self) -> $type {
 | 
			
		||||
                    self
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $(#[$cfg])?
 | 
			
		||||
            impl PeripheralBorrow for &mut $type {
 | 
			
		||||
                type Target = $type;
 | 
			
		||||
                unsafe fn unborrow(self) -> $type {
 | 
			
		||||
                    ::core::ptr::read(self)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        )*
 | 
			
		||||
 | 
			
		||||
        pub struct Peripherals {
 | 
			
		||||
            $(
 | 
			
		||||
                $(#[$cfg])?
 | 
			
		||||
                pub $name: $type,
 | 
			
		||||
            )*
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        impl Peripherals {
 | 
			
		||||
            pub unsafe fn steal() -> Self {
 | 
			
		||||
                Self {
 | 
			
		||||
                    $(
 | 
			
		||||
                        $(#[$cfg])?
 | 
			
		||||
                        $name: $type { _private: () },
 | 
			
		||||
                    )*
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
peripherals! {
 | 
			
		||||
embassy_extras::peripherals! {
 | 
			
		||||
    // RTC
 | 
			
		||||
    rtc0: RTC0,
 | 
			
		||||
    rtc1: RTC1,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user