From 1a6eab88da269bdc8110aa0f09d6728f6249dbf3 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 29 Mar 2018 20:57:23 +0200 Subject: [PATCH] Add README.md with example usage --- Cargo.toml | 3 ++- README.md | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/Cargo.toml b/Cargo.toml index d49cc09..4772295 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,13 @@ [package] name = "w5500" -version = "0.1.1" +version = "0.1.2" authors = ["Michael Watzko "] 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 } diff --git a/README.md b/README.md new file mode 100644 index 0000000..25c54e3 --- /dev/null +++ b/README.md @@ -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(); + } +```