aboutsummaryrefslogtreecommitdiffstats
path: root/sw/demo1/src
diff options
context:
space:
mode:
Diffstat (limited to 'sw/demo1/src')
-rw-r--r--sw/demo1/src/main.rs18
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;
}