The lowest hardware layer: pins, timing, pulse width, I2C and UART, backed by the board runtime or an in-memory simulation.
import hw.board
hw.board is the lowest layer. Everything else in the hardware family calls it, and it is the only package that changes between a real board and a computer: on a freestanding build its functions call the board runtime, and on a computer they work on a model kept in memory. Most programs use hw.gpio, hw.i2c and hw.uart instead and reach for hw.board only for timing and for the Sim functions that feed the simulation.
Reading and writing pins
Set a mode with GpioMode, then drive the pin with GpioWrite or read it with GpioRead. Any non-zero write is stored as 1, and a pin number outside 0 to 63 reads 0.
On a computer the board is a model you control: SimSetPulse sets what a pulse measurement returns, SimInject queues bytes that look like they came from the wire and SimTaken collects what the program sent. This is how the sensor drivers are tested without hardware.
Measures how long a pin stays at a level, in microseconds, giving up after the timeout. In the simulation it returns the width set with SimSetPulse, or 0 when none is set or it is longer than the timeout.
funcI2cWrite(bus: int, addr: int, reg: int, value: int): int
Writes one byte to a register of an I2C device. Returns 0 on success. The simulation keeps the registers per bus, address and register, and stores the low 8 bits.
Puts a simulated DS18B20 on a pin of the simulated board, with the given serial number in its ROM code (family code 0x28 first, the CRC last). It answers resets, ROM commands, conversions and scratchpad reads with the 1-Wire timings, so a driver that gets a slot wrong reads nothing. A pin outside 0 to 63 removes it. Does nothing on hardware.
Sets the temperature the simulated DS18B20 measures, in thousandths of a degree Celsius. The result of the next conversion is rounded to the resolution. Does nothing on hardware.
Puts a simulated DHT11 or DHT22 (kind 11 or 22) on a pin of the simulated board, with the humidity and the temperature in tenths. After a start signal long enough for the kind (18 ms for the DHT11, 0.8 ms for the DHT22) PulseIn on that pin returns the response pulses and the 40 data bits with the widths of the real protocol. A pin outside 0 to 63 removes it. Does nothing on hardware.
Wires one pin to read as another in the simulation: after SimLink(source, reader), GpioRead(reader) returns the level of the source pin. Link MOSI to MISO for an SPI loopback. A source outside 0 to 63 removes the link. Does nothing on hardware.
funcWifiCall(op: int, a: int, b: int, c: int): int
The numeric radio hook for Wi-Fi: op picks a salam_rt_wifi_* hook (0 init, 1 scan, 2 scan field, 3 disconnect, 4 state, 5 info, 6 TCP write, 7 TCP flush, 8 TCP read, 9 TCP close) and a, b and c are its arguments. Returns -1 on a computer and on boards without a radio. The hw.wifi package is the friendly way to call it.
funcWifiCallStr(op: int, s: str, t: str, a: int): int
The Wi-Fi hook with text arguments: op 0 connect (ssid s, password t), 1 start the access point (ssid s, password t, channel a), 2 open a TCP socket (host s, port a). Returns -1 on a computer and on boards without a radio.
The numeric radio hook for Bluetooth Low Energy: op picks a salam_rt_ble_* hook (0 advertise, 1 scan, 2 scan field, 3 to 6 characteristic values and notify, 7 to 8 and 13 write events, 9 disconnect, 10 read byte, 11 to 12 write staging, 14 connected). Returns -1 on a computer and on boards without a radio. The hw.ble package is the friendly way to call it.
funcBleCallStr(op: int, s: str, a: int, b: int): int
The Bluetooth hook with a text argument: op 0 init (name s), 1 add a service (uuid s), 2 add a characteristic (uuid s, service a, properties b), 3 connect (address s), 4 read (uuid s), 5 write (uuid s). Returns -1 on a computer and on boards without a radio.