Files
tinygo/src/machine/usb/descriptor/device.go
T
Ayke van Laethem 1270a50104 machine: use new internal/binary package
The encoding/binary package in Go 1.23 imports the slices package, which
results in circular import when imported from the machine package.
Therefore, encoding/binary cannot be used in the machine package.

This commit fixes that by introducing a new internal/binary package that
is just plain Go code without dependencies. It can be safely used
anywhere (including the runtime if needed).
2024-06-24 21:21:52 +02:00

74 lines
1.2 KiB
Go

package descriptor
import (
"internal/binary"
)
const (
deviceTypeLen = 18
)
type DeviceType struct {
data []byte
}
func (d DeviceType) Bytes() []byte {
return d.data
}
func (d DeviceType) Length(v uint8) {
d.data[0] = byte(v)
}
func (d DeviceType) Type(v uint8) {
d.data[1] = byte(v)
}
func (d DeviceType) USB(v uint16) {
binary.LittleEndian.PutUint16(d.data[2:4], v)
}
func (d DeviceType) DeviceClass(v uint8) {
d.data[4] = byte(v)
}
func (d DeviceType) DeviceSubClass(v uint8) {
d.data[5] = byte(v)
}
func (d DeviceType) DeviceProtocol(v uint8) {
d.data[6] = byte(v)
}
func (d DeviceType) MaxPacketSize0(v uint8) {
d.data[7] = byte(v)
}
func (d DeviceType) VendorID(v uint16) {
binary.LittleEndian.PutUint16(d.data[8:10], v)
}
func (d DeviceType) ProductID(v uint16) {
binary.LittleEndian.PutUint16(d.data[10:12], v)
}
func (d DeviceType) Device(v uint16) {
binary.LittleEndian.PutUint16(d.data[12:14], v)
}
func (d DeviceType) Manufacturer(v uint8) {
d.data[14] = byte(v)
}
func (d DeviceType) Product(v uint8) {
d.data[15] = byte(v)
}
func (d DeviceType) SerialNumber(v uint8) {
d.data[16] = byte(v)
}
func (d DeviceType) NumConfigurations(v uint8) {
d.data[17] = byte(v)
}