diff options
author | Ron Evans <[email protected]> | 2020-03-28 21:28:14 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2020-03-29 17:54:58 +0200 |
commit | 06797b6d1a59c6e76227762174a475e650519821 (patch) | |
tree | bb7057143e62a629834c0b30a164795c3131a66d | |
parent | 0596b3c003a3b12a9f425213fd5dbeaaf9a53493 (diff) | |
download | tinygo-06797b6d1a59c6e76227762174a475e650519821.tar.gz tinygo-06797b6d1a59c6e76227762174a475e650519821.zip |
machine/atsamd21,atsamd51,nrf52840: correct USB CDC composite descriptors
Signed-off-by: Ron Evans <[email protected]>
-rw-r--r-- | src/machine/machine_atsamd21.go | 44 | ||||
-rw-r--r-- | src/machine/machine_atsamd51.go | 44 | ||||
-rw-r--r-- | src/machine/usb_nrf52840.go | 14 |
3 files changed, 28 insertions, 74 deletions
diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index 92b7119ba..c01e74164 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -1477,6 +1477,8 @@ func handleUSB(intr interrupt.Interrupt) { // clear stall request setEPINTENCLR(0, sam.USB_DEVICE_EPINTENCLR_STALL1) } + } else { + sendZlp(0) } // Now the actual transfer handlers, ignore endpoint number 0 (setup) @@ -1796,53 +1798,29 @@ func sendDescriptor(setup usbSetup) { sendConfiguration(setup) return case usb_DEVICE_DESCRIPTOR_TYPE: - if setup.wLength == 8 { - // composite descriptor requested, so only send 8 bytes - dd := NewDeviceDescriptor(0xEF, 0x02, 0x01, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) - sendUSBPacket(0, dd.Bytes()[:8]) - } else { - // complete descriptor requested so send entire packet - dd := NewDeviceDescriptor(0x02, 0x00, 0x00, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) - sendUSBPacket(0, dd.Bytes()) + // composite descriptor + dd := NewDeviceDescriptor(0xef, 0x02, 0x01, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) + l := deviceDescriptorSize + if setup.wLength < deviceDescriptorSize { + l = int(setup.wLength) } + sendUSBPacket(0, dd.Bytes()[:l]) return case usb_STRING_DESCRIPTOR_TYPE: switch setup.wValueL { case 0: - b := make([]byte, 4) - b[0] = 0x04 - b[1] = 0x03 - b[2] = 0x09 - b[3] = 0x04 + b := []byte{0x04, 0x03, 0x09, 0x04} sendUSBPacket(0, b) return case usb_IPRODUCT: - prod := []byte(usb_STRING_PRODUCT) - b := make([]byte, len(prod)*2+2) - b[0] = byte(len(prod)*2 + 2) - b[1] = 0x03 - - for i, val := range prod { - b[i*2+2] = val - b[i*2+3] = 0 - } - + b := strToUTF16LEDescriptor(usb_STRING_PRODUCT) sendUSBPacket(0, b) return case usb_IMANUFACTURER: - prod := []byte(usb_STRING_MANUFACTURER) - b := make([]byte, len(prod)*2+2) - b[0] = byte(len(prod)*2 + 2) - b[1] = 0x03 - - for i, val := range prod { - b[i*2+2] = val - b[i*2+3] = 0 - } - + b := strToUTF16LEDescriptor(usb_STRING_MANUFACTURER) sendUSBPacket(0, b) return diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index 66246c948..674ef6c85 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -1648,6 +1648,8 @@ func handleUSBIRQ(interrupt.Interrupt) { // clear stall request setEPINTENCLR(0, sam.USB_DEVICE_ENDPOINT_EPINTENCLR_STALL1) } + } else { + sendZlp(0) } // Now the actual transfer handlers, ignore endpoint number 0 (setup) @@ -1967,53 +1969,29 @@ func sendDescriptor(setup usbSetup) { sendConfiguration(setup) return case usb_DEVICE_DESCRIPTOR_TYPE: - if setup.wLength == 8 { - // composite descriptor requested, so only send 8 bytes - dd := NewDeviceDescriptor(0xEF, 0x02, 0x01, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) - sendUSBPacket(0, dd.Bytes()[:8]) - } else { - // complete descriptor requested so send entire packet - dd := NewDeviceDescriptor(0x02, 0x00, 0x00, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) - sendUSBPacket(0, dd.Bytes()) + // composite descriptor + dd := NewDeviceDescriptor(0xef, 0x02, 0x01, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) + l := deviceDescriptorSize + if setup.wLength < deviceDescriptorSize { + l = int(setup.wLength) } + sendUSBPacket(0, dd.Bytes()[:l]) return case usb_STRING_DESCRIPTOR_TYPE: switch setup.wValueL { case 0: - b := make([]byte, 4) - b[0] = 0x04 - b[1] = 0x03 - b[2] = 0x09 - b[3] = 0x04 + b := []byte{0x04, 0x03, 0x09, 0x04} sendUSBPacket(0, b) return case usb_IPRODUCT: - prod := []byte(usb_STRING_PRODUCT) - b := make([]byte, len(prod)*2+2) - b[0] = byte(len(prod)*2 + 2) - b[1] = 0x03 - - for i, val := range prod { - b[i*2+2] = val - b[i*2+3] = 0 - } - + b := strToUTF16LEDescriptor(usb_STRING_PRODUCT) sendUSBPacket(0, b) return case usb_IMANUFACTURER: - prod := []byte(usb_STRING_MANUFACTURER) - b := make([]byte, len(prod)*2+2) - b[0] = byte(len(prod)*2 + 2) - b[1] = 0x03 - - for i, val := range prod { - b[i*2+2] = val - b[i*2+3] = 0 - } - + b := strToUTF16LEDescriptor(usb_STRING_MANUFACTURER) sendUSBPacket(0, b) return diff --git a/src/machine/usb_nrf52840.go b/src/machine/usb_nrf52840.go index 328a6902e..13710789d 100644 --- a/src/machine/usb_nrf52840.go +++ b/src/machine/usb_nrf52840.go @@ -408,15 +408,13 @@ func sendDescriptor(setup usbSetup) { sendConfiguration(setup) return case usb_DEVICE_DESCRIPTOR_TYPE: - if setup.wLength == 8 { - // composite descriptor requested, so only send 8 bytes - dd := NewDeviceDescriptor(0xEF, 0x02, 0x01, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) - sendUSBPacket(0, dd.Bytes()[:8]) - } else { - // complete descriptor requested so send entire packet - dd := NewDeviceDescriptor(0x02, 0x00, 0x00, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) - sendUSBPacket(0, dd.Bytes()) + // composite descriptor + dd := NewDeviceDescriptor(0xef, 0x02, 0x01, 64, usb_VID, usb_PID, 0x100, usb_IMANUFACTURER, usb_IPRODUCT, usb_ISERIAL, 1) + l := deviceDescriptorSize + if setup.wLength < deviceDescriptorSize { + l = int(setup.wLength) } + sendUSBPacket(0, dd.Bytes()[:l]) return case usb_STRING_DESCRIPTOR_TYPE: |