Example #1
0
/*******************************************************************************
* Function Name: HandleCapSenseSlider
********************************************************************************
* Summary:
* This function scans for finger position on CapSense slider, and if the  
* position is different, triggers separate routine for BLE notification.
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void HandleCapSenseSlider(void)
{
	/* Last read CapSense slider position value */
	static uint16 lastPosition;	
	
	/* Present slider position read by CapSense */
	uint16 sliderPosition;
		
	/* Update CapSense baseline for next reading*/
	CapSense_UpdateEnabledBaselines();	
		
	/* ADD_CODE to scan the slider widget */
	CapSense_ScanEnabledWidgets();			
	
	/* Wait for CapSense scanning to be complete. This could take about 5 ms */
	while(CapSense_IsBusy());
	
	/* ADD_CODE to read the finger position on the slider */
	sliderPosition = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS);	

	/*If finger is detected on the slider*/
	if((sliderPosition != NO_FINGER) && (sliderPosition <= SLIDER_MAX_VALUE))
	{
        /* If finger position on the slider is changed then send data as BLE 
         * notifications */
        if(sliderPosition != lastPosition)
		{
			/* Update global variable with present finger position on slider*/
			lastPosition = sliderPosition;

			SendCapSenseNotification((uint8)sliderPosition);

		}	
	}	
}
Example #2
0
File: main.c Project: spiricom/Birl
int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    EZI2C_Init();
    EZI2C_Start();
    CapSense_Start();
    CyGlobalIntEnable;
    CapSense_InitializeAllBaselines();
    EZI2C_EzI2CSetBuffer1(BUFFER_SIZE, BUFFER_SIZE, ezi2cBuffer);
    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    for(;;)
    {
           /* Update all baselines */
            CapSense_UpdateEnabledBaselines();
        
   		    /* Start scanning all enabled sensors */
    	    CapSense_ScanEnabledWidgets();   
    
            /* Wait for scanning to complete */
		
            while(CapSense_IsBusy() != 0)
            {
                ; //wait for the scan to finish
            }
            
            touched = CapSense_GetTouchCentroidPos(CapSense_TOUCHPAD0__TP, pos);
            
            
            ezi2cBuffer[0] = (uint8) pos[0];
            ezi2cBuffer[1] = (uint8) pos[1];
            ezi2cBuffer[2] = touched;
            
            //ezi2cBuffer[0] = i;
            //ezi2cBuffer[1] = i+1;
            //i++;
            XY_DATAREADY_Write(1);
            
            while (!(EZI2C_EzI2CGetActivity() & EZI2C_EZI2C_STATUS_READ1))
            {
                ; //wait for the data to be read from the master
            }
            
            XY_DATAREADY_Write(0);
            
    }
}
Example #3
0
int main()
{
    CyGlobalIntEnable;
    CapSense_Start();
    CapSense_InitializeEnabledBaselines();
    CapSense_ScanEnabledWidgets();

    for(;;)
    {
        if(!CapSense_IsBusy())
        {
            LED0_Write(!CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN));
            LED1_Write(!CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN));
            CapSense_UpdateEnabledBaselines();
            CapSense_ScanEnabledWidgets();
        }
    }
}
Example #4
0
int main()
{
    uint8 interruptState;

    CyGlobalIntEnable; /* Enable global interrupts */
    
    EZI2C_Start(); /* Start EZI2C component */
    
    /*
    * Set up communication and initialize data buffer to CapSense data structure
    * to use Tuner application
    */
    EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),
                            (uint8 *)&CapSense_dsRam);

    CapSense_Start(); /* Initialize component */

    BleHandler_Init();
    Tuner_Init(BleHandler_RefreshBuffer, BleHandler_SendBuffer);

    CapSense_ScanAllWidgets(); /* Scan all widgets */

    for(;;)
    {
        /* Do this only when a scan is done */
        interruptState = CyEnterCriticalSection();
        if(CapSense_NOT_BUSY == CapSense_IsBusy())
        {
            CyExitCriticalSection(interruptState);
            CapSense_ProcessAllWidgets(); /* Process all widgets */
            Tuner_RunTuner();

            if (CapSense_IsAnyWidgetActive()) /* Scan result verification */
            {
                /* add custom tasks to execute when touch detected */
            }
            CapSense_ScanAllWidgets(); /* Start next scan */
        }
        CySysPmSleep(); /* Sleep until scan is finished */
        CyExitCriticalSection(interruptState);
    }
}
/*******************************************************************************
* Function Name: void processCapsense( void )
********************************************************************************
*
* Summary:
*  This function steps through each capSense sensor one by one and captures its state.
*
*  For the humidity and humidity reference capacitors, the raw counts are stored 
*  and then the humidity is calculated.
*******************************************************************************/
void processCapSense(void)
{
    static uint8  state = B0;               /* CapSense sensor state machine to cycle through sensors */
    static uint16 humidityRawCounts;        /* Raw count from CapSense Component for the humidity sensor */
    static uint16 humidityRefRawCounts;     /* Raw count from CapSense Component for the Reference capacitor */
    static uint8  buttonValPrev = 0x00;     /* Previous CapSense button state */
    
    if(!CapSense_IsBusy())
    {
        switch(state) {
            case B0: /* Process Button 0, Scan Button 1 */
                CapSense_ProcessWidget(CapSense_BUTTON0_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED0_Write(LEDON);
                        
                    }      
                    LocData.buttonVal |= (BVAL_B0_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED0_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B0_MASK);
                }
                CapSense_SetupWidget(CapSense_BUTTON1_WDGT_ID);
                state++;
                break;
            case B1: /* Process Button 1, Scan Button 2 */
                CapSense_ProcessWidget(CapSense_BUTTON1_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED1_Write(LEDON);
                    }
                    LocData.buttonVal |= (BVAL_B1_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED1_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B1_MASK);
                }
                
                CapSense_SetupWidget(CapSense_BUTTON2_WDGT_ID);
                state++;                
                break;
            case B2: /* Process Button 2, Scan Button 3 */
                CapSense_ProcessWidget(CapSense_BUTTON2_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON2_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED2_Write(LEDON);
                    }
                    LocData.buttonVal |= (BVAL_B2_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED2_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B2_MASK);
                }
                CapSense_SetupWidget(CapSense_BUTTON3_WDGT_ID);
                state++;
                break;
            case B3: /* Process Button 3, Scan Proximity */
                CapSense_ProcessWidget(CapSense_BUTTON3_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_BUTTON3_WDGT_ID))
                {
                    if(capLedBase == false)
                    {
                        CBLED3_Write(LEDON);
                    }
                    LocData.buttonVal |= (BVAL_B3_MASK);
                }
                else
                {
                    if(capLedBase == false)
                    {
                        CBLED3_Write(LEDOFF);
                    }
                    LocData.buttonVal &= (~BVAL_B3_MASK);
                }
                
                /* Now that butons have all been processed, set interrupt state */
                if((LocData.buttonVal & BVAL_ALLB_MASK) != buttonValPrev) /* At least 1 CapSense button state changed */
                {
                    CSINTR_Write(1);
                    buttonValPrev = (LocData.buttonVal & BVAL_ALLB_MASK);
                }
                
                /* Setup Proximity scan */
                CapSense_SetupWidget(CapSense_PROXIMITY0_WDGT_ID);
                state++;
                break;      
            case PROX: /* Process Proximity, Scan Humidity */
                CapSense_ProcessWidget(CapSense_PROXIMITY0_WDGT_ID);
                if(CapSense_IsWidgetActive(CapSense_PROXIMITY0_WDGT_ID))
                {
                    PROXLED_Write(LEDON);
                    LocData.buttonVal |= (BVAL_PROX_MASK);
                }
                else
                {
                    PROXLED_Write(LEDOFF);
                    LocData.buttonVal &= (~BVAL_PROX_MASK);
                }
                CapSense_SetupWidget(CapSense_HUMIDITY_WDGT_ID);
                state++;
                break;
            case HUM: /* Process Humidity, Scan Button 0  and go back to start of loop */                
                humidityRawCounts =    CapSense_HUMIDITY_SNS0_RAW0_VALUE; 
                humidityRefRawCounts = CapSense_HUMIDITY_SNS1_RAW0_VALUE;
                /* Convert raw counts to capacitance */
                capacitance = CalculateCapacitance(humidityRawCounts, humidityRefRawCounts);
                /* Calculate humidity */
                humidity = CalculateHumidity(capacitance); 
                LocData.humidity = ((float32)(humidity))/10.0;
                CapSense_SetupWidget(CapSense_BUTTON0_WDGT_ID);
                state=0;
                break;
        } /* End of CapSense Switch statement */
        #ifdef ENABLE_TUNER
        CapSense_RunTuner();
        #endif
        CapSense_Scan();
    }
}
Example #6
0
int main()
{
    
    CyDelay(200);

    uint16 Counts=0;            // ADC value (0 to 4095) right shifted by 6 which gives
                                // us 0 to 63 to be used to simulate actual temperature
    uint16 TempSet = 2400;      // Temperature set default value (left justified) 24 deg
    uint16 DisplayTemp = 0;     // The combined sum of desired temp and actual temp
    
    uint16 bleTemp = 0;         // Temperature sent to BLE module
    uint16 bleTempSet = 0;      // Temperature set value sent to BLE module
    
    uint8 button0 = 0;      // Declare CapSense button name button0
    uint8 button1 = 0;      // Declare CapSense button name button1
    uint8 firstpress0 = 0;  // Detects a transition of button1 from 0 to 1
    uint8 firstpress1 = 0;  // Detects a transition of button1 from 0 to 1
    
    int buttonPrevious = 1;

    CyGlobalIntEnable;
    
    ADC_Start();        // Starts the ADC component
    ADC_StartConvert(); // The ADC conversion process begins
    LCD_Start();        // Start the LCD component 
    
    CapSense_Start();
    CapSense_ScanAllWidgets();
    
    LCD_WritePixel(LCD_COLON, TRUE);
       
    ResetTimer_Start();
    sendBootload_StartEx(StartBootload_ISR);
    
    BLEIOT_Start();
    
    /* Initialize temperuature values out of range so that main loop update is triggered */
    BLEIOT_updateTemperature(10000);
    BLEIOT_updatePot(100);    
       
    for(;;)
    {
        
        /* Turn BLE on/off with button press */
        if(buttonPrevious && (Button_Read() == 0))
        {          
            if(BLEIOT_remote.bleState == BLEIOT_BLEOFF)
            {
                BLEIOT_updateBleState(BLEIOT_BLEON);  
            }
            else
            {
                BLEIOT_updateBleState(BLEIOT_BLEOFF);
            }
            
        }
        buttonPrevious = Button_Read();
           
        /* Local Thermostat Operation */
        /* ADC */
        // Read the ADC, shift right by 6 (i.e. divide by 64)
        // and store result in Counts
        Counts = ADC_GetResult16(POT_CHAN);
        Counts = Counts >> 6;

        /* CapSense */
        if (!CapSense_IsBusy())
        {
            // Check Button states and store
            CapSense_ProcessAllWidgets();
            if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
            {
                button0 = 1;
            }
            else
            {
                button0 = 0;
            }
            if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID))
            {
                button1 = 1;
            }
            else
            {
                button1 = 0;
            }
            
            // Light LEDs Based on Capsense buttons
            LED_CS0_Write(~button0);
            LED_CS1_Write(~button1);
            
            // Check for button touchdown transitions
            if (button0 == 1)
            {
                if(firstpress0 == 0) // Touchdown event
                {
                    firstpress0 = 1; // Remember button0 was pressed
                    TempSet = TempSet + 100; // Increment Temp by 1 deg
                }
            }
            else
            {
                firstpress0 = 0; // Button released
            }
            if (button1 == 1)
            {
                if(firstpress1 == 0) // Touchdown event
                {
                    firstpress1 = 1; // Remember button0 was pressed                   
                    TempSet = TempSet - 100; // Decrement Temp by 1 deg
                }
            }
            else
            {
                firstpress1 = 0; // Button released
            }
                 
            CapSense_ScanAllWidgets();  // Start Next Scan
        }
     
        /* Warning LEDs and Buzzer */
        if((Counts * 100) < TempSet)    // Temperature Cold
        {
            LED_Blue_Write(LED_ON);     // Blue On
            LED_Green_Write(LED_OFF);   // Green Off
            LED_Red_Write(LED_OFF);     // Red Off
            PWM_Stop(); // Buzzer Off
        }
        else if ((Counts * 100) <= (TempSet + 500))  // Temperature OK
        {
            LED_Blue_Write(LED_OFF);    // Blue Off
            LED_Green_Write(LED_ON);    // Green On
            LED_Red_Write(LED_OFF);     // Red Off
            PWM_Stop();// Buzzer Off
        }
        else // Tempearture too high
        {
            LED_Blue_Write(LED_OFF);    // Blue Off
            LED_Green_Write(LED_OFF);   // Green Off
            LED_Red_Write(LED_ON);      // Red On
            PWM_Start(); // Buzzer On
        }
    
        /* LCD Display */
        DisplayTemp = TempSet + Counts;
        LCD_Write7SegNumber_0(DisplayTemp, POS, MODE);        
    
        
        /* BLE operation - do only if BLE is not off */    
        if(BLEIOT_remote.bleState != BLEIOT_BLEOFF)
        {
            /* Send new temperature data to the BLE module */
            if(bleTemp != Counts)
            {
                bleTemp = Counts;
                BLEIOT_updatePot(bleTemp);
            }
            if(bleTempSet != TempSet)
            {
                bleTempSet = TempSet;
                /* Scale set temperature down to whole number of  degrees */
                BLEIOT_updateTemperature(TempSet / 100); 
            }     
                       
            /* Get new data from the BLE module */
            /* LED0 is used for temperature changes */
            if(BLEIOT_getDirtyFlags() & BLEIOT_FLAG_LED0)
            {
                /* Update local variable copy and clear dirty flag */
                BLEIOT_updateLed0(BLEIOT_remote.led0); 
                if(BLEIOT_local.led0 == UP)
                {
                    TempSet = TempSet + 100; // Increment Temp by 1 deg
                }
                else if (BLEIOT_local.led0 == DOWN)
                {
                    TempSet = TempSet - 100; // Decrement Temp by 1 deg
                }
            }
        } /* End of !BLEOFF state operations */
    } /* End of superloop */
} /* End of main */
/*******************************************************************************
* Function Name: SMS_LIB_IsBusy
********************************************************************************
*
* Summary:
*  Wrapper to CapSense_IsBusy function.
*  
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
uint8 SMS_LIB_IsBusy(void) 
{
    return CapSense_IsBusy();
}
Example #8
0
/*******************************************************************************
* Function Name: ServiceUSB
********************************************************************************
* Summary: This routine performs tasks that should be done soon after USB 
*          enumeration is completed (configure DMA, initialize state machine etc).
*          When the USB configuration is changed, this routine reinitializes all
*          the USB endpoints as required by the application.       
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void ServiceUSB(void)
{
    CYBIT macPC_flag=FALSE;
	if(USB_INTERFACE_INACTIVE == USBDeviceState)
    {
        USBDeviceState = USB_INIT_AFTER_ENUMERATION_REQUIRED;
    }
	
	/* Initialization sequence for every USB host enumeration event */
    if(USBDeviceState == USB_INIT_AFTER_ENUMERATION_REQUIRED)
    {
        uint16 index = 0;
        
        USBDeviceState = USB_INIT_AFTER_ENUMERATION_COMPLETED;
        SetAppleDeviceAudioSource(AUDIO_SOURCE_DIGITAL);
        macPC_flag = IsMacPCConnected();
        
        #if(USBFS_EP_MM == USBFS__EP_DMAAUTO)
            /* USER_CODE: [Audio Buffers] Add a separate for loop if the playback and recording audio buffer size are 
             * not equal */
            for(index=0; index< OUT_AUDIOMAXPKT; index++)
            {
                #ifndef ENABLE_DIGITAL_AUDIO_OUT_ONLY
                inRam[index] = 0;
                #endif
                #ifndef ENABLE_DIGITAL_AUDIO_IN_ONLY
                outRam[index] = 0;
                #endif
            }
            #ifndef ENABLE_DIGITAL_AUDIO_OUT_ONLY
            inCnt = IN_AUDIOMAXPKT;
            #endif
        #endif
        
        #ifdef CDC_ENABLED
        USBUARTStart(); /* Initializes the USB UART interface */
        #endif
                
        /* Configure the HID input endpoint buffer for Mac/PC playlist control */
        if(macPC_flag)
        {
            USBFS_LoadInEP(MAC_PC_HID_CONTROL_ENDPOINT, (uint8 *)&playlistControlReport, sizeof(playlistControlReport));
            
            #ifdef PHONE_CONTROL_ENABLED
            USBFS_ReadOutEP(MAC_PC_HID_OUT_ENDPOINT, &hidOutReport, sizeof(hidOutReport));
            USBFS_EnableOutEP(MAC_PC_HID_OUT_ENDPOINT);
            #endif
        }
        
        /* If Aux is not currently configured, then switch to digital audio mode */
        if(IS_AUX_NOT_SELECTED())
        {
            ConfigureDigitalAudioDMA();
        }
        else
        {
            #ifdef LCD_MODULE_ENABLED
            /* Else Display Aux Configured message on the LCD */
            LCD2LineDisplay("Analog Loopback ",
                            "                ");
            #endif                
        }
        
        /* USER_CODE: [USB enumeration] placeholder for initializing custom user code after the USB host enumerates the
         * accessory. This routine will be called once per accessory connection after the host issues SET_CONFIGURATION
         * request */
    }
    
    #ifdef MIDI_ENABLED
    if (midiEPInitialized == FALSE || usbReset)
    {
        /* Initialize MIDI only when a valid USB host is connected */
        if ((IsUSBConfigured() && IsMacPCConnected()))
        {
            USBFS_MIDI_EP_Init();
            
            /* USB Component internally sets the priority of the UART TX and RX ISRs to 4 and 2 respectively, change the
             * interrupt priority in the application code to match the system interrupt setup */
             
            CyIntSetPriority(MIDI1_UART_TX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_SIX);
            CyIntSetPriority(MIDI1_UART_RX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_FIVE);
            #if (USBFS_MIDI_EXT_MODE >= USBFS_TWO_EXT_INTRF)
            CyIntSetPriority(MIDI2_UART_TX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_SIX);
            CyIntSetPriority(MIDI2_UART_RX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_FIVE);
            #endif
            midiEPInitialized = TRUE;
            usbReset = 0;
        }
    }
    
    if(USBFS_midiInPointer%USBFS_EVENT_LENGTH == 0 && USBFS_midiInPointer!=0)
    {
        if(midiInWaitTimer == 0)
        {
            midiInWaitTimer = MIDI_IN_EP_WAIT_TIME;
            USBFS_MIDI_IN_EP_Service();
        }
    }
    else
    {
        midiInWaitTimer = MIDI_IN_EP_WAIT_TIME;
    }
    #endif
        
    /* USBFS_IsConfigurationChanged() is a clear on read status update therefore, only one read of 
     * USBFS_IsConfigurationChanged() should ever exist in user code */
    if(USBFS_IsConfigurationChanged())
    {
        macPC_flag = IsMacPCConnected();
		#ifndef ENABLE_DIGITAL_AUDIO_IN_ONLY    
        
        /* Get Alternate setting */
        altSetting[AUDIO_OUT_INTERFACE_INDEX] = (macPC_flag? USBFS_GetInterfaceSetting(1):USBFS_GetInterfaceSetting(2)); 
        
        /* ByteSwap control register bit is set to 1 if alt setting 2 is selected so that  
         * Byte swap digital logic processes data as 16 bits. ByteSwap control register is set to 0 
         * if alt setting 1 is selected and byte swap processes data as 24 bits */
        if (altSetting[AUDIO_OUT_INTERFACE_INDEX]==ALT_SETTING_ACTIVE_24_BIT)
        {
            ByteSwap_Tx_CONTROL_REG = ByteSwap_Tx_CONTROL_REG & (~ByteSwap_Tx_RES_CTRL_16);  
        }
        else if (altSetting[AUDIO_OUT_INTERFACE_INDEX]==ALT_SETTING_ACTIVE_16_BIT)
        {
            ByteSwap_Tx_CONTROL_REG = ByteSwap_Tx_CONTROL_REG | ByteSwap_Tx_RES_CTRL_16;            
        }
        
        /* Arming the audio out EP if it is not zero bandwidth alt setting */
        if (altSetting[AUDIO_OUT_INTERFACE_INDEX]!= ALT_SETTING_ZERO_BANDWIDTH && 
            (CY_GET_REG8(USBFS_SIE_EP1_CR0_PTR + ((AUDIO_OUT_ENDPOINT - USBFS_EP1) << USBFS_EPX_CNTX_ADDR_SHIFT)) & USBFS_MODE_MASK) 
                                                                                    == USBFS_MODE_NAK_IN_OUT)
        {
            /* Init DMA configurations for audio OUT EP */
            USBFS_ReadOutEP(AUDIO_OUT_ENDPOINT, &outRam[0], OUT_AUDIOMAXPKT);
            USBFS_EnableOutEP(AUDIO_OUT_ENDPOINT);
        }
        #endif
        
        #ifndef ENABLE_DIGITAL_AUDIO_OUT_ONLY
            #ifndef ENABLE_DIGITAL_AUDIO_IN_ONLY 
            if(altSetting[AUDIO_IN_INTERFACE_INDEX] != (macPC_flag? USBFS_GetInterfaceSetting(2):USBFS_GetInterfaceSetting(3)))
        {
                  altSetting[AUDIO_IN_INTERFACE_INDEX] = (macPC_flag? USBFS_GetInterfaceSetting(2):USBFS_GetInterfaceSetting(3));
            #else
            if(altSetting[AUDIO_IN_INTERFACE_INDEX] != (macPC_flag? USBFS_GetInterfaceSetting(1):USBFS_GetInterfaceSetting(2)))
        {
                  altSetting[AUDIO_IN_INTERFACE_INDEX] = (macPC_flag? USBFS_GetInterfaceSetting(1):USBFS_GetInterfaceSetting(2));
            #endif
            
            /* Setting the ByteSwap control register bit to 0 regardless of alt setting is selected. Because audio in 
            *  interface both the alternate settings alt setting1 and alt setting 2 both use 3 byte subframe size. */            
            ByteSwap_Rx_CONTROL_REG = ByteSwap_Rx_CONTROL_REG & (~ByteSwap_Rx_RES_CTRL_16); 
            
            /* Arming the audio in EP if it is not zero bandwidth alt setting */
            if (altSetting[AUDIO_IN_INTERFACE_INDEX]!= ALT_SETTING_ZERO_BANDWIDTH &&
                (CY_GET_REG8(USBFS_SIE_EP1_CR0_PTR + ((AUDIO_IN_ENDPOINT - USBFS_EP1) << USBFS_EPX_CNTX_ADDR_SHIFT)) & USBFS_MODE_MASK) 
                                                                                        == USBFS_MODE_NAK_IN_OUT)
            {
                /* Init DMA configurations for audio IN EP */  
                inCnt = IN_AUDIOMAXPKT;
                USBFS_LoadInEP(AUDIO_IN_ENDPOINT, &inRam[0], inCnt);
                /* Pre-arm first audio IN request */
                USBFS_LoadInEP(AUDIO_IN_ENDPOINT, USBFS_NULL, inCnt);
            }
        }
        #endif
        
        /* USER_CODE: [USB configuration changed] Placeholder for adding additional USB endpoint initialization code 
         * when the host issues either a SET_INTERFACE or SET_CONFIGURATION request to the accessory. After receiving
         * a SET_INTERFACE request from the host, the endpoint belonging to the alternate setting being configured
         * by the USB host is reset and must be reinitialized here for proper operation of the USB block */
    }
}

/*******************************************************************************
* Function Name: ServiceUSBSuspend
********************************************************************************
* Summary:
*       This function handles USB suspend event from USB host and forces PSoC 3 
*       to enter low power mode. Once the USB resume event is detected, PSoC3 
*       wakes up and starts operating in normal mode.
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
#ifdef HANDLE_USB_SUSPEND
void ServiceUSBSuspend(void)
{
    if(!IsMacPCConnected() || ! USBFS_initVar)
    {
      return;
    }
  
    /* Check if the host is active */
    if(USBFS_bCheckActivity() != 0 ) 
    {
      usbActivityCounter = 0;
    } 
    else 
    {
      usbActivityCounter++;
    }
        
    /* USB Suspend event is lack of greater than 3 consecutive SOF's */
    if(usbActivityCounter > USB_SUSPEND_TIME_TICKS )
    {
        /* The debounce delay is taken care by increasing the suspend time to 40ms (5 * 8ms) */                   
        if(IsMacPCConnected() && IsUSBConfigured()) 
        {  
            /* USER_CODE: [USB suspend] Placeholder for configuring ALL the additional components added by the user in 
             * sleep mode before calling USB suspend/PSoC 3 sleep API */
             
            #ifdef LCD_MODULE_ENABLED
              LCD_Position(0,0);
              LCD_PrintString("  USB Suspend   ");
            #endif
            
            /* If the accessory is not in low power mode, enter low power mode on seeing a USB suspend */
            if(!lowPowerIdle) 
            {
                lowPowerIdle = TRUE;
                StopAudioComponents();             /* Changes to 24 MHz IMO for USB */                        
                StopAnalogAudioComponents();       /* Turn OFF Analog path for Audio-In/iPod Analog */
            }
            
			if(!midiPowerIdle)
            {
                if(!lowPowerIdle)
                {
                    StopAudioComponents();        /* Changes to 24 MHz IMO for USB */
                }
                CyPins_SetPin(PSOC_MIDI_PWR_0);   /* Turn off the MIDI I/O hardware */
                midiPowerIdle = TRUE;             /* MIDI low power mode enabled */
            }
			
            CyPins_ClearPin(PSOC_CODEC_PWR_0);     /* Turn off the regulator to reduce suspend mode current */     
   
            USBFS_Suspend();
			
			I2C_Master_Sleep();                          /* Configure I2C master block in sleep mode */ 
           			
            #ifdef CAPSENSE_ENABLED
            while(CapSense_IsBusy());              /* Wait for current scan to complete */
            CapSense_Sleep();
            #endif
            
            #ifdef MIDI_ENABLED
            MIDI1_UART_Sleep();
			#if (USBFS_MIDI_EXT_MODE >= USBFS_TWO_EXT_INTRF)
            MIDI2_UART_Sleep();
			#endif
            #endif
            
            CyPmSaveClocks();            
            CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_PICU); /* PSoC 3 is in sleep mode */
            CyPmRestoreClocks();
            USBFS_Resume();
			I2C_Master_Wakeup();
			
            #ifdef CAPSENSE_ENABLED
            CapSense_Wakeup();
            CapSense_IntClock_SetSource(CYCLK_SRC_SEL_IMO);
            #endif
            
            #ifdef MIDI_ENABLED
            MIDI1_UART_Wakeup();
			#if (USBFS_MIDI_EXT_MODE >= USBFS_TWO_EXT_INTRF)
            MIDI2_UART_Wakeup();                              
			#endif
            #endif
            
            CyPins_SetPin(PSOC_CODEC_PWR_0);        /* Turn ON the CODEC regulator after wake up */            
           
            #ifdef WINDOWS7_WORKAROUND
            if(USBFS_GetConfiguration() != 0)
            {
                USBFS_configurationChanged = USBFS_TRUE;
                USBFS_Config(USBFS_FALSE);
            }
            #endif
     
            #ifdef LCD_MODULE_ENABLED
                LCD_Position(0,0);
                LCD_PrintString("Mac/PC Interface");
            #endif
            
            /* USER_CODE: [USB wakeup] Placeholder for re-configuring ALL the additional components added by the user in 
             * wakeup mode after calling USB wakeup */
        }
        usbActivityCounter = 0;
		/* After coming out of USB suspend, MIDI end point should be re-initialized */
		midiEPInitialized = 0;
    }
}
#endif

/*******************************************************************************
* Function Name: HandlePCMacUSBInterface
********************************************************************************
* Summary: Checks if PC/Mac is connected/disconnected and start the USB component
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void HandlePCMacUSBInterface(void)
{
    /* If Aux mode is enabled, then Mac/PC connection disconnection is handled only when the system is not in 
     * aux In mode. For self powered case, Apple device connection is also checked before starting the Mac/PC 
	 * interface */
    if(IS_AUX_NOT_SELECTED() && !USBFS_initVar && IsMacPCConnected())
    {  
        /* Switch the PSoC USB D+ and D- lines to USB Mini B */
        CyPins_ClearPin(PSOC_USB_SEL_0);
        
        /* Start the USB component when PC/Mac is connected */
        USBFS_Start(PC_MAC_AUDIO_WITH_VOLUME_DEVICE, USBFS_DWR_VDDD_OPERATION);
        USBDeviceState = USB_INIT_AFTER_ENUMERATION_REQUIRED;
        
        #ifdef LCD_MODULE_ENABLED
        if(IS_AUX_NOT_SELECTED())
        {
            LCD2LineDisplay("Mac/PC Interface",
                            "                ");
        }                
        #endif
        
        #ifdef ENABLE_VOLUME_CONTROL
        currentLCDVolume--; /* dirty the LCD volume and mute update flag to update volume and mute info on the LCD */
        currentLCDMute--;
        #endif

        usbMiniBActive = TRUE;
        
        /* USER_CODE: [Mac/PC connection] Placeholder for initializing components or external peripherals when the
         * accessory is plugged into Mac/PC (USB VBus = High) */
    }
	
	/* Check for PC/Mac USB Audio device disconnection in self powered mode.
	 *  In device powered mode project, no need of checking disconnection event as power is shut off 
	 *  as soon as USB cable is disconnected from USB mini connector. */
	else if(usbMiniBActive && (USBFS_bGetConfiguration() || USBDeviceState == USB_INIT_AFTER_ENUMERATION_REQUIRED))
    {
        /* If VBUS voltage from mini B is now gone and was previous present then stop USB interface */
        if(!IsMacPCConnected())
        {
            if(USBFS_initVar)  
        	{
				USBFS_Stop();
			}	
                    
            CyPins_SetPin(PSOC_USB_SEL_0); /* Switch the PSoC USB D+ and D- lines back to Apple device */        
            
            /* If Aux was not configured when PC is unplugged, then switch off CODEC */
            if(!auxConfigured)
            {
                CyPins_ClearPin(PSOC_CODEC_RST_0); /* Hold CODEC in reset */
				codecInit = FALSE;
            }
            usbMiniBActive = FALSE;
            
            /* USER_CODE: [Mac/PC disconnection] Placeholder for shutting down components or external peripherals when 
             * the accessory is disconnected from Mac/PC (USB VBus transitioned from High to Low) */
        }
    }
}

/*******************************************************************************
* Function Name: EnableNAKBulkIN
********************************************************************************
* Summary: Enables the NAK interrupt on a USB endpoint 
*
* Parameters:
*  Endpoint number for which NAK interrupt is to be enabled
*
* Return:
*  void
*
*******************************************************************************/
void EnableNAKBulkIN(uint8 bEPNumber)
{
    uint8 index = (bEPNumber - USBFS_EP1) << USBFS_EPX_CNTX_ADDR_SHIFT;
    
    if((CY_GET_REG8(&USBFS_SIE_EP1_CR0_PTR[index]) & USBFS_MODE_MASK) != USBFS_MODE_ACK_IN)
	{
    	CY_SET_REG8(&USBFS_SIE_EP1_CR0_PTR[index], 
                                    CY_GET_REG8(&USBFS_SIE_EP1_CR0_PTR[index]) | NAK_IN_INTERRUPT_ENABLE_MASK);
	}								
}
Example #9
0
void main()
{
	CYGlobalIntEnable; /* Enable global interrupts */
	
	ADC_DelSig_1_Start();/* Configure and power up ADC */
	LCD_Char_1_Start(); /* Initialize and clear the LCD */
	
	/* Move the cursor to Row 0 Column 0 */
	LCD_Char_1_Position(ROW_0,COLUMN_0); 
	/* Print Label for the pot voltage raw count */
	LCD_Char_1_PrintString("TEMP NOW:    C");
	
	LCD_Char_1_Position(ROW_1,COLUMN_0);
	LCD_Char_1_PrintString("TEMP SET:    C");
	
	ADC_DelSig_1_StartConvert(); /* Force ADC to initiate a conversion */
	
	/* Start capsense and initialize baselines and enable scan */
	CapSense_Start();
	CapSense_InitializeAllBaselines();
	CapSense_ScanEnabledWidgets();

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
	//Start the pwm;
	PWM_1_Start();
    for(;;)
    {
		/* If scanning is completed update the baseline count and check if sensor is active */
		while(CapSense_IsBusy());
		
		/* Update baseline for all the sensors */
		CapSense_UpdateEnabledBaselines();
		CapSense_ScanEnabledWidgets();
		
		/* Test if button widget is active */
		stateB_1 = CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN);
		stateB_2 = CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN);
	
        /* Wait for end of conversion */
		ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT);
		/* Get converted result */
		voltageRawCount = ADC_DelSig_1_GetResult16();
		//Change voltageRawCount to Temperature;
		temp = voltageRawCount / 3.870 * 0.1017 + 0.5;
		cold = (9999 - (temp > temp_set ? temp - temp_set : 0) * 50);
		if(cold < 1000)
			cold = 1000;
		if(cold > 9999)
			cold = 9999;
		//Change the pwm;
		PWM_1_WriteCompare(cold);
		/* Set range limit */
		if (temp > 0x7FFF)
		{
			temp = 0;
		}
		else
		{
		/* Continue on */
		}
		if(show < 10)
		{
			show++;
		}
		else
		{
			show = 0;
			UpdateDisplay(temp, 0); /* Print result on LCD */
			UpdateButtonState(stateB_1, stateB_2);
		}
    }
}