* Moves the tim2-specific code into macro which always uses TIM2 * For peripherals without clock specified, attempt to locate enable and reset registers in the RCC block matching the peripheral name. This could be useful for peripherals where deducing the clock name might not be feasible, but it remains to be tested with more chip families to see if it is sufficiently accurate.
		
			
				
	
	
		
			31 lines
		
	
	
		
			1019 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1019 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use crate::path::ModulePrefix;
 | |
| use proc_macro2::TokenStream;
 | |
| use quote::quote;
 | |
| 
 | |
| pub fn generate(embassy_prefix: &ModulePrefix, config: syn::Expr) -> TokenStream {
 | |
|     let embassy_path = embassy_prefix.append("embassy").path();
 | |
|     let embassy_stm32_path = embassy_prefix.append("embassy_stm32").path();
 | |
| 
 | |
|     quote!(
 | |
|         use #embassy_stm32_path::{interrupt, peripherals, clock::Clock, time::Hertz};
 | |
| 
 | |
|         let p = #embassy_stm32_path::init(#config);
 | |
| 
 | |
|         let mut c = Clock::new(
 | |
|             unsafe { <peripherals::TIM2 as embassy::util::Steal>::steal() },
 | |
|             interrupt::take!(TIM2),
 | |
|         );
 | |
|         let clock = unsafe { make_static(&mut c) };
 | |
| 
 | |
|         // TODO: Is TIM2 always APB1?
 | |
|         let timer_freq = unsafe { #embassy_stm32_path::rcc::get_freqs().apb1_clk };
 | |
|         clock.start(timer_freq);
 | |
| 
 | |
|         let mut alarm = clock.alarm1();
 | |
|         unsafe { #embassy_path::time::set_clock(clock) };
 | |
| 
 | |
|         let alarm = unsafe { make_static(&mut alarm) };
 | |
|         executor.set_alarm(alarm);
 | |
|     )
 | |
| }
 |