/******************************************************************************* * Function Name: ServiceUSB ******************************************************************************** * Summary: This routine performs tasks that should be done soon after USB * enumeration is completed (configure DMA, initialize state machine etc). * When the USB configuration is changed, this routine reinitializes all * the USB endpoints as required by the application. * * Parameters: * void * * Return: * void * *******************************************************************************/ void ServiceUSB(void) { CYBIT macPC_flag=FALSE; if(USB_INTERFACE_INACTIVE == USBDeviceState) { USBDeviceState = USB_INIT_AFTER_ENUMERATION_REQUIRED; } /* Initialization sequence for every USB host enumeration event */ if(USBDeviceState == USB_INIT_AFTER_ENUMERATION_REQUIRED) { uint16 index = 0; USBDeviceState = USB_INIT_AFTER_ENUMERATION_COMPLETED; SetAppleDeviceAudioSource(AUDIO_SOURCE_DIGITAL); macPC_flag = IsMacPCConnected(); #if(USBFS_EP_MM == USBFS__EP_DMAAUTO) /* USER_CODE: [Audio Buffers] Add a separate for loop if the playback and recording audio buffer size are * not equal */ for(index=0; index< OUT_AUDIOMAXPKT; index++) { #ifndef ENABLE_DIGITAL_AUDIO_OUT_ONLY inRam[index] = 0; #endif #ifndef ENABLE_DIGITAL_AUDIO_IN_ONLY outRam[index] = 0; #endif } #ifndef ENABLE_DIGITAL_AUDIO_OUT_ONLY inCnt = IN_AUDIOMAXPKT; #endif #endif #ifdef CDC_ENABLED USBUARTStart(); /* Initializes the USB UART interface */ #endif /* Configure the HID input endpoint buffer for Mac/PC playlist control */ if(macPC_flag) { USBFS_LoadInEP(MAC_PC_HID_CONTROL_ENDPOINT, (uint8 *)&playlistControlReport, sizeof(playlistControlReport)); #ifdef PHONE_CONTROL_ENABLED USBFS_ReadOutEP(MAC_PC_HID_OUT_ENDPOINT, &hidOutReport, sizeof(hidOutReport)); USBFS_EnableOutEP(MAC_PC_HID_OUT_ENDPOINT); #endif } /* If Aux is not currently configured, then switch to digital audio mode */ if(IS_AUX_NOT_SELECTED()) { ConfigureDigitalAudioDMA(); } else { #ifdef LCD_MODULE_ENABLED /* Else Display Aux Configured message on the LCD */ LCD2LineDisplay("Analog Loopback ", " "); #endif } /* USER_CODE: [USB enumeration] placeholder for initializing custom user code after the USB host enumerates the * accessory. This routine will be called once per accessory connection after the host issues SET_CONFIGURATION * request */ } #ifdef MIDI_ENABLED if (midiEPInitialized == FALSE || usbReset) { /* Initialize MIDI only when a valid USB host is connected */ if ((IsUSBConfigured() && IsMacPCConnected())) { USBFS_MIDI_EP_Init(); /* USB Component internally sets the priority of the UART TX and RX ISRs to 4 and 2 respectively, change the * interrupt priority in the application code to match the system interrupt setup */ CyIntSetPriority(MIDI1_UART_TX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_SIX); CyIntSetPriority(MIDI1_UART_RX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_FIVE); #if (USBFS_MIDI_EXT_MODE >= USBFS_TWO_EXT_INTRF) CyIntSetPriority(MIDI2_UART_TX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_SIX); CyIntSetPriority(MIDI2_UART_RX_VECT_NUM, MIDI_UART_INTERRUPT_PRIORITY_FIVE); #endif midiEPInitialized = TRUE; usbReset = 0; } } if(USBFS_midiInPointer%USBFS_EVENT_LENGTH == 0 && USBFS_midiInPointer!=0) { if(midiInWaitTimer == 0) { midiInWaitTimer = MIDI_IN_EP_WAIT_TIME; USBFS_MIDI_IN_EP_Service(); } } else { midiInWaitTimer = MIDI_IN_EP_WAIT_TIME; } #endif /* USBFS_IsConfigurationChanged() is a clear on read status update therefore, only one read of * USBFS_IsConfigurationChanged() should ever exist in user code */ if(USBFS_IsConfigurationChanged()) { macPC_flag = IsMacPCConnected(); #ifndef ENABLE_DIGITAL_AUDIO_IN_ONLY /* Get Alternate setting */ altSetting[AUDIO_OUT_INTERFACE_INDEX] = (macPC_flag? USBFS_GetInterfaceSetting(1):USBFS_GetInterfaceSetting(2)); /* ByteSwap control register bit is set to 1 if alt setting 2 is selected so that * Byte swap digital logic processes data as 16 bits. ByteSwap control register is set to 0 * if alt setting 1 is selected and byte swap processes data as 24 bits */ if (altSetting[AUDIO_OUT_INTERFACE_INDEX]==ALT_SETTING_ACTIVE_24_BIT) { ByteSwap_Tx_CONTROL_REG = ByteSwap_Tx_CONTROL_REG & (~ByteSwap_Tx_RES_CTRL_16); } else if (altSetting[AUDIO_OUT_INTERFACE_INDEX]==ALT_SETTING_ACTIVE_16_BIT) { ByteSwap_Tx_CONTROL_REG = ByteSwap_Tx_CONTROL_REG | ByteSwap_Tx_RES_CTRL_16; } /* Arming the audio out EP if it is not zero bandwidth alt setting */ if (altSetting[AUDIO_OUT_INTERFACE_INDEX]!= ALT_SETTING_ZERO_BANDWIDTH && (CY_GET_REG8(USBFS_SIE_EP1_CR0_PTR + ((AUDIO_OUT_ENDPOINT - USBFS_EP1) << USBFS_EPX_CNTX_ADDR_SHIFT)) & USBFS_MODE_MASK) == USBFS_MODE_NAK_IN_OUT) { /* Init DMA configurations for audio OUT EP */ USBFS_ReadOutEP(AUDIO_OUT_ENDPOINT, &outRam[0], OUT_AUDIOMAXPKT); USBFS_EnableOutEP(AUDIO_OUT_ENDPOINT); } #endif #ifndef ENABLE_DIGITAL_AUDIO_OUT_ONLY #ifndef ENABLE_DIGITAL_AUDIO_IN_ONLY if(altSetting[AUDIO_IN_INTERFACE_INDEX] != (macPC_flag? USBFS_GetInterfaceSetting(2):USBFS_GetInterfaceSetting(3))) { altSetting[AUDIO_IN_INTERFACE_INDEX] = (macPC_flag? USBFS_GetInterfaceSetting(2):USBFS_GetInterfaceSetting(3)); #else if(altSetting[AUDIO_IN_INTERFACE_INDEX] != (macPC_flag? USBFS_GetInterfaceSetting(1):USBFS_GetInterfaceSetting(2))) { altSetting[AUDIO_IN_INTERFACE_INDEX] = (macPC_flag? USBFS_GetInterfaceSetting(1):USBFS_GetInterfaceSetting(2)); #endif /* Setting the ByteSwap control register bit to 0 regardless of alt setting is selected. Because audio in * interface both the alternate settings alt setting1 and alt setting 2 both use 3 byte subframe size. */ ByteSwap_Rx_CONTROL_REG = ByteSwap_Rx_CONTROL_REG & (~ByteSwap_Rx_RES_CTRL_16); /* Arming the audio in EP if it is not zero bandwidth alt setting */ if (altSetting[AUDIO_IN_INTERFACE_INDEX]!= ALT_SETTING_ZERO_BANDWIDTH && (CY_GET_REG8(USBFS_SIE_EP1_CR0_PTR + ((AUDIO_IN_ENDPOINT - USBFS_EP1) << USBFS_EPX_CNTX_ADDR_SHIFT)) & USBFS_MODE_MASK) == USBFS_MODE_NAK_IN_OUT) { /* Init DMA configurations for audio IN EP */ inCnt = IN_AUDIOMAXPKT; USBFS_LoadInEP(AUDIO_IN_ENDPOINT, &inRam[0], inCnt); /* Pre-arm first audio IN request */ USBFS_LoadInEP(AUDIO_IN_ENDPOINT, USBFS_NULL, inCnt); } } #endif /* USER_CODE: [USB configuration changed] Placeholder for adding additional USB endpoint initialization code * when the host issues either a SET_INTERFACE or SET_CONFIGURATION request to the accessory. After receiving * a SET_INTERFACE request from the host, the endpoint belonging to the alternate setting being configured * by the USB host is reset and must be reinitialized here for proper operation of the USB block */ } } /******************************************************************************* * Function Name: ServiceUSBSuspend ******************************************************************************** * Summary: * This function handles USB suspend event from USB host and forces PSoC 3 * to enter low power mode. Once the USB resume event is detected, PSoC3 * wakes up and starts operating in normal mode. * * Parameters: * void * * Return: * void * *******************************************************************************/ #ifdef HANDLE_USB_SUSPEND void ServiceUSBSuspend(void) { if(!IsMacPCConnected() || ! USBFS_initVar) { return; } /* Check if the host is active */ if(USBFS_bCheckActivity() != 0 ) { usbActivityCounter = 0; } else { usbActivityCounter++; } /* USB Suspend event is lack of greater than 3 consecutive SOF's */ if(usbActivityCounter > USB_SUSPEND_TIME_TICKS ) { /* The debounce delay is taken care by increasing the suspend time to 40ms (5 * 8ms) */ if(IsMacPCConnected() && IsUSBConfigured()) { /* USER_CODE: [USB suspend] Placeholder for configuring ALL the additional components added by the user in * sleep mode before calling USB suspend/PSoC 3 sleep API */ #ifdef LCD_MODULE_ENABLED LCD_Position(0,0); LCD_PrintString(" USB Suspend "); #endif /* If the accessory is not in low power mode, enter low power mode on seeing a USB suspend */ if(!lowPowerIdle) { lowPowerIdle = TRUE; StopAudioComponents(); /* Changes to 24 MHz IMO for USB */ StopAnalogAudioComponents(); /* Turn OFF Analog path for Audio-In/iPod Analog */ } if(!midiPowerIdle) { if(!lowPowerIdle) { StopAudioComponents(); /* Changes to 24 MHz IMO for USB */ } CyPins_SetPin(PSOC_MIDI_PWR_0); /* Turn off the MIDI I/O hardware */ midiPowerIdle = TRUE; /* MIDI low power mode enabled */ } CyPins_ClearPin(PSOC_CODEC_PWR_0); /* Turn off the regulator to reduce suspend mode current */ USBFS_Suspend(); I2C_Master_Sleep(); /* Configure I2C master block in sleep mode */ #ifdef CAPSENSE_ENABLED while(CapSense_IsBusy()); /* Wait for current scan to complete */ CapSense_Sleep(); #endif #ifdef MIDI_ENABLED MIDI1_UART_Sleep(); #if (USBFS_MIDI_EXT_MODE >= USBFS_TWO_EXT_INTRF) MIDI2_UART_Sleep(); #endif #endif CyPmSaveClocks(); CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_PICU); /* PSoC 3 is in sleep mode */ CyPmRestoreClocks(); USBFS_Resume(); I2C_Master_Wakeup(); #ifdef CAPSENSE_ENABLED CapSense_Wakeup(); CapSense_IntClock_SetSource(CYCLK_SRC_SEL_IMO); #endif #ifdef MIDI_ENABLED MIDI1_UART_Wakeup(); #if (USBFS_MIDI_EXT_MODE >= USBFS_TWO_EXT_INTRF) MIDI2_UART_Wakeup(); #endif #endif CyPins_SetPin(PSOC_CODEC_PWR_0); /* Turn ON the CODEC regulator after wake up */ #ifdef WINDOWS7_WORKAROUND if(USBFS_GetConfiguration() != 0) { USBFS_configurationChanged = USBFS_TRUE; USBFS_Config(USBFS_FALSE); } #endif #ifdef LCD_MODULE_ENABLED LCD_Position(0,0); LCD_PrintString("Mac/PC Interface"); #endif /* USER_CODE: [USB wakeup] Placeholder for re-configuring ALL the additional components added by the user in * wakeup mode after calling USB wakeup */ } usbActivityCounter = 0; /* After coming out of USB suspend, MIDI end point should be re-initialized */ midiEPInitialized = 0; } } #endif /******************************************************************************* * Function Name: HandlePCMacUSBInterface ******************************************************************************** * Summary: Checks if PC/Mac is connected/disconnected and start the USB component * * Parameters: * void * * Return: * void * *******************************************************************************/ void HandlePCMacUSBInterface(void) { /* If Aux mode is enabled, then Mac/PC connection disconnection is handled only when the system is not in * aux In mode. For self powered case, Apple device connection is also checked before starting the Mac/PC * interface */ if(IS_AUX_NOT_SELECTED() && !USBFS_initVar && IsMacPCConnected()) { /* Switch the PSoC USB D+ and D- lines to USB Mini B */ CyPins_ClearPin(PSOC_USB_SEL_0); /* Start the USB component when PC/Mac is connected */ USBFS_Start(PC_MAC_AUDIO_WITH_VOLUME_DEVICE, USBFS_DWR_VDDD_OPERATION); USBDeviceState = USB_INIT_AFTER_ENUMERATION_REQUIRED; #ifdef LCD_MODULE_ENABLED if(IS_AUX_NOT_SELECTED()) { LCD2LineDisplay("Mac/PC Interface", " "); } #endif #ifdef ENABLE_VOLUME_CONTROL currentLCDVolume--; /* dirty the LCD volume and mute update flag to update volume and mute info on the LCD */ currentLCDMute--; #endif usbMiniBActive = TRUE; /* USER_CODE: [Mac/PC connection] Placeholder for initializing components or external peripherals when the * accessory is plugged into Mac/PC (USB VBus = High) */ } /* Check for PC/Mac USB Audio device disconnection in self powered mode. * In device powered mode project, no need of checking disconnection event as power is shut off * as soon as USB cable is disconnected from USB mini connector. */ else if(usbMiniBActive && (USBFS_bGetConfiguration() || USBDeviceState == USB_INIT_AFTER_ENUMERATION_REQUIRED)) { /* If VBUS voltage from mini B is now gone and was previous present then stop USB interface */ if(!IsMacPCConnected()) { if(USBFS_initVar) { USBFS_Stop(); } CyPins_SetPin(PSOC_USB_SEL_0); /* Switch the PSoC USB D+ and D- lines back to Apple device */ /* If Aux was not configured when PC is unplugged, then switch off CODEC */ if(!auxConfigured) { CyPins_ClearPin(PSOC_CODEC_RST_0); /* Hold CODEC in reset */ codecInit = FALSE; } usbMiniBActive = FALSE; /* USER_CODE: [Mac/PC disconnection] Placeholder for shutting down components or external peripherals when * the accessory is disconnected from Mac/PC (USB VBus transitioned from High to Low) */ } } } /******************************************************************************* * Function Name: EnableNAKBulkIN ******************************************************************************** * Summary: Enables the NAK interrupt on a USB endpoint * * Parameters: * Endpoint number for which NAK interrupt is to be enabled * * Return: * void * *******************************************************************************/ void EnableNAKBulkIN(uint8 bEPNumber) { uint8 index = (bEPNumber - USBFS_EP1) << USBFS_EPX_CNTX_ADDR_SHIFT; if((CY_GET_REG8(&USBFS_SIE_EP1_CR0_PTR[index]) & USBFS_MODE_MASK) != USBFS_MODE_ACK_IN) { CY_SET_REG8(&USBFS_SIE_EP1_CR0_PTR[index], CY_GET_REG8(&USBFS_SIE_EP1_CR0_PTR[index]) | NAK_IN_INTERRUPT_ENABLE_MASK); } }
/******************************************************************************* * Function Name: PWM_3_ReadStatusRegister ******************************************************************************** * * Summary: * This function returns the current state of the status register. * * Parameters: * None * * Return: * uint8 : Current status register value. The status register bits are: * [7:6] : Unused(0) * [5] : Kill event output * [4] : FIFO not empty * [3] : FIFO full * [2] : Terminal count * [1] : Compare output 2 * [0] : Compare output 1 * *******************************************************************************/ uint8 PWM_3_ReadStatusRegister(void) { return (CY_GET_REG8(PWM_3_STATUS_PTR)); }
/******************************************************************************* * Function Name: PWM_3_ReadCompare2 ******************************************************************************** * * Summary: * Reads the compare value for the compare2 output. * * Parameters: * None * * Return: * uint8/uint16: Current compare value. * *******************************************************************************/ uint8 PWM_3_ReadCompare2(void) { return (CY_GET_REG8(PWM_3_COMPARE2_LSB_PTR)); }
/******************************************************************************* * FUNCTION NAME: PrISM_2_ReadSeed ******************************************************************************** * * Summary: * Reads the PrISM Seed register. * * Parameters: * None. * * Return: * Current Period register value. * *******************************************************************************/ uint8 PrISM_2_ReadSeed(void) { return( CY_GET_REG8(PrISM_2_SEED_PTR) ); }
/******************************************************************************* * FUNCTION NAME: PrISM_2_ReadPulse1 ******************************************************************************** * * Summary: * Reads the PrISM Pulse Density1 register. * * Parameters: * None. * * Return: * Pulse Density1 register value. * *******************************************************************************/ uint8 PrISM_2_ReadPulse1(void) { return( CY_GET_REG8(PrISM_2_DENSITY1_PTR) ); }
/******************************************************************************* * Function Name: pwm_ReadKillTime ******************************************************************************** * * Summary: * Reads the kill time value used by the hardware when the Kill Mode is set * to Minimum Time. * * Parameters: * None * * Return: * uint8: The current Minimum Time kill counts * *******************************************************************************/ uint8 pwm_ReadKillTime(void) { return (CY_GET_REG8(pwm_KILLMODEMINTIME_PTR)); }
/******************************************************************************* * FUNCTION NAME: RedGreenPrISM_ReadPolynomial ******************************************************************************** * * Summary: * Reads the PrISM polynomial. * * Parameters: * None. * * Return: * PrISM polynomial. * *******************************************************************************/ uint8 RedGreenPrISM_ReadPolynomial(void) { return( CY_GET_REG8(RedGreenPrISM_POLYNOM_PTR) ); }
/******************************************************************************* * Function Name: PWM_BC_ReadCompare1 ******************************************************************************** * * Summary: * Reads the compare value for the compare1 output. * * Parameters: * None * * Return: * uint8/uint16: Current compare value. * *******************************************************************************/ uint8 PWM_BC_ReadCompare1(void) { return (CY_GET_REG8(PWM_BC_COMPARE1_LSB_PTR)); }
/******************************************************************************* * Function Name: MainTimer_SoftwareCapture ******************************************************************************** * * Summary: * This function forces a capture independent of the capture signal. * * Parameters: * void * * Return: * void * * Side Effects: * An existing hardware capture could be overwritten. * * Reentrant * Yes * *******************************************************************************/ void MainTimer_SoftwareCapture(void) { /* Generate a software capture by reading the counter register */ CY_GET_REG8(MainTimer_COUNTER_LSB_PTR); /* Capture Data is now in the FIFO */ }
/******************************************************************************* * Function Name: hallTickCounter_ReadCompare ******************************************************************************** * Summary: * Returns the compare value. * * Parameters: * void: * * Return: * (uint8) Present compare value. * *******************************************************************************/ uint8 hallTickCounter_ReadCompare(void) { return (CY_GET_REG8(hallTickCounter_COMPARE_LSB_PTR)); }
int main() { // This must be more dynamic in the future, but right now this IOREF is only used for the analog switches in the 10-pin connector // (UART pins are handled by SIORefGen, and that voltage has to be lower than this IORef voltage) //#define DYN_IOREF #ifdef DYN_IOREF // ~1.0V to 4.1V vref IOVoltGen_Start(); IOVoltGen_SetValue(0x80); IOVoltBuffer_Start(); #else // Results in 5V vref VDDIO2ref_SetDriveMode(VDDIO2ref_DM_STRONG); VDDIO2ref_Write(1); #endif NV_Init(); SIORefGen_Start(); SIORefGen_SetValue(62); // 1V GPIO_SetTXDrive(0); debuguart1_init(); CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */ CyPins_ClearPin(LED_Status_0); CyPins_SetPin(FanEna_0); if(NVREAD->USBserial[0] != 0 && NVREAD->USBserial[0] != 0xff) { for(uint8_t loopah=0; loopah<8; loopah++) { mySerial[2 + (loopah<<1)] = NVREAD->USBserial[loopah]; // Update USB descriptor Unicode values with our ASCII } USBFS_1_SerialNumString(mySerial); } USB_Init(); CyDelay(500); CyPins_ClearPin(FanEna_0); targetuart_init(); #ifdef SPECIAL_EDITION // Note that VtargetRef is in the 5V quadrant so that pin will always // output 5V when set high, no matter what the IOREF is set to! GPIO_SetPinState( TREF_PIN7, PIN_OUT_HIGH ); // Output on Vref GPIO_SetPinState( DFMS_PIN8, PIN_UART_TX ); // Send on DFMS pin, recv on DTMS! GPIO_SetPinState( DTMS_PIN9, PIN_UART_RX ); #else GPIO_SetPinState( DTMS_PIN9, PIN_UART_TX ); // Send on DTMS pin, recv on DFMS! GPIO_SetPinState( DFMS_PIN8, PIN_UART_RX ); #endif printf("\n\nWJ CDB Assist v3 controller init\n"); FB_init(); FB_clear(); disp_str("CDB ASSIST V3",13,(64-39),0,FONT6X6 | INVERT); disp_str("Sony Mobile",11,(64-33),64-12,FONT6X6); #ifdef SPECIAL_EDITION disp_str("Calibration Edition",19,(64-57),64-6,FONT6X6); #else disp_str("Open Devices",12,(64-36),64-6,FONT6X6); #endif FB_update(); GPIO_Init(); DummyLoad_Init(); USBMux_Init(); I2C_Init(); PWM_Init(); ADC_Init(); uint16_t ctr=0; for(;;) { char buffah[22]; uint8_t num; float vbatvolt,vbatcur,vbusvolt,vbuscur; I2C_Work(); vbatvolt=(float)I2C_Get_VBAT_VoltAvg() * 0.001f; vbatcur=I2C_Get_VBAT_CurAvg(); PWM_Work(I2C_Get_VBAT_Volt(),I2C_Get_VBAT_CurRaw()); DummyLoad_Work(I2C_Get_VBAT_Volt()); ADC_Work(); uint8_t vrefok = ADC_VtargetValid(); static uint8_t oldvrefok = 2; if( vrefok != oldvrefok ) { if( vrefok ) { CyPins_ClearPin(LED_Vref_0); GPIO_SetTXDrive( 1 ); } else { CyPins_SetPin(LED_Vref_0); GPIO_SetTXDrive( 0 ); SIORefGen_SetValue(62); // Default 1V ref } oldvrefok = vrefok; } if(ctr == 0) { vbusvolt=(float)I2C_Get_VBUS_Volt() * 0.001f; vbuscur=I2C_Get_VBUS_Cur(); USBMux_UpdateMeasurements(vbusvolt,vbuscur); num = snprintf(buffah, sizeof(buffah), "VBAT %5.2fV %6.1fmA", vbatvolt,vbatcur); disp_str(buffah, num, 0, 8, FONT6X6); num = snprintf(buffah, sizeof(buffah), "VBUS %5.2fV %6.1fmA", vbusvolt,vbuscur); disp_str(buffah, num, 0, 8+6, FONT6X6); DummyLoad_ADCWork(); float loadcur = DummyLoad_GetCur(); float loadtemp = DummyLoad_GetTemp(); num = snprintf(buffah, sizeof(buffah), "Load %5.1f` %6.1fmA", loadtemp,loadcur); disp_str(buffah, num, 0, 8+12, FONT6X6); float tmp = ADC_GetVoltage(VBATSENSE); num = snprintf(buffah, sizeof(buffah), "VBAT %5.2fV", tmp); disp_str(buffah, num, 0, 8+18, FONT6X6); tmp = ADC_GetVoltage(USB2SENSE); num = snprintf(buffah, sizeof(buffah), "USB2 %5.2fV", tmp); disp_str(buffah, num, 0, 8+24, FONT6X6); tmp = ADC_GetVoltage(USB3SENSE); num = snprintf(buffah, sizeof(buffah), "USB3 %5.2fV", tmp); disp_str(buffah, num, 0, 8+30, FONT6X6); tmp = ADC_GetVoltage(VTARGETSENSE); if( tmp > 4.5f ) { // Assume 5V, disable regulated output CY_SET_REG8(DTMS__SIO_CFG, (CY_GET_REG8(DTMS__SIO_CFG) & 0xcf) | 0x20); CY_SET_REG8(DTMS__SIO_DIFF, (CY_GET_REG8(DTMS__SIO_DIFF) & 0xcf) | 0x00); CY_SET_REG8(DTMS__SIO_HYST_EN, (CY_GET_REG8(DTMS__SIO_HYST_EN) & 0xcf) | 0x00); } else if( tmp > 0.89f ) { float val = tmp * 255.0f / 4.096f; if(val > 255.0f) val = 255.0f; SIORefGen_SetValue((uint8_t)val); CY_SET_REG8(DTMS__SIO_CFG, (CY_GET_REG8(DTMS__SIO_CFG) & 0xcf) | 0x30); // Regulated output buffer CY_SET_REG8(DTMS__SIO_DIFF, (CY_GET_REG8(DTMS__SIO_DIFF) & 0xcf) | 0x20); CY_SET_REG8(DTMS__SIO_HYST_EN, (CY_GET_REG8(DTMS__SIO_HYST_EN) & 0xcf) | 0x20); } num = snprintf(buffah, sizeof(buffah), "VTGT %5.2fV", tmp); disp_str(buffah, num, 0, 8+36, FONT6X6); FB_update(); UpdateCtrl(); ctr=256; } else { ctr--; } USB_Work(); } }
/******************************************************************************* * FUNCTION NAME: LED1_ReadPulse1 ******************************************************************************** * * Summary: * Reads the PrISM Pulse Density1 register. * * Parameters: * None. * * Return: * Pulse Density1 register value. * *******************************************************************************/ uint8 LED1_ReadPulse1(void) { return( CY_GET_REG8(LED1_DENSITY1_PTR) ); }
/******************************************************************************* * FUNCTION NAME: LED1_ReadPolynomial ******************************************************************************** * * Summary: * Reads the PrISM polynomial. * * Parameters: * None. * * Return: * PrISM polynomial. * *******************************************************************************/ uint8 LED1_ReadPolynomial(void) { return( CY_GET_REG8(LED1_POLYNOM_PTR) ); }
/******************************************************************************* * FUNCTION NAME: LED1_ReadSeed ******************************************************************************** * * Summary: * Reads the PrISM Seed register. * * Parameters: * None. * * Return: * Current Period register value. * *******************************************************************************/ uint8 LED1_ReadSeed(void) { return( CY_GET_REG8(LED1_SEED_PTR) ); }
/******************************************************************************* * Function Name: pwm_ReadCapture ******************************************************************************** * * Summary: * Reads the capture value from the capture FIFO. * * Parameters: * None * * Return: * uint8/uint16: The current capture value * *******************************************************************************/ uint8 pwm_ReadCapture(void) { return (CY_GET_REG8(pwm_CAPTURE_LSB_PTR)); }
/******************************************************************************* * Function Name: Counter_reset_gen_ReadCompare ******************************************************************************** * Summary: * Returns the compare value. * * Parameters: * void: * * Return: * (uint8) Present compare value. * *******************************************************************************/ uint8 Counter_reset_gen_ReadCompare(void) { return (CY_GET_REG8(Counter_reset_gen_COMPARE_LSB_PTR)); }
/******************************************************************************* * Function Name: pwm_ReadCompare2 ******************************************************************************** * * Summary: * Reads the compare value for the compare2 output. * * Parameters: * None * * Return: * uint8/uint16: Current compare value. * *******************************************************************************/ uint8 pwm_ReadCompare2(void) { return (CY_GET_REG8(pwm_COMPARE2_LSB_PTR)); }
/******************************************************************************* * Function Name: CsBtns_PWM_ReadStatusRegister ******************************************************************************** * * Summary: * This function returns the current state of the status register. * * Parameters: * None * * Return: * uint8 : Current status register value. The status register bits are: * [7:6] : Unused(0) * [5] : Kill event output * [4] : FIFO not empty * [3] : FIFO full * [2] : Terminal count * [1] : Compare output 2 * [0] : Compare output 1 * *******************************************************************************/ uint8 CsBtns_PWM_ReadStatusRegister(void) { return (CY_GET_REG8(CsBtns_PWM_STATUS_PTR)); }
/******************************************************************************* * FUNCTION NAME: RedGreenPrISM_ReadSeed ******************************************************************************** * * Summary: * Reads the PrISM Seed register. * * Parameters: * None. * * Return: * Current Period register value. * *******************************************************************************/ uint8 RedGreenPrISM_ReadSeed(void) { return( CY_GET_REG8(RedGreenPrISM_SEED_PTR) ); }
/******************************************************************************* * Function Name: CsBtns_PWM_ReadKillTime ******************************************************************************** * * Summary: * Reads the kill time value used by the hardware when the Kill Mode is set * to Minimum Time. * * Parameters: * None * * Return: * uint8: The current Minimum Time kill counts * *******************************************************************************/ uint8 CsBtns_PWM_ReadKillTime(void) { return (CY_GET_REG8(CsBtns_PWM_KILLMODEMINTIME_PTR)); }
/******************************************************************************* * FUNCTION NAME: RedGreenPrISM_ReadPulse1 ******************************************************************************** * * Summary: * Reads the PrISM Pulse Density1 register. * * Parameters: * None. * * Return: * Pulse Density1 register value. * *******************************************************************************/ uint8 RedGreenPrISM_ReadPulse1(void) { return( CY_GET_REG8(RedGreenPrISM_DENSITY1_PTR) ); }
/******************************************************************************* * FUNCTION NAME: PrISM_1_ReadPulse0 ******************************************************************************** * * Summary: * Reads the PrISM Pulse Density0 register. * * Parameters: * None. * * Return: * Pulse Density0 register value. * *******************************************************************************/ uint8 PrISM_1_ReadPulse0(void) { return( CY_GET_REG8(PrISM_1_DENSITY0_PTR) ); }
/******************************************************************************* * FUNCTION NAME: PrISM_2_ReadPolynomial ******************************************************************************** * * Summary: * Reads the PrISM polynomial. * * Parameters: * None. * * Return: * PrISM polynomial. * *******************************************************************************/ uint8 PrISM_2_ReadPolynomial(void) { return( CY_GET_REG8(PrISM_2_POLYNOM_PTR) ); }
void cyfitter_cfg(void) { #ifdef CYGlobalIntDisable /* Disable interrupts by default. Let user enable if/when they want. */ CYGlobalIntDisable #endif /* Enable/Disable Debug functionality based on settings from System DWR */ CY_SET_XTND_REG8((void CYFAR *)CYREG_MLOGIC_DEBUG, (CY_GET_XTND_REG8((void CYFAR *)CYREG_MLOGIC_DEBUG) | 0x04u)); { CYPACKED typedef struct { void CYFAR *address; uint16 size; } CYPACKED_ATTR cfg_memset_t; static const cfg_memset_t CYCODE cfg_memset_list [] = { /* address, size */ {(void CYFAR *)(CYREG_TMR0_CFG0), 12u}, {(void CYFAR *)(CYREG_PRT0_DR), 32u}, {(void CYFAR *)(CYREG_PRT3_DR), 32u}, {(void CYFAR *)(CYREG_PRT12_DR), 16u}, {(void CYFAR *)(CYDEV_UCFG_B0_P0_U0_BASE), 4096u}, {(void CYFAR *)(CYDEV_UCFG_B1_P2_U0_BASE), 2048u}, {(void CYFAR *)(CYDEV_UCFG_DSI0_BASE), 2560u}, {(void CYFAR *)(CYDEV_UCFG_DSI12_BASE), 512u}, {(void CYFAR *)(CYREG_BCTL0_MDCLK_EN), 32u}, }; uint8 CYDATA i; /* Zero out critical memory blocks before beginning configuration */ for (i = 0u; i < (sizeof(cfg_memset_list)/sizeof(cfg_memset_list[0])); i++) { const cfg_memset_t CYCODE * CYDATA ms = &cfg_memset_list[i]; CYMEMZERO(ms->address, (size_t)(uint32)(ms->size)); } cfg_write_bytes32(cy_cfg_addr_table, cy_cfg_data_table); /* Perform normal device configuration. Order is not critical for these items. */ CY_SET_XTND_REG16((void CYFAR *)(CYREG_LUT0_CR), 0x0003u); CY_SET_XTND_REG16((void CYFAR *)(CYREG_LUT1_CR), 0x0103u); CY_SET_XTND_REG16((void CYFAR *)(CYREG_LUT3_CR), 0x0303u); /* Enable digital routing */ CY_SET_XTND_REG8((void CYFAR *)CYREG_BCTL0_BANK_CTL, CY_GET_XTND_REG8((void CYFAR *)CYREG_BCTL0_BANK_CTL) | 0x02u); CY_SET_XTND_REG8((void CYFAR *)CYREG_BCTL1_BANK_CTL, CY_GET_XTND_REG8((void CYFAR *)CYREG_BCTL1_BANK_CTL) | 0x02u); /* Enable UDB array */ CY_SET_XTND_REG8((void CYFAR *)CYREG_PM_ACT_CFG0, CY_GET_XTND_REG8((void CYFAR *)CYREG_PM_ACT_CFG0) | 0x40u); CY_SET_XTND_REG8((void CYFAR *)CYREG_PM_AVAIL_CR2, CY_GET_XTND_REG8((void CYFAR *)CYREG_PM_AVAIL_CR2) | 0x10u); } /* Perform second pass device configuration. These items must be configured in specific order after the regular configuration is done. */ CYCONFIGCPY((void CYFAR *)(CYREG_PRT15_DR), (const void CYFAR *)(BS_IOPINS0_8_VAL), 10u); CYCONFIGCPY((void CYFAR *)(CYREG_PRT2_DR), (const void CYFAR *)(BS_IOPINS0_2_VAL), 10u); CYCONFIGCPY((void CYFAR *)(CYREG_PRT5_DM0), (const void CYFAR *)(BS_IOPINS0_5_VAL), 8u); CYCONFIGCPY((void CYFAR *)(CYREG_PRT6_DR), (const void CYFAR *)(BS_IOPINS0_6_VAL), 10u); /* Switch Boost to the precision bandgap reference from its internal reference */ CY_SET_REG8((void CYXDATA *)CYREG_BOOST_CR2, (CY_GET_REG8((void CYXDATA *)CYREG_BOOST_CR2) | 0x08u)); /* Set Flash Cycles based on max possible frequency in case a glitch occurs during ClockSetup(). */ CY_SET_XTND_REG8((void CYFAR *)(CYREG_CACHE_CC_CTL), (((CYDEV_INSTRUCT_CACHE_ENABLED) != 0) ? 0x01u : 0x00u)); /* Setup clocks based on selections from Clock DWR */ ClockSetup(); /* Set Flash Cycles based on newly configured 12.00MHz Bus Clock. */ CY_SET_XTND_REG8((void CYFAR *)(CYREG_CACHE_CC_CTL), (((CYDEV_INSTRUCT_CACHE_ENABLED) != 0) ? 0x41u : 0x40u)); CY_SET_XTND_REG8((void CYFAR *)(CYREG_PANTHER_WAITPIPE), 0x01u); /* Perform basic analog initialization to defaults */ AnalogSetDefault(); /* Configure alternate active mode */ CYCONFIGCPY((void CYFAR *)CYDEV_PM_STBY_BASE, (const void CYFAR *)CYDEV_PM_ACT_BASE, 14u); }
/******************************************************************************* * Function Name: USBUART_1_DispatchHIDClassRqst ******************************************************************************** * * Summary: * This routine dispatches class requests * * Parameters: * None. * * Return: * requestHandled * * Reentrant: * No. * *******************************************************************************/ uint8 USBUART_1_DispatchHIDClassRqst(void) { uint8 requestHandled = USBUART_1_FALSE; uint8 interfaceNumber; interfaceNumber = CY_GET_REG8(USBUART_1_wIndexLo); if ((CY_GET_REG8(USBUART_1_bmRequestType) & USBUART_1_RQST_DIR_MASK) == USBUART_1_RQST_DIR_D2H) { /* Control Read */ switch (CY_GET_REG8(USBUART_1_bRequest)) { case USBUART_1_GET_DESCRIPTOR: if (CY_GET_REG8(USBUART_1_wValueHi) == USBUART_1_DESCR_HID_CLASS) { USBUART_1_FindHidClassDecriptor(); if (USBUART_1_currentTD.count != 0u) { requestHandled = USBUART_1_InitControlRead(); } } else if (CY_GET_REG8(USBUART_1_wValueHi) == USBUART_1_DESCR_HID_REPORT) { USBUART_1_FindReportDescriptor(); if (USBUART_1_currentTD.count != 0u) { requestHandled = USBUART_1_InitControlRead(); } } else { /* requestHandled is initialezed as FALSE by default */ } break; case USBUART_1_HID_GET_REPORT: USBUART_1_FindReport(); if (USBUART_1_currentTD.count != 0u) { requestHandled = USBUART_1_InitControlRead(); } break; case USBUART_1_HID_GET_IDLE: /* This function does not support multiple reports per interface*/ /* Validate interfaceNumber and Report ID (should be 0) */ if( (interfaceNumber < USBUART_1_MAX_INTERFACES_NUMBER) && (CY_GET_REG8(USBUART_1_wValueLo) == 0u ) ) /* Do not support Idle per Report ID */ { USBUART_1_currentTD.count = 1u; USBUART_1_currentTD.pData = &USBUART_1_hidIdleRate[interfaceNumber]; requestHandled = USBUART_1_InitControlRead(); } break; case USBUART_1_HID_GET_PROTOCOL: /* Validate interfaceNumber */ if( interfaceNumber < USBUART_1_MAX_INTERFACES_NUMBER) { USBUART_1_currentTD.count = 1u; USBUART_1_currentTD.pData = &USBUART_1_hidProtocol[interfaceNumber]; requestHandled = USBUART_1_InitControlRead(); } break; default: /* requestHandled is initialized as FALSE by default */ break; } } else if ((CY_GET_REG8(USBUART_1_bmRequestType) & USBUART_1_RQST_DIR_MASK) == USBUART_1_RQST_DIR_H2D) { /* Control Write */ switch (CY_GET_REG8(USBUART_1_bRequest)) { case USBUART_1_HID_SET_REPORT: USBUART_1_FindReport(); if (USBUART_1_currentTD.count != 0u) { requestHandled = USBUART_1_InitControlWrite(); } break; case USBUART_1_HID_SET_IDLE: /* This function does not support multiple reports per interface */ /* Validate interfaceNumber and Report ID (should be 0) */ if( (interfaceNumber < USBUART_1_MAX_INTERFACES_NUMBER) && (CY_GET_REG8(USBUART_1_wValueLo) == 0u ) ) /* Do not support Idle per Report ID */ { USBUART_1_hidIdleRate[interfaceNumber] = CY_GET_REG8(USBUART_1_wValueHi); /* With regards to HID spec: "7.2.4 Set_Idle Request" * Latency. If the current period has gone past the * newly proscribed time duration, then a report * will be generated immediately. */ if(USBUART_1_hidIdleRate[interfaceNumber] < USBUART_1_hidIdleTimer[interfaceNumber]) { /* Set the timer to zero and let the UpdateHIDTimer() API return IDLE_TIMER_EXPIRED status*/ USBUART_1_hidIdleTimer[interfaceNumber] = 0u; } /* If the new request is received within 4 milliseconds * (1 count) of the end of the current period, then the * new request will have no effect until after the report. */ else if(USBUART_1_hidIdleTimer[interfaceNumber] <= 1u) { /* Do nothing. * Let the UpdateHIDTimer() API continue to work and * return IDLE_TIMER_EXPIRED status */ } else { /* Reload the timer*/ USBUART_1_hidIdleTimer[interfaceNumber] = USBUART_1_hidIdleRate[interfaceNumber]; } requestHandled = USBUART_1_InitNoDataControlTransfer(); } break; case USBUART_1_HID_SET_PROTOCOL: /* Validate interfaceNumber and protocol (must be 0 or 1) */ if( (interfaceNumber < USBUART_1_MAX_INTERFACES_NUMBER) && (CY_GET_REG8(USBUART_1_wValueLo) <= 1u) ) { USBUART_1_hidProtocol[interfaceNumber] = CY_GET_REG8(USBUART_1_wValueLo); requestHandled = USBUART_1_InitNoDataControlTransfer(); } break; default: /* requestHandled is initialized as FALSE by default */ break; } } else { /* requestHandled is initialized as FALSE by default */ } return(requestHandled); }
/******************************************************************************* * Function Name: USB_Bootloader_Suspend ******************************************************************************** * * Summary: * This function disables the USBFS block and prepares for power donwn mode. * * Parameters: * None. * * Return: * None. * * Global variables: * USB_Bootloader_backup.enable: modified. * * Reentrant: * No. * *******************************************************************************/ void USB_Bootloader_Suspend(void) { uint8 enableInterrupts; enableInterrupts = CyEnterCriticalSection(); if((CY_GET_REG8(USB_Bootloader_CR0_PTR) & USB_Bootloader_CR0_ENABLE) != 0u) { /* USB block is enabled */ USB_Bootloader_backup.enableState = 1u; #if(USB_Bootloader_EP_MM != USB_Bootloader__EP_MANUAL) USB_Bootloader_Stop_DMA(USB_Bootloader_MAX_EP); /* Stop all DMAs */ #endif /* End USB_Bootloader_EP_MM != USB_Bootloader__EP_MANUAL */ #if(CY_PSOC3_ES2 || CY_PSOC5_ES1) /* Disable USBIO for TO3 */ USB_Bootloader_PM_AVAIL_CR_REG &= ~USB_Bootloader_PM_AVAIL_EN_FSUSBIO; #endif /* End CY_PSOC3_ES2 || CY_PSOC5_ES1 */ /* Power Down Sequencing for USBIO for TO4*/ #if(CY_PSOC3_ES3 || CY_PSOC5_ES2) /* Ensure USB transmit enable is low (USB_USBIO_CR0.ten). - Manual Transmission - Disabled */ USB_Bootloader_USBIO_CR0_REG &= ~USB_Bootloader_USBIO_CR0_TEN; CyDelayUs(0); /*~50ns delay */ /* Disable the USBIO by asserting PM.USB_CR0.fsusbio_pd_n(Inverted) and pd_pullup_hv(Inverted) high. */ USB_Bootloader_PM_USB_CR0_REG &= \ ~(USB_Bootloader_PM_USB_CR0_PD_N | USB_Bootloader_PM_USB_CR0_PD_PULLUP_N); #endif /* End CY_PSOC3_ES3 || CY_PSOC5_ES2 */ /* Disable the SIE */ USB_Bootloader_CR0_REG &= ~USB_Bootloader_CR0_ENABLE; #if(CY_PSOC3_ES3 || CY_PSOC5_ES2) CyDelayUs(0); /*~50ns delay */ /* Store mode and Disable VRegulator*/ USB_Bootloader_backup.mode = USB_Bootloader_CR1_REG & USB_Bootloader_CR1_REG_ENABLE; USB_Bootloader_CR1_REG &= ~USB_Bootloader_CR1_REG_ENABLE; CyDelayUs(1); /* 0.5 us min delay */ /* Disable the USBIO reference by setting PM.USB_CR0.fsusbio_ref_en.*/ USB_Bootloader_PM_USB_CR0_REG &= ~USB_Bootloader_PM_USB_CR0_REF_EN; /* Switch DP and DM terminals to GPIO mode and disconnect 1.5k pullup*/ USB_Bootloader_USBIO_CR1_REG |= USB_Bootloader_USBIO_CR1_IOMODE; #endif /* End CY_PSOC3_ES3 || CY_PSOC5_ES2*/ /* Disable USB in ACT PM */ USB_Bootloader_PM_ACT_CFG_REG &= ~USB_Bootloader_PM_ACT_EN_FSUSB; /* Disable USB block for Standby Power Mode */ USB_Bootloader_PM_STBY_CFG_REG &= ~USB_Bootloader_PM_STBY_EN_FSUSB; CyDelayUs(1); /* min 0.5us delay required */ } else { USB_Bootloader_backup.enableState = 0u; } CyExitCriticalSection(enableInterrupts); /* Set the DP Interrupt for wake-up from sleep mode. */ #if(USB_Bootloader_DP_ISR_REMOVE == 0u) CyIntSetVector(USB_Bootloader_DP_INTC_VECT_NUM, USB_Bootloader_DP_ISR); CyIntSetPriority(USB_Bootloader_DP_INTC_VECT_NUM, USB_Bootloader_DP_INTC_PRIOR); CyIntClearPending(USB_Bootloader_DP_INTC_VECT_NUM); CyIntEnable(USB_Bootloader_DP_INTC_VECT_NUM); #endif /* End USB_Bootloader_DP_ISR_REMOVE */ }
/******************************************************************************* * Function Name: PWM_3_ReadCapture ******************************************************************************** * * Summary: * Reads the capture value from the capture FIFO. * * Parameters: * None * * Return: * uint8/uint16: The current capture value * *******************************************************************************/ uint8 PWM_3_ReadCapture(void) { return (CY_GET_REG8(PWM_3_CAPTURE_LSB_PTR)); }
/******************************************************************************* * Function Name: pwm_ReadStatusRegister ******************************************************************************** * * Summary: * This function returns the current state of the status register. * * Parameters: * None * * Return: * uint8 : Current status register value. The status register bits are: * [7:6] : Unused(0) * [5] : Kill event output * [4] : FIFO not empty * [3] : FIFO full * [2] : Terminal count * [1] : Compare output 2 * [0] : Compare output 1 * *******************************************************************************/ uint8 pwm_ReadStatusRegister(void) { return (CY_GET_REG8(pwm_STATUS_PTR)); }
/******************************************************************************* * Function Name: PWM_3_ReadKillTime ******************************************************************************** * * Summary: * Reads the kill time value used by the hardware when the Kill Mode is set * to Minimum Time. * * Parameters: * None * * Return: * uint8: The current Minimum Time kill counts * *******************************************************************************/ uint8 PWM_3_ReadKillTime(void) { return (CY_GET_REG8(PWM_3_KILLMODEMINTIME_PTR)); }
/******************************************************************************* * Function Name: ChargeDelay_ReadKillTime ******************************************************************************** * * Summary: * Reads the kill time value used by the hardware when the Kill Mode is set * to Minimum Time. * * Parameters: * None * * Return: * uint8: The current Minimum Time kill counts * *******************************************************************************/ uint8 ChargeDelay_ReadKillTime(void) { return (CY_GET_REG8(ChargeDelay_KILLMODEMINTIME_PTR)); }