Skip to content

Commit

Permalink
Merge branch 'master' of gitee.com:openLuat/LuatOS
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Jan 21, 2024
2 parents 174d667 + 9c9acca commit 6c4f947
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 24 deletions.
11 changes: 11 additions & 0 deletions components/cc/luat_lib_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ static int l_cc_record_call(lua_State* L) {
return 1;
}

/**
获取当前通话质量
@api cc.quality()
@return int 1为低音质,2为高音质,0没有在通话
*/
static int l_cc_get_quality(lua_State* L) {
lua_pushinteger(L, luat_cc.record_type);
return 1;
}

/**
注册通话回调
@api cc.on(event, func)
Expand Down Expand Up @@ -435,6 +445,7 @@ static const rotable_Reg_t reg_cc[] =
{ "accept" , ROREG_FUNC(l_cc_answer_call)},
{ "hangUp" , ROREG_FUNC(l_cc_hangup_call)},
{ "lastNum" , ROREG_FUNC(l_cc_get_last_call_num)},
{ "quality" , ROREG_FUNC(l_cc_get_quality)},
{ "on" , ROREG_FUNC(l_cc_on)},
{ "record", ROREG_FUNC(l_cc_record_call)},
{ NULL, {}}
Expand Down
10 changes: 6 additions & 4 deletions components/lcd/luat_lib_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,11 +1316,13 @@ static int lcd_out_func (JDEC* jd, void* bitmap, JRECT* rect){

// rgb高低位swap
uint16_t count = (rect->right - rect->left + 1) * (rect->bottom - rect->top + 1);
for (size_t i = 0; i < count; i++)
{
dev->buff[i] = ((tmp[i] >> 8) & 0xFF)+ ((tmp[i] << 8) & 0xFF00);
for (size_t i = 0; i < count; i++){
if (default_conf->port == LUAT_LCD_HW_ID_0)
dev->buff[i] = tmp[i];
else
dev->buff[i] = ((tmp[i] >> 8) & 0xFF)+ ((tmp[i] << 8) & 0xFF00);
}

// LLOGD("jpeg seg %dx%d %dx%d", rect->left, rect->top, rect->right, rect->bottom);
// LLOGD("jpeg seg size %d %d %d", rect->right - rect->left + 1, rect->bottom - rect->top + 1, (rect->right - rect->left + 1) * (rect->bottom - rect->top + 1));
luat_lcd_draw(default_conf, dev->x + rect->left, dev->y + rect->top,
Expand Down
4 changes: 4 additions & 0 deletions components/network/libhttp/luat_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define LUAT_HTTP_H

#ifdef __LUATOS__
#include "luat_zbuff.h"


#if defined(AIR101) || defined(AIR103)
// #define HTTP_REQ_HEADER_MAX_SIZE (2048)
#define HTTP_RESP_BUFF_SIZE (2048)
Expand Down Expand Up @@ -86,6 +89,7 @@ typedef struct{
char *req_header;
char *req_body; //发送body
size_t req_body_len; //发送body长度
luat_zbuff_t *zbuff_body;
char *req_auth;
#ifdef LUAT_USE_FOTA
//OTA相关
Expand Down
9 changes: 9 additions & 0 deletions components/network/libhttp/luat_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ static int on_body(http_parser* parser, const char *at, size_t length){
}
}
#endif
else if(http_ctrl->is_post==0 && http_ctrl->zbuff_body!=NULL){
if (http_ctrl->zbuff_body->len < http_ctrl->zbuff_body->used+length+1 ){
http_ctrl->zbuff_body->addr = luat_heap_realloc(http_ctrl->zbuff_body->addr,http_ctrl->zbuff_body->used+length+1);
}
memcpy(http_ctrl->zbuff_body->addr + http_ctrl->zbuff_body->used ,at,length);
http_ctrl->zbuff_body->used += length;
}
else{
if (!http_ctrl->body){
http_ctrl->body = luat_heap_malloc(length+1);
Expand Down Expand Up @@ -475,6 +482,8 @@ static void http_send_message(luat_http_ctrl_t *http_ctrl){
// 发送body
if (http_ctrl->req_body){
http_send(http_ctrl, (uint8_t*)http_ctrl->req_body, http_ctrl->req_body_len);
}else if(http_ctrl->is_post==1 && http_ctrl->zbuff_body!=NULL){
http_send(http_ctrl, http_ctrl->zbuff_body->addr, http_ctrl->zbuff_body->used);
}
#else
int result;
Expand Down
17 changes: 14 additions & 3 deletions components/network/libhttp/luat_lib_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ http客户端
@string 请求方法, 支持 GET/POST 等合法的HTTP方法
@string url地址, 支持 http和https, 支持域名, 支持自定义端口
@tabal 请求头 可选 例如 {["Content-Type"] = "application/x-www-form-urlencoded"}
@string body 可选, 对POST/PUT等请求方式有效
@string/zbuff body 可选
@table 额外配置 可选 包含 timeout:超时时间单位ms 可选,默认10分钟,写0即永久等待 dst:下载路径,可选 adapter:选择使用网卡,可选 debug:是否打开debug信息,可选,ipv6:是否为ipv6 默认不是,可选 callback:下载回调函数,参数 content_len:总长度 body_len:以下载长度 userdata 用户传参,可选 userdata:回调自定义传参
@string 服务器ca证书数据, 可选, 一般不需要
@string 客户端ca证书数据, 可选, 一般不需要, 双向https认证才需要
Expand Down Expand Up @@ -242,6 +242,11 @@ static int l_http_request(lua_State *L) {
// memcpy(http_ctrl->method, method, len + 1);
// LLOGD("method:%s",http_ctrl->method);

if (strcmp("POST", method) == 0 || strcmp("PUT", method) == 0){
http_ctrl->is_post = 1;
}


const char *url = luaL_checklstring(L, 2, &len);
// http_ctrl->url = luat_heap_malloc(len + 1);
// memset(http_ctrl->url, 0, len + 1);
Expand Down Expand Up @@ -278,11 +283,17 @@ static int l_http_request(lua_State *L) {
if (lua_isstring(L, 4)) {
const char *body = luaL_checklstring(L, 4, &(http_ctrl->req_body_len));
http_ctrl->req_body = luat_heap_malloc((http_ctrl->req_body_len) + 1);
// TODO 检测req_body是否为NULL
// TODO 检测req_body是否为NULL
memset(http_ctrl->req_body, 0, (http_ctrl->req_body_len) + 1);
memcpy(http_ctrl->req_body, body, (http_ctrl->req_body_len));
snprintf_(body_len, 6,"%d",(http_ctrl->req_body_len));
http_add_header(http_ctrl,"Content-Length",body_len);
}else if(lua_isuserdata(L, 4)){//zbuff
http_ctrl->zbuff_body = ((luat_zbuff_t *)luaL_checkudata(L, 4, LUAT_ZBUFF_TYPE));
if (http_ctrl->is_post){
snprintf_(body_len, 6,"%d",(http_ctrl->zbuff_body->used));
http_add_header(http_ctrl,"Content-Length",body_len);
}
}

// TODO 对 req_header进行realloc
Expand Down Expand Up @@ -413,7 +424,7 @@ int32_t l_http_callback(lua_State *L, void* ptr){
http_ctrl->headers_len -= temp-header;
header = temp;
}
LLOGD("http_ctrl->body:%.*s len:%d",http_ctrl->body_len,http_ctrl->body,http_ctrl->body_len);
// LLOGD("http_ctrl->body:%.*s len:%d",http_ctrl->body_len,http_ctrl->body,http_ctrl->body_len);
// 处理body, 需要区分下载模式和非下载模式
if (http_ctrl->is_download) {
// 下载模式
Expand Down
34 changes: 18 additions & 16 deletions demo/lcd/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ 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
return lcd.HWID_0,36,0xff,0xff,0xff -- 硬件lcd驱动
else
log.info("main", "bsp not support")
return
Expand All @@ -69,28 +71,28 @@ end
local spi_id,pin_reset,pin_dc,pin_cs,bl = lcd_pin()

-- v0006及以后版本可用pin方式, 请升级到最新固件 https://gitee.com/openLuat/LuatOS/releases
spi_lcd = spi.deviceSetup(spi_id,pin_cs,0,0,8,20*1000*1000,spi.MSB,1,0)
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)

--[[ 此为合宙售卖的2.4寸TFT LCD 分辨率:240X320 屏幕ic:GC9306 购买地址:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-24045920841.39.6c2275a1Pa8F9o&id=655959696358]]
-- lcd.init("gc9a01",{port = "device",pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 240,h = 320,xoffset = 0,yoffset = 0},spi_lcd)
--[[ 此为合宙售卖的1.8寸TFT LCD LCD 分辨率:128X160 屏幕ic:st7735 购买地址:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-24045920841.19.6c2275a1Pa8F9o&id=560176729178]]
-- lcd.init("st7735",{port = "device",pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 128,h = 160,xoffset = 0,yoffset = 0},spi_lcd)

--[[ 此为合宙售卖的1.8寸TFT LCD LCD 分辨率:128X160 屏幕ic:st7735 购买地址:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-24045920841.19.6c2275a1Pa8F9o&id=560176729178]]
lcd.init("st7735",{port = "device",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 = "device",pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 240,h = 320,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 = "device",pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 240,h = 240,xoffset = 0,yoffset = 0},spi_lcd)
--[[ 此为合宙售卖的0.96寸TFT LCD LCD 分辨率:160X80 屏幕ic:st7735s 购买地址:https://item.taobao.com/item.htm?id=661054472686]]
--lcd.init("st7735v",{port = "device",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 = "device",pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 2,w = 160,h = 80,xoffset = 0,yoffset = 0},spi_lcd)

--[[ 此为合宙售卖的0.96寸TFT LCD LCD 分辨率:160X80 屏幕ic:st7735s 购买地址:https://item.taobao.com/item.htm?id=661054472686]]
--lcd.init("st7735v",{port = "device",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 = "device",pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 2,w = 160,h = 80,xoffset = 0,yoffset = 0},spi_lcd)
else
lcd.init("st7789",{port = spi_id, pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 240,h = 320})
end

--[[ 此为合宙售卖的2.4寸TFT LCD 分辨率:240X320 屏幕ic:GC9306 购买地址:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-24045920841.39.6c2275a1Pa8F9o&id=655959696358]]
-- lcd.init("gc9306",{port = "device",pin_dc = pin_dc , pin_pwr = bl,pin_rst = pin_reset,direction = 0,w = 240,h = 320,xoffset = 0,yoffset = 0},spi_lcd)

-- 不在上述内置驱动的, 看demo/lcd_custom
-- 不在内置驱动的, 看demo/lcd_custom

sys.taskInit(function()
-- 开启缓冲区, 刷屏速度回加快, 但也消耗2倍屏幕分辨率的内存
Expand Down
30 changes: 29 additions & 1 deletion luat/modules/luat_lib_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,32 @@ static int l_i2s_tx_stat(lua_State *L) {
lua_pushinteger(L, remain);
return 2;
}

#if 0
/*
获取I2S参数,参数具体参考setup
@api i2s.getPara(id)
@int 通道id
@return boolean 是否在工作状态 true是
@return int 模式, 0 主机 1 从机
@return int 采样率
@return int 数据位数
@return int 声道
@return int 格式
@return int 1个声道的BCLK数量
*/
static int l_i2s_get_param(lua_State *L) {
int id = luaL_checkinteger(L, 1);
luat_i2s_conf_t *config = luat_i2s_get_config(id);
lua_pushboolean(L, config->state);
lua_pushinteger(L, config->mode);
lua_pushinteger(L, config->sample_rate);
lua_pushinteger(L, config->data_bits);
lua_pushinteger(L, config->channel_format);
lua_pushinteger(L, config->standard);
lua_pushinteger(L, config->channel_bits);
return 7;
}
#endif
int l_i2s_play(lua_State *L);
int l_i2s_pause(lua_State *L);
int l_i2s_stop(lua_State *L);
Expand Down Expand Up @@ -287,6 +312,9 @@ static const rotable_Reg_t reg_i2s[] =
{ "close", ROREG_FUNC(l_i2s_close)},
{ "on", ROREG_FUNC(l_i2s_on)},
{ "txStat", ROREG_FUNC(l_i2s_tx_stat)},
#if 0
{ "getPara", ROREG_FUNC(l_i2s_get_param)},
#endif
// 以下为兼容扩展功能,待定
{ "play", ROREG_FUNC(l_i2s_play)},
{ "pause", ROREG_FUNC(l_i2s_pause)},
Expand Down
119 changes: 119 additions & 0 deletions script/libs/pca9555.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
--[[
@module pca9555
@summary pca9555 IO扩展
@version 1.0
@date 2024/1/15
@author 小牛
@usage
i2c.setup(0, i2c.FAST)
pca9555.setup(0, 0x20, 0x0000)
for i=0,7 do
pca9555.pin(i,0)
end
]]

local pca9555 = {}

local PCA9555_i2cid=0
local PCA9555_addr=0x20
local PCA9555_mode=0x0000 --IO全为输出
local PCA9555_IOstart=0xffff

-- pca9555 registers define
local PCA9555_REG_IN0 = 0x00 --输入端口寄存器0 默认值由外部逻辑决定 只可读不可写
local PCA9555_REG_IN1 = 0x01 --输入端口寄存器1 默认值由外部逻辑决定 只可读不可写
local PCA9555_REG_OUT0 = 0x02 --输出端口寄存器0 默认值为1 可读可写
local PCA9555_REG_OUT1 = 0x03 --输入端口寄存器1 默认值为1 可读可写
local PCA9555_REG_POL0 = 0x04 --极性反转寄存器0 默认值为0 可读可写
local PCA9555_REG_POL1 = 0x05 --极性反转寄存器1 默认值为0 可读可写
local PCA9555_REG0_CFG0 = 0x06 --配置端口寄存器0 默认为1 可读可写
local PCA9555_REG1_CFG1 = 0x07 --配置端口寄存器1 默认为1 可读可写

--[[
配置寄存器说明 1为输入模式 0为输出模式
Config registers
---------------------------------------------------------------------------------------
Config prot 0 register
Bit 7 6 5 4 3 2 1
Symbol C0.7 C0.6 C0.5 C0.4 C0.3 C0.2 C0.0
Default 1 1 1 1 1 1 1
---------------------------------------------------------------------------------------
Config prot 1 register
Bit 7 6 5 4 3 2 1
Symbol C1.7 C1.6 C1.5 C1.4 C1.3 C1.2 C1.0
Default 1 1 1 1 1 1 1
---------------------------------------------------------------------------------------
]]

--[[
pca9555初始化
@api pca955.setup(i2cid, addr,mode)
@number i2cid 所在的i2c总线
@number addr pca9555设备的i2c地址
@number mode 配置输入输出模式 --0xffff 高八位配置IO 17-10 低八位配置IO 7-0
@return 初始化失败,返回nil
@usage
i2c.setup(0, i2c.FAST)
pca9555.setup(0,0x20,0xffff)
]]
function pca9555.setup(i2cid,addr,mode)
PCA9555_i2cid=i2cid
PCA9555_addr=addr
PCA9555_mode=mode
readEncoder()
local tmp=i2c.readReg(PCA9555_i2cid, PCA9555_addr, 0x02, 2)
if tmp==nil then
log.info("PCA9555初始化失败")
return nil
end
if PCA9555_mode~=nil then
i2c.writeReg(PCA9555_i2cid,PCA9555_addr,0x06,pack.pack("<H",PCA9555_mode))
i2c.writeReg(PCA9555_i2cid,PCA9555_addr,0x02,pack.pack("<H",PCA9555_IOstart))
else
local recvData=i2c.readReg(PCA9555_i2cid, PCA9555_addr,0x00,2)
_,recvData=pack.unpack(recvData,"<H")
log.info("pca9555默认为完全输入模式",recvData)
end
end

--[[
pca9555 pin控制
@api pca9555.pin(pin,val)
@number pin 引脚 0-7 10-17
@number val 高/低电平 1/0
@return number 如果val未填,则读取pin的输出电平
@usage
for i=0,7 do
pca9555.pin(i,0)
end
]]
function pca9555.pin(pin,val)
if pin==nil then
log.info("请选择引脚")
elseif pin then
if val==nil then
if pin>9 then
pin=pin-2
end
local tmp=i2c.readReg(PCA9555_i2cid, PCA9555_addr,0x00,2)
_,tmp=pack.unpack(tmp,"<H")
val=(tmp&(1<<pin))>>pin
return val
elseif val==0 then
if pin>9 then
pin=pin-2
end
PCA9555_IOstart=PCA9555_IOstart&(~(1<<pin))
i2c.writeReg(PCA9555_i2cid,PCA9555_addr,0x02,pack.pack("<H",PCA9555_IOstart))
else
if pin>9 then
pin=pin-2
end
PCA9555_IOstart=PCA9555_IOstart|(1<<pin)
i2c.writeReg(PCA9555_i2cid,PCA9555_addr,0x02,pack.pack("<H",PCA9555_IOstart))
end
end
end

return pca9555

0 comments on commit 6c4f947

Please sign in to comment.