This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

After NCS 1.3.0 nRF Desktop LLPM is disconnected, there is no data on the USB.

I now integrate USB, BLE, LLPM, keyboard HID and Mouse HID to nrf52833.


When I added CONFIG_DESKTOP_HID_MOUSE=y, my project was abnormal.


BLE connection:                     Move Mouse and report keyboard work correctly.

USB connected:                      data cannot be reported to PC.

LLPM cannot be connected:   disconnect after connection, and then repeat the process.

Parents
  • Hello,

    Have you tried the latest v1.4.1 release?

    Kenneth

  • I tried for a few days and still couldn’t achieve the desired effect. I made the following changes:

    1. usb_state.c

    1.1 Modify usb_init usb_hid_device[1] as KEYBOARD and usb_hid_device[0] as MOUSE.

            usb_hid_device[0].dev = device_get_binding("HID_0");
    	if (usb_hid_device[0].dev == NULL) {
    		LOG_ERR("Cannot get USB HID 0 Device");
    		return 0;
    	}
    
    	usb_hid_register_device(usb_hid_device[0].dev, hid_mouse_report_desc,   // hid_kbd_report_desc   hid_mouse_report_desc
    				sizeof(hid_mouse_report_desc),&hid_ops[0]);
    
    	usb_hid_init(usb_hid_device[0].dev);
    
    
    	usb_hid_device[1].dev = device_get_binding("HID_1");
    	if (usb_hid_device[1].dev == NULL) {
    		LOG_ERR("Cannot get USB HID 1 Device");
    		return 0;
    	}
    
    	usb_hid_register_device(usb_hid_device[1].dev, hid_mouse_report_desc,
    				sizeof(hid_mouse_report_desc),&hid_ops[1]);
    
    	usb_hid_init(usb_hid_device[1].dev);

    2.hid_static.c

    #define SUBSCRIBER_COUNT (IS_ENABLED(CONFIG_DESKTOP_HIDS_ENABLE) + \
    IS_ENABLED(CONFIG_DESKTOP_USB_ENABLE)+IS_ENABLED(CONFIG_DESKTOP_USB_ENABLE))

    Modify hid_state struct to add an additional subscriber for usb_hid_device[1] (KEYBOARD).

    struct hid_state {
    struct report_data report_data[INPUT_REPORT_DATA_COUNT];
    struct subscriber subscriber[SUBSCRIBER_COUNT];
    struct subscriber *selected;
          struct subscriber *selected_extra;//!!
    };

    handle_usb_hid_event{
      if (event->enabled) {
          //if (!get_subscriber_by_type(true)) { //Multiple USB subscribers can be added
              connect_subscriber(event->id, true, 1);
          //}
      } else {
          disconnect_subscriber(event->id);
      }

    Assign the subscriber of MOUSE to state.selected KEYBOARD to state.selected_extra

    connect_subscriber{
    
    static uint8_t usb_count = 0; // sean 1.6
      usb_count++;// sean 1.6
    //				for (size_t j = 0; j < ARRAY_SIZE(state.report_data); j++) { //sean 1.6
    //					struct report_data *rd = &state.report_data[j];
    //
    //					rd->linked_rs = NULL;
    //					clear_report_data(rd);
    //				}
                                      if(usb_count==1)
    				state.selected = NULL;
                                 
    			}
                         
                if(usb_count == 2)
                      state.selected_extra = &state.subscriber[i];
    
    			if (!state.selected ) {
    
                              if(usb_count==1)
                              {
                              state.selected = &state.subscriber[i];
                              LOG_INF("!! Active subscriber %p %d",state.selected->id,i);
                              }
    
    			}
    			...
    }

    Used state.selected_extra at the time of sending keyboard report

    send_report_keyboard
    {
      ...
      event->subscriber = state.selected_extra->id;
    }

    report_send{
      ....
        __ASSERT_NO_MSG(rs->subscriber == state.selected || rs->subscriber == state.selected_extra);
       
       

       

    Press the mouse, the mouse responds.

    You can see that the code is executed to hid_int_ep_write

    LOG print

    usb_hid->dev = 0x20000f18; usb_hid_device[1].dev = 0x20000f00

    Note: usb_hid_device[0].dev = 0x20000f18 (MOUSE)

    Press the keyboard, No characters output on PC !!!

    LOG print

    usb_hid->dev = 0x20000f00; usb_hid_device[1].dev = 0x20000f00

    Note: usb_hid_device[1].dev = 0x20000f00 (KEYBOARD)

    But report_sent_cb is not executed.

    I tried many methods and I don't know how to modify it!

  • Combining mouse and keyboard is something that we have "missed" in ncs1.3, we have added the functionality to ncs1.4.0. In general the problem is in hid_state - we have assumed all reports will go to "separate" transports (by separate I mean each handling its own state).

    The problem with usb in ncs1.3.0 is that it can send only one report at a time so there is no way you can send both mouse and keyboard report as hid_state will not know how to handle it.

    I believe this fix may have been backported to ncs1.3 - you can see the backported changes here:
    https://github.com/pdunaj/fw-nrfconnect-nrf/commits/DESK-1072 

    What you are interested in is:
    https://github.com/pdunaj/fw-nrfconnect-nrf/commit/e4cf5d2af1f626d5e35ad0fc1ec0124996c63fd1 

    I recommend to have a look at all the changes - because some are fixing report descriptors to make them compliant. After you apply the fix the only thing needed to have mouse + keyboard reports on one peripheral device would be to enable these reports in kconfig.

    There is however one thing to know - we still don't support multiple usb hid class instances for peripheral. That is hid_state will NOT handle this situation right and we believe this was the problem that you were experiencing when trying out ncs1.4.0.

    Since there is all the code needed (I believe) to redirect reports (in hid_state) to different instances of USB HID class, this should be doable, but you still you have to add some logic to correctly select which instance to use as a selected subscriber for a given report.

Reply
  • Combining mouse and keyboard is something that we have "missed" in ncs1.3, we have added the functionality to ncs1.4.0. In general the problem is in hid_state - we have assumed all reports will go to "separate" transports (by separate I mean each handling its own state).

    The problem with usb in ncs1.3.0 is that it can send only one report at a time so there is no way you can send both mouse and keyboard report as hid_state will not know how to handle it.

    I believe this fix may have been backported to ncs1.3 - you can see the backported changes here:
    https://github.com/pdunaj/fw-nrfconnect-nrf/commits/DESK-1072 

    What you are interested in is:
    https://github.com/pdunaj/fw-nrfconnect-nrf/commit/e4cf5d2af1f626d5e35ad0fc1ec0124996c63fd1 

    I recommend to have a look at all the changes - because some are fixing report descriptors to make them compliant. After you apply the fix the only thing needed to have mouse + keyboard reports on one peripheral device would be to enable these reports in kconfig.

    There is however one thing to know - we still don't support multiple usb hid class instances for peripheral. That is hid_state will NOT handle this situation right and we believe this was the problem that you were experiencing when trying out ncs1.4.0.

    Since there is all the code needed (I believe) to redirect reports (in hid_state) to different instances of USB HID class, this should be doable, but you still you have to add some logic to correctly select which instance to use as a selected subscriber for a given report.

Children
No Data
Related