github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/usb/descriptor/descriptor.go (about) 1 package descriptor 2 3 import ( 4 "runtime/volatile" 5 ) 6 7 const ( 8 TypeDevice = 0x1 9 TypeConfiguration = 0x2 10 TypeString = 0x3 11 TypeInterface = 0x4 12 TypeEndpoint = 0x5 13 TypeDeviceQualifier = 0x6 14 TypeInterfaceAssociation = 0xb 15 TypeClassHID = 0x21 16 TypeHIDReport = 0x22 17 TypeClassSpecific = 0x24 18 TypeClassSpecificEndpoint = 0x25 19 ) 20 21 // DeviceDescBank is the USB device endpoint . 22 type DeviceDescBank struct { 23 ADDR volatile.Register32 24 PCKSIZE volatile.Register32 25 EXTREG volatile.Register16 26 STATUS_BK volatile.Register8 27 _reserved [5]volatile.Register8 28 } 29 30 type Device struct { 31 DeviceDescBank [2]DeviceDescBank 32 } 33 34 type Descriptor struct { 35 Device []byte 36 Configuration []byte 37 HID map[uint16][]byte 38 } 39 40 func (d *Descriptor) Configure(idVendor, idProduct uint16) { 41 dev := DeviceType{d.Device} 42 dev.VendorID(idVendor) 43 dev.ProductID(idProduct) 44 45 conf := ConfigurationType{d.Configuration} 46 conf.TotalLength(uint16(len(d.Configuration))) 47 } 48 49 func Append[T any](slices [][]T) []T { 50 var size, pos int 51 52 for _, s := range slices { 53 size += len(s) 54 } 55 56 result := make([]T, size) 57 58 for _, s := range slices { 59 pos += copy(result[pos:], s) 60 } 61 62 return result 63 }