Felix Obenhuber | 18746e4 | 2019-01-16 13:29:01 +0100 | [diff] [blame] | 1 | #![no_std] |
| 2 | |
Alistair Francis | e5f74c3 | 2020-09-11 15:21:14 -0700 | [diff] [blame] | 3 | use libtock::println; |
torfmaster | 3d60524 | 2019-12-16 22:36:39 +0100 | [diff] [blame] | 4 | use libtock::result::TockResult; |
Felix Obenhuber | 18746e4 | 2019-01-16 13:29:01 +0100 | [diff] [blame] | 5 | use libtock::timer::Duration; |
| 6 | |
Johnathan Van Why | 074fa7d | 2020-10-14 17:06:50 -0700 | [diff] [blame^] | 7 | libtock_core::stack_size! {0x800} |
| 8 | |
torfmaster | b06f637 | 2019-12-17 09:20:48 +0100 | [diff] [blame] | 9 | #[libtock::main] |
Woyten | 22bc254 | 2019-11-15 23:18:40 +0100 | [diff] [blame] | 10 | async fn main() -> TockResult<()> { |
Woyten | b122620 | 2020-01-13 22:47:48 +0100 | [diff] [blame] | 11 | let mut drivers = libtock::retrieve_drivers()?; |
torfmaster | f7ac7c9 | 2019-11-17 00:33:28 +0100 | [diff] [blame] | 12 | |
Woyten | b122620 | 2020-01-13 22:47:48 +0100 | [diff] [blame] | 13 | 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 Francis | e5f74c3 | 2020-09-11 15:21:14 -0700 | [diff] [blame] | 16 | drivers.console.create_console(); |
Felix Obenhuber | 18746e4 | 2019-01-16 13:29:01 +0100 | [diff] [blame] | 17 | |
Woyten | 141e48a | 2020-01-12 21:01:25 +0100 | [diff] [blame] | 18 | let mut callback = |channel, value| { |
Alistair Francis | e5f74c3 | 2020-09-11 15:21:14 -0700 | [diff] [blame] | 19 | println!("channel: {}, value: {}", channel, value); |
Woyten | 141e48a | 2020-01-12 21:01:25 +0100 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | let _subscription = adc_driver.subscribe(&mut callback)?; |
Felix Obenhuber | 18746e4 | 2019-01-16 13:29:01 +0100 | [diff] [blame] | 23 | |
torfmaster | d5db030 | 2019-11-14 19:06:10 +0100 | [diff] [blame] | 24 | loop { |
Woyten | 141e48a | 2020-01-12 21:01:25 +0100 | [diff] [blame] | 25 | adc_driver.sample(0)?; |
torfmaster | 6ecb72f | 2019-12-18 12:17:34 +0100 | [diff] [blame] | 26 | timer_driver.sleep(Duration::from_ms(2000)).await?; |
torfmaster | d5db030 | 2019-11-14 19:06:10 +0100 | [diff] [blame] | 27 | } |
Felix Obenhuber | 18746e4 | 2019-01-16 13:29:01 +0100 | [diff] [blame] | 28 | } |