12次发布
0.5.0 | 2024年7月8日 |
---|---|
0.4.1 | 2023年1月2日 |
0.4.0 | 2022年1月23日 |
0.3.0 | 2020年6月10日 |
0.1.2 | 2018年3月29日 |
#1 in #spi-driver
57 每月下载
在 2 crates 中使用
105KB
2K SLoC
W5500 驱动器
此crate是WIZnet W5500芯片的驱动程序。W5500芯片是一个硬连接的TCP/IP嵌入式以太网控制器,它使使用SPI(串行外围接口)的嵌入式系统能够访问LAN。它是Arduino平台最受欢迎的以太网模块之一。
嵌入式HAL
embedded-hal
是一组旨在允许MCU实现与硬件驱动程序(如本例中的驱动程序)之间通信的特质。任何实现了 spi::SpiDevice
或 spi::SpiBus
的微控制器都可以使用此驱动程序。
示例用法
以下是一个向远程主机发送UDP数据包的基本示例。一个重要的事情是确认SPI实现的配置。它必须设置成符合W5500芯片的要求。该配置如下:
- 数据顺序:最高有效位优先
- 时钟极性:空闲低
- 时钟相位:采样前缘
- 时钟速度:最大33MHz
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);
待办事项
以下是一些改进此驱动程序的待办事项,无特定顺序。
- 添加对TCP服务器实现的支持
- 添加对DHCP的支持
依赖关系
~2MB
~42K SLoC