This is a port of PSGroove hub emulation to the Microchip PIC18 family with USB.
This code is provided as-is, I take no responsibility on any damage that it can do to your computer or
your game console.
I can't provide the usb descriptor data for the devices as it's not yet proved they don't contain any copyrighted code,
so you'll need to get them from another open source project (psgroove).
I can't also provide a .hex for burning, you'll need to compile your own.
Prerequisites:
- CCS compiler V4.112 (it's not free, sorry I tried with C18, but the Microchip usb stack seems to have some
problems or there as a timing problem in my side)
- MinGW (or other windows C/C++ compiler)
- Unix Patch tool for windows (to modify CCS USB stack)
- psgroove.c & descriptor.h (USB descriptors for the devices with "special" data and jig challenge response, you
can get from psgroove repository). Remember that psgroove descriptors only allow unsigned code, and no backup copies.
- PIC programmer (PIC devices don't have a bootloader and can't be programed through USB).
Build:
Fist, you need to convert the usb descriptor format to a big array as required by CCS compiler (doesn't support
pointers to ROM), to do so just copy descriptor.h and psgroove.c to the source directory, and build GenDescriptors.
To do so, you'll need a windows C compiler (VC++ or Mingw).
with VC++:
cl gendescriptors.c
or with mingw:
gcc gendescriptors.c -o gendescriptors
If you get some error, you are missing some files.
Now, to build the descriptors, run
gendescriptors > usb_desc.h
Now you need to modify the CCS usb stack. CCS stack distribution not allowed outside licensed users, so you'll need
to patch the one from your ccs installation:
copy usb.c,usb.h, pic18_usb.c and pic18_usb.h (they are in the Drivers folder in CCS) to your source directory and run:
patch -p1 < stack.diff
Now you can compile the source to a .hex with
ccsc +FH +Y9 main.c
Check main.err for errors during compile (missing files or something)
Program main.hex to the PIC
Once plugged, the led will slowly blink till there is traffic on the bus, when it's being accessed, the led
will chirp while processing USB messages, and will stay on once it sees the success message from the descriptor payloads.
If the led keeps blinking for a long time (more than 10s) or stays off, there is something wrong, and you'll need
to reset and try again.
The code is very timing sensitive, so much, that if you remove the UART messages, it will fail more often . So
if it doesn't work, reset and try again, it should eventually work.
For the instructions on how to properly reset it, ask google...
It has been tested with a 20Mhz crystal, but you can probably also run it with a resonator, and for different speeds.
To use different crystal speeds, you need to change PLL fuse in main.h, so that you crystal speed divided by the PLL
divider is 4. (PLL5 for 20Mhz xtal , PLL4 for 16Mhz, PLL3 for 12Mhz, PLL2 for 8Mhz, PLL1 for 4Mhz). Remember to adjust
the xtal capacitor values too.
The config fuses have MCLR disabled, so you dont need a resistor or connection there.