#![no_std]
#![no_main]
use core::fmt::Write;
use embedded_hal::blocking::delay::DelayMs;
use esp32_hal::{
clock::ClockControl,
dport::Split,
gpio::{Gpio0, Gpio2, Gpio4, Gpio5, Output, PushPull},
peripherals::Peripherals,
prelude::*,
Rtc,
};
use hd44780_driver::{HD44780, DisplayMode};
use panic_halt as _; // choose your panic handler
#[entry]
fn main() -> ! {
// Initialize the peripherals
let peripherals = Peripherals::take().unwrap();
let system = peripherals.DPORT.split();
let clocks = ClockControl::configure(
peripherals.RTC.clock,
80.mhz(), // or a setting supported by your ESP32 module
&system,
)
.freeze();
// Configure GPIO pins connected to the LCD.
// Adjust the pins according to your Wokwi simulation wiring.
let mut gpio = peripherals.GPIO.split();
let rs: Gpio0<Output<PushPull>> = gpio.gpio0.into_push_pull_output();
let en: Gpio2<Output<PushPull>> = gpio.gpio2.into_push_pull_output();
let d4: Gpio4<Output<PushPull>> = gpio.gpio4.into_push_pull_output();
let d5: Gpio5<Output<PushPull>> = gpio.gpio5.into_push_pull_output();
// If using 4-bit mode, you’ll need only these data GPIOs.
// Create a delay provider (you may need to adapt this to your HAL)
let mut delay = esp32_hal::delay::Delay::new(&clocks);
// Initialize the LCD controller using the HD44780 protocol.
let mut lcd = HD44780::new_4bit(rs, en, d4, d5, &mut delay).unwrap();
lcd.clear();
// Set display mode if necessary
lcd.set_display_mode(DisplayMode {
display: true,
cursor: false,
blink: false,
});
// Write a sample message to the LCD
write!(lcd, "Hello ESP32!").unwrap();
loop {
delay.delay_ms(1000u16);
// Here you could update the LCD or perform other tasks.
}
}