# HG changeset patch # User darius # Date 1134433428 -37800 # Node ID 350e8655cbb78050f8234e873385874fd002ef74 # Parent a52bc6b9e3052133ae19a815c0aeb7ffe7e1c4de - Remove some #if'd out code. - Use STRING_DESCRIPTOR types instead of rolling one for each type of string. - Fix comment typo. diff -r a52bc6b9e305 -r 350e8655cbb7 usb.c --- a/usb.c Mon Dec 12 23:38:29 2005 +1030 +++ b/usb.c Tue Dec 13 10:53:48 2005 +1030 @@ -132,51 +132,29 @@ 0x0409 /* LANGID US English */ }; -/* These are really STRING_DESCRIPTOR's but we can't statically - * declare them as that and have the compiler generate the right size - * structure */ -typedef struct { - uint8_t bLenght; - uint8_t bDescriptorType; - char bString[32]; -} MANUFACTURER_DESCRIPTOR, *PMANUFACTURER_DESCRIPTOR; - -const MANUFACTURER_DESCRIPTOR Manufacturer_Descriptor = { /* ManufacturerString 1 */ - sizeof(MANUFACTURER_DESCRIPTOR), /* bLength */ - TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ - "G\0e\0n\0e\0s\0i\0s\0 \0S\0o\0f\0t\0w\0a\0r\0e\0" /* ManufacturerString in - * UNICODE */ +STRING_DESCRIPTOR Manufacturer_Descriptor = { + sizeof(STRING_DESCRIPTOR) + 32, /* bLength */ + TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ + "G\0e\0n\0e\0s\0i\0s\0 \0S\0o\0f\0t\0w\0a\0r\0e\0" /* ManufacturerString in + * UNICODE */ }; -typedef struct { - uint8_t bLenght; - uint8_t bDescriptorType; - char bString[48]; -} PRODUCT_DESCRIPTOR, *PPRODUCT_DESCRIPTOR; - -const PRODUCT_DESCRIPTOR Product_Descriptor = { /* ProductString 2 */ - sizeof(PRODUCT_DESCRIPTOR), /* bLength */ +STRING_DESCRIPTOR Product_Descriptor = { + sizeof(STRING_DESCRIPTOR) + 48, /* bLength */ TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ /* ProductString in * UNICODE */ "R\0S\0""-\0""4\0""8\0""5\0"" \0M\0u\0l\0t\0i\0d\0r\0o\0p\0 \0A\0d\0a\0p\0t\0e\0r\0" /* XXX: dunno why I need the double quote magic above.. */ -}; +}; -typedef struct { - uint8_t bLenght; - uint8_t bDescriptorType; - char bString[20]; -} SERIAL_DESCRIPTOR, *PSERIAL_DESCRIPTOR; - -const SERIAL_DESCRIPTOR EE_Serial_Descriptor __attribute__ ((section (".eeprom"))) = { /* SerialString 3 */ - sizeof(SERIAL_DESCRIPTOR), /* bLength - must match string below */ +STRING_DESCRIPTOR Serial_Descriptor; +STRING_DESCRIPTOR EE_Serial_Descriptor __attribute__ ((section (".eeprom"))) = { /* SerialString 3 */ + sizeof(STRING_DESCRIPTOR) + 20, /* bLength - must match string below */ TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ "1\02\03\0" }; -SERIAL_DESCRIPTOR Serial_Descriptor; - /* * The PDIUSBD12 is wired up like so * @@ -192,9 +170,7 @@ uint8_t d12_get_data(void) { uint8_t data; -#if 0 - _delay_us(1); -#endif + PORTB &= ~_BV(PB3); /* Data phase */ DDRA = 0x00; /* Set to input */ PORTB &= ~_BV(PB1); /* Pull RD_N low */ @@ -208,9 +184,6 @@ void set_d12_data(uint8_t data) { -#if 0 - _delay_us(1); -#endif PORTB &= ~_BV(PB3); /* Data phase */ DDRA = 0xff; /* Set to output */ PORTA = data; /* Put the data on the bus */ @@ -227,9 +200,6 @@ void set_d12_cmd(uint8_t cmd) { -#if 0 - _delay_us(1); -#endif PORTB |= _BV(PB3); /* Command phase */ DDRA = 0xff; /* Set to output */ PORTA = cmd; /* Put the data on the bus */ @@ -249,9 +219,6 @@ uint8_t i; set_d12_cmd(command); -#if 0 - _delay_us(1); -#endif if (count) { for (i = 0; i < count; i++) { set_d12_data(buffer[i]); @@ -277,7 +244,7 @@ uint8_t buffer[2]; /* pull EE_Serial_Descriptor into RAM */ - eeprom_read_block(&Serial_Descriptor, &EE_Serial_Descriptor, sizeof(Serial_Descriptor)); + eeprom_read_block(&Serial_Descriptor, &EE_Serial_Descriptor, EE_Serial_Descriptor.bLength); /* Set Address to zero (default) and enable function */ buffer[0] = 0x80; @@ -611,7 +578,7 @@ } -/* Reset the micro +/* Reset the micro */ static void reset(void) { MCUCR = _BV(IVCE); @@ -655,22 +622,22 @@ case 0: pSendBuffer = (const uint8_t *)&LANGID_Descriptor; - BytesToSend = sizeof(LANGID_Descriptor); + BytesToSend = LANGID_Descriptor.bLength; break; case 1: pSendBuffer = (const uint8_t *)&Manufacturer_Descriptor; - BytesToSend = sizeof(Manufacturer_Descriptor); + BytesToSend = Manufacturer_Descriptor.bLength; break; case 2: pSendBuffer = (const uint8_t *)&Product_Descriptor; - BytesToSend = sizeof(Product_Descriptor); + BytesToSend = Product_Descriptor.bLength; break; case 3: pSendBuffer = (const uint8_t *)&Serial_Descriptor; - BytesToSend = sizeof(Serial_Descriptor); + BytesToSend = Serial_Descriptor.bLength; break; default: @@ -770,7 +737,7 @@ * If BytesToSend is Zero and we get called again, assume * buffer is smaller * than Setup Request Size and indicate end by sending Zero - * Lenght packet + * Length packet */ d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0); send_Bytes = 0;