How theees/crossink works
Purpose and Entrypoints
CrossInk is C++ firmware for Xteink X3/X4 e-ink readers, targeting ESP32-C3 and emphasizing custom typography, EPUB/TXT/XTC reading, and lightweight reading statistics. PlatformIO builds hardware variants; src/main.cpp is the firmware entry point. A separate SDL2-oriented simulator integration is exposed through include/SimulatorDisplay.h and src/simulator/SimulatorSmokeTest.cpp.
Application Lifecycle and UI
The application is organized as stack-like activities managed centrally by src/activities/ActivityManager.cpp and the Activity abstraction in src/activities/Activity.h. Boot/sleep, home/file browsing, settings, network, and reader flows are distinct activity families under src/activities/. Rendering ownership is protected at the activity boundary by src/activities/RenderLock.h, while reusable visual themes live in src/components/themes/BaseTheme.cpp.
Reading Pipeline
Reader activities select a format-specific reader: EPUB, plain text, or XTC, represented by src/activities/reader/EpubReaderActivity.cpp, src/activities/reader/TxtReaderActivity.cpp, and src/activities/reader/XtcReaderActivity.cpp. EPUB processing opens ZIP-contained package data, parses container/OPF/TOC and chapter HTML/CSS, then produces pages and blocks for display. Core boundaries are lib/Epub/Epub.cpp, lib/Epub/Epub/parsers/ContentOpfParser.cpp, and lib/Epub/Epub/Page.cpp.
Text Layout, Fonts, and Display
EPUB text is represented as parsed text and styled blocks, then laid out with language-aware hyphenation and rendered through the graphics layer. Key components are lib/Epub/Epub/ParsedText.cpp, lib/Epub/Epub/hyphenation/Hyphenator.cpp, and lib/GfxRenderer/GfxRenderer.cpp. Font access is isolated in lib/EpdFont/EpdFont.cpp; built-in compressed font assets are compiled from lib/EpdFont/builtinFonts/, while SD-card font discovery/loading is handled by lib/EpdFont/SdCardFontManager.cpp. Hardware-facing display calls pass through lib/hal/HalDisplay.h.
Persistent Device and Book State
Settings, bookmarks, clippings, recent books, credentials, and reading state are persisted primarily on the SD card rather than retained in constrained ESP32 RAM. Main application stores include src/CrossPointSettings.cpp, src/BookmarkStore.cpp, and src/RecentBooksStore.cpp; generic persistence is provided by lib/Serialization/PersistableStore.cpp. Book indexing and file operations are separated into lib/FileIndex/FileIndex.cpp and lib/FsHelpers/FsHelpers.cpp. Memory-sensitive code uses dedicated arena/scratch abstractions in lib/Memory/Arena.h and lib/Memory/ScratchWorkspace.cpp.
Networking, Transfer, and Synchronization
Wi-Fi-facing activities coordinate device network modes and user flows, including src/activities/network/CrossPointWebServerActivity.cpp and src/activities/network/CalibreConnectActivity.cpp. The firmware provides an embedded web server and WebDAV-oriented file transfer through src/network/CrossPointWebServer.cpp and src/network/WebDAVHandler.cpp; its static UI is sourced from web/pages/. OTA firmware downloads/flashing are separated into src/network/OtaUpdater.cpp and src/network/FirmwareFlasher.cpp. External content/sync boundaries include OPDS parsing (lib/OpdsParser/OpdsParser.cpp) and KOReader progress synchronization (lib/KOReaderSync/KOReaderSyncClient.cpp).
Platform Boundaries and Dependencies
Platform-specific concerns are behind HAL interfaces for storage, GPIO, SPI, power, clock, tilt sensing, and system functions, e.g. lib/hal/HalStorage.h, lib/hal/HalPowerManager.h, and lib/hal/HalSystem.h. The codebase embeds XML and deflate implementations in lib/expat/ and lib/uzlib/, which support EPUB/XML and compressed content handling. Build partitioning and target configuration are defined by platformio.ini and partitions.csv.
Main entry points: ActivityManager.cpp Activity manager · HalStorage.h Storage HAL · Activity.h Activity boundary · EpubReaderActivity.cpp Format reader activities
Components 24
Application
Firmware lifecycle and activity-driven UI.
- Firmware entry
src/main.cpp - Activity manager · Manages stack-like application activities.
src/activities/ActivityManager.cpp - Activity boundary · Owns activity lifecycle and rendering boundary.
src/activities/Activity.h - Render lock
src/activities/RenderLock.h - Base theme
src/components/themes/BaseTheme.cpp
Reading & Rendering
Format readers, EPUB layout, fonts, and display output.
- Format reader activities · Select EPUB, TXT, or XTC reading flows.
src/activities/reader/EpubReaderActivity.cpp - EPUB engine · Opens ZIP-contained EPUB package content.
lib/Epub/Epub.cpp - OPF and TOC parser
lib/Epub/Epub/parsers/ContentOpfParser.cpp - Parsed text blocks · Parsed HTML/CSS text representation for layout.
lib/Epub/Epub/ParsedText.cpp - Page layout
lib/Epub/Epub/Page.cpp - Hyphenator · Provides language-aware line breaking.
lib/Epub/Epub/hyphenation/Hyphenator.cpp - Graphics renderer
lib/GfxRenderer/GfxRenderer.cpp - Font subsystem · Uses built-in assets and SD-discovered fonts.
lib/EpdFont/EpdFont.cpp
Device State
SD-backed settings and book state.
- Application stores · Settings, bookmarks, and recent-book state.
src/CrossPointSettings.cpp - Persistable store
lib/Serialization/PersistableStore.cpp - Book index
lib/FileIndex/FileIndex.cpp
Network & Sync
Device transfer, update, and external synchronization.
- Embedded web server · Serves the static UI and WebDAV transfer.
src/network/CrossPointWebServer.cpp - WebDAV handler
src/network/WebDAVHandler.cpp - OTA updater · Downloads updates for flashing.
src/network/OtaUpdater.cpp - Firmware flasher
src/network/FirmwareFlasher.cpp - OPDS and KOReader sync · Catalog parsing and reading-progress synchronization.
lib/KOReaderSync/KOReaderSyncClient.cpp
Platform & Build
Hardware abstractions and target configuration.
- Display HAL
lib/hal/HalDisplay.h - Storage HAL · SD-card storage boundary.
lib/hal/HalStorage.h - PlatformIO targets · Defines ESP32-C3 hardware variants and partitions.
platformio.ini
Connections 26
- Firmware entry → Activity manager: starts
- Activity manager → Activity boundary: manages
- Activity boundary → Render lock: guards rendering
- Activity boundary → Base theme: applies
- Activity manager → Format reader activities: pushes
- Format reader activities → EPUB engine: opens EPUB
- EPUB engine → OPF and TOC parser: parses package
- EPUB engine → Parsed text blocks: parses chapters
- Parsed text blocks → Page layout: lays out
- Hyphenator → Page layout: breaks words
- Page layout → Graphics renderer: renders pages
- Font subsystem → Graphics renderer: supplies glyphs
- Graphics renderer → Display HAL: draws through
- Activity manager → Application stores: reads and updates
- Application stores → Persistable store: serializes with
- Persistable store → Storage HAL: persists to
- Book index → Storage HAL: indexes files
- Format reader activities → Book index: selects books
- Activity manager → Embedded web server: network activity controls
- Embedded web server → WebDAV handler: routes transfers
- WebDAV handler → Storage HAL: reads and writes
- OTA updater → Firmware flasher: hands off image
- Firmware flasher → Storage HAL: uses firmware storage
- Activity manager → OPDS and KOReader sync: initiates sync
- OPDS and KOReader sync → Application stores: updates progress
- PlatformIO targets → Firmware entry: builds target