/* DMA callback for the mouse application. */ void CyFxMouseDmaCb (CyU3PDmaChannel *ch, CyU3PDmaCbType_t type, CyU3PDmaCBInput_t *input) { uint8_t *buf = NULL; if (type == CY_U3P_DMA_CB_PROD_EVENT) { if (input->buffer_p.count < 4) { CyU3PDebugPrint (4, "Unknown mouse input.\r\n"); return; } /* Print the current mouse event. This example supports only * 4 byte input reports with the following format: * BYTE0: Bitmask for each of the button present. * BYTE1: Signed movement in X direction. * BYTE2: Signed movement in Y direction. * BYTE3: Signed movement in scroll wheel. */ buf = input->buffer_p.buffer; CyU3PDebugPrint (4, "Mouse event: X = %d, Y = %d, scroll = %d, BMask = 0x%x.\r\n", (int8_t)buf[1], (int8_t)buf[2], (int8_t)buf[3], (uint8_t)buf[0]); /* Discard the current buffer to free it. */ CyU3PDmaChannelDiscardBuffer (ch); } }
/* Entry function for the gpioCounterThread */ void GpioCounterThread_Entry ( uint32_t input) { uint32_t threshold = 0; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; for (;;) { /* This will retreive the current counter value. */ apiRetStatus = CyU3PGpioComplexSampleNow (52, &threshold); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PGpioComplexSampleNow failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Print out the counter value. */ CyU3PDebugPrint (4, "GPIO 52 counter reading = %d.\n", threshold); /* Sample every 2s. */ CyU3PThreadSleep (2000); } }
CyU3PReturnStatus_t SensorRead(uint8_t slaveAddr, uint8_t highAddr, uint8_t lowAddr, uint8_t count, uint8_t *buf) { CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; CyU3PI2cPreamble_t preamble; /* Validate the parameters. */ if ((slaveAddr != SENSOR_ADDR_RD) && (slaveAddr != I2C_MEMORY_ADDR_RD)) { CyU3PDebugPrint(4, "I2C Slave address is not valid!\n"); return 1; } if (count > 64) { CyU3PDebugPrint(4, "ERROR: SensorWrite count > 64\n"); return 1; } preamble.buffer[0] = slaveAddr & I2C_SLAVEADDR_MASK; /* Mask out the transfer type bit. */ preamble.buffer[1] = 0x55;//highAddr; preamble.buffer[2] = 0xaa;//lowAddr; preamble.buffer[3] = slaveAddr; preamble.length = 4; preamble.ctrlMask = 0x0004; /* Send start bit after third byte of preamble. */ apiRetStatus = CyU3PI2cReceiveBytes(&preamble, buf, count, 0); SensorI2CAccessDelay(apiRetStatus); return apiRetStatus; }
static void UartBridgeStop(void) { CyU3PEpConfig_t epCfg; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; /* Flush the endpoint memory */ CyU3PUsbFlushEp(BLADE_UART_EP_PRODUCER); CyU3PUsbFlushEp(BLADE_UART_EP_CONSUMER); /* Destroy the channel */ CyU3PDmaChannelDestroy(&glChHandlebladeRFUARTtoU); CyU3PDmaChannelDestroy(&glChHandlebladeRFUtoUART); /* Disable endpoints. */ CyU3PMemSet((uint8_t *)&epCfg, 0, sizeof (epCfg)); epCfg.enable = CyFalse; /* Producer endpoint configuration. */ apiRetStatus = CyU3PSetEpConfig(BLADE_UART_EP_PRODUCER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler (apiRetStatus); } apiRetStatus = CyU3PSetEpConfig(BLADE_UART_EP_CONSUMER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler (apiRetStatus); } CyU3PUartDeInit(); }
/* Entry function for the gpioInputThread */ void GpioInputThread_Entry ( uint32_t input) { uint32_t eventFlag; CyU3PReturnStatus_t txApiRetStatus = CY_U3P_SUCCESS; for (;;) { /* Wait for a GPIO event */ txApiRetStatus = CyU3PEventGet (&glFxGpioAppEvent, (CY_FX_GPIOAPP_GPIO_HIGH_EVENT | CY_FX_GPIOAPP_GPIO_LOW_EVENT), CYU3P_EVENT_OR_CLEAR, &eventFlag, CYU3P_WAIT_FOREVER); if (txApiRetStatus == CY_U3P_SUCCESS) { if (eventFlag & CY_FX_GPIOAPP_GPIO_HIGH_EVENT) { /* Print the status of the pin */ CyU3PDebugPrint (4, "GPIO 45 is set to high\n"); } else { /* Print the status of the pin */ CyU3PDebugPrint (4, "GPIO 45 is set to low\n"); } } } }
CyU3PReturnStatus_t SensorWrite(uint8_t slaveAddr, uint8_t highAddr, uint8_t lowAddr, uint8_t count, uint8_t *buf) { CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; CyU3PI2cPreamble_t preamble; /* Validate the I2C slave address. */ if ((slaveAddr != SENSOR_ADDR_WR) && (slaveAddr != I2C_MEMORY_ADDR_WR)) { CyU3PDebugPrint(4, "I2C Slave address is not valid!\n"); return 1; } if (count > 64) { CyU3PDebugPrint(4, "ERROR: SensorWrite count > 64\n"); return 1; } /* Set up the I2C control parameters and invoke the write API. */ preamble.buffer[0] = slaveAddr; preamble.buffer[1] = 0xab;//highAddr; preamble.buffer[2] = 0xcd;//lowAddr; preamble.length = 3; preamble.ctrlMask = 0x0000; apiRetStatus = CyU3PI2cTransmitBytes(&preamble, buf, count, 0); SensorI2CAccessDelay(apiRetStatus); return apiRetStatus; }
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 }
/* Entry function for the gpioPWMThread */ void GpioPWMThread_Entry ( uint32_t input) { CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; /* Initialize Debug module */ apiRetStatus = CyFxDebugInit(); if (apiRetStatus != CY_U3P_SUCCESS) { CyFxAppErrorHandler(apiRetStatus); } /* Initialize GPIO module. */ CyFxGpioInit (); /* Now resume the other two threads. */ CyU3PThreadResume (&gpioMeasureThread); CyU3PThreadResume (&gpioCounterThread); for (;;) { /* Wait for 1s. */ CyU3PThreadSleep (1000); /* Change the PWM duty cycle to 75%. */ apiRetStatus = CyU3PGpioComplexUpdate (50, CY_FX_PWM_75P_THRESHOLD, CY_FX_PWM_PERIOD); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PGpioComplexUpdate failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Wait for 1s. */ CyU3PThreadSleep (1000); /* Change the PWM duty cycle to 25%. */ apiRetStatus = CyU3PGpioComplexUpdate (50, CY_FX_PWM_25P_THRESHOLD, CY_FX_PWM_PERIOD); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PGpioComplexUpdate failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } } }
/* Entry function for the gpioOutputThread */ void GpioOutputThread_Entry ( uint32_t input) { CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; /* Initialize Debug module */ apiRetStatus = CyFxDebugInit(); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "Debug module initialization failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Initialize GPIO module. */ CyFxGpioInit (); for (;;) { /* Set the GPIO 21 to high */ apiRetStatus = CyU3PGpioSetValue (21, CyTrue); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "CyU3PGpioSetValue failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Wait for two seconds */ CyU3PThreadSleep(2000); /* Set the GPIO 21 to low */ apiRetStatus = CyU3PGpioSetValue (21, CyFalse); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "CyU3PGpioSetValue failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Wait for two seconds */ CyU3PThreadSleep(2000); } }
/* This function stops the slave FIFO loop application. This shall be called * whenever a RESET or DISCONNECT event is received from the USB host. The * endpoints are disabled and the DMA pipe is destroyed by this function. */ static void NuandRFLinkStop (void) { CyU3PEpConfig_t epCfg; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; CyU3PGpioSetValue(GPIO_SYS_RST, CyTrue); CyU3PGpioSetValue(GPIO_RX_EN, CyFalse); CyU3PGpioSetValue(GPIO_TX_EN, CyFalse); /* Flush endpoint memory buffers */ CyU3PUsbFlushEp(BLADE_RF_SAMPLE_EP_PRODUCER); CyU3PUsbFlushEp(BLADE_RF_SAMPLE_EP_CONSUMER); /* Destroy the channels */ CyU3PDmaChannelDestroy(&glChHandleUtoP); if (!loopback_when_created) CyU3PDmaChannelDestroy(&glChHandlePtoU); /* Disable endpoints. */ CyU3PMemSet ((uint8_t *)&epCfg, 0, sizeof (epCfg)); epCfg.enable = CyFalse; /* Disable producer endpoint */ apiRetStatus = CyU3PSetEpConfig(BLADE_RF_SAMPLE_EP_PRODUCER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint(4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Disable consumer endpoint */ apiRetStatus = CyU3PSetEpConfig(BLADE_RF_SAMPLE_EP_CONSUMER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint(4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Reset the GPIF */ apiRetStatus = NuandConfigureGpif(GPIF_CONFIG_DISABLED); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint(4, "Failed to deinitialize GPIF. Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } UartBridgeStop(); NuandAllowSuspend(CyTrue); glAppMode = MODE_NO_CONFIG; }
void AR0330_SetManualfocus(int32_t enable) { CyU3PDebugPrint(4, "AR0330_SetManualfocus\r\n"); if (0 != enable) { // stop auto focus process Focus_Stop(); } }
void AR0330_SetAutofocus(int32_t enable) { CyU3PDebugPrint(4, "AR0330_SetAutofocus\r\n"); if (0 != enable) { // trigger a new focus cycle Focus_Start(); } }
/* This function disables the mouse driver application. */ static void CyFxApplnStop () { /* Destroy the DMA channel. */ CyU3PDmaChannelDestroy (&glHostInCh); if (glHostInEp != 0) { CyU3PUsbHostEpRemove (glHostInEp); glHostInEp = 0; } CyU3PDmaChannelDestroy (&glHostOutCh); if (glHostOutEp != 0) { CyU3PUsbHostEpRemove (glHostOutEp); glHostOutEp = 0; } /* Remove EP0. and disable the port. */ CyU3PUsbHostEpRemove (0); glHostEpSize = 0; CyU3PUsbHostPortDisable (); /* Clear state variables. */ glIsApplnActive = CyFalse; glTimerCount = 0; glIsHnp = CyFalse; glDoHnp = CyFalse; glIsHnpSupported = CyFalse; /* Reset counter to zero. */ glDMARxCount = 0; glDMATxCount = 0; CyU3PDebugPrint (4, "Host mode application stopped.\r\n"); }
uint8_t SensorSetControl(uint8_t IDext, uint8_t devAdd, uint8_t value) //for register w/r, the IDext is Reg. addrss. { SensorWrite2B(SENSOR_ADDR_WR, I2C_DSPBOARD_ADDR_WR, devAdd, IDext, value); //#ifdef USB_DEBUG_PRINT CyU3PDebugPrint (4, "The Set control regAdd 0x%x 0x%x\r\n", IDext, value); // additional debug //#endif return 0; };
void CyFxGpifAppInit ( void) { CyU3PReturnStatus_t status; CyU3PGpioClock_t gpioClock; CyU3PPibClock_t pibClock; /* GPIO module needs to be initialized before SIB is initialized. This is required because GPIOs are used in the SIB code. */ gpioClock.fastClkDiv = 2; gpioClock.slowClkDiv = 16; gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2; gpioClock.clkSrc = CY_U3P_SYS_CLK; gpioClock.halfDiv = 0; status = CyU3PGpioInit (&gpioClock, NULL); if (status != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "GPIO Init failed, code=%d\r\n", status); CyFxGpifAppErrorHandler (status); } /* Initialize PIB and load the GPIF waveform. */ pibClock.clkDiv = 2; pibClock.clkSrc = CY_U3P_SYS_CLK; pibClock.isHalfDiv = CyFalse; pibClock.isDllEnable = CyFalse; status = CyU3PPibInit (CyTrue, &pibClock); if (status != CY_U3P_SUCCESS) { CyU3PDebugPrint (2, "Error: PIB Init failed with code %d\r\n", status); CyFxGpifAppErrorHandler (status); } status = CyU3PGpifLoad (&Async_Admux_CyFxGpifConfig); if (status != CY_U3P_SUCCESS) { CyU3PDebugPrint (2, "Error: GPIF load failed with code %d\r\n", status); CyFxGpifAppErrorHandler (status); } /* Register a callback that will receive notifications of incoming requests. */ CyU3PMboxInit (CyFxAppMboxCallback); }
void AR0330_SetBrightness(int32_t brightness) { CyU3PDebugPrint(4, "AR0330_SetBrightness: %d\r\n", brightness); if (brightness < BRIGHTNESS_MINIMUM && brightness > BRIGHTNESS_MAXIMUM) { return; // ignore invalid values } current_brightness = brightness; sensor_write(0x301e, (uint16_t)(brightness)); // data_pedestal }
void AR0330_SetSharpness(int32_t sharpness) { CyU3PDebugPrint(4, "AR0330_SetSharpness: %d\r\n", sharpness); if (sharpness < SHARPNESS_MINIMUM && sharpness > SHARPNESS_MAXIMUM) { return; // ignore invalid values } current_sharpness = sharpness; sensor_write(0x305e, (uint16_t)(sharpness)); // global_gain }
void AR0330_5MP_config(void) { CyU3PDebugPrint(4, "AR0330_5MP_config\r\n"); //SENSOR_WRITE_ARRAY(AR0330_PrimaryInitialisation); SENSOR_WRITE_ARRAY(sensor_5MP_regs); AR0330_Debug(); }
uint8_t SensorSetIrisControl(uint8_t IDext, uint8_t devAdd, uint8_t value, uint8_t boardID) //for register w/r, the IDext is Reg. addrss. { SensorWrite2B(SENSOR_ADDR_WR, boardID, devAdd, IDext, value); #ifdef USB_DEBUG_PRINT CyU3PDebugPrint (4, "The Set control ID 0x%x 0x%x 0x%x\r\n", boardID, IDext, value); // additional debug #endif return 0; };
uint8_t SensorGetIrisControl(uint8_t IDext, uint8_t devAdd, uint8_t boardID) //for register w/r, the IDext is Reg. addrss. { uint8_t buf[2]; SensorRead2B(SENSOR_ADDR_RD, boardID, devAdd, IDext, buf); #ifdef USB_DEBUG_PRINT CyU3PDebugPrint (4, "The Get control ID 0x%x 0x%x %d\r\n", boardID, IDext, buf[0]); // additional debug #endif return buf[0]; };
void AR0330_SetContrast(int32_t contrast) { CyU3PDebugPrint(4, "AR0330_SetContrast %d\r\n", contrast); if (contrast < CONTRAST_MINIMUM && contrast > CONTRAST_MAXIMUM) { return; // ignore invalid values } current_contrast = contrast; uint16_t gain = analog_gain[contrast] & 0x3f; // 6 bit fields: cb=13..8 ca=5..0 sensor_write(0x3060, (gain << 8) | gain); // analog_gain_cb | analog_gain }
static CyBool_t check_photo_switch(void) { p_n += p_i; CyBool_t value = CyFalse; CyU3PReturnStatus_t rc = CyU3PGpioSimpleGetValue(FOCUS_POSITION, &value); CyBool_t state = (CY_U3P_SUCCESS == rc) && (CyTrue == value); if (state != p_switch) { p_switch = state; CyU3PDebugPrint(4, "ps = %x @ %d\r\n", state, p_n); } return state; }
void AR0330_Debug(void) { #if DEBUG_ENABLE uint16_t tempaddr = 0x3000; int i; for (i = 0; i < 256; i += 4) { CyU3PDebugPrint(4, "DEBUG: 0x%x: ", tempaddr); int j; for (j = 0; j < 4; ++j, tempaddr += 2) { uint16_t d; sensor_read(tempaddr, &d); CyU3PDebugPrint(4, "0x%x%x%x%x ", (d >> 12) & 0x0f, (d >> 8) & 0x0f, (d >> 4) & 0x0f, (d >> 0) & 0x0f); } CyU3PDebugPrint(4, "\r\n"); } static const uint16_t addresses[] = { 0x3780, 0x301A // reset status // 0x3ED0, 0x3ED2, 0x3ED4, 0x3ED6, // 0x3ED8, 0x3EDA, 0x3EDC, 0x3EDE, // 0x3EE0, 0x3EE6, // 0x3EE8, 0x3EEA, // 0x3F06, }; for (i = 0; i < SIZE_OF_ARRAY(addresses); ++i) { tempaddr = addresses[i]; uint16_t tempdata; sensor_read(tempaddr, &tempdata); CyU3PDebugPrint(4, "DEBUG: read address = 0x%x data = 0x%x\r\n", tempaddr, tempdata); } // report if MIPI is active CyU3PDebugPrint(4, "DEBUG: MIPI active = %d\r\n", CyU3PMipicsiCheckBlockActive()); #endif }
/* Entry function for the gpioMeasureThread. */ void GpioMeasureThread_Entry ( uint32_t input) { uint32_t threshold = 0; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; for (;;) { /* Invoke the measure API. This will measure the low period for the PWM */ apiRetStatus = CyU3PGpioComplexMeasureOnce (51, CY_U3P_GPIO_MODE_MEASURE_LOW_ONCE); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PGpioComplexMeasureOnce failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Since this thread should not block other threads, do not wait. */ do { CyU3PThreadSleep (1); apiRetStatus = CyU3PGpioComplexWaitForCompletion (51, &threshold, CyFalse); } while (apiRetStatus == CY_U3P_ERROR_TIMEOUT); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PGpioComplexWaitForCompletion failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Print out the threshold value. */ CyU3PDebugPrint (4, "GPIO 51 low threshold = %d.\n", threshold); /* Sample every 0.5s. */ CyU3PThreadSleep (500); } }
/* USB host stack event callback function. */ static void CyFxHostEventCb (CyU3PUsbHostEventType_t evType, uint32_t evData) { /* This is connect / disconnect event. Log it so that the * application thread can handle it. */ if (evType == CY_U3P_USB_HOST_EVENT_CONNECT) { CyU3PDebugPrint (4, "USB host mode: Remote peripheral detected.\r\n"); glIsPeripheralPresent = CyTrue; } else { CyU3PDebugPrint (4, "USB host mode: Remote peripheral disconnected.\r\n"); glIsPeripheralPresent = CyFalse; /* Indicate that this is a HNP role change. */ if (glIsHnp) { glDoHnp = CyTrue; } } }
/* Write to an I2C slave with two bytes of data for 5MP camera. */ CyU3PReturnStatus_t SensorWrite2B2( uint8_t slaveAddr, uint8_t highAddr, uint8_t lowAddr, uint8_t highData, uint8_t lowData) { CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; CyU3PI2cPreamble_t preamble; uint8_t buf[2]; /* Validate the I2C slave address. */ //if ((slaveAddr != SENSOR_ADDR_WR) && (slaveAddr != I2C_MEMORY_ADDR_WR)) { // CyU3PDebugPrint(4, "I2C Slave address is not valid!\n"); // return 1; //} preamble.buffer[0] = slaveAddr; /************** command block ***************************************/ preamble.buffer[1] = highAddr; //preamble.buffer[2] = lowAddr; preamble.ctrlMask = 0x0000; preamble.length = 2; /* Three byte preamble. */ buf[0] = highData; apiRetStatus = CyU3PI2cTransmitBytes(&preamble, buf, 1, 0); //#ifdef DbgInfo CyU3PDebugPrint(4, "sensor write2B(0) %d %d %d\r\n", lowAddr, buf[0], lowData); //additional debug //#endif SensorI2CAccessDelay(apiRetStatus); buf[0] = lowData; /****************** data block *****************************************/ preamble.ctrlMask = 0x0000; preamble.length = 1; //apiRetStatus = CyU3PI2cTransmitBytes(&preamble, buf, 1, 0); #ifdef DbgInfo CyU3PDebugPrint(4, "sensor write2B(1) %d %d %d\r\n", lowAddr, buf[0], buf[1]); //additional debug #endif /* Set the parameters for the I2C API access and then call the write API. */ //SensorI2CAccessDelay(apiRetStatus); return apiRetStatus; }
/* OTG event handler. */ void CyFxOtgEventCb ( CyU3POtgEvent_t event, uint32_t input) { CyU3PDebugPrint (4, "OTG Event: %d, Input: %d.\r\n", event, input); switch (event) { case CY_U3P_OTG_PERIPHERAL_CHANGE: if (input == CY_U3P_OTG_TYPE_A_CABLE) { /* Enable the VBUS supply. */ CyFxUsbVBusControl (CyTrue); } else { /* Make sure that the VBUS supply is disabled. */ CyFxUsbVBusControl (CyFalse); /* Stop the previously started host stack. */ if ((!CyU3POtgIsHostMode ()) && (CyU3PUsbHostIsStarted ())) { CyFxUsbHostStop (); } } break; case CY_U3P_OTG_VBUS_VALID_CHANGE: if (input) { /* Start the host mode stack. */ if (!CyU3PUsbHostIsStarted ()) { CyFxUsbHostStart (); } } else { /* If the OTG mode has changed, stop the previous stack. */ if ((!CyU3POtgIsHostMode ()) && (CyU3PUsbHostIsStarted ())) { /* Stop the previously started host stack. */ CyFxUsbHostStop (); } } break; default: /* do nothing */ break; } }
/* Entry function for the AppThread. */ void ApplnThread_Entry ( uint32_t input) { CyBool_t isPresent = CyFalse; CyU3PReturnStatus_t status = CY_U3P_SUCCESS; /* Initialize the debug logger. */ CyFxApplnDebugInit (); /* Initialize the example application. */ status = CyFxApplnInit(); if (status != CY_U3P_SUCCESS) { CyU3PDebugPrint (2, "Application initialization failed. Aborting.\r\n"); CyFxAppErrorHandler (status); } for (;;) { CyU3PThreadSleep (100); if (isPresent != glIsPeripheralPresent) { /* Stop previously started application. */ if (glIsApplnActive) { CyFxApplnStop (); } /* If a peripheral got connected, then enumerate * and start the application. */ if (glIsPeripheralPresent) { status = CyU3PUsbHostPortEnable (); if (status == CY_U3P_SUCCESS) { CyFxApplnStart (); } } /* Update the state variable. */ isPresent = glIsPeripheralPresent; } /* Since the test needs to be done from a thread, * this function is called at fixed interval. */ if (glHostOwner == CY_FX_HOST_OWNER_MSC_DRIVER) { CyFxMscDriverDoWork (); } } }
/* * Reset the image sensor using GPIO. */ void SensorReset(void) { CyU3PReturnStatus_t apiRetStatus; uint16_t preTick, posTick; /* Drive the GPIO low to reset the sensor. */ //apiRetStatus = CyU3PGpioSetValue(SENSOR_POWER_GPIO, CyFalse); apiRetStatus = CyU3PGpioSetValue(SENSOR_RESET_GPIO, CyFalse); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint(4, "GPIO Set Value Error, Error Code = %d\n", apiRetStatus); return; } CyU3PDebugPrint(4, "GPIO Set Value\r\n"); /* Wait for some time to allow proper reset. */ uint8_t i = 0; while (i++ < 2){ preTick = CyU3PGetTime(); CyU3PThreadSleep(500); // change the value into 100 from 10. posTick = CyU3PGetTime(); CyU3PDebugPrint(4, "The ticks %d %d \r\n", preTick, posTick); //additional debug //;//CyU3PDebugPrint(4, "cpu pause \r\n"); } /* Drive the GPIO high to bring the sensor out of reset. */ //apiRetStatus = CyU3PGpioSetValue(SENSOR_POWER_GPIO, CyTrue); apiRetStatus = CyU3PGpioSetValue(SENSOR_RESET_GPIO, CyTrue); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint(4, "GPIO Set Value Error, Error Code = %d\n", apiRetStatus); return; } /* pause the cpu */ while (i++ < 4){ CyU3PThreadSleep(600); // change the value into 100 from 10. //;//CyU3PDebugPrint(4, "cpu pause \r\n"); } return; }
/* Image sensor initialization sequence. */ void SensorInit(void) { if (SensorI2cBusTest() != CY_U3P_SUCCESS) /* Verify that the sensor is connected. */ { CyU3PDebugPrint(4, "Error: Reading Sensor ID failed!\r\n"); return; } /* Generic settings (which are common for all resolutions) for bringing up the image sensor to stream video data should be populated here. */ /* Update sensor configuration based on desired video stream parameters. Using 720p 30fps as default setting.*/ //SensorScaling_HD720p_30fps(); }