GH-3: Update README as well

This commit is contained in:
Michael Watzko 2019-02-12 23:23:28 +01:00
commit 4708d31518

View file

@ -3,25 +3,33 @@
Below some really basic usage how I am ca using it: Below some really basic usage how I am ca using it:
```rust ```rust
let spi = ...; // SPI interface to use let mut w5500: Option<W5500> = W5500::with_initialisation(
let cs : OutputPin = ...; // chip select &mut cs_w5500, // borrowed for whole W5500 lifetime
&mut spi, // borrowed for call to `with_initialisation` only
let mut w5500 = W5500::new(spi, cs).unwrap(); OnWakeOnLan::Ignore,
OnPingRequest::Respond,
ConnectionType::Ethernet,
ArpResponses::Cache,
)
.ok();
w5500.set_mode(false, false, false, false).unwrap(); let mut udp_server_socket: Option<UdpSocket> = w5500.as_mut().and_then(|w5500| {
// using a 'locally administered' MAC address let mut w5500: ActiveW5500<_> = w5500.activate(&mut spi).ok()?;
w5500.set_mac(&MacAddress::new(0x02, 0x01, 0x02, 0x03, 0x04, 0x05)).unwrap(); let socket0: UninitializedSocket = w5500.take_socket(Socket::Socket0)?;
w5500.set_ip(&IpAddress::new(192, 168, 0, 222)).unwrap(); (&mut w5500, socket0).try_into_udp_server_socket(1234).ok()
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 mut buffer = [0u8; 256];
let buffer = [u8; 2048]; if let (Some(ref mut w5500), Some(ref socket)) = (
w5500.as_mut().and_then(w5500.activate(&mut spi).ok()),
if let Some((ip, port, size)) = w5500.try_receive_udp(socket_rcv, &mut buffer).unwrap() { udp_server_socket,
let (request_buffer, response_buffer) = buffer.split_mut_at(size); ) {
// ... if let Ok(Some((ip, port, len))) = (w5500, socket).receive(&mut buffer[..]) {
let (request_buffer, response_buffer) = buffer.split_mut_at(len);
w5500.send_udp(Socket::Socket0, 50, &ip, port, &response_buffer[..response_size]).unwrap(); //...
(w5500, socket).blocking_send(ip, port, 1234, response_buffer[..response_len]).unwrap();
}
} }
``` ```