Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ let mut lcd = HD44780::new(
DisplayOptions8Bit::new(MemoryMap1602::new())
.with_pins(FourBitBusPins {
rs: d4.into_push_pull_output(&mut port), // Register Select pin,
rw: WriteOnlyMode, // Read/Write pin is pulled low,
en: d3.into_push_pull_output(&mut port), // Enable pin,

d4: d9.into_push_pull_output(&mut port), // d4,
Expand Down Expand Up @@ -84,6 +85,7 @@ let mut display = HD44780::new(
DisplayOptions8Bit::new(MemoryMap1602::new())
.with_pins(FourBitBusPins {
rs,
rw,
en,
d4,
d5,
Expand Down
50 changes: 50 additions & 0 deletions examples/atmega328-nostd/src/bin/hello-4bit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![no_std]
#![no_main]

use arduino_hal::Delay;
use embedded_hal::delay::DelayNs as _;
use hd44780_driver::{
bus::{FourBitBusPins, WriteOnlyMode},
memory_map::MemoryMap1602,
setup::DisplayOptions4Bit,
HD44780,
};
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
let peripherals = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(peripherals);

// Setup USB Serial
let mut serial = arduino_hal::default_serial!(peripherals, pins, 115200);

let mut delay = Delay::new();

ufmt::uwriteln!(serial, "Start").unwrap();

// Configure LCD driver with 10 pins
let options = DisplayOptions4Bit::new(MemoryMap1602::new()).with_pins(FourBitBusPins {
rs: pins.d12.into_output(),
rw: WriteOnlyMode,
en: pins.d11.into_output(),

d4: pins.d6.into_opendrain(),
d5: pins.d5.into_opendrain(),
d6: pins.d4.into_opendrain(),
d7: pins.d3.into_opendrain(),
});

// Initialize LCD driver
// Note: IO Error is infallible, thus unwrapping won't panic here
let mut display = HD44780::new(options, &mut delay).unwrap_or_else(|_| unreachable!());

display.clear(&mut delay).unwrap();
display.reset(&mut delay).unwrap();

display.write_str("Hello, world!", &mut delay).unwrap();

loop {
delay.delay_ms(1000);
}
}
49 changes: 49 additions & 0 deletions examples/atmega328-nostd/src/bin/hello-8bit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#![no_std]
#![no_main]

use arduino_hal::Delay;
use embedded_hal::delay::DelayNs as _;
use hd44780_driver::{bus::{EightBitBusPins, WriteOnlyMode}, memory_map::MemoryMap1602, setup::DisplayOptions8Bit, HD44780};
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
let peripherals = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(peripherals);

// Setup USB Serial
let mut serial = arduino_hal::default_serial!(peripherals, pins, 115200);

let mut delay = Delay::new();

ufmt::uwriteln!(serial, "Start").unwrap();

// Configure LCD driver with 10 pins
let options = DisplayOptions8Bit::new(MemoryMap1602::new()).with_pins(EightBitBusPins {
rs: pins.d12.into_output(),
rw: WriteOnlyMode,
en: pins.d11.into_output(),

d0: pins.d10.into_opendrain(),
d1: pins.d9.into_opendrain(),
d2: pins.d8.into_opendrain(),
d3: pins.d7.into_opendrain(),
d4: pins.d6.into_opendrain(),
d5: pins.d5.into_opendrain(),
d6: pins.d4.into_opendrain(),
d7: pins.d3.into_opendrain(),
});

// Initialize LCD driver
// Note: IO Error is infallible, thus unwrapping won't panic here
let mut display = HD44780::new(options, &mut delay).unwrap_or_else(|_| unreachable!());

display.clear(&mut delay).unwrap();
display.reset(&mut delay).unwrap();

display.write_str("Hello, world!", &mut delay).unwrap();

loop {
delay.delay_ms(1000);
}
}
51 changes: 51 additions & 0 deletions examples/atmega328-nostd/src/bin/read-i2c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![no_std]
#![no_main]

use arduino_hal::Delay;
use embedded_hal::delay::DelayNs as _;
use hd44780_driver::{memory_map::MemoryMap1602, setup::DisplayOptionsI2C, HD44780};
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
let peripherals = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(peripherals);

// Setup USB Serial
let mut serial = arduino_hal::default_serial!(peripherals, pins, 115200);

let mut delay = Delay::new();

ufmt::uwriteln!(serial, "Start\r").unwrap();

// Configure I2C interface
let i2c =
arduino_hal::I2c::new(peripherals.TWI, pins.a4.into_pull_up_input(), pins.a5.into_pull_up_input(), 100_000);

// Configure LCD driver with I2C
let mut options = DisplayOptionsI2C::new(MemoryMap1602::new()).with_i2c_bus(i2c, 0x27);

// Initialize LCD driver
let mut display = loop {
match HD44780::new(options, &mut delay) {
Err((options_back, error)) => {
ufmt::uwriteln!(serial, "Error creating LCD Driver: {}", error).unwrap();
options = options_back;
delay.delay_ms(500);
// try again
}
Ok(display) => break display,
}
};

display.clear(&mut delay).unwrap();
display.reset(&mut delay).unwrap();

display.write_str("Hello, world!", &mut delay).unwrap();
let status = display.read_status(&mut delay).unwrap();
ufmt::uwriteln!(serial, "{:?}\r", status).unwrap();

loop {
delay.delay_ms(1000);
}
}
8 changes: 6 additions & 2 deletions examples/esp32-nostd/src/bin/charset-4bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ use esp_hal::{
system::SystemControl,
};
use hd44780_driver::{
bus::FourBitBusPins, charset::CharsetA00, memory_map::MemoryMap1602, setup::DisplayOptions4Bit, Cursor,
CursorBlink, Direction, Display, DisplayMode, HD44780,
bus::{FourBitBusPins, WriteOnlyMode},
charset::CharsetA00,
memory_map::MemoryMap1602,
setup::DisplayOptions4Bit,
Cursor, CursorBlink, Direction, Display, DisplayMode, HD44780,
};
use log::{error, info};

Expand All @@ -33,6 +36,7 @@ fn main() -> ! {
let mut options = DisplayOptions4Bit::new(MemoryMap1602::new())
.with_pins(FourBitBusPins {
rs: make_output(io.pins.gpio12),
rw: WriteOnlyMode,
en: make_output(io.pins.gpio14),

d4: make_output(io.pins.gpio17),
Expand Down
8 changes: 6 additions & 2 deletions examples/esp32-nostd/src/bin/charset-8bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ use esp_hal::{
system::SystemControl,
};
use hd44780_driver::{
bus::EightBitBusPins, charset::CharsetA00, memory_map::MemoryMap1602, setup::DisplayOptions8Bit, Cursor,
CursorBlink, Direction, Display, DisplayMode, HD44780,
bus::{EightBitBusPins, WriteOnlyMode},
charset::CharsetA00,
memory_map::MemoryMap1602,
setup::DisplayOptions8Bit,
Cursor, CursorBlink, Direction, Display, DisplayMode, HD44780,
};
use log::{error, info};

Expand All @@ -33,6 +36,7 @@ fn main() -> ! {
let mut options = DisplayOptions8Bit::new(MemoryMap1602::new())
.with_pins(EightBitBusPins {
rs: make_output(io.pins.gpio12),
rw: WriteOnlyMode,
en: make_output(io.pins.gpio14),

d0: make_output(io.pins.gpio2),
Expand Down
8 changes: 7 additions & 1 deletion examples/esp32-nostd/src/bin/hello-4bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use esp_hal::{
prelude::*,
system::SystemControl,
};
use hd44780_driver::{bus::FourBitBusPins, memory_map::MemoryMap1602, setup::DisplayOptions4Bit, HD44780};
use hd44780_driver::{
bus::{FourBitBusPins, WriteOnlyMode},
memory_map::MemoryMap1602,
setup::DisplayOptions4Bit,
HD44780,
};
use log::{error, info};

#[entry]
Expand All @@ -29,6 +34,7 @@ fn main() -> ! {
// Configure LCD driver with 6 pins
let mut options = DisplayOptions4Bit::new(MemoryMap1602::new()).with_pins(FourBitBusPins {
rs: make_output(io.pins.gpio12),
rw: WriteOnlyMode,
en: make_output(io.pins.gpio14),

d4: make_output(io.pins.gpio17),
Expand Down
8 changes: 7 additions & 1 deletion examples/esp32-nostd/src/bin/hello-8bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use esp_hal::{
prelude::*,
system::SystemControl,
};
use hd44780_driver::{bus::EightBitBusPins, memory_map::MemoryMap1602, setup::DisplayOptions8Bit, HD44780};
use hd44780_driver::{
bus::{EightBitBusPins, WriteOnlyMode},
memory_map::MemoryMap1602,
setup::DisplayOptions8Bit,
HD44780,
};
use log::{error, info};

#[entry]
Expand All @@ -29,6 +34,7 @@ fn main() -> ! {
// Configure LCD driver with 10 pins
let mut options = DisplayOptions8Bit::new(MemoryMap1602::new()).with_pins(EightBitBusPins {
rs: make_output(io.pins.gpio12),
rw: WriteOnlyMode,
en: make_output(io.pins.gpio14),

d0: make_output(io.pins.gpio2),
Expand Down
Loading