PDA

View Full Version : HID USB Multimedia Keypad



pmacleod
- 4th February 2011, 09:14
Hi, I am trying to make a simple multimedia keypad (Next, Previous, Play, Stop, Eject, Volume Up, Volume Down) and can't seem to get it to work. I started with the example HID Keyboard and it worked fine so I modified the USB Descriptor for the Consumer Device which supports the correct buttons but can't get it to work. Either I am sending the data from the PIC to the PC incorrectly or something is wrong in the USB Descriptor.

I have included my PBP code, hopefully someone out there might have a better understanding of how it would work.

Any help would be greatly appreciated, Thanks.

pmacleod
- 7th February 2011, 12:12
Well looks like nobody had any luck figuring this out but thats ok. It was a simple problem in the HID Descriptor I missed but its fixed now.

Only problem I am having now it the keys keep repeating but that should be an easy fix :D

pmacleod
- 8th February 2011, 12:08
Ok now that that is worked out its time to move on to next stage, adding a standard HID or CDC interface to access the PIC from a PC/Mac.

Is it possible to combine a second interface to the same device?

mister_e
- 8th February 2011, 17:41
I would say yes, but how to... hell I don't know.

What I would suggest, is to develop a pure HID device, from there you develop a Driver. This driver (or standalone application) will take care of sending the keystrokes and perform other tasks.

MIDI devices use 2 Generic Classes, MIDI Device and Audio Composite, but it is still considered as a single device...

pmacleod
- 8th February 2011, 19:15
Sounds good but I need this to be universal meaning must work with Mac and Linux as well as PC. Standalone app with custom driver would not work in this case.

mackrackit
- 8th February 2011, 19:18
Standalone app with custom driver would not work in this case.
Depends on what you write it in...

pmacleod
- 12th February 2011, 12:09
Would it be difficult to do the USB Service with an interrupt routine instead of in the main loop?

mackrackit
- 12th February 2011, 13:08
ISR is the way to go. Here is a project using DT's Instants.
http://www.picbasic.co.uk/forum/content.php?r=272-USB-SD-LOGGING
Darrel gave us another USB service routine also, but it seems to work best as a stand alone ISR. That is why I like using the Instant approach.
But you can take a look at the other here.
http://www.picbasic.co.uk/forum/showthread.php?t=11728&p=78306#post78306

pmacleod
- 12th February 2011, 14:43
Thanks again for the help.

I put the code you sugested in but I keep getting an error saying Syntax Error for

UIE = $7F 'ENABLE USB INTERRUPTS

I am using Picbasic Pro 2.47

mackrackit
- 12th February 2011, 15:15
Can you give a little more info.. Are you trying the instant solution or the other?
Go ahead and post your code and config setup.

pmacleod
- 12th February 2011, 17:21
Ok I updated to PBP 2.60 (just found the CD) and it compiles ok now but if I enable the innterrupt routines it won't detect the device.

pmacleod
- 12th February 2011, 17:41
I am using a custom HID Bootloader (Modified the Microchip one since it won't compile using the free tools)

I am also using an external 48MHz Oscilator since I have hundreds.

pmacleod
- 12th February 2011, 17:58
Ok I just had some of that code you gave me in wrong place, seems to be working fine now.

I noticed they really changed the USB examples in the new PBP, is it hard to convert an exsisting project to the new format or is it even worth doing.

mackrackit
- 12th February 2011, 18:40
Ok I just had some of that code you gave me in wrong place, seems to be working fine now.
Great!!


I noticed they really changed the USB examples in the new PBP, is it hard to convert an exsisting project to the new format or is it even worth doing.
Your base code should not really change, just the supporting files. So what I do when upgrading an old project like this is start a new directory with the old base code and all of the new supporting files if I need the features from the new PBP. Otherwise I just leave things as they are and use the version of PBP that was originally used for the project. You can have more than one version of PBP installed, just pick the one you want at compile time.

pmacleod
- 13th February 2011, 01:23
Ok I am seeing some wierd things in the new USB Descriptor file for PBP 2.60. Is there a filesize limit for the descriptors now?

mackrackit
- 13th February 2011, 01:41
I have not heard of any changes . Not sure why there would be.
Which file are you looking at?

pmacleod
- 13th February 2011, 01:51
I converted my project to the new format and everything was ok so I went ahead and added the section for the Endpoint 1 In. Once I added it I started getting 'Block overflow for ENDASM'.

I went over and over the ASM code in the descriptor and nothing was wrong. I removed an equal amount of comment lines and it compiled ok. I continued to do the same thing but ran out of comment lines I could remove, My full USB Descriptor file is quite big and I can't even finish getting all of the first endpoint code in before getting the error.

mackrackit
- 13th February 2011, 01:59
I am afraid you are beyond me. I have not written my own descriptor file :o Sorry.

pmacleod
- 13th February 2011, 02:26
Wierd thing is it works fine if i use the old method but still compile for PBP 2.60, its just the new method of putting the descriptor in a BAS file as an include that does not work.... I guess I will just stick to the old method for now.

Must but a problem with PBP itself, I hope they fix it.


P.S.: Just wanted to let you know that the interrupt method you gave me (the instant one) works wonders, I moved the button press code to interrup also and works perfectly, thanks so much :D

Darrel Taylor
- 13th February 2011, 19:52
There is a limit to the number of characters in a single ASM block (includes comments and spaces/tabs).

You can just start a new block when you reach the limit ...


ENDASM
ASM

pmacleod
- 14th February 2011, 02:52
All I can say is WOW, thanks so much, you are an absolute genius :D

I searched and search the new PBP 2.60 manual and did not see any mention of that and would have never guessed that was the cause.

Again thanks. Oh and great job on your Interrupt routines, works wonders :)

PJALM
- 24th February 2011, 07:04
Here is the finished code and schematics if anyone is interested, enjoy :)

PJALM
- 6th November 2014, 00:08
Oh I just wanted to say I did not include Darrels Interupt routine files, you need to download those for this project to work.

djathom
- 8th September 2015, 09:07
hi guys i know this thread is a little bit old but im sure you can help me...
when i try to compile the hid usb keypad it doesnt compile (too many errors) im using pbp 2.60 and microcode studio, but, i have used another device and string descriptor with peter's report descriptor and it compiles but when i put something on the buffer no mater if buffer is a byte variable array or not the pc show 4 key pressed at the same time, i think that the problem is that the descriptor sends the data but the endpoint or the hid descriptor is handling it in a different way not acording with the report descriptor...
thanks a lot for your help!!!

djathom
- 8th September 2015, 22:19
update: it compiles now. the pbp folder had some missing files...

but when i plug in the device windows say "the device can't start"

as far as i know it could be a descriptor problem right?

thanks<label for="rb_iconid_7">http://www.picbasic.co.uk/forum/images/icons/icon7.png</label>

PJALM
- 9th September 2015, 01:26
Sorry I have been away working on other projects. Are you compiling the original source or your modified one?

djathom
- 9th September 2015, 03:49
i have downloaded the las HID USB Multimedia Keypad.zip attachment and now it compiles. but still the pc doesnt recognizes the device...

i´ve changed the original reportdescriptor1, to the \usb18 folder mouse in a circle example keeping all the keypad original code and the pc recognizes the hid mouse, of course it moves the mouse pointer weird because the main program code is made for another reportdescriptor.
that makes me doubt about the original reportdescriptor.


ReportDescriptor1
retlw 0x05
retlw 0x01 ;usage page (generic desktop)
retlw 0x09
retlw 0x02 ;usage (mouse)
retlw 0xA1
retlw 0x01 ;collection (application)
retlw 0x09
retlw 0x01 ;usage (pointer)
retlw 0xA1
retlw 0x00 ;collection (linked)
retlw 0x05
retlw 0x09 ;usage page (buttons)
retlw 0x19
retlw 0x01 ;usage minimum (1)
retlw 0x29
retlw 0x03 ;usage maximum (3)
retlw 0x15
retlw 0x00 ;logical minimum (0)
retlw 0x25
retlw 0x01 ;logical maximum (1)
retlw 0x95
retlw 0x03 ;report count (3)
retlw 0x75
retlw 0x01 ;report size (1)
retlw 0x81
retlw 0x02 ;input (3 button bits)
retlw 0x95
retlw 0x01 ;report count (1)
retlw 0x75
retlw 0x05 ;report size (5)
retlw 0x81
retlw 0x01 ;input (constant 5 bit padding)
retlw 0x05
retlw 0x01 ;usage page (generic desktop)
retlw 0x09
retlw 0x30 ;usage (X)
retlw 0x09
retlw 0x31 ;usage (Y)
retlw 0x15
retlw 0x81 ;logical minimum (-127)
retlw 0x25
retlw 0x7F ;logical maximum (127)
retlw 0x75
retlw 0x08 ;report size (8)
retlw 0x95
retlw 0x02 ;report count (2)
retlw 0x81
retlw 0x06 ;input (2 position bytes X & Y)
retlw 0xC0 ;end collection
retlw 0xC0 ;end collection
EndReportDescriptor1

PJALM
- 9th September 2015, 04:20
If you have doubts about it did you at least test the original code as is to verify?

djathom
- 9th September 2015, 07:42
yes i did... i compiled the whole original project and tested it in a 18f2550 and didn't work...

after testing many different configs and even not too logical things i found the problem... :)

i managed to use a different report descriptor and the rest from the circle in a mouse descriptor example.
now the pc recognizes the device but when i put in the buffer anything it sends many keys at the same time, that's because i had the endopint buffer size set to 1 byte so it only sends the first byte of data and discard the rest...

#define USB_POLLING
#define HID_INTF_ID 0x00
#define HID_EP 1
#define HID_INT_OUT_EP_SIZE 3 ; 1
#define HID_INT_IN_EP_SIZE 3 ; 1
#define HID_NUM_OF_DSC 1

now that i have changed the HID_INT_IN_EP_SIZE from 1 to 3 it let me to put on the buffer a variable array and send for example

variable[0]=%00000000
variable[1]=%00000001

the usb raw data will llok like this

00 01

thanks for your help!!!

CuriousOne
- 17th April 2021, 19:27
So will this work in PBP3?
I want to have such a keypad, and ashamed to have to use Arduino Pro Micro :D

mpgmike
- 18th April 2021, 16:59
Give it a try and report your results. I use HIDMaker for USB stuff. The last time I had to create a USB project (this time using XC8), nothing compiled. I got numerous errors. I tried generating the code for PBP, XC8, even ASM... Dr. Bob worked with me, and it appears the newer MPLABX versions generated curious errors. I had to use an older MPLABX v1.45 to get it working (MPLABX is currently at version 5.45). You may find issues that require you to link PBP to an older version of MPLABX.

CuriousOne
- 7th May 2021, 16:50
Thanks, will try all this this weekend....