资源简介
使用单片机的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个文件信息
评论
共有 条评论