Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Characters #55

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
40 changes: 40 additions & 0 deletions src/character.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use core::iter::once;

use embedded_hal::delay::DelayNs;

use crate::{bus::DataBus, charset::CharsetWithFallback, error::Result, memory_map::DisplayMemoryMap, HD44780};

pub struct CharacterDefinition {
pub pattern: [u8; 10],
pub cursor: u8,

// /// Since lines 12 to 16 are not used for display,
// /// they can be used for general data RAM.
// pub data: Option<[u8; 5]>,
}

impl<B, M, C> HD44780<B, M, C>
where
B: DataBus,
M: DisplayMemoryMap,
C: CharsetWithFallback,
{
pub fn define_custom_character<D: DelayNs>(
&mut self,
code: u8,
def: &CharacterDefinition,
delay: &mut D,
) -> Result<(), B::Error> {
self.write_command(0b01000000 | (code & 0b11) << 4, delay)?;
delay.delay_us(100);

let lines = def.pattern.iter().cloned().chain(once(def.cursor));
for line in lines {
self.write_byte(line, delay)?;
}

// Change back to DDRAM
self.set_cursor_pos(0, delay)?;
Ok(())
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use entry_mode::{CursorMode, EntryMode};
pub mod setup;

pub mod charset;
pub mod character;

pub mod memory_map;

Expand Down