GH-3: Update README as well
This commit is contained in:
parent
1415adbae0
commit
4708d31518
1 changed files with 25 additions and 17 deletions
42
README.md
42
README.md
|
|
@ -3,25 +3,33 @@
|
|||
Below some really basic usage how I am ca using it:
|
||||
|
||||
```rust
|
||||
let spi = ...; // SPI interface to use
|
||||
let cs : OutputPin = ...; // chip select
|
||||
|
||||
let mut w5500 = W5500::new(spi, cs).unwrap();
|
||||
let mut w5500: Option<W5500> = W5500::with_initialisation(
|
||||
&mut cs_w5500, // borrowed for whole W5500 lifetime
|
||||
&mut spi, // borrowed for call to `with_initialisation` only
|
||||
OnWakeOnLan::Ignore,
|
||||
OnPingRequest::Respond,
|
||||
ConnectionType::Ethernet,
|
||||
ArpResponses::Cache,
|
||||
)
|
||||
.ok();
|
||||
|
||||
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();
|
||||
let mut udp_server_socket: Option<UdpSocket> = w5500.as_mut().and_then(|w5500| {
|
||||
let mut w5500: ActiveW5500<_> = w5500.activate(&mut spi).ok()?;
|
||||
let socket0: UninitializedSocket = w5500.take_socket(Socket::Socket0)?;
|
||||
(&mut w5500, socket0).try_into_udp_server_socket(1234).ok()
|
||||
});
|
||||
|
||||
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);
|
||||
// ...
|
||||
let mut buffer = [0u8; 256];
|
||||
if let (Some(ref mut w5500), Some(ref socket)) = (
|
||||
w5500.as_mut().and_then(w5500.activate(&mut spi).ok()),
|
||||
udp_server_socket,
|
||||
) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue