github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/usb/descriptor/device.go (about)

     1  package descriptor
     2  
     3  import (
     4  	"encoding/binary"
     5  )
     6  
     7  const (
     8  	deviceTypeLen = 18
     9  )
    10  
    11  type DeviceType struct {
    12  	data []byte
    13  }
    14  
    15  func (d DeviceType) Bytes() []byte {
    16  	return d.data
    17  }
    18  
    19  func (d DeviceType) Length(v uint8) {
    20  	d.data[0] = byte(v)
    21  }
    22  
    23  func (d DeviceType) Type(v uint8) {
    24  	d.data[1] = byte(v)
    25  }
    26  
    27  func (d DeviceType) USB(v uint16) {
    28  	binary.LittleEndian.PutUint16(d.data[2:4], v)
    29  }
    30  
    31  func (d DeviceType) DeviceClass(v uint8) {
    32  	d.data[4] = byte(v)
    33  }
    34  
    35  func (d DeviceType) DeviceSubClass(v uint8) {
    36  	d.data[5] = byte(v)
    37  }
    38  
    39  func (d DeviceType) DeviceProtocol(v uint8) {
    40  	d.data[6] = byte(v)
    41  }
    42  
    43  func (d DeviceType) MaxPacketSize0(v uint8) {
    44  	d.data[7] = byte(v)
    45  }
    46  
    47  func (d DeviceType) VendorID(v uint16) {
    48  	binary.LittleEndian.PutUint16(d.data[8:10], v)
    49  }
    50  
    51  func (d DeviceType) ProductID(v uint16) {
    52  	binary.LittleEndian.PutUint16(d.data[10:12], v)
    53  }
    54  
    55  func (d DeviceType) Device(v uint16) {
    56  	binary.LittleEndian.PutUint16(d.data[12:14], v)
    57  }
    58  
    59  func (d DeviceType) Manufacturer(v uint8) {
    60  	d.data[14] = byte(v)
    61  }
    62  
    63  func (d DeviceType) Product(v uint8) {
    64  	d.data[15] = byte(v)
    65  }
    66  
    67  func (d DeviceType) SerialNumber(v uint8) {
    68  	d.data[16] = byte(v)
    69  }
    70  
    71  func (d DeviceType) NumConfigurations(v uint8) {
    72  	d.data[17] = byte(v)
    73  }