samd21,samd51,nrf52840: move usbcdc to machine/usb/cdc (#2972)

* samd21,samd51,nrf52840: move usbcdc to machine/usb/cdc
This commit is contained in:
sago35
2022-07-10 18:33:52 +09:00
committed by GitHub
parent 56780c2691
commit d434058aef
15 changed files with 662 additions and 839 deletions
+14 -2
View File
@@ -14,6 +14,9 @@ var (
const (
hidEndpoint = 4
usb_SET_REPORT_TYPE = 33
usb_SET_IDLE = 10
)
type hidDevicer interface {
@@ -27,7 +30,7 @@ var size int
// calls machine.EnableHID for USB configuration
func SetCallbackHandler(d hidDevicer) {
if size == 0 {
machine.EnableHID(callback)
machine.EnableHID(callback, nil, callbackSetup)
}
devices[size] = d
@@ -45,7 +48,16 @@ func callback() {
}
}
func callbackSetup(setup machine.USBSetup) bool {
ok := false
if setup.BmRequestType == usb_SET_REPORT_TYPE && setup.BRequest == usb_SET_IDLE {
machine.SendZlp()
ok = true
}
return ok
}
// SendUSBPacket sends a HIDPacket.
func SendUSBPacket(b []byte) {
machine.SendUSBHIDPacket(hidEndpoint, b)
machine.SendUSBInPacket(hidEndpoint, b)
}