USBX HID Host

Hi,

I'm experimenting with the USBX HID Host stack on a SK-S7G2 board.

 

Added

- USBX Host Configuration

- USBX Host Class HUB

- USBX Host Class HID

to a new thread created in the Blinky ThreadX.

Added a callback for the USB Host Event Notification.

When a usb mouse is plugged in the notification callback is called as expected.

When a breakpoint is set in the protected code in the function _ux_host_class_hid_mouse_entry the code stops at the breakpoint when pluggin a mouse in.

A breakpoint in _ux_host_class_hid_mouse_callback also get called when the mouse is moved or a button is pressed on the mouse.

So all works as expected.

 

The big question for me is how to get this mouse data into my own thread so the move\button data can be used in the application?

 

Thanks.

 

Jefe

  • Hello Jefe,
    I worked on deprecated USBX hid on ux module but this was the same code tree.
    In the usbx hid callback you can get X,Y coords and the click information (there is a switch case on a hid_report_callback to detect the right HID identifier) you will have to calculate the new X and Y coordinates for the arrow (because you will get a vector or some absolute value depending on your hid device but you need to adapt them to your graphics format eg. : I use a touchscreen with position between 0 and 4095 on X and Y axis so I have to convert X and Y to fit the 800 x 480 graphic system) then you will have to create and send a GX_EVENT something like that :
    gxe.gx_event_sender = GX_ID_NONE;
    gxe.gx_event_target = 0;
    gxe.gx_event_display_handle = 0;
    gxe.gx_event_type = GX_EVENT_PEN_DOWN; // pen_down to click pen_up to release click
    gxe.gx_event_payload.gx_event_pointdata.gx_point_x = coordX;
    gxe.gx_event_payload.gx_event_pointdata.gx_point_y = coordY;
    gx_system_event_send(&gxe);
    you can also insert X and Y coords in an extern struct to move an arrow picture.
    Hope this helps,
    regards,
  • In reply to TLHQ:

    Hi Jefe,

    You can use ux_host_class_hid_mouse_position_get function. See an example below:

     

    static UX_HOST_CLASS_HID * g_hid;

    UINT ux_host_event_callback(ULONG event, UX_HOST_CLASS * p_host_class, VOID * p_instance)
    {
        UINT          status;
        UX_HOST_CLASS * hid_class;

        if ((ULONG) UX_DEVICE_INSERTION == event)
        {
            status = ux_host_stack_class_get(_ux_system_host_class_hid_name, &hid_class);
            if ((UINT) UX_SUCCESS == status)
            {
                if (hid_class == p_host_class)
                {
                    if (NULL == g_hid)
                    {
                        g_hid = p_instance;
                        while (g_hid->ux_host_class_hid_state != (ULONG) UX_HOST_CLASS_INSTANCE_LIVE)
                        {
                            tx_thread_sleep(1);
                        }

                        while (g_hid->ux_host_class_hid_client->ux_host_class_hid_client_status != (ULONG) UX_HOST_CLASS_INSTANCE_LIVE)
                        {
                            tx_thread_sleep(1);
                        }
                    }
                }
            }
        }

        else if((ULONG) UX_DEVICE_REMOVAL == event)
        {
            if (p_instance == g_hid)
            {
                g_hid = NULL;
            }
        }
        else
        {
        }

        return (UINT) UX_SUCCESS;
    }


    void new_thread_entry(void)
    {
        SLONG pos_x;
        SLONG pos_y;
        UINT status;
        
        while (1) {
            status = ux_host_class_hid_mouse_position_get(g_hid, &pos_x, &pos_y);
            
            if (UX_SUCCESS == status) {
                // process pos_x and pos_y
            }
            
            tx_thread_sleep(5);
        }
    }

     

    Regards,
    adboc

  • In reply to adboc:

    Thanks TLHQ & adboc
    for your reply

    I'm not actually looking to get the mouse data for using it in a gui or so.
    It is just a path I'm taking to get a working environment for using a usbx hid device.
    As mouse & keyboard are already implemented out of the box I was thinking it would be the fastest\easiest way getting started with usbx.

    @adboc
    your code is more or less looking the same as I implemented for my testing.
    Except for the 2 tx_thread_sleep loops.
    What are they exactly needed for ?

    The status of the ux_host_class_hid_mouse_position_get function is always UX_CLASS_INSTANCE_UNKNOWN in the worker thread.

    I see a warning that the g_hid is of the wrong type for that function.
    It is a UX_HOST_CLASS_HID but should be a UX_HOST_CLASS_HID_MOUSE pointer.
    Looking in the (protected) source for the ux_host_class_hid_mouse_position_get tells that the instance is indeed of the wrong type and is the cause of the wrong status


    Any idee's how to get valid data from a connected mouse ?


    btw I'm using the latest ssp package.

    jefe
  • In reply to el jefe:

    Hi Jefe,

    Let's try the following one:
    ux_host_class_hid_mouse_position_get((UX_HOST_CLASS_HID_MOUSE *)g_hid->ux_host_class_hid_client->ux_host_class_hid_client_local_instance, &pos_x, &pos_y);

    Regards,
    adboc
  • In reply to adboc:

    hi adboc,

    Working !

    Where can one find information like this ?
    Most of the stuff for the event callback I collected from this forum.


    greetings

    jefe
  • In reply to el jefe:

    Hi Jefe,

    As far as I know, Renesas and Express Logic are working on the manual for USBX HID, however I don't know when it'll be available. Taking a look at USBX header files gives some hints, at least available APIs e.g. in synergy/ssp/inc/framework/el/ux_host_class_hid.h or ux_host_class_hid_mouse.h.

    Regards,
    adboc