void ConnectionSend(CHANNEL_HANDLE ch, const void *data, int size) { switch (ch >> 8) { case CHANNEL_TYPE_ADB: ADBWrite(ch & 0xFF, data, size); break; case CHANNEL_TYPE_ACC: AccessoryWrite(ch & 0xFF, data, size); break; case CHANNEL_TYPE_BT: assert((ch & 0xFF) == 0); BTWrite(data, size); break; } }
void AppProtocolTasks(ADB_CHANNEL_HANDLE h) { UARTTasks(); SPITasks(); I2CTasks(); ICSPTasks(); if (ADBChannelReady(h)) { BYTE prev = SyncInterruptLevel(1); const BYTE* data; int size; if (bytes_transmitted) { ByteQueuePull(&tx_queue, bytes_transmitted); bytes_transmitted = 0; } ByteQueuePeek(&tx_queue, &data, &size); if (size > 0) { ADBWrite(h, data, size); bytes_transmitted = size; } SyncInterruptLevel(prev); } }
int main() { CFGCONbits.JTAGEN = 0; // turn off JTAG, get back those pins for IO use // set PIC32to max computing power DEBUGLED = 0; // enable multi-vector interrupts INTEnableSystemMultiVectoredInt(); INTEnableInterrupts(); PIC32MX250_setup_pins(); SYSTEMConfigPerformance(SYS_FREQ); setTimer2(OUTPUT_FREQ); // setupTimer3(BUFFER_FREQ); initPWM(); //Initializing PWM on OC3. // Initialize texture buffer and index to zero int i; tBuff.Index = 0; //init to zero tBuff.On = 0; //turn off tBuff.Length0 = 0; //start with zero length tBuff.Length1 = 0; //start with zero length tBuff.Front = 0; for (i = 0; i < MAX_BUFFER_LENGTH; i++) { tBuff.Buff0[i] = 0; //init entire buffer to zero tBuff.Buff1[i] = 0; //init entire buffer to zero } // Initialize the USB host ConnectionInit(); DEBUGLED = 1; //Main USB State Machine while (1) { // Keep the USB connection running; // Handle incoming data and manage outgoing data. ConnectionTasks(); // Main state machine switch (state) { case STATE_INIT: state = STATE_WAITING; h = INVALID_CHANNEL_HANDLE; break; case STATE_WAITING: DEBUGLED = 0; if (ADBAttached()) { state = STATE_CONNECTING; } break; case STATE_CONNECTING: if (ADBConnected()) { // Open a channel to the Android device // See "adb.h" in libadb for more details // (I don't think the name tcp:4545 matters) h = ADBOpen("tcp:4545", &ADBCallback); if (h != INVALID_CHANNEL_HANDLE) { state = STATE_CONNECTED; WriteCoreTimer(0); // Send plaintext and let the recipient do formatting ADBWrite(h & 0xFF, "Hello from TPAD!", 17); } } break; case STATE_CONNECTED: DEBUGLED = 1; if (!ADBAttached()) { state = STATE_INIT; } if (ADBChannelReady(h)) { // Execute tasks that rely on the Android-PIC32 connection // Here we will just wait for messages to come in and be handled below } // Timeout timer. If the coretimer is not reset by a keepalive command from the Android, the PIC will reset the USB communications if (ReadCoreTimer() > 200000000) { state = STATE_INIT; } break; } // end state machine } // end while loop return 0; }
void ADBSend(u8 *buffer,u16 data_len) { ADBWrite(h,buffer,data_len); }
static void ADBConSend(int h, const void *data, int size) { ADBWrite(h, data, size); }