Elcdx.Driver (elcdx v0.1.1)

View Source

Low-level driver for ELCD LCD modules using Circuits.UART.

This module handles the UART communication protocol for ELCD LCD displays. It implements the command set for controlling LCD operations including initialization, text display, cursor control, and screen management.

UART Protocol

The ELCD modules use a simple UART protocol with the following commands:

  • 0xA0: Initialize display
  • 0xA3, 0x01: Clear display
  • 0xA3, 0x0C: Cursor off
  • 0xA3, 0x0E: Cursor on
  • 0xA1: Move cursor (followed by X, Y coordinates)
  • 0xA2: Print line (followed by text and null terminator)

Error Handling

All functions return either :ok on success or {:error, reason} on failure. Common error scenarios include:

  • UART communication failures
  • Invalid device paths
  • Hardware not responding

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears the LCD display.

Turns the cursor off.

Turns the cursor on.

Moves the cursor to the specified position.

Displays text on the LCD with various options.

Starts the LCD driver process.

Stops the driver and closes the UART connection.

Types

t()

@type t() :: pid()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(pid)

@spec clear(t()) :: :ok | {:error, term()}

Clears the LCD display.

cursor_off(pid)

@spec cursor_off(t()) :: :ok | {:error, term()}

Turns the cursor off.

cursor_on(pid)

@spec cursor_on(t()) :: :ok | {:error, term()}

Turns the cursor on.

move(pid, column, line)

@spec move(t(), non_neg_integer(), non_neg_integer()) :: :ok | {:error, term()}

Moves the cursor to the specified position.

Parameters

  • pid: Driver process
  • column: Column position (0-based)
  • line: Line position (0-based)

print(pid, text, opts \\ [])

@spec print(t(), String.t(), keyword()) :: :ok | {:error, term()}

Displays text on the LCD with various options.

Parameters

  • pid: Driver process
  • text: Text to display
  • opts: Display options
    • :show_cursor - Show cursor (default: false)
    • :scroll - Enable scrolling for long text (default: true)

start_link(device, opts \\ [])

@spec start_link(
  String.t(),
  keyword()
) :: {:ok, t()} | {:error, term()}

Starts the LCD driver process.

Parameters

  • device: UART device path
  • opts: Configuration options
    • :speed - UART baud rate (default: 19200)
    • :lines - Number of display lines (default: 2)
    • :columns - Number of display columns (default: 16)

Returns

{:ok, pid} on success, {:error, reason} on failure.

stop(pid)

@spec stop(t()) :: :ok

Stops the driver and closes the UART connection.