2. 範例程式下載連結: (使用IAR EWARM v7.7)
stm32f401_411_usb_device_hid_test_2016
============================= interrupt in/out =============================
3. 由於之前的範例僅有mcu to pc(interrupt in)的這個部份, 因此首先我們要先補上pc to mcu(interrupt out)的這個部份.
- 先到usbd_hid_core.c去新增相關function.
- 宣告USBD_HID_DataOut function.
- 新增endpoint out的描述.
- 由於新增了endpoint out的描述, 因此需要加上endpoint out描述的length.
- 目前程式定義pc to mcu的data length為8bytes.
- 將程式燒進去後, 我們便可以開啟bus hound來進行測試, 當程式成功執行且與pc連結後, 應該會在bus hound上看到如下顯示的畫面, 此時我們選擇最上層的USB輸入裝置, 並double click它.
- 此時我們選擇endpont 1裡面的interrupt out端點, 接著將Data Length修改為8, 並在底下data的區域中輸入與畫面相同的資料, 且依照1 - 2 - 3 - 4的步驟執行..
- 此時應該已經看到LED3已經開始亮起.
- 我們可以從USBD_HID_DataOut裡面看到, 當接收完pc傳來的8bytes後, 程式便開始判斷要對哪一個LED執行on/off function, 其中我們目前只有用到Report_buf[0] 和 Report_buf[1]而已, 分別代表的意義如下:
Report_buf[0]: LED number
Report_buf[1]: On/Off
Report_buf[2]~Report_buf[7]: Reserve
- interrupt in/out 的bus hound操作圖.
- 當按下user button後, 就會開始透過interrupt in的端點來傳送資料給pc, 接著pc透過interrupt out去開啟/關閉LED3.
============================= control in/out =============================
4. 除了使用EP-1 interrupt in/out外, 還可以使用EP-0 control in/out這個方式來與 pc之間溝通, 因此首先我們要補上control in/out的程式.
- 先對EP0所需使用的變數與程式進行宣告.
- 將EP0的程式加到call back function.
- 接著在USBD_HID_Setup function內, 加入set report和get report這2個command.
- 接著完成EP0_RxReady和EP0_TxSent這兩個function.
- control out(set report command) flow:
- USBD_HID_Setup function => case HID_REQ_SET_REPORT => USBD_HID_EP0_RxReady function
- control in(get report command) flow:
- USBD_HID_Setup function => case HID_REQ_GET_REPORT => USBD_HID_EP0_TxSent function
- pc to mcu測試方式與interrupt out相同, 將程式燒入後, 使用bus hound打開裝置後, 對EP0 Control double click, 接著再輸入指令(set report), 則可以開啟/關閉LED.
- control in/out 的bus hound操作圖.
- 使用set report command讓pc傳送資料給mcu來開啟/關閉LED, 接著pc再透過get report command去讀取資料.
Hi, Is the BusCommander application available is that application opensource.. if so can you provide link to get.
回覆刪除Thanks
Sorry for the late reply, since this is not the free software, so I cannot provide a link.
刪除I just wanted to say thank you! I had to receive rumble data for the original XBOX. The original XBOX does not send rumble datathrough the usb dataout pipe but through control requests. I wasn't sure how to get the 6 bytes of rumble data the xbox sends through control requests. But this worked great with adding the case for HID_REQ_SET_REPORT
回覆刪除This was the only place I could find that talked about this!
Thanks for your feedback, it makes me keep going.
刪除