Add README.md with example usage

This commit is contained in:
Michael Watzko 2018-03-29 20:57:23 +02:00
commit 1a6eab88da
2 changed files with 28 additions and 1 deletions

View file

@ -1,12 +1,13 @@
[package]
name = "w5500"
version = "0.1.1"
version = "0.1.2"
authors = ["Michael Watzko <michael@watzko.de>"]
repository = "https://github.com/kellerkindt/w5500.git"
description = "W5500 IoT Controller implementation. Currently UDP sending and receiving is working. WIP"
keywords = ["embedded", "w5500", "iot", "arm", "stm32"]
categories = ["embedded", "hardware-support", "no-std", "network-programming"]
license = "MIT"
readme = "README.md"
[dependencies]
byteorder = { version = "1.2.1", default-features = false }

26
README.md Normal file
View file

@ -0,0 +1,26 @@
# Example usage
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();
w5500.set_mode(false, false, false, false).unwrap();
w5500.set_mac(&MacAddress::new(0x00, 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();
}
```