Skip to content

Commit 0e476f1

Browse files
authored
Merge pull request #127 from mattheww/2024-01_mb2-refresh
Double the non-blocking display refresh frequency for the micro:bit V2
2 parents c7fbd9a + 3594c10 commit 0e476f1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Double the non-blocking display refresh frequency for the micro:bit V2
1011
- Fix faulty doc test in `blocking.rs`
1112
- Update the non-blocking display documentation to better explain when methods
1213
should be called from within a critical section

microbit-common/src/display/nonblocking/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,21 @@
117117
//! The [`Display`] expects to control a single timer. It can use the
118118
//! micro:bit's `TIMER0`, `TIMER1`, or `TIMER2`.
119119
//!
120-
//! This uses a 6ms period to light each of the three internal LED rows, so
121-
//! that the entire display is updated every 18ms.
120+
//! For the micro:bit v1 this uses a 6ms period to light each of the three
121+
//! internal LED rows, so that the entire display is updated every 18ms.
122+
//!
123+
//! For the micro:bit v2 this uses a 3ms period to light each of the five
124+
//! internal LED rows, so that the entire display is updated every 15ms.
122125
//!
123126
//! When rendering greyscale images, the `Display` requests extra interrupts
124-
//! within each 6ms period. It only requests interrupts for the greyscale
125-
//! levels which are actually required for what's currently being displayed.
127+
//! within each 6ms or 3ms period. It only requests interrupts for the
128+
//! greyscale levels which are actually required for what's currently being
129+
//! displayed.
126130
//!
127131
//! ### Technical details
128132
//!
129-
//! The timer is set to 16-bit mode, using a 62.5kHz clock (16 µs ticks). It
130-
//! resets every 375 ticks.
133+
//! The timer is set to 16-bit mode, using a 62.5kHz or 135Khz clock (16 µs or
134+
//! 8µs ticks). It resets every 375 ticks.
131135
//!
132136
//! ## Usage
133137
//!
@@ -137,7 +141,7 @@
137141
//! - create a [`Display`] struct passing the timer and
138142
//! [`gpio::DisplayPins`](crate::gpio::DisplayPins) to [`Display::new()`].
139143
//!
140-
//! In an interrupt handler forthe timer call [`.handle_display_event()`](Display::handle_display_event)
144+
//! In an interrupt handler for the timer call [`.handle_display_event()`](Display::handle_display_event)
141145
//!
142146
//! To change what's displayed; pass an image ([`GreyscaleImage`] or [`BitImage`]) to [`Display::show`].
143147
//!

microbit-common/src/display/nonblocking/timer.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ use crate::hal::timer::Instance;
1010
///
1111
/// `MicrobitDisplayTimer` instances implement the [`DisplayTimer`] trait.
1212
///
13-
/// The timer is set to 16-bit mode, using a 62.5kHz clock (16 µs ticks).
13+
/// The timer is set to 16-bit mode.
14+
///
15+
/// For micro:bit v1: uses a 62.5kHz clock clock (16 µs ticks).
1416
/// The primary cycle takes 6ms.
1517
///
18+
/// For micro:bit v2: uses a 135kHz clock (8 µs ticks).
19+
/// The primary cycle takes 3ms.
20+
///
1621
/// Uses CC0 for the primary cycle and CC1 for the secondary alarm. Uses the
1722
/// CC0_CLEAR shortcut to implement the primary cycle.
1823
///
@@ -43,8 +48,13 @@ impl<T: Instance> DisplayTimer for MicrobitDisplayTimer<T> {
4348
// set as 16 bits
4449
timer0.bitmode.write(|w| w.bitmode()._16bit());
4550

51+
#[cfg(feature = "v1")]
4652
// set frequency to 62500Hz
47-
timer0.prescaler.write(|w| unsafe { w.bits(8) });
53+
let prescaler = 8;
54+
#[cfg(feature = "v2")]
55+
// set frequency to 135000Hz
56+
let prescaler = 7;
57+
timer0.prescaler.write(|w| unsafe { w.bits(prescaler) });
4858

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

0 commit comments

Comments
 (0)