Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
CarlFoxmarten
 
Posts: 6
Joined: Fri Feb 03, 2023 1:03 am

Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by CarlFoxmarten »

So, I'll be the first to admit I have ancient Pro Trinket boards, but right now I can't afford to buy the new ones, so I'm stuck trying to use what I've got.

Anyway, I've got a Pro Trinket 5V board with six TTP223 touch-sensing modules I bought off AliExpress (which handle debouncing well enough) hooked up to an input each, and when a pad is touched my code sends out the relevant media control scan code. Unfortunately, there's a couple of conflicting reports on what scan codes Play/Pause, Previous Track, Next Track, Volume Up, Volume Down, and Mute are supposed to be, but it doesn't seem to make any difference.

The problem being that no host device and operating system I've tested this with actually recognizes any of the codes I'm sending. I've tested Linux (a slightly older Ubuntu distro), Windows 7 Pro, and Android 5.

While I have verified (through USBMON on Linux) that the correct code is being received by the OS, the OS isn't doing anything at all with it.

I've even used USBMON to figure out what what my Logitech G213 keyboard (with said media control buttons) is sending, and it turns out they're not even using scan codes!

Has anyone else run into this problem? Also, what information should I post to help diagnose this? The schematic is ludicrously simple, with each TTP223 module getting power and ground, and its output connected to a different GPIO pin on the microcontroller, and I've confirmed that each is being recognized correctly.

My source code also appears to at least be doing what I'm telling it to, but apparently there's something else you're supposed to be doing to pass media control commands along nowadays?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by adafruit_support_mike »

As a sanity check, try sending regular keyboard characters and see if those behave as they should.

The ProTrinketKeyboard library header file doesn't include media control codes, so it's possible the HID descriptor doesn't support them as-is:

https://github.com/adafruit/Pro_Trinket ... c#L75-L108

You might need to modify it to get support for media control keys.

User avatar
CarlFoxmarten
 
Posts: 6
Joined: Fri Feb 03, 2023 1:03 am

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by CarlFoxmarten »

Yes, I have been able to verify that all six buttons are working correctly by passing along the scan codes for the numbers 1 through 6 across the top of the keyboard. And also that it's been verified to be passing along the media control scan codes I'd pulled from elsewhere, they're just not being used for anything at all on any platform.
adafruit_support_mike wrote: Tue Feb 07, 2023 12:31 am As a sanity check, try sending regular keyboard characters and see if those behave as they should.

The ProTrinketKeyboard library header file doesn't include media control codes, so it's possible the HID descriptor doesn't support them as-is:

https://github.com/adafruit/Pro_Trinket ... c#L75-L108

You might need to modify it to get support for media control keys.
Is there a "USB programming for programmer dummies" guide anywhere? I keep basically getting directed to the actual USB specs, which I haven't been able to understand very well.

After staring at this descriptor for a while, I'm getting the vague idea that I'd need to raise the second value on line 105 that's currently set to 101 or 0x65, given that it's saying something along the lines of "Maximum code for keyboard usage" or something? But that doesn't quite sound right...

User avatar
CarlFoxmarten
 
Posts: 6
Joined: Fri Feb 03, 2023 1:03 am

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by CarlFoxmarten »

Yeah, this: https://www.microchip.com/forums/m859944.aspx

This is the thing I'd been expecting to need to do. Apparently, you need two separate endpoints between regular keyboard scan codes, and the media control flags. But I still don't understand how to assemble these HID descriptors, or even pass the information along the USB connection.

At this rate, I just might have to write my own keyboard library for this, if (and only if) this relatively major modification becomes needed on this microcontroller...
=>.<=

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by adafruit_support_mike »

CarlFoxmarten wrote: Tue Feb 07, 2023 5:09 am Is there a "USB programming for programmer dummies" guide anywhere?
Not really. USB is a table-driven monstrosity.

The actual data transfer part isn't too bad.. a USB device and the host communicate by reading and writing data to memory buffers called 'endpoints'. The individual messages are well defined, the problem is that the spec reads like a choose-your-own-adventure book of options. An initial message will contain codes defined in Table 1, and each code refers to messages whose contents are defined in tables 130 to 475. Those contain codes that refer to other tables, and so on and so on.

Ben Eater has a couple of good videos where he captures the signals on an oscilloscope and walks through the tables to find their meaning:

https://www.youtube.com/watch?v=wdgULBpRoXk
https://www.youtube.com/watch?v=N0O5Uwc3C0o

Creating and modifying device descriptors is a pain in the neck. I'll check to see if anyone knows the descriptor for a keyboard with media control keys.. I know we have code support for it in our own code.

User avatar
CarlFoxmarten
 
Posts: 6
Joined: Fri Feb 03, 2023 1:03 am

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by CarlFoxmarten »

Hmm. I guess I should use USBMON to analyze the stuff coming from my Logitech keyboard when I unplug it and plug it back in. That'd give me a byte sequence to compare to the USB spec, along with an n-key-rollover example, too.

Granted, the ProTrinketKeyboard library uses usbdrv to actually handle the USB port, so anything I do to add an extra endpoint, I'll either have to read usbdrv's documentation to see what they want people to do in order to communicate with said endpoint, or modify their code to enable writing to the second endpoint. Given my current reading of the ProTrinketKeyboard code, it doesn't actually pass the endpoint number that you're trying to send the data to through the functions called, so I'm confused.

I guess there aren't any other Adafruit Pro Trinket-compatible keyboard libraries, eh?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by adafruit_support_mike »

Not ours. The Pro Trinket USB code is based on V-USB though, which has lots of examples:

http://www.obdev.at/products/vusb/
https://www.obdev.at/products/vusb/projects.html

User avatar
CarlFoxmarten
 
Posts: 6
Joined: Fri Feb 03, 2023 1:03 am

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by CarlFoxmarten »

Actually, given that my end goal for this experiment is to control the media on an Android tablet, and I don't want to provide any actual keystrokes at the moment (just media control codes), I should probably swap out all the normal keyboard stuff from the device descriptors and just indicate that I'm sending media control stuff.

Aside:
My particular model of Android tablet (the Asus Zenpad 10, model Z301) has some kind of bug where I can't have BlueTooth and WiFi running at the same time, or the WiFi connection gets frozen until BT is turned off again. I'd even sent both of my tablets back for servicing and they weren't able to fix it at all. But if I connect an actual keyboard, the on-screen keyboard won't show up for text input, and if I override the default settings, it's not on a per-device basis, just in general. I've run into this problem with my phone and the cheap, five-button BlueTooth media controller devices off AliExpress in the past. Only some actually act as media controllers, while the others act as keyboards.

Anyway, since it looks like I'll want to completely revamp the way the USB interface works, maybe I should actually write my own library based directly off V-USB instead. Perhaps I can get it going generically enough to support other bit-bang-USB microcontrollers, too...

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by adafruit_support_mike »

CarlFoxmarten wrote: Thu Feb 16, 2023 6:10 am Actually, given that my end goal for this experiment is to control the media on an Android tablet, and I don't want to provide any actual keystrokes at the moment (just media control codes), I should probably swap out all the normal keyboard stuff from the device descriptors and just indicate that I'm sending media control stuff.
That's a good idea. No need to add complexity for features you don't need.
CarlFoxmarten wrote: Thu Feb 16, 2023 6:10 am Anyway, since it looks like I'll want to completely revamp the way the USB interface works, maybe I should actually write my own library based directly off V-USB instead. Perhaps I can get it going generically enough to support other bit-bang-USB microcontrollers, too...
Go ahead and give it a try, but I'll guess you'll end up somewhere in the middle. A lot of our code is already similar to what you want, and as you work with V-USB you'll understand both systems better.

User avatar
CarlFoxmarten
 
Posts: 6
Joined: Fri Feb 03, 2023 1:03 am

Re: Adafruit Pro Trinket 5V & ProTrinketKeyboard library: Media scan codes not working?

Post by CarlFoxmarten »

adafruit_support_mike wrote: Fri Feb 17, 2023 1:13 am
CarlFoxmarten wrote: Thu Feb 16, 2023 6:10 am Actually, given that my end goal for this experiment is to control the media on an Android tablet, and I don't want to provide any actual keystrokes at the moment (just media control codes), I should probably swap out all the normal keyboard stuff from the device descriptors and just indicate that I'm sending media control stuff.
That's a good idea. No need to add complexity for features you don't need.
CarlFoxmarten wrote: Thu Feb 16, 2023 6:10 am Anyway, since it looks like I'll want to completely revamp the way the USB interface works, maybe I should actually write my own library based directly off V-USB instead. Perhaps I can get it going generically enough to support other bit-bang-USB microcontrollers, too...
Go ahead and give it a try, but I'll guess you'll end up somewhere in the middle. A lot of our code is already similar to what you want, and as you work with V-USB you'll understand both systems better.
Oh, they'll be great references for how to do things, though I don't know if I'd be keeping all of the Adafruit code around, necessarily.
(though I now see a lot of the files began life as templates from the USB-V project. Hmm)

Unfortunately, my time is really busy right now, so I don't have the mental capacity to give this a go. Though I'll probably start a Git folder to track my progress, just to get things started. Without the GitHub repository, at least until it's working...

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”