bool enableUSBCDC()
{
  USBUART_Start(0, USBUART_3V_OPERATION);
  uint8_t delayCounter = 0;
  /* It's important that we not loop forever here, or we'll never leave in
   * cases where the device isn't plugged into a PC. We do, however, want to
   * provide enough time for the PC to do its thing. */  
  while(USBUART_GetConfiguration() == 0)
  {  
    CyDelay(100);
    delayCounter++;
    if (delayCounter > 20)
    {
      return false;
    }
  }
  USBUART_CDC_Init();
  return true;
}
示例#2
0
文件: uart.c 项目: nadavofir/IGVC2013
void InitializeUART(void){
	 /* Start USBFS Operation with 5V operation */
    USBUART_Start(0, USBUART_5V_OPERATION);
    while(!USBUART_GetConfiguration());
	USBUART_CDC_Init();
}
示例#3
0
int main()
{
    CyGlobalIntEnable; 
   
    /* Start SPI bus. */
    SDSPI_Start();

    
    // set up the USB connection
    USBUART_Start(0, USBUART_3V_OPERATION);
    while(USBUART_GetConfiguration() == 0){};
    USBUART_CDC_Init();
    
     
    
    while(true) {
        
        _USBBufDataCnt = USBUART_GetCount();
        
        // when we get usb data, grab it and parse it
        if (_USBBufDataCnt != 0) {
            if (_USBBufDataCnt > 128) {
                // too much data, do something (we throw away all the data)
                while(_USBBufDataCnt > 128) {
                    USBUART_GetData(_USBRxBuffer, 128);
                    _USBBufDataCnt -= 128;
                }
                USBUART_GetData(_USBRxBuffer, _USBBufDataCnt);
            }
            else {
                USBUART_GetData(_USBRxBuffer, _USBBufDataCnt);
                bool parseRes = Parse_USBBuffer();
                
                // if we got a vailid command, figure out what it was and run it
                if (parseRes) {
                    if (!strcmp(_CmdBuf, "list")) {
                        List_Dir();
                    }
                    else if (!strcmp(_CmdBuf, "?")) {
                        Display_Help();
                    }
                    else if (!strcmp(_CmdBuf, "mount")) {
                        Mount_Disk(&_FatFs);
                    }
                    else if (!strcmp(_CmdBuf, "free")) {
                        Get_FreeSpace(&_FatFs);        
                    }
                    else if (!strcmp(_CmdBuf, "print")) {
                        Print_File(_FnameBuf);
                    }
                    else if (!strcmp(_CmdBuf, "erase")) {
                        Erase_File(_FnameBuf);   
                    }
                    else if (!strcmp(_CmdBuf, "create")) {
                        Create_File(_FnameBuf);   
                    }
                    else if (!strcmp(_CmdBuf, "append")) {
                        Append_File(_FnameBuf, _DataBuf);
                    }
                }
            }
        }
    }
}
示例#4
0
int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    //PWM_1_Start();
    PWM_1_Start();
    USBUART_Start(0,USBUART_5V_OPERATION);
    while(!USBUART_bGetConfiguration()){}
    USBUART_CDC_Init();
    
    int count = 0;
    uint8 buff[64];
    buff[0] = 0;
    
    int up_b = 0;
    int left_b = 0;
    int down_b = 0;
    int right_b = 0;
    int PWM_count = 0;
    int judge_count = 0;
    
    while(1)//main loop
    {   
        if(0 != USBUART_GetConfiguration())
        {
            
            if(0 != USBUART_DataIsReady())
            {
                count = USBUART_GetAll(buff);
                if( count != 0){
                    
                    while(0 == USBUART_CDCIsReady()){}
                    
                    PWM_1_Start();
                    PWM_2_Start();
                    PWM_3_Start();
                    PWM_4_Start();
              
                    USBUART_PutData(buff,count);
                    CyDelay(500);
                    USBUART_PutCRLF(); 
                    
                    switch(buff[0]){
                        case 48:
                            up_b = 1;
                            break;
                        case 49:
                            up_b = 0;
                            break;
                        case 50:
                            left_b = 1;
                            break;
                        case 51:
                            left_b = 0;
                            break;
                        case 52:
                            right_b = 1;
                            break;
                        case 53:
                            right_b = 0;
                            break;
                        case 54:
                            down_b = 1;
                            break;
                        case 55:
                            down_b = 0;
                            break;
                        
                        default:
                        break;
                        
                    }   
            judge_count = up_b + left_b + down_b +right_b;
               
                    
                    if(judge_count == 0){
                        PWM_count = 0;
                    }
            if(judge_count == 1){//押されているボタンの数が1つの場合
                if(PWM_count <=100){
                    PWM_count++;
                    int i = 0;
                    for(i=0;i<=100;i++){}
                }else{}
                    
                    if(up_b == 1){//上ボタン
                    
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(1);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(1);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(1);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(1);
                    }
                    if(left_b == 1)

                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(1);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(1);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(0);

                    }
                    if(right_b == 1)

                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(1);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(1);

                    }
                    if(down_b == 1)
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(0);

                    }
        }else if(judge_count == 2){//2個の場合
            if(PWM_count <=100){
                    PWM_count++;
                    int i = 0;
                    for(i=0;i<=100;i++){}
                }else{}
                
                if(up_b == 1&& left_b == 1){
                    PWM_1_WriteCompare(0);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(1);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(1);
                    PWM_4_WriteCompare(0);
                    PWM_4_direction_Write(0);
                }else if(up_b == 1&& right_b == 1){
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(1);
                    PWM_2_WriteCompare(0);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(0);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(1);
                }else if(down_b == 1&& right_b==1){
                    PWM_1_WriteCompare(0);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(0);
                    PWM_4_direction_Write(0);
                }else if(down_b == 1&& left_b == 1){
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(0);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(0);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(0);
                }
        }else{}
            
                    //if(USBUART_IsLineChanged() == USBUART_LINE_CODING_CHANGED || USBUART_IsLineChanged() == USBUART_LINE_CONTROL_CHANGED)
                    //{
                    USBUART_PutCRLF(); 
                        //CyDelay(100);
                    //}
                    if(64 == count){
                        while(0 == USBUART_CDCIsReady()){}
                        //sent zero packet
                        USBUART_PutData(NULL,0);
                    }
                    //LED_Write(0);
                 
            }
           
}
示例#5
0
int main()
{
    char freq0Disp[16], freq1Disp[16];
    char usbRx[USBUART_BUFFER_SIZE], usbTx[USBUART_BUFFER_SIZE];
    
    
    /* Initializes the LCD. */
    LCD_Start();
    LCD_Position(1u,0u);
    LCD_Position(0u,0u);
    LCD_PrintString("F1=");
    
    WaveDAC_0_Clock_Start();
    WaveDAC_1_Clock_Start();
    
    // Needed for WaveDACs to operate concurrently
    // I think this might be a bug with PSoC
    WaveDAC_0_Start();
    WaveDAC_1_Start(); 
    WaveDAC_0_Stop();
    WaveDAC_1_Stop();

    USBUART_Start(USBFS_DEVICE, USBUART_5V_OPERATION);
    USBUART_CDC_Init();
    
    CyGlobalIntEnable;

    while (1) {
        if (USBUART_IsConfigurationChanged()) {
            if (USBUART_GetConfiguration()) {
                USBUART_CDC_Init();
            }
        }
        
        if (USBUART_GetConfiguration()) {
            if (USBUART_DataIsReady()) {
                int numArgs;
                int desiredFreq, newFreq, fnGenerator;
                char mode[USBUART_BUFFER_SIZE] = {0};
                
                Serial_GetString(usbRx);
                trimString(usbRx);
                numArgs = sscanf(usbRx, "%d %s %d", &fnGenerator, mode, &desiredFreq);
                if (numArgs == 3) {
                    if (!strcmp(mode, "square")) { 
                        newFreq = changeFrequency(desiredFreq, SQUARE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "sine")) { 
                        newFreq = changeFrequency(desiredFreq, SINE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "triangle")) { 
                        newFreq = changeFrequency(desiredFreq, TRIANGLE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "sawtooth")) { 
                        newFreq = changeFrequency(desiredFreq, SAWTOOTH, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "dc")) { 
                        newFreq = changeFrequency(desiredFreq, DC, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else {
                        sprintf(usbTx, "Invalid mode: %s\r\n", mode);
                    }
                    
                    
                } else if (numArgs == 2) {
                    if (!strcmp(mode, "off")) {
                        if (fnGenerator == 0) {
                            stopWaveDac(WAVEDAC_LOW_0);
                        } else if (fnGenerator == 1) {
                            stopWaveDac(WAVEDAC_LOW_1);   
                        }
                        sprintf(usbTx, "Stopped WaveDAC %d\r\n", fnGenerator);
                    } else {
                        sprintf(usbTx, "Invalid mode: %s\r\n", mode);
                    }
                } else {
                    sprintf(usbTx, "Invalid command: %s\r\n", usbRx);
                }
                
                Serial_PutString(usbTx);
            }
        }
    }
}