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
@@ -41,7 +41,8 @@ type keyboard struct {
// wideChar holds high bits for the UTF-8 decoder.
wideChar uint16
buf *hid.RingBuffer
buf *hid.RingBuffer
waitTxc bool
}
// decodeState represents a state in the UTF-8 decode state machine.
@@ -74,13 +75,24 @@ func newKeyboard() *keyboard {
}
func (kb *keyboard) Callback() bool {
kb.waitTxc = false
if b, ok := kb.buf.Get(); ok {
kb.waitTxc = true
hid.SendUSBPacket(b)
return true
}
return false
}
func (kb *keyboard) tx(b []byte) {
if kb.waitTxc {
kb.buf.Put(b)
} else {
kb.waitTxc = true
hid.SendUSBPacket(b)
}
}
func (kb *keyboard) ready() bool {
return true
}
@@ -214,7 +226,7 @@ func (kb *keyboard) Press(c Keycode) error {
}
func (kb *keyboard) sendKey(consumer bool, b []byte) bool {
kb.buf.Put(b)
kb.tx(b)
return true
}