Skip to content

Commit a281bcf

Browse files
bors[bot]sirhcel
andauthored
Merge #362
362: Streamline LED roulette example r=adamgreig a=sirhcel This PR brings the LED roulette to up-to-date dependencies and factors out the examples, so that they could be tested in CI. I wanted to update all examples at once in the first place. But this did not get to the pace I wanted, so I will attempt this one after another. Co-authored-by: Christian Meusel <christian.meusel@posteo.de>
2 parents 5f0f05a + c9ddb5a commit a281bcf

File tree

7 files changed

+51
-51
lines changed

7 files changed

+51
-51
lines changed

src/05-led-roulette/auxiliary/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "aux5"
99
version = "0.2.0"
1010

1111
[dependencies]
12-
cortex-m = "0.6.4"
13-
cortex-m-rt = "0.6.13"
14-
stm32f3-discovery = "0.6.0"
12+
cortex-m = "0.7.2"
13+
cortex-m-rt = "0.6.14"
14+
stm32f3-discovery = "0.7.0"
1515
panic-itm = "0.4.2"

src/05-led-roulette/auxiliary/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pub use stm32f3xx_hal::{
1414
delay::Delay,
1515
gpio::{gpioe, Output, PushPull},
1616
hal::blocking::delay::DelayMs,
17-
stm32,
17+
pac,
1818
};
1919

2020
pub type LedArray = [Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>; 8];
2121

2222
pub fn init() -> (Delay, LedArray) {
23-
let device_periphs = stm32::Peripherals::take().unwrap();
23+
let device_periphs = pac::Peripherals::take().unwrap();
2424
let mut reset_and_clock_control = device_periphs.RCC.constrain();
2525

2626
let core_periphs = cortex_m::Peripherals::take().unwrap();

src/05-led-roulette/debug-it.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ invokes a subroutine call to the `main` function using an ARM branch and link in
5454
```
5555
(gdb) disassemble /m
5656
Dump of assembler code for function main:
57-
8 #[entry]
57+
7 #[entry]
5858
0x080001ec <+0>: push {r7, lr}
5959
0x080001ee <+2>: mov r7, sp
60-
=> 0x080001f0 <+4>: bl 0x80001f6 <hello_world::__cortex_m_rt_main>
60+
=> 0x080001f0 <+4>: bl 0x80001f6 <_ZN12led_roulette18__cortex_m_rt_main17he61ef18c060014a5E>
6161
0x080001f4 <+8>: udf #254 ; 0xfe
6262

6363
End of assembler dump.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![deny(unsafe_code)]
2+
#![no_main]
3+
#![no_std]
4+
5+
use aux5::{Delay, DelayMs, LedArray, OutputSwitch, entry};
6+
7+
#[entry]
8+
fn main() -> ! {
9+
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
10+
11+
let ms = 50_u8;
12+
loop {
13+
for curr in 0..8 {
14+
let next = (curr + 1) % 8;
15+
16+
leds[next].on().ok();
17+
delay.delay_ms(ms);
18+
leds[curr].off().ok();
19+
delay.delay_ms(ms);
20+
}
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![deny(unsafe_code)]
2+
#![no_main]
3+
#![no_std]
4+
5+
use aux5::{entry, Delay, DelayMs, LedArray, OutputSwitch};
6+
7+
#[entry]
8+
fn main() -> ! {
9+
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
10+
11+
let half_period = 500_u16;
12+
13+
loop {
14+
leds[0].on().ok();
15+
delay.delay_ms(half_period);
16+
17+
leds[0].off().ok();
18+
delay.delay_ms(half_period);
19+
}
20+
}

src/05-led-roulette/my-solution.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,7 @@ What solution did you come up with?
55
Here's mine:
66

77
``` rust
8-
#![deny(unsafe_code)]
9-
#![no_main]
10-
#![no_std]
11-
12-
use aux5::{Delay, DelayMs, LedArray, OutputSwitch, entry};
13-
14-
#[entry]
15-
fn main() -> ! {
16-
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
17-
18-
let ms = 50_u8;
19-
loop {
20-
for curr in 0..8 {
21-
let next = (curr + 1) % 8;
22-
23-
leds[next].on().ok();
24-
delay.delay_ms(ms);
25-
leds[curr].off().ok();
26-
delay.delay_ms(ms);
27-
}
28-
}
29-
}
30-
8+
{{#include examples/my-solution.rs}}
319
```
3210

3311
One more thing! Check that your solution also works when compiled in "release" mode:

src/05-led-roulette/the-led-and-delay-abstractions.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,7 @@ and exposes two methods: `on` and `off` which can be used to turn the LED on or
1414
Let's try out these two abstractions by modifying the starter code to look like this:
1515

1616
``` rust
17-
#![deny(unsafe_code)]
18-
#![no_main]
19-
#![no_std]
20-
21-
use aux5::{entry, Delay, DelayMs, LedArray, OutputSwitch};
22-
23-
#[entry]
24-
fn main() -> ! {
25-
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
26-
27-
let half_period = 500_u16;
28-
29-
loop {
30-
leds[0].on().ok();
31-
delay.delay_ms(half_period);
32-
33-
leds[0].off().ok();
34-
delay.delay_ms(half_period);
35-
}
36-
}
37-
17+
{{#include examples/the-led-and-delay-abstractions.rs}}
3818
```
3919

4020
Now build it:

0 commit comments

Comments
 (0)