Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify QEI Mode #33

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bootload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub fn jump_to_bootloader_if_requested(dp: &stm32::Peripherals) {
let magic_num: u32 = read_backup_register(dp);

if magic_num == MAGIC_BOOTLOADER_NUMBER {
enable_backup_domain(&dp);
enable_backup_domain(dp);
write_to_backup_register(0, dp);
disable_backup_domain(&dp);
disable_backup_domain(dp);

unsafe {
cortex_m::asm::bootload(BOOTLOADER_FIRMWARE_MEMORY_LOCATION as *const u32);
Expand Down
14 changes: 12 additions & 2 deletions src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ pub struct Counter<PINS> {

impl<PINS> Counter<PINS> {
pub fn new(qei: Qei<TIM1, PINS>) -> Self {
unsafe {
// TODO(bschwind) - Expose this functionality with a safe interface
// in stm32f4xx-hal.
// Change the mode of the QEI decoder to mode 1:
// Counter counts up/down on TI2FP1 edge depending on TI1FP2 level.
// Or in layman's terms, the encoder counts up and down on encoder
// pin A edges, while referencing the state of encoder pin B.
(*TIM1::ptr()).smcr.write(|w| w.sms().encoder_mode_1());
}

let last_count = qei.count();
Counter { qei, last_count }
}
Expand All @@ -16,9 +26,9 @@ impl<PINS> Counter<PINS> {
let count = self.qei.count();
let diff = count.wrapping_sub(self.last_count) as i16;

if diff.abs() >= 4 {
if diff.abs() >= 2 {
self.last_count = count;
Some((diff / 4) as i8)
Some((diff / 2) as i8)
} else {
None
}
Expand Down
Loading