From a02c8131ff52da4f1f184b01056de6033facc647 Mon Sep 17 00:00:00 2001 From: Marcuss2 Date: Fri, 23 Jul 2021 10:37:36 +0200 Subject: [PATCH] Add HD44780 example (#60) * Added HD44780 lcd example * Formatting lcd_display.rs * Formatting Cargo.toml * Fixed import formatting issue * Fixed line with spaces --- rp2040-hal/Cargo.toml | 3 +- rp2040-hal/examples/lcd_display.rs | 52 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 rp2040-hal/examples/lcd_display.rs diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 1e20b38..f23c6a5 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -21,6 +21,7 @@ paste = "1.0" cortex-m-rt = "0.6.14" panic-halt = "0.2.0" rp2040-boot2 = { git = "https://github.com/rp-rs/rp2040-boot2-rs", branch="main" } +hd44780-driver = "0.4.0" [features] -rt = ["rp2040-pac/rt"] \ No newline at end of file +rt = ["rp2040-pac/rt"] diff --git a/rp2040-hal/examples/lcd_display.rs b/rp2040-hal/examples/lcd_display.rs new file mode 100644 index 0000000..840997d --- /dev/null +++ b/rp2040-hal/examples/lcd_display.rs @@ -0,0 +1,52 @@ +#![no_std] +#![no_main] + +use cortex_m_rt::entry; +use hal::pac; +use hal::sio::Sio; +use hd44780_driver as hd44780; +use panic_halt as _; +use rp2040_hal as hal; + +#[link_section = ".boot2"] +#[used] +pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER; + +#[entry] +fn main() -> ! { + let mut pac = pac::Peripherals::take().unwrap(); + let core = pac::CorePeripherals::take().unwrap(); + + // AHL bus speed default + let mut delay_provider = cortex_m::delay::Delay::new(core.SYST, 12_000_000); + + let sio = Sio::new(pac.SIO); + let pins = hal::gpio::Pins::new( + pac.IO_BANK0, + pac.PADS_BANK0, + sio.gpio_bank0, + &mut pac.RESETS, + ); + + let lcd = hd44780::HD44780::new_4bit( + pins.gpio16.into_push_pull_output(), // Register Select + pins.gpio17.into_push_pull_output(), // Enable + pins.gpio18.into_push_pull_output(), // d4 + pins.gpio19.into_push_pull_output(), // d5 + pins.gpio20.into_push_pull_output(), // d6 + pins.gpio21.into_push_pull_output(), // d7 + &mut delay_provider, + ); + + let mut lcd = lcd.unwrap(); + + lcd.reset(&mut delay_provider).unwrap(); + lcd.clear(&mut delay_provider).unwrap(); + lcd.write_str("rp-hal on", &mut delay_provider).unwrap(); + lcd.set_cursor_pos(40, &mut delay_provider).unwrap(); + lcd.set_cursor_visibility(hd44780::Cursor::Visible, &mut delay_provider) + .unwrap(); + lcd.write_str("HD44780!", &mut delay_provider).unwrap(); + + loop {} +}