Last active
April 5, 2024 20:39
-
-
Save urish/92a0b95022e23cdb846d17824913b6c1 to your computer and use it in GitHub Desktop.
Rust inverter chip (prototype API)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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