void send_keyboard(report_keyboard_t *report) { USB_LoadInEP(1, (uint8_t *)report, sizeof(report_keyboard_t)); /* Wait for ACK after loading data. */ while (0u == USB_GetEPAckState(1)) { } }
void usb_send(void) { USB_LoadInEP(OUTBOX_EP, outbox.raw, sizeof(outbox.raw)); // /* Wait for ACK after loading data. */ while (0u == USB_GetEPAckState(OUTBOX_EP)) { } }
void CommunicateUSB(void) { if (SOF_Flag) { char temp; // Arrive here every 1 msec SOF_Flag = 0; // send data to PC buttons_report[0] = debounced_state; buttons_report[1] = RedDuty; buttons_report[2] = GreenDuty; buttons_report[3] = BlueDuty; buttons_report[4] = Temperature; buttons_report[5] = Temperature+1; buttons_report[6] = Temperature+2; buttons_report[7] = Temperature+3; USB_LoadInEP(1, &buttons_report[0], 8, USB_TOGGLE); // receive data from PC lights_report = USB_INTERFACE_0_OUT_RPT_DATA[0]; // Control input from PC RedDutyMax = USB_INTERFACE_0_OUT_RPT_DATA[1]; // Red brightness from PC GreenDutyMax = USB_INTERFACE_0_OUT_RPT_DATA[2]; // Green brightness from PC BlueDutyMax = USB_INTERFACE_0_OUT_RPT_DATA[3]; // Blue brightness from PC temp = USB_INTERFACE_0_OUT_RPT_DATA[4]; // temp = USB_INTERFACE_0_OUT_RPT_DATA[5]; // temp = USB_INTERFACE_0_OUT_RPT_DATA[6]; // temp = USB_INTERFACE_0_OUT_RPT_DATA[7]; // if(USB_Tog != (lights_report & USB_AUTO_MASK)) // USB Auto status bit toggles { // if software is running USB_Tog = (lights_report & USB_AUTO_MASK); // mask for auto bit USBTimer = 255; // reset watchdog counter } if(USBTimer) { Auto = 0; // PC is in control if(lights_report & USB_BOOT_MASK) // USB Boot status bit { // Stop everything USB_Stop(); Timer8_Stop(); PRS8_Stop(); RED_Stop(); GREEN_Stop(); BLUE_Stop(); PWM8_Stop(); PGA_Stop(); ADCINC_Stop(); M8C_DisableGInt; // Global interrupt disable USB_EnterBootloader(); } if(lights_report & USB_LED_MASK) // USB LED status bit { LedPower = 1; // turn LEDs on LedPowerTog = 1; // flag change } else { LedPower = 0; // turn LEDs on LedPowerTog = 1; // flag change } PRT2DR = Port_2_Data_SHADE; // update port2 } else { Auto = 1; // auto (software not running) RedDutyMax = RamFlashBlock.RedDuty; // reset dutycycle BlueDutyMax = RamFlashBlock.BlueDuty; GreenDutyMax = RamFlashBlock.GreenDuty; } } }
void main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */ init(); // Start usb operation with 3V //Wait for device to enumerate USB_Start(0u,USB_3V_OPERATION); while(!USB_bGetConfiguration()); //Enumeration i done, enable out endpoint for recieve data from host USB_EnableOutEP(2); ADC_StartConvert(); while(1) { //wait for data while(USB_bGetEPState(2) !=USB_OUT_BUFFER_FULL); //read received bytes count length = USB_wGetEPCount(2); //turn on LED LED_Write(~LED_Read()); //unload the out buffer USB_ReadOutEP(2, &buffer[0], length); // check for in buffer is empty while(USB_bGetEPState(1) != USB_IN_BUFFER_EMPTY); // Turn off LED // load the in buffer USB_LoadInEP(1, &buffer[0], length); while(USB_bGetEPState(1) != USB_IN_BUFFER_EMPTY); USB_LoadInEP(1, &buffer[1], length); } for(;;) { } /* while(!USB_bGetConfiguration()); //Enumeration i done, enable out endpoint for recieve data from host USB_EnableOutEP(2); while(1) { //wait for data while(USB_bGetEPState(2) !=USB_OUT_BUFFER_FULL); //read received bytes count length = USB_wGetEPCount(2); //turn on LED LED_Write(~LED_Read()); //unload the out buffer USB_ReadOutEP(2, &buffer[0], length); // check for in buffer is empty while(USB_bGetEPState(1) != USB_IN_BUFFER_EMPTY); // Turn off LED // load the in buffer USB_LoadInEP(1, &buffer[0], length); }*/ /* if( ADC_IsEndConversion(ADC_WAIT_FOR_RESULT)) { //LCD_ClearDisplay(); //LCD_PrintNumber(ADC_GetResult16()); //CyDelay(250); Pin_1_Write(~Pin_1_Read()); //buffer[count]=ADC_GetResult8(); buffer[count]=count; ++count; USB_LoadInEP(1,&buffer[0],1); if (count==64) { // load the in buffer *? //USB_LoadInEP(1, &buffer[0], 64); count=0; } } */ }