lan8720

package module
v0.0.0-...-fadec3e Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

README

lan8720

go.dev reference Go Report Card Go sourcegraph

LAN 8720 driver for the Go programming language.

Documentation

Overview

Package lan8720 provides a driver for the LAN8720 Ethernet PHY transceiver.

The LAN8720 is a low-power 10BASE-T/100BASE-TX Ethernet PHY commonly used with RMII (Reduced Media Independent Interface) to connect microcontrollers to Ethernet networks. This package provides abstractions for configuring the PHY and interfacing with RMII hardware implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// PHYAddr is the MDIO address of the PHY. Most LAN8720 breakout boards
	// use address 1 by default, but this can vary based on hardware strapping.
	// Valid range is 0-31.
	PHYAddr uint8
	// Advertisement is the autonegotiation mode.
	Advertisement phy.ANAR
}

Config holds the configuration parameters for initializing a LAN8720 device.

type DeviceSingle

type DeviceSingle struct {
	PHY
	RMIISingle
}

DeviceSingle combines a LAN8720 PHY with single-frame RMII transmit and receive capabilities. This is the primary type for applications that need complete Ethernet PHY functionality with simple frame-by-frame operation.

func (*DeviceSingle) Configure

func (ds *DeviceSingle) Configure(mdio phy.MDIOBus, rmii RMIISingle, cfg Config) error

type PHY

type PHY struct {
	phy.Device
}

PHY represents a LAN8720 Ethernet PHY. It wraps the generic PHY device from the phy package and provides LAN8720-specific functionality. Use Configure to initialize the device before use.

func (*PHY) Configure

func (d *PHY) Configure(mdio phy.MDIOBus, cfg Config) (err error)

Configure initializes the LAN8720 device with the given MDIO bus and configuration. The mdio parameter provides access to the PHY's management registers. This must be called before using any other Device methods.

func (*PHY) WaitAutoNegotiation

func (d *PHY) WaitAutoNegotiation(timeout time.Duration) (phy.LinkMode, error)

WaitAutoNegotiation waits for auto-negotiation to complete and link to establish. The timeout specifies the maximum duration to wait. On success, returns the negotiated link mode. Returns an error if timeout expires or PHY communication fails.

It is suggested the timeout be at least 2 seconds to give LAN8720 enough time to autonegotiate.

type RMIIRxSingle

type RMIIRxSingle interface {
	// StopRx stops the receiver and aborts any ongoing reception.
	// Returns an error if the receiver is already stopped.
	StopRx() error
	// StartRxSingle enables asynchronous reception of a single frame.
	// After a frame is received, the RMII receiver automatically stops
	// and invokes the callback set via SetRxHandler. Call StartRxSingle
	// again to receive the next frame.
	StartRxSingle() error
	// SetRxHandler configures the receive buffer and callback function.
	// When a frame is received, the callback is invoked with the portion
	// of rxbuf containing the received data. Must be called before StartRxSingle.
	SetRxHandler(rxbuf []byte, callback func(buf []byte)) (err error)
	// InRx returns true if the receiver is actively listening for a frame
	// (i.e., StartRxSingle was called and no frame has been received yet).
	InRx() bool
}

RMIIRxSingle defines the interface for receiving Ethernet frames over RMII in single-frame mode. After receiving a frame, the receiver stops listening until explicitly restarted, allowing the application to process the frame without buffer overrun concerns.

type RMIISingle

type RMIISingle interface {
	RMIIRxSingle
	RMIITxSingle
}

RMIISingle combines both receive and transmit capabilities for single-frame RMII operation. This interface is suitable for simple, non-concurrent Ethernet communication where frames are processed one at a time.

type RMIITxSingle

type RMIITxSingle interface {
	// IsSending returns true if a frame transmission is currently in progress.
	// Use this to poll for transmission completion before sending another frame.
	IsSending() bool
	// SendFrame transmits a single Ethernet frame over RMII. The frame should
	// contain a complete Ethernet frame (destination MAC, source MAC, EtherType,
	// and payload). The implementation handles preamble, SFD, and CRC generation.
	// Returns an error if transmission cannot be initiated (e.g., busy).
	SendFrame(frame []byte) error
}

RMIITxSingle defines the interface for transmitting Ethernet frames over RMII in single-frame mode. Implementations handle the low-level timing and signaling required by the RMII specification.

Directories

Path Synopsis
examples
pico-pcap command

Jump to

Keyboard shortcuts

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