2021-08-09 11:17:02 +08:00
|
|
|
|
|
2021-08-14 15:07:34 +08:00
|
|
|
|
# 获取PikaScript
|
2021-08-17 21:47:11 +08:00
|
|
|
|
https://github.com/mimilib/pikascript/releases/download/v0.2.0/pikascript_v0.2.0.zip
|
2021-08-05 14:25:01 +08:00
|
|
|
|
# 1.简介
|
2021-08-14 15:08:28 +08:00
|
|
|
|
pikascript可以为mcu裸机c开发提供面向对象的脚本绑定。
|
2021-08-02 14:03:52 +08:00
|
|
|
|
|
2021-08-05 13:49:41 +08:00
|
|
|
|
支持裸机运行,可运行于内存20Kb以上的mcu中,如stm32f103c8t6,esp32。
|
2021-08-02 14:03:52 +08:00
|
|
|
|
|
2021-08-09 09:45:59 +08:00
|
|
|
|
官方支持api源码生成器
|
|
|
|
|
|
2021-08-17 21:40:01 +08:00
|
|
|
|
https://github.com/mimilib/pikascript-compiler-rust
|
2021-08-09 09:45:59 +08:00
|
|
|
|
|
2021-08-10 11:16:22 +08:00
|
|
|
|
支持跨平台,可在linux环境开发、测试内核。
|
2021-08-02 14:03:52 +08:00
|
|
|
|
|
2021-08-05 13:54:12 +08:00
|
|
|
|
开箱即用,零配置,仅使用C标准库,几乎不使用宏,几乎不使用全局变量。
|
|
|
|
|
|
|
|
|
|
完整的单元测试。
|
|
|
|
|
|
|
|
|
|
堆空间零占用,栈空间少量占用,内存信息可观测。
|
|
|
|
|
|
|
|
|
|
尽可能的结构清晰(尽我所能)。
|
2021-08-02 14:03:52 +08:00
|
|
|
|
|
2021-08-05 14:25:01 +08:00
|
|
|
|
# 2.STM32 例程仓库:
|
2021-08-14 22:14:53 +08:00
|
|
|
|
https://github.com/mimilib/pikascript-demo-stm32
|
2021-08-05 14:13:23 +08:00
|
|
|
|
|
2021-08-11 16:00:08 +08:00
|
|
|
|
stm32教程视频:https://www.bilibili.com/video/BV1mg411L72e
|
|
|
|
|
|
2021-08-05 14:25:01 +08:00
|
|
|
|
# 3.原理解析:
|
2021-08-05 14:20:07 +08:00
|
|
|
|
|
2021-08-05 15:06:52 +08:00
|
|
|
|
## 架构示意图
|
2021-08-02 14:03:52 +08:00
|
|
|
|
![K9C)%CZO)X`8VFBKCE8(9@W](https://user-images.githubusercontent.com/88232613/127806449-b476b2fd-9f40-4c53-94a0-e1e965c046c3.png)
|
|
|
|
|
|
2021-08-05 15:57:29 +08:00
|
|
|
|
## 内核源码
|
|
|
|
|
|
|
|
|
|
对象支持: https://github.com/mimilib/mimilib/tree/master/mimiObject
|
2021-08-05 15:57:45 +08:00
|
|
|
|
|
2021-08-05 15:57:29 +08:00
|
|
|
|
数据结构: https://github.com/mimilib/mimilib/tree/master/mimiData
|
|
|
|
|
|
2021-08-05 15:06:52 +08:00
|
|
|
|
## 解析文章
|
2021-08-05 14:20:07 +08:00
|
|
|
|
单片机运行python脚本,不移植micropython也行吗?
|
2021-08-05 14:20:23 +08:00
|
|
|
|
|
2021-08-05 14:20:07 +08:00
|
|
|
|
https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd
|
|
|
|
|
|
2021-08-05 15:06:52 +08:00
|
|
|
|
## 微信交流群
|
2021-08-05 14:23:22 +08:00
|
|
|
|
![image](https://user-images.githubusercontent.com/88232613/128301298-1bfbbecf-8199-416b-819b-0cdbb41d5b3a.png)
|
|
|
|
|
|
2021-08-05 15:06:52 +08:00
|
|
|
|
## 官方公众号
|
2021-08-05 14:23:22 +08:00
|
|
|
|
![image](https://user-images.githubusercontent.com/88232613/128301451-f0cdecea-6457-4925-b084-42e7796a856e.png)
|
|
|
|
|
|
2021-08-05 14:25:01 +08:00
|
|
|
|
# 4.内核测试与开发
|
2021-08-05 14:23:22 +08:00
|
|
|
|
|
2021-08-05 14:18:07 +08:00
|
|
|
|
## windows下测试mimiscript内核:
|
2021-08-04 18:50:24 +08:00
|
|
|
|
|
|
|
|
|
step1: 下载源码
|
|
|
|
|
```
|
|
|
|
|
https://github.com/mimilib/mimiscript/releases/download/v1.0/mimiscript-v1.0.zip
|
|
|
|
|
```
|
|
|
|
|
step2: 下载安装codeblocks
|
|
|
|
|
```
|
|
|
|
|
https://download.fosshub.com/Protected/expiretime=1628119786;badurl=aHR0cHM6Ly93d3cuZm9zc2h1Yi5jb20vQ29kZS1CbG9ja3MuaHRtbA==/9bc1258414546cedb7b0774846ec773613a89ed715964c9a3239fab0465f014d/5b85805cf9ee5a5c3e979f1b/5e80624f7d74bb810359a46c/codeblocks-20.03-setup.exe
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-04 18:50:51 +08:00
|
|
|
|
step3: 打开winproject文件夹下的demoXX/demoXX.cbs编译运行
|
|
|
|
|
|
|
|
|
|
|
2021-08-05 14:18:07 +08:00
|
|
|
|
## linux下测试mimiscript内核(推荐ubuntu20.04):
|
2021-08-03 22:47:42 +08:00
|
|
|
|
|
|
|
|
|
step1: 拉取项目
|
|
|
|
|
``` shell
|
|
|
|
|
git clone https://github.com/mimilib/mimiscript
|
|
|
|
|
cd mimiscript
|
|
|
|
|
git submodule init && git submodule update
|
|
|
|
|
```
|
|
|
|
|
step2: 安装编译链
|
|
|
|
|
``` shell
|
|
|
|
|
sudo apt update
|
|
|
|
|
sudo apt install -y clang llvm cmake zlib1g-dev
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
step3: 编译项目
|
|
|
|
|
```
|
|
|
|
|
cd mimiproject
|
|
|
|
|
sh init.sh # 第一次编译前运行,之后就不用运行了
|
|
|
|
|
sh make.sh # 编译项目
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
step4: 运行demo
|
|
|
|
|
``` shell
|
|
|
|
|
bin/demo01-led.bin
|
|
|
|
|
```
|
2021-08-04 18:48:26 +08:00
|
|
|
|
|
2021-08-04 18:51:24 +08:00
|
|
|
|
## 用法示例:
|
2021-08-02 14:03:52 +08:00
|
|
|
|
``` c
|
|
|
|
|
#include "sysObj.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
被绑定的方法
|
|
|
|
|
self 是对象指针,指向执行方法的对象
|
|
|
|
|
args 是参数列表,用于传入传出参数
|
|
|
|
|
(所有被绑定的方法均使用此形参)
|
|
|
|
|
*/
|
|
|
|
|
void add(MimiObj *self, Args *args)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
参数传递
|
|
|
|
|
从参数列表中取出输入参数val1和val2
|
|
|
|
|
*/
|
|
|
|
|
int val1 = args_getInt(args, "val1");
|
|
|
|
|
int val2 = args_getInt(args, "val2");
|
|
|
|
|
|
|
|
|
|
/* 实现方法的功能 */
|
|
|
|
|
int res = val1 + val2;
|
|
|
|
|
|
|
|
|
|
/* 将返回值传回参数列表 */
|
|
|
|
|
method_returnInt(args, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
定义测试类的构造器,一个构造器对应一个类
|
|
|
|
|
通过构造器即可新建对象
|
|
|
|
|
args是构造器的初始化参数列表
|
|
|
|
|
MimiObj*是新建对象的指针
|
|
|
|
|
(所有构造器均使用此形参)
|
|
|
|
|
*/
|
|
|
|
|
MimiObj *New_MimiObj_test(Args *args)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
继承sys类
|
|
|
|
|
只需要直接调用父类的构造器即可
|
|
|
|
|
*/
|
|
|
|
|
MimiObj *self = New_MimiObj_sys(args);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
为test类绑定一个方法(支持重载)
|
|
|
|
|
1.入口参数self:对象指针,指向当前对象
|
|
|
|
|
2.传入的第二参数是被绑定方法的接口定义
|
|
|
|
|
(此处使用typescript语法,简单的修改即可支持python格式)
|
|
|
|
|
3.传入的第三个参数是被绑定方法的函数指针
|
|
|
|
|
*/
|
|
|
|
|
class_defineMethod(self, "add(val1:int, val2:int):int", add);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 返回对象 */
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
新建根对象,对象名为“sys”
|
|
|
|
|
传入对象名和构造器的函数指针
|
|
|
|
|
*/
|
|
|
|
|
MimiObj *sys = newRootObj("sys", New_MimiObj_sys);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
新建test对象
|
|
|
|
|
test对象作为子对象挂载在sys对象下(对象树)
|
|
|
|
|
*/
|
|
|
|
|
obj_newObj(sys, "test", New_MimiObj_test);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
运行单行脚本。
|
|
|
|
|
因为test对象挂在在sys对象下,
|
|
|
|
|
因此可以通过test.add调用test对象的方法
|
|
|
|
|
运行后会动态新建res属性,该属性属于sys对象
|
|
|
|
|
*/
|
|
|
|
|
obj_run(sys, "res = test.add(val1 = 1, val2 = 2)");
|
|
|
|
|
/*
|
|
|
|
|
(也支持 "res = test.add(1, 2)"的调用方式)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* 从sys对象中取出属性值res */
|
|
|
|
|
int res = obj_getInt(sys, "res");
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
析构对象
|
|
|
|
|
所有挂载在sys对象下的子对象都会被自动析构
|
|
|
|
|
本例中挂载了test对象,因此在析构sys对象前,
|
|
|
|
|
test对象会被自动析构
|
|
|
|
|
*/
|
|
|
|
|
obj_deinit(sys);
|
|
|
|
|
|
|
|
|
|
/* 打印返回值 res = 3*/
|
|
|
|
|
printf("%d\r\n", res);
|
|
|
|
|
}
|
|
|
|
|
```
|
2021-08-06 13:41:41 +08:00
|
|
|
|
# 5. mimiscript-compiler
|
|
|
|
|
将pyton编译为mimiscript的C源码
|