NanoKVMGo.Display (nano_kvm_go v0.4.0)

Copy Markdown View Source

The NanoKVM-Go's LCD: 240 × 284 pixels in portrait, through the Linux framebuffer of its panel. The panel hides the last 14 rows: 240 × 270 of them show. Its light is NanoKVMGo.Backlight.

alias NanoKVMGo.Display.Canvas

{:ok, %{width: width, height: height}} = NanoKVMGo.Display.info()

Canvas.new(width, height, Canvas.rgb(0, 0, 0))
|> Canvas.text(8, 8, "Hello", Canvas.rgb(255, 255, 255), scale: 2)
|> NanoKVMGo.Display.show()

NanoKVMGo.Display.fill(100, 100, 8, 8, Canvas.rgb(255, 0, 0))

show/2 writes only the rows that differ from what the framebuffer holds, and the kernel sends only those to the panel: showing the same picture again costs little, and puts back what something else drew over it, such as the kernel's console. Without the framebuffer (no panel, or a system without the driver) the calls return an error. The framebuffer is looked for when first needed, and again after a write fails: the display carries on when the panel's driver loads late or probes again.

Options

  • :name - the name to register, NanoKVMGo.Display by default
  • :framebuffer - the framebuffer's sysfs directory, by default the one of the panel's driver (panel-mipi-dbi)
  • :root - the root of the file system with sysfs and the device nodes, "/" by default

Summary

Functions

Returns a specification to start this module under a supervisor.

Fills a rectangle with a colour and leaves the rest of the picture: quicker than showing a whole one for a small change. What falls outside the display is left out.

The size of the display in pixels, and of a row in bytes.

Shows a picture: a NanoKVMGo.Display.Canvas the size of the display, or rows of little-endian RGB565 pixels. Only the rows that differ from the framebuffer are written.

Starts the process. See the module documentation for the options.

Types

info()

@type info() :: %{width: pos_integer(), height: pos_integer(), stride: pos_integer()}

option()

@type option() ::
  {:name, GenServer.name()} | {:framebuffer, Path.t() | nil} | {:root, Path.t()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fill(server \\ __MODULE__, x, y, width, height, color)

Fills a rectangle with a colour and leaves the rest of the picture: quicker than showing a whole one for a small change. What falls outside the display is left out.

info(server \\ __MODULE__)

@spec info(GenServer.server()) :: {:ok, info()} | {:error, term()}

The size of the display in pixels, and of a row in bytes.

show(server \\ __MODULE__, picture)

@spec show(GenServer.server(), NanoKVMGo.Display.Canvas.t() | binary()) ::
  :ok | {:error, term()}

Shows a picture: a NanoKVMGo.Display.Canvas the size of the display, or rows of little-endian RGB565 pixels. Only the rows that differ from the framebuffer are written.

start_link(opts \\ [])

@spec start_link([option()]) :: GenServer.on_start()

Starts the process. See the module documentation for the options.