doudou 1 рік тому
батько
коміт
7b6498f2d9

+ 66 - 60
demo/camera/spi_cam/main.lua

@@ -1,18 +1,16 @@
-
-
 PROJECT = "camerademo"
-VERSION = "1.0.0"
---实际使用时选1个就行
+VERSION = "1.0.0"
+-- 实际使用时选1个就行
 require "bf30a2"
-require "gc032a"
+require "gc032a"
 require "gc0310"
 sys = require("sys")
 log.style(1)
 
-local SCAN_MODE = 0 --写1演示扫码
+local SCAN_MODE = 0 -- 写1演示扫码
 local scan_pause = true
 local getRawStart = false
-local RAW_MODE = 0 --写1演示获取原始图像
+local RAW_MODE = 0 -- 写1演示获取原始图像
 -- SCAN_MODE和RAW_MODE都没有写1就是拍照
 
 -- 根据不同的BSP返回不同的值
@@ -20,15 +18,15 @@ local RAW_MODE = 0 --写1演示获取原始图像
 local function lcd_pin()
     local rtos_bsp = rtos.bsp()
     if rtos_bsp == "EC718P" then
-        return lcd.HWID_0,36,0xff,0xff,0xff -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
+        return lcd.HWID_0, 36, 0xff, 0xff, 0xff -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
     else
         log.info("main", "bsp not support")
         return
     end
 end
-local spi_id,pin_reset,pin_dc,pin_cs,bl = lcd_pin() 
+local spi_id, pin_reset, pin_dc, pin_cs, bl = lcd_pin()
 if spi_id ~= lcd.HWID_0 then
-    spi_lcd = spi.deviceSetup(spi_id,pin_cs,0,0,8,20*1000*1000,spi.MSB,1,0)
+    spi_lcd = spi.deviceSetup(spi_id, pin_cs, 0, 0, 8, 20 * 1000 * 1000, spi.MSB, 1, 0)
     port = "device"
 else
     port = spi_id
@@ -38,23 +36,32 @@ end
 -- lcd.init("st7735",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 128,h = 160,xoffset = 0,yoffset = 0},spi_lcd)
 
 --[[ 此为合宙售卖的1.54寸TFT LCD LCD 分辨率:240X240 屏幕ic:st7789 购买地址:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-24045920841.20.391445d5Ql4uJl&id=659456700222]]
---lcd.init("st7789",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 240,h = 320,xoffset = 0,yoffset = 0},spi_lcd,true)
+-- lcd.init("st7789",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 240,h = 320,xoffset = 0,yoffset = 0},spi_lcd,true)
 
 --[[ 此为合宙售卖的0.96寸TFT LCD LCD 分辨率:160X80 屏幕ic:st7735s 购买地址:https://item.taobao.com/item.htm?id=661054472686]]
---lcd.init("st7735v",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 1,w = 160,h = 80,xoffset = 0,yoffset = 24},spi_lcd)
---如果显示颜色相反,请解开下面一行的注释,关闭反色
---lcd.invoff()
---如果显示依旧不正常,可以尝试老版本的板子的驱动
+-- lcd.init("st7735v",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 1,w = 160,h = 80,xoffset = 0,yoffset = 24},spi_lcd)
+-- 如果显示颜色相反,请解开下面一行的注释,关闭反色
+-- lcd.invoff()
+-- 如果显示依旧不正常,可以尝试老版本的板子的驱动
 -- lcd.init("st7735s",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 2,w = 160,h = 80,xoffset = 0,yoffset = 0},spi_lcd)
-lcd.init("gc9306x",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 240,h = 320,xoffset = 0,yoffset = 0},spi_lcd,true)
+lcd.init("gc9306x", {
+    port = port,
+    pin_dc = pin_dc,
+    pin_pwr = bl,
+    pin_rst = pin_reset,
+    direction = 0,
+    w = 240,
+    h = 320,
+    xoffset = 0,
+    yoffset = 0
+}, spi_lcd, true)
 
 local uartid = uart.VUART_0 -- 根据实际设备选取不同的uartid
---初始化
-local result = uart.setup(
-    uartid,--串口id
-    115200,--波特率
-    8,--数据位
-    1--停止位
+-- 初始化
+local result = uart.setup(uartid, -- 串口id
+115200, -- 波特率
+8, -- 数据位
+1 -- 停止位
 )
 
 camera.on(0, "scanned", function(id, str)
@@ -63,70 +70,70 @@ camera.on(0, "scanned", function(id, str)
     elseif str == false then
         log.error("摄像头没有数据")
     else
-        log.info("摄像头数据",str)
+        log.info("摄像头数据", str)
         sys.publish("capture done", true)
     end
 end)
 
-
-
 local function press_key()
     log.info("boot press")
     sys.publish("PRESS", true)
 end
-gpio.setup(0, press_key, gpio.PULLDOWN,gpio.RISING)
-gpio.debounce(0 ,100, 1)
-local rawbuff,err
+gpio.setup(0, press_key, gpio.PULLDOWN, gpio.RISING)
+gpio.debounce(0, 100, 1)
+local rawbuff, err
 if RAW_MODE ~= 1 then
-    rawbuff,err = zbuff.create(60 * 1024, 0, zbuff.HEAP_AUTO)
+    rawbuff, err = zbuff.create(60 * 1024, 0, zbuff.HEAP_AUTO)
 else
-    rawbuff,err = zbuff.create(640 * 480 * 2, 0, zbuff.HEAP_AUTO)    --gc032a
-    --local rawbuff = zbuff.create(240 * 320 * 2, zbuff.HEAP_AUTO)  --bf302a
+    rawbuff, err = zbuff.create(640 * 480 * 2, 0, zbuff.HEAP_AUTO) -- gc032a
+    -- local rawbuff = zbuff.create(240 * 320 * 2, zbuff.HEAP_AUTO)  --bf302a
+end
+if rawbuff == nil then
+    log.info(err)
 end
-if rawbuff == nil then log.info(err) end
 
 sys.taskInit(function()
     log.info("摄像头启动")
-    local cspiId,i2cId=1,1
-	local camera_id
-    i2c.setup(i2cId,i2c.FAST)
-    gpio.setup(5,0) --PD拉低
-    --camera_id = bf30a2Init(cspiId,i2cId,25500000,SCAN_MODE,SCAN_MODE)
-	camera_id = gc0310Init(cspiId,i2cId,25500000,SCAN_MODE,SCAN_MODE)
-    --camera_id = gc032aInit(cspiId,i2cId,24000000,SCAN_MODE,SCAN_MODE)
+    local cspiId, i2cId = 1, 1
+    local camera_id
+    i2c.setup(i2cId, i2c.FAST)
+    gpio.setup(5, 0) -- PD拉低
+    -- camera_id = bf30a2Init(cspiId,i2cId,25500000,SCAN_MODE,SCAN_MODE)
+    camera_id = gc0310Init(cspiId, i2cId, 25500000, SCAN_MODE, SCAN_MODE)
+    -- camera_id = gc032aInit(cspiId,i2cId,24000000,SCAN_MODE,SCAN_MODE)
     camera.stop(camera_id)
-    camera.preview(camera_id,true)
+    camera.preview(camera_id, true)
     log.info("按下boot开始测试")
     log.info(rtos.meminfo("sys"))
     log.info(rtos.meminfo("psram"))
     while 1 do
         result, data = sys.waitUntil("PRESS", 30000)
-        if result==true and data==true then
+        if result == true and data == true then
             if SCAN_MODE == 1 then
                 if scan_pause then
                     log.info("启动扫码")
-                    --camera_id = gc0310Init(cspiId,i2cId,25500000,SCAN_MODE,SCAN_MODE)
-                    camera.start(camera_id)	
-					scan_pause = false
+                    -- camera_id = gc0310Init(cspiId,i2cId,25500000,SCAN_MODE,SCAN_MODE)
+                    camera.start(camera_id)
+                    scan_pause = false
                     sys.wait(200)
                     log.info(rtos.meminfo("sys"))
                     log.info(rtos.meminfo("psram"))
                 else
                     log.info("停止扫码")
-                    --camera.close(camera_id)	--完全关闭摄像头才用这个
-					camera.stop(camera_id)
+                    -- camera.close(camera_id)	--完全关闭摄像头才用这个
+                    camera.stop(camera_id)
                     scan_pause = true
                     sys.wait(200)
                     log.info(rtos.meminfo("sys"))
                     log.info(rtos.meminfo("psram"))
                 end
             elseif RAW_MODE == 1 then
-                if getRawStart  == false then
+                if getRawStart == false then
                     getRawStart = true
                     log.debug("摄像头首次捕获原始图像")
-                    camera.startRaw(camera_id,640,480,rawbuff)  --gc032a
-                    --camera.startRaw(camera_id,240,320,rawbuff) --bf302a
-                else 
+                    camera.startRaw(camera_id, 640, 480, rawbuff) -- gc032a
+                    -- camera.startRaw(camera_id,240,320,rawbuff) --bf302a
+                else
                     log.debug("摄像头继续捕获原始图像")
                     camera.getRaw(camera_id)
                 end
@@ -134,22 +141,21 @@ sys.taskInit(function()
                 log.info("摄像头捕获原始图像完成")
                 log.info(rtos.meminfo("sys"))
                 log.info(rtos.meminfo("psram"))
-                --uart.tx(uartid, rawbuff) --找个能保存数据的串口工具保存成文件就能在电脑上看了, 格式为JPG                
+                -- uart.tx(uartid, rawbuff) --找个能保存数据的串口工具保存成文件就能在电脑上看了, 格式为JPG                
             else
-                log.debug("摄像头拍照")
-				--camera_id = gc0310Init(cspiId,i2cId,25500000,SCAN_MODE,SCAN_MODE)
-                camera.capture(camera_id,rawbuff,1)	--2和3需要非常多非常多的psram,尽量不要用
+                log.debug("摄像头拍照")
+                -- camera_id = gc0310Init(cspiId,i2cId,25500000,SCAN_MODE,SCAN_MODE)
+                camera.capture(camera_id, rawbuff, 1) -- 2和3需要非常多非常多的psram,尽量不要用
                 result, data = sys.waitUntil("capture done", 30000)
-                log.info(rawbuff:used())
-				--camera.close(camera_id)	--完全关闭摄像头才用这个
-				camera.stop(camera_id)
-				uart.tx(uartid, rawbuff) --找个能保存数据的串口工具保存成文件就能在电脑上看了, 格式为JPG
-				rawbuff:resize(60 * 1024)
+                log.info(rawbuff:used())
+                -- camera.close(camera_id)	--完全关闭摄像头才用这个
+                camera.stop(camera_id)
+                uart.tx(uartid, rawbuff) -- 找个能保存数据的串口工具保存成文件就能在电脑上看了, 格式为JPG
+                rawbuff:resize(60 * 1024)
                 log.info(rtos.meminfo("sys"))
                 log.info(rtos.meminfo("psram"))
             end
 
-
         end
     end
 

+ 6 - 8
script/turnkey/hz201p/camCapture.lua

@@ -1,11 +1,4 @@
 require "bf30a2"
-local uartid = uart.VUART_0 -- 根据实际设备选取不同的uartid
--- 初始化
-local result = uart.setup(uartid, -- 串口id
-115200, -- 波特率
-8, -- 数据位
-1 -- 停止位
-)
 
 camera.on(0, "scanned", function(id, str)
     if type(str) == 'string' then
@@ -33,6 +26,8 @@ if rawbuff == nil then
     log.info(err)
 end
 
+
+
 sys.taskInit(function()
     log.info("摄像头启动")
     local cspiId, i2cId = 1, 0
@@ -43,7 +38,7 @@ sys.taskInit(function()
     log.info(rtos.meminfo("sys"))
     log.info(rtos.meminfo("psram"))
     while 1 do
-        local result, data = sys.waitUntil("PRESS", 30000)
+        local result, data = sys.waitUntil("PRESS")
         if result == true and data == true then
             log.debug("摄像头拍照")
             camera_id = bf30a2Init(cspiId, i2cId, 25500000)
@@ -59,3 +54,6 @@ sys.taskInit(function()
         end
     end
 end)
+
+sys.publish("PRESS", true)
+sys.timerLoopStart(sys.publish, 60000, "PRESS", true)

+ 65 - 0
script/turnkey/hz201p/ccVolte.lua

@@ -0,0 +1,65 @@
+local cnt = 0
+sys.subscribe("CC_IND", function(state)
+    if state == "READY" then
+        sys.publish("CC_READY")
+    elseif state == "INCOMINGCALL" then
+		cnt = cnt + 1
+		if cnt > 1 then
+			cc.accept(0)
+		end
+    elseif state == "HANGUP_CALL_DONE" or state == "MAKE_CALL_FAILED" or state == "DISCONNECTED" then
+		audio.pm(0,audio.STANDBY)
+		-- audio.pm(0,audio.SHUTDOWN)	--低功耗可以选择SHUTDOWN或者POWEROFF,如果codec无法断电用SHUTDOWN
+	end
+end)
+
+sys.taskInit(function()
+    local multimedia_id = 0
+    local i2c_id = 0
+    local i2s_id = 0
+    local i2s_mode = 0
+    local i2s_sample_rate = 16000
+    local i2s_bits_per_sample = 16
+    local i2s_channel_format = i2s.MONO_R
+    local i2s_communication_format = i2s.MODE_LSB
+    local i2s_channel_bits = 16
+
+    local pa_pin = 25
+    local pa_on_level = 1
+    local pa_delay = 100
+    local power_pin = 255
+    local power_on_level = 1
+    local power_delay = 3
+    local power_time_delay = 100
+
+    local voice_vol = 70
+    local mic_vol = 65
+
+    local find_es8311 = false
+	--自适应开发板,如果明确是I2C几就不用了
+    i2c.setup(i2c_id, i2c.FAST)
+	pm.power(pm.LDO_CTL, false)  --开发板上ES8311由LDO_CTL控制上下电
+    sys.wait(10)
+    pm.power(pm.LDO_CTL, true)  --开发板上ES8311由LDO_CTL控制上下电
+	sys.wait(10)
+    if i2c.send(i2c_id, 0x18, 0xfd) == true then
+        find_es8311 = true
+    end
+
+    if not find_es8311 then
+        while true do
+            log.info("not find es8311")
+            sys.wait(1000)
+        end
+    end
+    i2s.setup(i2s_id, i2s_mode, i2s_sample_rate, i2s_bits_per_sample, i2s_channel_format, i2s_communication_format,i2s_channel_bits)
+    audio.config(multimedia_id, pa_pin, pa_on_level, power_delay, pa_delay, power_pin, power_on_level, power_time_delay)
+    audio.setBus(multimedia_id, audio.BUS_I2S,{chip = "es8311", i2cid = i2c_id, i2sid = i2s_id})	--通道0的硬件输出通道设置为I2S
+    audio.vol(multimedia_id, voice_vol)
+    audio.micVol(multimedia_id, mic_vol)
+    cc.init(multimedia_id)
+	audio.pm(0,audio.STANDBY)
+    sys.waitUntil("CC_READY")
+    sys.wait(100)   
+    --cc.dial(0,"114") --拨打电话
+end)

+ 1 - 1
script/turnkey/hz201p/da267.lua

@@ -1,4 +1,4 @@
-local i2cId = 0
+local i2cId = 1
 local da267Addr = 0x26
 local intPin = 39
 local function ind()

+ 47 - 0
script/turnkey/hz201p/gnss.lua

@@ -0,0 +1,47 @@
+local uartId = 2
+libgnss.clear() -- 清空数据,兼初始化
+uart.setup(uartId, 115200)
+
+
+
+sys.taskInit(function()
+    log.info("GPS", "start")
+    gpio.setup(27, 1)
+    libgnss.bind(uartId)
+    sys.wait(200) -- GPNSS芯片启动需要时间
+    -- 调试日志,可选
+    libgnss.debug(true)
+end)
+
+sys.taskInit(function()
+    while 1 do
+        sys.wait(5000)
+        -- uart.write(uartId, "$CFGSYS\r\n")
+        -- uart.write(uartId, "$CFGMSG,6,4\r\n")
+        log.info("RMC", json.encode(libgnss.getRmc(2) or {}))
+        -- log.info("GGA", libgnss.getGga(3))
+        -- log.info("GLL", json.encode(libgnss.getGll(2) or {}))
+        -- log.info("GSA", json.encode(libgnss.getGsa(2) or {}))
+        -- log.info("GSV", json.encode(libgnss.getGsv(2) or {}))
+        -- log.info("VTG", json.encode(libgnss.getVtg(2) or {}))
+        -- log.info("ZDA", json.encode(libgnss.getZda(2) or {}))
+        -- log.info("date", os.date())
+    end
+end)
+
+-- 订阅GNSS状态编码
+sys.subscribe("GNSS_STATE", function(event, ticks)
+    -- event取值有 
+    -- FIXED 定位成功
+    -- LOSE  定位丢失
+    -- ticks是事件发生的时间,一般可以忽略
+    log.info("gnss", "state", event, ticks)
+    if event == "FIXED" then
+        local locStr = libgnss.locStr()
+        log.info("gnss", "locStr", locStr)
+        if locStr then
+            io.writeFile("/gnssloc", locStr)
+        end
+    end
+end)
+

+ 27 - 0
script/turnkey/hz201p/main.lua

@@ -7,9 +7,36 @@ log.info("main", PROJECT, VERSION)
 -- 引入必要的库文件(lua编写), 内部库不需要require
 _G.sys = require "sys"
 
+
+-- Gsensor
 require "da267"
+
+-- 780ep不支持VOLTE,支持CAMERA
+-- 780epv固件支持VOLTE,但固件空间放不下CAMERA
+
+-- CAMERA
 require "camCapture"
 
+-- VOLTE
+-- require "ccVolte"
+
+-- LED
+sys.taskInit(function()
+    local netLed = gpio.setup(1, 0)
+    local pwrLed = gpio.setup(16, 0, nil, nil, 4)
+    while 1 do
+        netLed(1)
+        pwrLed(1)
+        sys.wait(5000)
+        netLed(0)
+        pwrLed(0)
+        sys.wait(5000)
+    end
+end)
+
+-- 默认是IDLE模式,可替换为pm.LIGHT
+pm.request(pm.IDLE)
+
 sys.taskInit(function()
     while 1 do
         log.info("lua", rtos.meminfo())