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

Merge branch 'master' of gitee.com:openLuat/LuatOS

Wendal Chen 3 лет назад
Родитель
Сommit
d538f19718

+ 63 - 0
demo/record/EC618/es8218e.lua

@@ -0,0 +1,63 @@
+local es8218e_reg = {
+    {0x00, 0x00},
+    {0x01, 0x2F + (0 << 7)},
+    {0x02, 0x01},
+    {0x03, 0x20},
+    {0x04, 0x01},
+    {0x05, 0x00},
+    {0x06, 4 + (0 << 5)},
+    {0x10, 0x18 + 0},
+    {0x07, 0 + (3 << 2)},
+    {0x09, 0x00},
+    {0x0A, 0x22 + (0xCC * 0)},
+    {0x0B, 0x02 - 0},
+    {0x14, 0xA0},
+    {0x0D, 0x30},
+    {0x0E, 0x20},
+    {0x23, 0x00},
+    {0x24, 0x00},
+    {0x18, 0x04},
+    {0x19, 0x04},
+    {0x0F, (0 << 5) + (1 << 4) + 7},
+    {0x08, 0x00},
+    {0x00, 0x80},
+    {0x12, 0x1C},
+    {0x11, 0},
+    {0x01, (0x2f) + (1 << 7)},
+}
+local rx_buff = zbuff.create(3200)
+local amr_buff = zbuff.create(10240)
+
+local encoder = codec.create(codec.AMR, false)--创建一个amr的encoder
+local function record_cb(id, buff)
+    if buff then
+        log.info("I2S", id, "接收了", rx_buff:used())
+        codec.encode(encoder, rx_buff, amr_buff)
+    end
+end
+
+
+
+function record_task()
+    sys.wait(5000)
+    uart.setup(1, 115200)
+    local es8218e_address = 0x10
+    log.info("i2c initial",i2c.setup(0, i2c.FAST))
+    audio.config(0, 25, 1, 6, 200)
+    i2s.setup(0, 0, 8000, 16, 1, i2s.MODE_I2S)
+    i2s.on(0, record_cb) 
+    i2s.recv(0, rx_buff, 3200)
+    sys.wait(300)
+    for i, v in pairs(es8218e_reg) do
+        i2c.send(0,es8218e_address,v,1)
+    end
+    sys.wait(5000)
+    i2c.send(0, es8218e_address,{0x01, (0x2f) + (1 << 7)},1)
+    i2s.stop(0)
+    log.info("录音5秒结束")
+    uart.write(1, "#!AMR\n")
+    sys.wait(5)
+    uart.write(1, amr_buff:query())
+end
+pm.power(pm.DAC_EN, true)
+sys.taskInit(record_task)

+ 71 - 0
demo/record/EC618/es8311.lua

@@ -0,0 +1,71 @@
+local es8311_reg = {
+	{0x45,0x00},
+	{0x01,0x30},
+	{0x02,0x10},
+	{0x02,0x00},
+	{0x03,0x10},
+	{0x16,0x24},
+	{0x04,0x20},
+	{0x05,0x00},
+	{0x06,(0<<5) + 4 -1},
+	{0x07,0x00},
+	{0x08,0xFF},
+	{0x09,0x0C},
+	{0x0A,0x0C},
+	{0x0B,0x00},
+	{0x0C,0x00},
+	{0x10,(0x1C*0) + (0x60*0x00) + 0x03},
+	{0x11,0x7F},
+	{0x00,0x80 + (0<<6)},
+	{0x0D,0x01},
+	{0x01,0x3F + (0x00<<7)},
+	{0x14,(0<<6) + (1<<4) + 10},
+	{0x12,0x28},
+	{0x13,0x00 + (0<<4)},
+	{0x0E,0x02},
+	{0x0F,0x44},
+	{0x15,0x00},
+	{0x1B,0x0A},
+	{0x1C,0x6A},
+	{0x37,0x48},
+	{0x44,(0 <<7)},
+	{0x17,210},
+	{0x32,200},
+    {0x00,0x80 + (1<<6)},
+}
+local rx_buff = zbuff.create(3200)
+local amr_buff = zbuff.create(10240)
+
+local encoder = codec.create(codec.AMR, false)--创建一个amr的encoder
+local function record_cb(id, buff)
+    if buff then
+        log.info("I2S", id, "接收了", rx_buff:used())
+        codec.encode(encoder, rx_buff, amr_buff)
+    end
+end
+
+
+
+function record_task()
+    sys.wait(5000)
+    uart.setup(1, 115200)
+    local es8311_address = 0x18
+    log.info("i2c initial",i2c.setup(0, i2c.FAST))
+    audio.config(0, 25, 1, 6, 200)
+    i2s.setup(0, 0, 8000, 16, 1, i2s.MODE_I2S)
+    i2s.on(0, record_cb) 
+    i2s.recv(0, rx_buff, 3200)
+    sys.wait(300)
+    for i, v in pairs(es8311_reg) do
+        i2c.send(0,es8311_address,v,1)
+    end
+    sys.wait(5050)
+    i2c.send(0, es8311_address,{0x00, 0x80 + (0<<6)},1)
+    i2s.stop(0)
+    log.info("录音5秒结束")
+    uart.write(1, "#!AMR\n")
+    sys.wait(5)
+    uart.write(1, amr_buff:query())
+end
+pm.power(pm.DAC_EN, true)
+sys.taskInit(record_task)

+ 2 - 57
demo/record/EC618/main.lua

@@ -5,61 +5,6 @@ log.info("main", PROJECT, VERSION)
 log.style(1)
 -- sys库是标配
 _G.sys = require("sys")
-local es8311_reg = {
-	{0x45,0x00},
-	{0x01,0x30},
-	{0x02,0x10},
-	{0x02,0x00},
-	{0x03,0x10},
-	{0x16,0x24},
-	{0x04,0x20},
-	{0x05,0x00},
-	{0x06,(0<<5) + 4 -1},
-	{0x07,0x00},
-	{0x08,0xFF},
-	{0x09,0x0C},
-	{0x0A,0x0C},
-	{0x0B,0x00},
-	{0x0C,0x00},
-	{0x10,(0x1C*0) + (0x60*0x00) + 0x03},
-	{0x11,0x7F},
-	{0x00,0x80 + (1<<6)},
-	{0x0D,0x01},
-	{0x01,0x3F + (0x00<<7)},
-	{0x14,(0<<6) + (1<<4) + 0},
-	{0x12,0x28},
-	{0x13,0x00 + (0<<4)},
-	{0x0E,0x02},
-	{0x0F,0x44},
-	{0x15,0x00},
-	{0x1B,0x0A},
-	{0x1C,0x6A},
-	{0x37,0x48},
-	{0x44,(0 <<7)},
-	{0x17,210},
-	{0x32,200},
-}
-local rx_buff = zbuff.create(3200)
-local function record_cb(id, buff)
-    if buff then
-        log.info("I2S", id, "接收了", rx_buff:used())
-    end
-end
-
-function record_task()
-    local es8311_address = 0x18
-    log.info("i2c initial",i2c.setup(0, i2c.FAST))
-    i2s.setup(0, 0, 8000, 16, 1, i2s.MODE_I2S)
-    i2s.on(0, record_cb)
-    i2s.recv(0, rx_buff, 3200)
-    sys.wait(300)
-    for i, v in pairs(es8311_reg) do
-        i2c.send(0,es8311_address,v,1)
-    end
-    sys.wait(5050)
-    i2s.stop(0)
-    log.info("录音5秒结束")
-end
-pm.power(pm.DAC_EN, true)
-sys.taskInit(record_task)
+require "es8311"
+-- require "es8218e"
 sys.run()

+ 2 - 1
demo/uart_wakeup/EC618/main.lua

@@ -1,4 +1,5 @@
--- 在休眠后通过UART1的RX唤醒,注意第一个字节会被舍弃,所以要发2次,第一次发送字节后,会有提示,然后再发送数据
+-- UART1支持600 1200 2400 4800 9600波特率下休眠仍然接收数据,并且不丢失数据
+-- 其他波特率时,在休眠后通过UART1的RX唤醒,注意唤醒开始所有连续数据会丢失,所以要发2次,第一次发送字节后,会有提示,然后再发送数据
 -- LuaTools需要PROJECT和VERSION这两个信息
 PROJECT = "uart_wakeup"
 VERSION = "1.0.0"

+ 1 - 1
luat/modules/luat_lib_uart.c

@@ -91,7 +91,7 @@ int l_uart_handler(lua_State *L, void* ptr) {
 @int 串口id, uart0写0, uart1写1, 如此类推, 最大值取决于设备
 @int 波特率, 默认115200,可选择波特率表:{2000000,921600,460800,230400,115200,57600,38400,19200,9600,4800,2400}
 @int 数据位,默认为8, 可选 7/8
-@int 停止位,默认为1, 可选 0/1, 有部分特殊芯片会支持1.5,使用2代表.
+@int 停止位,默认为1, 根据实际情况,可以有0.5/1/1.5/2等
 @int 校验位,可选 uart.None/uart.Even/uart.Odd
 @int 大小端,默认小端 uart.LSB, 可选 uart.MSB
 @int 缓冲区大小,默认值1024