2021-04-14 09:25:10 +02:00
|
|
|
use crate::path::ModulePrefix;
|
2021-03-29 02:47:10 +02:00
|
|
|
use proc_macro2::TokenStream;
|
2021-04-20 16:33:47 +02:00
|
|
|
use quote::quote;
|
2021-03-29 02:47:10 +02:00
|
|
|
|
2021-04-20 16:33:47 +02:00
|
|
|
pub fn generate(embassy_prefix: &ModulePrefix, config: syn::Expr) -> TokenStream {
|
|
|
|
let embassy_path = embassy_prefix.append("embassy").path();
|
|
|
|
let embassy_nrf_path = embassy_prefix.append("embassy_nrf").path();
|
2021-04-14 09:25:10 +02:00
|
|
|
|
2021-03-29 02:47:10 +02:00
|
|
|
quote!(
|
2021-04-14 09:25:10 +02:00
|
|
|
use #embassy_nrf_path::{interrupt, peripherals, rtc};
|
2021-03-29 02:47:10 +02:00
|
|
|
|
2021-05-12 01:57:01 +02:00
|
|
|
let p = #embassy_nrf_path::init(#config);
|
2021-03-29 02:47:10 +02:00
|
|
|
|
2021-04-14 09:25:10 +02:00
|
|
|
let mut rtc = rtc::RTC::new(unsafe { <peripherals::RTC1 as #embassy_path::util::Steal>::steal() }, interrupt::take!(RTC1));
|
2021-03-29 02:47:10 +02:00
|
|
|
let rtc = unsafe { make_static(&mut rtc) };
|
|
|
|
rtc.start();
|
|
|
|
let mut alarm = rtc.alarm0();
|
|
|
|
|
2021-04-14 09:25:10 +02:00
|
|
|
unsafe { #embassy_path::time::set_clock(rtc) };
|
2021-03-29 02:47:10 +02:00
|
|
|
|
|
|
|
let alarm = unsafe { make_static(&mut alarm) };
|
2021-03-29 04:11:32 +02:00
|
|
|
executor.set_alarm(alarm);
|
2021-03-29 02:47:10 +02:00
|
|
|
)
|
|
|
|
}
|