USB HID Keyboard
Moderators: David Barker, Jerry Messina
USB HID Keyboard
Just to let everyone know, I've put up a demo for using swordfish as a USB HID Keyboard on the wiki.
Hope this helps someone! Any feedback is welcome!
Nathan
Hope this helps someone! Any feedback is welcome!
Nathan
Glad to be of help!
Good luck with that! I'd like to see the results. Are you planning on working with frets-on-fire?
PS. I updated the example when I realised how simple it was to read back the LED status (ie. CapsLock, NumLock, etc), if that helps.
PPS. And I couldn't resist adding more functionality, such as opening its own wordpad instance!
Good luck with that! I'd like to see the results. Are you planning on working with frets-on-fire?
PS. I updated the example when I realised how simple it was to read back the LED status (ie. CapsLock, NumLock, etc), if that helps.
PPS. And I couldn't resist adding more functionality, such as opening its own wordpad instance!
I have an old Playstation2 Guitar that don't work anymore. I had plan to modify it and to make it a PC-USB guitar. I didn't had no trouble with the hardware but the software never worked like I want.
First things first, I have to go back to the beginning. I've ever try Microchip FS USB but it's been a while and it was with PDS. I don't really remember how to use it.
Do you have a link that can help me getting started with FS USB and Swordfish?
First things first, I have to go back to the beginning. I've ever try Microchip FS USB but it's been a while and it was with PDS. I don't really remember how to use it.
Do you have a link that can help me getting started with FS USB and Swordfish?
Hello Toley,
I don't really have any links, but I promise you the USB integration for swordfish is top notch. The Help file is very self explanatory and the examples are very flexible to base your own work off of.
My suggestion would be to just get out your PICDEM FS USB board and have a play around with this example code, and the example code from the Swordfish USB folder. The EasyHID creator is also worth playing with as it does make creating your own HID profiles very easy.
Make sure your FSUSB Board still has the default USB bootloader, compile the example code, and bootload it using the microchip PICDEM FS USB Demo Tool. Really easy to play around then. You won't screw anything up too badly doing this (although I did temporarily brick my iPhone whilst creating the Keyboard demo! It tried to update its firmware whilst I was accidentally sending dud data. Doh!).
If you have any questions post them to the forum, and I'm sure you'll get some replies, even if they are just from me!
Good luck with your project, I think I might start scouting around for a broken guitar hero guitar too now!
Nathan
I don't really have any links, but I promise you the USB integration for swordfish is top notch. The Help file is very self explanatory and the examples are very flexible to base your own work off of.
My suggestion would be to just get out your PICDEM FS USB board and have a play around with this example code, and the example code from the Swordfish USB folder. The EasyHID creator is also worth playing with as it does make creating your own HID profiles very easy.
Make sure your FSUSB Board still has the default USB bootloader, compile the example code, and bootload it using the microchip PICDEM FS USB Demo Tool. Really easy to play around then. You won't screw anything up too badly doing this (although I did temporarily brick my iPhone whilst creating the Keyboard demo! It tried to update its firmware whilst I was accidentally sending dud data. Doh!).
If you have any questions post them to the forum, and I'm sure you'll get some replies, even if they are just from me!
Good luck with your project, I think I might start scouting around for a broken guitar hero guitar too now!
Nathan
Help
I have been trying to compile the HID keyboard sample but I keep getting some errors. Can someone tell me why i am getting these errors. I have copied the files needed from the web page and saved them in the user library but I still get errors. I am kinda new to swordfish so please forgive me if its a stupid question. Thank you
hidkeyboard.bas: Identifier not declared: TXReportRAM
hidkeyboard.bas: Identifier not declared: RXReportRAM
..and about 10 more errors similar to these. Please let me know. thank you
hidkeyboard.bas: Identifier not declared: TXReportRAM
hidkeyboard.bas: Identifier not declared: RXReportRAM
..and about 10 more errors similar to these. Please let me know. thank you
Which device are you trying to compile for?
It needs to be a 18F2455, 18F2550, 18F4455 or 18F4550 which have the USB extended dual port ram, the error is stating that the USB ram buffers have not been declared, which normally occurs automatically on these devices.
I recommend a 18F4550 to start with as this is the device I have tested the code on.
If you need it to work on a 18F87J50 you will need my modified USB routines, you'll find them posted on the wiki too.
Are you trying this on the SE demo edition? If so then all bets are off i'm afraid. I understand that USB cannot be used in the SE demo edition due to the (fairly generous) RAM limitations. I haven't tried it myself so YMMV.
I'm afraid I will be offline for a while after this, if you post and I don't get back to you for a while, it's nothing personal! I'm sure others will try to help too, don't let it put you off!
Nathan
It needs to be a 18F2455, 18F2550, 18F4455 or 18F4550 which have the USB extended dual port ram, the error is stating that the USB ram buffers have not been declared, which normally occurs automatically on these devices.
I recommend a 18F4550 to start with as this is the device I have tested the code on.
If you need it to work on a 18F87J50 you will need my modified USB routines, you'll find them posted on the wiki too.
Are you trying this on the SE demo edition? If so then all bets are off i'm afraid. I understand that USB cannot be used in the SE demo edition due to the (fairly generous) RAM limitations. I haven't tried it myself so YMMV.
I'm afraid I will be offline for a while after this, if you post and I don't get back to you for a while, it's nothing personal! I'm sure others will try to help too, don't let it put you off!
Nathan
Simulation of your code to PROTEUS?
Hello!, i now the thread is a little old, but i just found it and while i can compile the code succesfully, when i load the hex file that swordfish produces, to the picdem fs usb board - that proteus has included in it's samples - i get the error "PIC18 STACK pc=0x1460 stack overflow is forcing device reset."
Any help would be really appreciated!
Tom.
Any help would be really appreciated!
Tom.
Hello Tom,
I've never tested on Proteus before, but the specific bug you're referencing is due to the bootloader offset at the beginning (ie. you don't have a bootloader and the ISIS doesn't like it!). You can stop this by commenting out the line:
However I am unsure of how good the virtual USB/HID profile is on ISIS as although the device enumerates with windows as a HID device, the program sits waiting indefinitely waiting for the HID.attach. If you comment this out, it goes through the motions but does not seem to communicate at all.
I do not know where this is coming from, but let me assure you, on real hardware this does work! If you get any results in your testing please let me know and i'll amend this.
Nathan
I've never tested on Proteus before, but the specific bug you're referencing is due to the bootloader offset at the beginning (ie. you don't have a bootloader and the ISIS doesn't like it!). You can stop this by commenting out the line:
Code: Select all
// Use with FSUSB Bootloader
#option org_reset = $0800
I do not know where this is coming from, but let me assure you, on real hardware this does work! If you get any results in your testing please let me know and i'll amend this.
Nathan
Testing with real hardware
Hello Again.
I have easypic5 and 18f4550 i have also commented the bootloader line.
The rd.0 led lights but nothing else happens.
Any ideas? I cannot even see the device in the device manager. I use PICFLASH to program the pic and i get no errors during the process. The only change i have done is change the xtal in the programmer from 20MHz to 8MHz couse this is the actual frequency.
Any ideas?
I have easypic5 and 18f4550 i have also commented the bootloader line.
The rd.0 led lights but nothing else happens.
Any ideas? I cannot even see the device in the device manager. I use PICFLASH to program the pic and i get no errors during the process. The only change i have done is change the xtal in the programmer from 20MHz to 8MHz couse this is the actual frequency.
Any ideas?
Hello Tom,
When you say you changed the "crystal in the programmer", do you mean the main system crystal? If so, when you changed the Crystal, did you change the config settings to reflect this?
The USB block of the IC only runs at 2 speeds, 6MHz (for low Speed USB) or 48Mhz (for High Speed USB - the one we use). If you changed the crystal without changing the config bits then the timings will be all wrong.
Looking at page 32 of the datasheet (OSCILLATOR CONFIGURATION OPTIONS FOR USB OPERATION), I think you'll need to change the Config bits to:
This means that your processor clock will still be running at the Main USB clock speed of 48 MHz, and the USB block gets what it needs.
The PLLDIV you changed divides the Main crystal oscillator down to a target of 4 MHz for feeding the 96 MHz PLL (page 26), which then gets divided-by-2 for our target 48MHz.
For a 20 Mhz input, this is a divide-by-5, for 8 MHz input its a divide-by-2.
I think this will work but cannot check right now as I am not with a board. If not hopefully this should put you on the right track! If not, can you exchange the crystal for a 20MHz?
Best Regards,
Nathan
When you say you changed the "crystal in the programmer", do you mean the main system crystal? If so, when you changed the Crystal, did you change the config settings to reflect this?
The USB block of the IC only runs at 2 speeds, 6MHz (for low Speed USB) or 48Mhz (for High Speed USB - the one we use). If you changed the crystal without changing the config bits then the timings will be all wrong.
Looking at page 32 of the datasheet (OSCILLATOR CONFIGURATION OPTIONS FOR USB OPERATION), I think you'll need to change the Config bits to:
Code: Select all
Clock = 48
// 8Mhz crystal, 48Mhz internal (FS USB)
Config
PLLDIV = 2, // Change this one
CPUDIV = OSC1_PLL2,
USBDIV = 2,
FOSC = HSPLL_HS,
VREGEN = ON
The PLLDIV you changed divides the Main crystal oscillator down to a target of 4 MHz for feeding the 96 MHz PLL (page 26), which then gets divided-by-2 for our target 48MHz.
For a 20 Mhz input, this is a divide-by-5, for 8 MHz input its a divide-by-2.
I think this will work but cannot check right now as I am not with a board. If not hopefully this should put you on the right track! If not, can you exchange the crystal for a 20MHz?
Best Regards,
Nathan