-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated teensy40 board and machine/usb to utilize new machine.Serial interface #1
base: feature/usb-common
Are you sure you want to change the base?
Conversation
@@ -16,7 +17,7 @@ const descCDCACMCount = 1 | |||
|
|||
// descHIDCount defines the number of USB cores that may be configured as a | |||
// composite (keyboard + mouse + joystick) human interface device (HID). | |||
const descHIDCount = 0 | |||
const descHIDCount = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only solutions I can think of to this:
tinygo
does an in-place file edit:- Would need a robust technique to find and edit this and other consts.
- Would need to decide if/how to restore the edits afterwards.
- Restoring the edits will confuse IDEs/debuggers that are comparing the source to the compiled executable.
- NOT restoring the edits means compiling source code is a destructive operation on that source code!
- Kinda hacky IMO
- Move these respective constants to their own standalone source files with appropriate build tag constraints:
- Let
tinygo
adjust active build tags automatically if command-line flag given.- For example:
GOFLAGS="-tags=...,usb.hid,...
if command-line flag-usb=hid
was given.
- For example:
- Let
Of course, 2. would be my preference and also seems the easiest to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that if 2. would be preferable, it will be necessary to add a separate command-line flag to tinygo
— piggybacking off of the -serial
flag is insufficient.
Something like the following, along with logic to verify the flags given are compatible (e.g., -serial=usb -usb=hid
contradicts itself)
tinygo -serial={none,{uart,usb}[:PORT]} -usb={cdc,hid}[:PORT]
As mentioned in the first comment, this new -usb
flag would be responsible for setting the respective build tags which causes the corresponding source file(s) containing USB configuration constants to get included.
Instead of doing everything in the interrupt lowering pass, generate some more code in gen-device to declare interrupt handler functions and do some work in the compiler so that interrupt lowering becomes a lot simpler. This has several benefits: - Overall code is smaller, in particular the interrupt lowering pass. - The code should be a bit less "magical" and instead a bit easier to read. In particular, instead of having a magic runtime.callInterruptHandler (that is fully written by the interrupt lowering pass), the runtime calls a generated function like device/sifive.InterruptHandler where this switch already exists in code. - Debug information is improved. This can be helpful during actual debugging but is also useful for other uses of DWARF debug information. For an example on debug information improvement, this is what a backtrace might look like before this commit: Breakpoint 1, 0x00000b46 in UART0_IRQHandler () (gdb) bt #0 0x00000b46 in UART0_IRQHandler () #1 <signal handler called> [..etc] Notice that the debugger doesn't see the source code location where it has stopped. After this commit, breaking at the same line might look like this: Breakpoint 1, (*machine.UART).handleInterrupt (arg1=..., uart=<optimized out>) at /home/ayke/src/github.com/tinygo-org/tinygo/src/machine/machine_nrf.go:200 200 uart.Receive(byte(nrf.UART0.RXD.Get())) (gdb) bt #0 (*machine.UART).handleInterrupt (arg1=..., uart=<optimized out>) at /home/ayke/src/github.com/tinygo-org/tinygo/src/machine/machine_nrf.go:200 #1 UART0_IRQHandler () at /home/ayke/src/github.com/tinygo-org/tinygo/src/device/nrf/nrf51.go:176 #2 <signal handler called> [..etc] By now, the debugger sees an actual source location for UART0_IRQHandler (in the generated file) and an inlined function.
This PR refactored TinyGo to have a compiler flag for choosing the type of output - one of "usb", "uart", or "none". This PR updates the Teensy 4.0 implementation and HID example to utilize this mechanism, making it much easier to switch between HID and CDC.
Please note that I set the descriptor count for HID to be 1 by default, which uses a few kb more RAM than necessary... but IMO that is an ok tradeoff for now, especially since Teensy 4.0/4.1 have a whole 1MB of RAM to work with. I think this can be optimized/fixed in the future.