Files
eink-api/README.md
2026-01-13 22:04:10 -05:00

70 lines
4.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# eInk API for Raspberry Pi Pico
This firmware drives a Waveshare 4.2" e-Paper display from a Raspberry Pi Pico / Pico W. It launches the e-paper driver on core 1 while core 0 acts as a simple serial command processor, giving you an interactive API for drawing primitives, text, and editor-mode logs over USB.
## Features
- Lightweight C implementation built on the official Pico SDK and Waveshare e-Paper drivers.
- Core 1 renders directly to a framebuffer and updates the display with both full and partial refreshes.
- Serial command queue exposes operations such as clearing, drawing geometry, writing text, and entering an editor mode.
- Automatic display shutdown after 30 seconds of inactivity to preserve the panel.
## Requirements
- Raspberry Pi Pico or Pico W (project sets `PICO_BOARD` to `pico_w`).
- Waveshare 4.2" e-Paper V2 display, wired to SPI + compatible GPIOs defined in `DEV_Config.h`.
- Pico SDK (2.2.0) installed and available via `PICO_SDK_PATH`.
- `cmake`, `ninja`, and `picotool` (or the Pico toolchain) for flashing.
## Building
```sh
# configure the build
cmake -S . -B build
# build the UF2 image
cmake --build build
```
After building, flash the firmware to your Pico (e.g. by copying `build/eink_api.uf2` to the Pico's mass storage device or using `picotool load build/eink_api.uf2`).
### Build/Flash Helper Script
Run `scripts/flash_and_connect.sh [/dev/ttyACM0]` to configure CMake, compile the firmware, optionally flash it with `picotool`, and open a serial session (defaults to `screen` at 115200 baud). Set `PICO_SERIAL` to override the port, `PICO_BAUD` for a different baud rate, and `SERIAL_CLIENT` if you prefer `picocom` or `minicom`. If `picotool` is missing, the script will remind you to copy the UF2 to the board manually.
## Usage
1. Open a serial terminal (115200 baud) over the Pico's USB CDC interface.
2. Type commands followed by `Enter`. The firmware echoes the command buffer and executes the operation on core 1.
3. Most commands require the display to be initialized (`init`). The device automatically turns off the screen after ~30seconds of inactivity, so send another command to revive it.
4. If `editor` mode is enabled, keystrokes are batched and rendered directly on the display until inactivity ends the mode.
### Supported Commands
| Command | Description |
| --- | --- |
| `init` | Initializes the e-Paper panel and allocates the framebuffer. |
| `clear` | Clears the current framebuffer to white (requires display on). |
| `display` | Pushes the framebuffer to the panel (requires display on). |
| `draw_test` | Draws a hard-coded Waveshare demo pattern. |
| `draw_text x y text` | Writes `text` at `(x,y)` using the current font. |
| `draw_text_white x y text` | Writes inverted white text at `(x,y)` with a black background. |
| `draw_point x y` | Draws a black point at the given coordinates. |
| `draw_line x1 y1 x2 y2` | Draws a black line between two points. |
| `draw_sine x y length amplitude frequency` | Draws a sine-wave curve of `length` pixels starting at `(x,y)`, oscillating by `amplitude`, with the given number of cycles. |
| `draw_rectangle x1 y1 x2 y2` | Draws an empty rectangle. |
| `draw_rectangle_fill x1 y1 x2 y2` | Draws a filled rectangle. |
| `draw_circle x y r` | Draws an empty circle with radius `r`. |
| `draw_circle_fill x y r` | Draws a filled circle with radius `r`. |
| `draw_num x y num` | Draws `num` using the default numeric font. |
| `set_pixel x y color` | Sets a single pixel to `color` (0=white, 1=black). |
| `close` | Sends the panel to deep sleep and frees the framebuffer. |
| `editor [0|1]` | Enables editor mode; default uses white background, non-zero switches to white text on black. Press Enter to run typed commands. |
## Notes
- The project imports the Waveshare e-Paper libraries from `Pico_ePaper_Code/c/lib/*` for configuration, fonts, GUI primitives, and the panel driver.
- USB serial I/O is enabled (`pico_enable_stdio_usb`), while UART stdio is disabled to avoid conflicts (`pico_enable_stdio_uart` set to `0`).
- The firmware allocates the framebuffer via `malloc` and frees it when the display goes to sleep; avoid running out of heap on severely constrained Pico builds.
- Editor-mode inactivity is 10 seconds before automatically exiting back to command mode.