diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-06-28 17:10:43 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-06-28 17:10:43 +0200 |
commit | 19999214aab4ededaee069677e6ae73e2ef254ec (patch) | |
tree | b1d4a587c3a66c20eacc4a3d6439ce4cb640d820 /sw | |
parent | e1a2fcdb6be3e6eecc3bec0ddfe0a192be05982a (diff) | |
download | picardy-19999214aab4ededaee069677e6ae73e2ef254ec.tar.gz picardy-19999214aab4ededaee069677e6ae73e2ef254ec.tar.bz2 picardy-19999214aab4ededaee069677e6ae73e2ef254ec.zip |
Configure quadrature decoder
Diffstat (limited to 'sw')
-rw-r--r-- | sw/demo1/src/main.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sw/demo1/src/main.rs b/sw/demo1/src/main.rs index 0b9f965..a45c0bb 100644 --- a/sw/demo1/src/main.rs +++ b/sw/demo1/src/main.rs @@ -12,6 +12,7 @@ use stm32f1xx_hal::{ pac, i2c::{BlockingI2c, Mode}, delay::Delay, + timer::{Timer}, }; use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin}; @@ -84,12 +85,19 @@ fn main() -> ! { let clocks = rcc.cfgr.freeze(&mut flash.acr); let mut delay = Delay::new(cp.SYST, clocks); + let gpioa = dp.GPIOA.split(&mut rcc.apb2); let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); // Configure PB14 as output. (LED) let mut led = gpiob.pb14.into_push_pull_output(&mut gpiob.crh); led.set_low().unwrap(); + let c1 = gpioa.pa6; + let c2 = gpioa.pa7; + + let qei = Timer::tim3(dp.TIM3, &clocks, &mut rcc.apb1) + .qei((c1, c2), &mut afio.mapr); + // Configure I2C1 to be used for Si5351 and display let scl = gpiob.pb6.into_alternate_open_drain(&mut gpiob.crl); let sda = gpiob.pb7.into_alternate_open_drain(&mut gpiob.crl); @@ -203,14 +211,18 @@ fn main() -> ! { let mut step = 0; print(step).unwrap(); + let mut last_encoder_count = qei.count(); loop { led.toggle().unwrap(); - delay.delay_ms(600u32); lcd.set_cursor_pos(40, &mut delay).unwrap(); let mut string = arrayvec::ArrayString::<[_; 16]>::new(); - write!(string, "Step {} ", step).unwrap(); - lcd.write_str(&string, &mut delay).unwrap(); + let encoder_count = qei.count(); + if encoder_count != last_encoder_count { + write!(string, "Enc {} ", encoder_count).unwrap(); + lcd.write_str(&string, &mut delay).unwrap(); + } + last_encoder_count = encoder_count; step += 1; } |