Rust implementation of ESP32 NVS partition generator.

Overview

Simple ESP32 NVS writer library for Rust

Overview

A library for Rust to generate NVS partitions for ESP32.

How to use

See examples/write_simple.rs.

  1. Make NvsPartition by calling NvsPartition::new
  2. call NvsPartition::add_primitive_entry to add primitive (u8, i8, u16, i16, u32, i32, u64, i64) values. Both namespace and key are must be represented by NvsKey type. (NvsKey is just a type alias of heapless::String<15>, because ESP32 NVS supports 15 + 1 (null terminator) string for namespace and key.)
  3. call NvsPartition::add_string_entry to add string values.
  4. call NvsPartition::add_binary_entry to add BLOBs.
  5. call NvsPartition::write to write out the NVS partition content to a file.
use esp32_nvs::{NvsKey, NvsPartition};
use std::{fs::File, io::*, str::FromStr};

fn main() -> Result<()> {
    let mut file = File::create("output.bin")?;
    let mut partition: NvsPartition = NvsPartition::new();
    let namespace = NvsKey::from_str("hoge").unwrap();
    let mut long_data = [0u8; 4097];
    for i in 0..long_data.len() {
        long_data[i] = (i & 0xff) as u8;
    }
    let mut long_string = String::with_capacity((126 - 10 - 1) * 32 - 1);
    for i in 0..long_string.capacity() {
        long_string.push(char::from_u32(0x20 + (i % 0x40) as u32).unwrap());
    }
    partition.add_primitive_entry(
        &namespace,
        &NvsKey::from_str("fuga").unwrap(),
        0xdeadbeefu32,
    );
    partition
        .add_string_entry(
            &namespace,
            &NvsKey::from_str("long_value").unwrap(),
            "string",
        )
        .unwrap();
    partition
        .add_binary_entry(
            &namespace,
            &NvsKey::from_str("long_long_value").unwrap(),
            &long_data,
        )
        .unwrap();
    partition
        .add_string_entry(
            &namespace,
            &NvsKey::from_str("long_str").unwrap(),
            &long_string,
        )
        .unwrap();
    partition
        .add_string_entry(
            &namespace,
            &NvsKey::from_str("long_str2").unwrap(),
            &long_string,
        )
        .unwrap();
    partition.write(&mut file)?;

    Ok(())
}

License

This library is available under the MIT License. See also LICENSE file.

You might also like...
kindly is a simple Rust implementation of a set-user-ID-root program, similar to sudo but in a much reduced way.

kindly is a simple Rust implementation of a set-user-ID-root program, similar to sudo but in a much reduced way.

An implementation of Joker Calculus in Rust

Joker Calculus An implementation of Joker Calculus in Rust Based on paper Joker Calculus, by Daniel Fischer, William Alexander Morris and Sven Nilsen

dustls, a pure-rust DTLS implementation

dustls, a pure-rust DTLS implementation A DTLSv1.2 implementation in Rust, reusing rustls for cryptographic primitives and most message payload format

Mild RSA implementation written in Rust for a class.

rust_rsa About this repo This is my Rust implementation of the RSA encryption standard, based on this book. This is for my CS 3000 - Advanced Algorith

A clean implementation of Reso using Rust.

A clean implementation of Reso using Rust. The principle of Reso Rust is almost identical to Reso, only missing some functionality

An experimental implementation of gitbom in Rust

gitbom-rs "An experimental implementation of GitBOM in Rust" NOTICE: This project is still a work in progress and is not ready for any use beyond expe

Rust implementation for parsing StarCraft .chk files.

bwmap Rust implementation for parsing StarCraft .chk files. bounding.net uses this library to parse StarCraft and StarCraft: Brood War maps and store

rlox-interpreter is an AST-walking implementation of Bob Nystrom's Lox language in Rust.

rlox-interpreter rlox-interpreter is an AST-walking implementation of Bob Nystrom's Lox language in Rust. Disclaimer: This is my first Rust project, d

Rust implementation for Wlroots (Sway, Wayfire, Hikari, River, etc.) of Gnome Screenshot and Idle DBUS Server, which Upwork uses to capture the screen as proof of work.

🚀 upwork-wlroots-bridge 🚀 Rust Implementation for Wlroots (Sway, Wayfire, Hikari, River, etc.) of Gnome Screenshot and Idle DBUS Server (with extra

Owner
Kenta IDA
Kenta IDA
A library for parsing and generating ESP-IDF partition tables

esp-idf-part A library for parsing and generating ESP-IDF partition tables. Supports parsing from and generating to both CSV and binary formats. This

esp-rs 5 Nov 16, 2022
ESP32-C3 interfacing to a PS/2 Keyboard (bare-metal Rust)

ESP32-C3 interfacing to a PS/2 Keyboard (bare-metal Rust) Very simplified example of connecting a PS/2 keyboard to ESP32-C3 You need to build it with

Björn Quentin 3 Dec 5, 2022
Example of reading the BME280 sensor on an ESP32-C3 using Rust

Rust ESP32-C3 BME280 Example of reading the BME280 sensor on an ESP32-C3 using Rust Hardware: ESP32-C3 microcontroller BME280 sensor Breadboard Jump w

Wei-ying Chen 21 Mar 9, 2024
Esp-backtrace - backtrace for ESP32 bare-metal

esp-backtrace - backtrace for ESP32 bare-metal supports ESP32, ESP32C3, ESP32S2, ESP32S3 optional features: panic-handler, exception-handler (will ena

Björn Quentin 10 Dec 14, 2022
Backtrace for ESP32 bare-metal

esp-backtrace - backtrace for ESP32 bare-metal supports ESP32, ESP32C3, ESP32S2, ESP32S3 optional features: panic-handler, exception-handler (will ena

esp-rs 10 Dec 14, 2022
Demo of tokio running on esp32 using esp-idf

Tokio running on esp32! This repo demonstrates a working hello world utilizing upstreamed tokio support for esp32. The tokio executor and I/O reactor

Josh Guilfoyle 9 Aug 7, 2023
Embedded demo based on esp32-c3

wot-esp-demo Demo Hygro-Thermometer based on the esp-rust-board. http version based on std-training Deploy Rust prerequisites Install espflash, ldprox

null 3 Dec 1, 2023
Rust ABI safe code generator

CGlue offers an easy way to ABI (application binary interface) safety. Just a few annotations and your trait is ready to go!

Auri 142 Jan 2, 2023
The official rust implementation of the SpamProtectionBot API

SpamProtection-rs Table of contents About Supported Rust version Features How to use Credits License About SpamProtection-Rust is a Rust wrapper for I

Intellivoid 0 Feb 26, 2022
RusTiny -- A Rust implementation of Tiny+ language

RusTiny -- A Rust implementation of Tiny+ language 编译器实践 基本要求: 参考《编译原理及实践》的TINY语言编译器(已上传到群中)完成TINY+ 语言(见附录 A)的解释器:即给定满足 TINY+语言的源代码输入,你的解 释器可以给出对其的解释执

M4tsuri 2 May 22, 2022