优化cat1 电源控制接口
authorSnickerSun <snickersun@163.com>
Mon, 19 Feb 2024 03:56:05 +0000 (11:56 +0800)
committerSnickerSun <snickersun@163.com>
Mon, 19 Feb 2024 03:56:05 +0000 (11:56 +0800)
code/sdk/application/wstp/at_service/app/app_at_process.c
code/sdk/drivers/peripheral/utils/CMakeLists.txt
code/sdk/drivers/peripheral/utils/cat1_ctl.c [new file with mode: 0644]
code/sdk/drivers/peripheral/utils/cat1_ctl.h [new file with mode: 0644]
code/sdk/drivers/peripheral/utils/custom_utils.c

index 719053a..5a3c1d4 100755 (executable)
@@ -1631,6 +1631,8 @@ static uint32_t adc_manu_sample_adc(uint8_t *para, uint32_t para_len)
     wstp_print("manu adc sample , channel = %x , voltage = %.03f , percent = %u\r\n", channel,voltage,percent);\r
     return 0;\r
 }\r
+\r
+#include "cat1_ctl.h"\r
 static uint32_t cat1_power_on(uint8_t *para, uint32_t para_len)\r
 {\r
     uint32_t pwron = 0;\r
@@ -1642,12 +1644,10 @@ static uint32_t cat1_power_on(uint8_t *para, uint32_t para_len)
 \r
     if( pwron == 0)\r
     {\r
-        uapi_gpio_set_dir(S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT);\r
-        uapi_gpio_set_val(S_AGPIO_L23, HAL_GPIO_LEVEL_LOW);\r
+        uapi_cat1_power_on(0);\r
         wstp_print("Power OFF Cat1! L23 low  \r\n");\r
     }else{\r
-        uapi_gpio_set_dir(S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT);\r
-        uapi_gpio_set_val(S_AGPIO_L23, HAL_GPIO_LEVEL_HIGH);\r
+        uapi_cat1_power_on(1);\r
         wstp_print("Power ON Cat1! L23 high \r\n");\r
     }\r
     \r
@@ -1665,12 +1665,10 @@ static uint32_t cat1_reset(uint8_t *para, uint32_t para_len)
 \r
     if( pwron == 0)\r
     {\r
-        uapi_gpio_set_dir(S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT);\r
-        uapi_gpio_set_val(S_AGPIO_L28, HAL_GPIO_LEVEL_HIGH);\r
+        uapi_cat1_reset(0);\r
         wstp_print("clear reset Cat1! L28 high \r\n");\r
     }else{\r
-        uapi_gpio_set_dir(S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT);\r
-        uapi_gpio_set_val(S_AGPIO_L28, HAL_GPIO_LEVEL_LOW); \r
+        uapi_cat1_reset(1);\r
         wstp_print("Reset Cat1! L28 low\r\n");\r
     }\r
     \r
index 33ba8c3..1bfcf49 100644 (file)
@@ -6,6 +6,7 @@ set(COMPONENT_NAME "custom_utils")
 
 set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/custom_utils.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/cat1_ctl.c
     ${CMAKE_CURRENT_SOURCE_DIR}/custom_utils_at_cmd.c
 )
 
diff --git a/code/sdk/drivers/peripheral/utils/cat1_ctl.c b/code/sdk/drivers/peripheral/utils/cat1_ctl.c
new file mode 100644 (file)
index 0000000..2534a13
--- /dev/null
@@ -0,0 +1,37 @@
+
+
+#include "platform_core.h"
+#include "stdint.h"
+#include "pinctrl.h"
+#include "cat1_ctl.h"
+uint32_t uapi_cat1_power_on(uint32_t pwron)
+{
+
+    if( pwron == 0)
+    {
+        uapi_gpio_set_dir(S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L23, HAL_GPIO_LEVEL_LOW);
+        // wstp_print("Power OFF Cat1! L23 low  \r\n");
+    }else{
+        uapi_gpio_set_dir(S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L23, HAL_GPIO_LEVEL_HIGH);
+        // wstp_print("Power ON Cat1! L23 high \r\n");
+    }
+    
+    return 0;
+}
+uint32_t uapi_cat1_reset(uint32_t pwron)
+{
+    if( pwron == 0)
+    {
+        uapi_gpio_set_dir(S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L28, HAL_GPIO_LEVEL_HIGH);
+        // wstp_print("clear reset Cat1! L28 high \r\n");
+    }else{
+        uapi_gpio_set_dir(S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L28, HAL_GPIO_LEVEL_LOW); 
+        // wstp_print("Reset Cat1! L28 low\r\n");
+    }
+
+    return 0;
+}
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/utils/cat1_ctl.h b/code/sdk/drivers/peripheral/utils/cat1_ctl.h
new file mode 100644 (file)
index 0000000..ba5313d
--- /dev/null
@@ -0,0 +1,9 @@
+\r
+#ifndef __CAT1_CTL_H\r
+#define __CAT1_CTL_H\r
+\r
+#include "stdint.h"\r
+uint32_t uapi_cat1_power_on(uint32_t pwron);\r
+uint32_t uapi_cat1_reset(uint32_t pwron);\r
+\r
+#endif\r
index 9b451b2..b259abf 100644 (file)
@@ -75,4 +75,173 @@ uint32_t zh_set_sn(uint8_t *buf_sn, uint32_t len_sn)
 #endif
     return nvRet;
 }
+#if 0
 
+#define PM_SLEEP_SOFT_RESET_FORCE_WKUP_REG 0x57000014
+#define PM_SLEEP_SOFT_RESET_FORCE_WKUP_VAL 0xb66
+#define PM_MCU_SEND_IPC_WKUP_BT_REG        0x52000034
+#define PM_MCU_SEND_IPC_WKUP_BT_VAL        0x2
+#define BT_RESET_DELAY  500
+#define POWER_KEY_PARAM_LEN                0x2
+#define CALENDAR_PARAM_LEN                 0x6
+#define DIAG_RES_LEN            4
+#include "non_os_reboot.h"
+#include "diag_service.h"
+diag_ser_header_t g_mcu_diag_header;    // 用于保存diag回复包头内容
+bool g_app_diag_flag = false;           // 用于控制执行功能后是否回复diag消息
+
+uint32_t mcu_os_sys_reset(uint8_t *para, uint32_t para_len)
+{
+    unused(para);
+    unused(para_len);
+    uint8_t res[DIAG_RES_LEN] = {0x80, 0x82, 0x00, 0x00};
+
+    send_spp_diag_msg(g_app_diag_flag, &g_mcu_diag_header, res, DIAG_RES_LEN);
+    reset_deal_with_fs();
+    // when bt at sleep, need wkup bt before soft reset
+    writew(PM_SLEEP_SOFT_RESET_FORCE_WKUP_REG, PM_SLEEP_SOFT_RESET_FORCE_WKUP_VAL);
+    writew(PM_MCU_SEND_IPC_WKUP_BT_REG, PM_MCU_SEND_IPC_WKUP_BT_VAL);
+    uapi_tcxo_delay_ms(BT_RESET_DELAY);
+    set_cpu_utils_reset_cause(REBOOT_CAUSE_APPLICATION_SYSRESETREQ);
+    hal_reboot_chip();
+    return ERRCODE_SUCC;
+}
+#include "power_display_service.h"
+uint8_t mcu_pms_is_screen_on(void)
+{
+    const power_display_svr_api_t *display_api = power_display_svr_get_api();
+    screen_state_t state = display_api->get_screen_state();
+    wstp_print("app get screen state = %u, on is %u, off is %u. \r\n", state, SCREEN_ON, SCREEN_OFF);
+    if( state == SCREEN_ON){
+        return 1;
+    }else{
+        return 0;
+    }
+}
+
+#ifdef CONFIG_LOW_POWER_TEST
+static bool g_dpu_ready_flag = false;
+#else
+static bool g_dpu_ready_flag = true;
+#endif
+#include "soc_errno.h"
+#include "pm_definition.h"
+#include "lcd_bus.h"
+uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len)
+{
+    unused(para);
+    unused(para_len);
+#ifdef SUPPORT_POWER_MANAGER
+    const power_display_svr_api_t *display_api = power_display_svr_get_api();
+    return display_api->turn_off_screen();
+#endif
+    if (!lcd_get_status()) {
+        wstp_print("\r\nLCD has benn off\r\n");
+        return ERRCODE_SUCC;
+    }
+#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL)
+    NotifyScreenOff(); // Instruct the uikit to close the display operation.
+#endif
+    osDelay(100);        // Wait 100ms for the uikit to complete display.
+    touch_screen_suspend(); // close touch
+    ext_errno ret = drv_vau_suspend(NULL);
+    if (ret != 0) {
+        wstp_print("drv vau suspend error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+#ifdef SUPPORT_GPU_JPEG
+    (void)drv_jpeg_suspend(NULL);
+#endif
+#ifndef QSPI_DISPLAY
+    ret = drv_dpu_suspend(NULL);
+    if (ret != 0) {
+        wstp_print("drv dpu suspend error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+#endif
+#ifdef SUPPORT_GPU_GMMU
+    ret = drv_gmmu_suspend(NULL);
+    if (ret != 0) {
+        wstp_print("drv gmmu suspend error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+#endif
+    ret = uapi_lcd_deinit();
+    if (ret != 0) {
+        wstp_print("lcd deinit error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+    pm_lcd_off_handle();
+    lcd_set_status(false);
+    g_dpu_ready_flag = false;
+    display_suspend_power_off();
+    uapi_pm_request_mode(PM_ID_VIDEO, PM_MODE_LP);
+    return ERRCODE_SUCC;
+}
+
+
+
+uint32_t mcu_pm_lcd_on(uint8_t *para, uint32_t para_len)
+{
+    unused(para);
+    unused(para_len);
+#ifdef SUPPORT_POWER_MANAGER
+    const power_display_svr_api_t *display_api = power_display_svr_get_api();
+    return display_api->turn_on_screen();
+#endif
+    uapi_pm_request_mode(PM_ID_VIDEO, PM_MODE_PERFORMACE);
+
+    if (lcd_get_status()) {
+        wstp_print("\r\nLCD has benn on\r\n");
+        return ERRCODE_SUCC;
+    }
+    pm_lcd_on_pre_handle();
+    lcd_bus_api *bus_api = lcd_get_bus_api();
+    ext_errno ret = bus_api->bus_resume();
+    if (ret != 0) {
+        wstp_print("bus resume error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+#ifndef QSPI_DISPLAY
+    if (g_dpu_ready_flag == false) {
+        ret = drv_dpu_resume(NULL);
+        if (ret != 0) {
+            wstp_print("drv dpu resume error ret=%x\r\n", ret);
+            return ERRCODE_FAIL;
+        }
+    }
+#endif
+#ifdef SUPPORT_GPU_JPEG
+    (void)drv_jpeg_resume(NULL);
+#endif
+    ret = drv_vau_resume(NULL);
+    if (ret != 0) {
+        wstp_print("drv vau resume error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+#ifdef SUPPORT_GPU_GMMU
+    ret = drv_gmmu_resume(NULL);
+    if (ret != 0) {
+        wstp_print("drv gmmu resume error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+#endif
+    ret = uapi_lcd_init();
+    if (ret != 0 && ret != EXT_ERR_MIPI_ALREADY_INIT) {
+        wstp_print("LCD init error ret=%x\r\n", ret);
+        return ERRCODE_FAIL;
+    }
+#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL)
+    NotifyScreenOn(); // Instruct the uikit to start the display operation.
+#endif
+    if (g_dpu_ready_flag == false) {
+        touch_screen_resume(); // open touch
+    }
+#ifdef CONFIG_CLDO1PD_SUPPORT
+    pmu_control_cldo1_sleep_bypass(TURN_ON);
+#endif
+    lcd_set_status(true);
+    return ERRCODE_SUCC;
+}
+
+#endif
\ No newline at end of file