GeneralDeviceInterface.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:132k
源码类别:

MTK

开发平台:

C/C++

  1.     #endif /* defined(__MMI_SUBLCD__) */ 
  2.         /* redraw main lcd */
  3.         gdi_lcd_repaint_all();
  4.         /* resume screensaver if it is playing before sleep-in, must after lcd sleep out */
  5.         mmi_scrsvr_lcd_sleepout_handler();
  6.     #if defined(__WIFI_SUPPORT__) && defined (__MTK_TARGET__)
  7.         wndrv_LCD_isON();
  8.     #endif /* #if defined(__WIFI_SUPPORT__) && defined (__MTK_TARGET__) */
  9.         
  10.         /* tvout sleepout */
  11.     #ifdef __MMI_TVOUT__
  12.         mmi_phnset_tvout_lcd_sleepout_handler();
  13.     #endif 
  14.     #ifdef __MMI_TOUCH_SCREEN__
  15.         /* diamond, 2006/06/09 Pen will not be blocked if keypad lock timeout after backlight is off */
  16.         if ((g_idle_context.IsOnIdleScreen || g_idle_context.IsOnSimErrorScreen)&& g_keylock_context.gKeyPadLockFlag)
  17.         {
  18.             mmi_pen_block();
  19.         }
  20.     #endif /* __MMI_TOUCH_SCREEN__ */ 
  21.     }
  22. #endif /* MMI_ON_HARDWARE_P */ 
  23. }
  24. /*****************************************************************************
  25.  * FUNCTION
  26.  *  GpioTurnOnKeypadLight
  27.  * DESCRIPTION
  28.  *  turn on keypad backlight
  29.  *  
  30.  *  PARAMETERS:
  31.  *  void
  32.  *****************************************************************************/
  33. static void GpioTurnOnKeypadLight(void)
  34. {
  35. #ifdef MMI_ON_HARDWARE_P
  36. //KP Jerry add on 2007-03-26 start
  37. #ifdef __MMI_PROFILE_POWER_SAVING__
  38. if(GetCurrentActivatedProfileKeyBKStatus())
  39. {
  40. #endif
  41. //KP Jerry add on 2007-03-26 end
  42.     /*----------------------------------------------------------------*/
  43.     /* Local Variables                                                */
  44.     /*----------------------------------------------------------------*/
  45.     /*----------------------------------------------------------------*/
  46.     /* Code Body                                                      */
  47.     /*----------------------------------------------------------------*/
  48.     /* turn on keypad backlight if currently off and clam open */
  49.     if (keypad_backlight == 0 && gMMIClamState == 1 && g_keylock_context.gKeyPadLockFlag == 0)
  50.     {
  51.         KeyPadBackLightOn();
  52.         keypad_backlight = 1;
  53.     }
  54.     StartTimer(GPIO_KEYPAD_LIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, GpioTurnOffKeypadLight);
  55. //KP Jerry add on 2007-03-26 start
  56. #ifdef __MMI_PROFILE_POWER_SAVING__
  57. }
  58. #endif
  59. //KP Jerry add on 2007-03-26 end
  60. #endif /* MMI_ON_HARDWARE_P */ 
  61. }
  62. //KP Jerry add on 2007-4-25 start
  63. void SetkeypadBacklightStuatus(U8 value)
  64. {
  65. keypad_backlight = value;
  66. }
  67. //KP Jerry add on 2007-4-25 end
  68. #ifdef MMI_BK_LIGHT_DELAY_TIME
  69. /*****************************************************************************
  70.  * FUNCTION
  71.  *  mmi_gpio_set_main_lcd_level_5
  72.  * DESCRIPTION
  73.  *  Set main LCD level to 5.
  74.  *  PARAMETERS:
  75.  *  void
  76.  *****************************************************************************/
  77. static void mmi_gpio_set_main_lcd_level_5(void)
  78. {
  79.     /*----------------------------------------------------------------*/
  80.     /* Local Variables                                                */
  81.     /*----------------------------------------------------------------*/
  82.     /*----------------------------------------------------------------*/
  83.     /* Code Body                                                      */
  84.     /*----------------------------------------------------------------*/
  85.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  86. }
  87. #endif /* MMI_BK_LIGHT_DELAY_TIME */ 
  88. /*****************************************************************************
  89.  * FUNCTION
  90.  *  IsBacklightOn
  91.  * DESCRIPTION
  92.  *  Test whether the backlight is on (half-light or full-light)
  93.  *  
  94.  *  PARAMETERS:
  95.  *  void
  96.  *****************************************************************************/
  97. MMI_BOOL IsBacklightOn(void)
  98. {
  99.     /*----------------------------------------------------------------*/
  100.     /* Local Variables                                                */
  101.     /*----------------------------------------------------------------*/
  102.     /*----------------------------------------------------------------*/
  103.     /* Code Body                                                      */
  104.     /*----------------------------------------------------------------*/
  105.     if (lcd_backlight)
  106.     {
  107.         return MMI_TRUE;
  108.     }
  109.     else
  110.     {
  111.         return MMI_FALSE;
  112.     }
  113. }
  114. /*****************************************************************************
  115.  * FUNCTION
  116.  *  HalfModeBacklight
  117.  * DESCRIPTION
  118.  *  Takes the Backlight to Half Mode
  119.  *  (Backlit is dimmed but not black)
  120.  *  
  121.  *  PARAMETERS: void
  122.  *  void
  123.  *****************************************************************************/
  124. void HalfModeBacklight(void)
  125. {
  126. #ifdef MMI_ON_HARDWARE_P
  127.     /*----------------------------------------------------------------*/
  128.     /* Local Variables                                                */
  129.     /*----------------------------------------------------------------*/
  130.     /*----------------------------------------------------------------*/
  131.     /* Code Body                                                      */
  132.     /*----------------------------------------------------------------*/
  133.     if (gbacklight_mode == 1)   /* for AT command */
  134.     {
  135.         if (sublcd_backlight == 0)
  136.         {
  137.             SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL5);
  138.             sublcd_backlight = 1;
  139.         }
  140.         if (lcd_backlight == 0 && gMMIClamState == 1)   /* sleep mode */
  141.         {
  142.         #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  143.             GpioLCDSleepOut();
  144.             UI_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
  145.             update_mainlcd_dt_display();
  146.             update_sublcd_dt_display();
  147.             /* resume screensaver if it is playing before sleep-in, must after lcd sleep out */
  148.             mmi_scrsvr_lcd_sleepout_handler();
  149.             /* tvout sleepout */
  150.         #ifdef __MMI_TVOUT__
  151.             mmi_phnset_tvout_lcd_sleepout_handler();
  152.         #endif 
  153.         #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  154.             SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL1);
  155.             lcd_backlight = 1;
  156.         }
  157.         if (isTimerSuspend == 1)
  158.         {
  159.             if (mmi_bootup_get_active_flight_mode() == 0)
  160.             {
  161.                 evshed_resume_all_events(event_scheduler1_ptr);
  162.             }
  163.             isTimerSuspend = 0;
  164.         }
  165.         if (gBackLightTimerStatus > 1)
  166.         {
  167.             StopTimer(BACKLIGHT_TIMER);
  168.             StartTimer(BACKLIGHT_TIMER, LCD_CLAM_OPEN_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  169.             gBackLightTimerStatus = 2;
  170.         }
  171.     }
  172. #endif /* MMI_ON_HARDWARE_P */ 
  173. }
  174. #if defined(__MMI_SYNC_LCD_GPIO_MODE__)
  175. /*****************************************************************************
  176.  * FUNCTION
  177.  *  mmi_gpio_turn_on_all_light
  178.  * DESCRIPTION
  179.  *  Turn on all light to whole bright
  180.  * PARAMETERS
  181.  *  void
  182.  * RETURNS
  183.  *  void
  184.  *****************************************************************************/
  185. static void mmi_gpio_turn_on_all_light(void)
  186. {
  187. #ifdef MMI_ON_HARDWARE_P
  188.     /*----------------------------------------------------------------*/
  189.     /* Local Variables                                                */
  190.     /*----------------------------------------------------------------*/
  191.     /*----------------------------------------------------------------*/
  192.     /* Code Body                                                      */
  193.     /*----------------------------------------------------------------*/
  194.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "turn_on_all_light() lcd_backlight=%d", lcd_backlight));    
  195.     
  196.     GpioLCDSleepOut();
  197.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  198.     lcd_backlight = 2;
  199. #endif /* MMI_ON_HARDWARE_P */ 
  200. }
  201. /*****************************************************************************
  202.  * FUNCTION
  203.  *  mmi_gpio_turn_off_all_light
  204.  * DESCRIPTION
  205.  *  Turn off all light to whole dark
  206.  * PARAMETERS
  207.  *  void
  208.  * RETURNS
  209.  *  void
  210.  *****************************************************************************/
  211. static void mmi_gpio_turn_off_all_light(void)
  212. {
  213. #ifdef MMI_ON_HARDWARE_P
  214.     /*----------------------------------------------------------------*/
  215.     /* Local Variables                                                */
  216.     /*----------------------------------------------------------------*/
  217.     /*----------------------------------------------------------------*/
  218.     /* Code Body                                                      */
  219.     /*----------------------------------------------------------------*/
  220.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "turn_off_all_light() lcd_backlight=%d", lcd_backlight));    
  221.     
  222.     /* set lcd backlight to half mode */
  223.     if (lcd_backlight != 0) /* backlight is on */
  224.     {
  225.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL0);
  226.         lcd_backlight = 0;
  227.     }
  228. #endif /* MMI_ON_HARDWARE_P */ 
  229. }
  230. /*****************************************************************************
  231.  * FUNCTION
  232.  *  TurnOffBacklight
  233.  * DESCRIPTION
  234.  *  It is typically paired with TurnOnBacklight(0) in order to resume backlight timer.
  235.  *  
  236.  *  PARAMETERS: void
  237.  *  void
  238.  *****************************************************************************/
  239. void TurnOffBacklight(void)
  240. {
  241.     /*----------------------------------------------------------------*/
  242.     /* Local Variables                                                */
  243.     /*----------------------------------------------------------------*/
  244.     /*----------------------------------------------------------------*/
  245.     /* Code Body                                                      */
  246.     /*----------------------------------------------------------------*/
  247.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "TurnOffBacklight(): lcd_backlight=%d, BLTimerStat=%d", lcd_backlight, gBackLightTimerStatus));    
  248.     
  249.     /* Share the same code for target and PC simulator */
  250.     /* AT command disables backlight mechanism */
  251.     if (gbacklight_mode == 0)
  252.     {
  253.         return;
  254.     }
  255.     if (gBackLightTimerStatus == 0)
  256.     {
  257.         StopTimer(BACKLIGHT_TIMER);
  258.         StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  259.         gBackLightTimerStatus = 1;
  260.     }
  261. }
  262. /*****************************************************************************
  263.  * FUNCTION
  264.  *  BacklightTimerHdlr
  265.  * DESCRIPTION
  266.  *  Timer handler to switch backlight state
  267.  *  
  268.  *  PARAMETERS: void
  269.  *  void
  270.  *****************************************************************************/
  271. static void BacklightTimerHdlr(void)
  272. {
  273. #ifdef MMI_ON_HARDWARE_P
  274.     /*----------------------------------------------------------------*/
  275.     /* Local Variables                                                */
  276.     /*----------------------------------------------------------------*/
  277.     /*----------------------------------------------------------------*/
  278.     /* Code Body                                                      */
  279.     /*----------------------------------------------------------------*/
  280.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "BacklightTimerHdlr() lcd_backlight=%d, BLTimerStat=%d", lcd_backlight, gBackLightTimerStatus));    
  281.     /* AT command disables backlight mechanism */
  282.     if (gbacklight_mode == 0)
  283.     {
  284.         return;
  285.     }
  286.     if (gBackLightTimerStatus == 0)
  287.     {
  288.         StopTimer(BACKLIGHT_TIMER);
  289.         StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  290.         gBackLightTimerStatus = 1;
  291.     }
  292.     else if (gBackLightTimerStatus == 1)
  293.     {
  294.         if (lcd_backlight == 2)
  295.         {
  296.             SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL1);
  297.             lcd_backlight = 1;
  298.         }
  299.         StopTimer(BACKLIGHT_TIMER);
  300.         StartTimer(BACKLIGHT_TIMER, LCD_CLAM_OPEN_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  301.         gBackLightTimerStatus = 2;
  302.     }
  303.     else    /* gBackLightTimerStatus == 2 */
  304.     {
  305.         if (lcd_backlight == 1)
  306.         {
  307.             if(/*!backlight_check_call_present()    //KP Jerry disable on 2006-12-21
  308.             &&*/ (g_phb_cntx.processing == FALSE)
  309.             /*&& (mdi_audio_get_state() != MDI_AUDIO_RECORD) && (mdi_audio_get_state() != MDI_AUDIO_RECORD_PAUSED)*/)    //KP Jerry disable on 2006-12-21
  310.             {
  311.                 SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL0);
  312.             #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)   /* { */
  313.                 GpioLCDSleepIn();
  314.             #ifdef __MMI_LCMSLEEP_BACK2IDLE__
  315.                 LCMSleepGotoIdleScreen();
  316.             #endif 
  317.             #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ /* } */
  318.                 lcd_backlight = 0;
  319.             }
  320.             gBackLightTimerStatus = 3;
  321.         }
  322.     #ifdef __MMI_CLAMSHELL__
  323.         if (isTimerSuspend == 0
  324.             && g_charbat_context.isChargerConnected == 0
  325. && !backlight_check_call_present()
  326. && mmi_msg_need_mem_full_ind() == 0 
  327. && g_phb_cntx.processing == FALSE
  328.     #if defined(__MMI_VIDEO_PLAYER__) && defined(__MMI_TVOUT__)
  329.             && mmi_vdoply_is_in_play_and_tvout_enable() == MMI_FALSE
  330.     #endif 
  331. /*&& mdi_audio_get_state() != MDI_AUDIO_RECORD && mdi_audio_get_state() != MDI_AUDIO_RECORD_PAUSED*/ )    //KP Jerry disable on 2006-12-21
  332.     #else /* __MMI_CLAMSHELL__ */ 
  333. if (isTimerSuspend == 0 && g_charbat_context.isChargerConnected == 0 
  334. && !backlight_check_call_present()
  335.     #if defined(__MMI_VIDEO_PLAYER__) && defined(__MMI_TVOUT__)
  336.             && mmi_vdoply_is_in_play_and_tvout_enable() == MMI_FALSE
  337.     #endif 
  338. && g_phb_cntx.processing == FALSE /*&& mdi_audio_get_state() != MDI_AUDIO_RECORD && mdi_audio_get_state() != MDI_AUDIO_RECORD_PAUSED*/ )    //KP Jerry disable on 2006-12-21
  339.     #endif /* __MMI_CLAMSHELL__ */ 
  340.         {
  341.             if (mmi_bootup_get_active_flight_mode() == 0)
  342.             {
  343.                 evshed_suspend_all_events(event_scheduler1_ptr);
  344.             }
  345.             isTimerSuspend = 1;
  346.         }
  347.     }
  348. #else /* MMI_ON_HARDWARE_P */ /* For PC Simulator only */
  349.     if (gbacklight_mode == 1)
  350.     {
  351.         if (gBackLightTimerStatus == 0)
  352.         {
  353.             StopTimer(BACKLIGHT_TIMER);
  354.             StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  355.             gBackLightTimerStatus = 1;
  356.         }
  357.         else if (gBackLightTimerStatus == 1)
  358.         {
  359.             if (lcd_backlight == 2)
  360.             {
  361.                 simulate_lcd_bklight_turn_off();
  362.                 lcd_backlight = 1;
  363.             }
  364.             if (sublcd_backlight == 1)
  365.             {
  366.                 simulate_sublcd_bklight_turn_off();
  367.                 sublcd_backlight = 0;
  368.             }
  369.             StopTimer(BACKLIGHT_TIMER);
  370.             StartTimer(BACKLIGHT_TIMER, LCD_CLAM_OPEN_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  371.             gBackLightTimerStatus = 2;
  372.         }
  373.         else    /* gBackLightTimerStatus == 2 */
  374.         {
  375.             if (sublcd_backlight == 1)
  376.             {
  377.                 simulate_sublcd_bklight_turn_off();
  378.                 sublcd_backlight = 0;
  379.             }
  380.             if (lcd_backlight == 1)
  381.             {
  382.                 simulate_lcd_bklight_turn_off();
  383.             }
  384.             gBackLightTimerStatus = 3;
  385.         }
  386.     }
  387. #endif /* MMI_ON_HARDWARE_P */ 
  388. }
  389. /*****************************************************************************
  390.  * FUNCTION
  391.  *  TurnOnBacklight
  392.  * DESCRIPTION
  393.  *  Turns On the backlight
  394.  * PARAMETERS
  395.  *  time_enum       [IN]        Time duration type
  396.  *****************************************************************************/
  397. void TurnOnBacklight(gpio_backlight_time_enum time_enum)
  398. {
  399. #ifdef MMI_ON_HARDWARE_P        /* { */
  400.     /*----------------------------------------------------------------*/
  401.     /* Local Variables                                                */
  402.     /*----------------------------------------------------------------*/
  403.     /*----------------------------------------------------------------*/
  404.     /* Code Body                                                      */
  405.     /*----------------------------------------------------------------*/
  406.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "TurnOnBacklight() time_enum=%d, BLTimerStat=%d", time_enum, gBackLightTimerStatus));    
  407.     
  408.     /* AT command disables backlight mechanism */
  409.     if (gbacklight_mode == 0)
  410.     {
  411.         return;
  412.     }
  413. #ifdef MMI_BK_LIGHT_DELAY_TIME
  414.     StopMyTimer(GPIO_BACKLIGHT_DELAY_TIMER);
  415. #endif 
  416.     /* resume timer if suspended */
  417.     if (isTimerSuspend == 1)
  418.     {
  419.         if (mmi_bootup_get_active_flight_mode() == 0)
  420.         {
  421.             evshed_resume_all_events(event_scheduler1_ptr);
  422.         }
  423.         isTimerSuspend = 0;
  424.     }
  425.     
  426. #ifdef LCM_MMI_TYPE_QUERY
  427. #ifdef __MMI_LCD_PARTIAL_ON__
  428.     /* If LCD is transmissive, there is meanless for partial display.
  429.        But if LCD is reflective or transflective, user can see the display when backlight is off.
  430.        In this case, when turn on backlight, handset should leave Screen saver */
  431.    if (get_lcm_type)
  432.    {
  433.        if (get_lcm_type() == LCM_TRANSFLECTIVE_TYPE)
  434.         {
  435.             LeavePartialOnScreenSaverIfOk();
  436.         }
  437.     }
  438. #endif    
  439. #endif /* LCM_MMI_TYPE_QUERY */
  440.     /* lcd backlight */
  441.     if (lcd_backlight == 0)
  442.     {
  443.         lcd_backlight = 2;
  444.     #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  445.         GpioLCDSleepOut();
  446.     #endif 
  447.     #ifdef __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__       /* { */
  448.     #ifdef MMI_BK_LIGHT_DELAY_TIME
  449.         StartTimer(GPIO_BACKLIGHT_DELAY_TIMER, MMI_BK_LIGHT_DELAY_TIME, mmi_gpio_set_main_lcd_level_5);
  450.     #else 
  451.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  452.     #endif 
  453.     #else /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* }{ */
  454.         if (gMMIClamState == 1) /* clam is opened */
  455.         {
  456.         #ifdef MMI_BK_LIGHT_DELAY_TIME
  457.             StartTimer(GPIO_BACKLIGHT_DELAY_TIMER, MMI_BK_LIGHT_DELAY_TIME, mmi_gpio_set_main_lcd_level_5);
  458.         #else 
  459.             SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  460.         #endif 
  461.             lcd_backlight = 2;
  462.         }
  463.         else    /* clam is closed */
  464.         {
  465.         #ifndef __MMI_SLIDE__
  466.             SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL1);
  467.             lcd_backlight = 1;
  468.         #else
  469.             #ifdef MMI_BK_LIGHT_DELAY_TIME
  470.                 StartTimer(GPIO_BACKLIGHT_DELAY_TIMER, MMI_BK_LIGHT_DELAY_TIME, mmi_gpio_set_main_lcd_level_5);
  471.             #else 
  472.                 SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  473.             #endif 
  474.                 lcd_backlight = 2;        
  475.         #endif 
  476.         }
  477.     #endif /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* } */
  478.     }
  479.     else if (lcd_backlight == 1)
  480.     {
  481.     #ifdef __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__
  482.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  483.         lcd_backlight = 2;
  484.     #else /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* }{ */
  485.     #ifndef __MMI_SLIDE__
  486.         if (gMMIClamState == 1 || !mmi_bootup_is_searching_or_idle_reached())   /* clam is opened */
  487.     #endif 
  488.         {
  489.             SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  490.             lcd_backlight = 2;
  491.         }
  492.     #endif /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* } */
  493.     }
  494.     /* turn on keypad backlight if currently off and clam open */
  495.     GpioTurnOnKeypadLight();
  496.     /* start/stop timer according to input parameter */
  497.     if (time_enum == GPIO_BACKLIGHT_PERMANENT)
  498.     {
  499.         StopTimer(BACKLIGHT_TIMER);
  500.         gBackLightTimerStatus = 0;
  501.     }
  502.     else if (gBackLightTimerStatus != 0)    /* start a timer */
  503.     {
  504.         StopTimer(BACKLIGHT_TIMER);
  505.     #ifdef __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__
  506.         StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  507.         gBackLightTimerStatus = 1;
  508.     #else /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* }{ */
  509.     #if defined (__MMI_CLAMSHELL__) && !defined(__MMI_SLIDE__)
  510.         if (gMMIClamState == 1) /* clam is opened */
  511.         {
  512.             StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  513.             gBackLightTimerStatus = 1;
  514.         }
  515.         else    /* clam is closed */
  516.         {
  517.             StartTimer(BACKLIGHT_TIMER, LCD_CLAM_CLOSE_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  518.             gBackLightTimerStatus = 1;
  519.         }
  520.     #else /* defined (__MMI_CLAMSHELL__) && !defined(__MMI_SLIDE__) */ 
  521.         StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  522.         gBackLightTimerStatus = 1;
  523.     #endif /* defined (__MMI_CLAMSHELL__) && !defined(__MMI_SLIDE__) */ 
  524.     #endif /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* } */
  525.     }
  526. #else /* MMI_ON_HARDWARE_P */ /* For PC Simulator only */                                                  /* }{ */
  527.     if (gbacklight_mode == 1)
  528.     {
  529.         if (sublcd_backlight == 0)
  530.         {
  531.             simulate_sublcd_bklight_turn_on();
  532.             sublcd_backlight = 1;
  533.         }
  534.         if (lcd_backlight == 0)
  535.         {
  536.             simulate_lcd_bklight_turn_on();
  537.             lcd_backlight = 2;
  538.         }
  539.         else if (lcd_backlight == 1)
  540.         {
  541.             simulate_lcd_bklight_turn_on();
  542.             lcd_backlight = 2;
  543.         }
  544.     }
  545.     if (time_enum == GPIO_BACKLIGHT_PERMANENT)
  546.     {
  547.         StopTimer(BACKLIGHT_TIMER);
  548.         gBackLightTimerStatus = 0;
  549.     }
  550.     else
  551.     {
  552.         if (gBackLightTimerStatus != 0) /* start a timer */
  553.         {
  554.             StopTimer(BACKLIGHT_TIMER);
  555.             StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  556.             gBackLightTimerStatus = 1;
  557.         }
  558.     }
  559. #endif /* MMI_ON_HARDWARE_P */ /* } */
  560. }
  561. /*****************************************************************************
  562.  * FUNCTION
  563.  *  CloseBacklight
  564.  * DESCRIPTION
  565.  *  Immeditae Baclight Close not going thru Half Mode
  566.  *  
  567.  *  PARAMETERS: void
  568.  *  void
  569.  *****************************************************************************/
  570. void CloseBacklight(void)
  571. {
  572. #ifdef MMI_ON_HARDWARE_P
  573.     /*----------------------------------------------------------------*/
  574.     /* Local Variables                                                */
  575.     /*----------------------------------------------------------------*/
  576.     /*----------------------------------------------------------------*/
  577.     /* Code Body                                                      */
  578.     /*----------------------------------------------------------------*/
  579.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "CloseBacklight() lcd_backlight=%d BLTimerStat=%d", lcd_backlight, gBackLightTimerStatus));    
  580.     
  581.     /* AT command disables backlight mechanism */
  582.     if (gbacklight_mode == 0)
  583.     {
  584.         return;
  585.     }
  586.     /* stop backlight timer */
  587.     if (gBackLightTimerStatus != 0)
  588.     {
  589.         StopTimer(BACKLIGHT_TIMER);
  590.     }
  591. #ifdef __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__       /* { */
  592.     if (lcd_backlight == 1) /* backlight is half light */
  593.     {
  594.         lcd_backlight = 2;
  595.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  596.     }
  597.     else if (lcd_backlight == 0)    /* backlight is off */
  598.     {
  599.         lcd_backlight = 2;
  600.     #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  601.         GpioLCDSleepOut();
  602.         update_mainlcd_dt_display();
  603.         update_sublcd_dt_display();
  604.         gdi_layer_blt_previous(0, 0, UI_device_width - 1, UI_device_height - 1);
  605.         GpioWakeUpTimer();
  606.         gIsInSleepMode = 0;
  607.         /* resume screensaver if it is playing before sleep-in, must after lcd sleep out */
  608.         mmi_scrsvr_lcd_sleepout_handler();
  609.         SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL5);
  610.     #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  611.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  612.     }
  613. #else /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* }{ */
  614.     /* set lcd backlight to half mode */
  615.     if (lcd_backlight == 2) /* backlight is on */
  616.     {
  617.         lcd_backlight = 1;
  618.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL1);
  619.     }
  620.     else if (lcd_backlight == 0)    /* backlight is off */
  621.     {
  622.         lcd_backlight = 1;
  623.     #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  624.         GpioLCDSleepOut();
  625.         update_mainlcd_dt_display();
  626.         update_sublcd_dt_display();
  627.         gdi_layer_blt_previous(0, 0, UI_device_width - 1, UI_device_height - 1);
  628.         GpioWakeUpTimer();
  629.         gIsInSleepMode = 0;
  630.         /* resume screensaver if it is playing before sleep-in, must after lcd sleep out */
  631.         mmi_scrsvr_lcd_sleepout_handler();
  632.         SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL5);
  633.     #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  634.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  635.     }
  636. #endif /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ /* } */
  637.     /* turn off keypad backlight */
  638.     GpioTurnOffKeypadLight();
  639. #ifdef __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__
  640.     StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  641.     gBackLightTimerStatus = 1;
  642. #else /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ 
  643.     StartTimer(BACKLIGHT_TIMER, LCD_CLAM_CLOSE_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  644.     gBackLightTimerStatus = 2;
  645. #endif /* __MMI_GPIO_3_STAGE_SUB_BACKLIGHT__ */ 
  646. #endif /* MMI_ON_HARDWARE_P */ 
  647. }
  648. #else /* defined(__MMI_SYNC_LCD_GPIO_MODE__) */ 
  649. /*****************************************************************************
  650.  * FUNCTION
  651.  *  mmi_gpio_turn_on_all_light
  652.  * DESCRIPTION
  653.  *  Turn on all light to whole bright
  654.  * PARAMETERS
  655.  *  void
  656.  * RETURNS
  657.  *  void
  658.  *****************************************************************************/
  659. static void mmi_gpio_turn_on_all_light(void)
  660. {
  661. #ifdef MMI_ON_HARDWARE_P
  662.     /*----------------------------------------------------------------*/
  663.     /* Local Variables                                                */
  664.     /*----------------------------------------------------------------*/
  665.     /*----------------------------------------------------------------*/
  666.     /* Code Body                                                      */
  667.     /*----------------------------------------------------------------*/
  668.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "turn_on_all_light() lcd_backlight=%d, BLTimerStat=%d", lcd_backlight, gBackLightTimerStatus));    
  669.     
  670.     GpioLCDSleepOut();
  671.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  672.     lcd_backlight = 2;
  673.     SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL5);
  674.     sublcd_backlight = 2;
  675. #endif /* MMI_ON_HARDWARE_P */ 
  676. }
  677. /*****************************************************************************
  678.  * FUNCTION
  679.  *  mmi_gpio_turn_off_all_light
  680.  * DESCRIPTION
  681.  *  Turn off all light to whole dark
  682.  * PARAMETERS
  683.  *  void
  684.  * RETURNS
  685.  *  void
  686.  *****************************************************************************/
  687. static void mmi_gpio_turn_off_all_light(void)
  688. {
  689. #ifdef MMI_ON_HARDWARE_P
  690.     /*----------------------------------------------------------------*/
  691.     /* Local Variables                                                */
  692.     /*----------------------------------------------------------------*/
  693.     /*----------------------------------------------------------------*/
  694.     /* Code Body                                                      */
  695.     /*----------------------------------------------------------------*/
  696.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "turn_off_all_light() lcd_backlight=%d", lcd_backlight));    
  697.     
  698.     /* set lcd backlight to half mode */
  699.     if (lcd_backlight != 0) /* backlight is on */
  700.     {
  701.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL0);
  702.         lcd_backlight = 0;
  703.     }
  704.     /* turn on sub-lcd baclight */
  705.     if (sublcd_backlight != 0)
  706.     {
  707.         SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL0);
  708.         sublcd_backlight = 0;
  709.     }
  710. #endif /* MMI_ON_HARDWARE_P */ 
  711. }
  712. /*****************************************************************************
  713.  * FUNCTION
  714.  *  TurnOffBacklight
  715.  * DESCRIPTION
  716.  *  Turns Off the backlight
  717.  *  
  718.  *  PARAMETERS: void
  719.  *  void
  720.  *****************************************************************************/
  721. void TurnOffBacklight(void)
  722. {
  723.     /*----------------------------------------------------------------*/
  724.     /* Local Variables                                                */
  725.     /*----------------------------------------------------------------*/
  726.     /*----------------------------------------------------------------*/
  727.     /* Code Body                                                      */
  728.     /*----------------------------------------------------------------*/
  729.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "TurnOffBacklight() lcd_backlight=%d, BLTimerStat=%d", lcd_backlight, gBackLightTimerStatus));    
  730.         
  731.     /* Share the same code for target and PC simulator */
  732.     /* AT command disables backlight mechanism */
  733.     if (gbacklight_mode == 0)
  734.     {
  735.         return;
  736.     }
  737.     if (gBackLightTimerStatus == 0) /* resume backlight mechanism */
  738.     {
  739.         StopTimer(BACKLIGHT_TIMER);
  740.         StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  741.         gBackLightTimerStatus = 1;
  742.     }
  743. }
  744. /*****************************************************************************
  745.  * FUNCTION
  746.  *  BacklightTimerHdlr
  747.  * DESCRIPTION
  748.  *  Timer handler to switch backlight state
  749.  *  
  750.  *  PARAMETERS: void
  751.  *  void
  752.  *****************************************************************************/
  753. static void BacklightTimerHdlr(void)
  754. {
  755. #ifdef MMI_ON_HARDWARE_P
  756.     /*----------------------------------------------------------------*/
  757.     /* Local Variables                                                */
  758.     /*----------------------------------------------------------------*/
  759.     /*----------------------------------------------------------------*/
  760.     /* Code Body                                                      */
  761.     /*----------------------------------------------------------------*/
  762.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "BacklightTimerHdlr() lcd_backlight=%d, BLTimerStat=%d", lcd_backlight, gBackLightTimerStatus));    
  763.     
  764.     /* AT command disables backlight mechanism */
  765.     if (gbacklight_mode == 0)
  766.     {
  767.         return;
  768.     }
  769.     if (gBackLightTimerStatus == 0) /* resume backlight mechanism */
  770.     {
  771.         gBackLightTimerStatus = 1;
  772.         StopTimer(BACKLIGHT_TIMER);
  773.         StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  774.     }
  775.     else if (gBackLightTimerStatus == 1)
  776.     {
  777.         if (lcd_backlight == 2) /* full light, switch to half light */
  778.         {
  779.             SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL1);
  780.             lcd_backlight = 1;
  781.         }
  782.         if (sublcd_backlight == 1)
  783.         {
  784.             sublcd_backlight = 0;
  785.             SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL0);
  786.         }
  787.         StopTimer(BACKLIGHT_TIMER);
  788.     #ifdef __MMI_CLAMSHELL__
  789.         if (gMMIClamState == 0)
  790.         {
  791.             StartTimer(BACKLIGHT_TIMER, LCD_CLAM_CLOSE_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  792.         }
  793.         else
  794.     #endif /* __MMI_CLAMSHELL__ */ 
  795.             StartTimer(BACKLIGHT_TIMER, LCD_CLAM_OPEN_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  796.         gBackLightTimerStatus = 2;
  797.     }
  798.     else    /* gBackLightTimerStatus == 2 */
  799.     {
  800.         if (sublcd_backlight == 1)
  801.         {
  802.             SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL0);
  803.             sublcd_backlight = 0;
  804.         }
  805.         if (lcd_backlight == 1)
  806.         {
  807.             if(/*!backlight_check_call_present()    //KP Jerry disable on 2006-12-21
  808.             &&*/ (g_phb_cntx.processing == FALSE)
  809.             /*&& (mdi_audio_get_state() != MDI_AUDIO_RECORD) && (mdi_audio_get_state() != MDI_AUDIO_RECORD_PAUSED)*/)    //KP Jerry disable on 2006-12-21
  810.             {
  811.             #ifdef __MMI_LCD_PARTIAL_ON__
  812.                 /* We do not enter partial display screen saver before idle screen */
  813.                 if (((mmi_bootup_is_searching_or_idle_reached() == MMI_TRUE) || mmi_bootup_is_sim_removed() == MMI_TRUE)
  814.                     && PhnsetIsScrSvrPartialOn())
  815.                 {
  816.                     /* 1. Turn off backlight if defined(__MMI_GPIO_DISABLE_SLEEP_MODE__), but keep
  817.                        half backlight if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__).
  818.                        (Typically __MMI_GPIO_DISABLE_SLEEP_MODE__ means that LCM can 
  819.                        retain display even when backlight is turned off, and hence we
  820.                        can turn off backlight without making LCM sleep.)
  821.                        
  822.                        2. __MMI_LCMSLEEP_BACK2IDLE__ is currently ignored */
  823.                     if (gBackLightTimerStatus == 2)
  824.                     {
  825.                         EnterPartialOnScreenSaverIfOk();
  826.                     }
  827.                 #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  828.                     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL0);
  829.                     lcd_backlight = 0;
  830.                 #endif /* defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  831.                 }
  832.                 else
  833.             #endif /* __MMI_LCD_PARTIAL_ON__ */ 
  834.                 {
  835.                     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL0);
  836.                 #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  837.                     GpioLCDSleepIn();
  838.                 #ifdef __MMI_LCMSLEEP_BACK2IDLE__
  839.                     LCMSleepGotoIdleScreen();
  840.                 #endif 
  841.                 #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  842.                     lcd_backlight = 0;
  843.                 }
  844.             }
  845.             gBackLightTimerStatus = 3;
  846.         }
  847. if (isTimerSuspend == 0 && g_charbat_context.isChargerConnected == 0 
  848. && !backlight_check_call_present()
  849.     #ifdef __MMI_CLAMSHELL__
  850.             && mmi_msg_need_mem_full_ind() == 0
  851.     #endif 
  852.     #if defined(__MMI_VIDEO_PLAYER__) && defined(__MMI_TVOUT__)
  853.             && mmi_vdoply_is_in_play_and_tvout_enable() == MMI_FALSE
  854.     #endif 
  855.             && g_phb_cntx.processing == FALSE
  856. /*&& mdi_audio_get_state() != MDI_AUDIO_RECORD && mdi_audio_get_state() != MDI_AUDIO_RECORD_PAUSED*/ )    //KP Jerry disable on 2006-12-21
  857.         {
  858.             if (mmi_bootup_get_active_flight_mode() == 0)
  859.             {
  860.                 evshed_suspend_all_events(event_scheduler1_ptr);
  861.             }
  862.             isTimerSuspend = 1;
  863.         }
  864.     }
  865. #else /* MMI_ON_HARDWARE_P */ /* For PC Simulator only */
  866.     if (gbacklight_mode == 1)
  867.     {
  868.         if (gBackLightTimerStatus == 0)
  869.         {
  870.             StopTimer(BACKLIGHT_TIMER);
  871.             StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  872.             gBackLightTimerStatus = 1;
  873.         }
  874.         else if (gBackLightTimerStatus == 1)
  875.         {
  876.             if (lcd_backlight == 2)
  877.             {
  878.                 simulate_lcd_bklight_turn_off();
  879.                 lcd_backlight = 1;
  880.             }
  881.             if (sublcd_backlight == 1)
  882.             {
  883.                 simulate_sublcd_bklight_turn_off();
  884.                 sublcd_backlight = 0;
  885.             }
  886.             StopTimer(BACKLIGHT_TIMER);
  887.             StartTimer(BACKLIGHT_TIMER, LCD_CLAM_OPEN_HALFLITE_TO_OFF_TIME, BacklightTimerHdlr);
  888.             gBackLightTimerStatus = 2;
  889.         }
  890.         else    /* gBackLightTimerStatus == 2 */
  891.         {
  892.             if (sublcd_backlight == 1)
  893.             {
  894.                 simulate_sublcd_bklight_turn_off();
  895.                 sublcd_backlight = 0;
  896.             }
  897.             if (lcd_backlight == 1)
  898.             {
  899.                 simulate_lcd_bklight_turn_off();
  900.             }
  901.             gBackLightTimerStatus = 3;
  902.         }
  903.     }
  904. #endif /* MMI_ON_HARDWARE_P */ 
  905. }
  906. /*****************************************************************************
  907.  * FUNCTION
  908.  *  TurnOnBacklight
  909.  * DESCRIPTION
  910.  *  Turns On the backlight
  911.  * PARAMETERS
  912.  *  time_enum       [IN]        Time duration type
  913.  *****************************************************************************/
  914. void TurnOnBacklight(gpio_backlight_time_enum time_enum)
  915. {
  916. #ifdef MMI_ON_HARDWARE_P
  917.     /*----------------------------------------------------------------*/
  918.     /* Local Variables                                                */
  919.     /*----------------------------------------------------------------*/
  920.     /*----------------------------------------------------------------*/
  921.     /* Code Body                                                      */
  922.     /*----------------------------------------------------------------*/
  923.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "TurnOnBacklight() time_enum=%d, BLTimerStat=%d", time_enum, gBackLightTimerStatus));    
  924.     
  925.     /* AT command disables backlight mechanism */
  926.     if (gbacklight_mode == 0)
  927.     {
  928.         return;
  929.     }
  930. #ifdef MMI_BK_LIGHT_DELAY_TIME
  931.     StopMyTimer(GPIO_BACKLIGHT_DELAY_TIMER);
  932. #endif 
  933.     /* resume timer if suspended */
  934.     if (isTimerSuspend == 1)
  935.     {
  936.         if (mmi_bootup_get_active_flight_mode() == 0)
  937.         {
  938.             evshed_resume_all_events(event_scheduler1_ptr);
  939.         }
  940.         isTimerSuspend = 0;
  941.     }
  942. #ifdef LCM_MMI_TYPE_QUERY
  943. #ifdef __MMI_LCD_PARTIAL_ON__
  944.     /* If LCD is transmissive, there is meanless for partial display.
  945.        But if LCD is reflective or transflective, user can see the display when backlight is off.
  946.        In this case, when turn on backlight, handset should leave Screen saver */
  947.    if (get_lcm_type)
  948.    {
  949.        if (get_lcm_type() == LCM_TRANSFLECTIVE_TYPE)
  950.         {
  951.             LeavePartialOnScreenSaverIfOk();
  952.         }
  953.     }
  954. #endif    
  955. #endif /* #ifdef LCM_MMI_TYPE_QUERY */
  956.     /* turn on sub-lcd backlight if currently off */
  957.     if (sublcd_backlight == 0)
  958.     {
  959.         SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL5);
  960.         sublcd_backlight = 1;
  961.     #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) && defined(__MMI_SUBLCD__)
  962.         {
  963.             S32 lcd_width;
  964.             S32 lcd_height;
  965.             gdi_lcd_set_active(GDI_LCD_SUB_LCD_HANDLE);
  966.             gdi_lcd_get_dimension(&lcd_width, &lcd_height);
  967.             UI_BLT_double_buffer(0, 0, lcd_width - 1, lcd_height - 1);
  968.             gdi_lcd_set_active(GDI_LCD_MAIN_LCD_HANDLE);
  969.         }
  970.     #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) && defined(__MMI_SUBLCD__) */ 
  971.     }
  972.     if (lcd_backlight == 0 && gMMIClamState == 1)   /* sleep mode and clam open */
  973.     {
  974.     #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  975.         GpioLCDSleepOut();
  976.         update_mainlcd_dt_display();
  977.         update_sublcd_dt_display();
  978.         UI_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
  979.         /* resume screensaver if it is playing before sleep-in */
  980.         mmi_scrsvr_lcd_sleepout_handler();
  981.         /* tvout sleepout */
  982.     #ifdef __MMI_TVOUT__
  983.         mmi_phnset_tvout_lcd_sleepout_handler();
  984.     #endif 
  985.     #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  986.     #ifdef MMI_BK_LIGHT_DELAY_TIME
  987.         StartTimer(GPIO_BACKLIGHT_DELAY_TIMER, MMI_BK_LIGHT_DELAY_TIME, mmi_gpio_set_main_lcd_level_5);
  988.     #else 
  989.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  990.     #endif 
  991.         lcd_backlight = 2;
  992.     }
  993.     else if (lcd_backlight == 1 && gMMIClamState == 1)  /* backlight off and clam open */
  994.     {
  995.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  996.         lcd_backlight = 2;
  997.     }
  998.     else if (lcd_backlight == 2 && gMMIClamState == 1)  /* backlight off and clam open */
  999.     {
  1000.      SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  1001.     }
  1002.     /* turn on keypad backlight if currently off and clam open */
  1003.     GpioTurnOnKeypadLight();
  1004.     /* start/stop timer according to input parameter */
  1005.     if (time_enum == GPIO_BACKLIGHT_PERMANENT)
  1006.     {
  1007.         StopTimer(BACKLIGHT_TIMER);
  1008.         gBackLightTimerStatus = 0;
  1009.     }
  1010.     else if (gBackLightTimerStatus != 0)    /* start a timer */
  1011.     {
  1012.         StopTimer(BACKLIGHT_TIMER);
  1013.         StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  1014.         gBackLightTimerStatus = 1;
  1015.     }
  1016. #else /* MMI_ON_HARDWARE_P */ /* For PC Simulator only */
  1017.     if (gbacklight_mode == 1)
  1018.     {
  1019.         if (sublcd_backlight == 0)
  1020.         {
  1021.             simulate_sublcd_bklight_turn_on();
  1022.             sublcd_backlight = 1;
  1023.         }
  1024.         if (lcd_backlight == 0)
  1025.         {
  1026.             simulate_lcd_bklight_turn_on();
  1027.             lcd_backlight = 2;
  1028.         }
  1029.         else if (lcd_backlight == 1)
  1030.         {
  1031.             simulate_lcd_bklight_turn_on();
  1032.             lcd_backlight = 2;
  1033.         }
  1034.     }
  1035.     if (time_enum == GPIO_BACKLIGHT_PERMANENT)
  1036.     {
  1037.         StopTimer(BACKLIGHT_TIMER);
  1038.         gBackLightTimerStatus = 0;
  1039.     }
  1040.     else
  1041.     {
  1042.         if (gBackLightTimerStatus != 0)
  1043.         {
  1044.             StopTimer(BACKLIGHT_TIMER);
  1045.             StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  1046.             gBackLightTimerStatus = 1;
  1047.         }
  1048.     }
  1049. #endif /* MMI_ON_HARDWARE_P */ 
  1050. }
  1051. /*****************************************************************************
  1052.  * FUNCTION
  1053.  *  CloseBacklight
  1054.  * DESCRIPTION
  1055.  *  Immeditae Baclight Close not going thru Half Mode
  1056.  *  We do not handle __MMI_LCD_PARTIAL_ON__ because CloseBacklight() is used only in clamshell
  1057.  *  
  1058.  *  PARAMETERS: void
  1059.  *  void
  1060.  *****************************************************************************/
  1061. void CloseBacklight()
  1062. {
  1063. #ifdef MMI_ON_HARDWARE_P
  1064.     /*----------------------------------------------------------------*/
  1065.     /* Local Variables                                                */
  1066.     /*----------------------------------------------------------------*/
  1067.     /*----------------------------------------------------------------*/
  1068.     /* Code Body                                                      */
  1069.     /*----------------------------------------------------------------*/
  1070.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "CloseBacklight() lcd_backlight=%d, BLTimerStat=%d", lcd_backlight, gBackLightTimerStatus));    
  1071.     
  1072.     /* AT command disables backlight mechanism */
  1073.     if (gbacklight_mode == 0)
  1074.     {
  1075.         return;
  1076.     }
  1077.     /* stop backlight timer */
  1078.     if (gBackLightTimerStatus != 0)
  1079.     {
  1080.         StopTimer(BACKLIGHT_TIMER);
  1081.     }
  1082.     /* turn off main-lcd backlight */
  1083.     if (lcd_backlight != 0)
  1084.     {
  1085.         SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL0);
  1086.     #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  1087.         GpioLCDSleepIn();
  1088.     #ifdef __MMI_LCMSLEEP_BACK2IDLE__
  1089.         LCMSleepGotoIdleScreen();
  1090.     #endif 
  1091.     #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  1092.         lcd_backlight = 0;
  1093.     }
  1094.     /* turn off keypad backlight */
  1095.     GpioTurnOffKeypadLight();
  1096.     /* turn on sub-lcd baclight */
  1097.     if (sublcd_backlight == 0)
  1098.     {
  1099.         GpioWakeUpTimer();
  1100.         gIsInSleepMode = 0;
  1101.         GpioLCDSleepOut();
  1102.         SetGPIOLevelReq(GPIO_DEV_LED_SUBLCD, LED_LIGHT_LEVEL5);
  1103.         sublcd_backlight = 1;
  1104.     }
  1105.     StartTimer(BACKLIGHT_TIMER, g_phnset_gpio_cntx_p->bl_setting_hftime * 1000, BacklightTimerHdlr);
  1106.     gBackLightTimerStatus = 2;
  1107. #endif /* MMI_ON_HARDWARE_P */ 
  1108. }
  1109. #endif /* defined(__MMI_SYNC_LCD_GPIO_MODE__) */ 
  1110. /*****************************************************************************
  1111.  * FUNCTION
  1112.  *  mmi_gpio_backlight_ctrl_req_hdlr
  1113.  * DESCRIPTION
  1114.  *  Handler of MSG_ID_MMIAPI_BACKLIGHT_CONTROL_REQ
  1115.  * PARAMETERS
  1116.  *  msg     [IN]        Requested data
  1117.  * RETURNS
  1118.  *  void
  1119.  *****************************************************************************/
  1120. void mmi_gpio_backlight_ctrl_req_hdlr(void *msg)
  1121. {
  1122. #ifdef MMI_ON_HARDWARE_P
  1123.     /*----------------------------------------------------------------*/
  1124.     /* Local Variables                                                */
  1125.     /*----------------------------------------------------------------*/
  1126.     mmiapi_backlight_control_req_struct *req = (mmiapi_backlight_control_req_struct*) msg;
  1127.     mmiapi_backlight_control_rsp_struct *rsp =
  1128.         (mmiapi_backlight_control_rsp_struct*) OslConstructDataPtr(sizeof(mmiapi_backlight_control_rsp_struct));
  1129.     MYQUEUE Message;
  1130.     /*----------------------------------------------------------------*/
  1131.     /* Code Body                                                      */
  1132.     /*----------------------------------------------------------------*/
  1133.     StopTimer(BACKLIGHT_TIMER);
  1134.     if (req->on_off)
  1135.     {
  1136.         if (req->disable_timer)
  1137.         {
  1138.             mmi_gpio_turn_on_all_light();
  1139.         }
  1140.         else
  1141.         {
  1142.             if (gBackLightTimerStatus < 2 || gbacklight_mode == 0)
  1143.             {   /* resume backlight timer and turn on the backlight */
  1144.                 TurnOnBacklight(1);
  1145.             }
  1146.             else
  1147.             {
  1148.                 gBackLightTimerStatus = 0;
  1149.                 TurnOffBacklight();
  1150.             }
  1151.         }
  1152.     }
  1153.     else
  1154.     {
  1155.         mmi_gpio_turn_off_all_light();
  1156.     }
  1157.     if (gBackLightTimerStatus == 0) /* timer disabled */
  1158.     {
  1159.         rsp->disable_timer = TRUE;
  1160.     }
  1161.     else
  1162.     {
  1163.         rsp->disable_timer = FALSE;
  1164.     }
  1165.     rsp->on_off = req->on_off;
  1166.     Message.oslSrcId = MOD_MMI;
  1167.     Message.oslDestId = MOD_MED;
  1168.     Message.oslMsgId = MSG_ID_MMIAPI_BACKLIGHT_CONTROL_RSP;
  1169.     Message.oslDataPtr = (oslParaType*) rsp;
  1170.     Message.oslPeerBuffPtr = NULL;
  1171.     OslMsgSendExtQueue(&Message);
  1172. #endif /* MMI_ON_HARDWARE_P */ 
  1173. }
  1174. /*****************************************************************************
  1175.  * FUNCTION
  1176.  *  mmi_gpio_led_ctrl_req_hdlr
  1177.  * DESCRIPTION
  1178.  *  Handler of MSG_ID_MMIAPI_LED_CONTROL_REQ
  1179.  * PARAMETERS
  1180.  *  msg     [IN]        Requested data
  1181.  * RETURNS
  1182.  *  void
  1183.  *****************************************************************************/
  1184. void mmi_gpio_led_ctrl_req_hdlr(void *msg)
  1185. {
  1186. #ifdef MMI_ON_HARDWARE_P
  1187.     /*----------------------------------------------------------------*/
  1188.     /* Local Variables                                                */
  1189.     /*----------------------------------------------------------------*/
  1190.     mmiapi_led_control_req_struct *req = (mmiapi_led_control_req_struct*) msg;
  1191.     mmiapi_led_control_rsp_struct *rsp =
  1192.         (mmiapi_led_control_rsp_struct*) OslConstructDataPtr(sizeof(mmiapi_led_control_rsp_struct));
  1193.     MYQUEUE Message;
  1194.     /*----------------------------------------------------------------*/
  1195.     /* Code Body                                                      */
  1196.     /*----------------------------------------------------------------*/
  1197.     if (req->on_off)
  1198.     {
  1199.         /* disable led background play pattern */
  1200.         gpioOutOfCtrl = 1;
  1201.         StopLEDPatternBackGround();
  1202.         /* turn on led */
  1203.         SetBackLightStatusRedOn();
  1204.         SetBackLightStatusGreenOn();
  1205.         SetBackLightStatusBlueOn();
  1206.     }
  1207.     else
  1208.     {
  1209.         /* turn off led */
  1210.         SetBackLightStatusRedOff();
  1211.         SetBackLightStatusGreenOff();
  1212.         SetBackLightStatusBlueOff();
  1213.         /* enable led background play pattern */
  1214.         gpioOutOfCtrl = 0;
  1215.         StartLEDPatternBackGround();
  1216.     }
  1217.     rsp->on_off = req->on_off;
  1218.     Message.oslSrcId = MOD_MMI;
  1219.     Message.oslDestId = MOD_MED;
  1220.     Message.oslMsgId = MSG_ID_MMIAPI_LED_CONTROL_RSP;
  1221.     Message.oslDataPtr = (oslParaType*) rsp;
  1222.     Message.oslPeerBuffPtr = NULL;
  1223.     OslMsgSendExtQueue(&Message);
  1224. #endif /* MMI_ON_HARDWARE_P */ 
  1225. }
  1226. /*****************************************************************************
  1227.  * FUNCTION
  1228.  *  InitHWBacklightTest
  1229.  * DESCRIPTION
  1230.  *  Initialisation function for Back Light Test
  1231.  *  
  1232.  *  PARAMETERS: void
  1233.  *  void
  1234.  *****************************************************************************/
  1235. void InitHWBacklightTest(void)
  1236. {
  1237.     /*----------------------------------------------------------------*/
  1238.     /* Local Variables                                                */
  1239.     /*----------------------------------------------------------------*/
  1240.     /*----------------------------------------------------------------*/
  1241.     /* Code Body                                                      */
  1242.     /*----------------------------------------------------------------*/
  1243. #ifdef MMI_ON_HARDWARE_P
  1244.     SetProtocolEventHandler(SetBacklightMode, MSG_ID_MMI_EQ_SET_SLEEP_MODE_REQ_IND);
  1245. #endif 
  1246. }
  1247. /*****************************************************************************
  1248.  * FUNCTION
  1249.  *  SetBacklightModeExe
  1250.  * DESCRIPTION
  1251.  *  Sets BackLight Mode
  1252.  *  
  1253.  *  PARAMETERS: void
  1254.  *  mode        [IN]        
  1255.  *****************************************************************************/
  1256. void SetBacklightModeExe(U8 mode)
  1257. {
  1258. #ifdef MMI_ON_HARDWARE_P
  1259.     /*----------------------------------------------------------------*/
  1260.     /* Local Variables                                                */
  1261.     /*----------------------------------------------------------------*/
  1262.     /*----------------------------------------------------------------*/
  1263.     /* Code Body                                                      */
  1264.     /*----------------------------------------------------------------*/
  1265.     if (mode == 1)  /* enable backlight mechanism. */
  1266.     {
  1267.         gbacklight_mode = mode;
  1268.         TurnOffBacklight();
  1269.     }
  1270.     else    /* disable backlight mechanism. */
  1271.     {
  1272.         gbacklight_mode = 1;
  1273.         TurnOnBacklight(0);
  1274.         gbacklight_mode = mode;
  1275.     }
  1276. #endif /* MMI_ON_HARDWARE_P */ 
  1277. }
  1278. /*****************************************************************************
  1279.  * FUNCTION
  1280.  *  SetBacklightMode
  1281.  * DESCRIPTION
  1282.  *  Protocol Handler for MSG_ID_MMI_EQ_SET_SLEEP_MODE_REQ_IND
  1283.  *  
  1284.  *  PARAMETERS: info: Data from L4
  1285.  *  info        [IN]        
  1286.  *****************************************************************************/
  1287. void SetBacklightMode(void *info)
  1288. {
  1289. #ifdef MMI_ON_HARDWARE_P
  1290.     /*----------------------------------------------------------------*/
  1291.     /* Local Variables                                                */
  1292.     /*----------------------------------------------------------------*/
  1293.     mmi_eq_set_sleep_mode_req_ind_struct *msg = (mmi_eq_set_sleep_mode_req_ind_struct*) info;
  1294.     /*----------------------------------------------------------------*/
  1295.     /* Code Body                                                      */
  1296.     /*----------------------------------------------------------------*/
  1297.     SetBacklightModeExe((U8) msg->on_off);
  1298. #endif /* MMI_ON_HARDWARE_P */ 
  1299. }
  1300. /*
  1301.  * Audio volume path                                
  1302.  */
  1303. /*****************************************************************************
  1304.  * FUNCTION
  1305.  *  EnableHandsFree
  1306.  * DESCRIPTION
  1307.  *  Enables Hands Free Mode
  1308.  *  
  1309.  *  PARAMETERS: mode
  1310.  *  void
  1311.  *****************************************************************************/
  1312. void EnableHandsFree(void)
  1313. {
  1314.     /*----------------------------------------------------------------*/
  1315.     /* Local Variables                                                */
  1316.     /*----------------------------------------------------------------*/
  1317.     /*----------------------------------------------------------------*/
  1318.     /* Code Body                                                      */
  1319.     /*----------------------------------------------------------------*/
  1320.     mdi_audio_set_audio_mode(AUD_MODE_LOUDSPK);
  1321.     SetModeSpeechVolume();
  1322. }
  1323. /*****************************************************************************
  1324.  * FUNCTION
  1325.  *  DisbleHandsFree
  1326.  * DESCRIPTION
  1327.  *  Disables Hands Free Mode
  1328.  *  
  1329.  *  PARAMETERS: mode
  1330.  *  void
  1331.  *****************************************************************************/
  1332. void DisbleHandsFree(void)
  1333. {
  1334.     /*----------------------------------------------------------------*/
  1335.     /* Local Variables                                                */
  1336.     /*----------------------------------------------------------------*/
  1337.     /*----------------------------------------------------------------*/
  1338.     /* Code Body                                                      */
  1339.     /*----------------------------------------------------------------*/
  1340.     if (isEarphonePlugged)
  1341.     {
  1342.     #ifdef __CTM_SUPPORT__
  1343.         if (mmi_ctm_is_tty_on() == MMI_FALSE)
  1344.     #endif 
  1345.         {
  1346.             mdi_audio_set_audio_mode(AUD_MODE_HEADSET);
  1347.             SetModeSpeechVolume();
  1348.             return;
  1349.         }
  1350.     }
  1351.     mdi_audio_set_audio_mode(AUD_MODE_NORMAL);
  1352.     SetModeSpeechVolume();
  1353. }
  1354. /*****************************************************************************
  1355.  * FUNCTION
  1356.  *  SaveSpeechVolume
  1357.  * DESCRIPTION
  1358.  *  Saves Speech Volume
  1359.  *  
  1360.  *  PARAMETERS:
  1361.  *  level       [IN]        
  1362.  *****************************************************************************/
  1363. void SaveSpeechVolume(U8 level)
  1364. {
  1365.     /*----------------------------------------------------------------*/
  1366.     /* Local Variables                                                */
  1367.     /*----------------------------------------------------------------*/
  1368.     S16 error;
  1369.     U8 audio_mode = mdi_audio_get_audio_mode();
  1370.     /*----------------------------------------------------------------*/
  1371.     /* Code Body                                                      */
  1372.     /*----------------------------------------------------------------*/
  1373.     switch (audio_mode)
  1374.     {
  1375.         case AUD_MODE_NORMAL:
  1376.             WriteValue(NVRAM_NORMAL_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1377.             break;
  1378.         case AUD_MODE_HEADSET:
  1379.             WriteValue(NVRAM_HDSET_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1380.             break;
  1381.         case AUD_MODE_LOUDSPK:
  1382.             WriteValue(NVRAM_LDSPK_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1383.             break;
  1384.     }
  1385.     SetSpeechVolume(level);
  1386. }
  1387. /*****************************************************************************
  1388.  * FUNCTION
  1389.  *  SetModeSpeechVolume
  1390.  * DESCRIPTION
  1391.  *  Sets Speech Volume as per the mode
  1392.  *  
  1393.  *  PARAMETERS: void
  1394.  *  void
  1395.  *****************************************************************************/
  1396. void SetModeSpeechVolume(void)
  1397. {
  1398.     /*----------------------------------------------------------------*/
  1399.     /* Local Variables                                                */
  1400.     /*----------------------------------------------------------------*/
  1401.     U8 audio_mode = mdi_audio_get_audio_mode();
  1402.     U8 level;
  1403.     S16 error;
  1404.     /*----------------------------------------------------------------*/
  1405.     /* Code Body                                                      */
  1406.     /*----------------------------------------------------------------*/
  1407.     switch (audio_mode)
  1408.     {
  1409.         case AUD_MODE_NORMAL:
  1410.             ReadValue(NVRAM_NORMAL_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1411.             break;
  1412.         case AUD_MODE_HEADSET:
  1413.             ReadValue(NVRAM_HDSET_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1414.             break;
  1415.         case AUD_MODE_LOUDSPK:
  1416.             ReadValue(NVRAM_LDSPK_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1417.             break;
  1418.     }
  1419.     if (level == 0xFF)
  1420.     {
  1421.         level = LEVEL4;
  1422.         WriteValue(NVRAM_HDSET_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1423.         WriteValue(NVRAM_LDSPK_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1424.         WriteValue(NVRAM_NORMAL_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1425.     }
  1426.     SetSpeechVolume(level);
  1427. }
  1428. /*****************************************************************************
  1429.  * FUNCTION
  1430.  *  GetModeSpeechVolume
  1431.  * DESCRIPTION
  1432.  *  Gets Speech Volume as per the mode
  1433.  *  
  1434.  *  PARAMETERS: void
  1435.  *  void
  1436.  *****************************************************************************/
  1437. U8 GetModeSpeechVolume(void)
  1438. {
  1439.     /*----------------------------------------------------------------*/
  1440.     /* Local Variables                                                */
  1441.     /*----------------------------------------------------------------*/
  1442.     U8 audio_mode = mdi_audio_get_audio_mode();
  1443.     U8 level;
  1444.     S16 error;
  1445.     /*----------------------------------------------------------------*/
  1446.     /* Code Body                                                      */
  1447.     /*----------------------------------------------------------------*/
  1448.     switch (audio_mode)
  1449.     {
  1450.         case AUD_MODE_NORMAL:
  1451.             ReadValue(NVRAM_NORMAL_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1452.             break;
  1453.         case AUD_MODE_HEADSET:
  1454.             ReadValue(NVRAM_HDSET_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1455.             break;
  1456.         case AUD_MODE_LOUDSPK:
  1457.             ReadValue(NVRAM_LDSPK_MODE_VOICE_LEVEL, &level, DS_BYTE, &error);
  1458.             break;
  1459.     }
  1460.     if (level == 0xFF)
  1461.     {
  1462.         level = LEVEL4;
  1463.     }
  1464.     return level;
  1465. }
  1466. /*
  1467.  * Device control interface for other modules
  1468.  */
  1469. /*****************************************************************************
  1470.  * FUNCTION
  1471.  *  GpioCtrlReq
  1472.  * DESCRIPTION
  1473.  *  Api for other modules get gpio control
  1474.  *  
  1475.  *  PARAMETERS: action: MMIAPI_DEV_CTRL_GET / MMIAPI_DEV_CTRL_RELEASE
  1476.  *  action      [IN]        
  1477.  *****************************************************************************/
  1478. kal_uint8 GpioCtrlReq(kal_uint8 action)
  1479. {
  1480.     /*----------------------------------------------------------------*/
  1481.     /* Local Variables                                                */
  1482.     /*----------------------------------------------------------------*/
  1483.     U8 result = MMI_TRUE;
  1484.     /*----------------------------------------------------------------*/
  1485.     /* Code Body                                                      */
  1486.     /*----------------------------------------------------------------*/
  1487.     if (action == MMIAPI_DEV_CTRL_GET)
  1488.     {
  1489.         if (gpioOutOfCtrl == 1)
  1490.         {
  1491.             result = MMI_FALSE;
  1492.         }
  1493.         else
  1494.         {
  1495.             gpioOutOfCtrl = 1;
  1496.             StopLEDPatternBackGround();
  1497.         }
  1498.     }
  1499.     else if (action == MMIAPI_DEV_CTRL_RELEASE)
  1500.     {
  1501.         if (gpioOutOfCtrl == 0)
  1502.         {
  1503.             result = MMI_FALSE;
  1504.         }
  1505.         else
  1506.         {
  1507.             gpioOutOfCtrl = 0;
  1508.             StartLEDPatternBackGround();
  1509.             GpioTurnOffKeypadLight();
  1510.             TurnOnBacklight(1);
  1511.         }
  1512.     }
  1513.     else
  1514.     {
  1515.         result = MMI_FALSE;
  1516.     }
  1517.     return result;
  1518. }
  1519. /*****************************************************************************
  1520.  * FUNCTION
  1521.  *  GpioCtrlReqHdlr
  1522.  * DESCRIPTION
  1523.  *  Other module get device control through MMI
  1524.  *  
  1525.  *  PARAMETERS: mmiapi_device_get_ctrl_req_struct *
  1526.  *  inMsg       [IN]        
  1527.  *****************************************************************************/
  1528. void GpioCtrlReqHdlr(void *inMsg)
  1529. {
  1530. #ifdef MMI_ON_HARDWARE_P
  1531.     /*----------------------------------------------------------------*/
  1532.     /* Local Variables                                                */
  1533.     /*----------------------------------------------------------------*/
  1534.     mmiapi_device_get_ctrl_req_struct *p = (mmiapi_device_get_ctrl_req_struct*) inMsg;
  1535.     mmiapi_device_get_ctrl_rsp_struct *p_out;
  1536.     /*----------------------------------------------------------------*/
  1537.     /* Code Body                                                      */
  1538.     /*----------------------------------------------------------------*/
  1539.     p_out = OslConstructDataPtr(sizeof(mmiapi_device_get_ctrl_rsp_struct));
  1540.     p_out->result = GpioCtrlReq(p->action);
  1541.     GpioSendMsg(p->src_mod_id, MSG_ID_MMIAPI_DEVICE_GET_CTRL_RSP, (void*)p_out, (void*)NULL);
  1542. #endif /* MMI_ON_HARDWARE_P */ 
  1543. }
  1544. /*****************************************************************************
  1545.  * FUNCTION
  1546.  *  GpioPlayReq
  1547.  * DESCRIPTION
  1548.  *  Other module control gpio device
  1549.  *  
  1550.  *  PARAMETERS: p_type, p_level
  1551.  *  p_type      [IN]        
  1552.  *  p_level     [IN]        
  1553.  *****************************************************************************/
  1554. kal_uint8 GpioPlayReq(kal_uint8 p_type, kal_uint8 p_level)
  1555. {
  1556.     /*----------------------------------------------------------------*/
  1557.     /* Local Variables                                                */
  1558.     /*----------------------------------------------------------------*/
  1559.     U8 result = MMI_TRUE;
  1560.     U8 device = 0, level = 0;
  1561.     /*----------------------------------------------------------------*/
  1562.     /* Code Body                                                      */
  1563.     /*----------------------------------------------------------------*/
  1564.     switch (p_type)
  1565.     {
  1566.         case MMIAPI_DEV_TYPE_MAINLCD_BL:
  1567.             device = GPIO_DEV_LED_MAINLCD;
  1568.             break;
  1569.         case MMIAPI_DEV_TYPE_SUBLCD_BL:
  1570.             device = GPIO_DEV_LED_SUBLCD;
  1571.             break;
  1572.         case MMIAPI_DEV_TYPE_KEYPAD_BL:
  1573.             device = GPIO_DEV_LED_KEY;
  1574.             break;
  1575.         case MMIAPI_DEV_TYPE_LED_1:
  1576.             device = GPIO_DEV_LED_STATUS_1;
  1577.             break;
  1578.         case MMIAPI_DEV_TYPE_LED_2:
  1579.             device = GPIO_DEV_LED_STATUS_2;
  1580.             break;
  1581.         case MMIAPI_DEV_TYPE_LED_3:
  1582.             device = GPIO_DEV_LED_STATUS_3;
  1583.             break;
  1584.         case MMIAPI_DEV_TYPE_VIBRATOR:
  1585.             device = GPIO_DEV_VIBRATOR;
  1586.             break;
  1587.         default:
  1588.             result = MMI_FALSE;
  1589.             break;
  1590.     }
  1591.     switch (p_level)
  1592.     {
  1593.         case MMIAPI_DEV_LEVEL_0:
  1594.             level = LED_LIGHT_LEVEL0;
  1595.             break;
  1596.         case MMIAPI_DEV_LEVEL_1:
  1597.             level = LED_LIGHT_LEVEL1;
  1598.             break;
  1599.         case MMIAPI_DEV_LEVEL_2:
  1600.             level = LED_LIGHT_LEVEL2;
  1601.             break;
  1602.         case MMIAPI_DEV_LEVEL_3:
  1603.             level = LED_LIGHT_LEVEL3;
  1604.             break;
  1605.         case MMIAPI_DEV_LEVEL_4:
  1606.             level = LED_LIGHT_LEVEL4;
  1607.             break;
  1608.         case MMIAPI_DEV_LEVEL_5:
  1609.             level = LED_LIGHT_LEVEL5;
  1610.             break;
  1611.         default:
  1612.             result = MMI_FALSE;
  1613.             break;
  1614.     }
  1615.     SetGPIOLevelReq(device, level);
  1616.     return result;
  1617. }
  1618. /*****************************************************************************
  1619.  * FUNCTION
  1620.  *  GpioPlayReqHdlr
  1621.  * DESCRIPTION
  1622.  *  Other module play device function through MMI
  1623.  *  
  1624.  *  PARAMETERS: mmiapi_device_play_req_struct *
  1625.  *  inMsg       [IN]        
  1626.  *****************************************************************************/
  1627. void GpioPlayReqHdlr(void *inMsg)
  1628. {
  1629. #ifdef MMI_ON_HARDWARE_P
  1630.     /*----------------------------------------------------------------*/
  1631.     /* Local Variables                                                */
  1632.     /*----------------------------------------------------------------*/
  1633.     mmiapi_device_play_req_struct *p = (mmiapi_device_play_req_struct*) inMsg;
  1634.     mmiapi_device_play_rsp_struct *p_out;
  1635.     /*----------------------------------------------------------------*/
  1636.     /* Code Body                                                      */
  1637.     /*----------------------------------------------------------------*/
  1638.     p_out = OslConstructDataPtr(sizeof(mmiapi_device_play_rsp_struct));
  1639.     p_out->result = GpioPlayReq(p->type, p->level);
  1640.     GpioSendMsg(p->src_mod_id, MSG_ID_MMIAPI_DEVICE_PLAY_RSP, (void*)p_out, (void*)NULL);
  1641. #endif /* MMI_ON_HARDWARE_P */ 
  1642. }
  1643. /*******************************************************/
  1644. /*                                                     */
  1645. /*    Send Message to Lower layer                      */
  1646. /*                                                     */
  1647. /*******************************************************/
  1648. /*****************************************************************************
  1649.  * FUNCTION
  1650.  *  SendPlayPatternReqToHW
  1651.  * DESCRIPTION
  1652.  *  Send pattern request to H/W
  1653.  *  
  1654.  *  PARAMETERS: pattern: pattern to be played
  1655.  *  pattern     [IN]        
  1656.  *  action      [IN]        ON/OFF
  1657.  *****************************************************************************/
  1658. void SendPlayPatternReqToHW(U8 pattern, U8 action)
  1659. {
  1660.     /*----------------------------------------------------------------*/
  1661.     /* Local Variables                                                */
  1662.     /*----------------------------------------------------------------*/
  1663.     MYQUEUE Message;
  1664.     mmi_eq_play_pattern_req_struct *displayLedPattern;
  1665.     /*----------------------------------------------------------------*/
  1666.     /* Code Body                                                      */
  1667.     /*----------------------------------------------------------------*/
  1668.     Message.oslMsgId = MSG_ID_MMI_EQ_PLAY_PATTERN_REQ;
  1669.     displayLedPattern = OslConstructDataPtr(sizeof(mmi_eq_play_pattern_req_struct));
  1670.     displayLedPattern->pattern = pattern;
  1671.     displayLedPattern->action = action;
  1672.     Message.oslDataPtr = (oslParaType*) displayLedPattern;
  1673.     Message.oslPeerBuffPtr = NULL;
  1674.     Message.oslSrcId = MOD_MMI;
  1675.     Message.oslDestId = MOD_L4C;
  1676.     OslMsgSendExtQueue(&Message);
  1677. }
  1678. /*****************************************************************************
  1679.  * FUNCTION
  1680.  *  SetGPIOLevelReq
  1681.  * DESCRIPTION
  1682.  *  Set Levels of Devices like LCD, LEDs
  1683.  *  
  1684.  *  PARAMETERS: device: device
  1685.  *  device      [IN]        
  1686.  *  level       [IN]        Device Level
  1687.  *****************************************************************************/
  1688. void SetGPIOLevelReq(gpio_device_enum device, U8 level)
  1689. {
  1690.     /*----------------------------------------------------------------*/
  1691.     /* Local Variables                                                */
  1692.     /*----------------------------------------------------------------*/
  1693.     MYQUEUE Message;
  1694.     mmi_eq_exe_gpio_level_req_struct *setGPIOLevelReq;
  1695.     /*----------------------------------------------------------------*/
  1696.     /* Code Body                                                      */
  1697.     /*----------------------------------------------------------------*/
  1698. #ifdef __LCD_ESD_RECOVERY__
  1699.     if ((device == GPIO_DEV_LED_MAINLCD) || (device == GPIO_DEV_LED_SUBLCD))
  1700.     {
  1701.         if (level == LED_LIGHT_LEVEL0)
  1702.         {
  1703.             gdi_lcd_stop_esd_recovery_timer();
  1704.         }
  1705.         else
  1706.         {
  1707.             gdi_lcd_start_esd_recovery_timer();
  1708.         }
  1709.     }
  1710. #endif /* __LCD_ESD_RECOVERY__ */ 
  1711.     Message.oslMsgId = MSG_ID_MMI_EQ_EXE_GPIO_LEVEL_REQ;
  1712.     setGPIOLevelReq = OslConstructDataPtr(sizeof(mmi_eq_exe_gpio_level_req_struct));
  1713.     setGPIOLevelReq->gpio_dev_type = device;
  1714.     if ((device == GPIO_DEV_LED_MAINLCD) && (level == LED_LIGHT_LEVEL5))
  1715.     {
  1716.         setGPIOLevelReq->gpio_dev_level = g_phnset_gpio_cntx_p->bl_setting_level;
  1717.     }
  1718.     else
  1719.     {
  1720.         setGPIOLevelReq->gpio_dev_level = level;
  1721.     }
  1722.     Message.oslDataPtr = (oslParaType*) setGPIOLevelReq;
  1723.     Message.oslPeerBuffPtr = NULL;
  1724.     Message.oslSrcId = MOD_MMI;
  1725.     Message.oslDestId = MOD_L4C;
  1726.     OslMsgSendExtQueue(&Message);
  1727.     return;
  1728. }
  1729. /*****************************************************************************
  1730.  * FUNCTION
  1731.  *  SetMuteReq
  1732.  * DESCRIPTION
  1733.  *  Mutes the device
  1734.  *  
  1735.  *  PARAMETERS: device: device
  1736.  *  device      [IN]        
  1737.  *  onoff       [IN]        TRUE/FALSE
  1738.  *****************************************************************************/
  1739. void SetMuteReq(audio_type_enum device, MMI_BOOL onoff)
  1740. {
  1741.     /*----------------------------------------------------------------*/
  1742.     /* Local Variables                                                */
  1743.     /*----------------------------------------------------------------*/
  1744.     MYQUEUE Message;
  1745.     mmi_eq_set_mute_req_struct *setMuteReq;
  1746.     /*----------------------------------------------------------------*/
  1747.     /* Code Body                                                      */
  1748.     /*----------------------------------------------------------------*/
  1749.     Message.oslMsgId = MSG_ID_MMI_EQ_SET_MUTE_REQ;
  1750.     setMuteReq = OslConstructDataPtr(sizeof(mmi_eq_set_mute_req_struct));
  1751.     setMuteReq->audio_device = device;
  1752.     setMuteReq->mute_onoff = onoff;
  1753.     Message.oslDataPtr = (oslParaType*) setMuteReq;
  1754.     Message.oslPeerBuffPtr = NULL;
  1755.     Message.oslSrcId = MOD_MMI;
  1756.     Message.oslDestId = MOD_L4C;
  1757.     OslMsgSendExtQueue(&Message);
  1758. }
  1759. /*****************************************************************************
  1760.  * FUNCTION
  1761.  *  GpioSendMsg
  1762.  * DESCRIPTION
  1763.  *  Send message to other modules
  1764.  *  
  1765.  *  PARAMETERS: mmiapi_device_play_req_struct *
  1766.  *  src_mod_id          [IN]        
  1767.  *  msg_id              [IN]        
  1768.  *  local_param_ptr     [IN]        
  1769.  *  peer_buf_ptr        [IN]        
  1770.  *****************************************************************************/
  1771. void GpioSendMsg(U16 src_mod_id, U16 msg_id, void *local_param_ptr, void *peer_buf_ptr)
  1772. {
  1773.     /*----------------------------------------------------------------*/
  1774.     /* Local Variables                                                */
  1775.     /*----------------------------------------------------------------*/
  1776. #ifdef MMI_ON_HARDWARE_P
  1777.     MYQUEUE Message;
  1778.     /*----------------------------------------------------------------*/
  1779.     /* Code Body                                                      */
  1780.     /*----------------------------------------------------------------*/
  1781.     Message.oslMsgId = (oslMsgType) msg_id;         /* Type casting, to make compiler happer */
  1782.     Message.oslDataPtr = (oslParaType*) local_param_ptr;
  1783.     Message.oslPeerBuffPtr = peer_buf_ptr;
  1784.     Message.oslSrcId = MOD_MMI;
  1785.     Message.oslDestId = (oslModuleType) src_mod_id; /* Type casting, to make compiler happer */
  1786.     OslMsgSendExtQueue(&Message);
  1787. #endif /* MMI_ON_HARDWARE_P */ 
  1788. }
  1789. /*****************************************************************************
  1790.  * FUNCTION
  1791.  *  KeyPadLCDBackLightStop
  1792.  * DESCRIPTION
  1793.  *  KeyPadLCDBackLightStop
  1794.  *  
  1795.  *  PARAMETERS: void
  1796.  *  void
  1797.  *  RETURNS:
  1798.  *  void
  1799.  *****************************************************************************/
  1800. void KeyPadLCDBackLightStop(void)
  1801. {
  1802.     /*----------------------------------------------------------------*/
  1803.     /* Local Variables                                                */
  1804.     /*----------------------------------------------------------------*/
  1805.     /*----------------------------------------------------------------*/
  1806.     /* Code Body                                                      */
  1807.     /*----------------------------------------------------------------*/
  1808.     StopTimer(TIMER_KEYPAD_BACKLIGHT);
  1809.     LCDBackLightOff();
  1810.     KeyPadBackLightOff();
  1811. }
  1812. /*****************************************************************************
  1813.  * FUNCTION
  1814.  *  LCMSleepGotoIdleScreen
  1815.  * DESCRIPTION
  1816.  *  KeyPadLCDBackLightStop
  1817.  *  
  1818.  *  PARAMETERS: void
  1819.  *  void
  1820.  *****************************************************************************/
  1821. #if defined(__MMI_LCMSLEEP_BACK2IDLE__)
  1822. void LCMSleepGotoIdleScreen(void)
  1823. {
  1824.     /*----------------------------------------------------------------*/
  1825.     /* Local Variables                                                */
  1826.     /*----------------------------------------------------------------*/
  1827.     /*----------------------------------------------------------------*/
  1828.     /* Code Body                                                      */
  1829.     /*----------------------------------------------------------------*/
  1830.     if (isEarphonePlugged == 1 && backlight_check_call_present())
  1831.     {
  1832.         return;
  1833.     }
  1834. #if defined(__MMI_FACTORY_MODE__) || defined(__MMI_ENGINEER_MODE__)
  1835.     if (gCurrentMode == FACTORY_MODE || gCurrentMode == ENGINEERING_MODE)
  1836.     {
  1837.         return;
  1838.     }
  1839. #endif /* defined(__MMI_FACTORY_MODE__) || defined(__MMI_ENGINEER_MODE__) */ 
  1840.     PRINT_INFORMATION(("LCMSleepGotoIdleScreen():END Key Press, FP: %x", GetKeyHandler(KEY_END, KEY_EVENT_DOWN)));
  1841.     ExecuteCurrKeyHandler(KEY_END, KEY_EVENT_DOWN);
  1842. }
  1843. #endif /* defined(__MMI_LCMSLEEP_BACK2IDLE__) */ 
  1844. /*****************************************************************************
  1845.  * FUNCTION
  1846.  *  mmi_gpio_is_lcd_sleep
  1847.  * DESCRIPTION
  1848.  *  To tell applications that lcd is sleeping or not
  1849.  * PARAMETERS
  1850.  *  void
  1851.  * RETURNS
  1852.  *  void
  1853.  *****************************************************************************/
  1854. BOOL mmi_gpio_is_lcd_sleep(void)
  1855. {
  1856.     /*----------------------------------------------------------------*/
  1857.     /* Local Variables                                                */
  1858.     /*----------------------------------------------------------------*/
  1859.     /*----------------------------------------------------------------*/
  1860.     /* Code Body                                                      */
  1861.     /*----------------------------------------------------------------*/
  1862.     return gIsInSleepMode;
  1863. }