summaryrefslogtreecommitdiff
path: root/apps/iap/iap-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/iap/iap-core.c')
-rw-r--r--apps/iap/iap-core.c115
1 files changed, 64 insertions, 51 deletions
diff --git a/apps/iap/iap-core.c b/apps/iap/iap-core.c
index f8373bab83..885ba2c188 100644
--- a/apps/iap/iap-core.c
+++ b/apps/iap/iap-core.c
@@ -45,7 +45,9 @@
45#include "usb.h" 45#include "usb.h"
46 46
47#include "tuner.h" 47#include "tuner.h"
48#if CONFIG_TUNER
48#include "ipod_remote_tuner.h" 49#include "ipod_remote_tuner.h"
50#endif
49 51
50 52
51/* MS_TO_TICKS converts a milisecond time period into the 53/* MS_TO_TICKS converts a milisecond time period into the
@@ -164,7 +166,13 @@ unsigned char lingo_versions[32][2] = {
164 {1, 5}, /* Display remote lingo, 0x03 */ 166 {1, 5}, /* Display remote lingo, 0x03 */
165 {1, 12}, /* Extended Interface lingo, 0x04 */ 167 {1, 12}, /* Extended Interface lingo, 0x04 */
166 {1, 1}, /* RF/BT Transmitter lingo, 0x05 */ 168 {1, 1}, /* RF/BT Transmitter lingo, 0x05 */
167 {} /* All others are unsupported */ 169 {0, 0}, /* USB Host lingo, 0x06, disabled */
170#if CONFIG_TUNER
171 {1, 0}, /* RF Receiver lingo, 0x07 */
172#else
173 {0, 0}, /* RF Receiver lingo, 0x07 disabled */
174#endif
175 {} /* every other lingo, disabled */
168}; 176};
169 177
170/* states of the iap de-framing state machine */ 178/* states of the iap de-framing state machine */
@@ -308,6 +316,17 @@ static int iap_task(struct timeout *tmo)
308 return MS_TO_TICKS(100); 316 return MS_TO_TICKS(100);
309} 317}
310 318
319
320void iap_set_remote_volume(void)
321{
322 IAP_TX_INIT(0x03, 0x0D);
323 IAP_TX_PUT(0x04);
324 IAP_TX_PUT(0x00);
325 IAP_TX_PUT(0xFF & (int)((global_settings.volume + 90) * 2.65625));
326 iap_send_tx();
327}
328
329
311/* This thread is waiting for events posted to iap_queue and calls 330/* This thread is waiting for events posted to iap_queue and calls
312 * the appropriate subroutines in response 331 * the appropriate subroutines in response
313 */ 332 */
@@ -859,11 +878,15 @@ void iap_periodic(void)
859 878
860 /* Volume change notifications are sent every 100ms */ 879 /* Volume change notifications are sent every 100ms */
861 if (device.notifications & (BIT_N(4) | BIT_N(16))) { 880 if (device.notifications & (BIT_N(4) | BIT_N(16))) {
862 /* Currently we do not track volume changes, so this is 881 /* Currently we do not track volume changes for BIT_N(16),
863 * never sent.
864 * 882 *
865 * TODO: Fix volume tracking
866 */ 883 */
884 IAP_TX_INIT(0x03, 0x09);
885 IAP_TX_PUT(0x04);
886 IAP_TX_PUT(0x00);
887 IAP_TX_PUT(0xFF &(int)((global_settings.volume + 90) * 2.65625));
888 device.changed_notifications |= BIT_N(4);
889 iap_send_tx();
867 } 890 }
868 891
869 /* All other events are sent every 500ms */ 892 /* All other events are sent every 500ms */
@@ -972,9 +995,15 @@ void iap_periodic(void)
972 unsigned char play_status; 995 unsigned char play_status;
973 996
974 play_status = audio_status(); 997 play_status = audio_status();
975
976 if (device.play_status != play_status) 998 if (device.play_status != play_status)
977 { 999 {
1000 /* If play_status = PAUSE/STOP we should mute else
1001 * we should unmute
1002 * 0 = Stopped
1003 * 1 = Playing
1004 * 2 = Pause
1005 * 3 = Play/Pause
1006 */
978 IAP_TX_INIT(0x03, 0x09); 1007 IAP_TX_INIT(0x03, 0x09);
979 IAP_TX_PUT(0x03); 1008 IAP_TX_PUT(0x03);
980 if (play_status & AUDIO_STATUS_PLAY) { 1009 if (play_status & AUDIO_STATUS_PLAY) {
@@ -994,6 +1023,23 @@ void iap_periodic(void)
994 iap_send_tx(); 1023 iap_send_tx();
995 1024
996 device.play_status = play_status; 1025 device.play_status = play_status;
1026 if (play_status != 1) {
1027 /* Not Playing */
1028 audio_pause();
1029#if CONFIG_TUNER
1030 if (radio_present==1) {
1031 tuner_set(RADIO_MUTE,1);
1032 }
1033#endif
1034 } else {
1035 /* Playing */
1036 audio_resume();
1037#if CONFIG_TUNER
1038 if (radio_present==1) {
1039 tuner_set(RADIO_MUTE,0);
1040 }
1041#endif
1042 }
997 } 1043 }
998 } 1044 }
999 1045
@@ -1212,43 +1258,6 @@ static void iap_handlepkt_mode5(const unsigned int len, const unsigned char *buf
1212 } 1258 }
1213} 1259}
1214 1260
1215#if 0
1216static void iap_handlepkt_mode7(const unsigned int len, const unsigned char *buf)
1217{
1218 unsigned int cmd = buf[1];
1219 switch (cmd)
1220 {
1221 /* RetTunerCaps */
1222 case 0x02:
1223 {
1224 /* do nothing */
1225
1226 /* GetAccessoryInfo */
1227 unsigned char data[] = {0x00, 0x27, 0x00};
1228 iap_send_pkt(data, sizeof(data));
1229 break;
1230 }
1231
1232 /* RetTunerFreq */
1233 case 0x0A:
1234 /* fall through */
1235 /* TunerSeekDone */
1236 case 0x13:
1237 {
1238 rmt_tuner_freq(len, buf);
1239 break;
1240 }
1241
1242 /* RdsReadyNotify, RDS station name 0x21 1E 00 + ASCII text*/
1243 case 0x21:
1244 {
1245 rmt_tuner_rds_data(len, buf);
1246 break;
1247 }
1248 }
1249}
1250#endif
1251
1252void iap_handlepkt(void) 1261void iap_handlepkt(void)
1253{ 1262{
1254 int level; 1263 int level;
@@ -1271,17 +1280,21 @@ void iap_handlepkt(void)
1271 logf("R: %s", hexstring(iap_rxstart+2, (length))); 1280 logf("R: %s", hexstring(iap_rxstart+2, (length)));
1272#endif 1281#endif
1273 1282
1274 unsigned char mode = *(iap_rxstart+2); 1283 if (length != 0) {
1275 switch (mode) { 1284 unsigned char mode = *(iap_rxstart+2);
1276 case 0: iap_handlepkt_mode0(length, iap_rxstart+2); break; 1285 switch (mode) {
1286 case 0: iap_handlepkt_mode0(length, iap_rxstart+2); break;
1277#ifdef HAVE_LINE_REC 1287#ifdef HAVE_LINE_REC
1278 case 1: iap_handlepkt_mode1(length, iap_rxstart+2); break; 1288 case 1: iap_handlepkt_mode1(length, iap_rxstart+2); break;
1279#endif 1289#endif
1280 case 2: iap_handlepkt_mode2(length, iap_rxstart+2); break; 1290 case 2: iap_handlepkt_mode2(length, iap_rxstart+2); break;
1281 case 3: iap_handlepkt_mode3(length, iap_rxstart+2); break; 1291 case 3: iap_handlepkt_mode3(length, iap_rxstart+2); break;
1282 case 4: iap_handlepkt_mode4(length, iap_rxstart+2); break; 1292 case 4: iap_handlepkt_mode4(length, iap_rxstart+2); break;
1283 case 5: iap_handlepkt_mode5(length, iap_rxstart+2); break; 1293 case 5: iap_handlepkt_mode5(length, iap_rxstart+2); break;
1284 /* case 7: iap_handlepkt_mode7(length, iap_rxstart+2); break; */ 1294#if CONFIG_TUNER
1295 case 7: iap_handlepkt_mode7(length, iap_rxstart+2); break;
1296#endif
1297 }
1285 } 1298 }
1286 1299
1287 /* Remove the handled packet from the RX buffer 1300 /* Remove the handled packet from the RX buffer