17,10 → 17,10 |
// the callback functions usb_in() and usb_out() will be called for IN |
// and OUT transfers. |
// |
// Maximum stack usage (gcc 3.4.3 & 4.1.0) of usb_poll(): 5 bytes plus |
// Maximum stack usage (gcc 4.1.0 & 4.3.4) of usb_poll(): 5 bytes plus |
// possible additional stack usage in usb_setup(), usb_in() or usb_out(). |
// |
// Copyright (C) 2006 Dick Streefland |
// Copyright 2006-2010 Dick Streefland |
// |
// This is free software, licensed under the terms of the GNU General |
// Public License as published by the Free Software Foundation. |
58,7 → 58,8 |
byte_t usb_tx_buf[USB_BUFSIZE]; // output buffer |
byte_t usb_tx_len; // output buffer size, 0 means empty |
|
byte_t usb_address; // assigned USB address |
byte_t usb_address; // assigned device address |
byte_t usb_new_address; // new device address |
|
// ---------------------------------------------------------------------- |
// Local data |
75,7 → 76,6 |
static byte_t usb_tx_state; // TX_STATE_*, see enum above |
static byte_t usb_tx_total; // total transmit size |
static byte_t* usb_tx_data; // pointer to data to transmit |
static byte_t new_address; // new device address |
|
#if defined USBTINY_VENDOR_NAME |
struct |
83,7 → 83,7 |
byte_t length; |
byte_t type; |
int string[sizeof(USBTINY_VENDOR_NAME)-1]; |
} string_vendor PROGMEM = |
} const string_vendor PROGMEM = |
{ |
2 * sizeof(USBTINY_VENDOR_NAME), |
DESCRIPTOR_TYPE_STRING, |
100,7 → 100,7 |
byte_t length; |
byte_t type; |
int string[sizeof(USBTINY_DEVICE_NAME)-1]; |
} string_device PROGMEM = |
} const string_device PROGMEM = |
{ |
2 * sizeof(USBTINY_DEVICE_NAME), |
DESCRIPTOR_TYPE_STRING, |
117,7 → 117,7 |
byte_t length; |
byte_t type; |
int string[sizeof(USBTINY_SERIAL)-1]; |
} string_serial PROGMEM = |
} const string_serial PROGMEM = |
{ |
2 * sizeof(USBTINY_SERIAL), |
DESCRIPTOR_TYPE_STRING, |
129,7 → 129,7 |
#endif |
|
#if VENDOR_NAME_ID || DEVICE_NAME_ID || SERIAL_ID |
static byte_t string_langid [] PROGMEM = |
static byte_t const string_langid [] PROGMEM = |
{ |
4, // bLength |
DESCRIPTOR_TYPE_STRING, // bDescriptorType (string) |
138,11 → 138,11 |
#endif |
|
// Device Descriptor |
static byte_t descr_device [18] PROGMEM = |
static byte_t const descr_device [18] PROGMEM = |
{ |
18, // bLength |
DESCRIPTOR_TYPE_DEVICE, // bDescriptorType |
LE(0x0110), // bcdUSB |
LE(0x0101), // bcdUSB |
USBTINY_DEVICE_CLASS, // bDeviceClass |
USBTINY_DEVICE_SUBCLASS, // bDeviceSubClass |
USBTINY_DEVICE_PROTOCOL, // bDeviceProtocol |
157,7 → 157,7 |
}; |
|
// Configuration Descriptor |
static byte_t descr_config [] PROGMEM = |
static byte_t const descr_config [] PROGMEM = |
{ |
9, // bLength |
DESCRIPTOR_TYPE_CONFIGURATION, // bDescriptorType |
223,7 → 223,10 |
} |
else if ( data[1] == 5 ) // SET_ADDRESS |
{ |
new_address = data[2]; |
usb_new_address = data[2]; |
#ifdef USBTINY_USB_OK_LED |
SET(USBTINY_USB_OK_LED);// LED on |
#endif |
} |
else if ( data[1] == 6 ) // GET_DESCRIPTOR |
{ |
371,6 → 374,13 |
{ |
USB_INT_CONFIG |= USB_INT_CONFIG_SET; |
USB_INT_ENABLE |= (1 << USB_INT_ENABLE_BIT); |
#ifdef USBTINY_USB_OK_LED |
OUTPUT(USBTINY_USB_OK_LED); |
#endif |
#ifdef USBTINY_DMINUS_PULLUP |
SET(USBTINY_DMINUS_PULLUP); |
OUTPUT(USBTINY_DMINUS_PULLUP); // enable pullup on D- |
#endif |
sei(); |
} |
|
392,16 → 402,9 |
usb_rx_len = 0; // accept next packet |
} |
// refill an empty transmit buffer, when the transmitter is active |
if ( usb_tx_len == 0 ) |
if ( usb_tx_len == 0 && usb_tx_state != TX_STATE_IDLE ) |
{ |
if ( usb_tx_state != TX_STATE_IDLE ) |
{ |
usb_transmit(); |
} |
else |
{ // change the USB address at the end of a transfer |
usb_address = new_address; |
} |
usb_transmit(); |
} |
// check for USB bus reset |
for ( i = 10; i > 0 && ! (USB_IN & USB_MASK_DMINUS); i-- ) |
409,10 → 412,10 |
} |
if ( i == 0 ) |
{ // SE0 for more than 2.5uS is a reset |
cli(); |
usb_tx_len=0; |
usb_rx_len=0; |
new_address = 0; |
sei(); |
usb_new_address = 0; |
usb_address = 0; |
#ifdef USBTINY_USB_OK_LED |
CLR(USBTINY_USB_OK_LED); // LED off |
#endif |
} |
} |