Giter Club home page Giter Club logo

oceanchip / pikascript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pikastech/pikapython

0.0 0.0 0.0 199.72 MB

PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM (such as STM32G030C8 and STM32F103C8), and is very easy to deploy and expand.

Home Page: http://pikascript.com/

License: MIT License

C 97.41% CMake 0.04% Shell 0.15% Python 0.41% Starlark 0.01% HTML 0.03% SCSS 0.01% Rust 0.02% Go 0.01% Assembly 1.48% Makefile 0.10% C++ 0.27% RPC 0.01% Batchfile 0.01% Perl 0.01% Pawn 0.01% M4 0.01% Lex 0.01% Yacc 0.02% CSS 0.02%

pikascript's Introduction

logo

PikaScript

Cross platform ultra lightweight embedded Python engine

中文页 | Forum | Documents | Videos | BSP | Package Manager | RT-Thread package | Contribute | Business

image

1. Abstract

PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM and 32KB of flash (such as STM32G030C8 and STM32F103C8).

It's very easy to bind C function to python module with the help of Pika Pre-compiler.

Get PikaScript:

Use Online Project Generator

Generator url: http://pikascript.com

Use Pika package manager PikaPackage.exe

  1. Run the PikaPackage.exe directly, then the pikascript repo would be downloaded auto in the /tmp/pikascript folder of your current disc partition.

  2. Add requestment.txt to the same folder of PikaPackage.exe then run PikaPackage.exe. The run-time core, pre-compiler and moudles would be installed in the current folder.

  3. Released modules:packages.toml

Quick Start

You can use simulation project to quick start without hardware,or use the out-of-the-box develop board Pika-Pi—Zero.

image

The board based on STM32G030C8T6 MCU, only 64kB Flash, 8kB RAM can run PikaScript with total peripheral device (GPIO、TIME、IIC、RGB、KEY、LCD、RGB). CH340 is deployed to support USB to serial with Type-C USB, support download python script py serial, there are 4 RGB on the board and support the LCD.

Document

1. PikaScript-Quick start within 3 minutes

2. PikaScript-Architecture and principle

3. PikaScript-Deploy within 10 minutes

4. PikaScript-Standard develop workflow

5. PikaScript-Demo show

6. Arm-2D simulation

Folders

src - core code

bsp - mcu/board support

port - OS support

document - developt document

examples - example scripts

package - packages and moudles

pikaCompiler - pre-compiler write by Rust, used to bind C function to python moudle.

pikaPackageManager - pacakge manager

2.Platform support

MCU support

MCU bsp gpio uart pwm adc i2c
stm32g030c8
stm32g070cB
stm32f103c8
stm32f103rb
stm32f103ze
stm32f103rc
stm32f401cc
stm32f411ce
stm32f407ze
stm32f407zg
stm32f051r8
ch32v103r8t6
cm32m101a
w801
w806
apm32f030r8
apm32e103vb
bl-706
Raspberry Pico
ESP32C3
TC264D
devc

Board support

Board bsp gpio uart pwm adc i2c rgb lcd arm-2d
Pika-Pi-Zero
Board bsp arm-2d
QEMU-arm2d
Board bsp LED KEY
SmartLoong

OS support

OS port GPIO TIME PWM
RT-Thread
vsf
OS port Google Test Benchmark
linux

3.Characteristic

(1)Run environment

Support run in mcu without OS or file system. Can run in everywhere with RAM ≥ 4kB and FLASH ≥ 32kB,such as stm32g030, stm32f103c8t6,esp8266.

(2)Develop enviroment

Support run and program python scripts by serial.

微信交流群

Support IDEs like Keil, IAR, RT-Thread studio and segger embedded studio to develop C moudle.

Support build tools like CMake, makeFile and Scons.

Zero dependencies, zero configuration, out-of-the-box, easy to integrated into privious C projcet.

Eazy to extern customized C moudles.

Support linux.

(3)Syntax

Support subaggregate of python 3 standard syntax.

Support class and method define, encapsulation-inheritance-polymorphism and moudles in compile time - Based on Pika Pre-compiler.

Support method invoke, argument define, new object, free object, control flow(if\while) and operator ( + - * / < == > ). - Based on Pika Runtime Core.

Syntax Compile-Time Run-Time
Module Define -
Module Import -
Class Define
Class Inherit
Method Define
Method Override
Method Invoke
Argument Define
Argument Assignment
Object New
Object Free
Object Nest

Operator

+ - * / == > < >= <= % ** // != & >> << and or not += -= *= /=

Control flow

if while for else elif break continue

(4)Develop standard.

Readability first, nearly never use macro function and global argument.

Complete unit testes based on google test.

4.Both talk and show the code:

Tencent QQ: 645275593

5.Contribute

Content Contributer
捐赠:EC600X QuecPython 开发板 移远模块 武加玉
Performance Point: 900->1400 GorgonMeducer
stm32f051r8 BSP unsigned
stm32f407ze BSP unsigned
devc BSP unsigned
TC264D BSP unsigned
PikaVM improvement GorgonMeducer
W801Device package 刘延(微信名)
W806 bsp 刘延(微信名)
捐赠:ESP32C3 5pic,调试器 启明云端 沧御
捐赠:LS1C101芯片10pic, LS1c101开发板,调试器 龙芯俱乐部 石南
PikaVSF OS package versaloon
ESP32C3 BSP 沧御
捐赠:ESP32开发板、墨水屏*4 name(微信名)
捐赠:智龙开发板 龙芯俱乐部 石南
package/STM32F1 sjy
package/STM32F103RBBooter sjy
bsp/stm32f103rb sjy
基于QEMU的ARM-2D仿真工程 liuduanfei
捐赠:GD32E103TB芯片2片 信息牛(微信名)
Rt-thread 支持包、适配层、模块 Meco Jianting Man
捐赠:移远EC600S-CN 4G模块 移远模块
捐赠:博流BL706 开发板 博流智能 bouffalolab
捐赠:**移动CM32M101A 开发板 孟巍(微信名)
捐赠:APM32F030R8 开发板 极海半导体 陈成
捐赠:APM32E103VB 开发板 极海半导体 陈成
捐赠:APEX-Link仿真器 极海半导体 陈成
源码格式化,增加git属性文件 Meco Jianting Man
demo/simulation-keil 千帆(微信名)
demo/stm32f103zet6/demo01-led-stm32f103zet6 甜航
demo/stm32f103zet6/demo02-led-stm32f103zet6_tworoot 甜航
demo/stm32f407zgt/demo01-led-stm32f407vgt 甜航

6.Test and develop Core

Test core in linux(ubuntu20.04 is recommend):

step1: Clone the repo

git clone https://github.com/pikastech/pikascript
cd pikascript/port/linux

step2: Compile the project

sh install_dependency.sh # install dependency 
sh init.sh # Only nedded in the first time.
sh make.sh # Compile the project.

step3: Run the unit tests.

sh gtest.sh

step4: Run the banchmark

sh ci_benchmark.sh

7.Demo

The scripts in demos are in the examples folder.

Demo 01 GPIO

import PikaStdLib
import STM32G0

mem = PikaStdLib.MemChecker()
io1 = STM32G0.GPIO()
time = STM32G0.Time()

io1.init()
io1.setPin('PA8')
io1.setMode('out')
io1.enable()
io1.low()

print('hello pikascript')
print('mem.max :')
mem.max()
print('mem.now :')
mem.now()

while True:
    io1.low()
    time.sleep_ms(500)
    io1.high()
    time.sleep_ms(500)

Hnet-image (2)

Demo 02 USART

import PikaStdLib
import STM32G0

time = STM32G0.Time()
uart = STM32G0.UART()
uart.init()
uart.setId(1)
uart.setBaudRate(115200)
uart.enable()

while True:
    time.sleep_ms(500)
    readBuff = uart.read(2)
    print('read 2 char:')
    print(readBuff)

Hnet-image (3)

Demo 03 ADC

import PikaStdLib
import STM32G0

time = STM32G0.Time()
adc1 = STM32G0.ADC()

adc1.init()
adc1.setPin('PA1')
adc1.enable()

while True:
    val = adc1.read()
    print('adc1 value:')
    print(val)
    time.sleep_ms(500)

mmexport1631351523907

Demo 04 PWM output

import PikaStdLib
import STM32G0

time = STM32G0.Time()
pwm = STM32G0.PWM()
pwm.setPin('PA8')
pwm.setFrequency(2000)
pwm.setDuty(0.5)
pwm.enable()

while True:
    time.sleep_ms(500)
    pwm.setDuty(0.5)
    time.sleep_ms(500)
    pwm.setDuty(0.001)
    

Demo 05 RGB

import STM32G0
import PikaPiZero
import PikaStdLib

rgb = PikaPiZero.RGB()
mem = PikaStdLib.MemChecker()

rgb.init()
rgb.enable()

print('hello 2')
print('mem used max:')
mem.max()

while True:
    print('flowing')
    rgb.flow()

Demo 06 Snake(Need LCD)

from PikaObj import *
import PikaStdLib
import PikaPiZero
import STM32G0

# hardware init
lcd = PikaPiZero.LCD()
lcd.init()
lcd.clear('white')
key = PikaPiZero.KEY()
key.init()
time = STM32G0.Time()
x_max = 120
y_max = 150

# snake init
s = PikaPiZero.Point()
w = 9
h = 9
s.x = 50
s.y = 10
len = 0
while len < 3:
    b = s
    i = 0
    while i < len:
        b = b.next
        i = i + 1
    b.next = PikaPiZero.Point()
    b.next.x = b.x - 10
    b.next.y = b.y
    b.next.prev = b
    len = len + 1
# ring link
b.next = s
s.prev = b

i = 0
b = s
while i < len:
    lcd.fill(b.x, b.y, w, h, 'blue')
    b = b.next
    i = i + 1

print('snake lengh')
print(len)

# fruit init
f = PikaPiZero.Point()
f.x = 30
f.y = 20
lcd.fill(f.x, f.y, w, h, 'green')

# memory check
mem = PikaStdLib.MemChecker()
print('mem used max:')
mem.max()

# main loop
d = 0
isUpdate = 1
isEat = 0
while True:
    if isUpdate:
        # isUpdate = 0
        # check eat fruit
        if f.x == s.x and f.y == s.y:
            # have eat fruit
            isEat = 1
            f.x = f.x + 30
            if f.x > x_max:
                f.x = f.x - x_max
            f.y = f.y + 30
            if f.y > y_max:
                f.y = f.y - y_max
            lcd.fill(f.x, f.y, w, h, 'green')
        # move snake by the direction
        if d == 0:
            x_new = s.x + 10
            y_new = s.y
            if x_new > x_max:
                x_new = 0
        elif d == 1:
            x_new = s.x
            y_new = s.y - 10
            if y_new < 0:
                y_new = y_max
        elif d == 2:
            x_new = s.x
            y_new = s.y + 10
            if y_new > y_max:
                y_new = 0
        elif d == 3:
            x_new = s.x - 10
            y_new = s.y
            if x_new < 0:
                x_new = x_max
        if isEat:
            isEat = 0
            b_new = PikaPiZero.Point()
            b_new.x = x_new
            b_new.y = y_new
            b_new.prev = s.prev
            b_new.next = s
            s.prev.next = b_new
            s.prev = b_new
            s = b_new
            len = len + 1
            print('snake lengh')
            print(len)
            print('mem used max:')
            mem.max()
        # drow the snake and fruit
        # clear last body
        lcd.fill(s.prev.x, s.prev.y, w, h, 'white')
        # new body
        s.prev.x = x_new
        s.prev.y = y_new
        # head is last body
        s = s.prev
        lcd.fill(s.x, s.y, w, h, 'blue')
        b = s
        i = 0
    # scan key
    key_val = key.get()
    if key_val == 0:
        d = 0
        isUpdate = 1
    elif key_val == 1:
        d = 1
        isUpdate = 1
    elif key_val == 2:
        d = 2
        isUpdate = 1
    elif key_val == 3:
        d = 3
        isUpdate = 1
	

image

The maximum RAM usage of these demos is only 3.56K, which is 4.56K if the 1K stack is included, and the maximum Flash usage is 30.4K. Refer to the 20K RAM and 64K Flash of STM32F103C8T6, less than 25% RAM and less than 50% Flash are used.

A quick comparison can be made between the microPython chip STM32F405RG and the PikaScript chip STM32G070CB.

RAM resource comparison

image

Flash Resource Comparison

image

Reference price comparison (take the selling price of 10 pieces in Lichuang Mall on September 11, 2021 as reference)

image

About the custom extern module ?

In addition to device drivers, developing custom Python modules for MCU is very easy. The following two demos are extensions of the custom module, which developed python interfaces for the ARM-2D image driver library.

Boxes~

Hnet-image (7)

Rotating suns~

Hnet-image (6)

pikascript's People

Contributors

pikastech avatar mysterywolf avatar gorgonmeducer avatar versaloon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.