convert-sketch

June 21, 2026 · View on GitHub

Converts a Teensyduino sketch into a self-contained teensy-cmake-macros project that cross-compiles with arm-none-eabi-gcc, targeting RT1060-EVKB (default) or Teensy 4.x.

Usage

node bin/convert-sketch.js <input> [options]

<input> is a .ino file, an Arduino sketch folder, or a folder of sketch folders (batch mode).

OptionDefaultMeaning
--out <dir>./<SketchName>-teensyoutput project directory
--board <42|41|40>4242 = RT1060-EVKB, 41 = Teensy 4.1, 40 = Teensy 4.0
--csv <file>header→library override/extension map
--compiler-path <dir>/Applications/ARM_10/bin/arm-none-eabi bin/ dir (trailing slash)
--no-vscode(vscode on)skip .vscode/ generation
--forceoffoverwrite a non-empty output dir

What it does

  1. Scans the sketch for #include <X.h> and maps each header to a git library (built-in PaulStoffregen map; override via --csv), pulling in each library's transitive dependencies (e.g. Audio → SPI/SD/SerialFlash/Wire/arm_math).
  2. Transforms the .ino(s) into a compilable .cpp (injects Arduino.h, generates forward prototypes — K&R and Allman brace styles — and concatenates multi-tab sketches).
  3. Emits CMakeLists.txt (linking stdc++ automatically when the sketch uses the C++ STL), a board toolchain file, optional .vscode/, and a README, and copies any companion files (local headers, extra sources, data) from the sketch folder.

CSV override format

See examples/libraries.sample.csv. Columns: header,library,git_url,branch,source_path,subdirs (subdirs is ;-separated; # lines are comments). A row overrides a built-in header or adds a new one — this is how you point a header at a fork (e.g. git@github.com:newdigate/SPI.git).

Build the generated project

cd <SketchName>-teensy
mkdir -p cmake-build-debug && cd cmake-build-debug
cmake .. -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy42.toolchain.cmake"
make

Develop

node --test    # run the suite