w5500

package
v0.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package w5500 implements a driver for the W5500 Ethernet controller.

The driver supports basic network functionality including TCP and UDP sockets. It currently does not use the IRQ or RST pins.

Datasheet: https://docs.wiznet.io/img/products/w5500/W5500_ds_v110e.pdf Product Page: https://wiznet.io/products/ethernet-chips/w5500

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DNS Resolver

	MAC        net.HardwareAddr
	IP         netip.Addr
	SubnetMask netip.Addr
	Gateway    netip.Addr

	// Optional, default is 8.
	MaxSockets int
}

Config is the configuration for the device.

The SPI bus must be fully configured.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device is a driver for the W5500 Ethernet controller.

func New

func New(bus drivers.SPI, csPin pin.Output) *Device

New returns a new w5500 driver.

func (*Device) Accept

func (d *Device) Accept(sockfd int) (int, netip.AddrPort, error)

Accept waits for an incoming connection on the specified socket file descriptor.

func (*Device) Addr

func (d *Device) Addr() (netip.Addr, error)

Addr returns the IP address of the device.

func (*Device) Bind

func (d *Device) Bind(sockfd int, ip netip.AddrPort) error

func (*Device) Close

func (d *Device) Close(sockfd int) error

Close closes the socket with the given file descriptor.

func (*Device) Configure

func (d *Device) Configure(cfg Config) error

Configure sets up the device.

MAC address must be provided. The other fields are optional.

func (*Device) Connect

func (d *Device) Connect(sockfd int, host string, ip netip.AddrPort) error

Connect establishes a connection to the specified host and port or ip and port.

If the host is an empty string, it will use the provided ip address and port, otherwise it will resolve the host name to an IP address.

func (*Device) GetHardwareAddr

func (d *Device) GetHardwareAddr() (net.HardwareAddr, error)

GetHardwareAddr returns the hardware address of the device.

func (*Device) GetHostByName

func (d *Device) GetHostByName(name string) (netip.Addr, error)

GetHostByName resolves the given host name to an IP address.

func (*Device) LinkInfo

func (d *Device) LinkInfo() string

LinkInfo returns the current link information of the device.

func (*Device) LinkStatus

func (d *Device) LinkStatus() LinkStatus

LinkStatus returns the current link status of the device.

func (*Device) Listen

func (d *Device) Listen(sockfd int, _ int) error

Listen sets the socket to listen for incoming connections on the specified socket file descriptor.

The backlog parameter is ignored, as the W5500 does not support it.

func (*Device) Recv

func (d *Device) Recv(sockfd int, buf []byte, _ int, deadline time.Time) (int, error)

Recv reads data from the socket with the given file descriptor into the provided buffer. It blocks until data is available or the deadline is reached.

func (*Device) Reset

func (d *Device) Reset()

Reset performs a soft reset.

func (*Device) Send

func (d *Device) Send(sockfd int, buf []byte, _ int, deadline time.Time) (int, error)

Send sends data to the socket with the given file descriptor. It blocks until all data is sent or the deadline is reached.

func (*Device) SetAddr

func (d *Device) SetAddr(ip netip.Addr) error

SetAddr sets the IP address of the device.

The IP address must be a valid IPv4 address.

func (*Device) SetGateway

func (d *Device) SetGateway(gateway netip.Addr) error

SetGateway sets the gateway address of the device.

The gateway must be a valid IPv4 address. It is not checked if the gateway is in the same subnet as the device.

func (*Device) SetSockOpt

func (d *Device) SetSockOpt(int, int, int, any) error

SetSockOpt sets the socket option for the given socket file descriptor. It is not supported by the W5500, so it always returns an error.

func (*Device) SetSubnetMask

func (d *Device) SetSubnetMask(mask netip.Addr) error

SetSubnetMask sets the subnet mask of the device.

The subnet mask must be a valid IPv4 address. It is not checked if the subnet mask is valid for the device's IP address.

func (*Device) Socket

func (d *Device) Socket(domain int, stype int, protocol int) (int, error)

type LinkStatus

type LinkStatus = uint8

LinkStatus is the link status of the device.

const (
	LinkStatusDown LinkStatus = iota
	LinkStatusUp
)

LinkStatus values.

type Resolver

type Resolver func(host string) (netip.Addr, error)

Resolver is a function that resolves a hostname to an IP address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL