Skip to content

Latest commit

 

History

History
88 lines (63 loc) · 6.78 KB

index.md

File metadata and controls

88 lines (63 loc) · 6.78 KB
title API Reference
description Every component an app links against: the umbrella header, the singleton accessors, and the per-component pages.

API Reference

The SDK exposes the PocketMage hardware and OS services to loaded apps through a set of component objects plus free functions. Every component is declared in pocketmage.h, the umbrella header an app includes first:

#include <pocketmage.h>

pocketmage.h pulls in every component header, config.h, the frames and assets modules, and Preferences.h. It also includes pocketmage_app_version.h when the build defines PM_TARGET_APP, so the SDK-version macros are always available to apps.

An external app does not call these C++ classes directly across the ELF boundary; it calls the flat pm_* C ABI that projects them. See The C ABI (pm_*) below, and the complete function index for every wrapper and its signature.

Compile target

config.h requires exactly one of these to be defined, and fails the build otherwise:

Macro Meaning
PM_TARGET_HOST the PocketMageOS firmware links the SDK in-process
PM_TARGET_APP an external app compiled to a loadable .app.elf

The two are mutually exclusive; defining both is a build error. Apps declare PM_TARGET_APP (see Building an app).

The singleton pattern

Most components are owned by a single global instance created inside the SDK and reached through a global accessor function. The accessor returns a reference; null checks are unnecessary once the component's setup*() call has run in PocketMage_INIT().

Component Accessor Hardware / role API page
OLED OLED() 256x32 SSD1326 OLED, status line oled
E-Ink EINK() 320x240 GDEQ031T10 panel, full-page rendering eink
Font FontEngine unified text on both displays font
Layout (free) display geometry constants, text fit helpers layout
UI helpers (free) status bars, list rows, chips ui
SD card PM_SDAUTO() files, metadata, dos/flash filesystem sd
Keyboard KB() TCA8418 matrix + USB HID kb
Touch TOUCH() MPR121 slider, scroll gestures touch
Buzzer BZ() PWM buzzer, jingles bz
Clock CLOCK() PCF8563 RTC, timeout bookkeeping clock
WiFi P_WIFI station radio service (apps may call) wifi
System (free) init, CPU speed, deep sleep sys
I18n I18n language tables, command normalization i18n-runtime
Text utils (free) string split/join/parse helpers io
Frames Frame e-ink text/bitmap frame model, scrolling frames
Assets (free) PROGMEM bitmaps: battery, sleep, screensavers assets
Config (free) pins, counters, prefs, SDK version stamping configuration

The frames component is used by the OS's built-in apps. Third-party apps start from the simpler primitives in oled, eink, font, and layout.

The C ABI (pm_*)

The accessors and classes above are the host-side API. The SDK compiles the firmware with the C++ API directly, but an external ELF app cannot: it links -nostdlib and resolves symbols by name at load time, so the app-facing surface is a flat C ABI, the pm_* functions, generated from the C++ classes by tools/gen_app_api.py. An app includes the generated header through pm_app_api.h:

#include <pm_app_api.h>

The generator projects each exported C++ method to one C function by a fixed set of rules:

C++ shape C projection
ClassName::method(args) pm_<module>_<method>(args) on the module's singleton
String parameter or return const char* (returns point into the string pool, below)
enum parameter or return plain int (values in SDK declaration order)
std::vector<T> return a _count function plus a _get(index, out, out_size) pair
scalar out-parameter by reference T* out-pointer

Enums become integers with generated value tables: pm_target, pm_style, pm_lang, pm_refresh, and pm_jingle. PM_APP_API_ABI tracks incompatible changes to this surface; an app compares it against pm_app_abi() at startup, and pocketmage_sdk_version (via pm_host_sdk_version()) gives the running host's SDK version.

Every const char* return points into a shared rotating string pool: four 256-byte slots, where the fifth string-returning call overwrites the first. Copy a returned string before making further SDK calls if you need to keep it. Functions that can return arbitrary length write into a caller-owned buffer instead. The full rule and the per-function list are in the function index.

The pm_* names are the app's real dependency contract and are gated at load time against the curated host surface; see symbols.md. Each component page below documents its pm_* wrappers alongside the C++ class they project.

Reading a component page

Every API page follows the same shape:

  • Access: how the object is reached and what to include.
  • Lifecycle: the setup*() call in PocketMage_INIT() that must run first, and how the component behaves across deep sleep and app load.
  • Reference: one section per class or function. Signatures are verbatim from the headers; notes state runtime behavior, threading constraints, and return values.
  • Example: a minimal snippet, usually drawing to one of the two displays.

Threading notes matter: the E-Ink panel is guarded by a recursive mutex and refreshed from a background task; code running in other tasks must take the