LcdDisplay.HD44780.Util (lcd_display v0.2.0) View Source

A collection of utility functions that are used for display drivers.

Link to this section Summary

Types

Typically 2x16 or 4x20.

Functions

Adjusts the backlight-related values in the display driver state.

Determine a list of row offsets based on how many columns the display has.

Determines a Display Data RAM (DDRAM) address based on the display configuration (rows and columns) and the zero-indexed cursor position (row and column).

Shuffles the RGB boolean values in the display driver state.

Link to this section Types

Specs

display_config() :: %{
  :rows => LcdDisplay.HD44780.Driver.num_rows(),
  :cols => LcdDisplay.HD44780.Driver.num_cols(),
  required(any()) => any()
}

Typically 2x16 or 4x20.

Specs

row_col_pos() :: {non_neg_integer(), non_neg_integer()}

Link to this section Functions

Link to this function

adjust_backlight_config(display)

View Source

Specs

adjust_backlight_config(map()) :: map()

Adjusts the backlight-related values in the display driver state.

Examples

  # Default to the white LED when no color is specified.
  iex> LcdDisplay.HD44780.Util.adjust_backlight_config(%{backlight: true, red: false, green: false, blue: false})
  %{backlight: true, blue: true, green: true, red: true}

  # Turn off all colors when the backlight is turned off.
  iex> LcdDisplay.HD44780.Util.adjust_backlight_config(%{backlight: false, red: true, green: true, blue: true})
  %{backlight: false, blue: false, green: false, red: false}

  # Else do nothing
  iex> LcdDisplay.HD44780.Util.adjust_backlight_config(%{backlight: true, red: true, green: false, blue: false})
  %{backlight: true, blue: false, green: false, red: true}
Link to this function

ddram_row_offsets(num_cols)

View Source

Specs

ddram_row_offsets(LcdDisplay.HD44780.Driver.num_cols()) ::
  {0, 64, pos_integer(), pos_integer()}

Determine a list of row offsets based on how many columns the display has.

0x00: | ROW 0 | ROW 2 |
0x40: | ROW 1 | ROW 3 |

For more info, please refer to Hitachi HD44780 datasheet page 10.

Examples

iex> LcdDisplay.HD44780.Util.ddram_row_offsets(8)
{0, 64, 8, 72}

iex> LcdDisplay.HD44780.Util.ddram_row_offsets(16)
{0, 64, 16, 80}

iex> LcdDisplay.HD44780.Util.ddram_row_offsets(20)
{0, 64, 20, 84}
Link to this function

determine_ddram_address(row_col_pos, display_config)

View Source

Specs

determine_ddram_address(row_col_pos(), display_config()) :: non_neg_integer()

Determines a Display Data RAM (DDRAM) address based on the display configuration (rows and columns) and the zero-indexed cursor position (row and column).

Examples

iex> LcdDisplay.HD44780.Util.determine_ddram_address({0,0}, %{rows: 2, cols: 16})
0

iex> LcdDisplay.HD44780.Util.determine_ddram_address({0,15}, %{rows: 2, cols: 16})
15

iex> LcdDisplay.HD44780.Util.determine_ddram_address({1,0}, %{rows: 2, cols: 16})
64

iex> LcdDisplay.HD44780.Util.determine_ddram_address({1,15}, %{rows: 2, cols: 16})
79

Specs

shuffle_color(map()) :: map()

Shuffles the RGB boolean values in the display driver state.