/*******************************************************************************
* Function Name: int  main( void )
********************************************************************************/
int main(void)
{
    uint32  i;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    EZI2C_Start();
    #ifdef ENABLE_TUNER
    EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),(uint8 *)&CapSense_dsRam);        
    #else
    EZI2C_EzI2CSetBuffer1(sizeof(I2Cbuf), RW, (void *) &I2Cbuf);     
    #endif   
    
    SmartIO_Start();    
    VDAC_Start();
    PVref_ALS_Start();
    Opamp_ALS1_Start();
    Opamp_ALS2_Start();
    PVref_Therm_Start();
    Opamp_Therm_Start();    
    ADC_Start();
    ADC_IRQ_Enable();
    
    CapSense_Start();   
    /* Over-ride IDAC values for buttons but keep auto for Prox and Humidity */
    CapSense_BUTTON0_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON0_SNS0_IDAC_COMP0_VALUE =    6u;
    CapSense_BUTTON1_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON1_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON2_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON2_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON3_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON3_SNS0_IDAC_COMP0_VALUE =    8u;
    /* Setup first widget and run the scan */    
    CapSense_SetupWidget(CapSense_BUTTON0_WDGT_ID);
    CapSense_Scan();      
    
    /* Start SysTick Timer to give a 1ms interrupt */
    CySysTickStart();
    /* Find unused callback slot and assign the callback. */
    for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
    {
        if (CySysTickGetCallback(i) == NULL)
        {
            /* Set callback */
            CySysTickSetCallback(i, SysTickISRCallback);
            break;
        }
    }
    
    /* Initialize I2C and local data registers to 0's */
    I2Cbuf.dacVal = 0.0;
    I2Cbuf.ledVal = 0x00;
    I2Cbuf.ledControl = 0x00;
    I2Cbuf.buttonVal = 0x00;
    I2Cbuf.temperature = 0.0;
    I2Cbuf.humidity = 0.0;
    I2Cbuf.illuminance = 0.0;
    I2Cbuf.potVal = 0.0;
    
    LocData.dacVal = 0.0;
    LocData.ledVal = 0x00;
    LocData.ledControl = 0x00;
    LocData.buttonVal = 0x00;
    LocData.temperature = 0.0;
    LocData.humidity = 0.0;
    LocData.illuminance = 0.0;
    LocData.potVal = 0.0;
    
    for(;;)
    {
        processButtons();  /* Mechanical buttons and bootloader entry */
        processCapSense(); /* CapSense Scanning */
        processDAC();      /* VDAC output voltage setting */
        processADC();      /* Process ADC results after each scan completes */
        processI2C();      /* Copy date between I2C registers and local operating registers */
    }
} /* End of main */
示例#2
0
int main()
{
    uint8 loop;  
    	/* *** Start SPI bus. *** */
    SPI_Start();    
    SPI_SS_Write(1);  
    /* *** Turn off leds at startup. *** */
    Led_Red_Write(1);
    Led_Green_Write(1);
    Led_Blue_Write(1);
    
    /* *** Start serial port. *** */
    UART_Start();
    UART_PutString("\nPSoC RFM69 Test... PSoC 5LP...\n");
    
     
    
    /* *** Blink Red Led two times before starting RFM69 module. * ***/
    Led_Red_Write(0); CyDelay(250); Led_Red_Write(1); CyDelay(250);
    Led_Red_Write(0); CyDelay(250); Led_Red_Write(1); CyDelay(250);
    
    /* *** Start RFM69 module. Configure it. If the module is not found, program gets locked. 
           And red led gets turned on. If can find RFM module, then turn on green led. *** */
    UART_PutString("Looking for RFM69 module... ");
    
	if (RFM69_Start() != 1) 
    { 
        UART_PutString("FAILED\n\n");
        Led_Red_Write(0);
        while (1) {}; 
        
    }
    else 
    {
        UART_PutString("OK\n\n");
        Led_Green_Write(1);   
    }
    
    /* If testing with interrupts. But disabled until entering RX mode. */
    #ifdef TEST_USING_INTERRUPTS
        
        RFM_isr_StartEx(RFM69_IsrHandler);
        
    #endif    
    
    /* Start SysTick.
       When compiled for "MASTER" this is used to control timeout while in reception state. */
    CySysTickStart();   // interrupt every 1ms.
    
    /* Find unused callback slot. */
    for (loop = 0; loop < CY_SYS_SYST_NUM_OF_CALLBACKS; ++loop)
    {
        if (CySysTickGetCallback(loop) == NULL)
        {
            /* Set callback */
            CySysTickSetCallback(loop, SysTickIsrHandler);
            break;
        }
    }
    
    /* ----------------------------------------- */
    /* Configuration depending on node type.     */
    #ifdef COMPILE_FOR_MASTER
        Config_ForMaster();
    #endif

    #if defined COMPILE_FOR_SLAVE_1 || defined COMPILE_FOR_SLAVE_2
        Config_ForSlave();
    #endif
    /* ----------------------------------------- */    
    
    /* Uncomment next line and adjust params if you want to change bitrate at runtime. */
    RFM69_SetBitrateCls(BITRATE_MSB_9600, BITRATE_LSB_9600);
    
    /* If testing using encryption, change encryption mode and key at runtime. */
    #ifdef TEST_WITH_ENCRYPTION
        RFM69_Encryption(1, encryptionkey);
    #endif
   
    CyGlobalIntEnable; /* Enable global interrupts. */

    for(;;)
    {
        
        /* ----------------------------------------- */ 
        /* Call main loop depending on node type.    */
        #ifdef COMPILE_FOR_MASTER
                Loop_Master();
        #endif

        #if defined COMPILE_FOR_SLAVE_1 || defined COMPILE_FOR_SLAVE_2
                Loop_Slave();
        #endif
        /* ----------------------------------------- */

    }
}