Вы находитесь на странице: 1из 25

APOSTILA DE MICROCONTROLA DORES PIC E PEFIFRICOS

264
}float get_float_usb() {char s[20];float f;get_string_usb(s, 20);f = atof(s);return(f);}#endif

BIBLIOTECA usb_san_desc.h:
//////////////////////////////////////// /////////////////////////////////////// usb_desc_cdc.h //////////////// //////////////////////////////////////// ///////////////////////#IFNDEF __USB_DESCRIPTORS__ #DEFINE __USB_DESCRIPTORS__ #include <usb.h>//////////////////////////// //////////////////////////////////////// //// start config descriptor //

/ right now we only support one configuration descriptor./// the config, interface, class, and endpoint goes into this array.///////////////////////// //////////////////////////////////////// ////#DEFINE USB_TOTAL _CONFIG_LEN 67 //config+interface+class+en dpoint+endpoint (2 endpoin ts)const char USB_CONFIG_DESC[] = {//IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE

ORDER OF THIS ARRAY MUST BE:// config(s)// interface(s)// class(es)// endpoint(s)//config_descrip tor for config index 1USB_DESC_CONFIG_L EN, //length of descriptor si ze ==0USB_DESC_CONF IG_TYPE, //constant CON FIGURATION (CONFIGU RATION 0x02) ==1USB_ TOTAL_CONFIG_LEN,0, //size of all data returned f or this config ==2,32, //nu mber of interfaces this devi ce supports ==40x01, //iden

tifier for this configuration. (IF we had more than one configuratio ns) ==50x00, //index of stri ng descriptor for this config uration ==60xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wak eup (we don't), bits 04 unused and bit7=1 ==70x 32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==8//interface descriptor 0 (comm class interface)USB_DESC_INT

ERFACE_LEN, //length of descriptor =9USB_DESC_I NTERFACE_TYPE, //cons tant INTERFACE (INTER FACE 0x04) =100x00, //number defining this interface (IF we had more than one interface) ==110x00, //alter nate setting ==121, //numb er of endpoints ==130x02, / /class code, 02 = Comm Interface Class ==140x02, //subclass code, 2 = Abstract ==150x 01, //protocol code, 1 = v.2

5ter ==160x00, //index of s tring descriptor for interfac e ==17//class descriptor [functional header]5, //length of descri ptor ==180x24, //dscriptor t ype (0x24 == ) ==190, //sub type (0=functional header) ==200x10,0x01, // ==21,22 //cdc version

APOSTILA DE MICROCONTROLA

DORES PIC E PEFIFRICOS

265
//class descriptor [acm header]4, //length of descri ptor ==230x24, //dscriptor t ype (0x24 == ) ==242, //su b type (2=ACM) ==252, //capabilities ==26 //we support Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.//class descriptor [union

header]5, //length of descri ptor ==270x24, //dscriptor t ype (0x24 == ) ==286, //su b type (6=union) ==290, //master intf ==30 //The interface number of the Communication or Dat a Cl ass interface, designated as the masteror controllinginterface for the union.1, //save intf0 ==31 //Interfac e number of first slave or associated interface in the union. *//class descriptor [call mgmt

header]5, //length of descri ptor ==320x24, //dscriptor t ype (0x24 == ) ==331, //sub type (1=call mgmt) ==340, //capabilities ==35 //device does not handle cal l management itself 1, //dat a interface ==36 //interface number of data c lass interface//endpoint descriptor USB_DESC_EN DPOINT_LEN, //length of descriptor ==37USB_DES C_ENDPOINT_TYPE, //co nstant ENDPOINT (ENDP

OINT 0x05) ==38USB_CD C_COMM_IN_ENDPOIN T | 0x80, //endpoint number and direction0x03, //transfer ty pe supported (0x03 is interr upt) ==40USB_CDC_CO MM_IN_SIZE,0x00, //max imum packet size supporte d ==41,42250, //polling interval, in ms. (cant be smaller than 10) = =43//interface descriptor 1 (data class interface)USB_DESC_INT ERFACE_LEN, //length of

descriptor =44USB_DESC _INTERFACE_TYPE, //co nstant INTERFACE (INTE RFACE 0x04) =450x01, //number defining this interface (IF we had more than one interface) ==460x00, //alter nate setting ==472, //numb er of endpoints ==480x0A, //class code, 0A = Data Interface Class ==490x00, / /subclass code ==500x00, // protocol code ==510x00, //i ndex of string descriptor fo r interface ==52//endpoint

descriptor USB_DESC_EN DPOINT_LEN, //length of descriptor ==60USB_DES C_ENDPOINT_TYPE, //co nstant ENDPOINT (ENDP OINT 0x05) ==61USB_CD C_DATA_OUT_ENDPOI NT, //endpoint number and direction (0x02 = EP2 OUT ) ==620x02, //transfer type supported (0x02 is bulk) == 63// make8(USB_CDC_D ATA_OUT_SIZE,0),make 8(USB_CDC_DATA_OUT _SIZE,1), //maximum pack et size supported ==64,65U

SB_CDC_DATA_OUT_SI ZE & 0xFF, (USB_CDC_DATA_OUT_ SIZE >> 8) & 0xFF, //maximum packet size supported==64, 65250, //polling interval, in ms. (cant be smaller than 10) = =66//endpoint descriptor USB_DESC_EN DPOINT_LEN, //length of descriptor ==53USB_DES C_ENDPOINT_TYPE, //co nstant ENDPOINT (ENDP OINT 0x05) ==54USB_CD C_DATA_IN_ENDPOINT

| 0x80, //endpoint number and direction (0x82 = EP2 IN) ==550x02, //transf er type supported (0x02 is bulk) ==56// make8(USB_ CDC_DATA_IN_SIZE,0), make8(USB_CDC_DATA _IN_SIZE,1), //maximum p acket size supported ==57, 58USB_CDC_DATA_IN_ SIZE & 0xFF, (USB_CDC _DATA_IN_SIZE >> 8) & 0xFF, //maximum packet si ze supported ==64, 65250, //polling interval, in ms. (cant be smaller than 10) =

=59};//****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********//since we can't make pointers to constants in certain pic16s, this is an offset table to find// a specific descriptor in the above table.//the maximum number of interfaces seen on any config//for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as

2#define USB_MAX_NU M_INTERFACES 2

APOSTILA DE MICROCONTROLA DORES PIC E PEFIFRICOS

266
//define how many interfaces there are per config. [0] is the first config, etc.const char USB_NUM_INTERF

ACES[USB_NUM_CONFI GURATIONS]={2};//defin e where to find class descriptors//first dimension is the config number //second dimension specifies which interface//last dimension specifies which class in this interface to get, but most will only have 1 class per interface//if a class descriptor is not valid, set the value to 0xFFFFconst int16 USB_C LASS_DESCRIPTORS[U

SB_NUM_CONFIGURAT IONS][USB_MAX_NUM_ INTERFACES][4]={//conf ig 1//interface 0//class 1418,23,27,32,//interface 1//no classes for this interface0xFFFF,0xFFFF,0 xFFFF,0xFFFF};#if (sizeof(USB_CONFIG_DE SC) != USB_TOTAL_CONFIG _LEN)#error USB_TOTAL_CONFIG_L EN not defined correctly#endif ///////////////// ////////////////////////////////////////

/////////////// start device desc riptors////////////////////////////// /////////////////////////////////////// const char USB_DEVICE_DESC[US B_DESC_DEVICE_LEN] ={//starts of with device configuration. only one possibleUSB_DESC_DEVI CE_LEN, //the length of this report ==00x01, //the constant DEVICE (DEVICE 0x01) ==10x10,0x01, //usb version in

bcd ==2,30x02, //class code. 0x02=Communication Device Class ==40x00, //subclass code ==50x00, //protocol code ==6USB_MAX_EP0_PAC KET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==70xD8,0x04, //vendor id (0x04D8 is Microchip)0x0 A,0x00, //product id// RR2 cambiado para 0x61,0 x04, //vendor id

(0x04D8 is Microchip, or is it 0x0461 ??) ==8,9// compatibilidad con .inf 0x33,0x00, //product id ==10,11// de Microchip0x00,0x01, //dev ice release number ==12,130x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==140x02, //index of string descriptor of the product ==150x00, //index of string descriptor of serial

number ==16USB_NUM_ CONFIGURATIONS //nu mber of possible configurations ==1 7};//the offset of the starting location of each string. offset[0] is the start of string 0, offset[1] is the start of string 1, etc.char USB_STRING_D ESC_OFFSET[]={0,4,12}; char const USB_STRING_DESC[]={/ /string 04, //length of string indexUSB_DESC_STRIN G_TYPE, //descriptor type

0x03 (STRING)0x09,0x04, //Mi crosoft Defined for USEnglish//string 18,USB_DESC_STRING_ TYPE,112,0,105,0,99,0,//st ring 232,

APOSTILA DE MICROCONTROLA DORES PIC E PEFIFRICOS

267

USB_DESC_STRING_TY PE,115,0,97,0,110,0,100,0, 114,0,111,0,' ',0,106,0,117, 0,99,0,97,0,' ',0,117,0,115,0 ,98,0};#ENDIF

Вам также может понравиться