Skip to content

Commit

Permalink
Merge branch 'master' of https://gitee.com/openLuat/LuatOS
Browse files Browse the repository at this point in the history
  • Loading branch information
allewalker committed Sep 5, 2024
2 parents 579bf7c + c11f8bf commit b807cfd
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 115 deletions.
3 changes: 2 additions & 1 deletion components/network/adapter_lwip2/net_lwip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include "net_lwip2.h"

#include "luat_crypto.h"

#include "luat_msgbus.h"
#include "luat_malloc.h"
#define LUAT_LOG_TAG "net"
#include "luat_log.h"

Expand Down
2 changes: 1 addition & 1 deletion demo/adc/testAdc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function adc_pin() -- 根据不同开发板,设置ADC编号
-- 设置分压要在adc.open之前设置,否则无效!!
-- adc.setRange(adc.ADC_RANGE_3_8)
return 0,1,255,255,adc.CH_CPU ,adc.CH_VBAT
elseif rtos_bsp == "EC718P" then --Air780EP开发板ADC编号
elseif string.find(rtos_bsp,"EC718") then --Air780EP开发板ADC编号
-- 默认不开启分压,范围是0-1.6v精度高
-- 开启分压后,外部输入最大不可超过3.3V
-- 设置分压要在adc.open之前设置,否则无效!!
Expand Down
2 changes: 1 addition & 1 deletion demo/aliyun/testPm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sys.taskInit(function()
-- mobile.rtime(2) -- RRC快速释放减少connect时间能大幅降低功耗,但是会带来可能得离线风险,可选择延迟时间或者不用
pm.power(pm.USB, false)
pm.force(pm.LIGHT)
elseif bsp == "EC718P" or bsp == "EC718PV" then
elseif string.find(bsp,"EC718") then
log.info("aliyun.pm", "EC718P/EC718PV方案进入低功耗模式")
-- mobile.rtime(2) -- RRC快速释放减少connect时间能大幅降低功耗,但是会带来可能得离线风险,可选择延迟时间或者不用
pm.power(pm.USB, false)
Expand Down
2 changes: 1 addition & 1 deletion demo/camera/spi_cam/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local RAW_MODE = 0 -- 写1演示获取原始图像
-- spi_id,pin_reset,pin_dc,pin_cs,bl
local function lcd_pin()
local rtos_bsp = rtos.bsp()
if rtos_bsp == "EC718P" then
if string.find(rtos_bsp,"EC718") then
return lcd.HWID_0, 36, 0xff, 0xff, 0xff -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/eink/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function eink_pin()
return 2,16,15,14,13
elseif rtos_bsp == "EC618" then
return 0,1,10,8,22
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return 0,10,14,8,15
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/fatfs/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local function fatfs_spi_pin()
return 2, 14
elseif rtos_bsp == "EC618" then
return 0, 8
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return 0, 8
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/gpio/gpio/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function pinx() -- 根据不同开发板,给LED赋值不同的gpio引脚编号
return 10, 11, 255 -- 开发板上就2个灯
elseif rtos_bsp == "EC618" then -- Air780E开发板引脚
return 27, 255, 255 -- AIR780E开发板上就一个灯
elseif rtos_bsp == "EC718P" then -- Air780E开发板引脚
elseif string.find(rtos_bsp,"EC718") then -- Air780E开发板引脚
return 27, 255, 255 -- AIR780EP开发板上就一个灯
elseif rtos_bsp == "UIS8850BM" then -- Air780UM开发板引脚
return 36, 255, 255 -- Air780UM开发板上就一个灯
Expand Down
2 changes: 1 addition & 1 deletion demo/gpio/powerkey/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local rtos_bsp = rtos.bsp()
local function pinx()
if rtos_bsp == "EC618" then -- AIR780E -- 35是虚拟GPIO,见https://wiki.luatos.com/chips/air780e/iomux.html#id1
return 35
elseif rtos_bsp == "EC718P" then -- AIR780EP -- 46是虚拟GPIO
elseif string.find(rtos_bsp,"EC718") then -- AIR780EP -- 46是虚拟GPIO
return 46
else
return 255
Expand Down
2 changes: 1 addition & 1 deletion demo/gpio/usbconnect/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local rtos_bsp = rtos.bsp()
local function pinx()
if rtos_bsp == "EC618" then -- AIR780E -- 33是虚拟GPIO,见https://wiki.luatos.com/chips/air780e/iomux.html#id1
return 24, 33
elseif rtos_bsp == "EC718P" then -- AIR780EP -- 40是虚拟GPIO
elseif string.find(rtos_bsp,"EC718") then -- AIR780EP -- 40是虚拟GPIO
return 27, 40
else
return 255, 255
Expand Down
2 changes: 1 addition & 1 deletion demo/gtfont/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function lcd_pin()
return 2,16,15,14,13
elseif rtos_bsp == "EC618" then
return 0,1,10,8,22
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return lcd.HWID_0,36,0xff,0xff,0xff -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
else
log.info("main", "bsp not support")
Expand Down
156 changes: 78 additions & 78 deletions demo/io_queue/main.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "ioqueue"
VERSION = "1.0.0"
-- 仅支持ioqueue的平台能使用!!
-- sys库是标配

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "ioqueue"
VERSION = "1.0.0"
-- 仅支持ioqueue的平台能使用!!
-- sys库是标配
_G.sys = require("sys")


local rtos_bsp = rtos.bsp()
function pinx() -- 根据不同开发板,给LED赋值不同的gpio引脚编号
if rtos_bsp == "AIR105" then
mcu.setXTAL(true) --为了测试更准确,调整到外部时钟
return 1, pin.PD06, pin.PD07
elseif rtos_bsp == "EC718P" then -- Air780E开发板引脚
elseif string.find(rtos_bsp,"EC718") then -- Air780E开发板引脚
gpio.setup(12,nil,nil)
gpio.setup(13,nil,nil)
return 1, 12,13
Expand All @@ -20,72 +20,72 @@ function pinx() -- 根据不同开发板,给LED赋值不同的gpio引脚编号
return 255,255
end
end

sys.taskInit(function()

local _,tick_us = mcu.tick64()
local hw_timer_id, capture_pin,out_pin = pinx()
local buff1 = zbuff.create(100)
local buff2 = zbuff.create(100)

sys.taskInit(function()

local _,tick_us = mcu.tick64()
local hw_timer_id, capture_pin,out_pin = pinx()
local buff1 = zbuff.create(100)
local buff2 = zbuff.create(100)
local cnt1,cnt2,i,lastTick,bit1Tick,nowTick,j,bit
mcu.hardfault(0)
sys.wait(2000)
bit1Tick = 100 * tick_us
mcu.hardfault(0)
sys.wait(2000)
bit1Tick = 100 * tick_us
while 1 do
log.info('start dht11')
--测试单总线DHT11
ioqueue.stop(hw_timer_id) --确保硬件定时器1是空闲的
ioqueue.init(hw_timer_id,100,1) --io队列设置100个命令,重复1次,实际上用不到那么多命令
ioqueue.setgpio(hw_timer_id, capture_pin, true, gpio.PULLUP) --数据线拉高,上拉输入
ioqueue.setdelay(hw_timer_id, 10000, 0, false) --单次延迟10ms
ioqueue.setgpio(hw_timer_id, capture_pin, false, 0, 0) --数据线拉低
ioqueue.setdelay(hw_timer_id, 18000, 0, false) --单次延迟18ms
ioqueue.set_cap(hw_timer_id, capture_pin, gpio.PULLUP, gpio.FALLING, 100000 * tick_us) --设置成下降沿中断捕获,最大计时100000us, 上拉输入,这里已经代替了输出20~40us高电平
for i = 1,42,1 do
ioqueue.capture(hw_timer_id) --捕获42次外部中断发生时的tick值,2个start信号+40bit数据
end
ioqueue.cap_done(hw_timer_id, capture_pin) --停止捕获
ioqueue.setgpio(hw_timer_id, capture_pin, true, gpio.PULLUP) --数据线拉高,上拉输入
ioqueue.start(hw_timer_id)
sys.waitUntil("IO_QUEUE_DONE_"..hw_timer_id)
ioqueue.stop(hw_timer_id)
--开始解析捕获的数据
cnt1,cnt2 = ioqueue.get(hw_timer_id, buff1, buff2)
if cnt2 ~= 42 then
log.info('test fail')
goto TEST_OUT
end
lastTick = buff2:query(6 + 2, 4, false) --以第二次中断的tick作为起始tick,第一次的tick没有用
j = 0
bit = 8
buff1[0] = 0
log.info('start dht11')
--测试单总线DHT11
ioqueue.stop(hw_timer_id) --确保硬件定时器1是空闲的
ioqueue.init(hw_timer_id,100,1) --io队列设置100个命令,重复1次,实际上用不到那么多命令
ioqueue.setgpio(hw_timer_id, capture_pin, true, gpio.PULLUP) --数据线拉高,上拉输入
ioqueue.setdelay(hw_timer_id, 10000, 0, false) --单次延迟10ms
ioqueue.setgpio(hw_timer_id, capture_pin, false, 0, 0) --数据线拉低
ioqueue.setdelay(hw_timer_id, 18000, 0, false) --单次延迟18ms
ioqueue.set_cap(hw_timer_id, capture_pin, gpio.PULLUP, gpio.FALLING, 100000 * tick_us) --设置成下降沿中断捕获,最大计时100000us, 上拉输入,这里已经代替了输出20~40us高电平
for i = 1,42,1 do
ioqueue.capture(hw_timer_id) --捕获42次外部中断发生时的tick值,2个start信号+40bit数据
end
ioqueue.cap_done(hw_timer_id, capture_pin) --停止捕获
ioqueue.setgpio(hw_timer_id, capture_pin, true, gpio.PULLUP) --数据线拉高,上拉输入
ioqueue.start(hw_timer_id)
sys.waitUntil("IO_QUEUE_DONE_"..hw_timer_id)
ioqueue.stop(hw_timer_id)
--开始解析捕获的数据
cnt1,cnt2 = ioqueue.get(hw_timer_id, buff1, buff2)
if cnt2 ~= 42 then
log.info('test fail')
goto TEST_OUT
end
lastTick = buff2:query(6 + 2, 4, false) --以第二次中断的tick作为起始tick,第一次的tick没有用
j = 0
bit = 8
buff1[0] = 0
for i = 2,41,1 do

--检查一下是不是对应pin的下降沿中断,不过也不太需要
if buff2[i * 6 + 0] ~= capture_pin or buff2[i * 6 + 1] ~= 0 then
log.error("capture", i, buff2[i * 6 + 0], buff2[i * 6 + 1])
end
--通过计算tick差值来确定是bit1还是bit0
nowTick = buff2:query(i * 6 + 2, 4, false)
buff1[j] = buff1[j] << 1
if (nowTick - lastTick) > bit1Tick then
buff1[j] = buff1[j] + 1
end
bit = bit - 1
if bit == 0 then
j = j + 1
bit = 8
end
lastTick = nowTick
end
buff1[5] = buff1[0] + buff1[1] + buff1[2] + buff1[3]
if buff1[4] ~= buff1[5] then
log.info('check fail', buff1[4], buff1[5])
else
log.info("湿度", buff1[0] .. '.' .. buff1[1], "温度", buff1[2] .. '.' .. buff1[3])
end
::TEST_OUT::
ioqueue.release(hw_timer_id)

--检查一下是不是对应pin的下降沿中断,不过也不太需要
if buff2[i * 6 + 0] ~= capture_pin or buff2[i * 6 + 1] ~= 0 then
log.error("capture", i, buff2[i * 6 + 0], buff2[i * 6 + 1])
end
--通过计算tick差值来确定是bit1还是bit0
nowTick = buff2:query(i * 6 + 2, 4, false)
buff1[j] = buff1[j] << 1
if (nowTick - lastTick) > bit1Tick then
buff1[j] = buff1[j] + 1
end
bit = bit - 1
if bit == 0 then
j = j + 1
bit = 8
end
lastTick = nowTick
end
buff1[5] = buff1[0] + buff1[1] + buff1[2] + buff1[3]
if buff1[4] ~= buff1[5] then
log.info('check fail', buff1[4], buff1[5])
else
log.info("湿度", buff1[0] .. '.' .. buff1[1], "温度", buff1[2] .. '.' .. buff1[3])
end
::TEST_OUT::
ioqueue.release(hw_timer_id)

log.info('output 1 start')
--测试高精度固定间隔定时输出,1us间隔翻转电平
Expand Down Expand Up @@ -132,10 +132,10 @@ sys.taskInit(function()




end
end)
-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!

end
end)
-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!
7 changes: 4 additions & 3 deletions demo/iotcloud/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "mqttdemo"
PROJECT = "iotclouddemo"
VERSION = "1.0.0"

-- sys库是标配
Expand Down Expand Up @@ -69,9 +69,9 @@ sys.taskInit(function()
-- iotcloudc = iotcloud.new(iotcloud.TENCENT,{produt_id = "xxx" ,product_secret = "xxx"})

-- 密钥校验
-- iotcloudc = iotcloud.new(iotcloud.TENCENT,{produt_id = "xxx",device_name = "123456789",key = "xxx=="})
-- iotcloudc = iotcloud.new(iotcloud.TENCENT,{produt_id = "xxx",device_name = "xxx",key = "xxx=="})
-- 证书校验
-- iotcloudc = iotcloud.new(iotcloud.TENCENT,{produt_id = "xxx",device_name = "123456789"},{tls={client_cert=io.readFile("/luadb/client_cert.crt")}})
-- iotcloudc = iotcloud.new(iotcloud.TENCENT,{produt_id = "xxx",device_name = "xxx"},{tls={client_cert=io.readFile("/luadb/client_cert.crt")}})


-- 阿里云
Expand Down Expand Up @@ -109,6 +109,7 @@ end)

sys.subscribe("iotcloud", function(cloudc,event,data,payload)
if event == iotcloud.CONNECT then -- 云平台联上了
print("iotcloud","CONNECT", "云平台连接成功")
-- iotcloud:subscribe("test") -- 定阅主题
elseif event == iotcloud.RECEIVE then
print("iotcloud","topic", data, "payload", payload)
Expand Down
2 changes: 1 addition & 1 deletion demo/ipv6/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
-- 演示task
function ipv6test()
-- 仅EC618系列支持, 例如Air780E/Air600E/Air780UG/Air700E
if rtos.bsp() ~= "EC618" and rtos.bsp() ~= "EC718P" then
if rtos.bsp() ~= "EC618" and not string.find(rtos.bsp(),"EC718") then
while 1 do
log.info("ipv6", "only Air780E/Air600E/Air780UG/Air700E/Air780EP supported")
sys.wait(1000)
Expand Down
2 changes: 1 addition & 1 deletion demo/ipv6/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ HTTP_200_EMTRY = "HTTP/1.0 200 OK\r\nServer: LuatOS\r\nConnection: close\r\nCont
-- 演示task
function ipv6test()
-- 仅EC618系列支持, 例如Air780E/Air600E/Air780UG/Air700E
if rtos.bsp() ~= "EC618" and rtos.bsp() ~= "EC718P" then
if rtos.bsp() ~= "EC618" and not string.find(rtos.bsp(),"EC718") then
while 1 do
log.info("ipv6", "only Air780E/Air600E/Air780UG/Air700E/Air780EP supported")
sys.wait(1000)
Expand Down
2 changes: 1 addition & 1 deletion demo/lcd/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function lcd_pin()
return 2,16,15,14,13
elseif rtos_bsp == "EC618" then
return 0,1,10,8,22
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return lcd.HWID_0,36,0xff,0xff,25 -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/lcd_custom/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local function lcd_pin()
return 2,16,15,14,13
elseif rtos_bsp == "EC618" then
return 0,1,10,8,22
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return lcd.HWID_0,36,0xff,0xff,0xff -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/little_flash/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function little_flash_spi_pin()
return 2,14
elseif rtos_bsp == "EC618" then
return 0,8
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return 0,8
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/lora/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local function lora_pin()
return 2,14,15,13,12
elseif rtos_bsp == "EC618" then
return 0,8,1,18,19
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return 0,8,1,31,32
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/lora2/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local function lora_pin()
return 2,14,15,13,12
elseif rtos_bsp == "EC618" then
return 0,8,1,18,19
elseif rtos_bsp == "EC718P" then
elseif string.find(rtos_bsp,"EC718") then
return 0,8,1,31,32
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/lvgl/Air780EP/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local rtos_bsp = rtos.bsp()
-- 根据不同的BSP返回不同的值
-- spi_id,pin_reset,pin_dc,pin_cs,bl
function lcd_pin()
if rtos_bsp == "EC718P" then
if string.find(rtos_bsp,"EC718") then
return lcd.HWID_0, 36, 0xff, 0xff, 25 -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
else
log.info("main", "bsp not support")
Expand Down
2 changes: 1 addition & 1 deletion demo/mqtt/multilink_mqtt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sys.taskInit(function()
-------- MQTT 演示代码 --------------
-------------------------------------

mqttc1 = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl, ca_file)
mqttc1 = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl)

mqttc1:auth(client1_id,user_name,password) -- client_id必填,其余选填
-- mqttc1:keepalive(240) -- 默认值240s
Expand Down
2 changes: 1 addition & 1 deletion demo/mqtt/single_mqtt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sys.taskInit(function()
-------- MQTT 演示代码 --------------
-------------------------------------

mqttc = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl, ca_file)
mqttc = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl)

mqttc:auth(client_id,user_name,password) -- client_id必填,其余选填
-- mqttc:keepalive(240) -- 默认值240s
Expand Down
2 changes: 1 addition & 1 deletion demo/mqtt/ssl_mqtt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sys.taskInit(function()
-------------------------------------
-------- MQTT 演示代码 --------------
-------------------------------------
mqttc = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl, ca_file)
mqttc = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl)

mqttc:auth(client_id,user_name,password) -- client_id必填,其余选填
-- mqttc:keepalive(240) -- 默认值240s
Expand Down
Loading

0 comments on commit b807cfd

Please sign in to comment.