changeset 214:adfdbcd360fd

backlight evolution: API between Condat driver and MFW With this change, the API between the Condat backlight driver and its user in MFW now carries more abstract backlight state codes (fully off, fully on, in call, charging boot mode) instead of 0-255 levels. This change is needed in order to more properly support different hardware targets with different capabilities and approaches in terms of backlight handling.
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 23 Apr 2021 23:52:02 +0000
parents 0947a816580c
children 76f65c8bb151
files src/condat/com/include/light.h src/condat/com/src/driver/light.c src/ui/mfw/mfw_mme.c
diffstat 3 files changed, 80 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/src/condat/com/include/light.h	Thu Apr 22 21:23:16 2021 +0000
+++ b/src/condat/com/include/light.h	Fri Apr 23 23:52:02 2021 +0000
@@ -33,9 +33,8 @@
  */
 #define LIGHT_STATUS_OFF           0
 #define LIGHT_STATUS_ON            1
-#define LIGHT_STATUS_DIMMED        2
-#define LIGHT_STATUS_INTERMEDIATE  3
-#define LIGHT_STATUS_BRIGHT        4
+#define LIGHT_STATUS_INCALL        2
+#define LIGHT_STATUS_CHG_BOOT      3
 
 #define LIGHT_STATUS_GREEN         5
 #define LIGHT_STATUS_ORANGE        6
@@ -57,9 +56,4 @@
 EXTERN UBYTE light_SetStatus (UBYTE in_DeviceID, UBYTE in_NewStatus);
 EXTERN UBYTE light_GetStatus (UBYTE in_DeviceID, UBYTE * in_StatusPtr);
 
-void light_setBacklightOn      (void);
-void light_setBacklightOnLevel (UBYTE level);
-void light_setBacklightIdle    (void);
-void light_setBacklightOff     (void);
-
 #endif
--- a/src/condat/com/src/driver/light.c	Thu Apr 22 21:23:16 2021 +0000
+++ b/src/condat/com/src/driver/light.c	Fri Apr 23 23:52:02 2021 +0000
@@ -66,6 +66,11 @@
 /*==== VARIABLES ==================================================*/
 UBYTE  backlight_status = LIGHT_STATUS_OFF;
 
+/* forward declaration for static functions */
+static void keypad_bl_on(void);
+static void keypad_bl_off(void);
+static void blrr_display_ctrl(UBYTE set_state);
+
 /*==== CONSTANTS ==================================================*/
 /*
 +--------------------------------------------------------------------+
@@ -135,12 +140,21 @@
     switch (in_NewStatus)
     {
       case LIGHT_STATUS_OFF:
-        light_setBacklightOff();
+      case LIGHT_STATUS_INCALL:
+      case LIGHT_STATUS_CHG_BOOT:
+        #if defined(CONFIG_TARGET_C139) || defined(CONFIG_TARGET_PIRELLI)
+          keypad_bl_off();
+        #endif
+        break;
+      case LIGHT_STATUS_ON:
+        #if defined(CONFIG_TARGET_C139) || defined(CONFIG_TARGET_PIRELLI)
+          keypad_bl_on();
+        #endif
         break;
       default:
-        light_setBacklightOnLevel(backlight_status);
-        break;
+        return DRV_INVALID_PARAMS;
     }
+    blrr_display_ctrl(backlight_status);
     return DRV_OK;
   }
   else
@@ -177,18 +191,18 @@
 
 /*******************************************************************************
 
-Transitional FreeCalypso backlight driver
+Keypad backlight control for C139 and Pirelli targets
 
 *******************************************************************************/
 
+#if defined(CONFIG_TARGET_C139) || defined(CONFIG_TARGET_PIRELLI)
+
 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;
 	}
 }
@@ -196,68 +210,68 @@
 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;
 	}
 }
 
-/*******************************************************************************
-
- $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)
-{
-    #ifdef CONFIG_TARGET_LUNA
-	/* turn on PWL */
-	*(volatile SYS_UWORD8 *)0xFFFE8000 = level;
-	/* turn on physical backlight */
-	AI_SetBit(9);
-    #elif defined(CONFIG_TARGET_C139)
-	AI_SetBit(1);
-    #endif
-    if (level & 1)
-	keypad_bl_on();
-    else
-	keypad_bl_off();
-}
-
-/* backward compatibility function */
-void light_setBacklightOn( void )
-{
-    light_setBacklightOnLevel(255);
-}
+#endif
 
 /*******************************************************************************
 
- $Function:     setBacklightOff
-
- $Description:  switches backlight off. 
- 
- $Returns:      none.
-
- $Arguments:    none.
+BLRR display (backlight required for readability) on/off control;
+the plan is to have this control eventually moved to R2D task.
 
 *******************************************************************************/
-void light_setBacklightOff( void )
+
+#ifdef CONFIG_TARGET_LUNA
+
+static void blrr_display_ctrl(UBYTE set_state)
 {
-    #ifdef CONFIG_TARGET_LUNA
-	/* turn off PWL */
-	*(volatile SYS_UWORD8 *)0xFFFE8000 = 0;
-	/* turn off physical backlight */
-	AI_ResetBit(9);
-    #elif defined(CONFIG_TARGET_C139)
-	AI_ResetBit(1);
-    #endif
-    keypad_bl_off();
+	UBYTE on_off;
+
+	/* PWL indication for development */
+	switch (set_state) {
+	case LIGHT_STATUS_OFF:
+		*(volatile SYS_UWORD8 *)0xFFFE8000 = 0;
+		on_off = 0;
+		break;
+	case LIGHT_STATUS_ON:
+		*(volatile SYS_UWORD8 *)0xFFFE8000 = 255;
+		on_off = 1;
+		break;
+	case LIGHT_STATUS_INCALL:
+		*(volatile SYS_UWORD8 *)0xFFFE8000 = 16;
+		on_off = 1;
+		break;
+	case LIGHT_STATUS_CHG_BOOT:
+		*(volatile SYS_UWORD8 *)0xFFFE8000 = 64;
+		on_off = 1;
+		break;
+	default:
+		return;		/* error, but we are a void function */
+	}
+	/* physical backlight on/off */
+	if (on_off)
+		AI_SetBit(9);
+	else
+		AI_ResetBit(9);
 }
+
+#elif defined(CONFIG_TARGET_C139)
+
+static void blrr_display_ctrl(UBYTE set_state)
+{
+	if (set_state != LIGHT_STATUS_OFF)
+		AI_SetBit(1);
+	else
+		AI_ResetBit(1);
+}
+
+#else
+
+static void blrr_display_ctrl(UBYTE set_state)
+{
+}
+
+#endif
--- a/src/ui/mfw/mfw_mme.c	Thu Apr 22 21:23:16 2021 +0000
+++ b/src/ui/mfw/mfw_mme.c	Fri Apr 23 23:52:02 2021 +0000
@@ -168,11 +168,6 @@
 static U8 battState = 0;                /* state of power supply    */
 static U16 hdsPresence = 0;             /* headset presence         */
 
-/* backlight control internals */
-#define	LIGHT_LEVEL_OFF	0
-#define	LIGHT_LEVEL_LOW	16
-#define	LIGHT_LEVEL_MAX	255
-
 UBYTE mme_backlight_incall, mme_backlight_notimer;
 static U8 current_backlight_level;
 
@@ -462,7 +457,7 @@
 {
 	timStop(&bltimIdleH);
 	timStop(&bltimCallH);
-	mmeBackLight(LIGHT_LEVEL_MAX);
+	mmeBackLight(LIGHT_STATUS_ON);
 	if (mme_backlight_notimer)
 		return;
 	if (mme_backlight_incall)
@@ -475,21 +470,21 @@
 {
 	int ret;
 
-	ret = (current_backlight_level == LIGHT_LEVEL_OFF);
+	ret = (current_backlight_level == LIGHT_STATUS_OFF);
 	timStop(&bltimIdleH);
 	timStop(&bltimCallH);
-	mmeBackLight(LIGHT_LEVEL_MAX);
+	mmeBackLight(LIGHT_STATUS_ON);
 	return ret;
 }
 
 static int bl_timeout_idle (U32 t, void *h)
 {
-	mmeBackLight(LIGHT_LEVEL_OFF);
+	mmeBackLight(LIGHT_STATUS_OFF);
 }
 
 static int bl_timeout_call (U32 t, void *h)
 {
-	mmeBackLight(LIGHT_LEVEL_LOW);
+	mmeBackLight(LIGHT_STATUS_INCALL);
 }