Skip to content

Implemented Apple Silicon support via D2xx drivers for Rust.

Due to issues with Apple Silicon MacOS drivers for the FT230x USB-serial converter chip on the drone, it was not possible to use this library with apple devices. Using the D2xx drivers provided by FTDI, I have implemented support for apple silicon devices.

The newly added connection.rs exposes a new Port enum with read, read_exact and write_all functions. D2xx and Tty connections are established with open_d2xx and open_tty functions respectively, with path(for tty), baud rate and timeout parameters. The upload functions are unchanged, except for a new PortSelector::D2xx enum variant that selects the new driver.

Here is the example usage of the library:

fn main() {
    // get a filename from the command line. This filename will be uploaded to the drone
    // note that if no filename is given, the upload to the drone does not fail.
    // `upload_file_or_stop` will still try to detect the serial port on which the drone
    // is attached. This may be useful if you don't want to actually change the code on the
    // drone, but you do want to rerun your UI. In that case you simply don't provide any
    // command line parameter.
    // For using with MacOS,
    let file = args().nth(1);
    let path = upload_file_or_stop(PortSelector::D2xx, file);

    // The code below shows a very simple start to a PC-side receiver of data from the drone.
    // You can extend this into an entire interface to the drone written in Rust. However,
    // if you are more comfortable writing such an interface in any other programming language
    // you like (for example, python isn't a bad choice), you can also call that here. The
    // commented function below gives an example of how to do that with python, but again
    // you don't need to choose python.

    // start_interface(&port);

    // open the serial port we got back from `upload_file_or_stop`. This is the same port
    // as the upload occurred on, so we know that we can communicate with the drone over
    // this port.
    let mut serial = if path.as_os_str().is_empty() {
        open_d2xx(115_200, Duration::from_millis(500)).wrap_err("Failed to open d2xx")
    } else {
        open_tty(&path, 115_200, Duration::from_millis(500)).wrap_err("Failed to open tty")
    }.unwrap();

    // infinitely print whatever the drone sends us
    let mut buf = [0u8; 255];
    loop {
        if let Ok(num) = serial.read(&mut buf) {
            print!("{}", String::from_utf8_lossy(&buf[0..num]));
        }
    }
}
Edited by Ilgaz Er

Merge request reports

Loading