int main() { uint8 status = STS_CMD_FAIL; RGB_LED_OFF; /* Setup buffer and start EZI2C slave (SCB mode) */ EZI2C_EzI2CSetBuffer1(BUFFER_SIZE, READ_ONLY_OFFSET, ezI2cBuffer); EZI2C_Start(); CyGlobalIntEnable; /* Enable global interrupts. */ for(;;) { /* Write complete: parse packet */ if (0u != (EZI2C_EzI2CGetActivity() & EZI2C_EZI2C_STATUS_WRITE1)) { /* Check start and end of packet markers */ if ((ezI2cBuffer[PACKET_SOP_POS] == PACKET_SOP) && (ezI2cBuffer[PACKET_EOP_POS] == PACKET_EOP)) { status = ExecuteCommand(ezI2cBuffer[PACKET_CMD_POS]); } /* Update buffer with status */ ezI2cBuffer[PACKET_STS_POS] = status; status = STS_CMD_FAIL; } /* Buffer is always available to be read */ } }
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); } }
/******************************************************************************* * Function Name: void processI2C( void ) ******************************************************************************** * * Summary: * This function copies date from/to the I2C registers to local values that are * used in the rest of the firmware. The values are: * From I2C: Desired DAC Voltage, LED states (if LEDs are under baseboard control), LED control register * To I2C: Button Values, Temperature, Humidity, Ambient Light, POT Voltage *******************************************************************************/ void processI2C(void) { uint8 interruptState; /* Variable to store the status returned by CyEnterCriticalSection() */ /* Update I2C registers to/from local copy if it isn't busy */ /* Enter critical section to check if I2C bus is busy or not */ interruptState = CyEnterCriticalSection(); if(!(EZI2C_EzI2CGetActivity() & EZI2C_EZI2C_STATUS_BUSY)) { /* Get values that are written by the master */ LocData.dacVal = I2Cbuf.dacVal; LocData.ledVal = I2Cbuf.ledVal; LocData.ledControl = I2Cbuf.ledControl; capLedBase = LocData.ledControl & CAPLEDMASK; /* Send values that are updated by the slave */ I2Cbuf.buttonVal = LocData.buttonVal; I2Cbuf.temperature = LocData.temperature; I2Cbuf.humidity = LocData.humidity; I2Cbuf.illuminance = LocData.illuminance; I2Cbuf.potVal = LocData.potVal; } CyExitCriticalSection(interruptState); }