資源簡介
使用單片機的IO口直接模擬USB接口,實現單片機通過USB與計算機連接.

代碼片段和文件信息
/*?Name:?opendevice.c
?*?Project:?AVR-USB?host-side?library
?*?Author:?Christian?Starkjohann
?*?Creation?Date:?2008-04-10
?*?Tabsize:?4
?*?Copyright:?(c)?2008?by?objectIVE?DEVELOPMENT?Software?GmbH
?*?License:?GNU?GPL?v2?(see?License.txt)?GNU?GPL?v3?or?proprietary?(CommercialLicense.txt)
?*?This?Revision:?$Id:?opendevice.c?692?2008-11-07?15:07:40Z?cs?$
?*/
/*
General?Description:
The?functions?in?this?module?can?be?used?to?find?and?open?a?device?based?on
libusb?or?libusb-win32.
*/
#include?
#include?“opendevice.h“
/*?-------------------------------------------------------------------------?*/
#define?MATCH_SUCCESS 1
#define?MATCH_FAILED 0
#define?MATCH_ABORT -1
/*?private?interface:?match?text?and?p?return?MATCH_SUCCESS?MATCH_FAILED?or?MATCH_ABORT.?*/
static?int??_shellstyleMatch(char?*text?char?*p)
{
int?last?matched?reverse;
????for(;?*p;?text++?p++){
????????if(*text?==?0?&&?*p?!=?‘*‘)
????????????return?MATCH_ABORT;
????????switch(*p){
????????case?‘\\‘:
????????????/*?Literal?match?with?following?character.?*/
????????????p++;
????????????/*?FALLTHROUGH?*/
????????default:
????????????if(*text?!=?*p)
????????????????return?MATCH_FAILED;
????????????continue;
????????case?‘?‘:
????????????/*?Match?anything.?*/
????????????continue;
????????case?‘*‘:
????????????while(*++p?==?‘*‘)
????????????????/*?Consecutive?stars?act?just?like?one.?*/
????????????????continue;
????????????if(*p?==?0)
????????????????/*?Trailing?star?matches?everything.?*/
????????????????return?MATCH_SUCCESS;
????????????while(*text)
????????????????if((matched?=?_shellstyleMatch(text++?p))?!=?MATCH_FAILED)
????????????????????return?matched;
????????????return?MATCH_ABORT;
????????case?‘[‘:
????????????reverse?=?p[1]?==?‘^‘;
????????????if(reverse)?/*?Inverted?character?class.?*/
????????????????p++;
????????????matched?=?MATCH_FAILED;
????????????if(p[1]?==?‘]‘?||?p[1]?==?‘-‘)
????????????????if(*++p?==?*text)
????????????????????matched?=?MATCH_SUCCESS;
????????????for(last?=?*p;?*++p?&&?*p?!=?‘]‘;?last?=?*p)
????????????????if?(*p?==?‘-‘?&&?p[1]?!=?‘]‘???*text?<=?*++p?&&?*text?>=?last?:?*text?==?*p)
????????????????????matched?=?MATCH_SUCCESS;
????????????if(matched?==?reverse)
????????????????return?MATCH_FAILED;
????????????continue;
????????}
????}
????return?*text?==?0;
}
/*?public?interface?for?shell?style?matching:?returns?0?if?fails?1?if?matches?*/
static?int?shellstyleMatch(char?*text?char?*pattern)
{
????if(pattern?==?NULL)?/*?NULL?pattern?is?synonymous?to?“*“?*/
????????return?1;
????return?_shellstyleMatch(text?pattern)?==?MATCH_SUCCESS;
}
/*?-------------------------------------------------------------------------?*/
int?usbGetStringAscii(usb_dev_handle?*dev?int?index?char?*buf?int?buflen)
{
char????buffer[256];
int?????rval?i;
????if((rval?=?usb_get_string_simple(dev?index?buf?buflen))?>=?0)?/*?use?libusb?version?if?it?works?*/
????????return?rval;
????if((rval?=?usb_control_msg(dev?USB_ENDPOINT_IN?USB_REQ_GET
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\
?????文件???????11812??2008-11-26?17:24??avrusb-20081126\Changelog.txt
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\circuits\
?????文件????????4297??2008-11-26?17:24??avrusb-20081126\circuits\Readme.txt
?????文件????????8316??2008-11-26?17:24??avrusb-20081126\circuits\tiny45-rc.png
?????文件??????193502??2008-11-26?17:24??avrusb-20081126\circuits\tiny45-rc.sch
?????文件???????13285??2008-11-26?17:24??avrusb-20081126\circuits\with-series-diodes.png
?????文件??????213956??2008-11-26?17:24??avrusb-20081126\circuits\with-series-diodes.sch
?????文件???????14060??2008-11-26?17:24??avrusb-20081126\circuits\with-vreg.png
?????文件??????215922??2008-11-26?17:24??avrusb-20081126\circuits\with-vreg.sch
?????文件???????13421??2008-11-26?17:24??avrusb-20081126\circuits\with-zener.png
?????文件??????225561??2008-11-26?17:24??avrusb-20081126\circuits\with-zener.sch
?????文件????????6705??2008-11-26?17:24??avrusb-20081126\CommercialLicense.txt
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\examples\
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\examples\custom-class\
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\examples\custom-class\commandline\
?????文件????????1192??2008-11-26?17:24??avrusb-20081126\examples\custom-class\commandline\Makefile
?????文件?????????539??2008-11-26?17:24??avrusb-20081126\examples\custom-class\commandline\Makefile.windows
?????文件????????8682??2008-11-26?17:24??avrusb-20081126\examples\custom-class\commandline\opendevice.c
?????文件????????4079??2008-11-26?17:24??avrusb-20081126\examples\custom-class\commandline\opendevice.h
?????文件????????5683??2008-11-26?17:24??avrusb-20081126\examples\custom-class\commandline\set-led.c
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\examples\custom-class\firmware\
?????文件????????3857??2008-11-26?17:24??avrusb-20081126\examples\custom-class\firmware\main.c
?????文件????????6848??2008-11-26?17:24??avrusb-20081126\examples\custom-class\firmware\Makefile
?????文件????????1300??2008-11-26?17:24??avrusb-20081126\examples\custom-class\firmware\requests.h
?????文件???????16867??2008-11-26?17:24??avrusb-20081126\examples\custom-class\firmware\usbconfig.h
?????文件????????2722??2008-11-26?17:24??avrusb-20081126\examples\custom-class\Readme.txt
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\examples\hid-custom-rq\
?????目錄???????????0??2008-11-26?17:24??avrusb-20081126\examples\hid-custom-rq\commandline\
?????文件????????1193??2008-11-26?17:24??avrusb-20081126\examples\hid-custom-rq\commandline\Makefile
?????文件?????????540??2008-11-26?17:24??avrusb-20081126\examples\hid-custom-rq\commandline\Makefile.windows
............此處省略88個文件信息
評論
共有 條評論