1- use std:: { ffi:: { c_void, CString } , os :: raw :: c_char } ;
1+ use std:: ffi:: { c_void, CString } ;
22
3- // --- API Declaration ---
4-
5- type PinId = i32 ;
6-
7- #[ repr( C ) ]
8- pub struct WatchConfig {
9- user_data : * const c_void ,
10- edge : u32 ,
11- pin_change : * const c_void ,
12- }
13-
14- /* Just a stub to specify the Chip API version */
15- #[ no_mangle]
16- pub unsafe extern "C" fn __wokwi_api_version_1 ( ) -> u32 { return 0 ; }
17-
18- extern "C" {
19- fn pinInit ( name : * const c_char , mode : u32 ) -> PinId ;
20- fn pinRead ( pin : PinId ) -> u32 ;
21- fn pinWrite ( pin : PinId , value : u32 ) ;
22- fn pinWatch ( pin : PinId , watch_config : * const WatchConfig ) -> bool ;
23- fn debugPrint ( message : * const c_char ) ;
24- }
25-
26- /* Pin values */
27- const LOW : u32 = 0 ;
28- const HIGH : u32 = 1 ;
29-
30- /* Pin modes */
31- const INPUT : u32 = 0 ;
32- const OUTPUT : u32 = 1 ;
33- const INPUT_PULLUP : u32 = 2 ;
34- const INPUT_PULLDOWN : u32 = 3 ;
35- const ANALOG : u32 = 4 ;
36- const OUTPUT_LOW : u32 = 16 ;
37- const OUTPUT_HIGH : u32 = 16 ;
38-
39- /* Pin edges */
40- const RISING : u32 = 1 ;
41- const FALLING : u32 = 2 ;
42- const BOTH : u32 = 3 ;
43-
44- /// --- Implementation ---
3+ use wokwi_chip_ll:: {
4+ debugPrint, pinInit, pinWatch, pinWrite, PinId , WatchConfig , BOTH , HIGH , INPUT , LOW , OUTPUT ,
5+ } ;
456
467struct Chip {
478 pin_in : PinId ,
@@ -59,7 +20,7 @@ pub unsafe fn on_pin_change(user_data: *const c_void, _pin: PinId, value: u32) {
5920
6021#[ no_mangle]
6122pub unsafe extern "C" fn chipInit ( ) {
62- debugPrint ( CString :: new ( "Hello rust !" ) . unwrap ( ) . into_raw ( ) ) ;
23+ debugPrint ( CString :: new ( "Hello rusty !" ) . unwrap ( ) . into_raw ( ) ) ;
6324
6425 let chip = Chip {
6526 pin_in : pinInit ( CString :: new ( "IN" ) . unwrap ( ) . into_raw ( ) , INPUT ) ,
0 commit comments