hid

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package hid provides a structured representation of HID report descriptors.

A HID report descriptor is a byte-coded DSL. This package models it as a tree of Go structs (including nested collections) and encodes it to the exact descriptor byte stream.

Index

Constants

View Source
const (
	UsagePageGenericDesktop uint16 = 0x01
	UsagePageSimulation     uint16 = 0x02
	UsagePageVR             uint16 = 0x03
	UsagePageSport          uint16 = 0x04
	UsagePageGame           uint16 = 0x05
	UsagePageKeyboard       uint16 = 0x07
	UsagePageLEDs           uint16 = 0x08
	UsagePageButton         uint16 = 0x09
	UsagePageConsumer       uint16 = 0x0C
)

Common Usage Pages. Values per HID Usage Tables.

View Source
const (
	UsagePointer  uint16 = 0x01
	UsageMouse    uint16 = 0x02
	UsageJoystick uint16 = 0x04
	UsageGamePad  uint16 = 0x05
	UsageKeyboard uint16 = 0x06
	UsageX        uint16 = 0x30
	UsageY        uint16 = 0x31
	UsageZ        uint16 = 0x32
	UsageRx       uint16 = 0x33
	UsageRy       uint16 = 0x34
	UsageRz       uint16 = 0x35
	UsageWheel    uint16 = 0x38
)

Generic Desktop usages.

View Source
const (
	UsageACPan uint16 = 0x0238
)

Consumer usages.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyItem

type AnyItem struct {
	Type ItemType
	Tag  uint8
	Data Data
}

AnyItem is an escape hatch for rarely used or vendor-defined items.

For short items, Data must have length 0, 1, 2, or 4. For other sizes, use LongItem.

type Collection

type Collection struct {
	Kind  CollectionKind
	Items []Item
}

Collection begins a collection (Main item, tag 0xA) and implicitly ends it.

type CollectionKind

type CollectionKind uint8

CollectionKind values.

const (
	CollectionPhysical    CollectionKind = 0x00
	CollectionApplication CollectionKind = 0x01
	CollectionLogical     CollectionKind = 0x02
)

type Data

type Data []uint8

Data is a strongly-typed byte slice used for HID report descriptor payloads.

It exists to avoid exposing raw []byte fields on report descriptor models. The underlying representation is still bytes because that is what the USB/HID specification ultimately requires.

type Feature

type Feature struct{ Flags MainFlags }

Feature encodes a Feature main item (tag 0xB).

type Input

type Input struct{ Flags MainFlags }

Input encodes an Input main item (tag 0x8).

type Item

type Item interface {
	// contains filtered or unexported methods
}

Item is one node in a HID report descriptor.

type ItemType

type ItemType uint8

ItemType is the HID short item "type" field. See HID 1.11 spec: Main=0, Global=1, Local=2, Reserved=3.

const (
	ItemTypeMain     ItemType = 0
	ItemTypeGlobal   ItemType = 1
	ItemTypeLocal    ItemType = 2
	ItemTypeReserved ItemType = 3
)

type LogicalMaximum

type LogicalMaximum struct{ Max int32 }

LogicalMaximum sets the logical maximum (Global item, tag 0x2).

type LogicalMinimum

type LogicalMinimum struct{ Min int32 }

LogicalMinimum sets the logical minimum (Global item, tag 0x1).

type LongItem

type LongItem struct {
	Tag  uint8
	Data Data
}

LongItem encodes a HID long item (rare). Format: 0xFE, len, tag, data...

type MainFlags

type MainFlags uint8
const (
	MainData  MainFlags = 0x00
	MainConst MainFlags = 0x01

	MainArray MainFlags = 0x00
	MainVar   MainFlags = 0x02

	MainAbs MainFlags = 0x00
	MainRel MainFlags = 0x04

	MainNoWrap MainFlags = 0x00
	MainWrap   MainFlags = 0x08

	MainLinear    MainFlags = 0x00
	MainNonLinear MainFlags = 0x10

	MainPreferredState   MainFlags = 0x00
	MainNoPreferredState MainFlags = 0x20

	MainNoNullPosition MainFlags = 0x00
	MainNullState      MainFlags = 0x40

	MainNonVolatile MainFlags = 0x00
	MainVolatile    MainFlags = 0x80
)

type Output

type Output struct{ Flags MainFlags }

Output encodes an Output main item (tag 0x9).

type Report

type Report struct {
	Items []Item
}

Report is a complete HID report descriptor (type 0x22).

func (Report) Bytes

func (r Report) Bytes() (Data, error)

Bytes encodes the report descriptor.

type ReportCount

type ReportCount struct{ Count uint16 }

ReportCount sets report count (Global item, tag 0x9).

type ReportSize

type ReportSize struct{ Bits uint8 }

ReportSize sets report size in bits (Global item, tag 0x7).

type Usage

type Usage struct{ Usage uint16 }

Usage sets the current usage (Local item, tag 0x0).

type UsageMaximum

type UsageMaximum struct{ Max uint16 }

UsageMaximum sets the usage maximum (Local item, tag 0x2).

type UsageMinimum

type UsageMinimum struct{ Min uint16 }

UsageMinimum sets the usage minimum (Local item, tag 0x1).

type UsagePage

type UsagePage struct{ Page uint16 }

UsagePage sets the current usage page (Global item, tag 0x0).

Jump to

Keyboard shortcuts

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