CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (2024)

FAQ Forum Help Official CCS Support SearchRegisterProfile Log in to check your private messages Log in

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

(Solved) USB_HID_REQUEST_SET_REPORT implementation

CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic
AuthorMessage
steav

Joined: 22 Nov 2011
Posts: 10


(Solved) USB_HID_REQUEST_SET_REPORT implementation
Posted: Wed Nov 05, 2014 3:36 am
Hi!
I'm using CCS PCD v5.030 with PIC24FJ256DA210 (MCP development board).
The CCS HID USB driver is working fine, but I can't get the HID get_report/set_report feature to work.

USB.h - CCS already defined these codes, but didn't implement it.

Code:

//HID Class Setup bRequest Codes
#define USB_HID_REQUEST_GET_REPORT 0x01
#define USB_HID_REQUEST_GET_IDLE 0x02
#define USB_HID_REQUEST_GET_PROTOCOL 0x03
#define USB_HID_REQUEST_SET_REPORT 0x09
#define USB_HID_REQUEST_SET_IDLE 0x0A
#define USB_HID_REQUEST_SET_PROTOCOL 0x0B

USB.c - The function which handles these codes is already defined

Code:

/**************************************************************
/* usb_isr_tkn_setup_ClassInterface()
/*
/* Input: usb_ep0_rx_buffer[1] == bRequest
/*
/* Summary: bmRequestType told us it was a Class request. The only Class this drivers supports is HID.
/* bRequest says which request. Only certain requests are valid,
/* if a non-valid request was made then return with an Wrong-Statue (IDLE)
/*
/* Part of usb_isr_tok_setup_dne()
/* Only compiled if HID_DEVICE is TRUE
/***************************************************************/
#IF USB_HID_DEVICE
void usb_isr_tkn_setup_ClassInterface(void) {
switch(usb_ep0_rx_buffer[1]) {

#IF USB_HID_BOOT_PROTOCOL
case USB_HID_REQUEST_GET_PROTOCOL: //03
debug_usb(debug_putc,"GP");
usb_ep0_tx_buffer[0]=hid_protocol[usb_ep0_rx_buffer[4]];
usb_request_send_response(1);
break;
#ENDIF

#IF USB_HID_BOOT_PROTOCOL
case USB_HID_REQUEST_SET_PROTOCOL: //0b
debug_usb(debug_putc,"SP");
hid_protocol[usb_ep0_rx_buffer[4]]=usb_ep0_rx_buffer[2];
usb_put_0len_0(); //send 0len packet69
break;
#ENDIF

#IF USB_HID_IDLE
case USB_HID_REQUEST_SET_IDLE: //0a
#error TODO: if you want to support SET_IDLE, add code here
#ENDIF

#IF USB_HID_IDLE
case USB_HID_REQUEST_GET_IDLE: //02
#error TODO: if you want to support GET_IDLE, add code here
#ENDIF


case USB_HID_REQUEST_SET_REPORT:
output_high(P_GREEN);
// Do something here
break;

case USB_HID_REQUEST_GET_REPORT:
// Do something here
break;

default:
usb_request_stall();
break;
}
}
#ENDIF

I added the USB_HID_REQUEST_SET_REPORT and USB_HID_REQUEST_GET_REPORT.
In the moment I write a packet using HIDAPI (http://www.signal11.us/oss/hidapi/), the green led lights up CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (17)

Code:

unsigned char buf[65];
res = hid_write(handle, buf, 65);

I also set all HID buffer sizes to 64:

Code:

#define USB_MAX_EP0_PACKET_LENGTH 64
#define USB_CONFIG_HID_RX_SIZE 64
#define USB_CONFIG_HID_TX_SIZE 64

Now I just want to receive USB_HID_REQUEST_SET_REPORT 64byte packets of custom data from HIDAPI, using usb_get_packet().

The strange thing is, if I use usb_kbhit() and usb_get_packet(), to check if there are some new packets available, I only get packets from the operation system asking the PIC e.g. for device descriptors, and since I receive them in my main application instead of the CCS HID driver, the USB device is freezing.

Thanks a lot!

Last edited by steav on Wed Nov 05, 2014 6:15 am; edited 1 time in total

CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (18)
Ttelmah

Joined: 11 Mar 2010
Posts: 19260


Posted: Wed Nov 05, 2014 4:44 am
Look at ex_usb_kbmouse2.c

This uses two HID reports one to handle a mouse, and one a keyboard. Note it is just sent as a packet. No fiddling changing the driver.
Then look at the reception of the LED settings.
Beware that unless you must have 64bytes, if you are using a report ID, then it is faster to keep the total packet <=64bytes, including the ID.

CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (23)
steav

Joined: 22 Nov 2011
Posts: 10


Posted: Wed Nov 05, 2014 5:01 am
Thank you for your answer!

I do it exactly the same way:

Code:

void usb_rx_task(void)
{
int8 rx_msg[USB_EP1_RX_SIZE];
if (usb_kbhit(1))
{
usb_get_packet(1, rx_msg, sizeof(rx_msg));
}
}

Unfortunately, the usb_kbhit(1) triggers on every incoming USB packet, especially on those which should by handled by the HID driver itself. If I use this code above, my USB Prober App (http://touch-base.com/documentation/USBMacProber.htm) doesn't show the string desc. (manufacturer, serial...) anymore and is freezing while waiting for these reply packets. So I decided to extend the HID driver with the code for the case USB_HID_REQUEST_SET_REPORT. I just don't know how to access the payload of a HID set report request (initiated by HIDAPI) within this switch-case.

I didn't change anything else in the driver but the sizes to 64.
As you mentioned, 32bytes of payload for each HID packet are enough for me. I can change that.

CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (28)
steav

Joined: 22 Nov 2011
Posts: 10


Posted: Wed Nov 05, 2014 6:14 am
I found the problem!

The USB driver files where included in incorrect order, overwriting some #define macros. Now it is working as it shound using usb_kbhit(), without the need of adding a USB_HID_REQUEST_SET_REPORT switch-case.

CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (33)
VernonAMiller

Joined: 11 Sep 2014
Posts: 25
Location: Contoocook, NH


Posted: Wed Nov 05, 2014 8:07 am
If it's a mistake you think one of us might make, please let us know the correct order so we can not make it CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (38)

Thanks!
VAM

CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (39)
steav

Joined: 22 Nov 2011
Posts: 10


Posted: Wed Nov 05, 2014 8:18 am
The correct order is just to include the USB files in the same way as shown as in the examples and NOT to remove #includes within driver files CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (44)

In my main application, these are the includes, copied from the PICC drivers folder:

Header includes

Code:

#include "Driver/USB/usb_desc_hid.h"
#include "Driver/USB/usb.h"
#include "Driver/USB/pic24_usb.h"

Source includes

Code:

#include "Driver/USB/usb.c"
CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (45)
VernonAMiller

Joined: 11 Sep 2014
Posts: 25
Location: Contoocook, NH


Posted: Wed Nov 05, 2014 8:40 am
steav wrote:
The correct order is just to include the USB files in the same way as shown as in the examples and NOT to remove #includes within driver files CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (50)

Cool. Thanks!

VAM

CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (51)
Ttelmah

Joined: 11 Mar 2010
Posts: 19260


Posted: Wed Nov 05, 2014 10:01 am
Well done, and well done for updating (helps others).
CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (56)
CCS Forum Index -> General CCS C DiscussionAll times are GMT - 6 Hours
Page 1 of 1


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group

CCS :: View topic - (Solved) USB_HID_REQUEST_SET_REPORT implementation (2024)
Top Articles
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 5997

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.