Dozingfiretruck 4 лет назад
Родитель
Сommit
3aba813747
3 измененных файлов с 16 добавлено и 16 удалено
  1. 2 2
      luat/include/luat_pwm.h
  2. 11 10
      luat/modules/luat_lib_pwm.c
  3. 3 4
      luat/rtt/luat_pwm_rtt.c

+ 2 - 2
luat/include/luat_pwm.h

@@ -4,8 +4,8 @@
 
 #include "luat_base.h"
 
-int luat_pwm_open(int channel, size_t period, size_t pulse);
-int luat_pwm_capture(int channel,int freq,int*pwmH,int*pwmL);
+int luat_pwm_open(int channel, size_t period, size_t pulse,int pnum);
+int luat_pwm_capture(int channel,int freq);
 int luat_pwm_close(int channel);
 
 #endif

+ 11 - 10
luat/modules/luat_lib_pwm.c

@@ -13,21 +13,22 @@
 @int PWM通道
 @int 频率, 1-1000000hz
 @int 占空比 0-100
+@int 输出周期 0为持续输出
 @return boolean 处理结果,成功返回true,失败返回false
 @usage
 -- 打开PWM5, 频率1kHz, 占空比50%
 pwm.open(5, 1000, 50)
  */
 static int l_pwm_open(lua_State *L) {
+    int pnum = 0;
     int channel = luaL_checkinteger(L, 1);
     size_t period = luaL_checkinteger(L, 2);
     size_t pulse = luaL_checkinteger(L, 3);
-    if (luat_pwm_open(channel, period, pulse) == 0) {
-        lua_pushboolean(L, 1);
-    }
-    else {
-        lua_pushboolean(L, 0);
+    if (lua_type(L, 4) == LUA_TNUMBER){
+        pnum = luaL_checkinteger(L, 4);
     }
+    int ret = luat_pwm_open(channel, period, pulse,pnum);
+    lua_pushboolean(L, ret == 0 ? 1 : 0);
     return 1;
 }
 
@@ -50,15 +51,15 @@ PWM捕获
 @api pwm.capture(channel)
 @int PWM通道
 @int 捕获频率
-@return int 成功返回占空比,失败返回-1
+@return boolean 处理结果,成功返回true,失败返回false
 @usage
 -- PWM0捕获
-log.info("pwm.get(0)",pwm.capture(0))
+log.info("pwm.get(0)",pwm.capture(0,1000))
+log.info("PWM_CAPTURE",sys.waitUntil("PWM_CAPTURE", 2000))
  */
 static int l_pwm_capture(lua_State *L) {
-    int pwmH,pwmL;
-    int pulse = luat_pwm_capture(luaL_checkinteger(L, 1),luaL_checkinteger(L, 2),&pwmH,&pwmL);
-    lua_pushnumber(L,pulse);
+    int ret = luat_pwm_capture(luaL_checkinteger(L, 1),luaL_checkinteger(L, 2));
+    lua_pushboolean(L, ret == 0 ? 1 : 0);
     return 1;
 }
 

+ 3 - 4
luat/rtt/luat_pwm_rtt.c

@@ -62,7 +62,7 @@ INIT_COMPONENT_EXPORT(luat_pwm_rtt_init);
 //  - I: 十位
 //  - N: 个位
 // @return -1 打开失败。 0 打开成功
-int luat_pwm_open(int channel, size_t period, size_t pulse) {
+int luat_pwm_open(int channel, size_t period, size_t pulse,int pnum) {
     int i = channel / 10;
     int n = channel - (i * 10);
     if (i < 0 || i >= DEVICE_ID_MAX )
@@ -86,9 +86,8 @@ int luat_pwm_open(int channel, size_t period, size_t pulse) {
     return 0;
 }
 
-int luat_pwm_capture(int channel,int freq,int*pwmH,int*pwmL) {
-    int pulse = -1;
-    return pulse;
+int luat_pwm_capture(int channel,int freq) {
+    return -1;
 }