Skip to content

feat: add Lua modules for Lilka v2 extension modules - #155

Merged
black-ghost-off merged 2 commits into
mainfrom
yboichuk/remove/add_lua_modules_for_new_hardware_modules
Nov 16, 2026
Merged

black-ghost-off merged 2 commits into
mainfrom
yboichuk/remove/add_lua_modules_for_new_hardware_modules

Conversation

@black-ghost-off

@black-ghost-off black-ghost-off commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Lua support for the Lilka v2 extension modules, on top of the new LilkaModules SDK library (lilka-dev/sdk#40).

Lua module Hardware
gps 005 GPS (NEO-M8N) — NMEA fix, satellites, UBX
can 008 CAN — send/receive, filters, listen-only, bus status/recovery
ir 002 IR — NEC / Samsung / Sony send & decode, raw learn/replay
lora 003 LORA (SX1262 / SX1268) — send/receive, RSSI/SNR, time on air
nrf24 004 RF nRF24L01+ — pipes, auto-ack, 2.4 GHz channel scan
cc1101 004 RF CC1101 — 2-FSK/GFSK/ASK/4-FSK/MSK, RSSI
imu 006 BMI260 — accel/gyro; config blob built-in, from a file, or off
mag 006 TMAG5273 — field, heading, hard-iron calibration

Every module is an object (local radio = assert(lora.new{...}), then radio:send("hi")). It claims its pins and peripherals through lilka::mod::resources, so a Lua app and a Lua service can't drive the same hardware, and releases them on close(), on __gc/<close>, or when the script ends. new returns nil, error if the module isn't found and frees its pins right away.

Changes to existing bindings:

  • serial.begin(baud, config, rx, tx): optional pins (default stays 47/48, so existing scripts keep working); read(n) is binary-safe; the global HardwareSerial in src/apps is gone.
  • spi.transfer also accepts strings and an optional CS pin; spi, i2c and serial claim their pins/peripherals.
  • Lua apps and services release all claimed hardware on exit.

Pins: default pins (and GPS baud / IR carrier) come from lilka::config (lilka-dev/sdk#40): built-in values for Lilka v2, overridable with INI files in /sd/.lilka/config/ (e.g. [lora] nss = 21). Radio bindings raise a clear error if the board has no pins configured.

Docs: docs/lua/reference/modules.rst plus a page per module with a short snippet; full scripts are in lilka-dev/examples#6 (LUA/modules).

Merge order

Draft until lilka-dev/sdk#40 is merged and released (needs both lilka/LilkaModules and the lilka/config module in lilka/Lilka). platformio.ini now depends on lilka/LilkaModules, which the SDK release workflow will publish; until then the firmware build fails with Could not find the package with 'lilka/LilkaModules'.

Testing

  • v2 builds against the SDK branch with both libraries linked via symlink:// (+36 KB flash for the modules), no new warnings; clang-format and cppcheck clean on the changed files (cppcheck memleak on driver pointers owned by Lua userdata suppressed inline).
  • NMEA parser and IR codec unit-tested on the host.
  • Not tested on hardware, and no Lua script has been run on a device yet. GPS, IR and CAN boards have never been tested on hardware at all. v1 build not checked; the docs build was not run.

New Lua modules backed by the LilkaModules SDK library: gps, can, ir,
lora, nrf24, cc1101, imu and mag. Each is an object created with
X.new{...}; it claims its pins and peripherals, so an app and a service
can't drive the same hardware, and releases them on close() or when the
script ends.

Existing bindings:
- serial.begin(baud, config, rx, tx): optional pins (default 47/48);
  read() is binary-safe; no global HardwareSerial in src/apps
- spi.transfer accepts strings and an optional CS pin
- spi, i2c and serial claim their pins/peripherals
- Lua apps and services release all claimed hardware on exit

Docs: modules overview and a reference page with an example per module.
- lora, nrf24, cc1101, imu, mag, gps take their default pins (and GPS
  baud) from lilka::config, so they can be changed with INI files in
  /sd/.lilka/config; radio bindings report unconfigured pins
- docs: short snippets per module, full scripts now live in
  lilka-dev/examples (LUA/modules); modules page explains the config
@black-ghost-off
black-ghost-off marked this pull request as ready for review November 16, 2026 12:54
@black-ghost-off
black-ghost-off merged commit 7fdebd5 into main Nov 16, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants