Elcdx.Driver (elcdx v0.1.1)
View SourceLow-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 display0xA3, 0x01: Clear display0xA3, 0x0C: Cursor off0xA3, 0x0E: Cursor on0xA1: 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
@type t() :: pid()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Clears the LCD display.
Turns the cursor off.
Turns the cursor on.
@spec move(t(), non_neg_integer(), non_neg_integer()) :: :ok | {:error, term()}
Moves the cursor to the specified position.
Parameters
pid: Driver processcolumn: Column position (0-based)line: Line position (0-based)
Displays text on the LCD with various options.
Parameters
pid: Driver processtext: Text to displayopts: Display options:show_cursor- Show cursor (default: false):scroll- Enable scrolling for long text (default: true)
Starts the LCD driver process.
Parameters
device: UART device pathopts: 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.
@spec stop(t()) :: :ok
Stops the driver and closes the UART connection.