coloX Airimg Host Streaming Guide
Incoming image streaming (airimg): the computer sends JPG frames over USB → device firmware receives them in the background and stores them in a ring buffer (retaining the latest 2 complete frames) → the home screen's animated standby display shows them automatically, or a cartridge pulls and renders them itself. Both knob and ColoPLAY firmware support this feature.
Starting with CXUS v2, the same USB interface also carries a bidirectional application data channel (types 16–31 for audio, input, or arbitrary application data). The platform does not interpret the payload. Device-to-host traffic uses the IN endpoint on the same interface, and PING/PONG reports statistics. See Data Channel and the knob project's tools/airdata_test.py reference implementation.
No cartridge is required: once streaming starts, the device's animated home screen displays it automatically (see default behavior below). For the cartridge APIs (
img_airinfo/img_loadair/img_scrair), see the incoming image stream section in img.md.
Identifying the USB Device
The device enumerates as a composite USB device (CDC + HID + vendor interface). Airimg uses the vendor interface:
| Identification feature | Value |
|---|---|
| VID / PID | 0x303A (Espressif) / 0x4005 |
| Product string | ColoPlay |
| Vendor interface | Interface 3, class 0xFF, bulk OUT 0x03 / IN 0x83 (maxpacket 512; v2 uses IN for device-to-host traffic) |
| Interface string | cxair_R<width>x<height>_M<maximum-frame-bytes>, e.g. cxair_R480x480_M262144—reports the screen resolution and maximum frame size |
How to inspect it on each system:
# macOS (no lsusb)
system_profiler SPUSBDataType | grep -iA8 303a
# Linux
lsusb | grep 303a:4005
On Windows, the vendor interface binds directly to WinUSB (the firmware includes an MS-OS 2.0 descriptor, so no driver installation is required). With pyusb installed, you can also run open_device() from the example below. It prints the interface string to confirm the device and its capabilities in one step.
Streaming Protocol (CXUS)
Each frame consists of a 20-byte little-endian header + JPEG payload, written to the vendor bulk OUT endpoint:
| Offset | Field | Type | Description |
|---|---|---|---|
| 0 | magic | u32 | 0x53555843 (wire order: 'C','X','U','S') |
| 4 | type | u16 | 1 = JPG frame. See Data Channel for v2 message types |
| 6 | flags | u16 | For JPG use 0x0001. For data messages, bit 0 is the priority |
| 8 | payload_len | u32 | JPEG byte count |
| 12 | frame_id | u16 | Incrementing counter (wraps around) |
| 14 | width | u16 | Must contain the actual width (used by the device for liveness detection and layout) |
| 16 | height | u16 | Same as above |
| 18 | crc16 | u16 | CRC-16/CCITT-FALSE of the payload; use 0 to skip verification |
Key points:
- Frames may be dropped: the device retains only the latest 2 complete frames. The sender can send at its target frame rate; when the device consumes frames slowly, USB bulk applies backpressure automatically (NAK), without corrupting the stream.
- Frames exceeding the interface string's
Mlimit, or failing the CRC check, are discarded in full. - Image dimensions do not have to match the screen: the device centers the image and crops anything outside the screen (no scaling). For a full-screen image, crop it to the screen dimensions before sending.
Data Channel (CXUS v2, Bidirectional)
CXUS v2 extends the existing 20-byte frame header and preserves JPG streaming. Message types:
| Type | Meaning | Direction |
|---|---|---|
| 1 | JPG frame (unchanged from v1) | Host → device |
| 2–15 | Reserved (the device discards the entire message without disrupting the stream) | — |
| 16–31 | Data channel. Applications define the payload. 16=AUDIO (Opus) and 17=INPUT (unified input protocol) are predefined, while 18–31 are available to applications | Bidirectional |
| 32 | PING (empty payload) | Host → device |
| 33 | PONG (38-byte payload, sent automatically by the device) | Device → host |
Control messages (type ≥32) must fit in 64 bytes including the header, so they can be sent in one packet on full-speed USB devices with 64-byte packets.
Data Message Fields and Queues
- Bit 0 of
flagssets the priority (0 for normal, 1 for high). Set reserved bits 1–15 to zero. On reception, the bit selects the device queue. On transmission, it identifies the source queue. The host can track each sequence independently using this bit. wcarries tag andhcarries sub. Both are application-defined u16 values.payload_len=0is valid for events carrying only tag/sub.frame_idis supplied by the host for inbound messages. Outbound frames carry the low 16 bits of the device queue's sequence number. A gap within one queue indicates a drop on the device.- The device has four queues (receive/send × normal/high), each with its own message and byte limits. A full queue drops its oldest message. An unread channel cannot block the JPG stream. Use PONG feedback to slow down, and application-level acknowledgment and retransmission when needed.
- The firmware sets the maximum message size (8 KB by default on knob). An oversized message is discarded in full.
PING / PONG (Device Status)
The host sends type 32 with an empty payload and a frame_id that increments for each request. The device replies on IN with type 33 and a 38-byte little-endian payload:
| Offset | Field | Description |
|---|---|---|
| 0 | u16 ver | 2, used to distinguish future layouts |
| 2 | u16 echo_fid | frame_id from the triggering PING |
| 4 | u32 uptime_ms | Device uptime in milliseconds. A smaller value indicates a restart, so counter deltas across it are unreliable |
| 8 | u16 max_cnt | Maximum message count shared by all four queues, used to set the sending rate |
| 10 | u32×3+u16 | Normal RX queue: enq/popped/dropped deltas since the previous PING, followed by current depth |
| 24 | u32×3+u16 | Same fields for the high-priority RX queue |
enq = popped + dropped + Δcur. The popped count shows how fast the cartridge is consuming messages. A growing dropped count shows it cannot keep up. Each interval runs between two PINGs. A new PING received before its predecessor's PONG is sent resets the interval, which can be detected with echo_fid.
AUDIO (Type 16)
The payload contains one or more [u16 big-endian length][Opus packet] units. The format matches micpoll(...,3) output and wave(...,3) input byte for byte, so the cartridge can forward the payload directly. One packet contains one frame. Live streams use one packet per message (16 kHz, mono, 60 ms by default). Buffered messages may contain multiple units. tag identifies the format profile (0 is the default). Version 1 has no timestamp, so the live stream follows its own pacing.
INPUT (Type 17, Unified Input Protocol)
payload[0] is the kind, followed by little-endian fields. The protocol does not reserve tag or sub.
| Kind | Name | Payload | Description |
|---|---|---|---|
| 0x01 | EVT | [1]=src. For src=1 (touch), phase u8 (0 down / 1 move / 2 up) + x i16 + y i16. For src=2 (buttons), a mask u16 snapshot with bits 0–7 in X Y A B CENTER LEFT RIGHT SYS order, matching btn(). For src=3 (key), id u16 + down u8 | Bidirectional input event. Device reports and host injections share the same encoding |
| 0x02 | REQ | timeout_ms u32 (0 means no timeout) + mask u8 (bit 0 for touch pointer, bit 1 for buttons. 0 or omitted means buttons only) | Ask the device to report input as EVT. The timeout covers a lost END, and the mask determines capture and exclusivity |
| 0x03 | END | No fields after the kind byte | Stop reporting input |
| 0x04 and above | Reserved | — | Future extensions such as cursor or vibration |
For use as a host UI terminal, the host sends JPG frames, type 16 Opus, and a type 17 REQ. The device reports touch or buttons as EVT, and the host sends END when done. Button mode reports a simulated button mask for touch. Touch mode reports raw coordinates and captures touch exclusively on the device.
Reading on the Host
- Read endpoint
0x83using the same 20-byte header. Frames arrive in device transmission order, with high-priority messages sent first. - Resynchronize by scanning for the magic value. A resumed stream may start mid-packet. Parse the remaining fields as on the device.
- Send PING periodically to check the connection and adjust the sending rate based on consumption.
- See
tools/airdata_test.pyin the knob project for the reference implementation of sending, parsing, PING/PONG, priority checks, and the terminal UI. - See
airdata_rec/play_airrec.clxin the example index for capture on the device, type 16 transmission, and WAV decoding on the host withairmic_recv.py.
Python Streaming Example
Dependencies: pip install pyusb pillow (macOS also requires brew install libusb; Windows needs no driver installation; non-root access on Linux requires a udev rule, shown at the end of this section).
#!/usr/bin/env python3
"""airimg_push.py — Minimal CXUS streaming example: cover-crop a JPG and stream it repeatedly to the device."""
import io
import struct
import sys
import time
import usb.core
import usb.util
from PIL import Image
VID, PID = 0x303A, 0x4005 # Espressif VID / CDC+HID composite PID
ITF_CLASS = 0xFF # Vendor interface class
CXUS_MAGIC, CXUS_TYPE_JPG, CXUS_FLAG = 0x53555843, 1, 0x0001
HDR = struct.Struct("<IHHIHHHH") # magic,type,flags,payload_len,frame_id,w,h,crc16
def crc16(data):
"""CRC-16/CCITT-FALSE; use 0 to skip verification."""
crc = 0xFFFF
for b in data:
crc ^= b << 8
for _ in range(8):
crc = ((crc << 1) ^ 0x1021) if crc & 0x8000 else (crc << 1)
crc &= 0xFFFF
return crc
def open_device():
dev = usb.core.find(idVendor=VID, idProduct=PID)
if dev is None:
sys.exit(f"Device not found {VID:04x}:{PID:04x}")
if dev.is_kernel_driver_active(0): # Linux: detach the kernel driver
dev.detach_kernel_driver(0)
try:
dev.set_configuration()
except usb.core.USBError:
pass # Already configured
cfg = dev.get_active_configuration()
itf = next(i for i in cfg if i.bInterfaceClass == ITF_CLASS)
print("vendor itf", itf.bInterfaceNumber,
usb.util.get_string(dev, itf.iInterface) or "") # For example, cxair_R480x480_M262144
usb.util.claim_interface(dev, itf)
ep = next(e.bEndpointAddress for e in itf
if usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
return dev, ep
def cover_jpeg(path, w, h, quality=85):
"""Resize to w x h (cover: scale proportionally to fill, then center-crop) and re-encode as JPEG."""
im = Image.open(path).convert("RGB")
s = max(w / im.width, h / im.height)
nw, nh = round(im.width * s), round(im.height * s)
im = im.resize((nw, nh))
l, t = (nw - w) // 2, (nh - h) // 2
im = im.crop((l, t, l + w, t + h))
buf = io.BytesIO()
im.save(buf, "JPEG", quality=quality)
return buf.getvalue(), w, h
def main(path, size=(480, 480), fps=10):
dev, ep = open_device()
jpg, w, h = cover_jpeg(path, *size) # Header w/h must contain the actual dimensions
fid = 0
t0 = time.monotonic()
while True: # Only the latest 2 frames are retained; frames may be dropped
hdr = HDR.pack(CXUS_MAGIC, CXUS_TYPE_JPG, CXUS_FLAG,
len(jpg), fid & 0xFFFF, w, h, crc16(jpg))
dev.write(ep, hdr + jpg, 2000) # USB NAK applies backpressure when the device consumes frames slowly
fid += 1
if fid % 50 == 0:
print(f"{fid} frames, {fid / (time.monotonic() - t0):.1f} fps")
time.sleep(1.0 / fps)
if __name__ == "__main__":
main(sys.argv[1] if len(sys.argv) > 1 else "test.jpg")
For a live source such as a camera or screen capture, replace image loading in main with capture (cv2.VideoCapture/mss). The packing and transmission code stays the same.
Non-root access on Linux requires a udev rule (for example, /etc/udev/rules.d/99-colox.rules):
SUBSYSTEM=="usb", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="4005", MODE="0666"
Default Behavior: Automatic Display on the Animated Home Screen
The knob / ColoPLAY firmware's animated home screen (standby display) has built-in airimg detection—start streaming from the computer and the image appears on screen, without writing cartridge code:
- Each frame, the animated screen checks airimg (
img_airinfo()). As long as the latest frame hasage_ms < 2000(streaming is still active), it immediately displays the live image withimg_scrair(), taking priority over screensaver content (GIFs/images/emulator screensavers). - About 2 seconds after streaming stops or the cable is disconnected (
age_msexceeds the threshold), the display automatically returns to its original animated screen content. - While the stream is active, screensaver content is not loaded, so it takes no additional memory.
A cartridge is needed only to customize the display (overlay text/status, display a region, or change the display condition). Use the APIs in the incoming image stream section of img.md.