Skip to content

Nrf52840 usb hid #1074

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

Merged
merged 20 commits into from
Aug 1, 2018
Merged

Nrf52840 usb hid #1074

merged 20 commits into from
Aug 1, 2018

Conversation

hathach
Copy link
Member

@hathach hathach commented Jul 31, 2018

PS: tinyusb submodule needs to be updated

@tannewt tannewt removed their request for review July 31, 2018 18:39
@jerryneedell
Copy link
Collaborator

jerryneedell commented Aug 1, 2018

FYI - I pulled this PR and built an image for the pca10056 board. It seems ok for basic operation - I was able to mount an SD Card (SPI ) and run a BLE scan.
Note: the BLE scan only shows one record, but I think this is something that @arturo182 is aware of and already has a fix for.
I have not tried any of the HID functions.

@jerryneedell
Copy link
Collaborator

I did try mounting/unmounting CIRCUITPY a few times - no errors ...yet!

@hathach
Copy link
Member Author

hathach commented Aug 1, 2018

@jerryneedell you could try hid mouse, it is easiest thing to test with
https://circuitpython.readthedocs.io/projects/hid/en/latest/index.html

copy adafruit_hid from bundle to lib/ folder and type these into REPL

from adafruit_hid.mouse import Mouse

m = Mouse()

# Click the left mouse button.
m.click(Mouse.LEFT_BUTTON)

# Move the mouse diagonally to the upper left.
m.move(-100, -100, 0)

@jerryneedell
Copy link
Collaborator

@hathach I tried it and it works!!

while ( (ticks_ms < end_ticks) && !tud_hid_generic_ready() ) { }

if ( !tud_hid_generic_ready() ) {
mp_raise_msg(&mp_type_OSError, "USB Busy");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use mp_raise_OSError("USB Busy") here and similarly elsewhere. Easier to read and saves a few bytes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mp_raise_OSError takes int parameter, since usb does have its error enu, what should be the value for these in the list
https://github.com/adafruit/circuitpython/blob/master/py/mperrno.h

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, never mind, I forgot that it takes only an integer arg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, nrf52 still got plenty of space left anyway :D

TUD_DESC_STRCONV('A','d','a','f','r','u','i','t',' ','I','n','d','u','s','t','r','i','e','s'),

// 2 Product
TUD_DESC_STRCONV('C','i','r','c','u','i','t','P','Y',' ','n','R','F','5','2'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial, but make these lowercase y. CircuitPy instead of CircuitPY.

// SCSI output
}
}
if ( resplen > bufsize ) resplen = bufsize;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use curly braces on all ifs, even one-line ones. Thanks. We're trying to keep to that style.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor changes. Looks great! TinyUSB looks very clean :).

I tested mouse, keyboard, consumer control, and gamepad.

Don't worry about digitizer. I could not set up a digitizer-style device that worked across Windows, Linux, and Mac. I left the report descriptor in just to remember what I'd done.

@ladyada
Copy link
Member

ladyada commented Aug 1, 2018

nice work, thach! i hope to get back to testing nrf52840 again soon!

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks!

#define USB_HID_DEVICE_CONSUMER 1
#define USB_HID_DEVICE_SYS_CONTROL 1
#define USB_HID_DEVICE_GAMEPAD 1
#define USB_HID_DEVICE_DIGITIZER 0 // not supported yet
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhalbert list of enabled hid devices is here, just in case you wan to disable any of these.

@hathach
Copy link
Member Author

hathach commented Aug 1, 2018

@dhalbert thanks, I tried to get all the ugly part inside the tinyusb stack itself :D

@hathach
Copy link
Member Author

hathach commented Aug 1, 2018

@ladyada thanks, hopefully you won't find out too many bugs :D

@dhalbert dhalbert merged commit 65bd07b into adafruit:master Aug 1, 2018
@hathach hathach deleted the nrf52840_usb_hid branch August 22, 2018 08:26
@dhalbert dhalbert mentioned this pull request Sep 17, 2018
@dhalbert
Copy link
Collaborator

Fixes #1008 as well (and maybe also via other PRs).

@dhalbert dhalbert mentioned this pull request Sep 17, 2018
@dhalbert
Copy link
Collaborator

Fixes #1009.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants