Skip to content

Commit a368c2d

Browse files
bors[bot]burrbull
andauthored
Merge #441
441: hd44780-driver example r=therealprof a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents aa934ca + c52dbf5 commit a368c2d

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2929

3030
- Missing `DelayMs<u8>` / `DelayUs<u8>` impls for fugit::Delay
3131
- Support of embedded-hal 1.0.0-alpha.7 [#443]
32+
- `hd44780` example [#441]
3233
- Aliases for peripheral wrappers [#434]
3334
- `WithPwm` trait implemented for timers with channels (internals) [#425]
3435
- `Pwm` struct with `split` method and implementation of embedded-hal::Pwm (similar to f1xx-hal) [#425]
@@ -52,6 +53,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
5253
[#439]: https://github.com/stm32-rs/stm32f4xx-hal/pull/439
5354
[#440]: https://github.com/stm32-rs/stm32f4xx-hal/pull/440
5455
[#443]: https://github.com/stm32-rs/stm32f4xx-hal/pull/443
56+
[#441]: https://github.com/stm32-rs/stm32f4xx-hal/pull/441
5557

5658
### Changed
5759

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fugit-timer = "0.1.3"
4646
rtic-monotonic = { version = "1.0", optional = true }
4747
bitflags = "1.3.2"
4848
embedded-storage = "0.2"
49+
hd44780-driver = "0.4.0"
4950

5051
[dependencies.time]
5152
version = "0.3"
@@ -473,3 +474,7 @@ required-features = ["device-selected"]
473474
name = "rtc"
474475
required-features = ["device-selected"]
475476

477+
[[example]]
478+
name = "hd44780"
479+
required-features = ["device-selected"]
480+

examples/blinky-timer-irq.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::hal::{
1818
};
1919

2020
use core::cell::RefCell;
21-
use cortex_m::{asm::wfi, interrupt::Mutex};
21+
use cortex_m::interrupt::Mutex;
2222
use cortex_m_rt::entry;
2323

2424
// NOTE You can uncomment 'hprintln' here and in the code below for a bit more
@@ -93,6 +93,7 @@ fn main() -> ! {
9393
}
9494

9595
loop {
96-
wfi();
96+
// Uncomment if you want to make controller sleep
97+
// cortex_m::asm::wfi();
9798
}
9899
}

examples/hd44780.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
extern crate panic_halt;
5+
6+
use cortex_m_rt::entry;
7+
use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780};
8+
use stm32f4xx_hal::{pac, prelude::*};
9+
10+
// Connections:
11+
// VSS: GND
12+
// VDD: 5V
13+
// V0: 10k poti between 5V and GND
14+
// RS: PB7
15+
// RW: GND
16+
// E: PB8
17+
// D4-D7: PB6-PB3
18+
// A: 5V
19+
// K: GND
20+
21+
#[entry]
22+
fn main() -> ! {
23+
let dp = pac::Peripherals::take().unwrap();
24+
25+
let rcc = dp.RCC.constrain();
26+
let gpiob = dp.GPIOB.split();
27+
28+
let clocks = rcc.cfgr.freeze();
29+
let mut delay = dp.TIM1.delay_us(&clocks);
30+
31+
let rs = gpiob.pb7.into_push_pull_output();
32+
let en = gpiob.pb8.into_push_pull_output();
33+
let d4 = gpiob.pb6.into_push_pull_output();
34+
let d5 = gpiob.pb5.into_push_pull_output();
35+
let d6 = gpiob.pb4.into_push_pull_output();
36+
let d7 = gpiob.pb3.into_push_pull_output();
37+
38+
let mut lcd = HD44780::new_4bit(rs, en, d4, d5, d6, d7, &mut delay).unwrap();
39+
lcd.reset(&mut delay).unwrap();
40+
lcd.clear(&mut delay).unwrap();
41+
lcd.set_display_mode(
42+
DisplayMode {
43+
display: Display::On,
44+
cursor_visibility: Cursor::Visible,
45+
cursor_blink: CursorBlink::On,
46+
},
47+
&mut delay,
48+
)
49+
.unwrap();
50+
lcd.write_str("Hello, world!", &mut delay).unwrap();
51+
52+
loop {}
53+
}

0 commit comments

Comments
 (0)