This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2540: HID Keyboard by USB Dongle (Feature Report)

Other Parts Discussed in Thread: CC2540

Hi to all

I'm trying to make a HID Keyboard via USB Dongle. I used HIDAdvRemoteDongle sample.

All things work well but my problem is working with "Feature Report". I changed entity0Desc (Keyboard report descriptor) in the "usb_hid_descriptor.s51" file to this one :

entity0Desc:    ; Keyboard report descriptor (using format for Boot interface descriptor)
	DB    0x05, 0x01                   ; USAGE_PAGE (Generic Desktop)
	DB    0x09, 0x06                    ; USAGE (Keyboard)
	DB    0xa1, 0x01                    ; COLLECTION (Application)
	DB    0x05, 0x07                    ;   USAGE_PAGE (Keyboard)
	DB    0x19, 0xe0                    ;   USAGE_MINIMUM (Keyboard LeftControl)
	DB    0x29, 0xe7                    ;   USAGE_MAXIMUM (Keyboard Right GUI)
	DB    0x15, 0x00                    ;   LOGICAL_MINIMUM (0)
	DB    0x25, 0x01                    ;   LOGICAL_MAXIMUM (1)
	DB    0x75, 0x01                    ;   REPORT_SIZE (1)
	DB    0x95, 0x08                    ;   REPORT_COUNT (8)
	DB    0x81, 0x02                    ;   INPUT (Data,Var,Abs)
 	DB   0x95, 0x01                    ;   REPORT_COUNT (1)
 	DB   0x75, 0x08                    ;   REPORT_SIZE (8)
 	DB   0x81, 0x01                    ;   INPUT (Cnst,Ary,Abs)
  	DB  0x95, 0x05                    ;   REPORT_COUNT (5)
	DB    0x75, 0x01                    ;   REPORT_SIZE (1)
 	DB   0x05, 0x08                    ;   USAGE_PAGE (LEDs)
  	DB  0x19, 0x01                    ;   USAGE_MINIMUM (Num Lock)
 	DB   0x29, 0x05                    ;   USAGE_MAXIMUM (Kana)
  	DB  0x91, 0x02                    ;   OUTPUT (Data,Var,Abs)
 	DB   0x95, 0x01                    ;   REPORT_COUNT (1)
  	DB  0x75, 0x03                    ;   REPORT_SIZE (3)
  	DB  0x91, 0x01                    ;   OUTPUT (Cnst,Ary,Abs)
 	DB   0x95, 0x06                    ;   REPORT_COUNT (6)
 	DB   0x75, 0x08                    ;   REPORT_SIZE (8)
 	DB   0x15, 0x00                    ;   LOGICAL_MINIMUM (0)
 	DB   0x25, 0x65                    ;   LOGICAL_MAXIMUM (101)
  	DB  0x05, 0x07                    ;   USAGE_PAGE (Keyboard)
  	DB  0x19, 0x00                    ;   USAGE_MINIMUM (Reserved (no event indicated))
  	DB  0x29, 0x65                   ;   USAGE_MAXIMUM (Keyboard Application)
 	DB   0x81, 0x00                    ;   INPUT (Data,Ary,Abs)
 	DB   0x09, 0x00                    ;   USAGE (Reserved (no event indicated))
  	DB  0x75, 0x08                    ;   REPORT_SIZE (8)
  	DB  0x95, 0x01                    ;   REPORT_COUNT (1)
 	DB   0x15, 0x00                    ;   LOGICAL_MINIMUM (0)
  	DB  0x25, 0x7f                   ;   LOGICAL_MAXIMUM (127)
 	DB   0xb1, 0x02                    ;   FEATURE (Data,Var,Abs)
 	DB   0xc0                           ; END_COLLECTION
entity0DescEnd:

I tested my code by SimpleHIDWrite. Every time that I send Feature report , I receive invalid values in the EP0 (Data received in the one time USBF0 reading):

0xFF Sent => 0xFF Received

0x02 Sent => 0x7E Received!

0xFF Sent => 0xBE Received!

cc2540 code :

.
.
void usbcrSetReport(void)
{
// Received setup header?
if (usbfwData.ep0Status == EP_IDLE) {
if ((HI_UINT16(usbSetupHeader.value) == HID_REP_TYPE_FEATURE))  // Feature Report Received
output = USBF0;
.
.
.

PrintKeys(output); // Send output value as keyboard key(!!!) to windows

Why "output" value don't valid and don't match with sent value?????

I wrote a VC++ program that send a feature report , but there is an error .GetLastError return 31 (0x1F) [A device attached to the system is not functioning] and HidD_SetFeature return zero. why?????

VC++ code :

	buff[0] = 0; // ReportID
	buff[1] = 0x3; //Report Value
	res = hid_send_feature_report(handle, buff, 2);
	if (res < 0) {
		printf("Unable to send a feature report.\n");
	}

Sorry for my English language ;-)

  • Hi,

    I'm not sure what is going on. Perhaps if you had a USB trace someone can help out.

    Best wishes
  • hamid reza mehrabian said:
    I wrote a VC++ program that send a feature report , but there is an error .GetLastError return 31 (0x1F) [A device attached to the system is not functioning] and HidD_SetFeature return zero. why?????

    HID keyboard is a so-called system device, which is exclusively opened by Windows system.

    "Top-Level Collections Opened by Windows for System Use"
    msdn.microsoft.com/.../ff543477(VS.85).aspx

    To open such "exclusive" HID device from your application, you have to apply these parameters to CreateFile()
    - dwDesiredAccess = 0
    - dwShareMode = (FILE_SHARE_READ | FILE_SHARE_WRITE)

    WriteFile() and ReadFile() to "exclusive" device are not allowed.
    but HidD_SetFeature()/HidD_GetFeature()
    and HidD_GetInputReport()/HidD_SetOutputReport() should work.

    Tsuneo