Skip to content

feat: add LilkaModules library and lilka/config INI module - #40

Merged
black-ghost-off merged 3 commits into
mainfrom
yboichuk/feat/lua_modules
Nov 13, 2026
Merged

black-ghost-off merged 3 commits into
mainfrom
yboichuk/feat/lua_modules

Conversation

@black-ghost-off

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

Copy link
Copy Markdown
Member

Summary

Adds lib/lilka_modules (LilkaModules), a separate PlatformIO library with drivers for the Lilka v2 extension modules. Keira uses it for new Lua modules (gps, can, ir, lora, nrf24, cc1101, imu, mag) — companion PR in lilka-dev/keira.

Module Class Bus
002 IR (KY-005 + KY-022) lilka::mod::Ir, IrCodec (NEC, Samsung, Sony SIRC) RMT
003 LORA (SX1262 / SX1268) lilka::mod::SX126x SPI
004 RF lilka::mod::Nrf24, lilka::mod::Cc1101 SPI
005 GPS (NEO-M8N) lilka::mod::Gps, Nmea UART
006 GYRO MAGNET lilka::mod::Bmi260, lilka::mod::Tmag5273 I2C
008 CAN (SN65HVD232) lilka::mod::Can TWAI

Design:

  • Plain classes, not singletons: modules are optional and plugged in at runtime, nothing starts in lilka::begin().
  • Every pin is a Config field; defaults come from lilka::config (see below) via pins::get(section, key). SPI/I2C drivers take the bus and never start/stop it.
  • lilka::mod::resources tracks pin/peripheral ownership (Keira uses it so an app and a service can't drive the same pins).
  • Nmea and IrCodec have no hardware access and build on a PC.
  • BMI260 config blob from Bosch (BSD-3-Clause, BMI260_CONFIG_LICENSE); passed to the driver as pointer + length, so it can come from flash, a file, or be skipped.

Other changes:

  • config.h: LILKA_EXT_RX / LILKA_EXT_TX (GPIO44/43, header pins 3 and 4).
  • LuaLS stubs for the new Keira Lua modules; serial.begin gets optional rx, tx.
  • releases.yml: version and publish lib/lilka_modules to the registry next to lib/lilka, so Keira can depend on lilka/LilkaModules.

lilka/config (review feedback)

New core module lib/lilka/src/lilka/config/:

  • lilka::IniTable — zero-dependency INI parser (libc only) stored in a hash table (separate chaining, FNV-1a, case-insensitive sections/keys). STL-like accessors: begin()/end() (range-for), find(), has_key(), size(), empty(), plus get(), getInt() (dec/hex), getFloat(), getBool(), set(), erase(). ;/# comments (also inline), quoted values.
  • lilka::config — loads built-in values for LILKA_VERSION == 2 first (generated from the config.h macros: sections ext, gps, can, ir, lora, rf, gyro_magnet), then /sd/.lilka/config/*.ini in alphabetical order; later values override earlier ones. Called from lilka::begin() right after the SD card is mounted (config.reload(); not begin(), which is the iterator). Defaults are also available before begin().
  • Intended to be reused for other per-board settings later.

Examples moved to lilka-dev/examples#6 (lib/lilka_modules/examples removed).

Testing

  • Keira v2 builds against this branch (symlink:// to both libraries); no new warnings; clang-format and cppcheck clean on the new code. The LoRa example in lilka-dev/examples builds too.
  • IniTable unit-tested on the host with ASan/UBSan: comments, quotes, case-insensitivity, overrides, find/erase, growth to 1000 keys, range-for, over-long lines, and parsing the built-in v2 defaults (35 keys).
  • Nmea and IrCodec unit-tested on the host (multi-constellation GSV, bad checksums; NEC 8/16-bit + repeat, Samsung, Sony 12/15/20 with ±90 µs distortion).
  • Not tested on hardware. SX126x, nRF24 and CC1101 code is ported from the self-tests that passed on the boards (lilka_modules repo); the GPS, IR and CAN boards were never tested on hardware. SX1268 PA settings are from the datasheet. Whether BMI260 data is valid without the config blob is unknown.
  • The registry publish step was not run.

New PlatformIO library lib/lilka_modules with drivers for the Lilka v2
extension modules:

- GPS (NEO-M8N): UART + NMEA parser (GGA, RMC, GSA, GSV)
- CAN (SN65HVD232): TWAI wrapper
- IR (KY-005 + KY-022): RMT TX/RX, NEC / Samsung / Sony SIRC codec
- LORA (SX1262 / SX1268): polled IRQs, TCXO, RF switch
- RF: nRF24L01+ and CC1101
- GYRO MAGNET: BMI260 (optional Bosch config blob) and TMAG5273

Also:
- lilka::mod::resources: pin/peripheral ownership tracking
- LILKA_EXT_RX / LILKA_EXT_TX in config.h (header pins 3 and 4)
- LuaLS stubs for the new Keira Lua modules, serial.begin rx/tx args
- releases.yml publishes lib/lilka_modules to the registry too
@frostmorn

Copy link
Copy Markdown
Collaborator

Examples should be moved to examples repo : https://github.com/lilka-dev/examples

Config for hardware require more scalability: suggested to create lilka/config module which would be able to parse .ini files from /sd/.lilka/config

Requirements: zero dependencies, since ini parsing algorithm have trivial implementation. STL-container like accessors( .begin(), .end(), has_key() ), store in a hashtable form to improve search speed

This module later can be integrated in other lilka-sdk parts, specifically pins config per board.

Provide fallback values for LILKA_VERSION 2.

lilka/config:
- IniTable: zero-dependency INI parser stored in a hash table (chaining,
  FNV-1a, case-insensitive sections/keys) with STL-like accessors:
  begin()/end(), find(), has_key(), size(), empty(), plus typed getters
- lilka::config: built-in hardware values for LILKA_VERSION 2 (from
  config.h macros), then /sd/.lilka/config/*.ini in alphabetical order,
  later values override earlier ones; loaded in lilka::begin() after the
  SD card

LilkaModules:
- driver pin defaults read from lilka::config sections (gps, can, ir,
  lora, rf, gyro_magnet) via pins::get(); compile-time pin constants
  removed
- example moved to lilka-dev/examples
@black-ghost-off black-ghost-off changed the title feat: add LilkaModules library for extension module drivers feat: add LilkaModules library and lilka/config INI module Nov 10, 2026
@frostmorn

Copy link
Copy Markdown
Collaborator

while config is landed, it's still unused by any of modules.
config itself requires operator[] overload as an accessor

@black-ghost-off

Copy link
Copy Markdown
Member Author

@frostmorn Do you want all modules—such as audio, buzzer, battery, etc.—to have this configuration as well?

@frostmorn

Copy link
Copy Markdown
Collaborator

@black-ghost-off yes, it would be convenient for any module in future to use .ini like configuration. this may open us a possibility for hotswap/change configuration later, with .ini files with pinmaps specified by user somewhere on sdcard

@frostmorn

frostmorn commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

so you boot a system, check if .ini hardware files present for initializing specific hardware. also it would allow us to use any pin any other way, removing sdcard would allow to init default state.

this may allow user to configure lilka differently without changing code, firmware, etc.

it sound logical to have that feature in sdk, so would be less boilerplate in custom firmwares. though we can't support aaaall existing hardware, rather supported by lilka-dev, since dependency management part might be nightmare, and let's be real, it's not designed around that idea. but some freedom we can get

@black-ghost-off

Copy link
Copy Markdown
Member Author

I think it out of this scope. It can be in feature PR's. This PR just for one reason, give us support for new LUA modules.

@frostmorn

Copy link
Copy Markdown
Collaborator

for fast feature it works, in general it can be another pr, no problem

@black-ghost-off
black-ghost-off merged commit 24d56c9 into main Nov 13, 2026
3 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