Skip to content

Commit e4873c2

Browse files
Powerbyte7urish
authored andcommitted
refactor: use typed callbacks
1 parent 73b2d43 commit e4873c2

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
wokwi_chip_ll = "0.1"
7+
wokwi_chip_ll = "0.2"
88

99
[lib]
1010
crate-type = ["cdylib"]

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ fn draw_line(chip: &Chip, row: u32, color: u32) {
3838
}
3939
}
4040

41-
pub unsafe fn on_timer_fired(user_data: *const c_void) {
42-
let mut chip = &mut CHIP_VEC[user_data as usize];
41+
pub extern "C" fn on_timer_fired(user_data: *mut c_void) {
42+
let chip = unsafe { &mut CHIP_VEC[user_data as usize] };
4343

4444
if chip.current_row == 0 {
45-
debugPrint(CString::new("First row!").unwrap().into_raw());
45+
unsafe {
46+
debugPrint(CString::new("First row!").unwrap().into_raw());
47+
}
4648
}
4749

4850
draw_line(chip, chip.current_row, DEEP_GREEN);
@@ -73,7 +75,7 @@ pub unsafe extern "C" fn chipInit() {
7375

7476
let timer_config = TimerConfig {
7577
user_data: (CHIP_VEC.len() - 1) as *const c_void,
76-
callback: on_timer_fired as *const c_void,
78+
callback: on_timer_fired,
7779
};
7880

7981
let timer = timerInit(&timer_config);

0 commit comments

Comments
 (0)