Mercurial > ~darius > hgwebdir.cgi > avr
comparison usb.c @ 26:350e8655cbb7
- Remove some #if'd out code.
- Use STRING_DESCRIPTOR types instead of rolling one for each type of
string.
- Fix comment typo.
author | darius |
---|---|
date | Tue, 13 Dec 2005 10:53:48 +1030 |
parents | 845934a4e7fe |
children | 4e417d84365e |
comparison
equal
deleted
inserted
replaced
25:a52bc6b9e305 | 26:350e8655cbb7 |
---|---|
130 sizeof(LANGID_DESCRIPTOR), /* bLength - must match string below */ | 130 sizeof(LANGID_DESCRIPTOR), /* bLength - must match string below */ |
131 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ | 131 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ |
132 0x0409 /* LANGID US English */ | 132 0x0409 /* LANGID US English */ |
133 }; | 133 }; |
134 | 134 |
135 /* These are really STRING_DESCRIPTOR's but we can't statically | 135 STRING_DESCRIPTOR Manufacturer_Descriptor = { |
136 * declare them as that and have the compiler generate the right size | 136 sizeof(STRING_DESCRIPTOR) + 32, /* bLength */ |
137 * structure */ | 137 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ |
138 typedef struct { | 138 "G\0e\0n\0e\0s\0i\0s\0 \0S\0o\0f\0t\0w\0a\0r\0e\0" /* ManufacturerString in |
139 uint8_t bLenght; | 139 * UNICODE */ |
140 uint8_t bDescriptorType; | |
141 char bString[32]; | |
142 } MANUFACTURER_DESCRIPTOR, *PMANUFACTURER_DESCRIPTOR; | |
143 | |
144 const MANUFACTURER_DESCRIPTOR Manufacturer_Descriptor = { /* ManufacturerString 1 */ | |
145 sizeof(MANUFACTURER_DESCRIPTOR), /* bLength */ | |
146 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ | |
147 "G\0e\0n\0e\0s\0i\0s\0 \0S\0o\0f\0t\0w\0a\0r\0e\0" /* ManufacturerString in | |
148 * UNICODE */ | |
149 }; | 140 }; |
150 | 141 |
151 typedef struct { | 142 STRING_DESCRIPTOR Product_Descriptor = { |
152 uint8_t bLenght; | 143 sizeof(STRING_DESCRIPTOR) + 48, /* bLength */ |
153 uint8_t bDescriptorType; | |
154 char bString[48]; | |
155 } PRODUCT_DESCRIPTOR, *PPRODUCT_DESCRIPTOR; | |
156 | |
157 const PRODUCT_DESCRIPTOR Product_Descriptor = { /* ProductString 2 */ | |
158 sizeof(PRODUCT_DESCRIPTOR), /* bLength */ | |
159 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ | 144 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ |
160 /* ProductString in | 145 /* ProductString in |
161 * UNICODE */ | 146 * UNICODE */ |
162 "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" | 147 "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" |
163 /* XXX: dunno why I need the double quote magic above.. */ | 148 /* XXX: dunno why I need the double quote magic above.. */ |
164 }; | 149 }; |
165 | 150 |
166 typedef struct { | 151 STRING_DESCRIPTOR Serial_Descriptor; |
167 uint8_t bLenght; | 152 STRING_DESCRIPTOR EE_Serial_Descriptor __attribute__ ((section (".eeprom"))) = { /* SerialString 3 */ |
168 uint8_t bDescriptorType; | 153 sizeof(STRING_DESCRIPTOR) + 20, /* bLength - must match string below */ |
169 char bString[20]; | |
170 } SERIAL_DESCRIPTOR, *PSERIAL_DESCRIPTOR; | |
171 | |
172 const SERIAL_DESCRIPTOR EE_Serial_Descriptor __attribute__ ((section (".eeprom"))) = { /* SerialString 3 */ | |
173 sizeof(SERIAL_DESCRIPTOR), /* bLength - must match string below */ | |
174 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ | 154 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */ |
175 "1\02\03\0" | 155 "1\02\03\0" |
176 }; | 156 }; |
177 | |
178 SERIAL_DESCRIPTOR Serial_Descriptor; | |
179 | 157 |
180 /* | 158 /* |
181 * The PDIUSBD12 is wired up like so | 159 * The PDIUSBD12 is wired up like so |
182 * | 160 * |
183 * PDI AVR | 161 * PDI AVR |
190 * SUSPEND <=> PB4 | 168 * SUSPEND <=> PB4 |
191 */ | 169 */ |
192 uint8_t | 170 uint8_t |
193 d12_get_data(void) { | 171 d12_get_data(void) { |
194 uint8_t data; | 172 uint8_t data; |
195 #if 0 | 173 |
196 _delay_us(1); | |
197 #endif | |
198 PORTB &= ~_BV(PB3); /* Data phase */ | 174 PORTB &= ~_BV(PB3); /* Data phase */ |
199 DDRA = 0x00; /* Set to input */ | 175 DDRA = 0x00; /* Set to input */ |
200 PORTB &= ~_BV(PB1); /* Pull RD_N low */ | 176 PORTB &= ~_BV(PB1); /* Pull RD_N low */ |
201 PORTB &= ~_BV(PB1); /* Delay 40ns */ | 177 PORTB &= ~_BV(PB1); /* Delay 40ns */ |
202 PORTB &= ~_BV(PB1); | 178 PORTB &= ~_BV(PB1); |
206 return(data); | 182 return(data); |
207 } | 183 } |
208 | 184 |
209 void | 185 void |
210 set_d12_data(uint8_t data) { | 186 set_d12_data(uint8_t data) { |
211 #if 0 | |
212 _delay_us(1); | |
213 #endif | |
214 PORTB &= ~_BV(PB3); /* Data phase */ | 187 PORTB &= ~_BV(PB3); /* Data phase */ |
215 DDRA = 0xff; /* Set to output */ | 188 DDRA = 0xff; /* Set to output */ |
216 PORTA = data; /* Put the data on the bus */ | 189 PORTA = data; /* Put the data on the bus */ |
217 PORTB &= ~_BV(PB2); /* Pull WR_N low */ | 190 PORTB &= ~_BV(PB2); /* Pull WR_N low */ |
218 PORTB &= ~_BV(PB2); /* Delay 40ns */ | 191 PORTB &= ~_BV(PB2); /* Delay 40ns */ |
225 DDRA = 0x00; /* Back to input */ | 198 DDRA = 0x00; /* Back to input */ |
226 } | 199 } |
227 | 200 |
228 void | 201 void |
229 set_d12_cmd(uint8_t cmd) { | 202 set_d12_cmd(uint8_t cmd) { |
230 #if 0 | |
231 _delay_us(1); | |
232 #endif | |
233 PORTB |= _BV(PB3); /* Command phase */ | 203 PORTB |= _BV(PB3); /* Command phase */ |
234 DDRA = 0xff; /* Set to output */ | 204 DDRA = 0xff; /* Set to output */ |
235 PORTA = cmd; /* Put the data on the bus */ | 205 PORTA = cmd; /* Put the data on the bus */ |
236 PORTB &= ~_BV(PB2); /* Pull WR_N low */ | 206 PORTB &= ~_BV(PB2); /* Pull WR_N low */ |
237 PORTB &= ~_BV(PB2); /* Delay 40ns */ | 207 PORTB &= ~_BV(PB2); /* Delay 40ns */ |
247 void | 217 void |
248 d12_write_cmd(uint8_t command, const uint8_t *buffer, uint8_t count) { | 218 d12_write_cmd(uint8_t command, const uint8_t *buffer, uint8_t count) { |
249 uint8_t i; | 219 uint8_t i; |
250 | 220 |
251 set_d12_cmd(command); | 221 set_d12_cmd(command); |
252 #if 0 | |
253 _delay_us(1); | |
254 #endif | |
255 if (count) { | 222 if (count) { |
256 for (i = 0; i < count; i++) { | 223 for (i = 0; i < count; i++) { |
257 set_d12_data(buffer[i]); | 224 set_d12_data(buffer[i]); |
258 } | 225 } |
259 } | 226 } |
275 void | 242 void |
276 usb_init(void) { | 243 usb_init(void) { |
277 uint8_t buffer[2]; | 244 uint8_t buffer[2]; |
278 | 245 |
279 /* pull EE_Serial_Descriptor into RAM */ | 246 /* pull EE_Serial_Descriptor into RAM */ |
280 eeprom_read_block(&Serial_Descriptor, &EE_Serial_Descriptor, sizeof(Serial_Descriptor)); | 247 eeprom_read_block(&Serial_Descriptor, &EE_Serial_Descriptor, EE_Serial_Descriptor.bLength); |
281 | 248 |
282 /* Set Address to zero (default) and enable function */ | 249 /* Set Address to zero (default) and enable function */ |
283 buffer[0] = 0x80; | 250 buffer[0] = 0x80; |
284 d12_write_cmd(D12_SET_ADDRESS_ENABLE, buffer, 1); | 251 d12_write_cmd(D12_SET_ADDRESS_ENABLE, buffer, 1); |
285 | 252 |
609 /* This is a Data Packet */ | 576 /* This is a Data Packet */ |
610 } | 577 } |
611 | 578 |
612 } | 579 } |
613 | 580 |
614 /* Reset the micro | 581 /* Reset the micro */ |
615 static void | 582 static void |
616 reset(void) { | 583 reset(void) { |
617 MCUCR = _BV(IVCE); | 584 MCUCR = _BV(IVCE); |
618 MCUCR = 0; | 585 MCUCR = 0; |
619 WDTCR = _BV(WDE); | 586 WDTCR = _BV(WDE); |
653 case TYPE_STRING_DESCRIPTOR: | 620 case TYPE_STRING_DESCRIPTOR: |
654 switch (setuppkt->wValue & 0xFF) { | 621 switch (setuppkt->wValue & 0xFF) { |
655 | 622 |
656 case 0: | 623 case 0: |
657 pSendBuffer = (const uint8_t *)&LANGID_Descriptor; | 624 pSendBuffer = (const uint8_t *)&LANGID_Descriptor; |
658 BytesToSend = sizeof(LANGID_Descriptor); | 625 BytesToSend = LANGID_Descriptor.bLength; |
659 break; | 626 break; |
660 | 627 |
661 case 1: | 628 case 1: |
662 pSendBuffer = (const uint8_t *)&Manufacturer_Descriptor; | 629 pSendBuffer = (const uint8_t *)&Manufacturer_Descriptor; |
663 BytesToSend = sizeof(Manufacturer_Descriptor); | 630 BytesToSend = Manufacturer_Descriptor.bLength; |
664 break; | 631 break; |
665 | 632 |
666 case 2: | 633 case 2: |
667 pSendBuffer = (const uint8_t *)&Product_Descriptor; | 634 pSendBuffer = (const uint8_t *)&Product_Descriptor; |
668 BytesToSend = sizeof(Product_Descriptor); | 635 BytesToSend = Product_Descriptor.bLength; |
669 break; | 636 break; |
670 | 637 |
671 case 3: | 638 case 3: |
672 pSendBuffer = (const uint8_t *)&Serial_Descriptor; | 639 pSendBuffer = (const uint8_t *)&Serial_Descriptor; |
673 BytesToSend = sizeof(Serial_Descriptor); | 640 BytesToSend = Serial_Descriptor.bLength; |
674 break; | 641 break; |
675 | 642 |
676 default: | 643 default: |
677 pSendBuffer = NULL; | 644 pSendBuffer = NULL; |
678 BytesToSend = 0; | 645 BytesToSend = 0; |
768 if (BytesToSend == 0) { | 735 if (BytesToSend == 0) { |
769 /* | 736 /* |
770 * If BytesToSend is Zero and we get called again, assume | 737 * If BytesToSend is Zero and we get called again, assume |
771 * buffer is smaller | 738 * buffer is smaller |
772 * than Setup Request Size and indicate end by sending Zero | 739 * than Setup Request Size and indicate end by sending Zero |
773 * Lenght packet | 740 * Length packet |
774 */ | 741 */ |
775 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0); | 742 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0); |
776 send_Bytes = 0; | 743 send_Bytes = 0; |
777 } else if (BytesToSend >= EP0_SIZE) { | 744 } else if (BytesToSend >= EP0_SIZE) { |
778 /* Write another EP0_SIZE Bytes to buffer and send */ | 745 /* Write another EP0_SIZE Bytes to buffer and send */ |