This commit is contained in:
pikastech 2021-11-09 21:36:59 +08:00
commit 17492271a1
25 changed files with 262 additions and 212 deletions

View File

@ -24,8 +24,10 @@ jobs:
- name: PULL_CORE
run: cd ${{github.workspace}}/port/linux && bash pull-core.sh
- name: INIT
- name: CHMOD
run: cd ${{github.workspace}}/port/linux/package/pikascript && chmod +x ./rust-msc-latest-linux
- name: INIT
run: cd ${{github.workspace}}/port/linux && bash init.sh
- name: TEST

View File

@ -31,6 +31,20 @@ It's very easy to bind C function to python module with the help of Pika Pre-com
3. Released modules[packages.toml](packages.toml)
# Document
[1. PikaScript-Quick start within 3 minutes](document/1.三分钟快速上手.md)
[2. PikaScript-Architecture and principle](https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd)
[3. PikaScript-Deploy within 10 minutes](document/2.十分钟快速部署.md)
[4. PikaScript-Standard develop workflow](document/3.PikaScript标准开发流程.md)
[5. PikaScript-Demo show](document/5.我就要用最便宜的单片机来跑python还要用Keil开发怎么地吧.md)
[6. Arm-2D simulation](document/6.用Python玩ARM%202D认真的嘛.md)
## Folders
[src](../../tree/master/src) - core code
@ -117,20 +131,6 @@ Readability first, nearly never use macro function and global argument.
Complete unit testes based on google test.
### (5)Document
[1. PikaScript-Quick start within 3 minutes](document/1.三分钟快速上手.md)
[2. PikaScript-Architecture and principle](https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd)
[3. PikaScript-Deploy within 10 minutes](document/2.十分钟快速部署.md)
[4. PikaScript-Standard develop workflow](document/3.PikaScript标准开发流程.md)
[5. PikaScript-Demo show](document/5.我就要用最便宜的单片机来跑python还要用Keil开发怎么地吧.md)
[6. Arm-2D simulation](document/6.用Python玩ARM%202D认真的嘛.md)
# 4.Both talk and show the code
## E-mail: liang6516@outlook.com

View File

@ -17,12 +17,24 @@ PikaScript是一个完全重写的超轻量级python引擎零依赖零配
![image](https://user-images.githubusercontent.com/88232613/138021445-13643518-b0a3-4872-a290-5dec27697837.png)
# 获取PikaScript:
## 使用Pika包管理器[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe)
1. 直接运行[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动下载并更新pikaScript主仓库(文件在当前磁盘的/tmp/pikaScript文件夹)
2. 将[requestment.txt](/bsp/stm32g030c8/pikascript/requestment.txt)放在[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe)同一文件夹下, 运行[pikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动在当前目录下安装[内核](../../tree/master/src)、[预编译器](../../tree/master/tools/pikaCompiler)与[模块](../../tree/master/package)。
3. 已发布的模块列表:[packages.toml](/packages.toml)
# 视频教程
## 入门篇 - 面向单片机Python编程用户
[PikaScript入门-单片机python编程和环境配置](https://www.bilibili.com/video/BV1mg411L72e)
[Pika派开发板手把手单片机python编程01——模块安装和GPIO类](https://www.bilibili.com/video/BV1kg411K7W2)
## 中级篇 - 面向驱动开发者
[PikaScript中级 RISC-V部署PikaScript CH32V103R8](https://www.bilibili.com/video/BV1Cq4y1G7Tj)
@ -43,15 +55,19 @@ PikaScript是一个完全重写的超轻量级python引擎零依赖零配
[PikaScript进阶-数据结构源码精讲](https://www.bilibili.com/video/BV1Ky4y157nW/)
# 获取PikaScript:
# 开发手册
## 使用Pika包管理器[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe)
[1. PikaScript-三分钟快速上手](document/1.三分钟快速上手.md)
1. 直接运行[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动下载并更新pikaScript主仓库(文件在当前磁盘的/tmp/pikaScript文件夹)
[2. PikaScript-架构与原理](https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd)
2. 将[requestment.txt](/bsp/stm32g030c8/pikascript/requestment.txt)放在[PikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe)同一文件夹下, 运行[pikaPackage.exe](../../raw/master/tools/pikaPackageManager/pikaPackage.exe), 自动在当前目录下安装[内核](../../tree/master/src)、[预编译器](../../tree/master/tools/pikaCompiler)与[模块](../../tree/master/package)。
[3. PikaScript-十分钟快速部署](document/2.十分钟快速部署.md)
3. 已发布的模块列表:[packages.toml](/packages.toml)
[4. PikaScript-标准开发流程](document/3.PikaScript标准开发流程.md)
[5. PikaScript-Demo展示](document/5.我就要用最便宜的单片机来跑python还要用Keil开发怎么地吧.md)
[6. Arm-2D GUI引擎和pikascript联合仿真](document/6.用Python玩ARM%202D认真的嘛.md)
## 文件目录
[src](../../tree/master/src) - 内核源码
@ -139,24 +155,6 @@ PikaScript是一个完全重写的超轻量级python引擎零依赖零配
完整的googletest单元测试。
### (5)stm32例程
[pikascript-stm32-demo](../../tree/master/bsp)
### (6)开发手册
[1. PikaScript-三分钟快速上手](document/1.三分钟快速上手.md)
[2. PikaScript-架构与原理](https://mp.weixin.qq.com/s?__biz=MzU4NzUzMDc1OA==&mid=2247484127&idx=1&sn=f66cff49c488e48c52570c7bb570328f&chksm=fdebd5b6ca9c5ca0707fd221c32f3ad63e94aeb6f917a92774b89ea042381ea261990f5cca3c&token=2045971639&lang=zh_CN#rd)
[3. PikaScript-十分钟快速部署](document/2.十分钟快速部署.md)
[4. PikaScript-标准开发流程](document/3.PikaScript标准开发流程.md)
[5. PikaScript-Demo展示](document/5.我就要用最便宜的单片机来跑python还要用Keil开发怎么地吧.md)
[6. Arm-2D GUI引擎和pikascript联合仿真](document/6.用Python玩ARM%202D认真的嘛.md)
# 4.交流与技术支持:
## 微信交流群

View File

@ -138,7 +138,7 @@
<DriverSelection>4101</DriverSelection>
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2V8M.DLL</Flash2>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3></Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>

View File

@ -1,5 +1,5 @@
pikascript-core==v1.1.1
PikaStdLib==v1.1.0
CH32V103R8Booter==v1.0.0
PikaStdDevice==latest
PikaStdDevice==v1.4.1
CH32V103==latest

View File

@ -1,6 +1,6 @@
pikascript-core==v0.9.0
PikaStdLib==latest
PikaStdDevice==latest
PikaStdLib==v1.1.0
PikaStdDevice==v1.4.1
STM32==v1.1.1
PikaMath==v1.0.0
PikaRunExternControl==v1.0.0

View File

@ -10,6 +10,7 @@
<TargetName>stm32g030c8</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pArmCC>6160000::V6.16::ARMCLANG</pArmCC>
<pCCUsed>6160000::V6.16::ARMCLANG</pCCUsed>
<uAC6>1</uAC6>
<TargetOption>

View File

@ -1,6 +1,6 @@
pikascript-core==v1.1.3
pikascript-core==v1.2.0
PikaStdLib==v1.1.0
PikaStdDevice==v1.4.1
STM32==v1.4.1
PikaStdDevice==latest
STM32==latest
PikaPiZero==latest
STM32G030Booter==latest

View File

@ -1,6 +1,6 @@
pikascript-core==v0.9.0
PikaStdLib==latest
PikaStdDevice==latest
PikaStdLib==v1.1.0
PikaStdDevice==v1.4.1
STM32==v1.1.1
PikaMath==v1.0.0
PikaRunExternControl==v1.0.0

View File

@ -3,7 +3,6 @@ import PikaPiZero
import PikaStdLib
time = STM32.Time()
uart = STM32.UART()
adc = STM32.ADC()
pin = STM32.GPIO()
pwm = STM32.PWM()
@ -11,11 +10,6 @@ uart = STM32.UART()
rgb = PikaPiZero.RGB()
mem = PikaStdLib.MemChecker()
uart.init()
uart.setId(1)
uart.setBaudRate(115200)
uart.enable()
rgb.init()
rgb.enable()

View File

@ -4,8 +4,8 @@ import STM32
time = STM32.Time()
uart = STM32.UART()
uart.init()
uart.setBaudRate(115200)
uart.setId(1)
uart.setBaudRate(115200)
uart.enable()
while True:

View File

@ -39,7 +39,7 @@ void PikaStdDevice_GPIO_high(PikaObj* self) {
}
int PikaStdDevice_GPIO_read(PikaObj *self){
obj_run(self, "readBuff = platformRead()");
obj_run(self, "platformRead()");
return obj_getInt(self, "readBuff");
}
@ -62,7 +62,7 @@ void PikaStdDevice_GPIO_setPull(PikaObj *self, char * pull){
}
}
void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) {
void PikaStdDevice_GPIO_setPin(PikaObj* self, char *pinName) {
obj_setStr(self, "pin", pinName);
}
@ -85,7 +85,7 @@ void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self, char* mode) {
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
@ -100,8 +100,7 @@ void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
obj_setSysOut(self, "[error] platform method need to be override.");
}
int PikaStdDevice_GPIO_platformRead(PikaObj *self){
void PikaStdDevice_GPIO_platformRead(PikaObj *self){
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
return -1;
}

View File

@ -52,11 +52,11 @@ class GPIO(TinyObj):
pass
# need override
def platformSetMode(mode: str):
def platformSetMode():
pass
# need override
def platformRead()->int:
def platformRead():
pass
@ -84,11 +84,11 @@ class ADC(TinyObj):
pass
# need override
def platformEnable(pin: str):
def platformEnable():
pass
# need override
def platformRead(pin: str) -> float:
def platformRead():
pass
@ -112,15 +112,15 @@ class UART(TinyObj):
pass
# need override
def platformEnable(id: int, baudRate: int):
def platformEnable():
pass
# need override
def platformWrite(id: int, data: str):
def platformWrite():
pass
# need override
def platformRead(id: int, length: int) -> str:
def platformRead():
pass
@ -151,11 +151,11 @@ class IIC(TinyObj):
pass
# need override
def platformWrite(addr: int, data: str):
def platformWrite():
pass
# need override
def platformRead(addr: int, length: int) -> str:
def platformRead():
pass
@ -182,13 +182,13 @@ class PWM(TinyObj):
pass
# need override
def platformEnable(pin: str, freq: int, duty: float):
def platformEnable():
pass
# need override
def platformSetFrequency(pin: str, freq: int):
def platformSetFrequency():
pass
# need override
def platformSetDuty(pin: str, duty: float):
def platformSetDuty():
pass

View File

@ -2,7 +2,7 @@
#include "BaseObj.h"
void PikaStdDevice_ADC_enable(PikaObj* self) {
obj_run(self, "platformEnable(pin)");
obj_run(self, "platformEnable()");
}
void PikaStdDevice_ADC_init(PikaObj* self) {
@ -10,21 +10,20 @@ void PikaStdDevice_ADC_init(PikaObj* self) {
}
float PikaStdDevice_ADC_read(PikaObj* self) {
obj_run(self, "val = platformRead(pin)");
obj_run(self, "platformRead()");
return obj_getFloat(self, "val");
}
void PikaStdDevice_ADC_setPin(PikaObj* self, char* pin) {
void PikaStdDevice_ADC_setPin(PikaObj* self, char *pin) {
obj_setStr(self, "pin", pin);
}
void PikaStdDevice_ADC_platformEnable(PikaObj* self, char* pin) {
void PikaStdDevice_ADC_platformEnable(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
float PikaStdDevice_ADC_platformRead(PikaObj* self, char* pin) {
void PikaStdDevice_ADC_platformRead(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
return -1;
}

View File

@ -26,17 +26,17 @@ void PikaStdDevice_IIC_setPinSDA(PikaObj *self, char * pin){
void PikaStdDevice_IIC_write(PikaObj *self, int addr, char * data){
obj_setStr(self, "writeData", data);
obj_setInt(self, "writeAddr", addr);
obj_run(self, "platformWrite(writeAddr, writeData)");
obj_run(self, "platformWrite()");
}
char * PikaStdDevice_IIC_read(PikaObj *self, int addr, int length){
obj_setInt(self, "length", length);
obj_setInt(self, "readAddr", addr);
obj_run(self, "readData = platformRead(readAddr, length)");
obj_run(self, "platformRead()");
return obj_getStr(self, "readData");
}
void PikaStdDevice_IIC_platformWrite(PikaObj *self, int addr, char * data){
void PikaStdDevice_IIC_platformWrite(PikaObj *self){
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
@ -46,8 +46,7 @@ void PikaStdDevice_IIC_platformEnable(PikaObj *self){
obj_setSysOut(self, "[error] platform method need to be override.");
}
char * PikaStdDevice_IIC_platformRead(PikaObj *self, int addr, int length){
void PikaStdDevice_IIC_platformRead(PikaObj *self){
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
return NULL;
}

View File

@ -13,16 +13,16 @@ void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) {
void PikaStdDevice_PWM_setFrequency(PikaObj* self, int freq) {
obj_setInt(self, "freq", freq);
obj_run(self, "platformSetFrequency(pin, freq)");
obj_run(self, "platformSetFrequency()");
}
void PikaStdDevice_PWM_setDuty(PikaObj* self, float duty) {
obj_setFloat(self, "duty", duty);
obj_run(self, "platformSetDuty(pin, duty)");
obj_run(self, "platformSetDuty()");
}
void PikaStdDevice_PWM_enable(PikaObj* self) {
obj_run(self, "platformEnable(pin, freq, duty)");
obj_run(self, "platformEnable()");
}
float PikaStdDevice_PWM_getDuty(PikaObj* self) {
@ -33,20 +33,15 @@ int PikaStdDevice_PWM_getFrequency(PikaObj* self) {
return obj_getInt(self, "freq");
}
void PikaStdDevice_PWM_platformEnable(PikaObj* self,
float dute,
int freq,
char* pin) {
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) {
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self,
int freq,
char* pin) {
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}

View File

@ -2,7 +2,7 @@
#include "BaseObj.h"
void PikaStdDevice_UART_enable(PikaObj* self) {
obj_run(self, "platformEnable(id, baudRate)");
obj_run(self, "platformEnable()");
}
void PikaStdDevice_UART_init(PikaObj* self) {
obj_setInt(self, "baudRate", 115200);
@ -11,7 +11,7 @@ void PikaStdDevice_UART_init(PikaObj* self) {
}
char* PikaStdDevice_UART_read(PikaObj* self, int length) {
obj_setInt(self, "length", length);
obj_run(self, "readData = platformRead(id, length)");
obj_run(self, "platformRead()");
return obj_getStr(self, "readData");
}
void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) {
@ -22,19 +22,18 @@ void PikaStdDevice_UART_setId(PikaObj* self, int id) {
}
void PikaStdDevice_UART_write(PikaObj* self, char* data) {
obj_setStr(self, "writeData", data);
obj_run(self, "platformWrite(id, writeData)");
obj_run(self, "platformWrite()");
}
void PikaStdDevice_UART_platformEnable(PikaObj* self, int baudRate, int id) {
void PikaStdDevice_UART_platformEnable(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
char* PikaStdDevice_UART_platformRead(PikaObj* self, int id, int length) {
void PikaStdDevice_UART_platformRead(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
return NULL;
}
void PikaStdDevice_UART_platformWrite(PikaObj* self, char* data, int id) {
void PikaStdDevice_UART_platformWrite(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}

View File

@ -20,11 +20,11 @@ class GPIO(PikaStdDevice.GPIO):
pass
# override
def platformSetMode(mode: str):
def platformSetMode():
pass
# override
def platformRead() -> int:
def platformRead():
pass
@ -40,39 +40,39 @@ class Time(PikaStdDevice.Time):
class ADC(PikaStdDevice.ADC):
# override
def platformEnable(pin: str):
def platformEnable():
pass
# override
def platformRead(pin: str) -> float:
def platformRead():
pass
class UART(PikaStdDevice.UART):
# override
def platformEnable(id: int, baudRate: int):
def platformEnable():
pass
# override
def platformWrite(id: int, data: str):
def platformWrite():
pass
# override
def platformRead(id: int, length: int) -> str:
def platformRead():
pass
class PWM(PikaStdDevice.PWM):
# override
def platformEnable(pin: str, freq: int, duty: float):
def platformEnable():
pass
# override
def platformSetFrequency(pin: str, freq: int):
def platformSetFrequency():
pass
# override
def platformSetDuty(pin: str, duty: float):
def platformSetDuty():
pass
@ -85,11 +85,11 @@ class IIC(PikaStdDevice.IIC):
pass
# override
def platformWrite(addr: int, data: str):
def platformWrite():
pass
# override
def platformRead(addr: int, length: int) -> str:
def platformRead():
pass

View File

@ -22,7 +22,8 @@ uint16_t Get_Adc(ADC_HandleTypeDef* hadc, uint32_t ch) {
return (uint16_t)HAL_ADC_GetValue(hadc);
}
void STM32_ADC_platformEnable(PikaObj* self, char* pin) {
void STM32_ADC_platformEnable(PikaObj* self) {
char *pin = obj_getStr(self, "pin");
if (!strIsStartWith(pin, "PA")) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match adc pin.");
@ -162,6 +163,7 @@ exit:
return channel;
}
float STM32_ADC_platformRead(PikaObj* self, char* pin) {
return 3.3f * Get_Adc(&pika_hadc1, getChannel(pin)) / 4096.0f;
void STM32_ADC_platformRead(PikaObj* self) {
char *pin = obj_getStr(self, "pin");
obj_setFloat(self, "val", 3.3f * Get_Adc(&pika_hadc1, getChannel(pin)) / 4096.0f);
}

View File

@ -105,9 +105,9 @@ void STM32_GPIO_platformHigh(PikaObj* self) {
}
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
}
void STM32_GPIO_platformSetMode(PikaObj* self, char* mode) {
void STM32_GPIO_platformSetMode(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
char *mode = obj_getStr(self, "mode");
if (0 != enableClk(pin)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
@ -142,7 +142,7 @@ void STM32_GPIO_platformSetMode(PikaObj* self, char* mode) {
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
}
int STM32_GPIO_platformRead(PikaObj *self){
void STM32_GPIO_platformRead(PikaObj *self){
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
@ -154,7 +154,7 @@ int STM32_GPIO_platformRead(PikaObj *self){
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
return HAL_GPIO_ReadPin(gpioPort,gpioPin);
obj_setInt(self, "readBuff", HAL_GPIO_ReadPin(gpioPort,gpioPin));
}
int STM32_lowLevel_readPin(PikaObj *self, char * pin){

View File

@ -1,35 +1,34 @@
#include "STM32_IIC.h"
#include <stdint.h>
#include "BaseObj.h"
#include "STM32_common.h"
#include "STM32_GPIO.h"
#include "STM32_common.h"
#include "dataStrs.h"
typedef struct pika_IIC_info_t{
GPIO_TypeDef *SCL_GPIO;
GPIO_TypeDef *SDA_GPIO;
typedef struct pika_IIC_info_t {
GPIO_TypeDef* SCL_GPIO;
GPIO_TypeDef* SDA_GPIO;
uint32_t SCL_GPIO_Pin;
uint32_t SDA_GPIO_Pin;
uint8_t deviceAddr;
uint8_t readBuff[32];
}pika_IIC_info;
uint8_t readBuff[32];
} pika_IIC_info;
#define delay_rate 1
void SDA_OUT(pika_IIC_info *iic){
void SDA_OUT(pika_IIC_info* iic) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO*/
GPIO_InitStruct.Pin = iic->SDA_GPIO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP ;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(iic->SDA_GPIO, &GPIO_InitStruct);
}
void SDA_IN(pika_IIC_info *iic){
void SDA_IN(pika_IIC_info* iic) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO*/
GPIO_InitStruct.Pin = iic->SDA_GPIO_Pin;
@ -39,31 +38,31 @@ void SDA_IN(pika_IIC_info *iic){
HAL_GPIO_Init(iic->SDA_GPIO, &GPIO_InitStruct);
}
void IIC_SDA_high(pika_IIC_info *iic){
void IIC_SDA_high(pika_IIC_info* iic) {
HAL_GPIO_WritePin(iic->SDA_GPIO, iic->SDA_GPIO_Pin, GPIO_PIN_SET);
}
void IIC_SDA_low(pika_IIC_info *iic){
void IIC_SDA_low(pika_IIC_info* iic) {
HAL_GPIO_WritePin(iic->SDA_GPIO, iic->SDA_GPIO_Pin, GPIO_PIN_RESET);
}
void IIC_SCL_high(pika_IIC_info *iic){
void IIC_SCL_high(pika_IIC_info* iic) {
HAL_GPIO_WritePin(iic->SCL_GPIO, iic->SCL_GPIO_Pin, GPIO_PIN_SET);
}
void IIC_SCL_low(pika_IIC_info *iic){
void IIC_SCL_low(pika_IIC_info* iic) {
HAL_GPIO_WritePin(iic->SCL_GPIO, iic->SCL_GPIO_Pin, GPIO_PIN_RESET);
}
uint8_t READ_SDA(pika_IIC_info *iic){
uint8_t READ_SDA(pika_IIC_info* iic) {
return HAL_GPIO_ReadPin(iic->SDA_GPIO, iic->SDA_GPIO_Pin);
}
void WRITE_SDA(pika_IIC_info *iic, uint8_t data){
void WRITE_SDA(pika_IIC_info* iic, uint8_t data) {
HAL_GPIO_WritePin(iic->SDA_GPIO, iic->SDA_GPIO_Pin, data);
}
void IIC_Start(pika_IIC_info *iic) {
void IIC_Start(pika_IIC_info* iic) {
SDA_OUT(iic);
IIC_SDA_high(iic);
IIC_SCL_high(iic);
@ -73,7 +72,7 @@ void IIC_Start(pika_IIC_info *iic) {
IIC_SCL_low(iic);
}
void IIC_Stop(pika_IIC_info *iic) {
void IIC_Stop(pika_IIC_info* iic) {
SDA_OUT(iic);
IIC_SCL_low(iic);
IIC_SDA_low(iic);
@ -83,7 +82,7 @@ void IIC_Stop(pika_IIC_info *iic) {
delay_us(delay_rate * 4);
}
uint8_t IIC_Wait_Ack(pika_IIC_info *iic) {
uint8_t IIC_Wait_Ack(pika_IIC_info* iic) {
uint8_t ucErrTime = 0;
SDA_IN(iic);
@ -102,7 +101,7 @@ uint8_t IIC_Wait_Ack(pika_IIC_info *iic) {
return 0;
}
void IIC_Ack(pika_IIC_info *iic) {
void IIC_Ack(pika_IIC_info* iic) {
IIC_SCL_low(iic);
SDA_OUT(iic);
@ -113,7 +112,7 @@ void IIC_Ack(pika_IIC_info *iic) {
IIC_SCL_low(iic);
}
void IIC_NAck(pika_IIC_info *iic) {
void IIC_NAck(pika_IIC_info* iic) {
IIC_SCL_low(iic);
SDA_OUT(iic);
@ -124,7 +123,7 @@ void IIC_NAck(pika_IIC_info *iic) {
IIC_SCL_low(iic);
}
void IIC_Send_Byte(pika_IIC_info *iic, uint8_t txd) {
void IIC_Send_Byte(pika_IIC_info* iic, uint8_t txd) {
uint8_t t;
SDA_OUT(iic);
@ -140,7 +139,7 @@ void IIC_Send_Byte(pika_IIC_info *iic, uint8_t txd) {
}
}
uint8_t IIC_Read_Byte(pika_IIC_info *iic, unsigned char ack) {
uint8_t IIC_Read_Byte(pika_IIC_info* iic, unsigned char ack) {
unsigned char i, receive = 0;
SDA_IN(iic);
@ -160,7 +159,11 @@ uint8_t IIC_Read_Byte(pika_IIC_info *iic, unsigned char ack) {
return receive;
}
uint8_t MPU_Write_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len, uint8_t* buf) {
uint8_t MPU_Write_Len(pika_IIC_info* iic,
uint8_t addr,
uint8_t reg,
uint8_t len,
uint8_t* buf) {
uint8_t i;
IIC_Start(iic);
IIC_Send_Byte(iic, (addr << 1) | 0);
@ -181,7 +184,11 @@ uint8_t MPU_Write_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len
return 0;
}
uint8_t MPU_Read_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len, uint8_t* buf) {
uint8_t MPU_Read_Len(pika_IIC_info* iic,
uint8_t addr,
uint8_t reg,
uint8_t len,
uint8_t* buf) {
IIC_Start(iic);
IIC_Send_Byte(iic, (addr << 1) | 0);
if (IIC_Wait_Ack(iic)) {
@ -205,7 +212,7 @@ uint8_t MPU_Read_Len(pika_IIC_info *iic, uint8_t addr, uint8_t reg, uint8_t len,
return 0;
}
void STM32_IIC_platformEnable(PikaObj *self){
void STM32_IIC_platformEnable(PikaObj* self) {
obj_run(self, "SCL.init()");
obj_run(self, "SDA.init()");
obj_run(self, "SCL.setPin(SCLpin)");
@ -216,13 +223,13 @@ void STM32_IIC_platformEnable(PikaObj *self){
obj_run(self, "SDA.enable()");
obj_run(self, "SCL.low()");
obj_run(self, "SDA.low()");
char *SCLpin = obj_getStr(self, "SCLpin");
char *SDApin = obj_getStr(self, "SDApin");
char* SCLpin = obj_getStr(self, "SCLpin");
char* SDApin = obj_getStr(self, "SDApin");
uint8_t deviceAddr = obj_getInt(self, "deviceAddr");
pika_IIC_info *iic = obj_getPtr(self, "iic");
if(NULL == iic){
iic = pikaMalloc(sizeof(pika_IIC_info));
pika_IIC_info* iic = obj_getPtr(self, "iic");
if (NULL == iic) {
iic = pikaMalloc(sizeof(pika_IIC_info));
obj_setPtr(self, "iic", iic);
}
iic->SDA_GPIO = getGpioPort(SDApin);
@ -233,15 +240,19 @@ void STM32_IIC_platformEnable(PikaObj *self){
SDA_OUT(iic);
}
char * STM32_IIC_platformRead(PikaObj *self, int addr, int length){
pika_IIC_info *iic = obj_getPtr(self, "iic");
MPU_Read_Len(iic, iic->deviceAddr, addr, length,(uint8_t *) iic->readBuff);
return (char *)iic->readBuff;
void STM32_IIC_platformRead(PikaObj* self) {
int addr = obj_getInt(self, "addr");
int length = obj_getInt(self, "length");
pika_IIC_info* iic = obj_getPtr(self, "iic");
MPU_Read_Len(iic, iic->deviceAddr, addr, length, (uint8_t*)iic->readBuff);
obj_setStr(self, "readData", (char*)iic->readBuff);
}
void STM32_IIC_platformWrite(PikaObj *self, int addr, char * data){
pika_IIC_info *iic = obj_getPtr(self, "iic");
void STM32_IIC_platformWrite(PikaObj* self) {
int addr = obj_getInt(self, "addr");
char* data = obj_getStr(self, "data");
pika_IIC_info* iic = obj_getPtr(self, "iic");
MPU_Write_Len(iic, iic->deviceAddr, addr, strGetSize(data), (uint8_t *)data);
MPU_Write_Len(iic, iic->deviceAddr, addr, strGetSize(data), (uint8_t*)data);
}

View File

@ -230,7 +230,10 @@ uint32_t getTimChennel(char* pin) {
return 99999;
}
void STM32_PWM_platformEnable(PikaObj* self, float duty, int freq, char* pin) {
void STM32_PWM_platformEnable(PikaObj* self) {
float duty = obj_getFloat(self, "duty");
int freq = obj_getInt(self, "freq");
char *pin = obj_getStr(self, "pin");
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
@ -334,7 +337,9 @@ void STM32_PWM_platformEnable(PikaObj* self, float duty, int freq, char* pin) {
HAL_TIM_PWM_Start(pika_tim, getTimChennel(pin));
}
void STM32_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) {
void STM32_PWM_platformSetDuty(PikaObj* self) {
float duty = obj_getFloat(self, "duty");
char *pin = obj_getStr(self, "pin");
TIM_HandleTypeDef* pika_tim = getTimHandle(pin);
if (NULL == pika_tim) {
obj_setSysOut(self, "[error]: can not found PWM hardware.");
@ -348,7 +353,9 @@ void STM32_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) {
}
}
void STM32_PWM_platformSetFrequency(PikaObj* self, int freq, char* pin) {
void STM32_PWM_platformSetFrequency(PikaObj* self) {
int freq = obj_getInt(self, "freq");
char *pin = obj_getStr(self, "pin");
TIM_HandleTypeDef* pika_tim = getTimHandle(pin);
if (NULL == pika_tim) {
obj_setSysOut(self, "[error]: can not found PWM hardware.");

View File

@ -19,6 +19,21 @@ pika_uart_t pika_uart3;
pika_uart_t pika_uart4;
#endif
UART_HandleTypeDef huart1;
/* support prinf */
int fputc(int ch, FILE* f) {
HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, 0xffff);
return ch;
}
/* support scanf */
int fgetc(FILE* f) {
uint8_t ch = 0;
HAL_UART_Receive(&huart1, &ch, 1, 0xffff);
return ch;
}
static pika_uart_t* getPikaUart(uint8_t id) {
if (1 == id) {
return &pika_uart1;
@ -338,11 +353,14 @@ void USART3_4_IRQHandler(void) {
#endif
#endif
void STM32_UART_platformEnable(PikaObj* self, int baudRate, int id) {
#ifdef Code_ENABLE
STM32_Code_Init();
#endif
void STM32_UART_platformEnable(PikaObj* self) {
int id = obj_getInt(self, "id");
int baudRate = obj_getInt(self, "baudRate");
setUartObj(id, self);
/* uart 1 is inited by hardward */
if (1 == id) {
return;
}
UART_HandleTypeDef* huart = getUartHandle(id);
huart->Instance = getUartInstance(id);
UART_MspInit(huart);
@ -355,7 +373,9 @@ void STM32_UART_platformEnable(PikaObj* self, int baudRate, int id) {
HAL_UART_Receive_IT(getUartHandle(id), (uint8_t*)getUartRxBuff(id), 1);
}
char* STM32_UART_platformRead(PikaObj* self, int id, int length) {
void STM32_UART_platformRead(PikaObj* self) {
int id = obj_getInt(self, "id");
int length = obj_getInt(self, "length");
Args* buffs = New_strBuff();
char* readBuff = NULL;
pika_uart_t* pika_uart = getPikaUart(id);
@ -379,10 +399,12 @@ char* STM32_UART_platformRead(PikaObj* self, int id, int length) {
(uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
exit:
args_deinit(buffs);
return readBuff;
obj_setStr(self,"readData", readBuff);
}
void STM32_UART_platformWrite(PikaObj* self, char* data, int id) {
void STM32_UART_platformWrite(PikaObj* self) {
char *data = obj_getStr(self, "data");
int id = obj_getInt(self, "id");
HAL_UART_Transmit(getUartHandle(id), (uint8_t*)data, strGetSize(data), 100);
}
@ -418,14 +440,14 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
pikaShellRxOk = 1;
#endif
}
/* avoid recive buff overflow */
/* avoid recive buff overflow */
if (pika_uart->rxBuffOffset + 2 > RX_BUFF_LENGTH) {
memmove(pika_uart->rxBuff, pika_uart->rxBuff + 1, RX_BUFF_LENGTH);
UART_Start_Receive_IT(
huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
return;
}
/* recive next char */
pika_uart->rxBuffOffset++;
pika_uart->rxBuff[pika_uart->rxBuffOffset] = 0;
@ -433,15 +455,36 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
}
/* support prinf */
int fputc(int ch, FILE* f) {
HAL_UART_Transmit(&pika_uart1.huart, (uint8_t*)&ch, 1, 0xffff);
return ch;
}
void HARDWARE_PRINTF_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_USART1_CLK_ENABLE();
/* support scanf */
int fgetc(FILE* f) {
uint8_t ch = 0;
HAL_UART_Receive(&pika_uart1.huart, &ch, 1, 0xffff);
return ch;
}
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(&huart1);
HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8);
HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8);
HAL_UARTEx_DisableFifoMode(&huart1);
pika_uart1.huart = huart1;
pika_uart1.id = 1;
pika_uart1.obj = NULL;
HAL_UART_Receive_IT(getUartHandle(1), (uint8_t*)getUartRxBuff(1), 1);
}

View File

@ -87,4 +87,5 @@ void STM32_UART_clearRxBuff(pika_uart_t* pika_uart);
uint8_t STM32_Code_reciveHandler(char *data, uint32_t rxSize);
void STM32_Code_Init();
void STM32_Code_flashHandler();
void HARDWARE_PRINTF_Init();
#endif

View File

@ -24,8 +24,8 @@
/* USER CODE BEGIN Includes */
#include "STM32_common.h"
#include "pikaScript.h"
#include "stdbool.h"
#include "pikaVM.h"
#include "stdbool.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -61,6 +61,7 @@ void SystemClock_Config(void);
PikaObj* pikaMain;
extern char pikaShell[RX_BUFF_LENGTH];
extern uint8_t pikaShellRxOk;
/* USER CODE END 0 */
/**
@ -97,60 +98,59 @@ int main(void) {
SCB->VTOR = FLASH_BASE | 0x2000;
__enable_irq();
pikaMain = newRootObj("pikaMain", New_PikaMain);
obj_run(pikaMain, "uart = STM32.UART()");
obj_run(pikaMain, "uart.init()");
obj_run(pikaMain, "uart.setId(1)");
obj_run(pikaMain, "uart.setBaudRate(115200)");
obj_run(pikaMain, "uart.enable()");
obj_run(pikaMain, "print('uart init ok')");
obj_run(pikaMain, "remove('uart')");
obj_deinit(pikaMain);
HARDWARE_PRINTF_Init();
STM32_Code_Init();
printf("stm32 hardware init ok\r\n");
char* code = (char*)FLASH_SCRIPT_START_ADDR;
uint16_t codeOffset = 0;
if (code[0] != 0xFF) {
/* boot from flash */
pikaMain = newRootObj("pikaMain", New_PikaMain);
if(code[0] == 'i'){
if (code[0] == 'i') {
printf("[info]: boot from Script.\r\n");
Arg *codeBuff = arg_setStr(NULL, "", code);
Arg* codeBuff = arg_setStr(NULL, "", code);
obj_run(pikaMain, arg_getStr(codeBuff));
arg_deinit(codeBuff);
goto main_loop;
}
if(code[0] == 'B'){
printf("[info]: boot from Pika Asm.\r\n");
printf("%s\n",code);
printf("asm size: %d\n", strGetSize(code));
if (code[0] == 'B') {
printf("==============[Pika ASM]==============\r\n");
for(int i = 0; i < strGetSize(code); i ++){
if('\n' == code[i]){
fputc('\r', (FILE*)!NULL);
}
fputc(code[i], (FILE*)!NULL);
}
printf("==============[Pika ASM]==============\r\n");
printf("asm size: %d\r\n", strGetSize(code));
printf("[info]: boot from Pika Asm.\r\n");
pikaVM_runAsm(pikaMain, code);
goto main_loop;
}
} else {
/* boot from firmware */
pikaMain = pikaScriptInit();
goto main_loop;
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
main_loop:
while (1) {
if(pikaShellRxOk){
Args * runRes = obj_runDirect(pikaMain, pikaShell);
char* sysOut = args_getSysOut(runRes);
uint8_t errcode = args_getErrorCode(runRes);
if (pikaShellRxOk) {
Parameters* runRes = obj_runDirect(pikaMain, pikaShell);
char* sysOut = args_getSysOut(runRes->attributeList);
uint8_t errcode = args_getErrorCode(runRes->attributeList);
__platformPrintf(">>> %s", pikaShell);
if (!strEqu("", sysOut)) {
__platformPrintf("%s\r\n", sysOut);
}
if (NULL != runRes) {
args_deinit(runRes);
}
obj_deinit(runRes);
}
pikaShellRxOk = 0;
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**