Standard Library
The KDAL standard library ships 7 .kdh files covering common device classes.
These files live in lang/stdlib/ and are installed to
~/.kdal/share/kdal/stdlib/ by kdalup.
Available Devices
Section titled “Available Devices”| File | Device Class | Notable Registers |
|---|---|---|
common.kdh |
Primitive types and constants | - |
uart.kdh |
UART 16550-compatible | DR, FR, IBRD, FBRD, LCRH, CR, IFLS, IMSC, RIS, MIS, ICR |
i2c.kdh |
I2C controller (DesignWare) | CON, TAR, SAR, DATA_CMD, SS/FS_SCL, ISR, IMR, CLR_INTR |
spi.kdh |
SPI controller (PL022) | CR0, CR1, DR, SR, CPSR, IMSC, RIS, MIS, ICR, DMACR |
gpio.kdh |
Generic GPIO bank | DIR, DATA, IS, IBE, IEV, IE, RIS, MIS, IC, AFSEL |
gpu.kdh |
Abstract GPU command queue | SUBMIT, STATUS, RESET, IRQ_STATUS, IRQ_ENABLE, FENCE |
npu.kdh |
Abstract NPU inference engine | MODEL_LOAD, INFER_CMD, STATUS, IRQ_STATUS, RESULT_ADDR |
Using Standard Library Headers
Section titled “Using Standard Library Headers”Import a standard library header by its kdal/stdlib/ path and give it
a name; the device class inside uart.kdh is UartDevice:
kdal_version: "0.1";
import "kdal/stdlib/uart.kdh" as UART;
driver MyUartDriver for UART.UartDevice { probe { write(UART.CR, 0x301); }
remove { write(UART.CR, 0x00); }}Where the header is found:
kdality lintreads it (for register checks) next to the.kdcfirst; akdal/stdlib/path then in$KDAL_STDLIB_DIR, the installed standard library (<prefix>/share/kdal/stdlib/) and a source tree’slang/stdlib/. A header it cannot find is error E002.kdality compiledoes not read imported headers today: register names pass to the generated C as written (ctx->regs.CR), so a misspelt register is caught bylint(W007 on the header, no access to the name) or by the C compiler, not bykdalc.
Creating Custom Device Headers
Section titled “Creating Custom Device Headers”Create a .kdh file following the format in the
Language Specification. A minimal device header declares:
kdal_version: "0.1";
device class MyDevice { compatible "vendor,my-device"; class gpio;
register_map { CTRL 0x00 rw; STATUS 0x04 ro; }
capabilities { version = 1; }}Then import it from your .kdc, next to it:
import "mydevice.kdh" as DEV;Extending the Standard Library
Section titled “Extending the Standard Library”To contribute a new standard library device:
- Create
lang/stdlib/<device>.kdh - Define
device classwithregisters(or the simplifiedregister_map),signals,capabilitiesandpower(orpower_states) - Follow existing patterns -
uart.kdhis the reference - Create a matching example
.kdcinexamples/ - Submit a pull request