tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

test(usb): create usb.Controller interface for testing

Open mikesmitty opened this issue 4 weeks ago • 2 comments

I mentioned this in a comment on #5109, this is a small refactor of the machine and usb package interactions (and some other changes mixed in that will be created as separate PRs and rebased later on). This creates a usb.Controller interface for use in the USB-related packages for mocking in unit testing and updates machine.USBDev to implement it:

type Controller interface {
	ConfigureUSBEndpoint(desc descriptor.Descriptor, epSettings []EndpointConfig, setup []SetupConfig)
	SendUSBInPacket(ep uint32, data []byte) bool
	AckUsbOutTransfer(ep uint32)
	SendZlp()
	IsInitEndpointComplete() bool
	SetStallEPIn(ep uint32)
	SetStallEPOut(ep uint32)
	ClearStallEPIn(ep uint32)
	ClearStallEPOut(ep uint32)
}

mikesmitty avatar Dec 05 '25 13:12 mikesmitty

@mikesmitty can you please resolve merge conflicts so I can help review. Thank you!

deadprogram avatar Dec 06 '25 11:12 deadprogram

I pushed up some changes to make it compatible with the change to disable USB-CDC when -serial=(uart|rtt), but the relevant nrf52840 code for example is still broken in this one. Now that the base is updated with the CSW fixes I'm back to working on that portion again though. Since this depends on changes to the nrf52840 and samd usb stacks those will need to be fixed before this one can be merged, but I'll be using this branch as the base for them for testing/debugging

mikesmitty avatar Dec 07 '25 00:12 mikesmitty