tools (0.3.0-rc.0)
Published 2026-07-08 22:05:27 +00:00 by faicel
Installation
[registries.forgejo]
index = "sparse+ " # Sparse index
# index = " " # Git
[net]
git-fetch-with-cli = truecargo add tools@0.3.0-rc.0 --registry forgejoAbout 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/ # SPI register I/O (embedded-hal)
│ ├── bus.rs # CS timing and raw transfers
│ ├── msb_flag.rs # Legacy MSB read/write flag protocol
│ └── st_mems.rs # STMicro MEMS SPI framing
├── 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 aheapless::String<17>with a colon-separated MAC. - Compression:
compression::compress(msg, &mut out)/compression::decompress(&input, &mut out)— both returnResult<usize, compression::CompressionError>.compressreturnsNoSizeReductionwhen the compressed length is not strictly smaller than the input. - 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(...)(legacy MSB-flag protocol). For STMicro MEMS sensors (LIS2DH12, LIS3DH), useregister::st_mems::{read_register, write_register, read_registers}.
Requirements
- Rust (edition 2021),
no_std. - Dependencies:
embedded-hal1.x,chacha20poly1305(heapless),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.9.2 |
| lzss | ^0.9.1 |
| embedded-hal-mock | ^0.11.1 |
| futures | ^0.3.32 |
Details
2026-07-08 22:05:27 +00:00
Assets (1)
Versions (2)
View all
Cargo
17
18 KiB
tools-0.3.0-rc.0.crate
18 KiB
0.3.0-rc.0
2026-07-08
0.2.0-rc.1
2026-04-05