Skip to content

Commit 8386f23

Browse files
authored
Merge pull request #36 from robyoung/docs-improvements
Various docs improvements
2 parents 8dae48e + ab55896 commit 8386f23

File tree

4 files changed

+94
-16
lines changed

4 files changed

+94
-16
lines changed

src/display/mod.rs

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//! Support for the 5×5 LED display.
1+
//! Non-blocking support for the 5×5 LED display.
22
//!
33
//! # Scope
44
//!
5-
//! Together with `tiny-led-matrix`, this module provides:
5+
//! Together with [`tiny-led-matrix`](tiny_led_matrix), this module provides:
66
//! - support for driving the LED display from a timer interrupt
77
//! - ten levels of brightness for each LED
88
//! - simple 5×5 greyscale and black-and-white image types.
@@ -13,8 +13,49 @@
1313
//!
1414
//! # Example
1515
//!
16-
//! `examples/led_nonblocking.rs` demonstrates the main features of this
17-
//! module.
16+
//! This shows general usage but is not a working example.
17+
//! For a working exaple see `examples/led_nonblocking.rs`.
18+
//!
19+
//! ```no_run
20+
//! // in your main function
21+
//! {
22+
//! let p = pac::Peripherals::take().unwrap();
23+
//! let mut timer = MicrobitDisplayTimer::new(p.TIMER1);
24+
//! let p0parts = P0Parts::new(p.GPIO);
25+
//! let mut pins = display_pins!(p0parts);
26+
//! display::initialise_display(&mut timer, &mut pins);
27+
//! let display = Display::new();
28+
//!
29+
//! static mut FRAME: MicrobitFrame = MicrobitFrame::const_default();
30+
//!
31+
//! loop {
32+
//! FRAME.set(GreyscaleImage::new(&[
33+
//! [0, 7, 0, 7, 0],
34+
//! [7, 0, 7, 0, 7],
35+
//! [7, 0, 0, 0, 7],
36+
//! [0, 7, 0, 7, 0],
37+
//! [0, 0, 7, 0, 0],
38+
//! ]));
39+
//! display.set_frame(&FRAME);
40+
//! timer2.delay_ms(1000);
41+
//!
42+
//! FRAME.set(GreyscaleImage::new(&[
43+
//! [0, 0, 0, 0, 0],
44+
//! [0, 0, 0, 0, 0],
45+
//! [0, 0, 0, 0, 0],
46+
//! [0, 0, 0, 0, 0],
47+
//! [0, 0, 0, 0, 0],
48+
//! ]));
49+
//! display.set_frame(&FRAME);
50+
//! timer2.delay_ms(1000);
51+
//! }
52+
//! }
53+
//!
54+
//! // in a timer interrupt
55+
//! {
56+
//! display::handle_display_event(display, timer, pins);
57+
//! }
58+
//! ```
1859
//!
1960
//! # Coordinate system
2061
//!
@@ -52,8 +93,8 @@
5293
//!
5394
//! The [`image`] submodule provides two static image types implementing
5495
//! `Render`:
55-
//! - [`GreyscaleImage`], allowing all 9 levels (using one byte for each LED)
56-
//! - [`BitImage`], allowing only 'on' and 'off' (using five bytes)
96+
//! - [`GreyscaleImage`](image::GreyscaleImage), allowing all 9 levels (using one byte for each LED)
97+
//! - [`BitImage`](image::BitImage), allowing only 'on' and 'off' (using five bytes)
5798
//!
5899
//! # Display
59100
//!
@@ -101,7 +142,7 @@
101142
//! * create a [`MicrobitDisplayTimer`] struct, passing the timer you chose to
102143
//! [`MicrobitDisplayTimer::new()`]
103144
//! * call [`initialise_display()`], passing it the `MicrobitDisplayTimer` and the
104-
//! [`crate::led::Pins`]
145+
//! [`crate::gpio::DisplayPins`]
105146
//! * create a [`Display`] struct (a `Display<MicrobitFrame>`).
106147
//!
107148
//! In an interrupt handler for the timer, call [`handle_display_event()`].

src/gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Named GPIO pin types
22
//!
33
//! This module maps the GPIO pin names as described in the
4-
//! [v1.5 schematic](https://github.com/bbcmicrobit/hardware/tree/master/V1.5).
4+
//! [Pins and Signals section of the micro:bit site](https://tech.microbit.org/hardware/edgeconnector/#pins-and-signals)
55
//! Where appropriate the pins are restricted with the appropriate `MODE`
66
//! from `nrf-hal`.
77
#![allow(clippy::upper_case_acronyms, missing_docs)]

src/led.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
1-
//! On-board user LEDs
2-
1+
//! Blocking support for the 5x5 LED display.
2+
//!
3+
//! This module provides a simple blocking interface
4+
//! to the on board 5x5 LED display. If you need a more sophisticated
5+
//! or non-blocking interface use the [`display`](crate::display) module.
6+
//!
7+
//! # Example
8+
//!
9+
//! ```no_run
10+
//! use microbit::{
11+
//! display_pins,
12+
//! hal::{gpio::p0::Parts, prelude::*, Timer},
13+
//! };
14+
//! // take the peripherals
15+
//! let p = microbit::pac::Peripherals::take().unwrap();
16+
//! // make a timer
17+
//! let mut timer = Timer::new(p.TIMER0);
18+
//! // split off the p0::Parts
19+
//! let p0parts = Parts::new(p.GPIO);
20+
//! // create the DisplayPins struct
21+
//! let pins = display_pins!(p0parts);
22+
//! // create the Display
23+
//! let mut leds = led::Display::new(pins);
24+
//! // and light up some LEDs
25+
//! let heart = [
26+
//! [0, 1, 0, 1, 0],
27+
//! [1, 0, 1, 0, 1],
28+
//! [1, 0, 0, 0, 1],
29+
//! [0, 1, 0, 1, 0],
30+
//! [0, 0, 1, 0, 0],
31+
//! ];
32+
//! loop {
33+
//! leds.display(&mut timer, heart, 1000);
34+
//! leds.clear();
35+
//! timer.delay_ms(250);
36+
//! }
37+
//! ```
38+
//!
39+
//! See a working example at `examples/led_blocking.rs`
340
use crate::hal::{
441
gpio::{Output, Pin, PushPull},
542
prelude::*,
@@ -21,16 +58,18 @@ const LED_LAYOUT: [[(usize, usize); 5]; 5] = [
2158
[(2, 2), (1, 6), (2, 0), (1, 5), (2, 1)],
2259
];
2360

24-
/// Array of all the LEDs in the 5x5 display on the board
61+
/// Blocking interface to the on board LED display
2562
pub struct Display {
2663
delay_ms: u32,
2764
rows: [LED; 3],
2865
cols: [LED; 9],
2966
}
3067

3168
impl Display {
32-
/// Initializes all the user LEDs
33-
#[allow(clippy::too_many_arguments)]
69+
/// Initialise display
70+
///
71+
/// The [`display_pins!`](crate::display_pins) macro can be used
72+
/// to create [`DisplayPins`].
3473
pub fn new(pins: DisplayPins) -> Self {
3574
let mut retval = Display {
3675
delay_ms: DEFAULT_DELAY_MS,

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ pub use hal::pac;
99
pub use hal::pac::Peripherals;
1010
pub use nrf51_hal as hal;
1111

12-
pub use nb::*;
13-
1412
pub mod display;
1513
pub mod gpio;
1614
pub mod led;
1715

18-
/// Create a [Uart](hal::uart::Uart] client with the default pins
16+
/// Create a [Uart](hal::uart::Uart) client with the default pins
1917
#[macro_export]
2018
macro_rules! serial_port {
2119
( $gpio:expr, $uart:expr, $speed:expr ) => {{

0 commit comments

Comments
 (0)