以下是論壇里找到的沁恒廠商提供的CH579與BLE外設(shè)混合使用的例程DEMO
打開工程編譯不過,發(fā)現(xiàn)缺少源文件,也是醉了,重新移植,看了這坨祖?zhèn)鞯拇a,看得真是心累,這是廠家雇大一學(xué)生寫的嗎?各種莫名其妙。不能規(guī)范一點(diǎn)么,為了節(jié)省成本真是不要face
原工程鏈接見附件:
Peripheral_usb_host_work_with_spug.rar
言歸正傳?。。。?!---------------------------------------------->
1. 同步標(biāo)志位為什么要做反轉(zhuǎn),
2.這個(gè)數(shù)據(jù)收發(fā)的DEMO寫得有什么問題沒,為什么移植到目標(biāo)芯片上就只收發(fā)成功了一次,后邊全亂了套了。
/*發(fā)送數(shù)據(jù)長度*/
uint8_t?UsbOut(?uint8_t?*pBuf,uint8_t?len?)??//?中斷端點(diǎn)3發(fā)送
{
????uint8_t?TxCnt,s,endp;
????endp?=?ThisUsbDev.GpVar[1];
????while?(?len?)?{
????????//mDelayuS(?200?);
????????R8_UH_TX_LEN?=?len?>=?32???32?:?len;
????????for?(?TxCnt?=?0;?TxCnt?!=?R8_UH_TX_LEN;?TxCnt?++?)?{
????????????TxBuffer[?TxCnt?]?=?*pBuf;
????????????pBuf?++;
????????}
????????s?=?USBHostTransact(?USB_PID_OUT?<<?4?|(?endp?&?0x7F),?endp?&?0x80???RB_UH_R_TOG?|?RB_UH_T_TOG?:?0,?0?);??//?OUT數(shù)據(jù)
????????if?(?s?==?ERR_SUCCESS?)?{
????????????len?-=?R8_UH_TX_LEN;
????????????endp?^=?0x80;??//?同步標(biāo)志翻轉(zhuǎn)
????????????ThisUsbDev.GpVar[1]?=?endp;??//?保存同步標(biāo)志位
????????????
????????}
????????else?return(?s?);
????}
????return?ERR_SUCCESS;
}
/*返回?cái)?shù)據(jù)接收長度,數(shù)據(jù)存放RxBuffer*/
uint8_t?UsbBulkIn(?void?)
{
????uint8_t?i,s,len,endp?=?ThisUsbDev.GpVar[0];
????s?=?USBHostTransact(?USB_PID_IN?<<?4?|?(endp?&?0x7F),?endp?&?0x80???RB_UH_R_TOG?|?RB_UH_T_TOG?:?0,?0?);
????if?(?s?==?ERR_SUCCESS?)?{
????????endp?^=?0x80;??//?同步標(biāo)志翻轉(zhuǎn)
????????ThisUsbDev.GpVar[0]?=?endp;??//?保存同步標(biāo)志位
????????//tmos_memcpy(RX_BUF,RxBuffer,11);
????????len?=?sizeof(RX_BUF);??//?接收到的數(shù)據(jù)長度
????????if?(?len?)?{
????????????if(m_handlers)
????????????{
????????????????usb_host_app_event_t?event;
????????????????event.type?=?USB_HOST_APP_DATA_IN;
????????????????event.data.p_data?=?RxBuffer;
????????????????//tmos_memcpy(event.data.p_data,RxBuffer,len);
????????????????event.data.bytes?=?len;
????????????????m_handlers(&event);
????????????}
//????????????USB_LOG("CH579?In?data:?\n");
//????????????for?(?i?=?0;?i?<?len;?i?++?)?USB_LOG("%02X?",(UINT16)(RxBuffer[i])?);
//????????????USB_LOG("\n");
????????}
????????return?len;
????}
????else?if?(?s?!=?(?USB_PID_NAK?|?ERR_USB_TRANSFER?)?)?USB_LOG("?error?%02x\n",(UINT16)s);??//?可能是斷開了
????return?0;
}