Skip to content

Commit

Permalink
Merge branch 'master' of https://gitee.com/openLuat/luatos-soc-pc
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed Nov 1, 2023
2 parents b38f3d6 + 36dcab5 commit 761496b
Show file tree
Hide file tree
Showing 34 changed files with 1,400 additions and 333 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
# 针对PC环境的LuatOS集成

* 使用说明
* [使用说明](doc/usage.md)
* [编译说明](doc/compile.md)
* [设计文档](doc/design.md)

本BSP已经替代主库的`bsp/linux``bsp/win32`

## 待完成列表功能

* [x] 支持windows编译,运行
* [x] 支持linux编译,运行
* [ ] 支持macos编译,运行 -- 理论上支持,没有测试环境
* [x] 支持macos编译,运行
* [x] 交互模式 REPL
* [x] 单文件模式,直接跑main.lua
* [x] 目录模式,把指定目录挂载成/luadb,模拟真实设备的路径
* [ ] ZTT机制(模拟器)的设计和实现
* [ ] 跑通iRTU代码

## 已支持的库

* lua基础库, io/os/table/math/bit等所有自带的库
* luatos基础库,log/rtos/timer
* 外设库, uart/gpio/mcu/fskv
* 网络库, socket/http/mqtt/websocket/sntp,含TLS/SSL
* UI库, lcd/lvgl
* 工具库, crypto/pack/json/gmssl/iotauth/bit64/zbuff/protobuf等所有工具库

## 授权协议

[MIT License](LICENSE)
Expand Down
3 changes: 2 additions & 1 deletion build_linux_32bit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

xmake clean -a
export VM_64bit=0
xmake f -p linux -a i386 -m debug -y
export LUAT_USE_GUI=n
xmake f -p linux -a i386 -m debug
xmake -w -y
1 change: 1 addition & 0 deletions build_linux_64bit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
xmake clean -a
export VM_64bit=1
export LUAT_USE_GUI=n
xmake f -p linux -a i386 -y
xmake -w -y
5 changes: 5 additions & 0 deletions build_linux_64bit_gui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
xmake clean -a
export VM_64bit=1
export LUAT_USE_GUI=y
xmake f -p linux -a i386 -y
xmake -w -y
1 change: 1 addition & 0 deletions build_windows_32bit_msvc.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

xmake clean -a
set VM_64bit=0
set LUAT_USE_GUI=n
xmake f -a x86 -y
xmake -y -w -v
6 changes: 6 additions & 0 deletions build_windows_32bit_msvc_gui.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

xmake clean -a
set VM_64bit=0
set LUAT_USE_GUI=y
xmake f -a x86 -y
xmake -y -w -v
1 change: 1 addition & 0 deletions build_windows_64bit_msvc.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

xmake clean -a
set VM_64bit=1
set LUAT_USE_GUI=n
xmake f -a x86 -y
xmake -y -w -v
6 changes: 6 additions & 0 deletions build_windows_64bit_msvc_gui.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

xmake clean -a
set VM_64bit=1
set LUAT_USE_GUI=n
xmake f -a x86 -y
xmake -y -w -v
57 changes: 57 additions & 0 deletions doc/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 用法指南

## 交互模式

windows

```bash
luatos-pc.exe
```

linux

```bash
./luatos-pc
```

若需退出交互模式
```lua
os.exit()
```

## 指定文件或文件夹加载并启动

支持指定多个文件或文件夹,一起加载并启动


单文件启动
```bash
luatos-pc.exe test/001.helloworld/main.lua
```

多文件启动,按第一个`main.lua`作为主文件
```bash
luatos-pc.exe test/001.helloworld/main.lua test/abc.lua test/logo.jpg
```

按文件夹启动, 路径需要以`/`或者`\` 结尾
```bash
luatos-pc.exe ../LuatOS/demo/gmssl/
```

文件和文件夹混合启动
```bash
luatos-pc.exe test/001.helloworld/main.lua ../LuatOS/demo/gmssl/
```

## 加载luatools项目文件直接启动

```bash
luatos-pc.exe --llt=D:/luatools/project/air101_gpio.ini
```

## 加载luadb镜像文件启动

```bash
luatos-pc.exe --ldb=D:/luatools/SoC量产文件/script.bin
```
106 changes: 106 additions & 0 deletions include/luat_conf_bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "stdint.h"

#define LUAT_BSP_VERSION "V1106"
#define LUAT_CONF_USE_LIBSYS_SOURCE 1
#define LUAT_USE_CMDLINE_ARGS 1
// 启用64位虚拟机
// #define LUAT_CONF_VM_64bit
Expand All @@ -27,6 +28,19 @@
#define LUAT_USE_SNTP 1
#define LUAT_USE_TLS 1

#define LV_HOR_RES_MAX (2000)
#define LV_VER_RES_MAX (2000)
#define LV_COLOR_DEPTH 16

#define LV_COLOR_16_SWAP 1
#define LUAT_LCD_COLOR_DEPTH 16
#define LUAT_USE_LVGL_SDL2 1
#define LUAT_USE_LCD_SDL2 1
#define LUAT_USE_LCD_CUSTOM_DRAW 1
#define LV_MEM_CUSTOM 1
// #define LV_USE_LOG 1
// #define LUAT_LV_DEBUG 1

//----------------------------
// 外设,按需启用, 最起码启用uart和wdt库
#define LUAT_USE_UART 1
Expand Down Expand Up @@ -90,4 +104,96 @@
#define LUAT_USE_BIT64 1
#define LUAT_USE_FASTLZ 1

//--------------------------------------------------
// GUI相关
//--------------------------------------------------
// 这里需要从环境变量里启用,不能直接修改下面的宏
// #define LUAT_USE_GUI 1

#ifdef LUAT_USE_GUI
//---------------------
// UI
// LCD 是彩屏, 若使用LVGL就必须启用LCD
#define LUAT_USE_LCD
#define LUAT_USE_TJPGD
// EINK 是墨水屏
// #define LUAT_USE_EINK

//---------------------
// U8G2
// 单色屏, 支持i2c/spi
// #define LUAT_USE_DISP
// #define LUAT_USE_U8G2

/**************FONT*****************/
#define LUAT_USE_FONTS
/**********U8G2&LCD&EINK FONT*************/
#define USE_U8G2_OPPOSANSM_ENGLISH 1
#define USE_U8G2_OPPOSANSM8_CHINESE
#define USE_U8G2_OPPOSANSM10_CHINESE
#define USE_U8G2_OPPOSANSM12_CHINESE
#define USE_U8G2_OPPOSANSM16_CHINESE
// #define USE_U8G2_OPPOSANSM24_CHINESE
// #define USE_U8G2_OPPOSANSM32_CHINESE
// SARASA
#define USE_U8G2_SARASA_ENGLISH
#define USE_U8G2_SARASA_M8_CHINESE
#define USE_U8G2_SARASA_M10_CHINESE
#define USE_U8G2_SARASA_M12_CHINESE
#define USE_U8G2_SARASA_M14_CHINESE
#define USE_U8G2_SARASA_M16_CHINESE
// #define USE_U8G2_SARASA_M18_CHINESE
// #define USE_U8G2_SARASA_M20_CHINESE
// #define USE_U8G2_SARASA_M22_CHINESE
// #define USE_U8G2_SARASA_M24_CHINESE
// #define USE_U8G2_SARASA_M26_CHINESE
// #define USE_U8G2_SARASA_M28_CHINESE
/**********LVGL FONT*************/
#define LV_FONT_OPPOSANS_M_8
#define LV_FONT_OPPOSANS_M_10
#define LV_FONT_OPPOSANS_M_12
#define LV_FONT_OPPOSANS_M_16

//---------------------
// LVGL
// 主推的UI库, 功能强大但API繁琐
#define LUAT_USE_LVGL 1

#define LUAT_USE_LVGL_INDEV 1 // 输入设备

#define LUAT_USE_LVGL_ARC //圆弧 无依赖
#define LUAT_USE_LVGL_BAR //进度条 无依赖
#define LUAT_USE_LVGL_BTN //按钮 依赖容器CONT
#define LUAT_USE_LVGL_BTNMATRIX //按钮矩阵 无依赖
#define LUAT_USE_LVGL_CALENDAR //日历 无依赖
#define LUAT_USE_LVGL_CANVAS //画布 依赖图片IMG
#define LUAT_USE_LVGL_CHECKBOX //复选框 依赖按钮BTN 标签LABEL
#define LUAT_USE_LVGL_CHART //图表 无依赖
#define LUAT_USE_LVGL_CONT //容器 无依赖
#define LUAT_USE_LVGL_CPICKER //颜色选择器 无依赖
#define LUAT_USE_LVGL_DROPDOWN //下拉列表 依赖页面PAGE 标签LABEL
#define LUAT_USE_LVGL_GAUGE //仪表 依赖进度条BAR 仪表(弧形刻度)LINEMETER
#define LUAT_USE_LVGL_IMG //图片 依赖标签LABEL
#define LUAT_USE_LVGL_IMGBTN //图片按钮 依赖按钮BTN
#define LUAT_USE_LVGL_KEYBOARD //键盘 依赖图片按钮IMGBTN
#define LUAT_USE_LVGL_LABEL //标签 无依赖
#define LUAT_USE_LVGL_LED //LED 无依赖
#define LUAT_USE_LVGL_LINE //线 无依赖
#define LUAT_USE_LVGL_LIST //列表 依赖页面PAGE 按钮BTN 标签LABEL
#define LUAT_USE_LVGL_LINEMETER //仪表(弧形刻度) 无依赖
#define LUAT_USE_LVGL_OBJMASK //对象蒙版 无依赖
#define LUAT_USE_LVGL_MSGBOX //消息框 依赖图片按钮IMGBTN 标签LABEL
#define LUAT_USE_LVGL_PAGE //页面 依赖容器CONT
#define LUAT_USE_LVGL_SPINNER //旋转器 依赖圆弧ARC 动画ANIM
#define LUAT_USE_LVGL_ROLLER //滚筒 无依赖
#define LUAT_USE_LVGL_SLIDER //滑杆 依赖进度条BAR
#define LUAT_USE_LVGL_SPINBOX //数字调整框 无依赖
#define LUAT_USE_LVGL_SWITCH //开关 依赖滑杆SLIDER
#define LUAT_USE_LVGL_TEXTAREA //文本框 依赖标签LABEL 页面PAGE
#define LUAT_USE_LVGL_TABLE //表格 依赖标签LABEL
#define LUAT_USE_LVGL_TABVIEW //页签 依赖页面PAGE 图片按钮IMGBTN
#define LUAT_USE_LVGL_TILEVIEW //平铺视图 依赖页面PAGE
#define LUAT_USE_LVGL_WIN //窗口 依赖容器CONT 按钮BTN 标签LABEL 图片IMG 页面PAGE
#endif

#endif
21 changes: 21 additions & 0 deletions include/luat_mock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef LUAT_MOCK_H
#define LUAT_MOCK_H

int luat_mock_init(const char* path);

#define MOCK_DISABLED (-0xFF)

typedef struct luat_mock_ctx
{
char key[128];
char* req_data;
size_t req_len;
char* resp_data;
size_t resp_len;
int resp_type;
int resp_code;
}luat_mock_ctx_t;

int luat_mock_call(luat_mock_ctx_t* ctx);

#endif
2 changes: 2 additions & 0 deletions include/luat_pcconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ void luat_pcconf_init(void);

void luat_pcconf_save(void);

void free_uv_handle(void* ptr);

#endif
File renamed without changes.
34 changes: 34 additions & 0 deletions port/driver/luat_i2c_pc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#include "luat_base.h"
#include "luat_i2c.h"

#define LUAT_LOG_TAG "luat.i2c"
#include "luat_log.h"

int luat_i2c_exist(int id) {
return id == 0;
}

int luat_i2c_setup(int id, int speed) {
return 0;
}

int luat_i2c_close(int id) {
return 0;
}

int luat_i2c_send(int id, int addr, void* buff, size_t len, uint8_t stop) {
return 0;
}

int luat_i2c_recv(int id, int addr, void* buff, size_t len) {
return 0;
}

int luat_i2c_transfer(int id, int addr, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len) {
return 0;
}

int luat_i2c_no_block_transfer(int id, int addr, uint8_t is_read, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len, uint16_t Toms, void *CB, void *pParam) {
return 0;
}
14 changes: 4 additions & 10 deletions port/luat_mcu_pc.c → port/driver/luat_mcu_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,18 @@ uint32_t luat_mcu_hz(void) {
return 1;
}

uint64_t uv_startup_ns;
uint64_t luat_mcu_tick64(void) {
uv_timespec64_t ts;
int ret = uv_clock_gettime(UV_CLOCK_MONOTONIC, &ts);
if (ret) {
return 0;
}
uint64_t tmp = ts.tv_sec * 1000000L + ts.tv_nsec;
uint64_t tmp2 = boot_ts.tv_sec * 1000000L + boot_ts.tv_nsec;
//LLOGD("tick64 %llu", tmp - tmp2);
return tmp - tmp2;
uint64_t ns = uv_hrtime();
return (ns - uv_startup_ns) / 1000;
}

int luat_mcu_us_period(void) {
return 1;
}

uint64_t luat_mcu_tick64_ms(void) {
return luat_mcu_tick64() / luat_mcu_us_period();
return luat_mcu_tick64() / 1000;
}

void luat_mcu_set_clk_source(uint8_t source_main, uint8_t source_32k, uint32_t delay) {
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 761496b

Please sign in to comment.