machine: fix usb truncation?

Remove the sendUSBPacket maxLen param because this greatly confused the compiler.
It also fixes a bug where the length provided to the hardware may not match the length of the packet.
sendUSBPacket now panics if the sent packet is too big.

I also fixed some of the string descriptor logic where we could create a packet without fully populating it.

RP2* systems might require some more work since they are implemented very differently?
I don't have any of those to test with yet, so maybe someone can deal with them in a seperate PR?
This commit is contained in:
Nia Waldvogel
2025-12-30 15:51:27 -05:00
committed by Ron Evans
parent c7f62bae9b
commit 8ef36ed939
8 changed files with 130 additions and 98 deletions
+3 -7
View File
@@ -72,19 +72,15 @@ func initEndpoint(ep, config uint32) {
// SendUSBInPacket sends a packet for USB (interrupt in / bulk in).
func SendUSBInPacket(ep uint32, data []byte) bool {
sendUSBPacket(ep, data, 0)
sendUSBPacket(ep, data)
return true
}
// Prevent file size increases: https://github.com/tinygo-org/tinygo/pull/998
//
//go:noinline
func sendUSBPacket(ep uint32, data []byte, maxsize uint16) {
func sendUSBPacket(ep uint32, data []byte) {
count := len(data)
if 0 < int(maxsize) && int(maxsize) < count {
count = int(maxsize)
}
if ep == 0 {
if count > usb.EndpointPacketSize {
count = usb.EndpointPacketSize
@@ -145,7 +141,7 @@ func setEPDataPID(ep uint32, dataOne bool) {
}
func SendZlp() {
sendUSBPacket(0, []byte{}, 0)
sendUSBPacket(0, []byte{})
}
func sendViaEPIn(ep uint32, data []byte, count int) {