Crates.io | w5500 |
lib.rs | w5500 |
version | 0.5.0 |
source | src |
created_at | 2018-03-17 15:49:57.234215 |
updated_at | 2024-07-08 08:21:34.040715 |
description | W5500 IoT Controller implementation. |
homepage | |
repository | https://github.com/kellerkindt/w5500.git |
max_upload_size | |
id | 56129 |
size | 122,327 |
This crate is a driver for the WIZnet W5500 chip. The W5500 chip is a hardwired TCP/IP embedded Ethernet controller that enables embedded systems using SPI (Serial Peripheral Interface) to access the LAN. It is one of the more popular ethernet modules on Arduino platforms.
The embedded-hal
is a standard set
of traits meant to permit communication between MCU implementations and hardware drivers like this
one. Any microcontroller that implements the
spi::SpiDevice
or
spi::SpiBus
can use this
driver.
Below is a basic example of sending UDP packets to a remote host. An important thing to confirm is the configuration of the SPI implementation. It must be set up to work as the W5500 chip requires. That configuration is as follows:
use embedded_nal::{IpAddr, Ipv4Addr, SocketAddr};
#
# struct Mock;
#
# impl embedded_hal::spi::ErrorType for Mock {
# type Error = core::convert::Infallible;
# }
#
# impl embedded_hal::spi::SpiDevice for Mock {
# fn transaction(&mut self, operations: &mut [embedded_hal::spi::Operation<'_, u8>]) -> Result<(), Self::Error> {
# Ok(())
# }
# }
use embedded_nal::UdpClientStack;
let mut spi = Mock;
let mut device = w5500::UninitializedDevice::new(w5500::bus::FourWire::new(spi))
.initialize_manual(
w5500::MacAddress::new(0, 1, 2, 3, 4, 5),
Ipv4Addr::new(192, 168, 86, 79),
w5500::Mode::default()
).unwrap();
// Allocate a UDP socket to send data with
let mut socket = device.socket().unwrap();
// Connect the socket to the IP address and port we want to send to.
device.connect(&mut socket,
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(192, 168, 86, 38)), 8000),
).unwrap();
// Send the data
nb::block!(device.send(&mut socket, &[104, 101, 108, 108, 111, 10]));
// Optionally close the socket
device.close(socket);
In no particular order, things to do to improve this driver.