Skip to main content

Crate kobo_core

Crate kobo_core 

Source
Expand description

§kobo-core

crates.io documentation license

A reusable Kobo e-reader device SDK for Rust. Provides hardware abstractions, rendering primitives, audio infrastructure, and EPUB parsing for any Kobo e-ink application.

Part of the KoThok e-reader ecosystem:

RepoRole
KoThok (EReader)E-reader app built on kobo-core
kobo-core (this)Device SDK (framebuffer, touch, audio, EPUB)
kothok-edge-ttsEdge TTS client (re-exported via the audio feature)

§Architecture

flowchart TD
    APP["Your Kobo app"]

    subgraph SDK["kobo-core"]
        DEV["device<br/>framebuffer, touch, power, BT, WiFi"]
        REND["rendering<br/>text, fonts, e-ink waveforms"]
        AUD["audio<br/>A2DP sink, MP3, TTS"]
        READ["formats<br/>EPUB parser"]
        UTIL["utilities<br/>HTML text, clock, capabilities"]
    end

    APP --> DEV
    APP --> REND
    APP --> AUD
    APP --> READ
    APP --> UTIL

    style APP fill:#dbeafe,stroke:#2563eb,stroke-width:2px
    style SDK fill:#dcfce7,stroke:#16a34a

Four feature-gated modules, pick what you need:

ModuleFeatureWhat it provides
devicedeviceFramebuffer + e-ink refresh, touch input, power button, frontlight, wakelocks, battery, WiFi, Bluetooth, device detection
renderingrenderingText engine (HarfBuzz + fontdue), e-ink waveform constants, dirty-region diffing, image decode (PNG/JPEG/GIF/BMP)
audioaudioA2DP sink, PCM player with paced writes, MP3 decode + resample, TTS synthesis orchestration (re-exports kothok-edge-tts; TTS needs WiFi)
formatsreaderEPUB parsing: chapter extraction, cover image, metadata

All enabled by default. Disable what you don’t need:

# A music player: device + audio only
kobo-core = { version = "0.2", default-features = false, features = ["device", "audio"] }

§Install

cargo add kobo-core

§Quick start

use kobo_core::device;

// Auto-detect which Kobo model is running
let cfg = device::detect::detect_device().expect("unknown Kobo");
println!("{} ({}dpi, {})", cfg.model, cfg.display_dpi, cfg.codename);

// Framebuffer + e-ink refresh
use kobo_core::device::fb::Fb;
use kobo_core::rendering::eink::WAVE_GC16;
if let Some(fb) = Fb::open() {
    let rgb565_bytes = vec![0u8; fb.xres * fb.yres * 2];
    fb.present(&rgb565_bytes, fb.xres, fb.yres, false, 0, fb.yres, WAVE_GC16);
}

// Frontlight brightness
use kobo_core::device::power;
if let Some(path) = power::frontlight_path(&cfg.frontlight) {
    power::frontlight_set(&path, 50);
}

// Battery
let pct = device::battery::battery_pct();
println!("Battery: {pct}%");

§Supported devices

ModelCodenameSoCColorBT
Libra Colourmonza / monzaKoboMTKYesYes
Clara ColourspaColourMTKYesYes
Clara BWspaBW / spaKoboBWMTKNoYes
Elipsa 2EcondorMTKNoYes
SagecadmussunxiNoYes
Libra 2ioNXPNoYes
Clara 2EgoldfinchNXPNoYes
Clara HDnovaNXPNoNo
FormafrostNXPNoNo
Forma 32GBstormNXPNoNo
NialunaNXPNoNo
ElipsaelipsaNXPNoNo
Aura ONEpikaNXPNoNo
Aura H2OdahliaNXPNoNo
Glo HDalyssumNXPNoNo
Aura SEstarNXPNoNo
AurasnowNXPNoNo
Aura HDdragonNXPNoNo
GlokrakenNXPNoNo
MinipixieNXPNoNo
TouchtrilogyNXPNoNo

Device detection is automatic from /sys/devices/soc0/machine (codename).

§E-ink waveforms

use kobo_core::rendering::eink;

// Pick the right waveform for each scenario
let transition = eink::waveform_for(eink::RenderScenario::Transition); // GL16
let content    = eink::waveform_for(eink::RenderScenario::Content);    // GL16
let animation  = eink::waveform_for(eink::RenderScenario::Animation);  // A2
ConstantValueUse case
WAVE_INIT0Boot/clear
WAVE_DU1Fast monochrome
WAVE_GC162Full grayscale clearing
WAVE_GL163Partial updates, less ghosting
WAVE_A24Animation (fastest, monochrome)
WAVE_GLR165MTK color optimized
WAVE_GLD166MTK color dark

§API reference

Complete alphabetical list of major public exports.

NameKindModuleDescription
battery_pctfndevice::batteryBattery percentage (0-100)
CapabilitiestraitcapabilitiesQuery WiFi/BT/battery/clock state
ChapterstructformatsEPUB chapter: title, XHTML content
decode_imagefnrendering::text_renderDecode PNG/JPEG/GIF/BMP to RGB565
detect_scriptfnrendering::text_renderDetect text script (Latin, Arabic, Bengali, CJK, etc.)
detect_devicefndevice::detectAuto-detect Kobo model from sysfs
DeviceConfigstructdevice::configModel name, codename, DPI, SoC, touch protocol
diff_rowsfnrendering::einkCompare two buffers, return dirty row range
EpubBookstructformatsParsed EPUB: chapters, cover, metadata
Fbstructdevice::fbFramebuffer mmap + e-ink refresh ioctl
frontlight_getfndevice::powerRead current brightness (returns Option<u32>)
frontlight_pathfndevice::powerLocate frontlight sysfs path from FrontlightConfig
frontlight_setfndevice::powerSet brightness (0-100)
init_tlsfnaudioInstall rustls crypto provider (for TTS)
install_fontfnrendering::text_render::fontsRegister a font for a script
MockCapabilitiesstructcapabilitiesTest mock for Capabilities trait
Playerstructaudio::playerA2DP PCM player with paced writes
Preparedstructaudio::playerDecoded PCM + word boundaries
set_rtl / is_rtlfnrendering::commonSet/read RTL text direction flag
slice_as_bytesfnrendering::commonReinterpret slice as &[u8] (generic)
synthesize_preparedfnaudio::synthTTS synthesis with retry + gap baking
waveform_forfnrendering::einkPick waveform by RenderScenario
wifi_statusfndevice::wifiCheck if WiFi is connected
wifi_togglefndevice::wifiTurn WiFi on/off (manages wpa_supplicant)

§Build

# Native (for tests)
cargo build
cargo test

# Cross-compile for Kobo (armv7)
cross build --target armv7-unknown-linux-musleabihf --release
  • KoThok (EReader): the e-reader app built on this SDK
  • kothok-edge-tts: Microsoft Edge TTS client (re-exported via the audio feature)

§License

MIT

Re-exports§

pub use capabilities::Capabilities;
pub use capabilities::MockCapabilities;
pub use clock::highlight_index;
pub use clock::SharedClock;
pub use formats::epub::Chapter;
pub use formats::epub::EpubBook;
pub use formats::epub::EpubError;
pub use html_text::TextSegment;
pub use html_text::lines;
pub use html_text::lines;
pub use html_text::sentence_index_at;
pub use html_text::Line;
pub use stub_player::StubPlayer;

Modules§

audio
capabilities
Capability detection (plan S5): drives the read-aloud vs plain-reader state machine. MockCapabilities is for the desktop simulator; the real impl (KoboCapabilities) lives in the kobo backend crate (checks network reach
clock
SharedClock - the single playback time source (decision 2).
device
Device module: hardware database, device I/O, and rendering primitives.
formats
Document formats. EPUB is the MVP format (PDF deferred - plan S8).
html_text
Chapter XHTML -> plain text + a char-offset->element map.
logger
rendering
Rendering primitives: text engine, UI draw helpers, e-ink constants.
stub_player
StubPlayer - a headless stub proving the control + shared-clock + highlight loop (decision 1 multi-thread + decision 2 single clock) WITHOUT real audio or a Slint window. The desktop sim drives it with fake WordMarks; the real Player (kobo-audio) and the real Slint sim reuse the same SharedClock + control pattern once a build env with cc/display is available.