# `NanoKVMGo.Display`
[🔗](https://github.com/cocoa-xu/nano_kvm_go/blob/v0.4.0/lib/nano_kvm_go/display.ex#L1)

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

# `info`

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

# `option`

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

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `fill`

```elixir
@spec fill(
  GenServer.server(),
  integer(),
  integer(),
  non_neg_integer(),
  non_neg_integer(),
  NanoKVMGo.Display.Canvas.color()
) :: :ok | {:error, term()}
```

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`

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

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

# `show`

```elixir
@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`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
