Skip to content

Commit

Permalink
Merge pull request nrf-rs#127 from mattheww/2024-01_mb2-refresh
Browse files Browse the repository at this point in the history
Double the non-blocking display refresh frequency for the micro:bit V2
  • Loading branch information
lulf authored Feb 2, 2024
2 parents c7fbd9a + 3594c10 commit 0e476f1
Show file tree
Hide file tree
Showing 3 changed files with 24 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]

- Double the non-blocking display refresh frequency for the micro:bit V2
- Fix faulty doc test in `blocking.rs`
- Update the non-blocking display documentation to better explain when methods
should be called from within a critical section
Expand Down
18 changes: 11 additions & 7 deletions microbit-common/src/display/nonblocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,21 @@
//! The [`Display`] expects to control a single timer. It can use the
//! micro:bit's `TIMER0`, `TIMER1`, or `TIMER2`.
//!
//! This uses a 6ms period to light each of the three internal LED rows, so
//! that the entire display is updated every 18ms.
//! For the micro:bit v1 this uses a 6ms period to light each of the three
//! internal LED rows, so that the entire display is updated every 18ms.
//!
//! For the micro:bit v2 this uses a 3ms period to light each of the five
//! internal LED rows, so that the entire display is updated every 15ms.
//!
//! When rendering greyscale images, the `Display` requests extra interrupts
//! within each 6ms period. It only requests interrupts for the greyscale
//! levels which are actually required for what's currently being displayed.
//! within each 6ms or 3ms period. It only requests interrupts for the
//! greyscale levels which are actually required for what's currently being
//! displayed.
//!
//! ### Technical details
//!
//! The timer is set to 16-bit mode, using a 62.5kHz clock (16 µs ticks). It
//! resets every 375 ticks.
//! The timer is set to 16-bit mode, using a 62.5kHz or 135Khz clock (16 µs or
//! 8µs ticks). It resets every 375 ticks.
//!
//! ## Usage
//!
Expand All @@ -137,7 +141,7 @@
//! - create a [`Display`] struct passing the timer and
//! [`gpio::DisplayPins`](crate::gpio::DisplayPins) to [`Display::new()`].
//!
//! In an interrupt handler forthe timer call [`.handle_display_event()`](Display::handle_display_event)
//! In an interrupt handler for the timer call [`.handle_display_event()`](Display::handle_display_event)
//!
//! To change what's displayed; pass an image ([`GreyscaleImage`] or [`BitImage`]) to [`Display::show`].
//!
Expand Down
14 changes: 12 additions & 2 deletions microbit-common/src/display/nonblocking/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ use crate::hal::timer::Instance;
///
/// `MicrobitDisplayTimer` instances implement the [`DisplayTimer`] trait.
///
/// The timer is set to 16-bit mode, using a 62.5kHz clock (16 µs ticks).
/// The timer is set to 16-bit mode.
///
/// For micro:bit v1: uses a 62.5kHz clock clock (16 µs ticks).
/// The primary cycle takes 6ms.
///
/// For micro:bit v2: uses a 135kHz clock (8 µs ticks).
/// The primary cycle takes 3ms.
///
/// Uses CC0 for the primary cycle and CC1 for the secondary alarm. Uses the
/// CC0_CLEAR shortcut to implement the primary cycle.
///
Expand Down Expand Up @@ -43,8 +48,13 @@ impl<T: Instance> DisplayTimer for MicrobitDisplayTimer<T> {
// set as 16 bits
timer0.bitmode.write(|w| w.bitmode()._16bit());

#[cfg(feature = "v1")]
// set frequency to 62500Hz
timer0.prescaler.write(|w| unsafe { w.bits(8) });
let prescaler = 8;
#[cfg(feature = "v2")]
// set frequency to 135000Hz
let prescaler = 7;
timer0.prescaler.write(|w| unsafe { w.bits(prescaler) });

// set compare register
timer0.cc[0].write(|w| unsafe { w.bits(ticks.into()) });
Expand Down

0 comments on commit 0e476f1

Please sign in to comment.