Skip to main content

Crate pico_de_gallo_hal

Crate pico_de_gallo_hal 

Source
Expand description

embedded-hal and embedded-hal-async implementations backed by a Pico de Gallo USB bridge.

This crate lets you run embedded Rust drivers on a host machine by forwarding I2C, SPI, GPIO, PWM, ADC, 1-Wire, and delay operations to a Pico de Gallo device over USB.

§Quick Start

use pico_de_gallo_hal::Hal;
use embedded_hal::i2c::I2c;

let hal = Hal::new();
let mut i2c = hal.i2c();

// Read 2 bytes from a TMP102 temperature sensor
let mut buf = [0u8; 2];
i2c.write_read(0x48, &[0x00], &mut buf).unwrap();

§Blocking vs. Async

Both embedded-hal (blocking) and embedded-hal-async traits are implemented. The HAL automatically detects whether it is running inside a tokio runtime and adjusts its execution strategy:

  • Inside tokio: Uses tokio::task::block_in_place to avoid blocking the async executor while waiting for USB responses.
  • Outside tokio: Blocks directly on the tokio handle.

This means the same Hal instance works in both synchronous test code and async application code.

§Implemented Traits

PeripheralBlocking TraitAsync Trait
GPIOOutputPin, InputPin, StatefulOutputPinWait
I2CI2cI2c
SPISpiBus, SpiDeviceSpiBus, SpiDevice
PWMSetDutyCycle
DelayDelayNsDelayNs

Structs§

Delay
Delay provider using host-side timers.
Gpio
GPIO pin handle implementing [embedded-hal] digital traits.
GpioEvent
A GPIO event notification published by the firmware.
Hal
Top-level HAL context for a Pico de Gallo device.
I2c
I2C bus handle implementing [embedded-hal] I2C traits.
OneWire
1-Wire bus handle backed by PIO hardware on the firmware.
PwmChannel
A single PWM channel on the Pico de Gallo board.
Spi
SPI bus handle implementing [embedded-hal] SPI traits.
SpiConfigurationInfo
Current SPI bus configuration as reported by the firmware.
SpiDev
SPI device handle implementing [embedded-hal] SpiDevice traits.
Uart
UART handle implementing [embedded-io] traits.
UartConfigurationInfo
Current UART bus configuration as reported by the firmware.

Enums§

AdcHalError
Error type for ADC HAL operations.
GpioHalError
Error type for GPIO HAL operations.
I2cFrequency
I2C bus clock frequency.
I2cHalError
Error type for I2C HAL operations.
OneWireHalError
Error type for 1-Wire HAL operations.
PwmHalError
Error type for PWM HAL operations.
SpiHalError
Error type for SPI HAL operations.
SpiPhase
SPI clock phase setting.
SpiPolarity
SPI clock polarity setting.
UartHalError
Error type for UART HAL operations.