void ProcessIO(void) { BYTE numBytesRead; //Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; if(buttonPressed) { if(stringPrinted == FALSE) { if(mUSBUSARTIsTxTrfReady()) { putrsUSBUSART("Button Pressed data-- \r\n"); stringPrinted = TRUE; } } } else { stringPrinted = FALSE; } if(USBUSARTIsTxTrfReady()) { numBytesRead = getsUSBUSART(USB_Out_Buffer,64); if(numBytesRead != 0) { BYTE i; for(i=0;i<numBytesRead;i++) { switch(USB_Out_Buffer[i]) { case 0x0A: case 0x0D: putUSBUSART(&USB_Out_Buffer[i],numBytesRead); break; case 0x53://letter S to start sampling ReadADC(); putUSBUSART(ADC_sample,SAMPLE_SIZE); break; case 0x51: //letter Q to stop break; default: putUSBUSART(&USB_Out_Buffer[i],numBytesRead); break; } } //putUSBUSART(USB_In_Buffer,numBytesRead); } } CDCTxService(); } //end ProcessIO
static void continueWithCurrentMode(void) { if(currentMode == PR_ECHO) { echo(); } else if(currentMode == PR_MOTOR_CONTROL) { handleMotorControlRequest(); } else if(currentMode == PR_READSENSOR) { if(dataAvailable==0) { loadNewData(); } if(dataAvailable>=1) { SensorDataPacket toSend; Sensor sensor; sensor = USB_In_Buffer[currentByte]; currentByte = (currentByte+1)%BUFFER_SIZE; dataAvailable--; currentMode = PR_NOREQUEST; toSend = getDataPacketForSensor(sensor); *((SensorDataPacket*)USB_Out_Buffer) = toSend; putUSBUSART(USB_Out_Buffer,sizeof(SensorDataPacket)); } } }
void ProcessIO(void) { //Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; // only check for new USB buffer if the old RS232 buffer is // empty. This will cause additional USB packets to be NAK'd // RS232_送信バッファに HostPC から届いたデータをFillする. if (LastRS232Out == 0) { LastRS232Out = getsUSBUSART(RS232_Out_Data,64); //until the buffer is free. if(LastRS232Out > 0) { // RS232_Out_Data_Rdy = 1; // signal buffer full RS232cp = 0; // Reset the current position } } if(LastRS232Out && (NextUSBOut==0)) { //エコーバック専用: memcpy(USB_Out_Buffer,RS232_Out_Data,LastRS232Out); NextUSBOut = LastRS232Out; LastRS232Out = 0; } //可能なら、RS232_受信バッファの内容をHostPCに送る. if((USBUSARTIsTxTrfReady()) && (NextUSBOut > 0)){ putUSBUSART(&USB_Out_Buffer[0], NextUSBOut); NextUSBOut = 0; } CDCTxService(); }
void SendUSBMessage(char *message, unsigned int len) { BYTE tosend; // give up if the other end isn't listening! if(!USBUSARTIsTxTrfReady()) return; while (len) { if(len <= (int) 255) tosend= (BYTE) len; else tosend= (BYTE) 255; putUSBUSART(message, tosend); message += tosend; len -= tosend; // don't return until message is sent otherwise we get problems // with buffer being overwitten - e.g. LIST while (!USBUSARTIsTxTrfReady()) CDCTxService(); } }
void cdc_print_all(BYTE x,BYTE y,BYTE z,UINT16 l,BYTE t,char* dstr,char* tstr) { sprintf(USB_Buffer,"acc[%03d,%03d,%03d] lgt[%04u] tmp[%03d] clk[%s,%s]", x, y, z, l, t, dstr, tstr); USB_Buffer[61] = 0; putUSBUSART(USB_Buffer, 62); }
void cdc_print_init(UINT32_VAL msg) { sprintf(USB_Buffer, "init: %02x %02x %02x", (msg.v[0]), (msg.v[1]), (msg.v[2])); USB_Buffer[14] = 0; putUSBUSART(USB_Buffer, 15); }
static void echo(void) { loadNewData(); if(dataAvailable>=1) { UINT8 i; for(i=0;i<dataAvailable;i++) { if(USB_In_Buffer[(currentByte+i)%BUFFER_SIZE] == 0) { currentMode = PR_NOREQUEST; break; } USB_Out_Buffer[i] = USB_In_Buffer[(currentByte+i)%BUFFER_SIZE]; } putUSBUSART(USB_Out_Buffer,i); currentByte = (currentByte+i)%BUFFER_SIZE; dataAvailable -= i; } }
unsigned int usb_tty_loop(void){ USB_BUFFER usb_task; /* regiao critica */ portENTER_CRITICAL(); if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)){ portEXIT_CRITICAL(); return 0; } if (USBUSARTIsTxTrfReady()){ if (buffer_entrada_cont == 0) { buffer_entrada_cont = getsUSBUSART((char *)buffer_entrada, sizeof(buffer_entrada)); } if(xQueueReceive(usb_buffer_queue, &usb_task, ( portTickType ) 10)){ putUSBUSART((char *)usb_task.out, usb_task.co); } } CDCTxService(); portEXIT_CRITICAL(); return 1; }
/* * Main program entry point. */ int main (void) { AD1PCFG = 0xFFFF; //Initialize all of the LED pins LATE |= 0x000F; TRISE &= 0xFFF0; USBDeviceInit(); //usb_device.c. Initializes USB module SFRs and firmware //variables to known states. PMCON = 0; for (;;) { // Check bus status and service USB interrupts. USBDeviceTasks(); // Interrupt or polling method. If using polling, must call // this function periodically. This function will take care // of processing and responding to SETUP transactions // (such as during the enumeration process when you first // plug in). USB hosts require that USB devices should accept // and process SETUP packets in a timely fashion. Therefore, // when using polling, this function should be called // frequently (such as once about every 100 microseconds) at any // time that a SETUP packet might reasonably be expected to // be sent by the host to your device. In most cases, the // USBDeviceTasks() function does not take very long to // execute (~50 instruction cycles) before it returns. // Application-specific tasks. // Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if (USBDeviceState >= CONFIGURED_STATE && ! (U1PWRC & PIC32_U1PWRC_USUSPEND)) { unsigned nbytes_read; static unsigned char inbuf[64], outbuf[64]; static unsigned led3_count = 0; // Pull in some new data if there is new data to pull in nbytes_read = getsUSBUSART ((char*) inbuf, 64); if (nbytes_read != 0) { snprintf (outbuf, sizeof(outbuf), "Received %d bytes: %02x...\r\n", nbytes_read, inbuf[0]); putUSBUSART ((char*) outbuf, strlen (outbuf)); mLED_2_Toggle(); mLED_3_On(); led3_count = 10000; } if (led3_count) { // Turn off LED3 when timeout expired. led3_count--; if (led3_count == 0) mLED_3_Off(); } CDCTxService(); } } }
/*=================================================== | Funtions | ===================================================*/ void USBGetInput(void) { if((USBUSARTIsTxTrfReady()) && (NextOut > 0)) { putUSBUSART(&Out_Buffer[0], NextOut); NextOut = 0; } }
void usb_char_send(char c) { if (!is_usb_available()) { //USBCBSendResume(); return; } while (!USBUSARTIsTxTrfReady()) CDCTxService(); putUSBUSART(&c, 1); CDCTxService(); }
/******************************************************************** * Function: void ProcessIO(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function is a place holder for other user * routines. It is a mixture of both USB and * non-USB tasks. * * Note: None *******************************************************************/ void ProcessIO(void) { BYTE numBytesRead; //Blink the LEDs according to the USB device status // // User Application USB tasks // // If suspended, do nothing. if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; // If character received, echo it if(mUSBUSARTIsTxTrfReady()) { numBytesRead = getsUSBUSART(USB_Out_Buffer,64); if(numBytesRead != 0) { BYTE i; #ifdef NETV #else for(i=0;i<numBytesRead;i++) { USB_In_Buffer[i] = USB_Out_Buffer[i]; } //Test: Send SPI word to control motor if(USB_In_Buffer[0] == 'u') { motor_speed += 250; if(motor_speed > 3000) motor_speed = 3000; SpiChnPutC(4, motor_speed); } else if(USB_In_Buffer[0] == 'i') { motor_speed -= 250; if(motor_speed < -3000) motor_speed = -3000; SpiChnPutC(4, motor_speed); } putUSBUSART(USB_In_Buffer,numBytesRead); //Echo HBLED1 ^= 1; //Toggle LEDs HBLED2 ^= 1; #endif } } // Service the USB CDC driver CDCTxService(); } // End ProcessIO
void cdc_print_ver(rom char* name_str, rom char* ver_str) { char i; for (i = 0; i < 8; i++) USB_Buffer[i] = name_str[i]; USB_Buffer[8] = ' '; for (i = 9; i < 16; i++) USB_Buffer[i] = ver_str[i - 9]; putUSBUSART(USB_Buffer, 16); }
/** Procesamiento de información USB */ void USB_process(void) { static char RTCC_CONF[] = "rtccconfig"; static char RTCC_TEST[] = "rtcctest"; static char XBEE_JOIN[] = "xbeejoin"; static char ADC_TEST[] = "adctest"; // Sht-11 test commands static char SHT[] = "shttest"; BYTE numBytesRead; // Init payloads Payload_init(&usbInputBuffer); Payload_init(&usbOutputBuffer); // User Application USB tasks if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)) { return; } // Recibe un buffer de tamaño determinado numBytesRead = getsUSBUSART((char*)usbOutputBuffer.data, 64); // Si ha leído datos if (numBytesRead != 0) { if (strncmp((char*)usbOutputBuffer.data, RTCC_CONF, strlen(RTCC_CONF)) == 0) { Rtc_readInputStream(&usbOutputBuffer); Rtc_writeFormattedTimestamp(&usbInputBuffer); } else if (strncmp((char*)usbOutputBuffer.data, RTCC_TEST, strlen(RTCC_TEST)) == 0) { Rtc_readTimestamp(); Rtc_writeFormattedTimestamp(&usbInputBuffer); } else if (strncmp((char*)usbOutputBuffer.data, XBEE_JOIN, strlen(XBEE_JOIN)) == 0) { XBee_join(); Payload_putString(&usbInputBuffer, (UINT8*) "Join request sent"); } else if (strncmp((char*)usbOutputBuffer.data, ADC_TEST, strlen(ADC_TEST)) == 0) { // TODO Payload_putString(&usbInputBuffer, (UINT8*) "Adc test received"); } else if (strncmp((char*)usbOutputBuffer.data, SHT, strlen(SHT)) == 0) { #if SHT_ENABLED Sht11_measure(&sht); Sht11_addMeasuresCalculatedToPayload(&sht, &usbInputBuffer); #else Payload_putString(&usbInputBuffer, (UINT8*) "SHT11 not installed"); #endif } else { // Si el comando es erróneo, muestra un mensaje de error Payload_putString(&usbInputBuffer, (UINT8*) "Comando desconocido"); } // Si está preparado para enviar datos if (USBUSARTIsTxTrfReady() && usbInputBuffer.size != 0) { putUSBUSART((char*)usbInputBuffer.data, (BYTE) usbInputBuffer.size); } } CDCTxService(); }
void ProcessIO(void) { uchar i; BlinkUSBStatus(); //Blink the LEDs according to the USB device status // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; // only check for new USB buffer if the old RS232 buffer is // empty. This will cause additional USB packets to be NAK'd // RS232_送信バッファに HostPC から届いたデータをFillする. if( mDataRdyUSART() < 32 ) if (LastRS232Out == 0) { LastRS232Out = getsUSBUSART(RS232_Out_Data,64); //until the buffer is free. if(LastRS232Out > 0) { // RS232_Out_Data_Rdy = 1; // signal buffer full RS232cp = 0; // Reset the current position } } #if USART_USE_TX_INTERRUPT // 送信割り込みを使用する. //USARTが送信可であれば RS232_送信バッファの内容を USARTに 1文字送る. if(LastRS232Out && mTxRdyUSART()) { // PIR1bits.TXIF = 0; // 送信割り込みフラグ. PIE1bits.TXIE = 1; // 送信割り込み許可. } #else //USARTが送信可であれば RS232_送信バッファの内容を USARTに 1文字送る. if(LastRS232Out && mTxRdyUSART()) { putcUSART(RS232_Out_Data[RS232cp]); //1文字送る. ++RS232cp; if (RS232cp == LastRS232Out) { // RS232_Out_Data_Rdy = 0; LastRS232Out=0; RS232cp=0; } } #endif //可能なら、RS232_受信バッファの内容をHostPCに送る. if((USBUSARTIsTxTrfReady()) && (mDataRdyUSART())){ i=0; while( mDataRdyUSART() ) { if(i>=CDC_DATA_OUT_EP_SIZE) break; USB_Out_Buffer[i++]=getcUSART(); } putUSBUSART(&USB_Out_Buffer[0], i); NextUSBOut = 0; } CDCTxService(); }
void BootProtocolTasks() { if (USBUSARTIsTxTrfReady()) { const BYTE* data; if (bytes_out) { ByteQueuePull(&tx_queue, bytes_out); bytes_out = 0; } ByteQueuePeek(&tx_queue, &data, &bytes_out); if (bytes_out > 0) { if (bytes_out > max_packet) bytes_out = max_packet; putUSBUSART((char *) data, bytes_out); } } }
void ProcessIO(void) { uchar cnt; //Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; // only check for new USB buffer if the old RS232 buffer is // empty. This will cause additional USB packets to be NAK'd // RS232_送信バッファに HostPC から届いたデータをFillする. if (LastRS232Out == 0) { LastRS232Out = getsUSBUSART(RS232_Out_Data,64); //until the buffer is free. if(LastRS232Out > 0) { RS232cp = 0; // Reset the current position } } for(cnt=0;cnt<32;cnt++) { //USARTが送信可であれば RS232_送信バッファの内容を USARTに 1文字送る. if(LastRS232Out && mTxRdyUSART()) { putcUSART(RS232_Out_Data[RS232cp]); //1文字送る. ++RS232cp; if (RS232cp == LastRS232Out) { LastRS232Out=0; RS232cp=0; } } //USARTがデータを受信済みであれば RS232_受信バッファに溜める. if(mDataRdyUSART()) { USB_Out_Buffer[NextUSBOut] = getcUSART(); ++NextUSBOut; //USB_Out_Buffer[NextUSBOut] = 0; } } //可能なら、RS232_受信バッファの内容をHostPCに送る. if((USBUSARTIsTxTrfReady()) && (NextUSBOut > 0)){ putUSBUSART(&USB_Out_Buffer[0], NextUSBOut); NextUSBOut = 0; } CDCTxService(); }
/******************************************************************** * Function: void ProcessIO(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function is a place holder for other user * routines. It is a mixture of both USB and * non-USB tasks. * * Note: None *******************************************************************/ void ProcessIO(void) { //Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; // only check for new USB buffer if the old RS232 buffer is // empty. // Additional USB packets will be NAK'd // until the buffer is free. if (RS232_Out_Data_Rdy == 0) { LastRS232Out = getsUSBUSART(RS232_Out_Data,64); if(LastRS232Out > 0) { RS232_Out_Data_Rdy = 1; // signal //buffer full RS232cp = 0;// Reset the current position } } if(RS232_Out_Data_Rdy && mTxRdyUSART()) { putcUSART(RS232_Out_Data[RS232cp]); ++RS232cp; if (RS232cp == LastRS232Out) RS232_Out_Data_Rdy = 0; } if(mDataRdyUSART()) { USB_Out_Buffer[NextUSBOut] = getcUSART(); ++NextUSBOut; USB_Out_Buffer[NextUSBOut] = 0; } if((mUSBUSARTIsTxTrfReady()) && (NextUSBOut > 0)) { putUSBUSART(&USB_Out_Buffer[0], NextUSBOut); NextUSBOut = 0; } CDCTxService(); } //end ProcessIO
unsigned char SUMPlogicService(void){ static unsigned char i, USBWriteCount; switch(LAstate){//dump data //case IDLE: //case ARMED: //case LA_START_DUMP: case LA_DUMP: if(USBUSARTIsTxTrfReady()){ USBWriteCount=0; for(i=0; i<8; i++){ loga.btrack<<=1; //shift bit at begin to reset from last loop if((loga.btrack==0) && (loga.ptr>0) ){//no bits left loga.btrack=0b00000001;//start at bit 0 loga.ptr--; } if( (irToy.s[loga.ptr] & loga.btrack)!=0) irToy.usbOut[USBWriteCount]=0; else irToy.usbOut[USBWriteCount]=1; USBWriteCount++; loga.sample--; if(loga.sample==0){//send 64/128/512/1024 samples exactly! LAstate=LA_RESET; break; } } putUSBUSART(irToy.usbOut,USBWriteCount); } break; case LA_RESET: LAstate = LA_IDLE; return 0xff; break; } return 0; }
void DebugService(void) { if(USBUSARTIsTxTrfReady() && current_buffer_len) { putUSBUSART((uint8_t *)current_buffer, current_buffer_len); if (current_buffer == buffer_1) { current_buffer = buffer_2; } else { current_buffer = buffer_1; } current_buffer_len = 0; if (dropped_lines) { // The USB layer couln't send the data fast enough. If this is a problem, calling CDCService() more often could help. current_buffer[0] = '\n'; // Send an empty line to show that the overflow happened. current_buffer_len++; dropped_lines = 0; } } }
// *--------------------------------------------------------------------------------* void ProcessIO(void){ BYTE numBytesRead; //Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; if(buttonPressed){ if(stringPrinted == FALSE){ if(mUSBUSARTIsTxTrfReady()){ putrsUSBUSART("Button Pressed -- \r\n"); stringPrinted = TRUE; } } }else{ stringPrinted = FALSE; } if(USBUSARTIsTxTrfReady()){ numBytesRead = getsUSBUSART(USB_Out_Buffer,64); if(numBytesRead != 0){ BYTE i; for(i=0;i<numBytesRead;i++){ switch(USB_Out_Buffer[i]){ case 0x0A: case 0x0D: USB_In_Buffer[i] = USB_Out_Buffer[i]; break; default: USB_In_Buffer[i] = USB_Out_Buffer[i] + 1; break; } } putUSBUSART(USB_In_Buffer,numBytesRead); } } CDCTxService(); }
void usb_send(const char *format, ...) { //char *usb_msg; static unsigned char usb_msg[CDC_DATA_OUT_EP_SIZE]; va_list args; va_start(args,__format); sprintf(usb_msg,format,args); if (( USBGetDeviceState() < CONFIGURED_STATE ) || ( USBIsDeviceSuspended() == true )) { return; } else { if (mUSBUSARTIsTxTrfReady()) { putUSBUSART(usb_msg,strlen(usb_msg)); } CDCTxService(); } }
/** * blink LED, send data on queue */ void ProcessIO(void) { BlinkUSBStatus(); if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)) { return; } if (USBUSARTIsTxTrfReady()) { int len = 0; char temp[QUEUE_SIZE]; while (QueueHas()) { temp[len++] = QueueGet(); } if (len > 0) { putUSBUSART(temp, len); } } CDCTxService(); }
void CDCputs(u8 *buffer, u8 length) { u16 i; for (i = 1000; i > 0; --i) { if (mUSBUSARTIsTxTrfReady()) break; #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__) USB_Service(); #else CDCTxService(); #endif } if (i > 0) { putUSBUSART(buffer, length); #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__) USB_Service(); #else CDCTxService(); #endif } }
/******************************************************************** * Function: void ProcessIO(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function is a place holder for other user * routines. It is a mixture of both USB and * non-USB tasks. * * Note: None *******************************************************************/ void ProcessIO(void) { char backSpace[3] = {0x8,' ',0x8}; // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; // If DTR is low no client is connected, back to default. if (UART_DTR == 0) { nextProcessState = P_VERSION; RS232cp = 0; } // Print welcome message if(USBUSARTIsTxTrfReady() && (UART_DTR == 1)) { setLEDs(0); // Print Version if(nextProcessState == P_VERSION) { putrsUSBUSART("\r\n POV serial configuration. Version 0.9\r\n\r\n\ttype 'help' for the list of available commands.\r\n"); nextProcessState = P_PROMPT; } // Print Prompt else if(nextProcessState == P_PROMPT) { putrsUSBUSART("\r\n>> "); nextProcessState = P_INPUT; } else if (nextProcessState == P_INPUT) { // In case the buffer is full, reset the input buffer and display error message. if (RS232cp == CDC_DATA_IN_EP_SIZE) { RS232cp = 0; nextProcessState = P_PROMPT; } // Process IO else { LastRS232Out = getsUSBUSART(&(RS232_Out_Data[RS232cp]), 1); if(LastRS232Out > 0) switch(RS232_Out_Data[RS232cp]) { // Enter/Return, process message case 0x0A: case 0x0D: ProcessMenu(); RS232cp = 0; nextProcessState = P_PROMPT; break; // Backspace case 0x7F: case 0x08: if(RS232cp > 0) {putUSBUSART(backSpace,3); RS232cp--;} break; // Replay character to user default: putUSBUSART(&(RS232_Out_Data[RS232cp]), 1); RS232cp++; } } } } CDCTxService(); // Limpa o buffer caso necess‡rio :) if(clearRS232Buffer == 1) { memset(RS232_Out_Data, '\0', sizeof(RS232_Out_Data)); clearRS232Buffer = 0; } } //end ProcessIO
void CDCTasks(void) { BYTE numBytesRead; // Blink the LEDs according to the USB device status if (blinkStatusValid) { BlinkUSBStatus(); } // User Application USB tasks if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)) { return; } #if (HILSIM_USB == 1) numBytesRead = getsUSBUSART(USB_In_Buffer, sizeof(USB_In_Buffer)); if (numBytesRead != 0) { int i = 0; while (i < numBytesRead) { udb_gps_callback_received_byte(USB_In_Buffer[i++]); } } if (mUSBUSARTIsTxTrfReady()) { int i = 0; int txchar; while ((i < sizeof(USB_Out_Buffer)) && ((txchar = udb_gps_callback_get_byte_to_send()) != -1)) { USB_Out_Buffer[i++] = txchar; } if (i > 0) { putUSBUSART(USB_Out_Buffer, i); } } #else if (mUSBUSARTIsTxTrfReady()) { numBytesRead = getsUSBUSART(USB_Out_Buffer, sizeof(USB_Out_Buffer)); if (numBytesRead != 0) { BYTE i; for (i = 0; i < numBytesRead; i++) { switch (USB_Out_Buffer[i]) { case 0x0A: case 0x0D: USB_In_Buffer[i] = USB_Out_Buffer[i]; break; default: USB_In_Buffer[i] = USB_Out_Buffer[i] + 1; break; } } putUSBUSART(USB_In_Buffer, numBytesRead); } } #endif CDCTxService(); }
/********************************************************************* * Function: void APP_DeviceCDCBasicDemoTasks(void); * * Overview: Keeps the demo running. * * PreCondition: The demo should have been initialized and started via * the APP_DeviceCDCBasicDemoInitialize() and APP_DeviceCDCBasicDemoStart() demos * respectively. * * Input: None * * Output: None * ********************************************************************/ void APP_DeviceCDCBasicDemoTasks() { uint8_t numBytesRead; uint8_t temp_level; static uint8_t numberChADC = 0; if (ready_scan){ temp_level = adc_levels[numberChADC]; numBytesRead = sprintf(writeBuffer, "ADC_NN=%u, LEVEL=%u \n\r", numberChADC, temp_level); if( USBUSARTIsTxTrfReady() == true) { putUSBUSART(writeBuffer,numBytesRead); numberChADC ++; if (numberChADC >= N_ADC) numberChADC = 0; } } CDCTxService(); // USBTxOnePacket(USB_MAX_EP_NUMBER,(uint8_t*)&midiData,2); // numBytesRead = sprintf(writeBuffer, "ADC_NN=%u, LEVEL=%u", midiData.IDX, midiData.ADC); // putUSBUSART(writeBuffer,numBytesRead); /* If the user has pressed the button associated with this demo, then we * are going to send a "Button Pressed" message to the terminal. */ // if(BUTTON_IsPressed(BUTTON_DEVICE_CDC_BASIC_DEMO) == true) // { /* Make sure that we only send the message once per button press and * not continuously as the button is held. */ // if(buttonPressed == false) // { /* Make sure that the CDC driver is ready for a transmission. */ // if(mUSBUSARTIsTxTrfReady() == true) // { // putrsUSBUSART(buttonMessage); // buttonPressed = true; // } // } // } // else // { /* If the button is released, we can then allow a new message to be * sent the next time the button is pressed. */ // buttonPressed = false; // } /* Check to see if there is a transmission in progress, if there isn't, then * we can see about performing an echo response to data received. */ // if( USBUSARTIsTxTrfReady() == true) // { // uint8_t i; // uint8_t numBytesRead; // numBytesRead = getsUSBUSART(readBuffer, sizeof(readBuffer)); /* For every byte that was read... */ // for(i=0; i<numBytesRead; i++) // { // switch(readBuffer[i]) // { /* If we receive new line or line feed commands, just echo * them direct. */ // case 0x0A: // case 0x0D: // writeBuffer[i] = readBuffer[i]; // break; /* If we receive something else, then echo it plus one * so that if we receive 'a', we echo 'b' so that the * user knows that it isn't the echo enabled on their * terminal program. */ // default: // writeBuffer[i] = readBuffer[i] + 1; // break; // } // } // if(numBytesRead > 0) // { /* After processing all of the received data, we need to send out * the "echo" data now. */ // putUSBUSART(writeBuffer,numBytesRead); // } // } // CDCTxService(); }
void ProcessIO(void) { //Blink the LEDs according to the USB device status //BlinkUSBStatus(); //C short circuit makes this work if(PORTBbits.RB13 && button_pressed < 250) { button_pressed += 1; } else if (!PORTBbits.RB13) { button_cnt = 0; button_pressed = 0; } getTouchUL(); getTouchUR(); getTouchRU(); getTouchRL(); frontBack = PORTAbits.RA8 ; shake = PORTBbits.RB8 ; // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; { unsigned char nread=0, i; nread = getsUSBUSART(USB_In_Buffer,64); //until the buffer is free. if(nread > 0) { /* speaker */ //LATAbits.LATA9 = !LATAbits.LATA9; if (USB_In_Buffer[0] == 92) play_count ^= 0x8000; play_count |= 0x0001; /* serial byte led */ //LATBbits.LATB15 = !LATBbits.LATB15; //LATBbits.LATB1 = 1;//!LATBbits.LATB1; /* contrast byte */ if (USB_In_Buffer[0] == '-') { char printme[8]; gContrast--; printme[0] = 48 + (unsigned char)gContrast / 100; printme[1] = 48 + ((unsigned char)gContrast % 100) / 10; printme[2] = 48 + ((unsigned char)gContrast % 100) % 10; printme[3] = 0; LCDString(printme); LCDInit(); //Init the LCD USB_In_Buffer[0] = 0; nread == 0; } if ((USB_In_Buffer[0] == '=') || (USB_In_Buffer[0] == '+')) { char printme[8]; gContrast++; printme[0] = 48 + (unsigned char)gContrast / 100; printme[1] = 48 + ((unsigned char)gContrast % 100) / 10; printme[2] = 48 + ((unsigned char)gContrast % 100) % 10; printme[3] = 0; LCDString(printme); LCDInit(); //Init the LCD USB_In_Buffer[0] = 0; nread == 0; } // special character that are not echoed to LCD if ((USB_In_Buffer[0] == 127) | (USB_In_Buffer[0] == 27) | (USB_In_Buffer[0] == '[')) { void LCDLogo(); /* backspace == clear screen */ if (USB_In_Buffer[0] == 127) LCDClear(); /* backlight byte */ if (USB_In_Buffer[0] == 27) LATBbits.LATB7 = !LATBbits.LATB7; /* hackrva logo */ if (USB_In_Buffer[0] == '[') LCDLogo(); USB_In_Buffer[0] = 0; nread == 0; } if (USB_In_Buffer[0] == ',') { unsigned char printme[8]; void gotoXY(int x, int y); char left = G_side_slider_left; char right = G_side_slider_right; gotoXY(0, 40); printme[0] = 'L'; printme[1] = 48 + (unsigned char)left / 100; printme[2] = 48 + ((unsigned char)left % 100) / 10; printme[3] = 48 + ((unsigned char)left % 100) % 10; printme[4] = 32; printme[5] = 0; LCDString(printme); for (i=0; printme[i] !=0 ; i++) USB_Out_Buffer[NextUSBOut++] = printme[i]; USB_Out_Buffer[NextUSBOut++] = ' '; gotoXY(42, 40); printme[0] = 'R'; printme[1] = 48 + (unsigned char)right / 100; printme[2] = 48 + ((unsigned char)right % 100) / 10; printme[3] = 48 + ((unsigned char)right % 100) % 10; printme[4] = 32; printme[5] = 0; LCDString(printme); for (i=0; printme[i] !=0 ; i++) USB_Out_Buffer[NextUSBOut++] = printme[i]; USB_Out_Buffer[NextUSBOut++] = '\r'; USB_Out_Buffer[NextUSBOut++] = '\n'; USB_In_Buffer[0] = 0; nread == 0; } if (USB_In_Buffer[0] == '.') { USB_In_Buffer[0] = 0; nread == 0; } if (USB_In_Buffer[0] == '/') { unsigned char printme[16]; void gotoXY(int x, int y); int setupRTCC(void); // shake sensor gotoXY(0, 41); printme[0] = 'S'; printme[1] = 48 + (unsigned char)shake / 100; printme[2] = 48 + ((unsigned char)shake % 100) / 10; printme[3] = 48 + ((unsigned char)shake % 100) % 10; printme[4] = 32; printme[5] = 0; LCDString(printme); for (i=0; printme[i] !=0 ; i++) USB_Out_Buffer[NextUSBOut++] = printme[i]; USB_Out_Buffer[NextUSBOut++] = ' '; // front sensor gotoXY(42, 41); printme[0] = 'F'; printme[1] = 48 + (unsigned char)frontBack / 100; printme[2] = 48 + ((unsigned char)frontBack % 100) / 10; printme[3] = 48 + ((unsigned char)frontBack % 100) % 10; printme[4] = 32; printme[5] = 0; LCDString(printme); for (i=0; printme[i] !=0 ; i++) USB_Out_Buffer[NextUSBOut++] = printme[i]; // secondary clock running status printme[0] = hextab[(OSCCON >> 28) & 0xF]; printme[1] = hextab[(OSCCON >> 24) & 0xF]; printme[2] = hextab[(OSCCON >> 20) & 0xF]; printme[3] = hextab[(OSCCON >> 16) & 0xF]; printme[4] = hextab[(OSCCON >> 12) & 0xF]; printme[5] = hextab[(OSCCON >> 8) & 0xF]; printme[6] = hextab[(OSCCON >> 4) & 0xF]; printme[7] = hextab[(OSCCON ) & 0xF]; printme[7] = 0; LCDString(printme); for (i=0; printme[i] !=0 ; i++) USB_Out_Buffer[NextUSBOut++] = printme[i]; printme[0] = 'R'; printme[1] = 'T'; printme[2] = 'C'; printme[3] = 'C'; printme[4] = ':'; printme[5] = setupRTCC(); printme[6] = 0; LCDString(printme); for (i=0; printme[i] !=0 ; i++) USB_Out_Buffer[NextUSBOut++] = printme[i]; USB_Out_Buffer[NextUSBOut++] = '\r'; USB_Out_Buffer[NextUSBOut++] = '\n'; USB_In_Buffer[0] = 0; nread == 0; } // IR xmit if (USB_In_Buffer[0] == '>') { LATCbits.LATC1 = !LATCbits.LATC1; USB_In_Buffer[0] = 0; nread == 0; } // IR recv #define IR_RECV PORTCbits.RC1 // print anything not handled above if (USB_In_Buffer[0] != 0) { char printme[32]; for (i=0; i<nread; i++) printme[i] = USB_In_Buffer[i]; printme[i] = 0; LCDString(printme); LCDInit(); //Init the LCD } for (i=0; i<nread; i++,NextUSBOut++) { USB_Out_Buffer[NextUSBOut] = USB_In_Buffer[i]; } } // echo back to USB if ((USBUSARTIsTxTrfReady()) && (NextUSBOut > 0)) { putUSBUSART(&USB_Out_Buffer[0], NextUSBOut); NextUSBOut = 0; } }
/******************************************************************** * Function: void ProcessIO(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function is a place holder for other user * routines. It is a mixture of both USB and * non-USB tasks. * * Note: None *******************************************************************/ void ProcessIO(void) { //Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; if (RS232_Out_Data_Rdy == 0) // only check for new USB buffer if the old RS232 buffer is { // empty. This will cause additional USB packets to be NAK'd LastRS232Out = getsUSBUSART(RS232_Out_Data,64); //until the buffer is free. if(LastRS232Out > 0) { RS232_Out_Data_Rdy = 1; // signal buffer full RS232cp = 0; // Reset the current position } } //Check if one or more bytes are waiting in the physical UART transmit //queue. If so, send it out the UART TX pin. if(RS232_Out_Data_Rdy && mTxRdyUSART()) { #if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL) //Make sure the receiving UART device is ready to receive data before //actually sending it. if(UART_CTS == USB_CDC_CTS_ACTIVE_LEVEL) { putcUSART(RS232_Out_Data[RS232cp]); ++RS232cp; if (RS232cp == LastRS232Out) RS232_Out_Data_Rdy = 0; } #else //Hardware flow control not being used. Just send the data. putcUSART(RS232_Out_Data[RS232cp]); ++RS232cp; if (RS232cp == LastRS232Out) RS232_Out_Data_Rdy = 0; #endif } //Check if we received a character over the physical UART, and we need //to buffer it up for eventual transmission to the USB host. if(mDataRdyUSART() && (NextUSBOut < (CDC_DATA_OUT_EP_SIZE - 1))) { USB_Out_Buffer[NextUSBOut] = getcUSART(); ++NextUSBOut; USB_Out_Buffer[NextUSBOut] = 0; } #if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL) //Drive RTS pin, to let UART device attached know if it is allowed to //send more data or not. If the receive buffer is almost full, we //deassert RTS. if(NextUSBOut <= (CDC_DATA_OUT_EP_SIZE - 5u)) { UART_RTS = USB_CDC_RTS_ACTIVE_LEVEL; } else { UART_RTS = (USB_CDC_RTS_ACTIVE_LEVEL ^ 1); } #endif //Check if any bytes are waiting in the queue to send to the USB host. //If any bytes are waiting, and the endpoint is available, prepare to //send the USB packet to the host. if((USBUSARTIsTxTrfReady()) && (NextUSBOut > 0)) { putUSBUSART(&USB_Out_Buffer[0], NextUSBOut); NextUSBOut = 0; } CDCTxService(); }//end ProcessIO
void ProcessIO(void) { unsigned short result; static char state=VALUES; static char count=-1; static char adc_nr=0; static short adcchannel=0; char overflow=0; // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; if(state == PUTHEADER){ if( mUSBUSARTIsTxTrfReady() ){ putsUSBUSART(USB_Head_Buffer); state = VALUES; } } else { if( mUSBUSARTIsTxTrfReady() ){ // Wait for completion USB_Out_Buffer[0]++; count++; if(count>=64){ //max channels count=0; USB_Out_Buffer[0] = 60; //start character } // if (count<=11) result = read_register(1, (0x0b+count) ); else // result = read_register(2, (0x0b+count-12) ); adcchannel++; if(adcchannel==16){ adcchannel=0; overflow=1; } result = spi_transfer(adc_nr, ( WRITE_REG | (adcchannel<<10) )); if(overflow==1){ overflow=0; adc_nr++; if(adc_nr==4) adc_nr=0; } USB_Out_Buffer[3] = result &0xFF; USB_Out_Buffer[2] = (result &0xFF00)>>8; putUSBUSART(USB_Out_Buffer,5); LED = !LED; } } CDCTxService(); } //end ProcessIO