From 5658759cf359a2a8783a6c7f7f1f75bd275b8c7e Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 1 Mar 2021 23:32:38 -0800 Subject: [PATCH] Move active pointer code to Rust --- radio.c | 10 ---------- src/radio.rs | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/radio.c b/radio.c index bf0eede..68dddf1 100644 --- a/radio.c +++ b/radio.c @@ -59,16 +59,6 @@ static radio_tab_t radio_tab[] = { }; */ -static radio_device_t *active_device; // Device-dependent interface - -radio_device_t* get_active_device() { - return active_device; -} - -void set_active_device(radio_device_t* d) { - active_device = d; -} - // // Read the configuration from text file, and modify the firmware. // diff --git a/src/radio.rs b/src/radio.rs index 50d59c1..6bce35c 100644 --- a/src/radio.rs +++ b/src/radio.rs @@ -37,9 +37,6 @@ pub static mut radio_mem: [u8; 1024*1024*2] = [0; 1024*1024*2]; extern { - fn get_active_device() -> *const radio_device_t; - fn set_active_device(device: *const radio_device_t); - fn radio_parse_config(device: *const radio_device_t, filename: *const c_char); fn dfu_init(vid: c_uint, pid: c_uint) -> *const c_char; @@ -55,6 +52,18 @@ extern { fn serial_close(); } + +static mut active_device: *const radio_device_t = std::ptr::null(); // Device-dependent interface + +unsafe fn get_active_device() -> *const radio_device_t { + return active_device; +} + +unsafe fn set_active_device(d: *const radio_device_t) { + active_device = d; +} + + /// Connect to the radio via the serial port. /// and identify the type of device. pub fn connect() -> Radio {