Hi. I too have some question for HID USB demo example project for LPC2148 MCU. Demo application work good but: if don't change any code then firmware still send GetReport (button state). In my code if send SetReport then show Led (on or off) and if use GetReport then read button state. but still receive GetReport events. but if add to ReportDescriptor constant for ReportID then stop it , no automatic send GetReport. this is not my problem (of course I need to know why to do it).
but now I need to know how to make interrupt with button and firmware send GetReport to PC with out of request form PC. I don't want every cycle time control if is change button state. there must be some function , whee I set report ID and fill buffer with data and execute code . and on PC I detect events. what is that function??? I want create small USB RFID reader. if read card then automatic send events to PC so card is read. now I must repeated demand that the card was loaded or not
best regards
Hi. I thinks so find solution: http://www.keil.com/forum/11531/ But I need help to better understand.
original example (for LPC2148) still send data to PC (GetReport) . where is this part of code??? in ISR or EndPoint0 ????
max size of data for send and read??? is max to 64bytes . but in my older application (low speed usb) in report ID I can set more then 128bytes. what is different??? my ReportDescriptor from V-USB project:
PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */ 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop) 0x09, 0x01, // USAGE (Vendor Usage 1) 0xa1, 0x01, // COLLECTION (Application) 0x85, 0x77, // REPORT_ID (0x77) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 0x75, 0x08, // REPORT_SIZE (8) 0x95, 0x08, // REPORT_COUNT (240) // C7 0x09, 0x00, // USAGE (Undefined) 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf) 0x09, 0x01, // USAGE (Vendor Usage 1) 0x95, 0x07, // REPORT_COUNT (5 bytes) 0x81, 0x02, // INPUT (Data,Var,Abs) 0x85, 0x78, // Report ID 78 0x09, 0x01, // USAGE (Vendor Usage 1) 0x95, 0x07, // REPORT_COUNT (5 bytes) 0x81, 0x02, // INPUT (Data,Var,Abs) 0xc0 // END_COLLECTION
and in my project is it only software implementation of USB.
I'm not sure if I can help you. I don't recognize your descriptor code.
original example (for LPC2148) still send data to PC (GetReport)
In my example code for the MCB2140 Keil board, GetInReport() is a function in the demo.c file.
All it does is read the PB and set InReport High or Low.
The Host (PC HID) will continually send a poll looking for data from any USB device connected. Your descriptor file request the frequency of this poll. Note I said request. Because the windows HID will set the frequency depending on the USB bus loading.
If you have data, you load the data in the FIFO and on the next poll, the data is sent to the host. If you do not have data in the FIFO, the USB engine in the hardware will send a NAK to the Host with no action from your code. Your Host application code maybe continually sending a "get data" request. The following is copied from Tsuneo Chinzei's post that you referenced.
When you follow Keil example, you may send the Input report in the USB IN Endpoint (EP) interrupt handler (ISR). The ISR is called every time when the host reads out the IN EP. That is, this interrupt is triggered by the host side event. However, you want to send the report just when you detect button change. That is, it is triggered by the device side (user) event.
That is why the EP ISR is not suitable for your purpose. Simply send the Input report when you detect button change. It means that the FIFO filler routine, USB_WriteEP(), is called in the main loop task, or in another ISR like timer ISR.
Note what he has said. You don't need to wait for an InReport ISR. You just look at your local PB and send data to the FIFO on a button change. Read again carefully what Tsuneo Chinzei has written and the code he included. http://www.keil.com/forum/11531/ and http://www.keil.com/forum/docs/thread11461.asp
max size of data for send and read??? is max to 64bytes.
The maximum packet size is 64 bytes but you can send as many packets as required to complete the data record you wish to send. Again the max packet size is defined in the descriptor file. The max record size is also defined in your descriptor file.
The max packet size tells the HID what size of data is contained in one packet. The max record size tells the HID application the number of packets to buffer until the data record is complete. If your data record is not a multiple of your packet size, then you must either pad your record to a full packet or you must tell HID that you have completed a data record by sending a ZLP (Zero Length Packet).
my ReportDescriptor from V-USB project:
Again I do not recognize this report descriptor. Can you better identify where this example code is located?
Bradford
Hi. about max. packet size. Fifo forTx and Rx is max size 64 bytes (hardware defined). but this is size of user data with ReportID or with out???
Step by step: original ReportDescriptor in Hid Demo is :
const BYTE HID_ReportDescriptor[] = { HID_UsagePageVendor(0x00), HID_Usage(0x01), HID_Collection(HID_Application), HID_UsagePage(HID_USAGE_PAGE_BUTTON), HID_UsageMin(1), HID_UsageMax(3), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportCount(3),/*3*/ HID_ReportSize(1),/*1*/ HID_Input(HID_Data | HID_Variable | HID_Absolute), HID_ReportCount(1), HID_ReportSize(5), HID_Input(HID_Constant), HID_UsagePage(HID_USAGE_PAGE_LED), HID_Usage(HID_USAGE_LED_GENERIC_INDICATOR), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportCount(8), HID_ReportSize(1), HID_Output(HID_Data | HID_Variable | HID_Absolute), HID_EndCollection, };
if open my application then receive 33 events per second (GetReport) but if add to report descriptor reportID.
const BYTE HID_ReportDescriptor[] = { HID_UsagePageVendor(0x00), HID_Usage(0x01), HID_Collection(HID_Application), HID_UsagePage(HID_USAGE_PAGE_BUTTON), HID_UsageMin(1), HID_UsageMax(3), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportID(0x0A), HID_ReportCount(3),/*3*/ HID_ReportSize(1),/*1*/ HID_Input(HID_Data | HID_Variable | HID_Absolute), HID_ReportCount(1), HID_ReportSize(5), HID_Input(HID_Constant), HID_UsagePage(HID_USAGE_PAGE_LED), HID_Usage(HID_USAGE_LED_GENERIC_INDICATOR), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportID(0x0A), HID_ReportCount(8), HID_ReportSize(1), HID_Output(HID_Data | HID_Variable | HID_Absolute), HID_EndCollection, };
then stop it. and I read data only if send request GetReport.
About max record size. My AVR application use max packet size 8 bytes and record size is up to 256 bytes? (with report ID).
I thinks so it's not just set in ReportDescriptor HID_ReportCount to 136 (example) and all work.
is possible to help me with this code??? If I use max record size 64bytes (max packet size) then user data are only 63 bytes + 1 report ID . is it right??? where and how can I detect so this packet is last .