-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement defining custom characters
- Loading branch information
1 parent
3304d93
commit ec34e2b
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters