39
39
enum {
40
40
PORT_STATE_DISCONNECTED = 0 ,
41
41
PORT_STATE_BUS_RESET ,
42
- PORT_STATE_WARMUP ,
43
42
PORT_STATE_SET_ADDRESS ,
44
43
PORT_STATE_GET_DEVICE_DESCRIPTOR ,
45
44
PORT_STATE_GET_CONFIGURATION_DESCRIPTOR ,
@@ -442,6 +441,10 @@ static void port_service(struct port_status *p, char name)
442
441
* transmission takes place.
443
442
*/
444
443
check_discon (p , name );
444
+ if (p -> full_speed )
445
+ wio8 (SIE_TX_LOW_SPEED , 0 );
446
+ else
447
+ wio8 (SIE_TX_LOW_SPEED , 1 );
445
448
switch (p -> state ) {
446
449
case PORT_STATE_DISCONNECTED : {
447
450
char linestat ;
@@ -452,11 +455,12 @@ static void port_service(struct port_status *p, char name)
452
455
if (linestat == 0x01 ) {
453
456
print_string (connect_fs ); print_char (name ); print_char ('\n' );
454
457
p -> full_speed = 1 ;
455
- p -> state = PORT_STATE_UNSUPPORTED ;
456
458
}
457
459
if (linestat == 0x02 ) {
458
460
print_string (connect_ls ); print_char (name ); print_char ('\n' );
459
461
p -> full_speed = 0 ;
462
+ }
463
+ if ((linestat == 0x01 )|| (linestat == 0x02 )) {
460
464
if (name == 'A' )
461
465
wio8 (SIE_TX_BUSRESET , rio8 (SIE_TX_BUSRESET ) | 0x01 );
462
466
else
@@ -472,12 +476,6 @@ static void port_service(struct port_status *p, char name)
472
476
wio8 (SIE_TX_BUSRESET , rio8 (SIE_TX_BUSRESET ) & 0x02 );
473
477
else
474
478
wio8 (SIE_TX_BUSRESET , rio8 (SIE_TX_BUSRESET ) & 0x01 );
475
- p -> state = PORT_STATE_WARMUP ;
476
- }
477
- break ;
478
- case PORT_STATE_WARMUP :
479
- if (frame_nr == ((p -> unreset_frame + 250 ) & 0x7ff )) {
480
- p -> retry_count = 0 ;
481
479
p -> state = PORT_STATE_SET_ADDRESS ;
482
480
}
483
481
break ;
@@ -503,7 +501,7 @@ static void port_service(struct port_status *p, char name)
503
501
case PORT_STATE_GET_DEVICE_DESCRIPTOR : {
504
502
struct setup_packet packet ;
505
503
unsigned char device_descriptor [18 ];
506
-
504
+
507
505
packet .bmRequestType = 0x80 ;
508
506
packet .bRequest = 0x06 ;
509
507
packet .wValue [0 ] = 0x00 ;
@@ -598,51 +596,36 @@ static void port_service(struct port_status *p, char name)
598
596
case PORT_STATE_UNSUPPORTED :
599
597
break ;
600
598
}
599
+ while (rio8 (SIE_TX_BUSY ));
601
600
}
602
601
603
602
static const char banner [] PROGMEM = "softusb-input v" VERSION "\n" ;
604
603
605
604
int main ()
606
605
{
607
- unsigned char mask ;
608
606
unsigned char i ;
607
+ unsigned char mask ;
609
608
610
609
print_string (banner );
611
610
612
- /* we only support low speed operation */
613
- wio8 (SIE_TX_LOW_SPEED , 1 );
614
- wio8 (SIE_LOW_SPEED , 3 );
615
-
616
611
wio8 (TIMER0 , 0 );
617
612
while (1 ) {
618
613
/* wait for the next frame */
619
614
while ((rio8 (TIMER1 ) < 0xbb ) || (rio8 (TIMER0 ) < 0x70 ));
620
615
wio8 (TIMER0 , 0 );
621
616
622
- /* send keepalive */
623
- mask = 0 ;
624
- if (port_a .state == PORT_STATE_WARMUP )
625
- mask |= 0x01 ;
626
- if (port_b .state == PORT_STATE_WARMUP )
627
- mask |= 0x02 ;
628
- wio8 (SIE_SEL_TX , mask );
629
- wio8 (SIE_GENERATE_EOP , 1 );
630
- while (rio8 (SIE_TX_BUSY ));
631
-
632
617
/*
633
- * wait extra time to allow the USB cable
634
- * capacitance to discharge (otherwise some disconnects
635
- * aren't properly detected)
618
+ * set RX speed bits
636
619
*/
637
- for (i = 0 ;i < 128 ;i ++ )
638
- asm("nop" );
620
+ mask = 0 ;
621
+ if (!port_a .full_speed ) mask |= 0x01 ;
622
+ if (!port_b .full_speed ) mask |= 0x02 ;
623
+ wio8 (SIE_LOW_SPEED , mask );
639
624
640
625
wio8 (SIE_SEL_RX , 0 );
641
626
wio8 (SIE_SEL_TX , 0x01 );
642
627
port_service (& port_a , 'A' );
643
628
644
- while (rio8 (SIE_TX_BUSY ));
645
-
646
629
wio8 (SIE_SEL_RX , 1 );
647
630
wio8 (SIE_SEL_TX , 0x02 );
648
631
port_service (& port_b , 'B' );
0 commit comments