diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-05-12 13:40:08 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-12 13:40:08 +0000 |
| commit | 45c0f1ab88edb7a635faf3bb0941d81772100da1 (patch) | |
| tree | 312d4acf488d7715850fac52323ec3b34968c0ab /examples | |
| parent | 30d4d0e9d78681e16a68ff953c61b96c9863bfc6 (diff) | |
| parent | 93cbd079ec1f5b8371fb4d52b00e0a404403f73d (diff) | |
Merge #756
756: Add async quadrature decoder for embassy-nrf r=Dirbaio a=kalkyl
Thsi PR adds an async interface to the QDEC peripheral to embassy-nrf, that can be used for rotary encoders for example.
Co-authored-by: Henrik Alsér <[email protected]>
Co-authored-by: Henrik Alsér <[email protected]>
Co-authored-by: Henrik Alsér <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/qdec.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf/src/bin/qdec.rs new file mode 100644 index 000000000..bf5b11468 --- /dev/null +++ b/examples/nrf/src/bin/qdec.rs | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::info; | ||
| 6 | use embassy::executor::Spawner; | ||
| 7 | use embassy_nrf::{ | ||
| 8 | interrupt, | ||
| 9 | qdec::{self, Qdec}, | ||
| 10 | Peripherals, | ||
| 11 | }; | ||
| 12 | |||
| 13 | use defmt_rtt as _; // global logger | ||
| 14 | use panic_probe as _; | ||
| 15 | |||
| 16 | #[embassy::main] | ||
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 18 | let irq = interrupt::take!(QDEC); | ||
| 19 | let config = qdec::Config::default(); | ||
| 20 | let mut rotary_enc = Qdec::new(p.QDEC, irq, p.P0_31, p.P0_30, config); | ||
| 21 | |||
| 22 | info!("Turn rotary encoder!"); | ||
| 23 | let mut value = 0; | ||
| 24 | loop { | ||
| 25 | value += rotary_enc.read().await; | ||
| 26 | info!("Value: {}", value); | ||
| 27 | } | ||
| 28 | } | ||
