15 releases (breaking)

0.12.0 Jun 9, 2024
0.11.0 Oct 2, 2023
0.10.0 Aug 6, 2023
0.9.0 May 4, 2022
0.3.0 Feb 27, 2021

#114 in Embedded development

Download history 47/week @ 2024-07-08 39/week @ 2024-07-15 134/week @ 2024-07-22 71/week @ 2024-07-29 96/week @ 2024-08-05 48/week @ 2024-08-12 59/week @ 2024-08-19 50/week @ 2024-08-26 46/week @ 2024-09-02 93/week @ 2024-09-09 96/week @ 2024-09-16 127/week @ 2024-09-23 64/week @ 2024-09-30 29/week @ 2024-10-07 52/week @ 2024-10-14 51/week @ 2024-10-21

208 downloads per month
Used in 5 crates

MIT license

425KB
3.5K SLoC

w5500-hl

Platform agnostic rust driver for the Wiznet W5500 internet offload chip.

This crate contains higher level (hl) socket operations, built on-top of my other crate, w5500-ll, which contains register accessors, and networking data types for the W5500.

Design

There are no separate socket structures. The Tcp and Udp traits provided in this crate simply extend the Registers trait provided in w5500-ll. This makes for a less ergonomic API, but a much more portable API because there are no mutexes or runtime checks to enable socket structures to share ownership of the underlying W5500 device.

You will likely want to wrap up the underlying structure that implements the Registers, Tcp, and Udp traits to provide separate socket structures utilizing whatever Mutex is available for your platform / RTOS.

Feature Flags

All features are disabled by default.

Examples

UDP sockets

use w5500_hl::ll::{
    net::{Ipv4Addr, SocketAddrV4},
    Registers,
    Sn::Sn0,
};
use w5500_hl::Udp;

// open Sn0 as a UDP socket on port 1234
w5500.udp_bind(Sn0, 1234)?;

// send 4 bytes to 192.168.2.4:8080, and get the number of bytes transmitted
let data: [u8; 4] = [0, 1, 2, 3];
let destination = SocketAddrV4::new(Ipv4Addr::new(192, 168, 2, 4), 8080);
let tx_bytes = w5500.udp_send_to(Sn0, &data, &destination)?;

TCP streams (client)

use w5500_hl::ll::{
    net::{Ipv4Addr, SocketAddrV4},
    Registers, Sn,
};
use w5500_hl::Tcp;

const MQTT_SOCKET: Sn = Sn::Sn0;
const MQTT_SOURCE_PORT: u16 = 33650;
const MQTT_SERVER: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 168, 2, 10), 1883);

// initiate a TCP connection to a MQTT server
w5500.tcp_connect(MQTT_SOCKET, MQTT_SOURCE_PORT, &MQTT_SERVER)?;

TCP listeners (server)

use w5500_hl::ll::{
    net::{Ipv4Addr, SocketAddrV4},
    Registers, Sn,
};
use w5500_hl::Tcp;

const HTTP_SOCKET: Sn = Sn::Sn1;
const HTTP_PORT: u16 = 80;

// serve HTTP
w5500.tcp_listen(HTTP_SOCKET, HTTP_PORT)?;

Dependencies

~175KB