Index: apps/screens.c =================================================================== --- apps/screens.c (revision 20237) +++ apps/screens.c (working copy) @@ -75,6 +75,11 @@ #include "dsp.h" #endif +#if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) +/* This needs to be declared in a proper header, but which one? */ +void usb_storage_try_release_ata(void); +#endif + #ifdef HAVE_LCD_BITMAP #define SCROLLBAR_WIDTH 6 #endif @@ -91,6 +96,42 @@ } #endif +int handle_usb_events(struct event_queue *q) +{ + struct queue_event ev; + int next_update=0; + + /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */ + while(1) + { + queue_wait_w_tmo(q, &ev, HZ/4); + switch(ev.id) + { + case SYS_USB_DISCONNECTED: + usb_acknowledge(SYS_USB_DISCONNECTED_ACK); + return 0; + case SYS_TIMEOUT: + break; + } +#if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) + if((button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON) + { + usb_storage_try_release_ata(); + } +#endif + if(TIME_AFTER(current_tick,next_update)) + { + if(usb_inserted()) { +#if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */ + led(mmc_usb_active(HZ)); +#endif /* STORAGE_MMC */ + gui_syncstatusbar_draw(&statusbars, false); + } + next_update=current_tick+HZ/2; + } + } +} + void usb_screen(void) { #ifdef USB_NONE @@ -142,14 +183,7 @@ while (button_get(true) & BUTTON_REL); #else usb_acknowledge(SYS_USB_CONNECTED_ACK); - while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) { - if(usb_inserted()) { -#if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */ - led(mmc_usb_active(HZ)); -#endif /* STORAGE_MMC */ - gui_syncstatusbar_draw(&statusbars, false); - } - } + while(handle_usb_events(&button_queue)); #endif /* SIMULATOR */ #ifdef HAVE_LCD_CHARCELLS status_set_usb(false); Index: firmware/usbstack/usb_storage.c =================================================================== --- firmware/usbstack/usb_storage.c (revision 20237) +++ firmware/usbstack/usb_storage.c (working copy) @@ -260,6 +260,7 @@ static void fill_inquiry(IF_MV_NONVOID(int lun)); static void send_and_read_next(void); static bool ejected[NUM_VOLUMES]; +static bool locked[NUM_VOLUMES]; static int usb_interface; static int ep_in, ep_out; @@ -304,14 +305,14 @@ #endif } -static void try_release_ata(void) +void usb_storage_try_release_ata(void) { /* Check if there is a connected drive left. If not, release excusive access */ bool canrelease=true; int i; for(i=0;icommand_block[4] & 0x03) == 0) { + locked[lun]=false; queue_broadcast(SYS_USB_LUN_LOCKED, (lun<<16)+0); } else { + locked[lun]=true; queue_broadcast(SYS_USB_LUN_LOCKED, (lun<<16)+1); } send_csw(UMS_STATUS_GOOD);