mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 06:23:39 +00:00
implemented USB HID composite keyboard support
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package usb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrHIDInvalidPort = errors.New("invalid USB port")
|
||||
ErrHIDInvalidCore = errors.New("invalid USB core")
|
||||
ErrHIDReportTransfer = errors.New("failed to transfer HID report")
|
||||
)
|
||||
|
||||
type HID struct {
|
||||
Port int
|
||||
core *core
|
||||
}
|
||||
|
||||
type HIDConfig struct {
|
||||
// Port is the MCU's native USB core number. If in doubt, leave it
|
||||
// uninitialized for default (0).
|
||||
Port int
|
||||
}
|
||||
|
||||
func (hid *HID) Configure(config HIDConfig) error {
|
||||
|
||||
if config.Port >= CoreCount || config.Port >= dcdCount {
|
||||
return ErrHIDInvalidPort
|
||||
}
|
||||
hid.Port = config.Port
|
||||
|
||||
// verify we have a free USB port and take ownership of it
|
||||
var st status
|
||||
hid.core, st = initCore(hid.Port, class{id: classDeviceHID, config: 1})
|
||||
if !st.ok() {
|
||||
return ErrHIDInvalidPort
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hid *HID) Keyboard() *Keyboard {
|
||||
return hid.core.dc.keyboard()
|
||||
}
|
||||
Reference in New Issue
Block a user