void uxn1330_boot(uint16_t term) { // set gpios uint16_t ret; log_info ( "uxn1330 boot\n"); CyU3PGpioSimpleConfig_t gpioConfig; ret = CyU3PDeviceGpioOverride( UXN1330_VCON_EN, CyTrue ); CHECK("vcon en"); ret = CyU3PDeviceGpioOverride( UXN1330_LP_B, CyTrue ); CHECK("LP_B"); ret = CyU3PDeviceGpioOverride( UXN1330_V18_EN, CyTrue ); CHECK("v18_en"); gpioConfig.outValue = CyFalse; gpioConfig.driveLowEn = CyTrue ; gpioConfig.driveHighEn = CyTrue; gpioConfig.inputEn = CyFalse; gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR; ret = CyU3PGpioSetSimpleConfig ( UXN1330_VCON_EN, &gpioConfig ); CHECK("vcon en set"); gpioConfig.outValue = CyTrue; ret = CyU3PGpioSetSimpleConfig ( UXN1330_V18_EN, &gpioConfig ); CHECK("V18_en set"); gpioConfig.outValue = LP_B_INITIAL; ret = CyU3PGpioSetSimpleConfig ( UXN1330_LP_B, &gpioConfig ); CHECK("lp_b set"); }
/* This function initializes the USB module. */ CyU3PReturnStatus_t CyFxApplnInit (void) { CyU3POtgConfig_t otgCfg; CyU3PGpioClock_t clkCfg; CyU3PGpioSimpleConfig_t simpleCfg; CyU3PReturnStatus_t status; /* Initialize GPIO module. */ clkCfg.fastClkDiv = 2; clkCfg.slowClkDiv = 0; clkCfg.halfDiv = CyFalse; clkCfg.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2; clkCfg.clkSrc = CY_U3P_SYS_CLK; status = CyU3PGpioInit (&clkCfg, NULL); if (status != CY_U3P_SUCCESS) { return status; } /* Override GPIO 21 for VBUS control. */ status = CyU3PDeviceGpioOverride (21, CyTrue); if (status != CY_U3P_SUCCESS) { return status; } /* Configure GPIO 21 as output for VBUS control. */ simpleCfg.outValue = CY_FX_HOST_VBUS_DISABLE_VALUE; simpleCfg.driveLowEn = CyTrue; simpleCfg.driveHighEn = CyTrue; simpleCfg.inputEn = CyFalse; simpleCfg.intrMode = CY_U3P_GPIO_NO_INTR; status = CyU3PGpioSetSimpleConfig (21, &simpleCfg); if (status != CY_U3P_SUCCESS) { return status; } /* Wait until VBUS is stabilized. */ CyU3PThreadSleep (100); /* Initialize the OTG module. */ otgCfg.otgMode = CY_U3P_OTG_MODE_OTG; otgCfg.chargerMode = CY_U3P_OTG_CHARGER_DETECT_ACA_MODE; otgCfg.cb = CyFxOtgEventCb; status = CyU3POtgStart (&otgCfg); if (status != CY_U3P_SUCCESS) { return status; } /* Since VBATT or VBUS is required for OTG operation enable it. */ status = CyU3PUsbVBattEnable (CyTrue); return status; }
void CyFxGpioInit (void) { CyU3PGpioClock_t gpioClock; CyU3PGpioSimpleConfig_t gpioConfig; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; /* Init the GPIO module */ gpioClock.fastClkDiv = 2; gpioClock.slowClkDiv = 0; gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2; gpioClock.clkSrc = CY_U3P_SYS_CLK; gpioClock.halfDiv = 0; apiRetStatus = CyU3PGpioInit(&gpioClock, CyFxGpioIntrCb); if (apiRetStatus != 0) { /* Error Handling */ CyU3PDebugPrint (4, "CyU3PGpioInit failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Configure GPIO 45 as input with interrupt enabled for both edges */ gpioConfig.outValue = CyTrue; gpioConfig.inputEn = CyTrue; gpioConfig.driveLowEn = CyFalse; gpioConfig.driveHighEn = CyFalse; gpioConfig.intrMode = CY_U3P_GPIO_INTR_BOTH_EDGE; apiRetStatus = CyU3PGpioSetSimpleConfig(45, &gpioConfig); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "CyU3PGpioSetSimpleConfig failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Override GPIO 21 as this pin is associated with GPIF Control signal. * The IO cannot be selected as GPIO by CyU3PDeviceConfigureIOMatrix call * as it is part of the GPIF IOs. Override API call must be made with * caution as this will change the functionality of the pin. If the IO * line is used as part of GPIF and is connected to some external device, * then the line will no longer behave as a GPIF IO.. Here CTL4 line is * not used and so it is safe to override. */ apiRetStatus = CyU3PDeviceGpioOverride (21, CyTrue); if (apiRetStatus != 0) { /* Error Handling */ CyU3PDebugPrint (4, "CyU3PDeviceGpioOverride failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Configure GPIO 21 as output */ gpioConfig.outValue = CyFalse; gpioConfig.driveLowEn = CyTrue; gpioConfig.driveHighEn = CyTrue; gpioConfig.inputEn = CyFalse; gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR; apiRetStatus = CyU3PGpioSetSimpleConfig(21, &gpioConfig); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "CyU3PGpioSetSimpleConfig failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } }
void AR0330_Base_Config(void) { uint16_t tempdata; uint16_t tempaddr; CyU3PDebugPrint(4, "AR0330_Base_Config: starting...\r\n"); //SensorReset(); // already done elsewhere // GPIO configuration CyU3PGpioSimpleConfig_t anInput = { .outValue = CyFalse, .driveLowEn = CyFalse, .driveHighEn = CyFalse, .inputEn = CyTrue, .intrMode = CY_U3P_GPIO_NO_INTR }; CyU3PGpioSimpleConfig_t anOutputInitiallyLow = { .outValue = CyFalse, .driveLowEn = CyTrue, .driveHighEn = CyTrue, .inputEn = CyFalse, .intrMode = CY_U3P_GPIO_NO_INTR }; CyU3PGpioSimpleConfig_t anOutputInitiallyHigh = { .outValue = CyFalse, .driveLowEn = CyTrue, .driveHighEn = CyTrue, .inputEn = CyFalse, .intrMode = CY_U3P_GPIO_NO_INTR }; struct { int pin; CyU3PGpioSimpleConfig_t *config; } initialiseIO[] = GPIO_SETUP_BLOCK; for (int i = 0; NULL != initialiseIO[i].config; ++i) { CyU3PReturnStatus_t status = CyU3PDeviceGpioOverride(initialiseIO[i].pin, CyTrue); if (CY_U3P_SUCCESS != status) { CyU3PDebugPrint(4, "AR0330_Base_Config: override pin: %d error = %d 0x%x\r\n", initialiseIO[i].pin, status, status); continue; } status = CyU3PGpioSetSimpleConfig(initialiseIO[i].pin, initialiseIO[i].config); if (CY_U3P_ERROR_NOT_CONFIGURED == status) { CyU3PDebugPrint(4, "AR0330_Base_Config: pin: %d not configured as simple IO in matrix\r\n", initialiseIO[i].pin); } else if (CY_U3P_SUCCESS != status) { CyU3PDebugPrint(4, "AR0330_Base_Config: pin: %d error = %d 0x%x\r\n", initialiseIO[i].pin, status, status); } } // set up focus system Focus_Initialise(); // sensor configuration SENSOR_WRITE_ARRAY(AR0330_PrimaryInitialisation); // display versions tempaddr = 0x3000; sensor_read(tempaddr, &tempdata); CyU3PDebugPrint(4, "AR0330_Base_Config: chip version@0x%x = 0x%x\r\n", tempaddr, tempdata); tempaddr = 0x300E; sensor_read(tempaddr, &tempdata); CyU3PDebugPrint(4, "AR0330_Base_Config: revision number@0x%x = 0x%x\r\n", tempaddr, tempdata); // report if MIPI is active CyU3PDebugPrint(4, "AR0330_Base_Config: MIPI active = %d\r\n", CyU3PMipicsiCheckBlockActive()); }