Go Down

Topic: Tutorial - How to change firmware on 8u2 (Read 116 times) previous topic - next topic

ant.b

PS2 has 2 more axes: Z and Rz
So Descriptors.c has to be modified:

Replace
Code: [Select]
     0x09, 0x30,          /*     Usage (X)                                      */
     0x09, 0x31,          /*     Usage (Y)                                      */
     0x15, 0x9c,          /*     Logical Minimum (-100)                         */
     0x25, 0x64,          /*     Logical Maximum (100)                          */
     0x75, 0x08,          /*     Report Size (8)                                */
     0x95, 0x02,          /*     Report Count (2)                               */


by

Code: [Select]
     0x09, 0x30,          /*     Usage (X)                                      */
     0x09, 0x31,          /*     Usage (Y)                                      */
     0x09, 0x32,          /*     Usage (Z)                                      */
     0x09, 0x35,          /*     Usage (Rz)                                      */
     0x15, 0x9c,          /*     Logical Minimum (-100)                         */
     0x25, 0x64,          /*     Logical Maximum (100)                          */
     0x75, 0x08,          /*     Report Size (8)                                */
     0x95, 0x04,          /*     Report Count (4)                               */


And change the data structure:
in Joystick.h

Replace

Code: [Select]
typedef struct
           {
                 int8_t  X; /**< Current absolute joystick X position, as a signed 8-bit integer */
                 int8_t  Y; /**< Current absolute joystick Y position, as a signed 8-bit integer */
                 uint8_t Button; /**< Bit mask of the currently pressed joystick buttons */
           } USB_JoystickReport_Data_t;


by:

Code: [Select]
           typedef struct
           {
                 int8_t  X; /**< Current absolute joystick X position, as a signed 8-bit integer */
                 int8_t  Y; /**< Current absolute joystick Y position, as a signed 8-bit integer */
                 int8_t  Z; /**< Current absolute joystick Z position, as a signed 8-bit integer */                  
                 int8_t  Rz; /**< Current absolute joystick Rz position, as a signed 8-bit integer */
                 uint8_t Button; /**< Bit mask of the currently pressed joystick buttons */
           } USB_JoystickReport_Data_t;


I think it's the only thing to modify to see the 8u2 as a 4 axes joystick.
The code that is used to manage serial communication between 8u2 and arduino has to be updated to.

Blue_Boy

Alright Ant!
Great work man, thanks!
Can you also direct me to the pages where you found this info?
The specific usage pages and hex values?

Blue_Boy

Hey,
I'm experimenting with this today.
I implemented your code. (Thanks!)
Now I have to figure out the encoding / decoding procedure.

My idea was this: send an "identification char" (a, b, c, d)
followed by the sensor data (0-255).

So in Arduino I do "Serial.println('a')" followed by "Serial.println(serialData)". That seems simple enough.

In the 82U I have this code.

Code: [Select]
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
                                        uint8_t* const ReportID,
                                        const uint8_t ReportType,
                                        void* ReportData,
                                        uint16_t* const ReportSize)
{
USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData;

while (Serial_IsCharReceived())
     {
     temp=Serial_RxByte();
     if (temp == "a"){JoystickReport->X  =  Serial_RxByte();}
     if (temp == "b"){JoystickReport->Y  =  Serial_RxByte();}
     if (temp == "c"){JoystickReport->Z  =  Serial_RxByte();}
     if (temp == "d"){JoystickReport->Rz =  Serial_RxByte();}
     }

*ReportSize = sizeof(USB_JoystickReport_Data_t);
     return false;
}


But that don't work. Bummer.
Could somebody point me to why?

Blue_Boy

Quote

Comment : I have had some difficulties with Flip : I often had the error 'Address is out of range'. I don't really now why?? Does someone have an idea?


I think this might actually have to do with the size of the generated HEX file. Whenever I wrote too much code, I got over 4KB and I got this error too.

stimmer

I think CALLBACK_HID_Device_CreateHIDReport has to return quickly, you don't have enough time to wait for serial data inside CALLBACK_HID_Device_CreateHIDReport. Instead you should process serial data in main, and just copy it in the callback.

Also you are assuming that the two characters will come to the serial port together - they won't. There will be a delay between the identification character and the data. However because main does other tasks (the USBTask() calls) you can't just block it while waiting for serial characters. Instead you have to code it as a state machine.

You want to use Serial.print or Serial.write rather than println as you don't want the extra newline.

The information on descriptors can be found here:
http://www.usb.org/developers/hidpage/
Unfortunately it is all very complicated and detailed. That's just the way it is.

Go Up