请问有CH372的HID方面的例子吗?

我在做HID的键盘,用CH272芯片,遇到了问题,贵公司有例子吗?

好像网上没有啊!!


以下例子,供参考: //CH372外部固件模式 命令子函数 默认在24MHz下 #include #include #include #include #include //#ifndef DELAY_CONSTANT //#define DELAY_CONSTANT //#endif sbit KEY= P3^3; sbit LED4= P1^4; sbit LED5= P1^5; sbit LED6= P1^6; sbit LED7= P1^7; UINT8 int_status; //bit flag_err_unknownsetup;

//UINT8 data_buf[8]; union _ep0_data { UINT8 data_buf[8]; struct { UINT8 bmRequestType; //标准请求字 UINT8 bRequest; //请求代码 UINT16 wValue; //特性选择高 UINT16 wIndx; //索引 UINT16 wLength; //数据长度 }device_request; }ep0_data;

struct _desc_info { UINT8 desc_type; UINT8 desc_index; UINT8 desc_length; }desc_info;

bit flag_return_desc; bit flag_configured; bit flag_set_add; bit flag_report_input; UINT8 configure_value;

UINT8 report_input_length; UINT8 report_id; UINT8 report_x=0,report_y=0; /////////////////////////////// UINT8 test_temp=0xff; UINT8 idata test_buf[128]; UINT8 test_count=0; //////////////////////////////// UINT8 *p_desc_type;

void delay(); UINT8 CH37x_get_status(); void CH37x_unlock_usb(); UINT8 CH37x_rd_usb_data(); void CH37x_set_endp3(UINT8); void CH37x_set_usb_addr(UINT8); void CH37x_return_desc(); void CH37x_wr_usb_data3(UINT8); void CH37x_wr_usb_data5(UINT8); bit CH37x_set_usb_mode(UINT8); void CH37x_set_endp4(UINT8); void CH37x_set_endp5(UINT8); void CH37x_set_endp6(UINT8); void CH37x_set_endp7(UINT8); void CH37x_return_report(); void intt0() interrupt 0 //using 1 { UINT8 status_temp,ep0_data_len,requesttype_temp,usb_address; IE0=0; status_temp=CH37x_get_status(); switch(status_temp) { case(USB_INT_EP0_SETUP): { ep0_data_len=CH37x_rd_usb_data(); if(ep0_data_len!=8) { //flag_err_unknownsetup=1; CH37x_set_endp3(0x0f);//return stall break; } /////////////////// test_buf[test_count++]=ep0_data.device_request.bmRequestType; test_buf[test_count++]=ep0_data.device_request.bRequest; test_buf[test_count++]=ep0_data.data_buf[2]; test_buf[test_count++]=ep0_data.data_buf[3]; test_buf[test_count++]=ep0_data.data_buf[4]; test_buf[test_count++]=ep0_data.data_buf[5]; test_buf[test_count++]=ep0_data.data_buf[6]; test_buf[test_count++]=ep0_data.data_buf[7]; /////////////////// requesttype_temp=ep0_data.device_request.bmRequestType>>5&0x03; switch(requesttype_temp) { case(0): //setup standard request { switch(ep0_data.device_request.bRequest) { case(DEF_USB_GET_STATUS): { ep0_data.data_buf[0]=0; ep0_data.data_buf[1]=0; CH37x_wr_usb_data3(2); break;//asm// return 数据0 } case(DEF_USB_CLR_FEATURE): { if(ep0_data.device_request.bmRequestType&0x1f==0x02) { switch(ep0_data.data_buf[4]) { case(0x82): { CH37x_set_endp7(0x8E); //发命令清除端点 break; } case(0x02): { CH37x_set_endp6(0x80); //清除端点2下传 break; } case(0x81): { CH37x_set_endp5(0x8E); break; } case(0x01): { CH37x_set_endp4(0x80); break; } default: break; } } else{CH37x_set_endp3(0x0f);}//return stall break; } case(DEF_USB_SET_FEATURE): { CH37x_set_endp3(0x0f);//return stall break; } case(DEF_USB_SET_ADDRESS): //////////////LED { usb_address=ep0_data.data_buf[2];//ep0_data.device_request.wValue>>8&0xff (UINT8); CH37x_wr_usb_data3(0);//CH37x_set_endp3(0xc0); //return ack //ep0_data.data_buf[0]=0;CH37x_wr_usb_data3(1); //delay();delay(); flag_set_add=1; break; } case(DEF_USB_GET_DESCR): ///////////////LED { desc_info.desc_type=ep0_data.data_buf[3]; desc_info.desc_index=ep0_data.data_buf[2]; desc_info.desc_length=ep0_data.data_buf[6]; flag_return_desc=1; switch(desc_info.desc_type) { case(1):{p_desc_type=device_descriptor;break;} case(2):{p_desc_type=config_descriptor;break;}//config interface class endpoint desc case(3): { //siwtch(desc_info.desc_index) //{ case(0):{p_desc_type=string_descriptor;break;} //case(1):{break;} //case(2):{break;} //} break; } case(4):{p_desc_type=interface_descriptor;break;} case(5):{p_desc_type=endpoint_descriptor;break;} case(0x21):{p_desc_type=hid_descriptor;break;}//hid descriptor case(0x22):{p_desc_type=report_descriptor;desc_info.desc_length=0x32;flag_report_input=1;break;}//report descriptor // case(0x23):{p_desc_type=physical_descriptor;break;}//physical descriptor } CH37x_return_desc(); break; } case(DEF_USB_SET_DESCR): { CH37x_set_endp3(0x0f);//return stall break; } case(DEF_USB_GET_CONFIG): { if(!flag_configured){ep0_data.data_buf[0]=0;CH37x_wr_usb_data3(1);} else {ep0_data.data_buf[0]=configure_value;CH37x_wr_usb_data3(1);} break; } case(DEF_USB_SET_CONFIG): { configure_value=ep0_data.data_buf[2]; flag_configured=1; CH37x_wr_usb_data3(0);// break; } //asm//从SET CONFIG 中得到CONFIG VALUE 返回ACK 保存,在GET CONFIG 中将CONFIG VALUE 返回, case(DEF_USB_GET_INTERF): { ep0_data.data_buf[0]=0;//asm//返回数据0 CH37x_wr_usb_data3(1); break; } case(DEF_USB_SET_INTERF): { CH37x_set_endp3(0x0f);//return stall break; } case(DEF_USB_SYNC_FRAME): { CH37x_set_endp3(0x0f);//return stall break; } default:{CH37x_set_endp3(0x0f);break;}//return stall } break; } case(1): //setup class request { /*switch(ep0_data.device_request.bRequest) { case(DEF_USB_HID_GET_REPORT): { switch(ep0_data.data_buf[3]) { case(1): //report type is input { //flag_report_input=1; report_input_length=0x32;//ep0_data.data_buf[7]; report_id=ep0_data.data_buf[2]; //CH37x_wr_usb_data3(0); p_desc_type=report_descriptor; CH37x_return_report(); break; } case(2):{CH37x_set_endp3(0x0f);break;} //report type is output case(3):{CH37x_set_endp3(0x0f);break;} //report type is feature } // CH37x_wr_usb_data3(0); LED4=0; break; } case(DEF_USB_HID_SET_REPORT):{LED5=0;CH37x_set_endp3(0x0f);break;}

case(DEF_USB_HID_GET_IDLE):{CH37x_set_endp3(0x0f);break;}//return stall case(DEF_USB_HID_GET_PROTOCOL):{CH37x_set_endp3(0x0f);break;}//return stall case(DEF_USB_HID_SET_IDLE):{CH37x_wr_usb_data3(0);break;}//return ack case(DEF_USB_HID_SET_PROTOCOL):{CH37x_set_endp3(0x0f);break;}//return stall } LED7=0;test_temp=ep0_data.device_request.bRequest;*/ break; } case(2):CH37x_set_endp3(0x0f);break; //setup vendor request case(3):CH37x_set_endp3(0x0f);break; //reserved request default:{CH37x_set_endp3(0x0f);break;}//return stall } break; } case(USB_INT_EP0_OUT):break; case(USB_INT_EP0_IN): { if(flag_return_desc)CH37x_return_desc(); else if(flag_set_add){CH37x_set_usb_addr(usb_address);flag_set_add=0;} else{} break; } case(USB_INT_EP1_OUT):break; case(USB_INT_EP1_IN):break; case(USB_INT_EP2_OUT):break; case(USB_INT_EP2_IN):break; case(USB_INT_BUS_RESET1):{flag_configured=0;flag_return_desc=0;flag_set_add=0;flag_report_input=0;break;} case(USB_INT_BUS_RESET2):{flag_configured=0;flag_return_desc=0;flag_set


顶一个!!!! 谢谢您的分析!!


这是一个用CH372/CH375做USB鼠标的例子,实验是通过的。就是没有注释,有兴趣拿去参考参考


怎么好像是照着cy的片子上修改的啊?


这是不可能的.


能够提供c的源代码吗? 这样的格式看起来太费尽啊! 谢谢!!


看不懂也,调试也没通过


谢谢分享·~顶了


只有登录才能回复,可以选择微信账号登录