hid

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FEATURE_RPT_SIZE                    = 8
	FEATURE_RPT_DATA_SIZE               = FEATURE_RPT_SIZE - 1
	SLOT_DATA_SIZE                      = 64
	FRAME_SIZE                          = SLOT_DATA_SIZE + 6
	RESP_PENDING_FLAG                   = 0x40 // response pending
	SLOT_WRITE_FLAG                     = 0x80 // write flag
	RESP_TIMEOUT_WAIT_FLAG              = 0x20 // waiting for touch/timeout
	DUMMY_REPORT_WRITE                  = 0x8F // not used directly here, kept for parity
	SEQUENCE_MASK                       = 0x1F
	STATUS_OFFSET_PROG_SEQ              = 0x4
	STATUS_OFFSET_TOUCH_LOW             = 0x5
	CONFIG_SLOTS_PROGRAMMED_MASK        = 0b00000011
	STATUS_PROCESSING                   = 1
	STATUS_UPNEEDED                     = 2
	CRC_OK_RESIDUAL              uint16 = 0xF0B8
)

Variables

This section is empty.

Functions

func Enumerate

func Enumerate() iter.Seq2[*Device, error]

Types

type CommandRejectedError

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

func (*CommandRejectedError) Error

func (e *CommandRejectedError) Error() string

type Conn

type Conn interface {
	Receive() ([]byte, error) // must return exactly 8 bytes
	Send([]byte) error        // must accept exactly 8 bytes
	Close() error
}

Conn representing an 8-byte HID feature report connection.

type Device

type Device struct {
	Path         string // Platform-Specific Device Path
	VendorID     uint16 // Device Vendor ID
	ProductID    uint16 // Device Product ID
	SerialNbr    string // Serial Number
	ReleaseNbr   uint16 // Device Version Number
	MfrStr       string // Manufacturer String
	ProductStr   string // Product String
	UsagePage    uint16 // Usage Page for Device/Interface
	Usage        uint16 // Usage for Device/Interface
	InterfaceNbr int    // USB Interface Number
}

func (*Device) Open

func (dev *Device) Open() (*HidrawOtpConn, error)

Open opens a hidraw path like '/dev/hidraw2' for OTP feature reports.

type HidrawOtpConn

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

HidrawOtpConn implements OtpConnection using Linux hidraw feature report ioctls.

func (*HidrawOtpConn) Close

func (c *HidrawOtpConn) Close() error

func (*HidrawOtpConn) Receive

func (c *HidrawOtpConn) Receive() ([]byte, error)

Receive gets an 8-byte feature report payload (without the report ID).

func (*HidrawOtpConn) Send

func (c *HidrawOtpConn) Send(data []byte) error

Send writes an 8-byte feature report payload (without the report ID).

type Keepalive

type Keepalive func(int)

Keepalive represents a callback function: STATUS_PROCESSING or STATUS_UPNEEDED.

type Protocol

type Protocol struct {
	Version Version
	// contains filtered or unexported fields
}

Protocol implements the OTP HID protocol.

func New

func New(conn Conn) (*Protocol, error)

New initializes and probes the device.

func (*Protocol) Close

func (p *Protocol) Close() error

func (*Protocol) ReadStatus

func (p *Protocol) ReadStatus() ([]byte, error)

ReadStatus returns the 6 status bytes (firmware version is first 3 bytes).

func (*Protocol) SendAndReceive

func (p *Protocol) SendAndReceive(ctx context.Context, slot byte, data []byte, onKeepalive Keepalive) ([]byte, error)

SendAndReceive sends a command to a slot and returns either data (with CRC) or updated status bytes. Pass a cancellable context to abort; onKeepalive receives STATUS_PROCESSING or STATUS_UPNEEDED.

type TimeoutError

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

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

type Version

type Version struct {
	Major, Minor, Patch uint8
}

Version struct parsed from 3 bytes.

func VersionFromBytes

func VersionFromBytes(b []byte) (Version, error)

Jump to

Keyboard shortcuts

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