Skip to content

Commit

Permalink
Merge pull request #129 from mattheww/2024-02_gpio-order
Browse files Browse the repository at this point in the history
Non-blocking display: change the order of GPIO writes
  • Loading branch information
lulf authored Feb 3, 2024
2 parents d4f3bfa + 18f4e68 commit 7726c24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Fix: non-blocking display on micro:bit V2 could spuriously light LEDs briefly
- Fix the `blocking::Display::set_refresh_rate` calculation for the micro:bit V2
- Double the non-blocking display refresh frequency for the micro:bit V2
- Fix faulty doc test in `blocking.rs`
Expand Down
27 changes: 18 additions & 9 deletions microbit-common/src/display/nonblocking/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,28 @@ impl DisplayControl for MicrobitGpio {
let rows_to_set = 1 << pins::P0_ROWS[row];
let rows_to_clear = P0_ROW_BITS ^ rows_to_set;

let cols_to_clear = column_pins(p0cols, &pins::P0_COLS);
let cols_to_set = P0_COL_BITS ^ cols_to_clear;

p0.outset.write(|w| w.bits(rows_to_set | cols_to_set));
p0.outclr.write(|w| w.bits(rows_to_clear | cols_to_clear));
#[cfg(feature = "v1")]
{
let cols_to_clear = column_pins(p0cols, &pins::P0_COLS);
let cols_to_set = P0_COL_BITS ^ cols_to_clear;
p0.outset.write(|w| w.bits(rows_to_set | cols_to_set));
p0.outclr.write(|w| w.bits(rows_to_clear | cols_to_clear));
}

#[cfg(feature = "v2")]
{
let p1 = &*P1::ptr();
let cols_to_clear = column_pins(p1cols, &pins::P1_COLS);
let cols_to_set = P1_COL_BITS ^ cols_to_clear;
p1.outset.write(|w| w.bits(cols_to_set));
p1.outclr.write(|w| w.bits(cols_to_clear));
let p0_cols_to_clear = column_pins(p0cols, &pins::P0_COLS);
let p0_cols_to_set = P0_COL_BITS ^ p0_cols_to_clear;
let p1_cols_to_clear = column_pins(p1cols, &pins::P1_COLS);
let p1_cols_to_set = P1_COL_BITS ^ p1_cols_to_clear;
// We do the row-clearing write first and the row-setting write last, so that
// intermediate states never light LEDs which aren't lit in either the old or new state.
p0.outclr
.write(|w| w.bits(rows_to_clear | p0_cols_to_clear));
p1.outset.write(|w| w.bits(p1_cols_to_set));
p1.outclr.write(|w| w.bits(p1_cols_to_clear));
p0.outset.write(|w| w.bits(rows_to_set | p0_cols_to_set));
}
}
}
Expand Down

0 comments on commit 7726c24

Please sign in to comment.