This reference covers the complete HIL API surface: hardware I/O functions, system operators, I2C, event handlers, autopilot commands, and the registry HTTP/WS endpoints (Rashwan, 2026).
HIL LISP Built-in Operators
Arithmetic
| Operator | Syntax | Description | Example |
|---|
+ | (+ a b) | Addition | (+ 3 4) → 7 |
- | (- a b) | Subtraction | (- 10 3) → 7 |
- | (- a) | Negation | (- 5) → -5 |
* | (* a b) | Multiplication | (* 6 7) → 42 |
/ | (/ a b) | Integer division | (/ 10 3) → 3 |
% | (% a b) | Modulo | (% 10 3) → 1 |
Comparison
| Operator | Syntax | Description |
|---|
== | (== a b) | Equal |
!= | (!= a b) | Not equal |
> | (> a b) | Greater than |
< | (< a b) | Less than |
>= | (>= a b) | Greater or equal |
<= | (<= a b) | Less or equal |
Boolean
| Operator | Syntax | Description |
|---|
AND | (AND a b) | Logical AND (both nonzero = 1) |
OR | (OR a b) | Logical OR (either nonzero = 1) |
NOT | (NOT a) | Logical NOT (0 → 1, nonzero → 0) |
Math Utilities
| Operator | Syntax | Description |
|---|
MIN | (MIN a b) | Minimum of two values |
MAX | (MAX a b) | Maximum of two values |
ABS | (ABS a) | Absolute value |
MAP | (MAP v inMin inMax outMin outMax) | Linear interpolation |
CONSTRAIN | (CONSTRAIN v min max) | Clamp to range |
RANDOM | (RANDOM min max) | Random integer in [min, max] |
Control Flow
| Operator | Syntax | Description |
|---|
IF | (IF cond then else) | Conditional |
COND | (COND (cond1 body1) ...) | Multi-way branch |
WHILE | (WHILE cond body) | Loop while true |
FOR | (FOR var from to body) | Counted loop (stop value exclusive; up or down) |
DO | (DO expr1 expr2 ...) | Sequence |
BREAK | (BREAK) | Exit innermost loop |
CONTINUE | (CONTINUE) | Skip to next iteration |
Variables and Functions
| Operator | Syntax | Description |
|---|
SET | (SET var value) | Assign variable |
DEFUN | (DEFUN name (params) body) | Define function |
LOAD | (LOAD "path") | Load a package file |
Hardware I/O
| Operator | Syntax | Description |
|---|
PIN-MODE | (PIN-MODE TYPE pin mode) | Configure pin (0=input, 1=output) |
WRITE | (WRITE TYPE pin value) | Write to pin (D=digital, A=analog, P=PWM) |
READ | (READ TYPE pin) | Read from pin |
TOGGLE | (TOGGLE pin) | Toggle digital pin |
TONE | (TONE pin freq duration) | Play a tone |
DELAY | (DELAY ms) | Delay in milliseconds |
DLY-US | (DLY-US us) | Delay in microseconds |
AWAIT | (AWAIT pin state timeout) | Wait for pin state with timeout |
MILLIS | (MILLIS) | Current time in ms |
PULSE | (PULSE pin timeout) | Measure pulse width (µs) |
BLINK | (BLINK pin count onMs offMs) | Blink LED pattern |
I2C
| Operator | Syntax | Description |
|---|
I2C-START | (I2C-START addr rw) | Start I2C transaction |
I2C-WRITE | (I2C-WRITE byte) | Write byte to I2C |
I2C-READ | (I2C-READ ack) | Read byte from I2C (ack=1) |
I2C-STOP | (I2C-STOP) | End I2C transaction |
Peripherals
| Operator | Syntax | Description |
|---|
SERVO | (SERVO pin angle) | Set servo angle (0-180) |
LCD-INIT | (LCD-INIT) | Initialize LCD |
LCD-PRINT | (LCD-PRINT text) | Print to LCD |
LCD-CLEAR | (LCD-CLEAR) | Clear LCD |
LCD-SETCURSOR | (LCD-SETCURSOR col row) | Set LCD cursor position |
NEO-SET | (NEO-SET idx r g b) | Set NeoPixel color |
NEO-SHOW | (NEO-SHOW) | Update NeoPixel display |
MP3-PLAY | (MP3-PLAY track) | Play MP3 track |
MP3-VOL | (MP3-VOL level) | Set MP3 volume |
Sensors
| Operator | Syntax | Description |
|---|
LM35 | (LM35) | Read LM35 temperature |
ULTRASONIC | (ULTRASONIC trig echo) | Read distance in cm |
DHT-READ | (DHT-READ pin) | Read DHT sensor data |
RTC-READ | (RTC-READ) | Read real-time clock |
Events
| Operator | Syntax | Description |
|---|
ON-EVENT | (ON-EVENT type pin action) | Arm digital event |
ON-CHANGE | (ON-CHANGE pin threshold action) | Arm analog threshold event |
ATTENTION | (ATTENTION pin flag) | Bypass event polling limits |
EVT-ARM | (EVT-ARM type pin threshold) | Low-level event arm |
EVT-POLL | (EVT-POLL) | Poll for events |
Control Systems
| Operator | Syntax | Description |
|---|
PID-INIT | (PID-INIT kp ki kd) | Initialize PID controller |
CLOSED-LOOP | (CLOSED-LOOP target pin) | Start closed-loop control |
OPEN-LOOP | (OPEN-LOOP) | Stop closed-loop control |
Autopilot
| Operator | Syntax | Description |
|---|
AUTOPILOT-BEGIN | (AUTOPILOT-BEGIN) | Start recording autopilot commands |
AUTOPILOT-END | (AUTOPILOT-END) | Stop recording and store to flash |
List Operations
| Operator | Syntax | Description |
|---|
FIRST | (FIRST list) | Get first element |
SECOND | (SECOND list) | Get second element |
Batching
| Operator | Syntax | Description |
|---|
BATCH-BEGIN | (BATCH-BEGIN) | Disable per-command ACK |
BATCH-END | (BATCH-END) | Re-enable per-command ACK |
System
| Operator | Syntax | Description |
|---|
EXIT | (EXIT) | Halt execution |
LOG | (LOG val...) | Print to serial console |
Registry HTTP API
| Endpoint | Method | Description |
|---|
/api | GET | Registry info (name, version, package count) |
/api/health | GET | Health check with uptime |
/api/search?q= | GET | Search packages |
/api/packages/:name | GET | Package metadata |
/api/packages/:name/download | GET | Download package |
/api/ota/versions | GET | List OTA versions |
/api/ota/announce | POST | Announce new version (admin) |
/api/errors | GET | List errors |
/api/errors/stats | GET | Error statistics |
/api/errors | POST | Report error |
/api/network/devices | GET | List IoT devices |
/api/network/feed | GET | Recent messages |
/api/network/topics | GET | Active topics |
WebSocket API
Connect to ws://host:3002/ws for real-time IoT communication:
| Message Type | Direction | Description |
|---|
auth | Client→Server | Authenticate device |
heartbeat | Client→Server | Keep-alive ping |
publish | Client→Server | Publish to topic |
subscribe | Client→Server | Subscribe to topic |
message | Both | Direct device message |
References
Rashwan, S. (2026). HIL: A LISP-based hardware-in-the-loop operating system. https://github.com/SRashwan/hilp