Prechádzať zdrojové kódy

add:模块内部的电源控制

alienwalker 3 rokov pred
rodič
commit
c128c025c0
2 zmenil súbory, kde vykonal 36 pridanie a 0 odobranie
  1. 8 0
      luat/include/luat_pm.h
  2. 28 0
      luat/modules/luat_lib_pm.c

+ 8 - 0
luat/include/luat_pm.h

@@ -10,6 +10,13 @@
 #define LUAT_PM_SLEEP_MODE_STANDBY	4	//待机模式,CPU 停止,设备上下文丢失(可保存至特殊外设),唤醒后通常复位
 //#define LUAT_PM_SLEEP_MODE_SHUTDOWN	5	//关断模式,比 Standby 模式功耗更低, 上下文通常不可恢复, 唤醒后复位
 
+enum
+{
+	LUAT_PM_POWER_USB,
+	LUAT_PM_POWER_GPS,
+	LUAT_PM_POWER_GPS_ANT,
+};
+
 int luat_pm_request(int mode);
 
 int luat_pm_release(int mode);
@@ -34,4 +41,5 @@ int luat_pm_dtimer_wakeup_id(int* id);
 
 int luat_pm_poweroff(void);
 
+int luat_pm_power_ctrl(int id, uint8_t onoff);
 #endif

+ 28 - 0
luat/modules/luat_lib_pm.c

@@ -269,6 +269,26 @@ int l_rtos_standby(lua_State *L);
 //     }
 // }
 
+/**
+开启内部的电源控制,注意不是所有的平台都支持,可能部分平台支持部分选项,看硬件
+@api pm.power(id, onoff)
+@int 电源控制id,pm.USB pm.GPS pm.GPS_ANT之类
+@boolean 开关true开,false关,默认关
+@return boolean 处理结果true成功,false失败
+@usage
+pm.power(pm.USB, false) --关闭USB电源
+ */
+static int l_pm_power_ctrl(lua_State *L) {
+	uint8_t onoff = 0;
+    int id = luaL_checkinteger(L, 1);
+    if (lua_isboolean(L, 2)) {
+    	onoff = lua_toboolean(L, 2);
+
+    }
+    lua_pushboolean(L, !luat_pm_power_ctrl(id, onoff));
+    return 1;
+}
+
 #include "rotable2.h"
 static const rotable_Reg_t reg_pm[] =
 {
@@ -285,6 +305,7 @@ static const rotable_Reg_t reg_pm[] =
     { "lastReson",      ROREG_FUNC(l_pm_last_reson)},
     { "shutdown",       ROREG_FUNC(l_pm_power_off)},
     { "reboot",         ROREG_FUNC(l_rtos_reboot)},
+	{ "power",         ROREG_FUNC(l_pm_power_ctrl)},
     //@const NONE number 不休眠模式
     { "NONE",           ROREG_INT(LUAT_PM_SLEEP_MODE_NONE)},
     //@const IDLE number IDLE模式
@@ -295,6 +316,13 @@ static const rotable_Reg_t reg_pm[] =
     { "DEEP",           ROREG_INT(LUAT_PM_SLEEP_MODE_DEEP)},
     //@const HIB number HIB模式
     { "HIB",            ROREG_INT(LUAT_PM_SLEEP_MODE_STANDBY)},
+    //@const USB number USB电源
+    { "USB",            ROREG_INT(LUAT_PM_POWER_USB)},
+    //@const GPS number GPS电源
+    { "GPS",            ROREG_INT(LUAT_PM_POWER_GPS)},
+    //@const GPS_ANT number GPS的天线电源,有源天线才需要
+    { "GPS_ANT",        ROREG_INT(LUAT_PM_POWER_GPS_ANT)},
+
 	{ NULL,             ROREG_INT(0) }
 };