Răsfoiți Sursa

fix:780E的部分GPIO复用不支持 https://gitee.com/openLuat/LuatOS/issues/I7HOHZ
add:修改mobile的band功能 https://gitee.com/openLuat/LuatOS/issues/I7GXZJ

alienwalker 2 ani în urmă
părinte
comite
8b94279a7b
3 a modificat fișierele cu 102 adăugiri și 0 ștergeri
  1. 55 0
      components/mobile/luat_lib_mobile.c
  2. 25 0
      demo/mobile/main.lua
  3. 22 0
      luat/modules/luat_lib_gpio.c

+ 55 - 0
components/mobile/luat_lib_mobile.c

@@ -767,6 +767,59 @@ static int l_mobile_config(lua_State* L) {
 
 #include "luat_uart.h"
 #include "luat_zbuff.h"
+
+/**
+获取当前使用/支持的band
+@api mobile.getBand(band, is_default)
+@zbuff 输出band
+@boolean true默认支持,false当前支持的,默认是false,当前是预留功能,不要写true
+@return boolean 成功返回true,失败放回false
+@usage
+local buff = zbuff.create(40)
+mobile.getBand(buff) --输出当前使用的band,band号放在buff内,buff[0],buff[1],buff[2] .. buff[buff:used() - 1]
+ */
+static int l_mobile_get_band(lua_State* L) {
+    luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE));
+    uint8_t total_num;
+    int re;
+    if (buff->len < 40)
+    {
+    	__zbuff_resize(buff, 40);
+    }
+    if (lua_isboolean(L, 2) && lua_toboolean(L, 2))
+    {
+    	re = luat_mobile_get_support_band(buff->addr,  &total_num);
+    }
+    else
+    {
+    	re = luat_mobile_get_band(buff->addr,  &total_num);
+    }
+    buff->used = total_num;
+    lua_pushboolean(L, !re);
+    return 1;
+}
+
+/**
+设置使用的band
+@api mobile.setBand(band, num)
+@zbuff 输入使用的band
+@int band数量
+@return boolean 成功返回true,失败放回false
+@usage
+local buff = zbuff.create(40)
+buff[0] = 3
+buff[1] = 5
+buff[2] = 8
+buff[3] = 40
+mobile.setBand(buff, 4) --设置使用的band一共4个,为3,5,8,40
+ */
+static int l_mobile_set_band(lua_State* L) {
+	luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE));
+	int num = luaL_optinteger(L, 2, 1);
+	lua_pushboolean(L, !luat_mobile_set_band(buff->addr,  num));
+	return 1;
+}
+
 /**
 RF测试开关和配置
 @api mobile.nstOnOff(onoff, uart_id)
@@ -835,6 +888,8 @@ static const rotable_Reg_t reg_mobile[] = {
 	{"reset",           ROREG_FUNC(l_mobile_reset)},
 	{"dataTraffic",     ROREG_FUNC(l_mobile_data_traffic)},
 	{"config",          ROREG_FUNC(l_mobile_config)},
+	{"getBand",          ROREG_FUNC(l_mobile_get_band)},
+	{"setBand",          ROREG_FUNC(l_mobile_set_band)},
 	{"nstOnOff",          ROREG_FUNC(l_mobile_nst_test_onoff)},
 	{"nstInput",          ROREG_FUNC(l_mobile_nst_data_input)},
 	//@const UNREGISTER number 未注册

+ 25 - 0
demo/mobile/main.lua

@@ -23,6 +23,31 @@ mobile.simid(2,true)--优先用SIM0
 
 
 sys.taskInit(function()
+    local band = zbuff.create(40)
+    local band1 = zbuff.create(40)
+    mobile.getBand(band)
+    log.info("当前使用的band:")
+    for i=0,band:used()-1 do
+        log.info("band", band[i])
+    end
+    band1[0] = 38
+    band1[1] = 39
+    band1[2] = 40
+    mobile.setBand(band1, 3)    --改成使用38,39,40
+    band1:clear()
+    mobile.getBand(band1)
+    log.info("修改后使用的band:")
+    for i=0,band1:used()-1 do
+        log.info("band", band1[i])
+    end
+    mobile.setBand(band, band:used())    --改回原先使用的band,也可以下载的时候选择清除fs
+
+    mobile.getBand(band1)
+    log.info("修改回默认使用的band:")
+    for i=0,band1:used()-1 do
+        log.info("band", band1[i])
+    end
+
     -- mobile.apn(0,2,"") -- 使用默认APN激活CID2
     mobile.rtime(2) -- 在无数据交互时,RRC2秒后自动释放
     -- 下面是配置自动搜索小区间隔,和轮询搜索冲突,开启1个就可以了

+ 22 - 0
luat/modules/luat_lib_gpio.c

@@ -164,6 +164,7 @@ int l_gpio_handler(lua_State *L, void* ptr) {
 @any mode 输入输出模式:<br>数字0/1代表输出模式<br>nil代表输入模式<br>function代表中断模式
 @int pull 上拉下列模式, 可以是gpio.PULLUP 或 gpio.PULLDOWN, 需要根据实际硬件选用
 @int irq 中断触发模式,默认gpio.BOTH。中断触发模式<br>上升沿gpio.RISING<br>下降沿gpio.FALLING<br>上升和下降都触发gpio.BOTH 
+@int alt 复用选项,目前只有EC618平台需要这个参数,有些GPIO可以复用到不同引脚上,可以选择复用选项(0或者4)从而复用到对应的引脚上
 @return any 输出模式返回设置电平的闭包, 输入模式和中断模式返回获取电平的闭包
 @usage
 -- 设置gpio17为输入
@@ -174,9 +175,14 @@ gpio.setup(17, 0)
 gpio.setup(17, 1, gpio.PULLUP)
 -- 设置gpio27为中断
 gpio.setup(27, function(val) print("IRQ_27",val) end, gpio.PULLUP)
+-- 设置gpio27为中断
+gpio.setup(27, function(val) print("IRQ_27",val) end, gpio.PULLUP)
+-- 设置AIR780E的PIN33复用成gpio18,方向输出,且初始化电平为低,使用硬件默认上下拉配置
+gpio.setup(18, 0, nil, nil, 4)
 */
 static int l_gpio_setup(lua_State *L) {
     luat_gpio_t conf;
+    luat_gpio_cfg_t cfg = {0};
     conf.pin = luaL_checkinteger(L, 1);
     //conf->mode = luaL_checkinteger(L, 2);
     conf.lua_ref = 0;
@@ -196,7 +202,23 @@ static int l_gpio_setup(lua_State *L) {
     }
     conf.pull = luaL_optinteger(L, 3, default_gpio_pull);
     conf.irq_cb = 0;
+#ifdef CHIP_EC618
+    int re;
+    if (lua_isinteger(L, 5)) {
+    	cfg.alt_fun = luaL_optinteger(L, 5, 0);
+    	cfg.pin = conf.pin;
+    	cfg.pull = conf.pull;
+    	cfg.mode = conf.mode;
+    	cfg.irq_type = conf.irq;
+    	cfg.output_level = conf.irq;
+    	re = luat_gpio_open(&cfg);
+    }
+    else {
+    	re = luat_gpio_setup(&conf);
+    }
+#else
     int re = luat_gpio_setup(&conf);
+#endif
     if (re != 0) {
         LLOGW("gpio setup fail pin=%d", conf.pin);
         return 0;