gizhw:bus
the buses a board exposes: a serial port's speed (termios2, any rate through BOTHER), GPIO lines (the character device's chardev v2 interface: a line request, then its values), I2C transfers (I2C_RDWR), SPI transfers (SPI_IOC_MESSAGE), USB control transfers (usbfs), and CAN frames (SocketCAN, raw). The ioctl numbers and the structs are the kernel's (termios.h, gpio.h, i2c-dev.h, spidev.h, usbdevice_fs.h, can.h), checked against those headers. Every ioctl is on a Handle of gizhw:device; the CAN socket and the interface lookup are libc calls through libcCall.
import * as Bus from "gizhw:bus";Types
I2cMessage
type I2cMessage = { address: i64; read: bool; length: i64; data: bytes; }One I2C message: the 7-bit address, read (true: length bytes come back) or the data to write.
address:i64read:boollength:i64data:bytes
CanFrame
type CanFrame = { id: i64; extended: bool; data: bytes; }One CAN frame: its identifier, whether it is an extended (29-bit) one, and its data (up to 8 bytes).
id:i64extended:booldata:bytes
Functions
termiosRate
function termiosRate(termios: bytes, baud: i64): bytesThe serial port's termios2 with the speed set: both directions at baud, through BOTHER.
Effects: fail.
serialRate
function serialRate(h: Device.Handle, baud: i64): void throws stringSets the serial port behind h to baud.
Effects: fail, io.
lineRequest
function lineRequest(offset: i64, flags: i64, consumer: string): bytesThe request for GPIO_V2_GET_LINE: one line of the chip (its offset), as an input or an output, under consumer.
Effects: fail.
parseLineFd
function parseLineFd(reply: bytes): i64The line's file descriptor in the reply to GPIO_V2_GET_LINE (at byte 588).
Effects: fail.
valuesRequest
function valuesRequest(bits: i64, mask: i64): bytesThe request for GPIO_V2_LINE_GET/SET_VALUES: the bit values and the mask of the lines it touches (bit 0: the line).
Effects: fail.
parseLineValue
function parseLineValue(reply: bytes): i64The value of the one line the reply to GPIO_V2_LINE_GET_VALUES describes: 0 or 1.
Effects: fail.
gpioRead
function gpioRead(sys: System, chip: Device.Handle, offset: i64): i64 throws stringReads GPIO line offset of the chip behind chip (its character device, /dev/gpiochipN): a line request, then its value.
Effects: fail, io.
gpioWrite
function gpioWrite(sys: System, chip: Device.Handle, offset: i64, value: i64): void throws stringSets GPIO line offset of the chip behind chip to value (0 or 1), as an output.
Effects: fail, io.
i2cMessageBytes
function i2cMessageBytes(address: i64, flags: i64, length: i64, buffer: u64): bytesOne I2C message (struct i2c_msg: 16 bytes): address, flags, length, and the buffer's native address.
Effects: fail.
i2cRdwrBytes
function i2cRdwrBytes(messages: u64, count: i64): bytesThe I2C_RDWR argument (struct i2c_rdwr_ioctl_data: 16 bytes): the messages' native address and their count.
Effects: fail.
i2c
function i2c(h: Device.Handle, messages: Vec<I2cMessage>): Vec<bytes> throws stringRuns I2C messages on the bus behind h, one transaction; gives each read's bytes (empty for a write).
Effects: fail, io.
spiTransferBytes
function spiTransferBytes(tx: u64, rx: u64, length: i64, speed: i64, bits: i64): bytesThe SPI transfer (struct spi_ioc_transfer: 32 bytes): the tx and rx buffers, the length, speed and bits per word.
Effects: fail.
spi
function spi(h: Device.Handle, tx: bytes, rxLength: i64, speed: i64): bytes throws stringOne SPI transfer on the device behind h: tx out, and rxLength bytes back; gives those bytes.
Effects: fail, io.
usbCtrlBytes
function usbCtrlBytes(requestType: i64, request: i64, value: i64, index: i64, length: i64, timeout: i64, data: u64): bytesThe usbfs control transfer (struct usbdevfs_ctrltransfer: 24 bytes).
Effects: fail.
usbControl
function usbControl(h: Device.Handle, requestType: i64, request: i64, value: i64, index: i64, data: bytes, readLength: i64, timeout: i64): bytes throws stringA control transfer on the device behind h. A device-to-host one (requestType with the IN bit) reads readLength
bytes back; a host-to-device one sends data. Gives the bytes that came back (empty for a send).
Effects: fail, io.
canFrameBytes
function canFrameBytes(frame: CanFrame): bytesA CAN frame as struct can_frame (16 bytes): the identifier (with the extended bit), the data length, and the data.
Effects: fail.
parseCanFrame
function parseCanFrame(data: bytes): CanFrameThe CAN frame from its 16 bytes.
Effects: fail.
canOpen
function canOpen(sys: System, name: string): Device.Handle throws stringThe CAN interface name (can0) as a raw SocketCAN handle: the socket is bound to the interface.
Effects: fail, io.
canSend
function canSend(h: Device.Handle, frame: CanFrame): i64 throws stringSends one frame on the CAN handle; gives the bytes written (16).
Effects: fail, io.
canReceive
function canReceive(h: Device.Handle): CanFrame throws stringReceives one frame from the CAN handle, waiting for it.
Effects: fail, io.