USB HID on modular builds

More
01 Dec 2013 14:42 - 01 Dec 2013 14:42 #16121 by IMback!
USB HID on modular builds was created by IMback!
Hi,

On modular builds (devo7e) USB HID dosent work, as expected, but I think we should hide the USB HID protocol in the menu, because its misleading and the error mesage (no /worng protocoll module) falsly suggests user error
Last edit: 01 Dec 2013 14:42 by IMback!.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 14:46 #16122 by FDR
Replied by FDR on topic USB HID on modular builds
Why is it expected?
AFAIK it should work...

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 14:49 #16123 by SadSack
Replied by SadSack on topic USB HID on modular builds
very unsure about this and no need of it myself but USB Hid on 7e not enough space for it.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 15:15 #16125 by IMback!
Replied by IMback! on topic USB HID on modular builds
target/common_devo/Makefile.inc clearly disables hid for devo7e

see:
ifdef MODULAR
PROTO_EXTRA_C = $(wildcard target/common_devo/protocol/*.c)
else
SRC_C   += $(wildcard target/common_devo/protocol/*.c) \
           $(wildcard target/common_devo/hid/*.c)
endif

and protocol/Makefile.inc dosent contain a rule for a USBHID module

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 15:30 #16126 by PhracturedBlue
Replied by PhracturedBlue on topic USB HID on modular builds
I don't think this was the intended behavior. I just never noticed it was missing. Most of the USB stack is already compiled into the core, so I would expect it to have a good chance of fitting. And I just compiled it, and was able to get the usbhid module to build. It is untested though, so it may need more work. Feel free to give it a shot though. It is available in my repo now.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 15:36 - 01 Dec 2013 15:37 #16128 by IMback!
Replied by IMback! on topic USB HID on modular builds
nice :)

Ill give it a spin immidiatly
Last edit: 01 Dec 2013 15:37 by IMback!.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 16:26 #16132 by IMback!
Replied by IMback! on topic USB HID on modular builds
No luck "bad missing protocol modules". usbhid.mod is generated and present on the filesystem

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 16:31 #16133 by PhracturedBlue
Replied by PhracturedBlue on topic USB HID on modular builds
Well, that specifically is easy enough to fix. Try it now.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 16:49 - 01 Dec 2013 16:56 #16135 by IMback!
Replied by IMback! on topic USB HID on modular builds
no dice, no more erros but no usb hid either (no new device in dmesg), nothing in erros.txt. Also annoyingly sometimes when you turn on the tx with ENT pressed usb disk mode will apear and work bunt only as long as ent is held, the tx will boot normally as soon as ENT is relased. Ill make a github bitbucket tiket for that
Last edit: 01 Dec 2013 16:56 by IMback!.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 17:00 #16137 by FDR
Replied by FDR on topic USB HID on modular builds
That is probably because of the bouncing of the button.
When you are in USB mode, pressing the ENT button turns it off...

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 18:37 - 01 Dec 2013 18:37 #16145 by IMback!
Replied by IMback! on topic USB HID on modular builds
Sometimes it dosent just not do anything, sometimes it crashes (resetts) upon enabeling usb hid

here is the errors.txt

File Attachment:

File Name: errors.txt
File Size:4 KB


and elfs

File Attachment:

File Name: debug-devo...c024.zip
File Size:281 KB
Attachments:
Last edit: 01 Dec 2013 18:37 by IMback!.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 19:05 #16146 by PhracturedBlue
Replied by PhracturedBlue on topic USB HID on modular builds
Well, that is inside the USB code.
Unfortunately I found this comment I left there:
    //HID is too big for the devo7e, and building as a module will be tricky
So apparently you were right all along; I didn't enable it on purpose, and just forgot.
I'll look at it a bit more. If the USB stack can be fit in 4kb, it is still possible we can enable it.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 20:02 #16148 by PhracturedBlue
Replied by PhracturedBlue on topic USB HID on modular builds
Ok, here is a more invasive patch. We're getting into territory where I really need to break out my Devo7e and test it myself, but we'll give this one shot.
Note that you'll get some compile warnings. This is not ready to be incorporated in to a production build, it is just a proof of concept.
diff -r 6cec02426da6 src/protocol/usbhid.c
--- a/src/protocol/usbhid.c	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/protocol/usbhid.c	Sun Dec 01 11:59:07 2013 -0800
@@ -65,12 +65,13 @@
     return 50000;
 }
 
+extern void HID_Enable();
 static void initialize()
 {
     CLOCK_StopTimer();
     num_channels = Model.num_channels;
     PrevXferComplete = 1;
-    USB_Enable(1, 1);
+    HID_Enable();
     CLOCK_StartTimer(1000, usbhid_cb);
 }
 
diff -r 6cec02426da6 src/target/common_devo/hid/hid_devo.c
--- a/src/target/common_devo/hid/hid_devo.c	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/target/common_devo/hid/hid_devo.c	Sun Dec 01 11:59:07 2013 -0800
@@ -14,11 +14,10 @@
  */
 
 #ifdef MODULAR
-  //Allows the linker to properly relocate
-  #define DEVO_Cmds PROTO_Cmds
   #pragma long_calls
   //This is otherwise included in the main binary
   #include "usb_regs.c"
+  #include <string.h>
 #endif
 
 #include "usb_lib.h"
@@ -34,3 +33,23 @@
     USB_SIL_Write(EP1_IN, (u8 *)packet, num_channels);
     SetEPTxValid(ENDP1);
 }
+
+extern void (*pEpInt_IN[7])(void);
+extern void (*pEpInt_OUT[7])(void);
+extern void (*HID_pEpInt_IN[7])(void);
+extern void (*HID_pEpInt_OUT[7])(void);
+extern DEVICE_PROP HID_Device_Property;
+extern USER_STANDARD_REQUESTS HID_User_Standard_Requests;
+extern void USB_Enable(u8 type, u8 use_interrupt);
+void ModuleHID_Init() {
+    memcpy(pEpInt_IN, HID_pEpInt_IN, sizeof(pEpInt_IN));
+    memcpy(pEpInt_OUT, HID_pEpInt_OUT, sizeof(pEpInt_OUT));
+    Device_Property = &HID_Device_Property;
+    User_Standard_Requests = &HID_User_Standard_Requests;
+}
+
+extern void (*_HID_Init)();
+void HID_Enable() {
+    _HID_Init = ModuleHID_Init;
+    USB_Enable(1, 1);
+}
diff -r 6cec02426da6 src/target/common_devo/hid/hid_usb_desc.c
--- a/src/target/common_devo/hid/hid_usb_desc.c	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/target/common_devo/hid/hid_usb_desc.c	Sun Dec 01 11:59:07 2013 -0800
@@ -13,6 +13,9 @@
 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
 *******************************************************************************/
 
+#ifdef MODULAR
+  #pragma long_calls
+#endif
 /* Includes ------------------------------------------------------------------*/
 #include "usb_lib.h"
 #include "hid_usb_desc.h"
@@ -160,7 +163,7 @@
     'o', 0, 'n', 0, ' ', 0, 'G', 0, 'a', 0, 'm', 0, 'e', 0,
     'P', 0, 'a', 0, 'd', 0
   };
-uint8_t Joystick_StringSerial[JOYSTICK_SIZ_STRING_SERIAL] =
+const uint8_t Joystick_StringSerial[JOYSTICK_SIZ_STRING_SERIAL] =
   {
     JOYSTICK_SIZ_STRING_SERIAL,           /* bLength */
     USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
diff -r 6cec02426da6 src/target/common_devo/hid/hid_usb_desc.h
--- a/src/target/common_devo/hid/hid_usb_desc.h	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/target/common_devo/hid/hid_usb_desc.h	Sun Dec 01 11:59:07 2013 -0800
@@ -49,7 +49,7 @@
 extern const uint8_t Joystick_StringLangID[JOYSTICK_SIZ_STRING_LANGID];
 extern const uint8_t Joystick_StringVendor[JOYSTICK_SIZ_STRING_VENDOR];
 extern const uint8_t Joystick_StringProduct[JOYSTICK_SIZ_STRING_PRODUCT];
-extern uint8_t Joystick_StringSerial[JOYSTICK_SIZ_STRING_SERIAL];
+extern const uint8_t Joystick_StringSerial[JOYSTICK_SIZ_STRING_SERIAL];
 
 #endif /* __USB_DESC_H */
 
diff -r 6cec02426da6 src/target/common_devo/hid/hid_usb_endp.c
--- a/src/target/common_devo/hid/hid_usb_endp.c	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/target/common_devo/hid/hid_usb_endp.c	Sun Dec 01 11:59:07 2013 -0800
@@ -13,6 +13,9 @@
 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
 *******************************************************************************/
 
+#ifdef MODULAR
+  #pragma long_calls
+#endif
 /* Includes ------------------------------------------------------------------*/
 #ifdef STM32L1XX_MD
 #include "stm32l1xx.h"
diff -r 6cec02426da6 src/target/common_devo/hid/hid_usb_istr.c
--- a/src/target/common_devo/hid/hid_usb_istr.c	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/target/common_devo/hid/hid_usb_istr.c	Sun Dec 01 11:59:07 2013 -0800
@@ -13,6 +13,10 @@
 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
 *******************************************************************************/
 
+#ifdef MODULAR
+  #pragma long_calls
+#endif
+
 /* Includes ------------------------------------------------------------------*/
 #include "usb_lib.h"
 #include "hid_usb_prop.h"
@@ -29,7 +33,7 @@
 /* Private function prototypes -----------------------------------------------*/
 /* Private functions ---------------------------------------------------------*/
 /* function pointers to non-control endpoints service routines */
-void (*HID_pEpInt_IN[7])(void) =
+void (* const HID_pEpInt_IN[7])(void) =
   {
     HID_EP1_IN_Callback,
     HID_EP2_IN_Callback,
@@ -40,7 +44,7 @@
     HID_EP7_IN_Callback,
   };
 
-void (*HID_pEpInt_OUT[7])(void) =
+void (* const HID_pEpInt_OUT[7])(void) =
   {
     HID_EP1_OUT_Callback,
     HID_EP2_OUT_Callback,
diff -r 6cec02426da6 src/target/common_devo/hid/hid_usb_prop.c
--- a/src/target/common_devo/hid/hid_usb_prop.c	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/target/common_devo/hid/hid_usb_prop.c	Sun Dec 01 11:59:07 2013 -0800
@@ -13,6 +13,10 @@
 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
 *******************************************************************************/
 
+#ifdef MODULAR
+  #pragma long_calls
+#endif
+
 /* Includes ------------------------------------------------------------------*/
 #include "usb_lib.h"
 #include "hid_usb_conf.h"
@@ -38,7 +42,7 @@
     1
   };
 */
-DEVICE_PROP HID_Device_Property =
+const DEVICE_PROP HID_Device_Property =
   {
     Joystick_init,
     Joystick_Reset,
@@ -53,7 +57,7 @@
     0,
     0x40 /*MAX PACKET SIZE*/
   };
-USER_STANDARD_REQUESTS HID_User_Standard_Requests =
+const USER_STANDARD_REQUESTS HID_User_Standard_Requests =
   {
     Joystick_GetConfiguration,
     Joystick_SetConfiguration,
@@ -66,31 +70,31 @@
     Joystick_SetDeviceAddress
   };
 
-ONE_DESCRIPTOR HID_Device_Descriptor =
+const ONE_DESCRIPTOR HID_Device_Descriptor =
   {
     (uint8_t*)Joystick_DeviceDescriptor,
     JOYSTICK_SIZ_DEVICE_DESC
   };
 
-ONE_DESCRIPTOR HID_Config_Descriptor =
+const ONE_DESCRIPTOR HID_Config_Descriptor =
   {
     (uint8_t*)Joystick_ConfigDescriptor,
     JOYSTICK_SIZ_CONFIG_DESC
   };
 
-ONE_DESCRIPTOR Joystick_Report_Descriptor =
+const ONE_DESCRIPTOR Joystick_Report_Descriptor =
   {
     (uint8_t *)Joystick_ReportDescriptor,
     JOYSTICK_SIZ_REPORT_DESC
   };
 
-ONE_DESCRIPTOR Mouse_Hid_Descriptor =
+const ONE_DESCRIPTOR Mouse_Hid_Descriptor =
   {
     (uint8_t*)Joystick_ConfigDescriptor + JOYSTICK_OFF_HID_DESC,
     JOYSTICK_SIZ_HID_DESC
   };
 
-ONE_DESCRIPTOR HID_String_Descriptor[4] =
+const ONE_DESCRIPTOR HID_String_Descriptor[4] =
   {
     {(uint8_t*)Joystick_StringLangID, JOYSTICK_SIZ_STRING_LANGID},
     {(uint8_t*)Joystick_StringVendor, JOYSTICK_SIZ_STRING_VENDOR},
diff -r 6cec02426da6 src/target/common_devo/msc2/usb_devo8.c
--- a/src/target/common_devo/msc2/usb_devo8.c	Sun Dec 01 08:31:07 2013 -0800
+++ b/src/target/common_devo/msc2/usb_devo8.c	Sun Dec 01 11:59:07 2013 -0800
@@ -61,22 +61,28 @@
     User_Standard_Requests = &MSC_User_Standard_Requests;
 }
 
+#ifdef MODULAR
+void (*_HID_Init)();
+#endif
 void HID_Init() {
-#ifndef MODULAR
-    //HID is too big for the devo7e, and building as a module will be tricky
     memcpy(pEpInt_IN, HID_pEpInt_IN, sizeof(pEpInt_IN));
     memcpy(pEpInt_OUT, HID_pEpInt_OUT, sizeof(pEpInt_OUT));
     Device_Property = &HID_Device_Property;
     User_Standard_Requests = &HID_User_Standard_Requests;
-#endif
 }
+
 void USB_Enable(u8 type, u8 use_interrupt)
 {
     if (type == 0) {
         //Mass Storage
         MSC_Init();
     } else if (type == 1) {
+#ifndef MODULAR
         HID_Init();
+#else
+        if(_HID_Init)
+            _HID_Init();
+#endif
     }
     gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
         GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 20:46 - 01 Dec 2013 20:47 #16153 by IMback!
Replied by IMback! on topic USB HID on modular builds
the patch fails for me

EDIT: nevermind my error

im out of time today anyways
Last edit: 01 Dec 2013 20:47 by IMback!.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 20:55 #16156 by IMback!
Replied by IMback! on topic USB HID on modular builds
It works! But the axis are fliped compared to the static module build that i made. Can be compensated via a mixer of course.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 21:01 #16157 by PhracturedBlue
Replied by PhracturedBlue on topic USB HID on modular builds
ok, I'll try to clean this up and commit it then

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 21:10 #16158 by victzh
Replied by victzh on topic USB HID on modular builds
I have my Devo7e unpacked (I recently moved ;-). On my Devo the patch does not work - no USB HID device is registered unlike with regular firmware on Devo10.

Please Log in or Create an account to join the conversation.

More
01 Dec 2013 23:01 #16166 by PhracturedBlue
Replied by PhracturedBlue on topic USB HID on modular builds
Well, whether it works or not, I've committed the patch to the trunk. It should be a good starting point, and since IMBack got it working, I'll assume it only requires minor changes.

Please Log in or Create an account to join the conversation.

More
02 Dec 2013 02:42 #16174 by PhracturedBlue
Replied by PhracturedBlue on topic USB HID on modular builds
I pulled out my devo7e and tested it. the usbhid works fine for me. Make sure you 'Re-Init' after changing the protocol

Please Log in or Create an account to join the conversation.

More
02 Dec 2013 05:15 #16177 by victzh
Replied by victzh on topic USB HID on modular builds
I rebuilt you most recent version and it works for me. Moreover, it almost builds with my current Windows compiler - 4.7.2 - 4 bytes short ;-)

It seems I figured why it did not work with your patch - you changed the name of the module to suit the module system requirement - removed space, so my old model did not work and I did not pay enough attention to figure it out. This time I was sure I'm doing something wrong, so I looked more thoroughly.

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum