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
+18 -6
View File
@@ -15,8 +15,9 @@ const (
)
type mouse struct {
buf *hid.RingBuffer
button Button
buf *hid.RingBuffer
button Button
waitTxc bool
}
func init() {
@@ -38,13 +39,24 @@ func newMouse() *mouse {
}
func (m *mouse) Callback() bool {
m.waitTxc = false
if b, ok := m.buf.Get(); ok {
m.waitTxc = true
hid.SendUSBPacket(b[:5])
return true
}
return false
}
func (m *mouse) tx(b []byte) {
if m.waitTxc {
m.buf.Put(b)
} else {
m.waitTxc = true
hid.SendUSBPacket(b)
}
}
// Move is a function that moves the mouse cursor.
func (m *mouse) Move(vx, vy int) {
if vx == 0 && vy == 0 {
@@ -65,7 +77,7 @@ func (m *mouse) Move(vx, vy int) {
vy = 127
}
m.buf.Put([]byte{
m.tx([]byte{
0x01, byte(m.button), byte(vx), byte(vy), 0x00,
})
}
@@ -79,7 +91,7 @@ func (m *mouse) Click(btn Button) {
// Press presses the given mouse buttons.
func (m *mouse) Press(btn Button) {
m.button |= btn
m.buf.Put([]byte{
m.tx([]byte{
0x01, byte(m.button), 0x00, 0x00, 0x00,
})
}
@@ -87,7 +99,7 @@ func (m *mouse) Press(btn Button) {
// Release releases the given mouse buttons.
func (m *mouse) Release(btn Button) {
m.button &= ^btn
m.buf.Put([]byte{
m.tx([]byte{
0x01, byte(m.button), 0x00, 0x00, 0x00,
})
}
@@ -105,7 +117,7 @@ func (m *mouse) Wheel(v int) {
v = 127
}
m.buf.Put([]byte{
m.tx([]byte{
0x01, byte(m.button), 0x00, 0x00, byte(v),
})
}