Lcd

Struct Lcd 

Source
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>

Source

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:

§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]))?;
Source

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)?;
Source

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,")?;
Source

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.

Source

pub fn display_off<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>

Turns off display for specified chip.

Source

pub fn display_on<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>

Turns on display for specified chip.

Source

pub fn cursor_off<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>

Turns off cursor for specified chip.

Source

pub fn cursor_on<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>

Turns on cursor for specified chip.

Turns off blink for specified chip.

Turns on blink for specified chip.

Source

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.

Source

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.

Source

pub fn autoscroll_off<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>

Turns off autoscroll for specified chip.

Source

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.

Source

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.

Source

pub fn return_home<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, ) -> Result<(), LcdError>

Sets cursor to first address for specified chip.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn write_instruction<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, instruction: u8, ) -> Result<(), LcdError>

Makes one instruction to specified chip.

Source

pub fn write_data<D: DelayNs>( &mut self, delay: &mut D, chip: Chip, data: u8, ) -> Result<(), LcdError>

Writes one byte to specified chip.

Source

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.

Source

pub fn release(self) -> (Bus, Layout, Config)

Destructs the Lcd and returns the bus, layout, and config.

Auto Trait Implementations§

§

impl<Bus> Freeze for Lcd<Bus>
where Bus: Freeze,

§

impl<Bus> RefUnwindSafe for Lcd<Bus>
where Bus: RefUnwindSafe,

§

impl<Bus> Send for Lcd<Bus>
where Bus: Send,

§

impl<Bus> Sync for Lcd<Bus>
where Bus: Sync,

§

impl<Bus> Unpin for Lcd<Bus>
where Bus: Unpin,

§

impl<Bus> UnwindSafe for Lcd<Bus>
where Bus: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.