Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

IAP: Reset IAP state upon headphone or dock unplug

Provides a semi-automatic way of recovering from desynchronization

Change-Id: I527b0bacc22ef38c1e7213653e522ea1b0ac155d

+93 -15
+7 -4
apps/debug_menu.c
··· 118 118 #include "usb_core.h" 119 119 #endif 120 120 121 - #if defined(IPOD_ACCESSORY_PROTOCOL) 122 - #include "iap.h" 123 - #endif 124 - 125 121 #include "talk.h" 126 122 127 123 #if defined(HAVE_DEVICEDATA)// && !defined(SIMULATOR) ··· 138 134 139 135 #if defined(IPOD_6G) && !defined(SIMULATOR) 140 136 #include "norboot-target.h" 137 + #endif 138 + 139 + #if defined(IPOD_ACCESSORY_PROTOCOL) 140 + #include "iap.h" 141 141 #endif 142 142 143 143 #define SCREEN_MAX_CHARS (LCD_WIDTH / SYSFONT_WIDTH) ··· 2852 2852 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \ 2853 2853 && !defined(IPOD_MINI) && !defined(SIMULATOR)) 2854 2854 {"Debug scrollwheel", dbg_scrollwheel }, 2855 + #endif 2856 + #if defined(IPOD_ACCESSORY_PROTOCOL) 2857 + {"Debug IAP", dbg_iap }, 2855 2858 #endif 2856 2859 {"Talk engine stats", dbg_talk }, 2857 2860 #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
+65 -10
apps/iap/iap-core.c
··· 177 177 178 178 /* states of the iap de-framing state machine */ 179 179 enum fsm_state { 180 - ST_SYNC, /* wait for 0xFF sync byte */ 180 + ST_SYNC = 0, /* wait for 0xFF sync byte */ 181 181 ST_SOF, /* wait for 0x55 start-of-frame byte */ 182 182 ST_LEN, /* receive length byte (small packet) */ 183 183 ST_LENH, /* receive length high byte (large packet) */ ··· 209 209 #endif 210 210 211 211 static void iap_malloc(void); 212 + 213 + static void iap_reset_buffers(void) 214 + { 215 + iap_txstart = iap_buffers; 216 + iap_txpayload = iap_txstart+5; 217 + iap_txnext = iap_txpayload; 218 + iap_rxstart = iap_buffers+(TX_BUFLEN+6); 219 + iap_rxpayload = iap_rxstart; 220 + iap_rxnext = iap_rxpayload; 221 + iap_rxlen = RX_BUFLEN+2; 222 + } 212 223 213 224 void put_u16(unsigned char *buf, const uint16_t data) 214 225 { ··· 295 306 auth->next_section = 0; 296 307 } 297 308 309 + void iap_reset_state(int port) 310 + { 311 + if (!iap_running) 312 + return; 313 + 314 + /* 0 is dock, 1 is headphone. This is for 315 + when we eventually maintain independent state */ 316 + (void)port; 317 + 318 + iap_reset_device(&device); 319 + iap_bitrate_set(global_settings.serial_bitrate); 320 + 321 + #if 0 // XXX this is still screwed up 322 + memset(&frame_state, 0, sizeof(frame_state)); 323 + interface_state = IST_STANDARD; 324 + frame_state.state = ST_SYNC; 325 + 326 + iap_reset_buffers(); 327 + #endif 328 + } 329 + 298 330 void iap_reset_device(struct device_t* device) 299 331 { 300 332 iap_reset_auth(&(device->auth)); ··· 325 357 IAP_TX_PUT(0xFF & (int)((global_status.volume + 90) * 2.65625)); 326 358 iap_send_tx(); 327 359 } 328 - 329 360 330 361 /* This thread is waiting for events posted to iap_queue and calls 331 362 * the appropriate subroutines in response ··· 460 491 #else 461 492 iap_buffers = serbuf; 462 493 #endif 463 - iap_txstart = iap_buffers; 464 - iap_txpayload = iap_txstart+5; 465 - iap_txnext = iap_txpayload; 466 - iap_rxstart = iap_buffers+(TX_BUFLEN+6); 467 - iap_rxpayload = iap_rxstart; 468 - iap_rxnext = iap_rxpayload; 469 - iap_rxlen = RX_BUFLEN+2; 494 + 495 + iap_reset_buffers(); 470 496 iap_running = true; 471 497 } 472 498 ··· 996 1022 if (device.play_status != play_status) 997 1023 { 998 1024 /* If play_status = PAUSE/STOP we should mute else 999 - * we should unmute 1025 + * we should unmute 1000 1026 * 0 = Stopped 1001 1027 * 1 = Playing 1002 1028 * 2 = Pause ··· 1418 1444 IAP_TX_PUT(0x00); 1419 1445 } 1420 1446 } 1447 + 1448 + #include "lcd.h" 1449 + #include "font.h" 1450 + bool dbg_iap(void) 1451 + { 1452 + lcd_setfont(FONT_SYSFIXED); 1453 + 1454 + while (1) 1455 + { 1456 + if (action_userabort(HZ/10)) 1457 + break; 1458 + 1459 + lcd_clear_display(); 1460 + 1461 + /* show internal state of IAP subsystem */ 1462 + lcd_putsf(0, 0, "auth: %d acc: %d", device.auth.state, device.accinfo); 1463 + lcd_putsf(0, 1, "lin: %08x", device.lingoes); 1464 + lcd_putsf(0, 2, "notif: %08x", device.notifications); 1465 + lcd_putsf(0, 3, "cap: %08x/%08x", device.capabilities, device.capabilities_queried); 1466 + 1467 + // frame_state.state 1468 + // serial state 1469 + 1470 + lcd_update(); 1471 + } 1472 + 1473 + lcd_setfont(FONT_UI); 1474 + return false; 1475 + }
+11
firmware/drivers/button.c
··· 45 45 #include "lcd.h" /* lcd_active() prototype */ 46 46 #endif 47 47 48 + #if defined(IPOD_ACCESSORY_PROTOCOL) && (defined(IPOD_COLOR) || defined(IPOD_4G) || defined(IPOD_MINI) || defined(IPOD_MINI2G)) 49 + #include "iap.h" 50 + #endif 51 + 48 52 static long lastbtn; /* Last valid button status */ 49 53 static long last_read; /* Last button status, for debouncing/filtering */ 50 54 static bool flipped; /* buttons can be flipped to match the LCD flip */ ··· 102 106 /* Try to post only transistions */ 103 107 const long id = tmo->data ? SYS_PHONE_PLUGGED : SYS_PHONE_UNPLUGGED; 104 108 button_queue_post_remove_head(id, 0); 109 + 110 + #if defined(IPOD_ACCESSORY_PROTOCOL) && (defined(IPOD_COLOR) || defined(IPOD_4G) || defined(IPOD_MINI) || defined(IPOD_MINI2G)) 111 + if (id == SYS_PHONE_UNPLUGGED) 112 + iap_reset_state(1); 113 + #endif 114 + 105 115 return 0; 106 116 /*misc.c:hp_unplug_change*/ 107 117 } ··· 113 123 /* Try to post only transistions */ 114 124 const long id = tmo->data ? SYS_LINEOUT_PLUGGED : SYS_LINEOUT_UNPLUGGED; 115 125 button_queue_post_remove_head(id, 0); 126 + 116 127 return 0; 117 128 /*misc.c:lo_unplug_change*/ 118 129 }
+2 -1
firmware/export/iap.h
··· 37 37 #ifdef HAVE_LINE_REC 38 38 extern bool iap_record(bool onoff); 39 39 #endif 40 - 40 + void iap_reset_state(int port); /* 0 is dock, 1 is headphone */ 41 + bool dbg_iap(void); 41 42 #endif
+8
firmware/usb.c
··· 51 51 #include "gui/skin_engine/skin_engine.h" 52 52 #endif 53 53 54 + #if defined(IPOD_ACCESSORY_PROTOCOL) 55 + #include "iap.h" 56 + #endif 57 + 54 58 /* Conditions under which we want the entire driver */ 55 59 #if !defined(BOOTLOADER) || \ 56 60 (defined(HAVE_USBSTACK) && defined(HAVE_BOOTLOADER_USB_MODE)) || \ ··· 520 524 521 525 if(usb_state == USB_POWERED || usb_state == USB_INSERTED) 522 526 usb_stack_enable(false); 527 + 528 + #ifdef IPOD_ACCESSORY_PROTOCOL 529 + iap_reset_state(0); 530 + #endif 523 531 524 532 /* Only disable the USB slave mode if we really have enabled 525 533 it. Some expected acks may not have been received. */