搜索
bottom↓
回复: 0

V-USB的Bulk-Out没法工作是怎么回事?

[复制链接]

出0入0汤圆

发表于 2013-1-20 16:53:40 | 显示全部楼层 |阅读模式
我移植了AVRCDC到LGT上。正常认出COM口。但是打开发送数据的时候,输出端并没有任何数据。这个让我觉得非常奇怪。
我移植后的代码是:

  1. /* Name: main.c
  2. * Project: AVR USB driver for CDC-SPI interface on Low-Speed USB
  3. *              for ATmega8/48/88/168
  4. * Author: Osamu Tamura
  5. * Creation Date: 2010-01-26
  6. * Tabsize: 4
  7. * Copyright: (c) 2010 by Recursion Co., Ltd.
  8. * License: Proprietary, free under certain conditions. See Documentation.
  9. *
  10. */

  11. #include <string.h>
  12. #include <avr/io.h>
  13. #include <avr/interrupt.h>
  14. #include <avr/pgmspace.h>
  15. #include <avr/wdt.h>
  16. #include <util/delay.h>

  17. #include "usbdrv.h"
  18. #include "oddebug.h"
  19. #include "iolgt8f0xa.h"

  20. #define SPI_DDR     DDRB
  21. #define SPI_PORT    PORTB
  22. #define SPI_SS      1                 // b2:DTS, b1:Break
  23. #define SPI_DO      3
  24. #define SPI_DI      4
  25. #define SPI_SCK     5                // F_CPU/64 (187.5KHz)

  26. #define SPI_PIN     PINC
  27. #define SPI_MODE    0       // 11:mode0

  28. #define HW_CDC_BULK_OUT_SIZE     8
  29. #define HW_CDC_BULK_IN_SIZE      8


  30. enum {
  31.     SEND_ENCAPSULATED_COMMAND = 0,
  32.     GET_ENCAPSULATED_RESPONSE,
  33.     SET_COMM_FEATURE,
  34.     GET_COMM_FEATURE,
  35.     CLEAR_COMM_FEATURE,
  36.     SET_LINE_CODING = 0x20,
  37.     GET_LINE_CODING,
  38.     SET_CONTROL_LINE_STATE,
  39.     SEND_BREAK
  40. };


  41. static PROGMEM char configDescrCDC[] = {   /* USB configuration descriptor */
  42.     9,          /* sizeof(usbDescrConfig): length of descriptor in bytes */
  43.     USBDESCR_CONFIG,    /* descriptor type */
  44.     67,
  45.     0,          /* total length of data returned (including inlined descriptors) */
  46.     2,          /* number of interfaces in this configuration */
  47.     1,          /* index of this configuration */
  48.     0,          /* configuration name string index */
  49. #if USB_CFG_IS_SELF_POWERED
  50.     (1 << 7) | USBATTR_SELFPOWER,       /* attributes */
  51. #else
  52.     (1 << 7),                           /* attributes */
  53. #endif
  54.     USB_CFG_MAX_BUS_POWER/2,            /* max USB current in 2mA units */

  55.     /* interface descriptor follows inline: */
  56.     9,          /* sizeof(usbDescrInterface): length of descriptor in bytes */
  57.     USBDESCR_INTERFACE, /* descriptor type */
  58.     0,          /* index of this interface */
  59.     0,          /* alternate setting for this interface */
  60.     USB_CFG_HAVE_INTRIN_ENDPOINT,   /* endpoints excl 0: number of endpoint descriptors to follow */
  61.     USB_CFG_INTERFACE_CLASS,
  62.     USB_CFG_INTERFACE_SUBCLASS,
  63.     USB_CFG_INTERFACE_PROTOCOL,
  64.     0,          /* string index for interface */

  65.     /* CDC Class-Specific descriptor */
  66.     5,           /* sizeof(usbDescrCDC_HeaderFn): length of descriptor in bytes */
  67.     0x24,        /* descriptor type */
  68.     0,           /* header functional descriptor */
  69.     0x10, 0x01,

  70.     4,           /* sizeof(usbDescrCDC_AcmFn): length of descriptor in bytes */
  71.     0x24,        /* descriptor type */
  72.     2,           /* abstract control management functional descriptor */
  73.     0x06,        /* SEND_BREAK,SET_LINE_CODING,GET_LINE_CODING,SET_CONTROL_LINE_STATE    */

  74.     5,           /* sizeof(usbDescrCDC_UnionFn): length of descriptor in bytes */
  75.     0x24,        /* descriptor type */
  76.     6,           /* union functional descriptor */
  77.     0,           /* CDC_COMM_INTF_ID */
  78.     1,           /* CDC_DATA_INTF_ID */

  79.     5,           /* sizeof(usbDescrCDC_CallMgtFn): length of descriptor in bytes */
  80.     0x24,        /* descriptor type */
  81.     1,           /* call management functional descriptor */
  82.     3,           /* allow management on data interface, handles call management by itself */
  83.     1,           /* CDC_DATA_INTF_ID */

  84.     /* Endpoint Descriptor */
  85.     7,           /* sizeof(usbDescrEndpoint) */
  86.     USBDESCR_ENDPOINT,  /* descriptor type = endpoint */
  87.     0x80|USB_CFG_EP3_NUMBER,        /* IN endpoint number */
  88.     0x03,        /* attrib: Interrupt endpoint */
  89.     8, 0,        /* maximum packet size */
  90.     USB_CFG_INTR_POLL_INTERVAL,        /* in ms */

  91.     /* Interface Descriptor  */
  92.     9,           /* sizeof(usbDescrInterface): length of descriptor in bytes */
  93.     USBDESCR_INTERFACE,           /* descriptor type */
  94.     1,           /* index of this interface */
  95.     0,           /* alternate setting for this interface */
  96.     2,           /* endpoints excl 0: number of endpoint descriptors to follow */
  97.     0x0A,        /* Data Interface Class Codes */
  98.     0,
  99.     0,           /* Data Interface Class Protocol Codes */
  100.     0,           /* string index for interface */

  101.     /* Endpoint Descriptor */
  102.     7,           /* sizeof(usbDescrEndpoint) */
  103.     USBDESCR_ENDPOINT,  /* descriptor type = endpoint */
  104.     0x01,        /* OUT endpoint number 1 */
  105.     0x02,        /* attrib: Bulk endpoint */
  106.     HW_CDC_BULK_OUT_SIZE, 0,        /* maximum packet size */
  107.     0,           /* in ms */

  108.     /* Endpoint Descriptor */
  109.     7,           /* sizeof(usbDescrEndpoint) */
  110.     USBDESCR_ENDPOINT,  /* descriptor type = endpoint */
  111.     0x81,        /* IN endpoint number 1 */
  112.     0x02,        /* attrib: Bulk endpoint */
  113.     HW_CDC_BULK_IN_SIZE, 0,        /* maximum packet size */
  114.     0,           /* in ms */
  115. };


  116. uchar usbFunctionDescriptor(usbRequest_t *rq)
  117. {

  118.     if(rq->wValue.bytes[1] == USBDESCR_DEVICE){
  119.         usbMsgPtr = (uchar *)usbDescriptorDevice;
  120.         return usbDescriptorDevice[0];
  121.     }else{  /* must be config descriptor */
  122.         usbMsgPtr = (uchar *)configDescrCDC;
  123.         return sizeof(configDescrCDC);
  124.     }
  125. }

  126. static uchar    modeBuffer[7];
  127. static uchar    sendEmptyFrame;
  128. static uchar    intr3Status;    /* used to control interrupt endpoint transmissions */

  129. /* ------------------------------------------------------------------------- */
  130. /* ----------------------------- USB interface ----------------------------- */
  131. /* ------------------------------------------------------------------------- */

  132. uchar usbFunctionSetup(uchar data[8])
  133. {
  134. usbRequest_t    *rq = (void *)data;

  135.     if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */
  136.                 uchar        value;

  137.         if( rq->bRequest==GET_LINE_CODING || rq->bRequest==SET_LINE_CODING ){
  138.            // return 0xff;
  139.            return USB_NO_MSG;
  140.         /*    GET_LINE_CODING -> usbFunctionRead()    */
  141.         /*    SET_LINE_CODING -> usbFunctionWrite()    */
  142.         }
  143.          
  144.                 value        = rq->wValue.word;
  145.         /*  DTR => SPI_SS+1                */
  146.         if( rq->bRequest==SET_CONTROL_LINE_STATE ) {
  147.             SPI_PORT    = (SPI_PORT&~(1<<(SPI_SS+1)))|((rq->wValue.word&1)<<(SPI_SS+1));

  148. #if USB_CFG_HAVE_INTRIN_ENDPOINT3
  149.             /* Report serial state (carrier detect). On several Unix platforms,
  150.              * tty devices can only be opened when carrier detect is set.
  151.              */
  152.             if( intr3Status==0 )
  153.                 intr3Status = 2;
  154. #endif
  155.         }
  156.         /*  Break => SPI_SS                */
  157.         else if( rq->bRequest==SEND_BREAK )
  158.             SPI_PORT    = (SPI_PORT&~(1<<SPI_SS))|((value&1)<<SPI_SS);

  159. #if 1
  160.         /*  Prepare bulk-in endpoint to respond to early termination   */
  161.         if((rq->bmRequestType & USBRQ_DIR_MASK) == USBRQ_DIR_HOST_TO_DEVICE)
  162.             sendEmptyFrame  = 1;
  163. #endif
  164.     }

  165.     return 0;
  166. }

  167. /*  spi buffer */
  168. static uchar    rx_buf[HW_CDC_BULK_IN_SIZE];
  169. static uchar    tx_buf[HW_CDC_BULK_OUT_SIZE];
  170. static uchar    iwptr, uwptr;

  171. /*---------------------------------------------------------------------------*/
  172. /* usbFunctionRead                                                           */
  173. /*---------------------------------------------------------------------------*/

  174. uchar usbFunctionRead( uchar *data, uchar len )
  175. {
  176.     memcpy( data, modeBuffer, 7 );
  177.     return 7;
  178. }

  179. /*---------------------------------------------------------------------------*/
  180. /* usbFunctionWrite                                                          */
  181. /*---------------------------------------------------------------------------*/

  182. uchar usbFunctionWrite( uchar *data, uchar len )
  183. {
  184.     memcpy( modeBuffer, data, 7 );
  185.     return 1;
  186. }


  187. /*  spi buffer */
  188. static uchar    rx_buf[HW_CDC_BULK_IN_SIZE];
  189. static uchar    tx_buf[HW_CDC_BULK_OUT_SIZE];
  190. static uchar    iwptr, uwptr;


  191. void usbFunctionWriteOut( uchar *data, uchar len )
  192. {
  193.         PORTA=0xFF;//这句代码为啥就是不执行呢?
  194.     /*  host -> spi     */
  195.     while( len-- )
  196.         tx_buf[uwptr++] = *data++;

  197.     /*  postpone receiving next data    */
  198.            usbDisableAllRequests();
  199. }


  200. static void hardwareInit(void)
  201. {

  202.     /* activate pull-ups except on USB lines */
  203.     USB_CFG_IOPORT   = (uchar)~((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));
  204.     /* all pins input except USB (-> USB reset) */
  205. #ifdef USB_CFG_PULLUP_IOPORT    /* use usbDeviceConnect()/usbDeviceDisconnect() if available */
  206.     USBDDR    = 0;    /* we do RESET by deactivating pullup */
  207.     usbDeviceDisconnect();
  208. #else
  209.     USBDDR    = (1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT);
  210. #endif

  211.     /* keep 300 mS  */
  212.     _delay_ms( 300.0 );

  213. #ifdef USB_CFG_PULLUP_IOPORT
  214.     usbDeviceConnect();
  215. #else
  216.     USBDDR    = 0;      /*  remove USB reset condition */
  217. #endif
  218. }

  219. void clockInit()
  220. {
  221.         uchar i,j;
  222.                 DDRC = DDRC & 0xFC;
  223.                 DDRA=0xFF;
  224.                 PORTA=0x00;
  225.         //USB初始化……
  226.                 // b. 打开外部晶振
  227.                 PMCR = (1 << RC16MEN) ;//| (1 << OSCMEN);
  228.                 i=255;
  229.                 while(i--)
  230.                 {
  231.                         j=255;while(j--);
  232.                 }
  233.                 // d. 切换时钟到外部晶体
  234.                 PMCR = (1 << EXTMSEL)|(1 << RC16MEN);
  235. }

  236. int main(void)
  237. {
  238.         uchar i;
  239.         clockInit();
  240.         SP=0x2ff;
  241.     wdt_enable( WDTO_1S );
  242.     //odDebugInit();
  243.     //hardwareInit();
  244.     usbInit();

  245.     intr3Status = 0;
  246.     sendEmptyFrame  = 0;

  247.     /* Set MOSI, SCK and /SS output, all others input        */
  248.     //SPI_DDR     = (1<<SPI_DO)|(1<<SPI_SCK)|(3<<SPI_SS);
  249.         //SPI_PORT    = (~SPI_DDR)|(3<<SPI_SS);

  250.     /* Enable SPI, Master, set clock rate fck/64   */
  251.    // SPCR    = (1<<SPE)|(1<<MSTR)|(1<<SPR1);
  252.        
  253.                 usbDeviceDisconnect();         // 复位
  254.                 for(i = 0; i<100; i++)  // 等待 500 ms
  255.                 {
  256.                         wdt_reset();                 // 复位WDT
  257.                         _delay_ms(1);
  258.                 }
  259.                 usbDeviceConnect();
  260.                 sei();                                         // 开中断
  261.         PORTA=0x01;       
  262.     for(;;){    /* main event loop */
  263.         wdt_reset();
  264.         usbPoll();

  265.         /*  host => device  */
  266.         if( uwptr!=0 && iwptr==0 ) {
  267.                    usbEnableAllRequests();

  268.                         //        set SPI mode
  269.            // SPCR    &= ~(3<<CPHA);
  270.           //  SPCR    |= (((~SPI_PIN)>>SPI_MODE)&3)<<CPHA;

  271.                 while( iwptr<uwptr ) {
  272.                                
  273.                                 iwptr++;
  274.                 /* Start transmission */
  275.                // SPDR    = tx_buf[iwptr];
  276.               /*  while( !(SPSR&(1<<SPIF)) )
  277.                                 wdt_reset();
  278.                 rx_buf[iwptr++] = SPDR;*/
  279.             }
  280.                         uwptr        = 0;
  281.         }

  282.         /*  host <= device  */
  283.         if( usbInterruptIsReady() && (iwptr|sendEmptyFrame) ) {
  284.             usbSetInterrupt(rx_buf, iwptr);
  285.             sendEmptyFrame    = iwptr & HW_CDC_BULK_IN_SIZE;
  286.             iwptr        = 0;
  287.         }

  288. #if USB_CFG_HAVE_INTRIN_ENDPOINT3
  289.         /* We need to report rx and tx carrier after open attempt */
  290.         if(intr3Status != 0 && usbInterruptIsReady3()){
  291.             static uchar serialStateNotification[10] = {0xa1, 0x20, 0, 0, 0, 0, 2, 0, 3, 0};

  292.             if(intr3Status == 2){
  293.                 usbSetInterrupt3(serialStateNotification, 8);
  294.             }else{
  295.                 usbSetInterrupt3(serialStateNotification+8, 2);//PORTA=-PORTA;
  296.             }
  297.             intr3Status--;
  298.         }

  299. #endif
  300.     }
  301.     return 0;
  302. }

复制代码
usbconfig.h
  1. /* Name: usbconfig.h
  2. * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
  3. * Author: Christian Starkjohann
  4. * Creation Date: 2005-04-01
  5. * Tabsize: 4
  6. * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
  7. * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
  8. * This Revision: $Id: usbconfig-prototype.h 740 2009-04-13 18:23:31Z cs $
  9. */

  10. #ifndef __usbconfig_h_included__
  11. #define __usbconfig_h_included__

  12. /*
  13. General Description:
  14. This file is an example configuration (with inline documentation) for the USB
  15. driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is
  16. also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
  17. wire the lines to any other port, as long as D+ is also wired to INT0 (or any
  18. other hardware interrupt, as long as it is the highest level interrupt, see
  19. section at the end of this file).
  20. + To create your own usbconfig.h file, copy this file to your project's
  21. + firmware source directory) and rename it to "usbconfig.h".
  22. + Then edit it accordingly.
  23. */

  24. /* ---------------------------- Hardware Config ---------------------------- */

  25. /* #define USB_CFG_IOPORTNAME      D */
  26. /* This is the port where the USB bus is connected. When you configure it to
  27. * "B", the registers PORTB, PINB and DDRB will be used.
  28. */
  29. /* #define USB_CFG_DMINUS_BIT      4 */
  30. /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
  31. * This may be any bit in the port.
  32. */
  33. /* #define USB_CFG_DPLUS_BIT       2 */
  34. /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
  35. * This may be any bit in the port. Please note that D+ must also be connected
  36. * to interrupt pin INT0! [You can also use other interrupts, see section
  37. * "Optional MCU Description" below, or you can connect D- to the interrupt, as
  38. * it is required if you use the USB_COUNT_SOF feature. If you use D- for the
  39. * interrupt, the USB interrupt will also be triggered at Start-Of-Frame
  40. * markers every millisecond.]
  41. */

  42. #define USB_CFG_IOPORTNAME      D
  43. #define USB_CFG_DMINUS_BIT      6
  44. #define USB_CFG_DPLUS_BIT       2


  45. #define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
  46. /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
  47. * 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the code require no
  48. * crystal, they tolerate +/- 1% deviation from the nominal frequency. All
  49. * other rates require a precision of 2000 ppm and thus a crystal!
  50. * Default if not specified: 12 MHz
  51. */
  52. #define USB_CFG_CHECK_CRC       0
  53. /* Define this to 1 if you want that the driver checks integrity of incoming
  54. * data packets (CRC checks). CRC checks cost quite a bit of code size and are
  55. * currently only available for 18 MHz crystal clock. You must choose
  56. * USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
  57. */

  58. /* ----------------------- Optional Hardware Config ------------------------ */

  59. /* #define USB_CFG_PULLUP_IOPORTNAME   D */
  60. /* If you connect the 1.5k pullup resistor from D- to a port pin instead of
  61. * V+, you can connect and disconnect the device from firmware by calling
  62. * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
  63. * This constant defines the port on which the pullup resistor is connected.
  64. */
  65. /* #define USB_CFG_PULLUP_BIT          4 */
  66. /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
  67. * above) where the 1.5k pullup resistor is connected. See description
  68. * above for details.
  69. */

  70. /* --------------------------- Functional Range ---------------------------- */

  71. #define USB_CFG_HAVE_INTRIN_ENDPOINT    1
  72. /* Define this to 1 if you want to compile a version with two endpoints: The
  73. * default control endpoint 0 and an interrupt-in endpoint (any other endpoint
  74. * number).
  75. */
  76. #define USB_CFG_HAVE_INTRIN_ENDPOINT3   1
  77. /* Define this to 1 if you want to compile a version with three endpoints: The
  78. * default control endpoint 0, an interrupt-in endpoint 3 (or the number
  79. * configured below) and a catch-all default interrupt-in endpoint as above.
  80. * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
  81. */
  82. #define USB_CFG_EP3_NUMBER              3
  83. /* If the so-called endpoint 3 is used, it can now be configured to any other
  84. * endpoint number (except 0) with this macro. Default if undefined is 3.
  85. */
  86. /* #define USB_INITIAL_DATATOKEN           USBPID_DATA1 */
  87. /* The above macro defines the startup condition for data toggling on the
  88. * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1.
  89. * Since the token is toggled BEFORE sending any data, the first packet is
  90. * sent with the oposite value of this configuration!
  91. */
  92. #define USB_CFG_IMPLEMENT_HALT          0
  93. /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
  94. * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
  95. * it is required by the standard. We have made it a config option because it
  96. * bloats the code considerably.
  97. */
  98. #define USB_CFG_SUPPRESS_INTR_CODE      0
  99. /* Define this to 1 if you want to declare interrupt-in endpoints, but don't
  100. * want to send any data over them. If this macro is defined to 1, functions
  101. * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
  102. * you need the interrupt-in endpoints in order to comply to an interface
  103. * (e.g. HID), but never want to send any data. This option saves a couple
  104. * of bytes in flash memory and the transmit buffers in RAM.
  105. */
  106. #define USB_CFG_INTR_POLL_INTERVAL      255
  107. /* If you compile a version with endpoint 1 (interrupt-in), this is the poll
  108. * interval. The value is in milliseconds and must not be less than 10 ms for
  109. * low speed devices.
  110. */
  111. #define USB_CFG_IS_SELF_POWERED         0
  112. /* Define this to 1 if the device has its own power supply. Set it to 0 if the
  113. * device is powered from the USB bus.
  114. */
  115. #define USB_CFG_MAX_BUS_POWER           100
  116. /* Set this variable to the maximum USB bus power consumption of your device.
  117. * The value is in milliamperes. [It will be divided by two since USB
  118. * communicates power requirements in units of 2 mA.]
  119. */
  120. #if defined (__AVR_ATtiny2313__)
  121. #define USB_CFG_IMPLEMENT_FN_WRITE      0
  122. #else
  123. #define USB_CFG_IMPLEMENT_FN_WRITE      1
  124. #endif
  125. /* Set this to 1 if you want usbFunctionWrite() to be called for control-out
  126. * transfers. Set it to 0 if you don't need it and want to save a couple of
  127. * bytes.
  128. */
  129. #define USB_CFG_IMPLEMENT_FN_READ       1
  130. /* Set this to 1 if you need to send control replies which are generated
  131. * "on the fly" when usbFunctionRead() is called. If you only want to send
  132. * data from a static buffer, set it to 0 and return the data from
  133. * usbFunctionSetup(). This saves a couple of bytes.
  134. */
  135. #define USB_CFG_IMPLEMENT_FN_WRITEOUT   1
  136. /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
  137. * You must implement the function usbFunctionWriteOut() which receives all
  138. * interrupt/bulk data sent to any endpoint other than 0. The endpoint number
  139. * can be found in 'usbRxToken'.
  140. */
  141. #define USB_CFG_HAVE_FLOWCONTROL        1
  142. /* Define this to 1 if you want flowcontrol over USB data. See the definition
  143. * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
  144. * usbdrv.h.
  145. */
  146. #define USB_CFG_LONG_TRANSFERS          0
  147. /* Define this to 1 if you want to send/receive blocks of more than 254 bytes
  148. * in a single control-in or control-out transfer. Note that the capability
  149. * for long transfers increases the driver size.
  150. */
  151. /* #define USB_RX_USER_HOOK(data, len)     if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */
  152. /* This macro is a hook if you want to do unconventional things. If it is
  153. * defined, it's inserted at the beginning of received message processing.
  154. * If you eat the received message and don't want default processing to
  155. * proceed, do a return after doing your things. One possible application
  156. * (besides debugging) is to flash a status LED on each packet.
  157. */
  158. /* #define USB_RESET_HOOK(resetStarts)     if(!resetStarts){hadUsbReset();} */
  159. /* This macro is a hook if you need to know when an USB RESET occurs. It has
  160. * one parameter which distinguishes between the start of RESET state and its
  161. * end.
  162. */
  163. /* #define USB_SET_ADDRESS_HOOK()              hadAddressAssigned(); */
  164. /* This macro (if defined) is executed when a USB SET_ADDRESS request was
  165. * received.
  166. */
  167. #define USB_COUNT_SOF                   0
  168. /* define this macro to 1 if you need the global variable "usbSofCount" which
  169. * counts SOF packets. This feature requires that the hardware interrupt is
  170. * connected to D- instead of D+.
  171. */
  172. /* #ifdef __ASSEMBLER__
  173. * macro myAssemblerMacro
  174. *     in      YL, TCNT0
  175. *     sts     timer0Snapshot, YL
  176. *     endm
  177. * #endif
  178. * #define USB_SOF_HOOK                    myAssemblerMacro
  179. * This macro (if defined) is executed in the assembler module when a
  180. * Start Of Frame condition is detected. It is recommended to define it to
  181. * the name of an assembler macro which is defined here as well so that more
  182. * than one assembler instruction can be used. The macro may use the register
  183. * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages
  184. * immediately after an SOF pulse may be lost and must be retried by the host.
  185. * What can you do with this hook? Since the SOF signal occurs exactly every
  186. * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in
  187. * designs running on the internal RC oscillator.
  188. * Please note that Start Of Frame detection works only if D- is wired to the
  189. * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
  190. */
  191. #define USB_CFG_CHECK_DATA_TOGGLING     1
  192. /* define this macro to 1 if you want to filter out duplicate data packets
  193. * sent by the host. Duplicates occur only as a consequence of communication
  194. * errors, when the host does not receive an ACK. Please note that you need to
  195. * implement the filtering yourself in usbFunctionWriteOut() and
  196. * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
  197. * for each control- and out-endpoint to check for duplicate packets.
  198. */
  199. #if USB_CFG_CLOCK_KHZ==16500 || USB_CFG_CLOCK_KHZ==12800
  200. #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   1
  201. #include "osccal.h"
  202. #else
  203. #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   0
  204. #endif
  205. /* define this macro to 1 if you want the function usbMeasureFrameLength()
  206. * compiled in. This function can be used to calibrate the AVR's RC oscillator.
  207. */
  208. #define USB_USE_FAST_CRC                0
  209. /* The assembler module has two implementations for the CRC algorithm. One is
  210. * faster, the other is smaller. This CRC routine is only used for transmitted
  211. * messages where timing is not critical. The faster routine needs 31 cycles
  212. * per byte while the smaller one needs 61 to 69 cycles. The faster routine
  213. * may be worth the 32 bytes bigger code size if you transmit lots of data and
  214. * run the AVR close to its limit.
  215. */

  216. /* -------------------------- Device Description --------------------------- */

  217. #define  USB_CFG_VENDOR_ID       0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */
  218. /* USB vendor ID for the device, low byte first. If you have registered your
  219. * own Vendor ID, define it here. Otherwise you may use one of obdev's free
  220. * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules!
  221. * *** IMPORTANT NOTE ***
  222. * This template uses obdev's shared VID/PID pair for Vendor Class devices
  223. * with libusb: 0x16c0/0x5dc.  Use this VID/PID pair ONLY if you understand
  224. * the implications!
  225. */
  226. #define  USB_CFG_DEVICE_ID       0xe1, 0x05 /* = 0x05e1 = 1505 */
  227. /* This is the ID of the product, low byte first. It is interpreted in the
  228. * scope of the vendor ID. If you have registered your own VID with usb.org
  229. * or if you have licensed a PID from somebody else, define it here. Otherwise
  230. * you may use one of obdev's free shared VID/PID pairs. See the file
  231. * USB-IDs-for-free.txt for details!
  232. * *** IMPORTANT NOTE ***
  233. * This template uses obdev's shared VID/PID pair for Vendor Class devices
  234. * with libusb: 0x16c0/0x5dc.  Use this VID/PID pair ONLY if you understand
  235. * the implications!
  236. */
  237. #define USB_CFG_DEVICE_VERSION  0x00, 0x01
  238. /* Version number of the device: Minor number first, then major number.
  239. */
  240. #define USB_CFG_VENDOR_NAME     'w', 'w', 'w', '.', 'r', 'e', 'c', 'u', 'r', 's', 'i', 'o', 'n', '.', 'j', 'p'
  241. #define USB_CFG_VENDOR_NAME_LEN 16
  242. /* These two values define the vendor name returned by the USB device. The name
  243. * must be given as a list of characters under single quotes. The characters
  244. * are interpreted as Unicode (UTF-16) entities.
  245. * If you don't want a vendor name string, undefine these macros.
  246. * ALWAYS define a vendor name containing your Internet domain name if you use
  247. * obdev's free shared VID/PID pair. See the file USBID-License.txt for
  248. * details.
  249. */
  250. #define USB_CFG_DEVICE_NAME     'U', 'S', 'B', '-', 'S', 'P', 'I'
  251. #define USB_CFG_DEVICE_NAME_LEN 7
  252. /* Same as above for the device name. If you don't want a device name, undefine
  253. * the macros. See the file USB-IDs-for-free.txt before you assign a name if
  254. * you use a shared VID/PID.
  255. */
  256. /*#define USB_CFG_SERIAL_NUMBER   'N', 'o', 'n', 'e' */
  257. /*#define USB_CFG_SERIAL_NUMBER_LEN   0 */
  258. /* Same as above for the serial number. If you don't want a serial number,
  259. * undefine the macros.
  260. * It may be useful to provide the serial number through other means than at
  261. * compile time. See the section about descriptor properties below for how
  262. * to fine tune control over USB descriptors such as the string descriptor
  263. * for the serial number.
  264. */
  265. #define USB_CFG_DEVICE_CLASS        2    /* set to 0 if deferred to interface */
  266. #define USB_CFG_DEVICE_SUBCLASS     0
  267. /* See USB specification if you want to conform to an existing device class.
  268. * Class 0xff is "vendor specific".
  269. */
  270. #define USB_CFG_INTERFACE_CLASS     2       /* CDC class */
  271. #define USB_CFG_INTERFACE_SUBCLASS  2       /* Abstract (Modem) */
  272. #define USB_CFG_INTERFACE_PROTOCOL  1       /* AT-Commands */
  273. /* See USB specification if you want to conform to an existing device class or
  274. * protocol. The following classes must be set at interface level:
  275. * HID class is 3, no subclass and protocol required (but may be useful!)
  276. * CDC class is 2, use subclass 2 and protocol 1 for ACM
  277. */
  278. /* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    42 */
  279. /* Define this to the length of the HID report descriptor, if you implement
  280. * an HID device. Otherwise don't define it or define it to 0.
  281. * If you use this define, you must add a PROGMEM character array named
  282. * "usbHidReportDescriptor" to your code which contains the report descriptor.
  283. * Don't forget to keep the array and this define in sync!
  284. */

  285. /* #define USB_PUBLIC static */
  286. /* Use the define above if you #include usbdrv.c instead of linking against it.
  287. * This technique saves a couple of bytes in flash memory.
  288. */

  289. /* ------------------- Fine Control over USB Descriptors ------------------- */
  290. /* If you don't want to use the driver's default USB descriptors, you can
  291. * provide our own. These can be provided as (1) fixed length static data in
  292. * flash memory, (2) fixed length static data in RAM or (3) dynamically at
  293. * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more
  294. * information about this function.
  295. * Descriptor handling is configured through the descriptor's properties. If
  296. * no properties are defined or if they are 0, the default descriptor is used.
  297. * Possible properties are:
  298. *   + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
  299. *     at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is
  300. *     used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if
  301. *     you want RAM pointers.
  302. *   + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
  303. *     in static memory is in RAM, not in flash memory.
  304. *   + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
  305. *     the driver must know the descriptor's length. The descriptor itself is
  306. *     found at the address of a well known identifier (see below).
  307. * List of static descriptor names (must be declared PROGMEM if in flash):
  308. *   char usbDescriptorDevice[];
  309. *   char usbDescriptorConfiguration[];
  310. *   char usbDescriptorHidReport[];
  311. *   char usbDescriptorString0[];
  312. *   int usbDescriptorStringVendor[];
  313. *   int usbDescriptorStringDevice[];
  314. *   int usbDescriptorStringSerialNumber[];
  315. * Other descriptors can't be provided statically, they must be provided
  316. * dynamically at runtime.
  317. *
  318. * Descriptor properties are or-ed or added together, e.g.:
  319. * #define USB_CFG_DESCR_PROPS_DEVICE   (USB_PROP_IS_RAM | USB_PROP_LENGTH(18))
  320. *
  321. * The following descriptors are defined:
  322. *   USB_CFG_DESCR_PROPS_DEVICE
  323. *   USB_CFG_DESCR_PROPS_CONFIGURATION
  324. *   USB_CFG_DESCR_PROPS_STRINGS
  325. *   USB_CFG_DESCR_PROPS_STRING_0
  326. *   USB_CFG_DESCR_PROPS_STRING_VENDOR
  327. *   USB_CFG_DESCR_PROPS_STRING_PRODUCT
  328. *   USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
  329. *   USB_CFG_DESCR_PROPS_HID
  330. *   USB_CFG_DESCR_PROPS_HID_REPORT
  331. *   USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
  332. *
  333. * Note about string descriptors: String descriptors are not just strings, they
  334. * are Unicode strings prefixed with a 2 byte header. Example:
  335. * int  serialNumberDescriptor[] = {
  336. *     USB_STRING_DESCRIPTOR_HEADER(6),
  337. *     'S', 'e', 'r', 'i', 'a', 'l'
  338. * };
  339. */

  340. #define USB_CFG_DESCR_PROPS_DEVICE                  0
  341. #define USB_CFG_DESCR_PROPS_CONFIGURATION           USB_PROP_IS_DYNAMIC
  342. #define USB_CFG_DESCR_PROPS_STRINGS                 0
  343. #define USB_CFG_DESCR_PROPS_STRING_0                0
  344. #define USB_CFG_DESCR_PROPS_STRING_VENDOR           0
  345. #define USB_CFG_DESCR_PROPS_STRING_PRODUCT          0
  346. #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    0
  347. #define USB_CFG_DESCR_PROPS_HID                     0
  348. #define USB_CFG_DESCR_PROPS_HID_REPORT              0
  349. #define USB_CFG_DESCR_PROPS_UNKNOWN                 0

  350. /* ----------------------- Optional MCU Description ------------------------ */

  351. /* The following configurations have working defaults in usbdrv.h. You
  352. * usually don't need to set them explicitly. Only if you want to run
  353. * the driver on a device which is not yet supported or with a compiler
  354. * which is not fully supported (such as IAR C) or if you use a differnt
  355. * interrupt than INT0, you may have to define some of these.
  356. */
  357. /* #define USB_INTR_CFG            MCUCR */
  358. /* #define USB_INTR_CFG_SET        ((1 << ISC00) | (1 << ISC01)) */
  359. /* #define USB_INTR_CFG_CLR        0 */
  360. /* #define USB_INTR_ENABLE         GIMSK */
  361. /* #define USB_INTR_ENABLE_BIT     INT0 */
  362. /* #define USB_INTR_PENDING        GIFR */
  363. /* #define USB_INTR_PENDING_BIT    INTF0 */
  364. /* #define USB_INTR_VECTOR         SIG_INTERRUPT0 */

  365. #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__)
  366. #define USB_INTR_CFG            PCMSK
  367. #define USB_INTR_CFG_SET        (1<<USB_CFG_DPLUS_BIT)
  368. #define USB_INTR_ENABLE_BIT     PCIE
  369. #define USB_INTR_PENDING_BIT    PCIF
  370. #define USB_INTR_VECTOR         SIG_PIN_CHANGE
  371. #endif

  372. #endif /* __usbconfig_h_included__ */
复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-27 04:14

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表