Rust W5100 Ethernet driver
Find a file
Michael Watzko 1415adbae0 GH-3: Refactor to allow to state tracking of sockets, take an &mut SPI while 'activated'
The activated mode allows one to call functions without passing the SPI reference
each time, while not consuming it for the lifetime of W5500.
2019-02-12 23:09:34 +01:00
src GH-3: Refactor to allow to state tracking of sockets, take an &mut SPI while 'activated' 2019-02-12 23:09:34 +01:00
.gitignore Add gitlab mirror script 2018-03-18 20:48:15 +01:00
.gitlab-ci.yml Add gitlab mirror script 2018-03-18 20:48:15 +01:00
Cargo.lock Remvoe unused feature requirement 2018-10-27 19:43:11 +02:00
Cargo.toml GH-3: Refactor to allow to state tracking of sockets, take an &mut SPI while 'activated' 2019-02-12 23:09:34 +01:00
LICENSE-APACHE GH-3: Clarify licensing 2019-02-12 17:25:17 +01:00
LICENSE-MIT GH-3: Clarify licensing 2019-02-12 17:25:17 +01:00
README.md Use a locally administered MAC address 2018-03-29 21:22:27 +02:00

Example usage

Below some really basic usage how I am ca using it:

    let spi = ...; // SPI interface to use
    let cs : OutputPin = ...; // chip select
    
    let mut w5500 = W5500::new(spi, cs).unwrap();

    w5500.set_mode(false, false, false, false).unwrap();
    // using a 'locally administered' MAC address
    w5500.set_mac(&MacAddress::new(0x02, 0x01, 0x02, 0x03, 0x04, 0x05)).unwrap();
    w5500.set_ip(&IpAddress::new(192, 168, 0, 222)).unwrap();
    w5500.set_subnet(&IpAddress::new(255, 255, 255, 0)).unwrap();
    w5500.set_gateway(&IpAddress::new(192, 168, 0, 1)).unwrap();

    w5500.listen_udp(Socket::Socket1, 51).unwrap();
    let buffer = [u8; 2048];
    
    if let Some((ip, port, size)) = w5500.try_receive_udp(socket_rcv, &mut buffer).unwrap() {
        let (request_buffer, response_buffer) = buffer.split_mut_at(size);
        // ...

        w5500.send_udp(Socket::Socket0, 50, &ip, port, &response_buffer[..response_size]).unwrap();
    }