tools (0.1.0)

Published 2026-03-07 21:00:17 +00:00 by faicel

Installation

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add tools@0.1.0 --registry forgejo

About this package

tools

no_std embedded utilities: encryption, MAC address generation, entropy/random, SPI register I/O, LZSS compression, and PWM RGB LED control.

Features

Each feature can be enabled independently in Cargo.toml:

Feature Description
encryption ChaCha20-Poly1305 encryption (controller and helpers).
mac Pseudo-random MAC address generation from a 16-byte UID.
random Entropy trait and byte generation from a hardware entropy source.
register SPI register read/write helpers (with chip-select and delay).
compression LZSS compress/decompress using stack-based buffers.
rgb PWM-driven RGB LED controller (duty-cycle setter + delay, active-high/low).

Default features: none. Enable what you need. From the Forgejo registry:

[dependencies]
tools = { version = "0.1", registry = "forgejo", features = ["encryption", "mac", "compression"] }

Configure the Forgejo registry in your project (e.g. .cargo/config.toml):

[registries.forgejo]
index = "sparse+https://code.bhk-itsolutions.com/api/packages/homeiot/cargo/"

Use your instance URL and index path if different. A token (e.g. CARGO_REGISTRIES_FORGEJO_TOKEN) is required for private registries.

Project structure

src/
├── lib.rs           # Feature-gated module re-exports
├── register.rs      # SPI register read/write (embedded-hal)
├── encryption/      # ChaCha20-Poly1305 (feature "encryption")
├── mac/             # MAC address from UID (feature "mac")
├── random/          # Entropy trait (feature "random")
├── compression/    # LZSS (feature "compression")
└── rgb/             # PWM RGB LED (feature "rgb")

Usage examples

  • MAC: mac::format_mac_from_uid(uid) returns a heapless::String<17> with a colon-separated MAC.
  • Compression: compression::compress(msg, &mut out) / compression::decompress(&input, &mut out).
  • RGB: RgbPwm::new(set_rgb, delay, max_duty, active_low) then .set_color(Color::Green) etc.
  • Register: register::write_register(spi, cs, addr, value, delay) / read_register(...).

Requirements

  • Rust (edition 2021), no_std.
  • Dependencies: embedded-hal 1.x, chacha20poly1305 (heapless), ufmt, lzss, heapless.

Tests

Run tests with the main features:

./scripts/test.sh

Or:

cargo test --features encryption,mac,compression

Status

Work in progress. API may change.

License

Personal Use Only — Non-Commercial. See LICENSE.

Dependencies

ID Version
chacha20poly1305 ^0.10.1
embedded-hal ^1.0.0
heapless ^0.8
lzss ^0.9.1
ufmt ^0.2.0
embedded-hal-mock ^0.11.1
futures ^0.3
Details
Cargo
2026-03-07 21:00:17 +00:00
56
14 KiB
Assets (1)
Versions (1) View all
0.1.0 2026-03-07