Skip to content

Instantly share code, notes, and snippets.

@urish
Last active April 5, 2024 20:39
Show Gist options
  • Save urish/92a0b95022e23cdb846d17824913b6c1 to your computer and use it in GitHub Desktop.
Save urish/92a0b95022e23cdb846d17824913b6c1 to your computer and use it in GitHub Desktop.
Rust inverter chip (prototype API)
// Wokwi Custom Chips with Rust
use wokwi_chips_api::println;
use wokwi_chips_api::pin::{Pin, PinMode, WatchEdge};
// chipInit() will be called once per chip instance.
#[no_mangle]
pub unsafe extern "C" fn chipInit() {
println!("Hello from Rust Chip!");
let pin_in = Pin::new("IN", PinMode::Input);
let pin_out = Pin::new("OUT", PinMode::Output);
pin_out.write(!pin_in.read());
pin_in.watch(WatchEdge::Both, move |_pin, value| {
pin_out.write(!value);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment