sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // template\Template_Variant\Specific\lcd.cpp sl@0: // Implementation of an LCD driver. sl@0: // This file is part of the Template Base port sl@0: // N.B. This sample code assumes that the display supports setting the backlight on or off, sl@0: // as well as adjusting the contrast and the brightness. sl@0: // sl@0: // sl@0: sl@0: sl@0: sl@0: #include sl@0: #include "platform.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: // TO DO: (mandatory) sl@0: // If the display supports Contrast and/or Brightness control then supply the following defines: sl@0: // This is only example code... you may need to modify it for your hardware sl@0: const TInt KConfigInitialDisplayContrast = 128; sl@0: const TInt KConfigLcdMinDisplayContrast = 1; sl@0: const TInt KConfigLcdMaxDisplayContrast = 255; sl@0: const TInt KConfigInitialDisplayBrightness = 128; sl@0: const TInt KConfigLcdMinDisplayBrightness = 1; sl@0: const TInt KConfigLcdMaxDisplayBrightness = 255; sl@0: sl@0: // TO DO: (mandatory) sl@0: // define a macro to calculate the screen buffer size sl@0: // This is only example code... you may need to modify it for your hardware sl@0: // aBpp is the number of bits-per-pixel, aPpl is the number of pixels per line and sl@0: // aLpp number of lines per panel sl@0: #define FRAME_BUFFER_SIZE(aBpp,aPpl,aLpp) (aBpp*aPpl*aLpp)/8 sl@0: sl@0: sl@0: // TO DO: (mandatory) sl@0: // define the physical screen dimensions sl@0: // This is only example code... you need to modify it for your hardware sl@0: const TUint KConfigLcdWidth = 640; // 640 pixels per line sl@0: const TUint KConfigLcdHeight = 480; // 480 lines per panel sl@0: sl@0: // TO DO: (mandatory) sl@0: // define the characteristics of the LCD display sl@0: // This is only example code... you need to modify it for your hardware sl@0: const TBool KConfigLcdIsMono = EFalse; sl@0: const TBool KConfigLcdPixelOrderLandscape = ETrue; sl@0: const TBool KConfigLcdPixelOrderRGB = ETrue; sl@0: const TInt KConfigLcdMaxDisplayColors = 65536; sl@0: sl@0: sl@0: // TO DO: (mandatory) sl@0: // define the display dimensions in TWIPs sl@0: // A TWIP is a 20th of a point. A point is a 72nd of an inch sl@0: // Therefore a TWIP is a 1440th of an inch sl@0: // This is only example code... you need to modify it for your hardware sl@0: const TInt KConfigLcdWidthInTwips = 9638; // = 6.69 inches sl@0: const TInt KConfigLcdHeightInTwips = 7370; // = 5.11 inches sl@0: sl@0: // TO DO: (mandatory) sl@0: // define the available display modes sl@0: // This is only example code... you need to modify it for your hardware sl@0: const TInt KConfigLcdNumberOfDisplayModes = 1; sl@0: const TInt KConfigLcdInitialDisplayMode = 0; sl@0: struct SLcdConfig sl@0: { sl@0: TInt iMode; sl@0: TInt iOffsetToFirstVideoBuffer; sl@0: TInt iLenghtOfVideoBufferInBytes; sl@0: TInt iOffsetBetweenLines; sl@0: TBool iIsPalettized; sl@0: TInt iBitsPerPixel; sl@0: }; sl@0: static const SLcdConfig Lcd_Mode_Config[KConfigLcdNumberOfDisplayModes]= sl@0: { sl@0: { sl@0: 0, // iMode sl@0: 0, // iOffsetToFirstVideoBuffer sl@0: FRAME_BUFFER_SIZE(8, KConfigLcdWidth, KConfigLcdHeight), // iLenghtOfVideoBufferInBytes sl@0: KConfigLcdWidth, // iOffsetBetweenLines sl@0: ETrue, // iIsPalettized sl@0: 8 // iBitsPerPixel sl@0: } sl@0: }; sl@0: sl@0: sl@0: sl@0: _LIT(KLitLcd,"LCD"); sl@0: sl@0: // sl@0: // TO DO: (optional) sl@0: // sl@0: // Add any private functions and data you require sl@0: // sl@0: NONSHARABLE_CLASS(DLcdPowerHandler) : public DPowerHandler sl@0: { sl@0: public: sl@0: DLcdPowerHandler(); sl@0: ~DLcdPowerHandler(); sl@0: sl@0: // from DPowerHandler sl@0: void PowerDown(TPowerState); sl@0: void PowerUp(); sl@0: sl@0: void PowerUpDfc(); sl@0: void PowerDownDfc(); sl@0: sl@0: TInt Create(); sl@0: void DisplayOn(); sl@0: void DisplayOff(); sl@0: TInt HalFunction(TInt aFunction, TAny* a1, TAny* a2); sl@0: sl@0: void PowerUpLcd(TBool aSecure); sl@0: void PowerDownLcd(); sl@0: sl@0: void ScreenInfo(TScreenInfoV01& aInfo); sl@0: void WsSwitchOnScreen(); sl@0: void WsSwitchOffScreen(); sl@0: void HandleMsg(); sl@0: void SwitchDisplay(TBool aSecure); sl@0: sl@0: void SetBacklightState(TBool aState); sl@0: void BacklightOn(); sl@0: void BacklightOff(); sl@0: TInt SetContrast(TInt aContrast); sl@0: TInt SetBrightness(TInt aBrightness); sl@0: sl@0: private: sl@0: TInt SetPaletteEntry(TInt aEntry, TInt aColor); sl@0: TInt GetPaletteEntry(TInt aEntry, TInt* aColor); sl@0: TInt NumberOfPaletteEntries(); sl@0: TInt GetCurrentDisplayModeInfo(TVideoInfoV01& aInfo, TBool aSecure); sl@0: TInt GetSpecifiedDisplayModeInfo(TInt aMode, TVideoInfoV01& aInfo); sl@0: TInt SetDisplayMode(TInt aMode); sl@0: void SplashScreen(); sl@0: TInt GetDisplayColors(TInt* aColors); sl@0: sl@0: private: sl@0: TBool iIsPalettized; sl@0: TBool iDisplayOn; // to prevent a race condition with WServer trying to power up/down at the same time sl@0: DPlatChunkHw* iChunk; sl@0: DPlatChunkHw* iSecureChunk; sl@0: TBool iWsSwitchOnScreen; sl@0: TBool iSecureDisplay; sl@0: TDynamicDfcQue* iDfcQ; sl@0: TMessageQue iMsgQ; sl@0: TDfc iPowerUpDfc; sl@0: TDfc iPowerDownDfc; sl@0: TVideoInfoV01 iVideoInfo; sl@0: TVideoInfoV01 iSecureVideoInfo; sl@0: NFastMutex iLock; // protects against being preempted whilst manipulating iVideoInfo/iSecureVideoInfo sl@0: TPhysAddr ivRamPhys; sl@0: TPhysAddr iSecurevRamPhys; sl@0: sl@0: TBool iBacklightOn; sl@0: TInt iContrast; sl@0: TInt iBrightness; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: HAL handler function sl@0: sl@0: @param aPtr a pointer to an instance of DLcdPowerHandler sl@0: @param aFunction the function number sl@0: @param a1 an arbitrary parameter sl@0: @param a2 an arbitrary parameter sl@0: */ sl@0: LOCAL_C TInt halFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2) sl@0: { sl@0: DLcdPowerHandler* pH=(DLcdPowerHandler*)aPtr; sl@0: return pH->HalFunction(aFunction,a1,a2); sl@0: } sl@0: sl@0: /** sl@0: DFC for receiving messages from the power handler sl@0: @param aPtr a pointer to an instance of DLcdPowerHandler sl@0: */ sl@0: void rxMsg(TAny* aPtr) sl@0: { sl@0: DLcdPowerHandler& h=*(DLcdPowerHandler*)aPtr; sl@0: h.HandleMsg(); sl@0: } sl@0: sl@0: /** sl@0: DFC for powering up the device sl@0: sl@0: @param aPtr aPtr a pointer to an instance of DLcdPowerHandler sl@0: */ sl@0: void power_up_dfc(TAny* aPtr) sl@0: { sl@0: ((DLcdPowerHandler*)aPtr)->PowerUpDfc(); sl@0: } sl@0: sl@0: /** sl@0: DFC for powering down the device sl@0: sl@0: @param aPtr aPtr a pointer to an instance of DLcdPowerHandler sl@0: */ sl@0: void power_down_dfc(TAny* aPtr) sl@0: { sl@0: ((DLcdPowerHandler*)aPtr)->PowerDownDfc(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Default constructor sl@0: */ sl@0: DLcdPowerHandler::DLcdPowerHandler() : sl@0: DPowerHandler(KLitLcd), sl@0: iMsgQ(rxMsg,this,NULL,1), sl@0: iPowerUpDfc(&power_up_dfc,this,6), sl@0: iPowerDownDfc(&power_down_dfc,this,7), sl@0: iBacklightOn(EFalse), sl@0: iContrast(KConfigInitialDisplayContrast), sl@0: iBrightness(KConfigInitialDisplayBrightness) sl@0: { sl@0: } sl@0: sl@0: DLcdPowerHandler::~DLcdPowerHandler() sl@0: { sl@0: if (iDfcQ) sl@0: iDfcQ->Destroy(); sl@0: } sl@0: sl@0: /** sl@0: Second-phase constructor sl@0: sl@0: Called by factory function at ordinal 0 sl@0: */ sl@0: TInt DLcdPowerHandler::Create() sl@0: { sl@0: const TInt KLCDDfcQPriority=27; // Equal to Kern::DfcQue0() priority sl@0: TInt r = Kern::DynamicDfcQCreate(iDfcQ, KLCDDfcQPriority, _L("LCDPowerHandler")); sl@0: if (r != KErrNone) sl@0: { sl@0: return r; sl@0: } sl@0: sl@0: // map the video RAM sl@0: TInt vSize = ((TemplateAssp*)Arch::TheAsic())->VideoRamSize(); sl@0: ivRamPhys = TTemplate::VideoRamPhys(); // EXAMPLE ONLY: assume TTemplate interface class sl@0: r = DPlatChunkHw::New(iChunk,ivRamPhys,vSize,EMapAttrUserRw|EMapAttrBufferedC); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: //create "secure" screen immediately after normal one sl@0: iSecurevRamPhys = ivRamPhys + vSize; sl@0: TInt r2 = DPlatChunkHw::New(iSecureChunk,iSecurevRamPhys,vSize,EMapAttrUserRw|EMapAttrBufferedC); sl@0: if (r2 != KErrNone) sl@0: return r2; sl@0: sl@0: TUint* pV=(TUint*)iChunk->LinearAddress(); sl@0: sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("DLcdPowerHandler::Create: VideoRamSize=%x, VideoRamPhys=%08x, VideoRamLin=%08x",vSize,ivRamPhys,pV)); sl@0: sl@0: // TO DO: (mandatory) sl@0: // initialise the palette for the initial display mode sl@0: // NOTE: the palette could either be a buffer allocated in system RAM (usually contiguous to Video buffer) sl@0: // or could be offered as part of the hardware block that implemenst the lcd control sl@0: // sl@0: sl@0: TUint* pV2=(TUint*)iSecureChunk->LinearAddress(); sl@0: sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("DLcdPowerHandler::Create: Secure display VideoRamSize=%x, VideoRamPhys=%08x, VideoRamLin=%08x",vSize,iSecurevRamPhys,pV2)); sl@0: sl@0: // TO DO: (mandatory) sl@0: // initialise the secure screen's palette for the initial display mode sl@0: // sl@0: sl@0: // setup the video info structure, this'll be used to remember the video settings sl@0: iVideoInfo.iDisplayMode = KConfigLcdInitialDisplayMode; sl@0: iVideoInfo.iOffsetToFirstPixel = Lcd_Mode_Config[KConfigLcdInitialDisplayMode].iOffsetToFirstVideoBuffer; sl@0: iVideoInfo.iIsPalettized = Lcd_Mode_Config[KConfigLcdInitialDisplayMode].iIsPalettized; sl@0: iVideoInfo.iOffsetBetweenLines = Lcd_Mode_Config[KConfigLcdInitialDisplayMode].iOffsetBetweenLines; sl@0: iVideoInfo.iBitsPerPixel = Lcd_Mode_Config[KConfigLcdInitialDisplayMode].iBitsPerPixel; sl@0: sl@0: iVideoInfo.iSizeInPixels.iWidth = KConfigLcdWidth; sl@0: iVideoInfo.iSizeInPixels.iHeight = KConfigLcdHeight; sl@0: iVideoInfo.iSizeInTwips.iWidth = KConfigLcdWidthInTwips; sl@0: iVideoInfo.iSizeInTwips.iHeight = KConfigLcdHeightInTwips; sl@0: iVideoInfo.iIsMono = KConfigLcdIsMono; sl@0: iVideoInfo.iVideoAddress=(TInt)pV; sl@0: iVideoInfo.iIsPixelOrderLandscape = KConfigLcdPixelOrderLandscape; sl@0: iVideoInfo.iIsPixelOrderRGB = KConfigLcdPixelOrderRGB; sl@0: sl@0: iSecureVideoInfo = iVideoInfo; sl@0: iSecureVideoInfo.iVideoAddress = (TInt)pV2; sl@0: sl@0: iDisplayOn = EFalse; sl@0: iSecureDisplay = EFalse; sl@0: sl@0: // install the HAL function sl@0: r=Kern::AddHalEntry(EHalGroupDisplay, halFunction, this); sl@0: if (r!=KErrNone) sl@0: return r; sl@0: sl@0: iPowerUpDfc.SetDfcQ(iDfcQ); sl@0: iPowerDownDfc.SetDfcQ(iDfcQ); sl@0: iMsgQ.SetDfcQ(iDfcQ); sl@0: iMsgQ.Receive(); sl@0: sl@0: // install the power handler sl@0: // power up the screen sl@0: Add(); sl@0: DisplayOn(); sl@0: sl@0: SplashScreen(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Turn the display on sl@0: May be called as a result of a power transition or from the HAL sl@0: If called from HAL, then the display may be already be on (iDisplayOn == ETrue) sl@0: */ sl@0: void DLcdPowerHandler::DisplayOn() sl@0: { sl@0: __KTRACE_OPT(KPOWER, Kern::Printf("DisplayOn %d", iDisplayOn)); sl@0: if (!iDisplayOn) // may have been powered up already sl@0: { sl@0: iDisplayOn = ETrue; sl@0: PowerUpLcd(iSecureDisplay); sl@0: SetContrast(iContrast); sl@0: SetBrightness(iBrightness); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Turn the display off sl@0: May be called as a result of a power transition or from the HAL sl@0: If called from Power Manager, then the display may be already be off (iDisplayOn == EFalse) sl@0: if the platform is in silent running mode sl@0: */ sl@0: void DLcdPowerHandler::DisplayOff() sl@0: { sl@0: __KTRACE_OPT(KPOWER, Kern::Printf("DisplayOff %d", iDisplayOn)); sl@0: if (iDisplayOn) sl@0: { sl@0: iDisplayOn = EFalse; sl@0: PowerDownLcd(); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Switch between secure and non-secure displays sl@0: sl@0: @param aSecure ETrue if switching to secure display sl@0: */ sl@0: void DLcdPowerHandler::SwitchDisplay(TBool aSecure) sl@0: { sl@0: if (aSecure) sl@0: { sl@0: if (!iSecureDisplay) sl@0: { sl@0: //switch to secure display sl@0: DisplayOff(); sl@0: iSecureDisplay = ETrue; sl@0: DisplayOn(); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if (iSecureDisplay) sl@0: { sl@0: //switch from secure display sl@0: DisplayOff(); sl@0: iSecureDisplay = EFalse; sl@0: DisplayOn(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: DFC to power up the display sl@0: */ sl@0: void DLcdPowerHandler::PowerUpDfc() sl@0: { sl@0: __KTRACE_OPT(KPOWER, Kern::Printf("PowerUpDfc")); sl@0: DisplayOn(); sl@0: sl@0: PowerUpDone(); // must be called from a different thread than PowerUp() sl@0: } sl@0: sl@0: /** sl@0: DFC to power down the display sl@0: */ sl@0: void DLcdPowerHandler::PowerDownDfc() sl@0: { sl@0: __KTRACE_OPT(KPOWER, Kern::Printf("PowerDownDfc")); sl@0: DisplayOff(); sl@0: PowerDownDone(); // must be called from a different thread than PowerUp() sl@0: } sl@0: sl@0: /** sl@0: Schedule the power-down DFC sl@0: */ sl@0: void DLcdPowerHandler::PowerDown(TPowerState) sl@0: { sl@0: iPowerDownDfc.Enque(); // schedules DFC to execute on this driver's thread sl@0: } sl@0: sl@0: /** sl@0: Schedule the power-up DFC sl@0: */ sl@0: void DLcdPowerHandler::PowerUp() sl@0: { sl@0: iPowerUpDfc.Enque(); // schedules DFC to execute on this driver's thread sl@0: } sl@0: sl@0: /** sl@0: Power up the display sl@0: sl@0: @param aSecure ETrue if powering up the secure display sl@0: */ sl@0: void DLcdPowerHandler::PowerUpLcd(TBool aSecure) sl@0: { sl@0: sl@0: // TO DO: (mandatory) sl@0: // Power up the display and configure it ready for use sl@0: // Examples of things that may need initializing are: sl@0: // panel dimensions sl@0: // line & frame timings sl@0: // bits-per-pixel sl@0: // Configuring the DMA engine to map the video buffer in ivRamPhys or iSecurevRamPhys sl@0: // contrast, brightness, backlight sl@0: // power sl@0: // etc. etc. sl@0: // sl@0: } sl@0: sl@0: /** sl@0: Power down the display and the backlight sl@0: */ sl@0: void DLcdPowerHandler::PowerDownLcd() sl@0: { sl@0: SetBacklightState(EFalse); sl@0: sl@0: // TO DO: (mandatory) sl@0: // Power down the display & disable LCD DMA. sl@0: // May need to wait until the current frame has been output sl@0: // sl@0: } sl@0: sl@0: /** sl@0: Set the Lcd contrast sl@0: sl@0: @param aValue the contrast setting sl@0: */ sl@0: TInt DLcdPowerHandler::SetContrast(TInt aValue) sl@0: { sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("SetContrast(%d)", aValue)); sl@0: sl@0: if (aValue >= KConfigLcdMinDisplayContrast && aValue <= KConfigLcdMaxDisplayContrast) sl@0: { sl@0: iContrast=aValue; sl@0: sl@0: // TO DO: (mandatory) sl@0: // set the contrast sl@0: // sl@0: return KErrNone; sl@0: } sl@0: sl@0: return KErrArgument; sl@0: } sl@0: sl@0: /** sl@0: Set the Lcd brightness sl@0: sl@0: @param aValue the brightness setting sl@0: */ sl@0: TInt DLcdPowerHandler::SetBrightness(TInt aValue) sl@0: { sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("SetBrightness(%d)", aValue)); sl@0: sl@0: if (aValue >= KConfigLcdMinDisplayBrightness && aValue <= KConfigLcdMaxDisplayBrightness) sl@0: { sl@0: iBrightness=aValue; sl@0: sl@0: // TO DO: (mandatory) sl@0: // set the brightness sl@0: // sl@0: return KErrNone; sl@0: } sl@0: return KErrArgument; sl@0: } sl@0: sl@0: /** sl@0: Turn the backlight on sl@0: */ sl@0: void DLcdPowerHandler::BacklightOn() sl@0: { sl@0: // TO DO: (mandatory) sl@0: // turn the backlight on sl@0: // sl@0: } sl@0: sl@0: /** sl@0: Turn the backlight off sl@0: */ sl@0: void DLcdPowerHandler::BacklightOff() sl@0: { sl@0: // TO DO: (mandatory) sl@0: // turn the backlight off sl@0: // sl@0: } sl@0: sl@0: /** sl@0: Set the state of the backlight sl@0: sl@0: @param aState ETrue if setting the backlight on sl@0: */ sl@0: void DLcdPowerHandler::SetBacklightState(TBool aState) sl@0: { sl@0: iBacklightOn=aState; sl@0: if (iBacklightOn) sl@0: BacklightOn(); sl@0: else sl@0: BacklightOff(); sl@0: } sl@0: sl@0: void DLcdPowerHandler::ScreenInfo(TScreenInfoV01& anInfo) sl@0: { sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("DLcdPowerHandler::ScreenInfo")); sl@0: anInfo.iWindowHandleValid=EFalse; sl@0: anInfo.iWindowHandle=NULL; sl@0: anInfo.iScreenAddressValid=ETrue; sl@0: anInfo.iScreenAddress=(TAny *)(iChunk->LinearAddress()); sl@0: anInfo.iScreenSize.iWidth=KConfigLcdWidth; sl@0: anInfo.iScreenSize.iHeight=KConfigLcdHeight; sl@0: } sl@0: sl@0: /** sl@0: Handle a message from the power handler sl@0: */ sl@0: void DLcdPowerHandler::HandleMsg(void) sl@0: { sl@0: sl@0: TMessageBase* msg = iMsgQ.iMessage; sl@0: if (msg == NULL) sl@0: return; sl@0: sl@0: if (msg->iValue) sl@0: DisplayOn(); sl@0: else sl@0: DisplayOff(); sl@0: msg->Complete(KErrNone,ETrue); sl@0: } sl@0: sl@0: /** sl@0: Send a message to the power-handler message queue to turn the display on sl@0: */ sl@0: void DLcdPowerHandler::WsSwitchOnScreen() sl@0: { sl@0: TThreadMessage& m=Kern::Message(); sl@0: m.iValue = ETrue; sl@0: m.SendReceive(&iMsgQ); // send a message and block Client thread until keyboard has been powered up sl@0: } sl@0: sl@0: /** sl@0: Send a message to the power-handler message queue to turn the display off sl@0: */ sl@0: void DLcdPowerHandler::WsSwitchOffScreen() sl@0: { sl@0: TThreadMessage& m=Kern::Message(); sl@0: m.iValue = EFalse; sl@0: m.SendReceive(&iMsgQ); // send a message and block Client thread until keyboard has been powered down sl@0: } sl@0: sl@0: /** sl@0: Return information about the current display mode sl@0: sl@0: @param aInfo a structure supplied by the caller to be filled by this function. sl@0: @param aSecure ETrue if requesting information about the secure display sl@0: @return KErrNone if successful sl@0: */ sl@0: TInt DLcdPowerHandler::GetCurrentDisplayModeInfo(TVideoInfoV01& aInfo, TBool aSecure) sl@0: { sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("GetCurrentDisplayModeInfo")); sl@0: NKern::FMWait(&iLock); sl@0: if (aSecure) sl@0: aInfo = iSecureVideoInfo; sl@0: else sl@0: aInfo = iVideoInfo; sl@0: NKern::FMSignal(&iLock); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Return information about the specified display mode sl@0: sl@0: @param aMode the display mode to query sl@0: @param aInfo a structure supplied by the caller to be filled by this function. sl@0: @return KErrNone if successful sl@0: */ sl@0: TInt DLcdPowerHandler::GetSpecifiedDisplayModeInfo(TInt aMode, TVideoInfoV01& aInfo) sl@0: { sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("GetSpecifiedDisplayModeInfo mode is %d",aMode)); sl@0: sl@0: if (aMode < 0 || aMode >= KConfigLcdNumberOfDisplayModes) sl@0: return KErrArgument; sl@0: sl@0: NKern::FMWait(&iLock); sl@0: aInfo = iVideoInfo; sl@0: NKern::FMSignal(&iLock); sl@0: sl@0: if (aMode != aInfo.iDisplayMode) sl@0: { sl@0: aInfo.iOffsetToFirstPixel=Lcd_Mode_Config[aMode].iOffsetToFirstVideoBuffer; sl@0: aInfo.iIsPalettized = Lcd_Mode_Config[aMode].iIsPalettized; sl@0: aInfo.iOffsetBetweenLines=Lcd_Mode_Config[aMode].iOffsetBetweenLines; sl@0: aInfo.iBitsPerPixel = Lcd_Mode_Config[aMode].iBitsPerPixel; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Set the display mode sl@0: sl@0: @param aMode the display mode to set sl@0: */ sl@0: TInt DLcdPowerHandler::SetDisplayMode(TInt aMode) sl@0: { sl@0: sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("SetDisplayMode = %d", aMode)); sl@0: sl@0: if (aMode < 0 || aMode >= KConfigLcdNumberOfDisplayModes) sl@0: return KErrArgument; sl@0: sl@0: NKern::FMWait(&iLock); sl@0: sl@0: // store the current mode sl@0: iVideoInfo.iDisplayMode = aMode; sl@0: iVideoInfo.iOffsetToFirstPixel = Lcd_Mode_Config[aMode].iOffsetToFirstVideoBuffer; sl@0: iVideoInfo.iIsPalettized = Lcd_Mode_Config[aMode].iIsPalettized; sl@0: iVideoInfo.iOffsetBetweenLines = Lcd_Mode_Config[aMode].iOffsetBetweenLines; sl@0: iVideoInfo.iBitsPerPixel = Lcd_Mode_Config[aMode].iBitsPerPixel; sl@0: sl@0: // store the current mode for secure screen sl@0: iSecureVideoInfo.iDisplayMode = aMode; sl@0: iSecureVideoInfo.iOffsetToFirstPixel = Lcd_Mode_Config[aMode].iOffsetToFirstVideoBuffer; sl@0: iSecureVideoInfo.iIsPalettized = Lcd_Mode_Config[aMode].iIsPalettized; sl@0: iSecureVideoInfo.iOffsetBetweenLines = Lcd_Mode_Config[aMode].iOffsetBetweenLines; sl@0: iSecureVideoInfo.iBitsPerPixel = Lcd_Mode_Config[aMode].iBitsPerPixel; sl@0: sl@0: // TO DO: (mandatory) sl@0: // set bits per pixel on hardware sl@0: // May need to reconfigure DMA if video buffer size and location have changed sl@0: // sl@0: NKern::FMSignal(&iLock); sl@0: sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("SetDisplayMode mode = %d, otfp = %d, palettized = %d, bpp = %d, obl = %d", sl@0: aMode, iVideoInfo.iOffsetToFirstPixel, iVideoInfo.iIsPalettized, iVideoInfo.iBitsPerPixel, iVideoInfo.iOffsetBetweenLines)); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Fill the video memory with an initial pattern or image sl@0: This will be displayed on boot-up sl@0: */ sl@0: void DLcdPowerHandler::SplashScreen() sl@0: { sl@0: // TO DO: (optional) sl@0: // replace the example code below to display a different spash screen sl@0: sl@0: // initialise the video ram to be a splash screen sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("SplashScreen")); sl@0: sl@0: TUint x,y; sl@0: TUint8 * p = (TUint8*)(iVideoInfo.iVideoAddress + iVideoInfo.iOffsetToFirstPixel); sl@0: sl@0: //draw >< on screen sl@0: TUint rsh = KConfigLcdHeight; sl@0: TUint rsw = KConfigLcdWidth; sl@0: for (y = 0; y < rsh>>1; y++) sl@0: { sl@0: TUint8* q = p; sl@0: for (x = 0; x < rsw; x++) sl@0: *p++ = (x < y || (rsw-x>1; y < rsh; y++) sl@0: { sl@0: TUint8* q = p; sl@0: for (x = 0; x < rsw; x++) sl@0: *p++ = ((x < rsh-y) || (rsw-x< on secure screen sl@0: for (y = 0; y < rsh>>1; y++) sl@0: { sl@0: TUint8* q = p; sl@0: for (x = 0; x < rsw; x++) sl@0: *p++ = (x < y || (rsw-x>1; y < rsh; y++) sl@0: { sl@0: TUint8* q = p; sl@0: for (x = 0; x < rsw; x++) sl@0: *p++ = ((x < rsh-y) || (rsw-x= NumberOfPaletteEntries())) sl@0: { sl@0: NKern::FMSignal(&iLock); sl@0: return KErrArgument; sl@0: } sl@0: sl@0: // TO DO: (mandatory) sl@0: // read the RGB value of the palette entry into aColor sl@0: // NOTE: the palette could either be a buffer allocated in system RAM (usually contiguous to Video buffer) sl@0: // or could be offered as part of the hardware block that implemenst the lcd control sl@0: // sl@0: NKern::FMSignal(&iLock); sl@0: sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("GetPaletteEntry %d color 0x%x", aEntry, aColor)); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Set the palette entry at a particular offset sl@0: sl@0: @param aEntry the palette index sl@0: @param aColor the RGB color to store sl@0: @return KErrNone if successful sl@0: KErrNotSupported if the current vide mode does not support a palette sl@0: KErrArgument if aEntry is out of range sl@0: */ sl@0: TInt DLcdPowerHandler::SetPaletteEntry(TInt aEntry, TInt aColor) sl@0: { sl@0: sl@0: NKern::FMWait(&iLock); sl@0: if (!iVideoInfo.iIsPalettized) sl@0: { sl@0: NKern::FMSignal(&iLock); sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: if ((aEntry < 0) || (aEntry >= NumberOfPaletteEntries())) //check entry in range sl@0: { sl@0: NKern::FMSignal(&iLock); sl@0: return KErrArgument; sl@0: } sl@0: sl@0: // TO DO: (mandatory) sl@0: // update the palette entry for the secure and non-secure screen sl@0: // NOTE: the palette could either be a buffer allocated in system RAM (usually contiguous to Video buffer) sl@0: // or could be offered as part of the hardware block that implemenst the lcd control sl@0: // sl@0: __KTRACE_OPT(KEXTENSION,Kern::Printf("SetPaletteEntry %d to 0x%x", aEntry, aColor )); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: a HAL entry handling function for HAL group attribute EHalGroupDisplay sl@0: sl@0: @param a1 an arbitrary argument sl@0: @param a2 an arbitrary argument sl@0: @return KErrNone if successful sl@0: */ sl@0: TInt DLcdPowerHandler::HalFunction(TInt aFunction, TAny* a1, TAny* a2) sl@0: { sl@0: __e32_memory_barrier(); // Ensure changes from other clients are picked up sl@0: sl@0: TInt r=KErrNone; sl@0: switch(aFunction) sl@0: { sl@0: case EDisplayHalScreenInfo: sl@0: { sl@0: TPckgBuf vPckg; sl@0: ScreenInfo(vPckg()); sl@0: Kern::InfoCopy(*(TDes8*)a1,vPckg); sl@0: break; sl@0: } sl@0: sl@0: case EDisplayHalWsRegisterSwitchOnScreenHandling: sl@0: iWsSwitchOnScreen=(TBool)a1; sl@0: break; sl@0: sl@0: case EDisplayHalWsSwitchOnScreen: sl@0: WsSwitchOnScreen(); sl@0: break; sl@0: sl@0: case EDisplayHalMaxDisplayContrast: sl@0: { sl@0: TInt mc=KConfigLcdMaxDisplayContrast; sl@0: kumemput32(a1,&mc,sizeof(mc)); sl@0: break; sl@0: } sl@0: case EDisplayHalSetDisplayContrast: sl@0: if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetDisplayContrast"))) sl@0: return KErrPermissionDenied; sl@0: r=SetContrast(TInt(a1)); sl@0: break; sl@0: sl@0: case EDisplayHalDisplayContrast: sl@0: kumemput32(a1,&iContrast,sizeof(iContrast)); sl@0: break; sl@0: sl@0: case EDisplayHalMaxDisplayBrightness: sl@0: { sl@0: TInt mc=KConfigLcdMaxDisplayBrightness; sl@0: kumemput32(a1,&mc,sizeof(mc)); sl@0: break; sl@0: } sl@0: sl@0: case EDisplayHalSetDisplayBrightness: sl@0: if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetDisplayBrightness"))) sl@0: return KErrPermissionDenied; sl@0: r=SetBrightness(TInt(a1)); sl@0: break; sl@0: sl@0: case EDisplayHalDisplayBrightness: sl@0: kumemput32(a1,&iBrightness,sizeof(iBrightness)); sl@0: break; sl@0: sl@0: case EDisplayHalSetBacklightOn: sl@0: if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetBacklightOn"))) sl@0: return KErrPermissionDenied; sl@0: if (Kern::MachinePowerStatus() vPckg; sl@0: r = GetCurrentDisplayModeInfo(vPckg(), (TBool)a2); sl@0: if (KErrNone == r) sl@0: Kern::InfoCopy(*(TDes8*)a1,vPckg); sl@0: } sl@0: break; sl@0: sl@0: case EDisplayHalSpecifiedModeInfo: sl@0: { sl@0: TPckgBuf vPckg; sl@0: TInt mode; sl@0: kumemget32(&mode, a1, sizeof(mode)); sl@0: r = GetSpecifiedDisplayModeInfo(mode, vPckg()); sl@0: if (KErrNone == r) sl@0: Kern::InfoCopy(*(TDes8*)a2,vPckg); sl@0: } sl@0: break; sl@0: sl@0: case EDisplayHalSecure: sl@0: kumemput32(a1, &iSecureDisplay, sizeof(TBool)); sl@0: break; sl@0: sl@0: case EDisplayHalSetSecure: sl@0: { sl@0: if(!Kern::CurrentThreadHasCapability(ECapabilityMultimediaDD,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetSecure"))) sl@0: return KErrPermissionDenied; sl@0: SwitchDisplay((TBool)a1); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: r=KErrNotSupported; sl@0: break; sl@0: } sl@0: sl@0: __e32_memory_barrier(); // Ensure any changes are propagated to other clients sl@0: sl@0: return r; sl@0: } sl@0: sl@0: sl@0: DECLARE_STANDARD_EXTENSION() sl@0: { sl@0: __KTRACE_OPT(KPOWER,Kern::Printf("Starting LCD power manager")); sl@0: sl@0: // create LCD power handler sl@0: TInt r=KErrNoMemory; sl@0: DLcdPowerHandler* pH=new DLcdPowerHandler; sl@0: if (pH) sl@0: r=pH->Create(); sl@0: sl@0: __KTRACE_OPT(KPOWER,Kern::Printf("Returns %d",r)); sl@0: return r; sl@0: } sl@0: