/*---------------------------------------------------------------------------* * Routine: UEZPlatform_Speaker_Require *---------------------------------------------------------------------------* * Description: * Setup the Speaker device driver *---------------------------------------------------------------------------*/ void UEZPlatform_Speaker_Require(void) { const T_ToneGenerator_Generic_PWM_Settings settings = { "PWM_TPU0", 1, GPIO_NONE, 0, 0, }; T_uezDevice pwmDevice; DEVICE_CREATE_ONCE(); UEZPlatform_PWM_TPU0_Require(); UEZDeviceTableFind("PWM_TPU0", &pwmDevice); // The PWM Speaker is output by setting and clearing a GPIO pin // through software by using Callback routines. UEZGPIOClear(GPIO_P17); // AUD_R UEZGPIOOutput(GPIO_P17); UEZGPIOClear(GPIO_PA0); // AUD_L UEZGPIOOutput(GPIO_PA0); UEZGPIOSet(GPIO_PA2); // AMP UEZGPIOOutput(GPIO_PA2); UEZPWMSetMatchCallback(pwmDevice, 0, UEZPlatform_SpeakerMasterCallback, 0); UEZPWMSetMatchCallback(pwmDevice, 1, UEZPlatform_SpeakerMatchCallback, 0); ToneGenerator_Generic_PWM_Create("Speaker", &settings); }
/*---------------------------------------------------------------------------* * Routine: UEZGUI_EXP_DK_FullDuplex_RS485_Require *---------------------------------------------------------------------------* * Description: * Setup a full duplex RS485 connection. *---------------------------------------------------------------------------*/ void UEZGUI_EXP_DK_FullDuplex_RS485_Require( TUInt32 aWriteBufferSize, TUInt32 aReadBufferSize) { // Need UART A without a stream UEZPlatform_ExpansionPrimary_UART_A_Require(); // Ensure the drive enable pin is always HIGH if (GPIO_EXPDK_485DE != GPIO_NONE) { UEZGPIOSetMux(GPIO_EXPDK_485DE, 0); UEZGPIOSet(GPIO_EXPDK_485DE); UEZGPIOOutput(GPIO_EXPDK_485DE); UEZGPIOLock(GPIO_EXPDK_485DE); } // Ensure the receive enable pin is always low if (GPIO_EXPDK_485RE != GPIO_NONE) { // Drive enable pin must be LOW UEZGPIOSetMux(GPIO_EXPDK_485RE, 0); UEZGPIOClear(GPIO_EXPDK_485RE); UEZGPIOOutput(GPIO_EXPDK_485RE); UEZGPIOLock(GPIO_EXPDK_485RE); } Serial_Generic_FullDuplex_Stream_Create("EXP_RS485", PRIMARY_EXPANSION_UART_A, aWriteBufferSize, aReadBufferSize); }
/*---------------------------------------------------------------------------* * Routine: SetLevel *---------------------------------------------------------------------------* * Description: * Set the gain of the audio amp to the desired level * Inputs: * void *aWorkspace * TUInt8 aLevel --new level to set the amp to * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError AudioAmp_8551T_SetLevel(void *aWorkSpace, TUInt8 aLevel) { T_AudioAmp_8551T_Workspace *p = (T_AudioAmp_8551T_Workspace *)aWorkSpace; TUInt8 i, setLevel, oldLevel; UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE); oldLevel = ((((p->iLevel * 100) / (0xFF)) * (p->iMaxLevel - p->iMinLevel))/100) + p->iMinLevel; p->iLevel = aLevel; setLevel = ((p->iLevel * (p->iMaxLevel - p->iMinLevel))/0xFF) + p->iMinLevel; UEZGPIOSetMux(p->iVolumeGPIO, 0); // set to GPIO if (setLevel != oldLevel) { if (oldLevel < setLevel) { for (i = oldLevel; i < setLevel; i++) { UEZGPIOSet(p->iVolumeGPIO); //set High to go up UEZGPIOOutput(p->iVolumeGPIO); //set to output if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOSet(p->iVolEnableGPIO); UEZTaskDelay(1); if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOClear(p->iVolEnableGPIO); UEZGPIOInput(p->iVolumeGPIO); UEZGPIOClear(p->iVolumeGPIO); UEZGPIOSetPull(p->iVolumeGPIO, GPIO_PULL_NONE); UEZTaskDelay(1); } } else { for (i = oldLevel; i > setLevel; i--) { UEZGPIOClear(p->iVolumeGPIO); //set low to go down UEZGPIOOutput(p->iVolumeGPIO); //set to output if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOSet(p->iVolEnableGPIO); UEZTaskDelay(1); if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOClear(p->iVolEnableGPIO); UEZGPIOInput(p->iVolumeGPIO); UEZGPIOSetPull(p->iVolumeGPIO, GPIO_PULL_NONE); UEZTaskDelay(1); } } p->iLevel = aLevel; } if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOClear(p->iVolEnableGPIO); UEZSemaphoreRelease(p->iSem); return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: Open *---------------------------------------------------------------------------* * Description: * Initalizes pins for the audio amp * turns it on * sets the level to the default * Inputs: * void *aWorkSpace * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError AudioAmp_8551T_Open(void *aWorkSpace) { T_AudioAmp_8551T_Workspace *p = (T_AudioAmp_8551T_Workspace *)aWorkSpace; TUInt8 i, setLevel; UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE); p->iNumOpen++; if (!(p->iIsOn)) { setLevel = ((p->iLevel * (p->iMaxLevel - p->iMinLevel))/0xFF) + p->iMinLevel; p->iIsOn = ETrue; UEZGPIOOutput(p->iModeGPIO); UEZGPIOSetMux(p->iModeGPIO, 0); // set to GPIO UEZGPIOClear(p->iModeGPIO); // Turn on the amp UEZGPIOOutput(p->iVolumeGPIO); UEZGPIOSetMux(p->iVolumeGPIO, 0); // set to GPIO for (i = HIGH_LEVEL; i > 0; i--) { UEZGPIOClear(p->iVolumeGPIO); // set low to go down UEZGPIOOutput(p->iVolumeGPIO); // set to output if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOSet(p->iVolEnableGPIO); UEZTaskDelay(1); if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOClear(p->iVolEnableGPIO); UEZGPIOInput(p->iVolumeGPIO); // set to input UEZGPIOSetPull(p->iVolumeGPIO, GPIO_PULL_NONE); UEZTaskDelay(1); } for (i = LOW_LEVEL; i < setLevel; i++) { UEZGPIOSet(p->iVolumeGPIO); // set low to go down UEZGPIOOutput(p->iVolumeGPIO); // set to output if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOSet(p->iVolEnableGPIO); UEZTaskDelay(1); if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOClear(p->iVolEnableGPIO); UEZGPIOInput(p->iVolumeGPIO); // set to input UEZGPIOSetPull(p->iVolumeGPIO, GPIO_PULL_NONE); UEZTaskDelay(1); } } if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOClear(p->iVolEnableGPIO); UEZSemaphoreRelease(p->iSem); return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: LCD_RH320240T_Open *---------------------------------------------------------------------------* * Description: * Start the LCD screen. If this is the first open, initialize the * screen. * Inputs: * void *aW -- Workspace * Outputs: * T_uezError -- If the device is opened, returns * UEZ_ERROR_NONE. *---------------------------------------------------------------------------*/ T_uezError LCD_RH320240T_Open(void *aW) { T_RH320240TWorkspace *p = (T_RH320240TWorkspace *)aW; HAL_LCDController **plcdc; T_uezError error = UEZ_ERROR_NONE; p->aNumOpen++; if (p->aNumOpen == 1) { plcdc = p->iLCDController; // Choose a settings based on the configuration switch (p->iConfiguration->iColorDepth) { case UEZLCD_COLOR_DEPTH_8_BIT: LCD_RH320240T_settings = LCD_RH320240T_params8bit; break; default: case UEZLCD_COLOR_DEPTH_16_BIT: LCD_RH320240T_settings = LCD_RH320240T_params16bit; break; case UEZLCD_COLOR_DEPTH_I15_BIT: LCD_RH320240T_settings = LCD_RH320240T_paramsI15bit; break; } LCD_RH320240T_settings.iBaseAddress = p->iBaseAddress; // Turn on LCD controller and output power pin // Programs SPI first after power up error = (*plcdc)->Configure(plcdc, &LCD_RH320240T_settings); // Testing (*p->iLCDController)->On(p->iLCDController); // turns on data next UEZGPIOSetMux(p->iSHUTGPIOPin, 0); UEZGPIOSet(p->iSHUTGPIOPin); UEZGPIOOutput(p->iSHUTGPIOPin); // Drop SHUT down to be a low (active) UEZGPIOClear(p->iSHUTGPIOPin); // What does data enable pin do? high or low? It doesn't appear to be needed. // UEZGPIOSetMux(p->iENBGPIOPin, 0); // UEZGPIOClear(p->iENBGPIOPin); // UEZGPIOSet(p->iENBGPIOPin); // UEZGPIOOutput(p->iENBGPIOPin); // Configure SPI LCD_ConfigureSPI(p); return error; } return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: uEZPlatformStartup *---------------------------------------------------------------------------* * Description: * When uEZ starts, a special Startup task is created and called. * This task brings up the all the hardware, reports any problems, * starts the main task, and then exits. *---------------------------------------------------------------------------*/ TUInt32 uEZPlatformStartup(T_uezTask aMyTask, void *aParameters) { extern T_uezTask G_mainTask; UEZPlatform_Standard_Require(); SUIInitialize(SIMPLEUI_DOUBLE_SIZED_ICONS, EFalse, EFalse); // SWIM not flipped // USB Flash drive host mode needed? #if USB_PORT_B_HOST_DETECT_ENABLED UEZGPIOLock(GPIO_P0_12); UEZGPIOSet(GPIO_P0_12); // disable MIC2025 UEZGPIOOutput(GPIO_P0_12); UEZGPIOInput(GPIO_P0_28); UEZGPIOSetMux(GPIO_P0_28, 0); G_usbIsDevice = UEZGPIORead(GPIO_P0_28); if (G_usbIsDevice) { // High for a device UEZPlatform_USBDevice_Require(); } else { // Low for a host #if UEZ_ENABLE_USB_HOST_STACK UEZPlatform_USBFlash_Drive_Require(0); #endif UEZGPIOClear(GPIO_P0_12); // enable MIC2025 } #else G_usbIsDevice = ETrue; // USB Device needed? UEZPlatform_USBDevice_Require(); #endif #if UEZ_ENABLE_USB_HOST_STACK // USB Host is required UEZPlatform_USBFlash_Drive_Require(0); #endif // SDCard needed? UEZPlatform_SDCard_Drive_Require(1); // Network needed? #if UEZ_ENABLE_WIRED_NETWORK UEZPlatform_WiredNetwork0_Require(); #endif // Create a main task (not running yet) UEZTaskCreate((T_uezTaskFunction)MainTask, "Main", MAIN_TASK_STACK_SIZE, 0, UEZ_PRIORITY_NORMAL, &G_mainTask); // Done with this task, fall out return 0; }
/*---------------------------------------------------------------------------* * Task: Heartbeat *---------------------------------------------------------------------------* * Description: * Blink heartbeat LED * Inputs: * T_uezTask aMyTask -- Handle to this task * void *aParams -- Parameters. Not used. * Outputs: * TUInt32 -- Never returns. *---------------------------------------------------------------------------*/ TUInt32 Heartbeat(T_uezTask aMyTask, void *aParams) { UEZGPIOOutput(GPIO_PD0); // Blink for (;;) { UEZGPIOSet(GPIO_PD0); UEZTaskDelay(250); UEZGPIOClear(GPIO_PD0); UEZTaskDelay(250); } return 0; }
/*---------------------------------------------------------------------------* * Routine: UEZGUI_EXP_DK_USB_Host_Port_B_Detect *---------------------------------------------------------------------------* * Description: * Detect USB Host mode on mini-AB port using OTG adapter ID pin to GND *---------------------------------------------------------------------------*/ TBool UEZGUI_EXP_DK_USB_Host_Port_B_Detect() { TBool IsDevice; UEZGPIOLock(GPIO_USB_HOST_ENABLE); // P0_12 on LPC1788 uEZGUIs UEZGPIOSet(GPIO_USB_HOST_ENABLE); // disable MIC2025 power for USB UEZGPIOOutput(GPIO_USB_HOST_ENABLE); UEZGPIOInput(GPIO_EXPDK_USBDID); UEZGPIOSetMux(GPIO_EXPDK_USBDID, 0); IsDevice = UEZGPIORead(GPIO_EXPDK_USBDID); if(!IsDevice){ UEZGPIOClear(GPIO_USB_HOST_ENABLE);// enable MIC2025 USB Power } return IsDevice; }
int CmdLED(void *aWorkspace, int argc, char *argv[]) { TUInt32 on; if (argc == 2) { on = FDICmdUValue(argv[1]); UEZGPIOOutput(GPIO_PE3); if (on) { UEZGPIOClear(GPIO_PE3); FDICmdPrintf(aWorkspace, "PASS: On\n"); } else { UEZGPIOSet(GPIO_PE3); FDICmdPrintf(aWorkspace, "PASS: Off\n"); } } else { FDICmdPrintf(aWorkspace, "FAIL: Incorrect parameters\n"); } return 0; }
/*---------------------------------------------------------------------------* * Routine: TS_EXC7200_Configure *---------------------------------------------------------------------------* * Description: * The SPI bus and GPIO device are being declared. * Inputs: * void *aW -- Particular SPI workspace * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError TS_EXC7200_Configure(T_uezDeviceWorkspace *aW) { T_EXC7200Workspace *p = (T_EXC7200Workspace *)aW; UEZSemaphoreGrab(p->iSemWaitForTouch, 0); UEZGPIOSetMux(p->iResetPin, 0);//Set to GPIO UEZGPIOOutput(p->iResetPin); UEZGPIOClear(p->iResetPin); UEZTaskDelay(1); UEZGPIOConfigureInterruptCallback( UEZ_GPIO_PORT_FROM_PORT_PIN(p->iInteruptPin), TS_EXC7200_InterruptISR, p); UEZGPIOEnableIRQ(p->iInteruptPin, GPIO_INTERRUPT_FALLING_EDGE); UEZGPIOSet(p->iResetPin); T_uezDevice i2c; I2C_Request request; T_uezError error; TUInt8 dataIn[10]; TUInt8 dataOut[10] = { 0x03, 0x06, 0x0A, 0x04, 0x36, 0x3f, 0x01, 9, 0, 0}; request.iAddr = EXC7200_I2C_ADDRESS; request.iSpeed = EXC7200_I2C_SPEED; request.iReadData = dataIn; request.iReadLength = 10; request.iWriteData = dataOut; request.iWriteLength = 10; UEZI2COpen(p->iI2CBus, &i2c); error = UEZI2CTransaction(i2c, &request); return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: Close *---------------------------------------------------------------------------* * Description: * Puts the device in standby when iNumOpen is 0 * Inputs: * void *aWorkSpace * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError AudioAmp_8551T_Close(void *aWorkSpace) { T_AudioAmp_8551T_Workspace *p = (T_AudioAmp_8551T_Workspace *)aWorkSpace; if (p->iIsOn) { p->iNumOpen--; } if (p->iNumOpen == 0) { UEZGPIOOutput(p->iModeGPIO); UEZGPIOSetMux(p->iModeGPIO, 0); // set to GPIO UEZGPIOSet(p->iModeGPIO); // set to standby p->iIsOn = EFalse; p->iIsMuted = EFalse; p->iLevel = DEFAULT_LEVEL; } if (p->iVolEnableGPIO != GPIO_NONE) UEZGPIOClear(p->iVolEnableGPIO); UEZSemaphoreRelease(p->iSem); return UEZ_ERROR_NONE; }
/*--------------------------------------------------------------------------*/ T_uezError GainSpan_CmdLib_ConfigureForSPI( const T_GainSpan_CmdLib_SPISettings *aSettings) { T_uezError error; ATLIBGS_MSG_ID_E r; int i; G_GSCmdLibSettings = *aSettings; G_GSSPITemplate.iBitsPerTransfer = 8; G_GSSPITemplate.iCSPolarity = EFalse; // Falling edge G_GSSPITemplate.iClockOutPolarity = EFalse; // Falling edge G_GSSPITemplate.iClockOutPhase = EFalse; // ETrue; G_GSSPITemplate.iDataMISO = 0; G_GSSPITemplate.iDataMISO = 0; G_GSSPITemplate.iNumTransferredIn = 0; G_GSSPITemplate.iNumTransferredOut = 0; G_GSSPITemplate.iRate = aSettings->iRate / 1000; G_GSSPITemplate.iCSGPIOPort = GPIO_TO_HAL_PORT(aSettings->iSPIChipSelect); G_GSSPITemplate.iCSGPIOBit = GPIO_TO_PIN_BIT(aSettings->iSPIChipSelect); error = UEZSPIOpen(G_GSCmdLibSettings.iSPIDeviceName, &G_GSSPI); if (error) return error; // Ensure these pins are not configured elsewhere UEZGPIOLock(G_GSCmdLibSettings.iDataReadyIO); if (G_GSCmdLibSettings.iSRSTn != GPIO_NONE ){ UEZGPIOLock(G_GSCmdLibSettings.iSRSTn); UEZGPIOOutput(G_GSCmdLibSettings.iSRSTn); // WIFI_SRSTn } UEZGPIOInput(G_GSCmdLibSettings.iDataReadyIO); // WIFI IRQ if (G_GSCmdLibSettings.iProgramMode != GPIO_NONE ) { UEZGPIOLock(G_GSCmdLibSettings.iProgramMode); UEZGPIOClear(G_GSCmdLibSettings.iProgramMode); // WIFI PROGRAM OFF UEZGPIOOutput(G_GSCmdLibSettings.iProgramMode); // WIFI PROGRAM OFF } if (G_GSCmdLibSettings.iSPIMode != GPIO_NONE ) { UEZGPIOLock(G_GSCmdLibSettings.iSPIMode); UEZGPIOSet(G_GSCmdLibSettings.iSPIMode); // WIFI_MODE SPI UEZGPIOOutput(G_GSCmdLibSettings.iSPIMode); // WIFI_MODE SPI } UEZTaskDelay(1250); if (G_GSCmdLibSettings.iSRSTn != GPIO_NONE ) UEZGPIOSet(G_GSCmdLibSettings.iSRSTn); // WIFI_SRSTn UEZTaskDelay(1000); // Initialize the GainSpan SPI routines GainSpan_SPI_Start(); // Flush anything there AtLibGs_FlushIncomingMessage(); /* Send command to check 5 times for module */ for (i = 0; i < 5; i++){ AtLibGs_FlushIncomingMessage(); r = AtLibGs_Check(GAINSPAN_AT_DEFAULT_TIMEOUT); if(ATLIBGS_MSG_ID_OK == r){ break; } } if(ATLIBGS_MSG_ID_RESPONSE_TIMEOUT == r){ return UEZ_ERROR_NOT_FOUND; } /* Send command to DISABLE echo */ do { r = AtLibGs_SetEcho(ATLIBGS_DISABLE); } while (ATLIBGS_MSG_ID_OK != r); // For now, just report it is not found if (r != ATLIBGS_MSG_ID_OK) return UEZ_ERROR_NOT_FOUND; return UEZ_ERROR_NONE; }