void AR0330_SetHue(int32_t hue) { CyU3PDebugPrint(4, "AR0330_SetHue: %d\r\n", hue); #define SetLow(io) CyU3PGpioSetValue(io, CyFalse) #define SetHigh(io) CyU3PGpioSetValue(io, CyTrue) #define SetBit(io, value) CyU3PGpioSetValue(io, 0 != (value & 0x80)) #if 0 CyU3PReturnStatus_t status; status = CyU3PGpioSetValue(LED_DRIVER_SDI, 0 != (hue & 1)); if (CY_U3P_SUCCESS != status) { CyU3PDebugPrint(4, "AR0330_SetHue: error = %d 0x%x\r\n", status, status); } status = CyU3PGpioSetValue(LED_DRIVER_CLK, 0 != (hue & 2)); if (CY_U3P_SUCCESS != status) { CyU3PDebugPrint(4, "AR0330_SetHue: error = %d 0x%x\r\n", status, status); } status = CyU3PGpioSetValue(LED_DRIVER_ED1, 0 != (hue & 4)); if (CY_U3P_SUCCESS != status) { CyU3PDebugPrint(4, "AR0330_SetHue: error = %d 0x%x\r\n", status, status); } status = CyU3PGpioSetValue(LED_DRIVER_ED2, 0 != (hue & 8)); if (CY_U3P_SUCCESS != status) { CyU3PDebugPrint(4, "AR0330_SetHue: error = %d 0x%x\r\n", status, status); } #else // initialise SetLow(LED_DRIVER_CLK); SetHigh(LED_DRIVER_ED2); SetLow(LED_DRIVER_ED1); CyU3PThreadSleep(1); for (int i = 0; i < 8; ++i) { SetBit(LED_DRIVER_SDI, hue); hue <<= 1; // output bit big endian CyU3PBusyWait(10); //CyU3PThreadSleep(10); SetHigh(LED_DRIVER_CLK); CyU3PBusyWait(10); //CyU3PThreadSleep(10); SetLow(LED_DRIVER_CLK); } //CyU3PThreadSleep(1); CyU3PBusyWait(10); SetHigh(LED_DRIVER_ED1); //CyU3PThreadSleep(10); CyU3PBusyWait(10); SetLow(LED_DRIVER_ED1); //CyU3PThreadSleep(1); CyU3PBusyWait(10); SetLow(LED_DRIVER_ED2); #endif }
/* This function inserts a delay between successful I2C transfers to prevent false errors due to the slave being busy. */ static void SensorI2CAccessDelay(CyU3PReturnStatus_t status) { /* Add a 10us delay if the I2C operation that preceded this call was successful. */ if (status == CY_U3P_SUCCESS) { CyU3PBusyWait(2000); //change into 100us. } else //if I2C operation is not success reconfig the I2C { // CyFxUVCApplnI2CInit (); CyU3PBusyWait(1000); } }
/* * This function initializes the GPIO module. */ CyU3PReturnStatus_t CyU3PGpioInit ( CyU3PGpioClock_t *clk_p, CyU3PGpioIntrCb_t irq) { CyU3PReturnStatus_t status; if (glIsGpioActive) { return CY_U3P_ERROR_ALREADY_STARTED; } if (clk_p == NULL) { return CY_U3P_ERROR_NULL_POINTER; } /* Store the interrupt handler function pointer. */ CyU3PRegisterGpioCallBack(irq); /* If the boot firmware has left the GPIO block ON, do not reset it. */ if ((CyU3PLppGpioBlockIsOn () == CyFalse) || ((GPIO->lpp_gpio_power & CY_U3P_LPP_GPIO_ACTIVE) == 0)) { status = CyU3PGpioSetClock (clk_p); if (status != CY_U3P_SUCCESS) return status; /* Register the fact that GPIO has been started with the FX3 API library. */ status = CyU3PLppInit (CY_U3P_LPP_GPIO, CyU3PGpioInt_Handler); if (status != CY_U3P_SUCCESS) return status; /* Power the GPIO block ON, and wait for it to be active. */ GPIO->lpp_gpio_power &= ~CY_U3P_LPP_GPIO_RESETN; CyU3PBusyWait (10); GPIO->lpp_gpio_power |= CY_U3P_LPP_GPIO_RESETN; while (!(GPIO->lpp_gpio_power & CY_U3P_LPP_GPIO_ACTIVE)); } else { /* GPIO block is already ON. Just register the block with the FX3 API library. */ status = CyU3PLppInit (CY_U3P_LPP_GPIO, CyU3PGpioInt_Handler); if (status != CY_U3P_SUCCESS) return status; } /* Update the status flag. */ glIsGpioActive = CyTrue; return CY_U3P_SUCCESS; }
CyU3PReturnStatus_t CyU3PGpioDeInit ( void) { CyU3PReturnStatus_t status = CY_U3P_SUCCESS; if (!glIsGpioActive) { return CY_U3P_ERROR_NOT_STARTED; } /* Reset the reset bit */ GPIO->lpp_gpio_power &= ~(CY_U3P_LPP_GPIO_RESETN); CyU3PBusyWait (10); /* Mark the block as disabled. */ glIsGpioActive = CyFalse; /* Identify if the LPP block has to be disabled. */ status = CyU3PLppDeInit (CY_U3P_LPP_GPIO); CyU3PGpioStopClock(); return status; }
// This function inserts a delay between successful I2C transfers to // prevent false errors due to the slave being busy. static void SensorI2CAccessDelay(CyU3PReturnStatus_t status) { if (status == CY_U3P_SUCCESS) { CyU3PBusyWait(10); } }