Modify init function to return a Clock instance defined by a per-chip SystemClock type and use this in macro setup A proof of concept implementation for STM32 L0 chips. This allows using embassy::main macros for STM32 devices that have the clock setup logic.
		
			
				
	
	
		
			24 lines
		
	
	
		
			739 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			739 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, mut c) = #embassy_stm32_path::init(#config);
 | |
| 
 | |
|         let clock = unsafe { make_static(&mut c) };
 | |
|         clock.start();
 | |
| 
 | |
|         let mut alarm = clock.alarm1();
 | |
|         unsafe { #embassy_path::time::set_clock(clock) };
 | |
| 
 | |
|         let alarm = unsafe { make_static(&mut alarm) };
 | |
|         executor.set_alarm(alarm);
 | |
|     )
 | |
| }
 |