common_hal_interface
A common interface between Rust HALs, for use in the Iron Coder IDE.
One interface, any board. The same macro names work across all supported platforms - just change the feature flag.
Quick Start
[dependencies]
common_hal_interface = { version = "1.0.16-alpha", features = ["adafruit-feather-rp2040"] }
use common_hal_interface::*;
rp2040_setup!(pac, core, clocks, pins);
let i2c = setup_i2c!(pac, clocks, 400_000u32, I2C1, pins.sda, pins.scl);
Features
RP2040 Boards
| Feature |
Board |
BSP Crate |
adafruit-feather-rp2040 |
Adafruit Feather RP2040 |
adafruit-feather-rp2040 |
rp-pico |
Raspberry Pi Pico |
rp-pico |
rp2040 |
Raw HAL (no BSP) |
rp2040-hal |
Arduino Boards
| Feature |
Board |
arduino-uno |
Arduino Uno |
arduino-nano |
Arduino Nano |
arduino-mega2560 |
Arduino Mega 2560 |
arduino-leonardo |
Arduino Leonardo |
Other
| Feature |
Platform |
esp |
ESP32 family |
stm32f4 |
STM32F4 (WIP) |
Universal Macros
RP2040 (all boards)
| Macro |
Description |
rp2040_setup!(pac, core, clocks, pins) |
Initialize peripherals |
new_delay!(core, clocks) |
Create cortex-m delay |
new_timer!(pac, clocks) |
Create hardware timer |
setup_i2c!(pac, clocks, baud, I2Cx, sda, scl) |
Set up I2C |
setup_spi!(pac, clocks, baud, SPIx, mosi, miso, sck, mode) |
Set up SPI |
setup_uart!(pac, clocks, baud, UARTx, tx, rx) |
Set up UART |
setup_neopixel!(pac, pin, clocks, timer) |
Set up WS2812 NeoPixel |
setup_onboard_neopixel!(pac, pins, clocks, timer) |
Set up onboard NeoPixel |
Arduino
| Macro |
Description |
arduino_setup!(dp, pins) |
Initialize peripherals |
setup_serial!(dp, pins, baud) |
Set up serial |
setup_i2c!(dp, sda, scl, freq) |
Set up I2C |
setup_spi!(dp, sck, mosi, miso, ss) |
Set up SPI |
ESP
| Macro |
Description |
esp_setup!() |
Initialize peripherals |
delay_ms!(ms) |
Delay milliseconds |
setup_i2c!(peripheral, sda, scl, freq_khz) |
Set up I2C |
setup_spi!(peripheral, sck, mosi, miso, freq_khz) |
Set up SPI |
Example: Adafruit Feather RP2040
#![no_std]
#![no_main]
use adafruit_feather_rp2040::entry;
use panic_halt as _;
use ws2812_pio::Ws2812;
use common_hal_interface::*;
#[entry]
fn main() -> ! {
rp2040_setup!(pac, core, clocks, pins);
let mut delay = new_delay!(core, clocks);
let timer = new_timer!(pac, clocks);
let i2c = setup_i2c!(pac, clocks, 400_000u32, I2C1, pins.sda, pins.scl);
let ws = setup_neopixel!(pac, pins.d4, clocks, timer);
loop {
delay.delay_ms(100);
}
}
Switching Boards
To switch from Feather to Pico, just change:
Cargo.toml: features = ["rp-pico"]
use statement: use rp_pico::entry;
- Pin names (BSP-specific):
pins.gpio2 instead of pins.sda
The macro calls stay the same!
License
MIT