Skip to main content

Module hal

Module hal 

Source
Expand description

Minimal hardware abstraction for IoT hosts.

Host firmware implements these traits and registers matching FFI callbacks. The simulated implementation below is used for desktop demos and tests.

Structs§

SimulatedHal
Desktop/simulator HAL: 32 virtual GPIO pins + a tick counter for delay. PWM duty/freq tables, UART loopback buffers, and I2C/SPI echo devices.

Traits§

Adc
Delay
Gpio
I2c
Pwm
Spi
Uart

Functions§

builtin_adc_read
adc_read(channel) 鈫?int raw
builtin_delay_ms
delay_ms(ms) 鈥?simulated; advances the HAL clock only.
builtin_gpio_read
gpio_read(pin) 鈫?bool
builtin_gpio_write
gpio_write(pin, high) 鈥?pin: int, high: bool
builtin_i2c_xfer
i2c_xfer(addr, hexdata, rlen) 鈫?hex string of rlen response bytes.
builtin_pwm_freq
pwm_freq(pin, hz)
builtin_pwm_write
pwm_write(pin, duty) 鈥?duty is 16-bit (0..=65535).
builtin_spi_xfer
spi_xfer(addr, hexdata, rxlen) 鈫?hex string of rxlen response bytes.
builtin_uart_read
uart_read(port, n) 鈫?string of up to n bytes (UTF-8 lossy).
builtin_uart_write
uart_write(port, s) 鈥?writes UTF-8 bytes of s (looped back in sim).
sim_drive_pin
Test/demo helper: force an external pin level.
sim_elapsed_ms
Test/demo helper: read simulated elapsed ms.
sim_i2c_last_write
Test/demo helper: last I2C write payload for addr.
sim_pwm_duty
Test/demo helper: PWM duty currently programmed on pin.
sim_pwm_freq
Test/demo helper: PWM frequency currently programmed on pin.
sim_set_adc
Test/demo helper: inject a simulated ADC reading.

Type Aliases§

I2cAddr
Pin
Port