aboutsummaryrefslogtreecommitdiffstats
path: root/sw/deps/hd44780-driver/examples/stm32f30x/src/main.rs
blob: 6b3b602be271bb35cbbf9c0aea24fa6af69d3374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![no_std]
#![no_main]

extern crate panic_halt;

use cortex_m_rt::entry;
use hal::gpio::GpioExt;
use hal::flash::FlashExt;
use hal::rcc::RccExt;
use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780};

// Connections:
// VSS: GND
// VDD: 5V
// V0:  10k poti between 5V and GND
// RS:  PD1
// RW:  GND
// E:   PD2
// D4-D7: PD4-PD7
// A:   5V
// K:   GND

#[entry]
fn main() -> ! {
    let cp = cortex_m::Peripherals::take().unwrap();
    let dp = hal::stm32f30x::Peripherals::take().unwrap();

    let mut flash = dp.FLASH.constrain();
    let mut rcc = dp.RCC.constrain();
    let mut gpiod = dp.GPIOD.split(&mut rcc.ahb);

    let clocks = rcc.cfgr.freeze(&mut flash.acr);
    let delay = hal::delay::Delay::new(cp.SYST, clocks);

    let rs = gpiod.pd1.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper);
    let en = gpiod.pd2.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper);
    let b4 = gpiod.pd4.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper);
    let b5 = gpiod.pd5.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper);
    let b6 = gpiod.pd6.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper);
    let b7 = gpiod.pd7.into_push_pull_output(&mut gpiod.moder, &mut gpiod.otyper);

    let mut lcd = HD44780::new_4bit(rs, en, b4, b5, b6, b7, delay);
    lcd.reset();
    lcd.clear();
    lcd.set_display_mode(
        DisplayMode {
            display: Display::On,
            cursor_visibility: Cursor::Visible,
            cursor_blink: CursorBlink::On,
        }
    );
    lcd.write_str("Hello, world!");

    loop {}
}