Просмотр исходного кода

fix: pwm.open获取的参数有误
add: luat_base.h添加adc和pwm的库引用
update: i2c的rtt实现查询设备时不需要char[]

Wendal Chen 5 лет назад
Родитель
Сommit
71ba9abd19
4 измененных файлов с 58 добавлено и 3 удалено
  1. 2 0
      luat/include/luat_base.h
  2. 2 2
      luat/modules/luat_lib_pwm.c
  3. 1 1
      luat/rtt/luat_i2c_rtt.c
  4. 53 0
      luat/rtt/luat_pwm_rtt.c

+ 2 - 0
luat/include/luat_base.h

@@ -23,6 +23,8 @@ LUAMOD_API int luaopen_rtos( lua_State *L );
 LUAMOD_API int luaopen_timer( lua_State *L );
 LUAMOD_API int luaopen_msgbus( lua_State *L );
 LUAMOD_API int luaopen_gpio( lua_State *L );
+LUAMOD_API int luaopen_adc( lua_State *L );
+LUAMOD_API int luaopen_pwm( lua_State *L );
 LUAMOD_API int luaopen_uart( lua_State *L );
 LUAMOD_API int luaopen_pm( lua_State *L );
 LUAMOD_API int luaopen_fs( lua_State *L );

+ 2 - 2
luat/modules/luat_lib_pwm.c

@@ -4,8 +4,8 @@
 
 static int l_pwm_open(lua_State *L) {
     int channel = luaL_checkinteger(L, 1);
-    size_t period = luaL_checkinteger(L, 1);
-    size_t pulse = 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);
     }

+ 1 - 1
luat/rtt/luat_i2c_rtt.c

@@ -18,7 +18,7 @@
 static struct rt_i2c_bus_device* i2c_devs[I2C_DEVICE_ID_MAX + 1];
 
 static int luat_i2c_rtt_init() {
-    char name[16];
+    char name[8];
     name[0] = 'i';
     name[1] = '2';
     name[2] = 'c';

+ 53 - 0
luat/rtt/luat_pwm_rtt.c

@@ -0,0 +1,53 @@
+
+#include "luat_base.h"
+#include "luat_pwm.h"
+
+#include "luat_log.h"
+
+#include "rtthread.h"
+#include "rthw.h"
+#include "rtdevice.h"
+
+#define DBG_TAG           "luat.pwm"
+#define DBG_LVL           DBG_WARN
+#include <rtdbg.h>
+
+#ifdef RT_USING_PWM
+
+#define DEVICE_ID_MAX 6
+static struct pwm_devs *pwm_devs[DEVICE_ID_MAX];
+
+static int luat_pwm_rtt_init() {
+    char name[8];
+    name[0] = 'p';
+    name[1] = 'w';
+    name[2] = 'm';
+    name[4] = 0x00;
+    
+    // 搜索pwm0,pwm1,pwm2 ....
+    for (size_t i = 0; i <= DEVICE_ID_MAX; i++)
+    {
+        name[3] = '0' + i;
+        pwm_devs[i] = (struct rt_device_pwm *)rt_device_find(name);
+        LOG_D("search pwm name=%s ptr=0x%08X", name, pwm_devs[i]);
+    }
+    // 看看有没有pwm
+    if (pwm_devs[0] == RT_NULL) {
+        pwm_devs[0] = (struct rt_device_pwm *)rt_device_find("pwm");
+        LOG_D("search pwm name=%s ptr=0x%08X", "pwm", pwm_devs[0]);
+    }
+}
+
+INIT_COMPONENT_EXPORT(luat_pwm_rtt_init);
+
+int luat_pwm_open(int channel, size_t period, size_t pulse) {
+    if (channel < 0 || channel >= DEVICE_ID_MAX )
+        return -1;
+    return -1;
+}
+
+int luat_pwm_close(int channel) {
+    return -1;
+}
+
+#endif