embassy/embassy-macros/src/chip/nrf.rs

25 lines
826 B
Rust
Raw Normal View History

use crate::path::ModulePrefix;
2021-03-29 02:47:10 +02:00
use proc_macro2::TokenStream;
use quote::quote;
2021-03-29 02:47:10 +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-03-29 02:47:10 +02:00
quote!(
use #embassy_nrf_path::{interrupt, peripherals, rtc};
2021-03-29 02:47:10 +02:00
let p = #embassy_nrf_path::init(#config);
2021-03-29 02:47: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();
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
)
}