Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Caduceus Programming LanguageNew to Visual Studio Code? Get it now.
Caduceus Programming Language

Caduceus Programming Language

Justin1230

|
1 install
| (0) | Free
Domain-Specific Language & Spatial CSI Engine for Hardware & AI
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Caduceus Programming Language (caduceus-dsl)

Zero-Boilerplate Domain-Specific Language & Hardware Transpiler for Microcontrollers, Bare-Metal Silicon, and Wireless Mesh Systems.

Overview

Caduceus eliminates the C/C++ boilerplate, header conflicts, and library dependency headaches of traditional embedded development. Write clean, strongly-typed hardware logic in .cad files and transpile directly into optimized native C++, bare-metal RISC-V register C, tokenized BASIC, or structural Verilog RTL—automatically managing platformio.ini dependencies, radio stacks, and on-chip web telemetry HUDs.

Why Caduceus?

Feature

Traditional Arduino / ESP-IDF

Caduceus DSL (.cad)

Project Setup

Manual platformio.ini, library version hunting, #include chains

Single target & use header directives; dependencies auto-injected

Hardware Config

Scattered #define macros and global magic numbers

Dedicated, self-documenting config { ... } block

Runtime State

Unstructured globals prone to race conditions

Explicit, typed state { ... } block

Wireless & HUD

300+ lines of WebSocket, SoftAP, and BLE callback boilerplate

Native wifi_ap_start(), ws_broadcast(), and bt_serial_start() primitives

Multi-Silicon

Rewrite firmware from scratch for every MCU family

One unified syntax targeting ESP32, RISC-V (CH32V003), AVR, PICAXE, and RTL

Supported Silicon & Universal Targets

Caduceus branches at the code-generation layer based on your target directive, compiling a single .cad mental model across multiple hardware tiers:

Target Directive

Architecture & Chip Family

Codegen Output

Primary Use Case

target ESP32S3

Xtensa LX7 Dual-Core 240MHz (ESP32-S3)

Native C++ / ESP-IDF

Flight controllers, AI edge nodes, WebSocket HUDs, BLE + Wi-Fi

target ESP32C3

RISC-V Single-Core 160MHz (ESP32-C3)

Native C++ / ESP-IDF

Compact wireless sensor nodes, IMU tilt gauges, OTA endpoints

target ESP32

Xtensa LX6 Dual-Core 240MHz (ESP32)

Native C++ / Arduino

General IoT, LoRa SX1276/1278 mesh bridges, motor control

target UNO

8-Bit AVR (ATmega328P / ATtiny85)

Optimized C++ / AVR

Legacy shields, deterministic PWM actuators, basic sensors

target CH32V003

32-Bit RISC-V 48MHz (WCH CH32V002/003)

Bare-Metal Register C

Ultra-low-cost ($0.15) distributed co-processors & fast interrupts

target PICAXE08M2

8-Bit Tokenized Core (08M2 / 14M2 / 20M2)

Structured PICAXE BASIC

Breadboard analog glue logic & rapid DIP prototyping

target SILICON_RTL

Zero-CPU Programmable Logic (SPLD / FPGA)

Structural Verilog Netlist

Hardware state machines, Manchester encoders, zero-latency gates

Installation & Quick Start

  1. Install the VS Code Extension

Open Visual Studio Code.

Go to the Extensions view (Ctrl+Shift+X / Cmd+Shift+X).

Search for Caduceus Programming Language (Publisher: Justin1230) and click Install.

Create any file ending in .cad to activate syntax highlighting, code snippets, and language diagnostics.

(Optional Offline Install): Download the .vsix package and run:

code --install-extension caduceus-dsl-1.0.4.vsix

  1. Install the Mercury V2 Transpiler CLI & PlatformIO

Ensure Python 3.10+ and PlatformIO Core are installed on your system:

Install PlatformIO CLI

pip install platformio

Clone or navigate to your Mercury V2 compiler directory and install in editable mode

cd Mercury.V2 pip install -e .

  1. Transpile, Build & Flash Your First Script

Run the Caduceus CLI against any .cad file to generate native firmware, auto-configure platformio.ini, and upload directly over USB or OTA:

Transpile a .cad script to native C++ / target output

caduceus transpile blink.cad

Transpile, compile, and flash directly to a connected board

caduceus run blink.cad --target ESP32C3 --port COM4

Language Architecture & Core Building Blocks

Every Caduceus program is organized into five clean, deterministic sections:

// 1. COMPILER DIRECTIVES target ESP32C3 frequency 160MHz use I2C use WIFI_WS

// 2. HARDWARE & NETWORK CONFIGURATION (Compile-Time Constants) config { board_name: "CADUCEUS_NODE_C3", pin_led: 8, pin_sda: 4, pin_scl: 5 }

// 3. PERSISTENT RUNTIME STATE (Typed Global Variables) state { led_on: false, tick_count: 0, sensor_val: 0.0 }

// 4. STRONGLY-TYPED HELPER FUNCTIONS fn clamp_float(val: float, min_v: float, max_v: float) -> float { if val < min_v { return min_v } if val > max_v { return max_v } return val }

// 5. HARDWARE INITIALIZATION & REAL-TIME EXECUTION LOOP setup { PIN(config.pin_led, 1) PRINT("CADUCEUS_READY") }

loop { state.tick_count = state.tick_count + 1 delay_ms(500) }

Data Types & Variable Declarations

Primitive Types: int, float, bool, string, void

Local Variables: Declared inside functions, setup, or loop using let:

let raw_adc = ANALOG_READ(1) let voltage = (raw_adc / 4095.0) * 3.3

Control Flow:

Conditionals: if condition { ... } else { ... }

Bounded Ranges: for i in 0 .. 4 { ... }

Early Exit: return or return value

Standard Library & Hardware Primitives Reference

  1. Digital, Analog & Timing Primitives

Primitive

Signature

Description

PIN

PIN(pin: int, mode: int)

Configures GPIO direction (1 = OUTPUT, 0 = INPUT)

DIGITAL_WRITE

DIGITAL_WRITE(pin: int, val: int)

Sets GPIO logic level (1 = HIGH, 0 = LOW)

DIGITAL_READ

DIGITAL_READ(pin: int) -> int

Reads digital logic state (0 or 1)

ANALOG_READ

ANALOG_READ(pin: int) -> int

Reads 12-bit ADC value (0..4095 on ESP32)

PRINT

PRINT(msg: string)

Outputs formatted telemetry/debug text over UART/USB CDC

MILLIS

MILLIS() -> int

Returns milliseconds elapsed since boot

micros

micros() -> int

Returns microseconds elapsed since boot for high-speed loops

delay_ms

delay_ms(ms: int)

Blocking delay in milliseconds

delay_us

delay_us(us: int)

Precision microsecond delay (used for ultrasonic/bit-banging)

pulse_in

pulse_in(pin: int, state: int, timeout_us: int) -> int

Measures pulse duration in microseconds with non-stalling timeout

  1. High-Resolution LEDC PWM & Actuator Primitives

Requires use LEDC_PWM:

Primitive

Signature

Description

pwm_attach

pwm_attach(ch: int, pin: int, freq_hz: int, res_bits: int)

Binds a hardware timer channel to a GPIO pin

pwm_write_us

pwm_write_us(ch: int, us: int)

Writes microsecond pulse width (1000..2000 µs for ESCs/servos)

pwm_write

pwm_write(ch: int, duty: int)

Writes raw PWM duty cycle (0..2^res - 1)

  1. I2C Bus & Sensor Register Primitives

Requires use I2C:

Primitive

Signature

Description

i2c_begin

i2c_begin(sda: int, scl: int, freq_hz: int)

Initializes hardware I2C bus (e.g., 400000 for 400kHz Fast Mode)

i2c_probe

i2c_probe(addr: int) -> bool

Checks if an I2C device acknowledges at addr (e.g., 0x68)

i2c_write_reg

i2c_write_reg(addr: int, reg: int, val: int)

Writes a single configuration byte to a device register

i2c_read_bytes

i2c_read_bytes(addr: int, reg: int, count: int) -> bytes

Burst-reads count sequential bytes starting at reg

to_int16

to_int16(msb: int, lsb: int) -> int

Combines high and low sensor bytes into a signed 16-bit integer

  1. Wireless, Mesh & Telemetry Primitives

Requires use WIFI_WS, use BLE_UART, use LORA, or use CADUCEUS_NOW:

Primitive

Signature

Description

wifi_ap_start

wifi_ap_start(ssid: string, pass: string)

Launches an on-chip Wi-Fi Access Point

ws_server_start

ws_server_start(port: int, path: string, ui: string)

Starts an async WebSocket server and hosts an HTML telemetry HUD

ws_available

ws_available() -> bool

Checks if an incoming WebSocket command packet is queued

ws_read_packet

ws_read_packet() -> string

Reads the next incoming WebSocket payload

ws_broadcast

ws_broadcast(payload: string)

Pushes live telemetry frames to all connected browser HUD clients

bt_serial_start

bt_serial_start(name: string, baud: int)

Initializes Nordic UART Service (BLE UART) / Bluetooth serial

bt_serial_available

bt_serial_available() -> bool

Checks for incoming Bluetooth command frames

bt_serial_read_line

bt_serial_read_line() -> string

Reads a newline-terminated command string over BLE

bt_serial_println

bt_serial_println(payload: string)

Transmits a telemetry frame over BLE

mesh_send

mesh_send(node_id: string, payload: string)

Sends a sub-2ms Layer-2 CaduceusNow frame over raw 2.4GHz RF

  1. Bare-Metal & Silicon RTL Primitives (target CH32V003 / target SILICON_RTL)

Primitive

Description

CLOCK_EDGE(pin, rising|falling)

Maps to hardware edge interrupts on MCUs or D-flip-flop clock triggers in RTL

SHIFT_REG(dir, bits, data, clk)

Synthesizes a parallel-in/serial-out shift register for framing packets without a UART

STATE_MACHINE(states...)

Compiles to jump-tables in bare C or one-hot flip-flop state registers in Verilog

MANCHESTER_TX(pin, baud, byte)

Emits self-clocking Manchester transitions for crystal-free wireless links

COMP_LATCH(in_pos, vref, out)

Binds internal analog comparators (CH32V003 / LM393) to hardware latches

REG_WRITE(addr, mask, val)

Direct memory-mapped register manipulation with zero abstraction overhead

Complete Building Block Examples

Example 1: Basic GPIO, ADC Threshold & Status Heartbeat (ESP32-C3)

A minimal hardware bring-up script verifying digital outputs, analog sensor polling, and non-blocking millisecond timing.

target ESP32C3 frequency 160MHz

config { pin_led: 8, pin_sensor: 2, threshold_mv: 1650, blink_interval_ms: 250 }

state { led_state: 0, last_blink_ms: 0, voltage_mv: 0.0 }

fn read_sensor_mv(adc_pin: int) -> float { let raw = ANALOG_READ(adc_pin) return (raw / 4095.0) * 3300.0 }

setup { PIN(config.pin_led, 1) PIN(config.pin_sensor, 0) DIGITAL_WRITE(config.pin_led, 0) state.last_blink_ms = MILLIS() PRINT("CADUCEUS_C3_HEARTBEAT_ACTIVE") }

loop { let now = MILLIS() state.voltage_mv = read_sensor_mv(config.pin_sensor)

if state.voltage_mv > config.threshold_mv {
    DIGITAL_WRITE(config.pin_led, 1)
    PRINT("ALERT_HIGH_VOLTAGE: " + fmt(state.voltage_mv, 1) + " mV")
} else {
    if (now - state.last_blink_ms) >= config.blink_interval_ms {
        state.last_blink_ms = now
        if state.led_state == 0 {
            state.led_state = 1
        } else {
            state.led_state = 0
        }
        DIGITAL_WRITE(config.pin_led, state.led_state)
    }
}

}

Example 2: MPU-6050 Gyroscope/Accelerometer + Live Web Tilt HUD (ESP32-C3 / ESP32-S3)

Initializes an MPU-6050 IMU over 400kHz I2C, fuses accelerometer and gyroscope axes using a complementary filter, and broadcasts live roll/pitch/yaw frames at 20Hz to a browser-based tilt HUD.

target ESP32C3 frequency 160MHz use I2C use WIFI_WS

config { wifi_ssid: "Caduceus_IMU_HUD", wifi_pass: "caduceus240", ws_port: 80, pin_sda: 8, pin_scl: 9, mpu_addr: 0x68, pin_led: 2 }

state { roll_deg: 0.0, pitch_deg: 0.0, yaw_deg: 0.0, gyro_x: 0.0, gyro_y: 0.0, gyro_z: 0.0, last_us: 0, last_telem_ms: 0 }

fn init_mpu6050() -> bool { i2c_begin(config.pin_sda, config.pin_scl, 400000) // Wake MPU-6050 (PWR_MGMT_1 = 0x6B -> 0x00) i2c_write_reg(config.mpu_addr, 0x6B, 0x00) // Gyro +/- 500 deg/s (0x1B -> 0x08), Accel +/- 8g (0x1C -> 0x10) i2c_write_reg(config.mpu_addr, 0x1B, 0x08) i2c_write_reg(config.mpu_addr, 0x1C, 0x10) return i2c_probe(config.mpu_addr) }

fn poll_imu(dt_sec: float) -> void { let raw = i2c_read_bytes(config.mpu_addr, 0x3B, 14) if len(raw) < 14 { return }

let ax = to_int16(raw[0], raw[1]) / 4096.0
let ay = to_int16(raw[2], raw[3]) / 4096.0
let az = to_int16(raw[4], raw[5]) / 4096.0

state.gyro_x = to_int16(raw[8], raw[9]) / 65.5
state.gyro_y = to_int16(raw[10], raw[11]) / 65.5
state.gyro_z = to_int16(raw[12], raw[13]) / 65.5

let acc_roll = atan2(ay, az) * 57.2958
let acc_pitch = atan2(-ax, sqrt(ay * ay + az * az)) * 57.2958

// Complementary Filter (98% Gyro + 2% Accel)
state.roll_deg = 0.98 * (state.roll_deg + state.gyro_x * dt_sec) + 0.02 * acc_roll
state.pitch_deg = 0.98 * (state.pitch_deg + state.gyro_y * dt_sec) + 0.02 * acc_pitch
state.yaw_deg = state.yaw_deg + state.gyro_z * dt_sec

}

setup { PIN(config.pin_led, 1) let ok = init_mpu6050() if !ok { PRINT("IMU_ERROR: Check SDA=8 SCL=9 wiring") DIGITAL_WRITE(config.pin_led, 0) } else { PRINT("IMU_LOCKED_0x68") DIGITAL_WRITE(config.pin_led, 1) }

wifi_ap_start(config.wifi_ssid, config.wifi_pass)
ws_server_start(config.ws_port, "/ws", "index.html")

state.last_us = micros()
state.last_telem_ms = MILLIS()

}

loop { let now_us = micros() let dt_us = now_us - state.last_us if dt_us < 4000 { return } state.last_us = now_us

let dt_sec = dt_us / 1000000.0
poll_imu(dt_sec)

let now_ms = MILLIS()
if (now_ms - state.last_telem_ms) >= 50 {
    state.last_telem_ms = now_ms
    let packet = "IMU:" + fmt(state.roll_deg, 1) + "," +
                 fmt(state.pitch_deg, 1) + "," +
                 fmt(state.yaw_deg, 1)
    ws_broadcast(packet)
}

}

Example 3: Dual-Link (Wi-Fi WS + BLE UART) PWM Actuator Controller (ESP32-S3)

Demonstrates priority-arbitrated wireless control with hardware failsafe watchdog and microsecond PWM output.

target ESP32S3 frequency 240MHz use LEDC_PWM use WIFI_WS use BLE_UART

config { wifi_ssid: "Caduceus_Control_AP", wifi_pass: "mercury240", ble_name: "Caduceus_Actuator_BLE", pin_pwm_1: 4, pin_pwm_2: 5, pin_buzzer: 12, pwm_freq: 400, pwm_min: 1000, pwm_max: 2000, failsafe_ms: 500 }

state { armed: false, last_cmd_ms: 0, throttle_us: 1000, active_source: "NONE" }

fn clamp_int(v: int, lo: int, hi: int) -> int { if v < lo { return lo } if v > hi { return hi } return v }

fn disarm_all() -> void { state.armed = false state.throttle_us = config.pwm_min pwm_write_us(0, config.pwm_min) pwm_write_us(1, config.pwm_min) }

fn handle_cmd(src: string, msg: string) -> void { if msg == "KILL" { disarm_all() DIGITAL_WRITE(config.pin_buzzer, 1) PRINT("EMERGENCY_KILL_BY_" + src) return }

if starts_with(msg, "SET:") {
    let parts = split(msg, ":")
    if len(parts) >= 3 {
        let arm_req = to_int(parts[1])
        let thr_req = to_int(parts[2])
        state.last_cmd_ms = MILLIS()
        state.active_source = src
        DIGITAL_WRITE(config.pin_buzzer, 0)

        if arm_req == 1 {
            state.armed = true
            state.throttle_us = clamp_int(thr_req, config.pwm_min, config.pwm_max)
            pwm_write_us(0, state.throttle_us)
            pwm_write_us(1, state.throttle_us)
        } else {
            disarm_all()
        }
    }
}

}

setup { PIN(config.pin_buzzer, 1) pwm_attach(0, config.pin_pwm_1, config.pwm_freq, 16) pwm_attach(1, config.pin_pwm_2, config.pwm_freq, 16) disarm_all()

wifi_ap_start(config.wifi_ssid, config.wifi_pass)
ws_server_start(80, "/ws", "index.html")
bt_serial_start(config.ble_name, 115200)
PRINT("DUAL_LINK_CONTROLLER_READY")

}

loop { if ws_available() { handle_cmd("WS", ws_read_packet()) } if bt_serial_available() { handle_cmd("BLE", bt_serial_read_line()) }

if state.armed && (MILLIS() - state.last_cmd_ms) > config.failsafe_ms {
    disarm_all()
    DIGITAL_WRITE(config.pin_buzzer, 1)
    PRINT("WATCHDOG_FAILSAFE_TRIGGERED")
}

}

Example 4: Bare-Metal RISC-V & Silicon RTL Wireless Beacon (CH32V003 / SILICON_RTL)

Compiles down to bare-metal register C on a $0.15 CH32V003 chip—or directly into structural Verilog gates when target SILICON_RTL is selected—to drive a crystal-free Manchester OOK wireless transmitter.

target CH32V003 frequency 48MHz

config { pin_rf_data: 4, pin_comp_in: 2, node_sync_byte: 0xCA, node_id: 0x01, baud_rate: 1200 }

state { trigger_count: 0, alert_active: false }

setup { PIN(config.pin_rf_data, 1) PIN(config.pin_comp_in, 0) DIGITAL_WRITE(config.pin_rf_data, 0) }

loop { let edge = DIGITAL_READ(config.pin_comp_in) if edge == 1 { state.trigger_count = state.trigger_count + 1 MANCHESTER_TX(config.pin_rf_data, config.baud_rate, config.node_sync_byte) MANCHESTER_TX(config.pin_rf_data, config.baud_rate, config.node_id) MANCHESTER_TX(config.pin_rf_data, config.baud_rate, state.trigger_count) delay_ms(250) } }

VS Code Extension Features

Full Syntax Highlighting: Dedicated TextMate grammar for .cad files covering compiler directives, config/state/setup/loop blocks, typed fn signatures, hardware primitives, and numeric/hex literals.

Intelligent Snippets: Type cad-setup, cad-imu, cad-ws, or cad-pwm to expand complete hardware blocks in one keystroke.

Integrated Build & Transpile Workflow: Run Caduceus: Transpile Current File or Caduceus: Build & Flash Target directly from the VS Code Command Palette (Ctrl+Shift+P).

License

Released under the MIT License. Free for personal, academic, and commercial hardware development.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft