pub struct Lcd<Bus> { /* private fields */ }Expand description
Represents the LCD.
This struct holds together the bus, the LCD config, and the layout of the display. Most configuration options can be set via the Lcd methods. Only the function_mode of the chip, ie. the interface bandwidth, the font, and the line count, has to be configured via the ChipConfig methods before the Lcd is created. The line count in the ChipConfig should not be confused with the layout. It is related to the mapping of DDRAM adresses to the display positions, see the HD44780 reference manual for further information.
Implementations§
Source§impl<Bus: LcdBus> Lcd<Bus>
impl<Bus: LcdBus> Lcd<Bus>
Sourcepub fn new(bus: Bus, layout: Layout, config: Config) -> Result<Self, LcdError>
pub fn new(bus: Bus, layout: Layout, config: Config) -> Result<Self, LcdError>
Returns Lcd object.
Not all combinations of bus, layout, and config objects can be combined together. The specific variants should result in a plausible combination. A layout that has lines configured to be controlled via Chip::Two combined with a Config::SingleChip or a bus type that can only communicate with a single chip will not work.
The following errors can occur:
- LcdError::InitSingleChipWrongLayout: When config is Config::SingleChip, but layout contains lines to be controlled via Chip::Two.
- LcdError::InitSingleChipWrongBus: When config is Config::SingleChip, but bus has no E2 pin.
- LcdError::InitDoubleChipWrongLayout: When config is Config::DoubleChip, but layout only addresses Chip::One.
- LcdError::InitDoubleChipWrongBus: When config is Config::DoubleChip, but bus has no E2 pin.
§Example
let layout = Layout::TwoLine([(Chip::One, [0, 39]), (Chip::One, [64, 103])]);
let mut chip_config = ChipConfig::default();
chip_config.display_on();
let bus = ParallelBus4SingleChip::new(rs, rw, en, d4, d5, d6, d7);
let mut lcd = Lcd::new(bus, layout, Config::SingleChip([chip_config]))?;Sourcepub fn init<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn init<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Initializes the specified chip.
Init needs to be called before communication with the lcd. Multiple calls are possible.
§Example
lcd.init(&mut delay, Chip::One)?;Sourcepub fn print<D: DelayNs>(
&mut self,
delay: &mut D,
line: usize,
column: u8,
string: &str,
) -> Result<(), LcdError>
pub fn print<D: DelayNs>( &mut self, delay: &mut D, line: usize, column: u8, string: &str, ) -> Result<(), LcdError>
Prints the given string to given line starting from specific position.
Convenience method that transforms the string to bytes and calls Lcd::print_bytes. See docs here.
§Example
lcd.print(&mut delay, 0, 0, "Hi there,")?;Sourcepub fn print_bytes<D: DelayNs>(
&mut self,
delay: &mut D,
line: usize,
column: u8,
byte_slice: &[u8],
) -> Result<(), LcdError>
pub fn print_bytes<D: DelayNs>( &mut self, delay: &mut D, line: usize, column: u8, byte_slice: &[u8], ) -> Result<(), LcdError>
Prints the given byte slice to given line starting from specific position.
Column is the position within the address range for that given line, starting at 0. If column is bigger than the length of the address range Err(LcdError::PrintStartOutsideLayout) is returned. If the slice is bigger than the remaining address range, the slice will be silently truncated.
Sourcepub fn display_off<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn display_off<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns off display for specified chip.
Sourcepub fn display_on<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn display_on<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns on display for specified chip.
Sourcepub fn cursor_off<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn cursor_off<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns off cursor for specified chip.
Sourcepub fn cursor_on<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn cursor_on<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns on cursor for specified chip.
Sourcepub fn blink_off<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn blink_off<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns off blink for specified chip.
Sourcepub fn blink_on<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn blink_on<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns on blink for specified chip.
Sourcepub fn right_to_left<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn right_to_left<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns on writing from right to left for specified chip.
Sourcepub fn left_to_right<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn left_to_right<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns on writing from left to right for specified chip.
Sourcepub fn autoscroll_off<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn autoscroll_off<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns off autoscroll for specified chip.
Sourcepub fn autoscroll_on<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn autoscroll_on<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Turns on autoscroll for specified chip.
For each character inserted the display moves one character along.
Sourcepub fn clear_display<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn clear_display<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Clears display and at same time moves cursor to first address for specified chip.
Sourcepub fn return_home<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn return_home<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Sets cursor to first address for specified chip.
Sourcepub fn move_cursor_left<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn move_cursor_left<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Moves cursor one address to the left for specified chip.
Sourcepub fn move_cursor_right<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn move_cursor_right<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Moves cursor one address to the right for specified chip.
Sourcepub fn scroll_display_left<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn scroll_display_left<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Scrolls display one step to the left for specified chip.
Sourcepub fn scroll_display_right<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(), LcdError>
pub fn scroll_display_right<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>
Scrolls display one step to the right for specified chip.
Sourcepub fn set_cg_address<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
address: u8,
) -> Result<(), LcdError>
pub fn set_cg_address<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, address: u8, ) -> Result<(), LcdError>
Sets address of CGRAM for specified chip to specified address.
Sourcepub fn set_dd_address<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
address: u8,
) -> Result<(), LcdError>
pub fn set_dd_address<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, address: u8, ) -> Result<(), LcdError>
Sets address of DDRAM for specified chip to specified address.
Sourcepub fn read_data<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<u8, LcdError>
pub fn read_data<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<u8, LcdError>
Reads one byte from the bus for specified chip.
Sourcepub fn busy_flag_and_address_counter<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
) -> Result<(bool, u8), LcdError>
pub fn busy_flag_and_address_counter<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(bool, u8), LcdError>
Reads the busy flag and the current address of the address counter for specified chip.
Sourcepub fn write_instruction<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
instruction: u8,
) -> Result<(), LcdError>
pub fn write_instruction<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, instruction: u8, ) -> Result<(), LcdError>
Makes one instruction to specified chip.
Sourcepub fn write_data<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
data: u8,
) -> Result<(), LcdError>
pub fn write_data<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, data: u8, ) -> Result<(), LcdError>
Writes one byte to specified chip.
Sourcepub fn set_custom_character<D: DelayNs>(
&mut self,
delay: &mut D,
chip: Chip,
address: u8,
pattern: [u8; 8],
) -> Result<(), LcdError>
pub fn set_custom_character<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, address: u8, pattern: [u8; 8], ) -> Result<(), LcdError>
Sets up a custom character for specified chip.
It is possible to store up to eight custom characters in the addresses from 0 to 7. They are defined via arrays of eight bytes in which the first five bits represent the pixel value of each line. A one represents a “dark” pixel.
The characters can be used by printing the bytes from 0 to 7.