C+
Packages · View as Markdown

espidf

C+ bindings for ESP-IDF on the esp32-xtensa target: just enough of the platform for a control loop to drive pins, read the clock, sleep, and print. See Embedded & ESP32 for the bigger picture.

Four modules:

  • espidf/gpioreset, set_direction, set_level, and level, over the role-named Mode (Disable/Input/Output/InputOutput) and Level (Low/High) Copy enums. The mutators return Status; level returns Option[Level], so a bad pin is None, not a -1 sentinel.
  • espidf/timernow_us, the esp_timer clock as i64 microseconds since boot.
  • espidf/taskdelay_ms / delay_us (newlib usleep, so they are tick-rate independent).
  • espidf/logprint_line / print_i32 / print_i64 over the UART.

The gpio and timer externs are #[no_alloc] + #[no_block] leaves, so a #[realtime] control loop can call them and keep its contract. The typed wrappers stay heap-free too: Status, Mode, and Level are payload-free Copy enums, and the log helpers take str but print through the length-aware printf("%.*s", ...) form, so no CString allocation is needed — every wrapper remains usable from #[no_alloc] code, while Text / Vec remain available on the chip's newlib heap when you do want them.

Building and entry point

A consuming package declares espidf = "*" and builds as a [lib] staticlib:

cpc build --target esp32-xtensa

cpc stops at the archive; the ESP-IDF / CMake build links the firmware (the bound symbols live in IDF's driver, esp_timer, and newlib components). The app exports cplus_app_main, and IDF's main component keeps a two-line C shim that calls it from app_main. The full entry convention is on the Embedded & ESP32 page.