Firmware

The firmware application is written in asynchronous Rust (no_std) using esp-hal along with some ancillary crates.

Prerequisites

To build and upload the firmware to your device, ensure you have the following installed:

  • Rust: See installation for details
  • The stable toolchain with the ESP32-C3 target architecture installed:
    rustup toolchain install stable --component rust-src --target riscv32imc-unknown-none-elf
    
  • probe-rs installed, see instructions

How to Build

To build the firmware, run:

cargo build --release

To build and upload the firmware to your device, refer to the Build and Flash your Device section.

How to Flash your Device

Build and Flash your Device

Since we've set a custom runner in the .cargo/config.toml, you can build and upload the resulting binary to your target using:

cargo run --release

This will also open a serial monitor, allowing you to view log messages in real time.

To modify the log level, update the DEFMT_LOG value in .cargo/config.toml or set it when running the command:

DEFMT_LOG=debug cargo run --release

Flashing From Your Browser

This method does not require any of the Prerequisites, but also it does not allow modifying the code. Instead, it only allows flashing a released firmware version.

To flash the released binary using your browser:

  1. Download the binary from the desired GitHub release
  2. Open Adafruit ESPTool
  3. Click Connect and select the serial port of your ESP board (should be named USB/JTAG serial debug unit...)
  4. Upload your .bin file(s) at offset 0x10000
  5. Click Program Flashing with ESPTool

Code Structure

hx711

This module implements the load cell functionality, it's an async version of the loadcell crate with additional modifications.

ble

This module implements the Bluetooth Low Energy (BLE) functionality:

  • Defines the GATT server and services
  • Handles advertising and connections
  • Defines the Progressor service with data point and control point characteristics

progressor

The progressor module implements the Tindeq API, enabling BLE (Bluetooth Low Energy) communication between the ESP32-C3 and a smartphone.

Main Tasks

The main.rs file defines several asynchronous tasks that run concurrently:

  • measurement_task:
    • Initializes the load cell
    • Handles taring and reading measurements from the sensor.
  • ble_task:
    • This is a background task that is required to run forever alongside any other BLE tasks.
  • gatt_events_task:
    • Processes GATT events like control point writes
  • data_processing_task:
    • Handles sending notifications with data points

Communication between tasks occurs via a Channel.