aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/usb
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-08-03 16:24:47 +0200
committerAyke <[email protected]>2022-08-04 12:18:32 +0200
commitc7a23183e822b9eebb639902414a0e08a09fbba0 (patch)
tree894a03fe2f4980a728c8401604d8a2c17503fde5 /src/machine/usb
parentf936125658e8aef885a0e31d8fc343859defe63c (diff)
downloadtinygo-c7a23183e822b9eebb639902414a0e08a09fbba0.tar.gz
tinygo-c7a23183e822b9eebb639902414a0e08a09fbba0.zip
all: format code according to Go 1.19 rules
Go 1.19 started reformatting code in a way that makes it more obvious how it will be rendered on pkg.go.dev. It gets it almost right, but not entirely. Therefore, I had to modify some of the comments so that they are formatted correctly.
Diffstat (limited to 'src/machine/usb')
-rw-r--r--src/machine/usb/hid/keyboard/keyboard.go45
-rw-r--r--src/machine/usb/hid/keyboard/keycode.go1
2 files changed, 22 insertions, 24 deletions
diff --git a/src/machine/usb/hid/keyboard/keyboard.go b/src/machine/usb/hid/keyboard/keyboard.go
index 7a51eff41..18fd0bb2e 100644
--- a/src/machine/usb/hid/keyboard/keyboard.go
+++ b/src/machine/usb/hid/keyboard/keyboard.go
@@ -114,24 +114,21 @@ func (kb *keyboard) Write(b []byte) (n int, err error) {
// stateful method with respect to the receiver Keyboard, meaning that its exact
// behavior will depend on the current state of its UTF-8 decode state machine:
//
-// (a) If the given byte is a valid ASCII encoding (0-127), then a keypress
-// sequence is immediately transmitted for the respective Keycode.
+// 1. If the given byte is a valid ASCII encoding (0-127), then a keypress
+// sequence is immediately transmitted for the respective Keycode.
+// 2. If the given byte represents the final byte in a multi-byte codepoint,
+// then a keypress sequence is immediately transmitted by translating the
+// multi-byte codepoint to its respective Keycode.
+// 3. If the given byte appears to represent high bits for a multi-byte
+// codepoint, then the bits are copied to the receiver's internal state
+// machine buffer for use by a subsequent call to WriteByte() (or Write())
+// that completes the codepoint.
+// 4. If the given byte is out of range, or contains illegal bits for the
+// current state of the UTF-8 decoder, then the UTF-8 decode state machine
+// is reset to its initial state.
//
-// (b) If the given byte represents the final byte in a multi-byte codepoint,
-// then a keypress sequence is immediately transmitted by translating the
-// multi-byte codepoint to its respective Keycode.
-//
-// (c) If the given byte appears to represent high bits for a multi-byte
-// codepoint, then the bits are copied to the receiver's internal state
-// machine buffer for use by a subsequent call to WriteByte() (or Write())
-// that completes the codepoint.
-//
-// (d) If the given byte is out of range, or contains illegal bits for the
-// current state of the UTF-8 decoder, then the UTF-8 decode state machine
-// is reset to its initial state.
-//
-// In cases (c) and (d), a keypress sequence is not generated and no data is
-// transmitted. In case (c), additional bytes must be received via WriteByte()
+// In cases 3 and 4, a keypress sequence is not generated and no data is
+// transmitted. In case 3, additional bytes must be received via WriteByte()
// (or Write()) to complete or discard the current codepoint.
func (kb *keyboard) WriteByte(b byte) error {
switch {
@@ -211,13 +208,13 @@ func (kb *keyboard) writeKeycode(c Keycode) error {
//
// The following values of Keycode are supported:
//
-// 0x0020 - 0x007F ASCII (U+0020 to U+007F) [USES LAYOUT]
-// 0x0080 - 0xC1FF Unicode (U+0080 to U+C1FF) [USES LAYOUT]
-// 0xC200 - 0xDFFF UTF-8 packed (U+0080 to U+07FF) [USES LAYOUT]
-// 0xE000 - 0xE0FF Modifier key (bitmap, 8 keys, Shift/Ctrl/Alt/GUI)
-// 0xE200 - 0xE2FF System key (HID usage code, page 1)
-// 0xE400 - 0xE7FF Media/Consumer key (HID usage code, page 12)
-// 0xF000 - 0xFFFF Normal key (HID usage code, page 7)
+// 0x0020 - 0x007F ASCII (U+0020 to U+007F) [USES LAYOUT]
+// 0x0080 - 0xC1FF Unicode (U+0080 to U+C1FF) [USES LAYOUT]
+// 0xC200 - 0xDFFF UTF-8 packed (U+0080 to U+07FF) [USES LAYOUT]
+// 0xE000 - 0xE0FF Modifier key (bitmap, 8 keys, Shift/Ctrl/Alt/GUI)
+// 0xE200 - 0xE2FF System key (HID usage code, page 1)
+// 0xE400 - 0xE7FF Media/Consumer key (HID usage code, page 12)
+// 0xF000 - 0xFFFF Normal key (HID usage code, page 7)
func (kb *keyboard) Press(c Keycode) error {
if err := kb.Down(c); nil != err {
return err
diff --git a/src/machine/usb/hid/keyboard/keycode.go b/src/machine/usb/hid/keyboard/keycode.go
index c9e3b9350..8b26eaccd 100644
--- a/src/machine/usb/hid/keyboard/keycode.go
+++ b/src/machine/usb/hid/keyboard/keycode.go
@@ -5,6 +5,7 @@ type Keycode uint16
// keycode returns the given Unicode codepoint translated to a Keycode sequence.
// Unicode codepoints greater than U+FFFF are unsupported.
+//
//go:inline
func keycode(p uint16) Keycode {
if p < 0x80 {