Signal Utilities
Small stateless surfaces that do not own a peripheral: the bit-bang shift functions and the random generator.
For a square wave on a buzzer, a PWM channel at 50% duty does it in two calls — setPeriod(1_000_000_000 / hz) then setDuty(0.5); see Analog & PWM.
Shift Registers (Bit-Banging)
Two module functions — a bounded sequence of pin toggles, not a class:
import { shiftOut, shiftIn } from '@typecad/hal';
shiftOut(dataPin, clockPin, 0b10110001); // MSB-first by default
const b = shiftIn(dataPin, clockPin); // reads 8 bitsRandom Numbers
import { Random } from '@typecad/hal';
Random.seed(0xC0FFEE); // only when you want reproducibility
const die = Random.upTo(6); // 0–5
const pct = Random.between(1, 101); // 1–100
const big = Random.int(); // non-negative 31-bit integerOn Zephyr the generator is seeded from hardware entropy at boot, so seed() is only needed for deterministic sequences (tests, simulations).
API Reference
| Member | Description |
|---|---|
shiftOut(data, clock, value, msbFirst?) / shiftIn(data, clock, msbFirst?) | Bit-bang a byte out/in. |
Random.seed(v) / upTo(max) / between(min, max) / int() | PRNG. |
On This Page