mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-12 23:13:40 +00:00
nrf52840: implement USB-CDC (#883)
* machine/nrf52840: usb-cdc implementation
This commit is contained in:
+18
-1
@@ -1,4 +1,4 @@
|
||||
// +build sam
|
||||
// +build sam nrf52840
|
||||
|
||||
package machine
|
||||
|
||||
@@ -376,6 +376,23 @@ type cdcLineInfo struct {
|
||||
lineState uint8
|
||||
}
|
||||
|
||||
// strToUTF16LEDescriptor converts a utf8 string into a string descriptor
|
||||
// note: the following code only converts ascii characters to UTF16LE. In order
|
||||
// to do a "proper" conversion, we would need to pull in the 'unicode/utf16'
|
||||
// package, which at the time this was written added 512 bytes to the compiled
|
||||
// binary.
|
||||
func strToUTF16LEDescriptor(in string) []byte {
|
||||
size := (len(in) << 1) + 2
|
||||
out := make([]byte, size)
|
||||
out[0] = byte(size)
|
||||
out[1] = 0x03
|
||||
for i, rune := range in {
|
||||
out[(i<<1)+2] = byte(rune)
|
||||
out[(i<<1)+3] = 0
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
var (
|
||||
// TODO: allow setting these
|
||||
usb_STRING_LANGUAGE = [2]uint16{(3 << 8) | (2 + 2), 0x0409} // English
|
||||
|
||||
Reference in New Issue
Block a user