# xelp C++ example: ESP-IDF (any ESP32 target) Pure ESP-IDF: one FreeRTOS task (`app_main`) owns the console and reads UART0 with the IDF UART driver. The commands come from `commands.cpp`, which is byte-identical in every example under `examples/cpp/`. ## What to copy The whole `esp-idf` folder. `main/idf_component.yml` takes xelp from this checkout by path; in your own project depend on the registry package instead (`deftio/xelp`), as the file shows. ## What to change Every line you may need to change is marked `PORT:` in the platform file: The UART number and driver setup, the `Port` struct, and the GPIO map in `led_set()`. Nothing outside the platform file needs to change. ## Build ```bash idf.py set-target esp32s3 # your chip idf.py build flash monitor ``` ## What you should see Type a few commands; the session looks like this (`make validate` checks the same commands on the host): ``` xelp>info xelp 0.4.0 xelp>led 0 on led 0 on xelp>num 0x7f 127 0x7f xelp>bogus unknown command: bogus xelp>help xelp example -- type help CLI functions info library version led led <n> on|off num num <n> -- decimal and hex echo echo <args...> help list commands xelp> ``` ## Rules These are in the code where they apply; they are what "holding it right" means: * **One owner** - one task or loop makes every call on a console (`parseKey`, `run`, configuration). Input from an interrupt or another task goes to the owner through a queue or ring buffer. * **Init first** - `init()` (or `begin()` on Arduino) resets everything, including the application pointer, so attach context with `setAppPtr()` after it. * **Long-lived context** - whatever `setAppPtr()` points at must outlive the console: static or global, never a local that goes out of scope. * **Commands stay portable** - put commands in `commands.cpp` as plain functions taking `XelpCLI&`, and they build unchanged on every platform. Platform code stays in the platform file.
To create a project from this example, run:
idf.py create-project-from-example "deftio/xelp=0.4.1:cpp/esp-idf"