view src/condat/com/src/driver/light.c @ 75:8697f358f505

backlight rework: Condat light driver accepts levels The present change is another intermediate step on the path toward new FreeCalypso backlight handling. At this intermediate step the Condat light driver accepts 0-255 backlight levels driven by MFW, and puts them out on PWL on Luna development boards. At the same time on C139 it is now possible to turn on the display backlight with or without the keypad bl - the lsb of the 0-255 backlight level controls the keypad bl. MFW presently drives only 0 and 255 backlight levels, thus there is no visible behavioral change yet - but the plan for subsequent stages of this backlight rework is to add a dimmed backlight state (no keypad bl on C139) during active calls.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 24 Oct 2020 20:44:04 +0000
parents 7bf39f5e834d
children bb5aba57ecfb
line wrap: on
line source

/* 
+----------------------------------------------------------------------------- 
|  Project :  GSM-PS
|  Modul   :  DRV_LT
+----------------------------------------------------------------------------- 
|  Copyright 2002 Texas Instruments Berlin, AG 
|                 All rights reserved. 
| 
|                 This file is confidential and a trade secret of Texas 
|                 Instruments Berlin, AG 
|                 The receipt of or possession of this file does not convey 
|                 any rights to reproduce or disclose its contents or to 
|                 manufacture, use, or sell anything it may describe, in 
|                 whole, or in part, without the specific written consent of 
|                 Texas Instruments Berlin, AG. 
+----------------------------------------------------------------------------- 
|  Purpose :  This Module defines the G23 light emitting driver. 
+----------------------------------------------------------------------------- 
 

    Apr 26, 2005   REF : CRR 30627 xpradipg
    Bug :   Replace the ABB APIs with Audio Service APIs
    Fix :   Remove the LT_ function calls   
*******************************************************************************/ 
/*
    June 03, 2005 REF: GSM-ENH-31636 xpradipg
    Description:    Change the board ID for Isample to 71 and add new defination
                    for the CALLISTO with baord ID 70
    Solution:       Add the definition of ALLISTO with board ID 70 and change the
                    board Id to 71 for Isample

    CRR 28825:  xpradipg - 11 Feb 2005
    Description:Extension of GDI-for display of ISample and code cleanup
    Solution: The code replication for D_Sample and E_sample are removed and a new
    flag is added for the ISample currently the BOARD ID is set to 60 for ISample.

*/
#ifndef DRV_LT_C
#define DRV_LT_C
#endif

/*==== INCLUDES ===================================================*/
#if defined (NEW_FRAME)

#include <string.h>
#include "typedefs.h"
#include "gdi.h"
#include "light.h"

#else

#include <string.h>
#include "stddefs.h"
#include "gdi.h"
#include "light.h"

#endif

#include "main/sys_types.h"
#include "fc-target.h"
#include "armio.h"
#include "lls/lls_api.h"

/*==== EXPORT =====================================================*/

/*==== VARIABLES ==================================================*/
UBYTE  backlight_status = LIGHT_STATUS_OFF;

/*==== CONSTANTS ==================================================*/
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103)       MODULE  : DRV_LT                     |
| STATE   : code                ROUTINE : light_Init                 |
+--------------------------------------------------------------------+

  PURPOSE : The function initializes the internal data of the driver.
            The function returns DRV_INITIALIZED if the driver has
            already been initialized and is ready to be used or is 
            already in use. In case of an initialization failure, 
            i.e. the driver cannot be used, the function returns
            DRV_INITFAILURE.

*/

GLOBAL UBYTE light_Init (void)
{
  backlight_status = LIGHT_STATUS_OFF;

#ifdef CONFIG_TARGET_LUNA
  /* PWL module clock enable */
  *(volatile SYS_UWORD8 *)0xFFFE8001 = 0x01;
#endif

  return DRV_OK;
}

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103)       MODULE  : DRV_LT                     |
| STATE   : code                ROUTINE : light_Exit                 |
+--------------------------------------------------------------------+

  PURPOSE : The function is called when the driver functionality is
            not longer needed. The function de-allocates the
            resources.

*/

GLOBAL void light_Exit (void)
{
  backlight_status = LIGHT_STATUS_OFF;
}

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103)       MODULE  : DRV_LT                     |
| STATE   : code                ROUTINE : light_SetStatus            |
+--------------------------------------------------------------------+

  PURPOSE : This function is used to change the status of a specific
            light emitting device supported by this driver. The device is
            identified by the parameter in_DeviceID. Depending on
            the capabilities of the device, the parameter in_NewStatus
            has different meanings.
            
*/

GLOBAL UBYTE light_SetStatus (UBYTE in_DeviceID,
                              UBYTE in_NewStatus)
{
  if (in_DeviceID EQ LIGHT_DEVICE_BACKLIGHT)
  {
    backlight_status = in_NewStatus;

    switch (in_NewStatus)
    {
      case LIGHT_STATUS_OFF:
        light_setBacklightOff();
        break;
      default:
        light_setBacklightOnLevel(backlight_status);
        break;
    }
    return DRV_OK;
  }
  else
    return DRV_INVALID_PARAMS;
}

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-PS (6103)       MODULE  : DRV_LT                     |
| STATE   : code                ROUTINE : light_GetStatus            |
+--------------------------------------------------------------------+

  PURPOSE : This function retrieves the status of a specific light
            emitting device supported by the driver. If the status
            of a specified device could be retrieved, the function
            returns DRV_OK. If the specified device is unknown, the 
            function returns DRV_INVALID_PARAMS.
            
*/

GLOBAL UBYTE light_GetStatus (UBYTE   in_DeviceID,
                              UBYTE * in_StatusPtr)
                              
{
  if (in_DeviceID EQ LIGHT_DEVICE_BACKLIGHT)
  {
    *in_StatusPtr = backlight_status;
    return DRV_OK;
  }
  else
    return DRV_INVALID_PARAMS;
}


/*******************************************************************************

Transitional FreeCalypso backlight driver

*******************************************************************************/

static UBYTE keypad_bl_state;

static void keypad_bl_on(void)
{
	if (!keypad_bl_state) {
	    #if defined(CONFIG_TARGET_C139) || defined(CONFIG_TARGET_PIRELLI)
		lls_switch_on(LLS_BACKLIGHT);
	    #endif
		keypad_bl_state = 1;
	}
}

static void keypad_bl_off(void)
{
	if (keypad_bl_state) {
	    #if defined(CONFIG_TARGET_C139) || defined(CONFIG_TARGET_PIRELLI)
		lls_switch_off(LLS_BACKLIGHT);
	    #endif
		keypad_bl_state = 0;
	}
}

enum {
    BACKLIGHT_OFF,
    BACKLIGHT_ON,
    BACKLIGHT_IDLE1
};
UBYTE backLightState = BACKLIGHT_OFF;

/*******************************************************************************

 $Function:     setBacklightOn

 $Description:  switches backlight on. Called on powerup or on a key press.
                Should also be called on incoming call, SMS etc ?
 
 $Returns:      none.

 $Arguments:    none.


*******************************************************************************/
void light_setBacklightOnLevel (UBYTE level)
{
    if (backLightState == BACKLIGHT_OFF)
    {
      #ifdef CONFIG_TARGET_LUNA
	/* turn on PWL */
	*(volatile SYS_UWORD8 *)0xFFFE8000 = level;
      #elif defined(CONFIG_TARGET_C139)
        AI_SetBit(1);
      #endif
      if (level & 1)
          keypad_bl_on();
      else
          keypad_bl_off();
    }
    backLightState = BACKLIGHT_ON;
}

/* backward compatibility function */
void light_setBacklightOn( void )
{
    light_setBacklightOnLevel(255);
}

/*******************************************************************************

 $Function:     setBacklightOff

 $Description:  switches backlight off. 
 
 $Returns:      none.

 $Arguments:    none.

*******************************************************************************/
void light_setBacklightOff( void )
{
    if ((backLightState == BACKLIGHT_ON) ||
       (backLightState == BACKLIGHT_IDLE1))
    {
      backLightState = BACKLIGHT_OFF;
      #ifdef CONFIG_TARGET_LUNA
	/* turn off PWL */
	*(volatile SYS_UWORD8 *)0xFFFE8000 = 0;
      #elif defined(CONFIG_TARGET_C139)
        AI_ResetBit(1);
      #endif
      keypad_bl_off();
    }
}

/*******************************************************************************

 $Function:     setBacklightIdle

 $Description:  switches backlight off (on second call). Called when the 1 minute timer expires.
                If no key press since the last call, the backlight is switched off.
 
 $Returns:      none.

 $Arguments:    none.

*******************************************************************************/
void light_setBacklightIdle( void )
{
    if (backLightState == BACKLIGHT_ON)
    {
        backLightState = BACKLIGHT_IDLE1;       
    }
    else
    {
        light_setBacklightOff();
    }
}