2727#include "nxos/drivers/aic.h"
2828#include "nxos/util.h"
2929
30+ #include <lego/usb.h>
31+ #include "pbdrvconfig.h"
32+
3033#include "usb_ch9.h"
3134#include "usb_common_desc.h"
3235
8689
8790#define USB_WVALUE_INDEX 0xFF
8891
92+ /**
93+ * Indices for string descriptors
94+ */
95+ enum {
96+ STRING_DESC_LANGID ,
97+ STRING_DESC_MFG ,
98+ STRING_DESC_PRODUCT ,
99+ };
100+
89101/* The following definitions are 'raw' USB setup packets. They are all
90102 * standard responses to various setup requests by the USB host. These
91103 * packets are all constant, and mostly boilerplate. Don't be too
@@ -110,8 +122,8 @@ static const pbdrv_usb_dev_desc_t pbdrv_usb_nxt_device_descriptor = {
110122 .idVendor = 0x0694 , /* Vendor ID : LEGO */
111123 .idProduct = 0x0002 , /* Product ID : NXT */
112124 .bcdDevice = 0x0200 , /* Product revision: 2.0.0. */
113- .iManufacturer = 1 ,
114- .iProduct = 2 ,
125+ .iManufacturer = STRING_DESC_MFG ,
126+ .iProduct = STRING_DESC_PRODUCT ,
115127 .iSerialNumber = 0 , // TODO: implement a serial number
116128 .bNumConfigurations = 1 ,
117129};
@@ -185,45 +197,6 @@ static const pbdrv_usb_nxt_conf_t pbdrv_usb_nxt_full_config = {
185197 },
186198};
187199
188- static const uint8_t pbdrv_usb_nxt_string_desc [] = {
189- 4 , USB_DESC_TYPE_STR , /* Descriptor length and type. */
190- 0x09 , 0x04 , /* Supported language ID (US English). */
191- };
192-
193- static const uint8_t pbdrv_usb_lego_str [] = {
194- 10 , USB_DESC_TYPE_STR ,
195- 'L' , 0 ,
196- 'E' , 0 ,
197- 'G' , 0 ,
198- 'O' , 0 ,
199- };
200-
201- static const uint8_t pbdrv_usb_nxt_str [] = {
202- 30 , USB_DESC_TYPE_STR ,
203- 'N' , 0 ,
204- 'X' , 0 ,
205- 'T' , 0 ,
206- ' ' , 0 ,
207- '+' , 0 ,
208- ' ' , 0 ,
209- 'P' , 0 ,
210- 'y' , 0 ,
211- 'b' , 0 ,
212- 'r' , 0 ,
213- 'i' , 0 ,
214- 'c' , 0 ,
215- 'k' , 0 ,
216- 's' , 0 ,
217- };
218-
219- /* Internal lookup table mapping string descriptors to their indices
220- * in the USB string descriptor table.
221- */
222- static const uint8_t * pbdrv_usb_nxt_strings [] = {
223- pbdrv_usb_lego_str ,
224- pbdrv_usb_nxt_str ,
225- };
226-
227200typedef enum {
228201 USB_UNINITIALIZED ,
229202 USB_READY ,
@@ -495,17 +468,30 @@ static void pbdrv_usb_handle_std_request(pbdrv_usb_nxt_setup_packet_t *packet) {
495468 break ;
496469
497470 case USB_DESC_TYPE_STR : /* String or language info. */
498- if ((packet -> value & USB_WVALUE_INDEX ) == 0 ) {
499- pbdrv_usb_nxt_write_data (0 , pbdrv_usb_nxt_string_desc ,
500- MIN (pbdrv_usb_nxt_string_desc [0 ], packet -> length ));
471+ {
472+ const void * desc = 0 ;
473+ switch (index ) {
474+ case STRING_DESC_LANGID :
475+ desc = & pbdrv_usb_str_desc_langid ;
476+ size = sizeof (pbdrv_usb_str_desc_langid .s );
477+ break ;
478+ case STRING_DESC_MFG :
479+ desc = & pbdrv_usb_str_desc_mfg ;
480+ size = sizeof (pbdrv_usb_str_desc_mfg .s );
481+ break ;
482+ case STRING_DESC_PRODUCT :
483+ desc = & pbdrv_usb_str_desc_prod ;
484+ size = sizeof (pbdrv_usb_str_desc_prod .s );
485+ break ;
486+ }
487+
488+ if (desc ) {
489+ pbdrv_usb_nxt_write_data (0 , desc , MIN (size , packet -> length ));
501490 } else {
502- /* The host wants a specific string. */
503- /* TODO: This should check if the requested string exists. */
504- pbdrv_usb_nxt_write_data (0 , pbdrv_usb_nxt_strings [index - 1 ],
505- MIN (pbdrv_usb_nxt_strings [index - 1 ][0 ],
506- packet -> length ));
491+ pbdrv_usb_nxt_send_stall (0 );
507492 }
508- break ;
493+ }
494+ break ;
509495
510496 case USB_DESC_TYPE_DEVICE_QUALIFIER : /* Device qualifier descriptor. */
511497 size = pbdrv_usb_nxt_dev_qualifier_desc .bLength ;
0 commit comments