Hi, I use usb HID to send and recive data. I used the sdk to generate the code. the way it is generated,
is when host send data to the micro (interrupt out), it will end up inside USB_DeviceHidGenericAction, then USB_DeviceHidSend is used to send data to host, then USB_DeviceHidRecv , is used to get the data that the host sent. in this case, USB_DeviceHidSend works fine.
However, I can only send data to host, only, when the host try sent data to the micro and I want to send and receive data separately. So what I tried to do is outside USB_DeviceHidGenericAction, and after specific time pass, I call USB_DeviceHidSend to send data to host. however, first time it return kStatus_USB_Success, then every time after it return kStatus_USB_Busy. it worth knowing that the code does not enter USB_DeviceHidInterruptIn even when it returned kStatus_USB_Success so it does not clear the busy flag.
so how I can use USB_DeviceHidSend outside of USB_DeviceHidGenericAction.
any Help is appreciated, thanks in advance.
已解决! 转到解答。
Thanks Alice, I was able to make it work Long time ago. the issue was that I thought that by connecting the USB to the PC and after the enumeration, the Hardware will start taking the data from the specified endpoints, which is not true. in order for the usb Hardware to start taking the data from endpoint, in case of HID, I need to createfile for HID in the host side, in my case PC. this will create the pipeline and the hardware will start reading the endpoint every Period, that was specified in the endpoint descriptor.
Thanks Alice, I was able to make it work Long time ago. the issue was that I thought that by connecting the USB to the PC and after the enumeration, the Hardware will start taking the data from the specified endpoints, which is not true. in order for the usb Hardware to start taking the data from endpoint, in case of HID, I need to createfile for HID in the host side, in my case PC. this will create the pipeline and the hardware will start reading the endpoint every Period, that was specified in the endpoint descriptor.
Hello,
It is not possible to send data at any time, only when USB master waiting responds from USB device, also the USB bus is not busy.
You can refer to dev_hid_generic demo under SDK, call this function "USB_DeviceHidSend()" inUSB_DeviceHidGenericCallback() function.
BR
Alice
Hi Alice, Thanks for your respond.
I understand, that after the polling time that I specified for the end point IN inside the descriptor, host (pc in my case)will check if the end point have data to read (hardware and lower layer do that for me and I do not need to send anything to check the end point).
So what I am trying to do is after every specific time I write the data to the end point(using USB_DeviceHidSend), and whenever the poling time pass the host can get the data from the end point. On the host side, when I want to read the received report, I use readfile API to read the received data(pc can keep reading up to around 22 report). so I can let the pc lower layer reading the reports and store them, then I can analyze them when it is needed.
is any part of my understanding is wrong?
Also,
using readfile does not send any thing to the host. so according to what you said, I will always need to use writefile from the pc to be able to get inside USB_DeviceInterface0HidGenericCallback then use USB_DeviceHidSend ?
Also, the following function is the one you are speaking about?
Thank you !