blob: c0a6da7366779c92ca5c96caeaa669a94256afaf [file] [log] [blame]
Felix Obenhuber18746e42019-01-16 13:29:01 +01001#![no_std]
2
Alistair Francise5f74c32020-09-11 15:21:14 -07003use libtock::println;
torfmaster3d605242019-12-16 22:36:39 +01004use libtock::result::TockResult;
Felix Obenhuber18746e42019-01-16 13:29:01 +01005use libtock::timer::Duration;
6
Johnathan Van Why074fa7d2020-10-14 17:06:50 -07007libtock_core::stack_size! {0x800}
8
torfmasterb06f6372019-12-17 09:20:48 +01009#[libtock::main]
Woyten22bc2542019-11-15 23:18:40 +010010async fn main() -> TockResult<()> {
Woytenb1226202020-01-13 22:47:48 +010011 let mut drivers = libtock::retrieve_drivers()?;
torfmasterf7ac7c92019-11-17 00:33:28 +010012
Woytenb1226202020-01-13 22:47:48 +010013 let adc_driver = drivers.adc.init_driver()?;
14 let mut timer_driver = drivers.timer.create_timer_driver();
15 let timer_driver = timer_driver.activate()?;
Alistair Francise5f74c32020-09-11 15:21:14 -070016 drivers.console.create_console();
Felix Obenhuber18746e42019-01-16 13:29:01 +010017
Woyten141e48a2020-01-12 21:01:25 +010018 let mut callback = |channel, value| {
Alistair Francise5f74c32020-09-11 15:21:14 -070019 println!("channel: {}, value: {}", channel, value);
Woyten141e48a2020-01-12 21:01:25 +010020 };
21
22 let _subscription = adc_driver.subscribe(&mut callback)?;
Felix Obenhuber18746e42019-01-16 13:29:01 +010023
torfmasterd5db0302019-11-14 19:06:10 +010024 loop {
Woyten141e48a2020-01-12 21:01:25 +010025 adc_driver.sample(0)?;
torfmaster6ecb72f2019-12-18 12:17:34 +010026 timer_driver.sleep(Duration::from_ms(2000)).await?;
torfmasterd5db0302019-11-14 19:06:10 +010027 }
Felix Obenhuber18746e42019-01-16 13:29:01 +010028}