mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
Merge branch 'master' into request-support
This commit is contained in:
commit
0f51072065
61
README.md
61
README.md
@ -106,36 +106,37 @@ https://pikadoc.readthedocs.io/en/latest/%E5%A6%82%E4%BD%95%E5%8F%82%E4%B8%8E%E7
|
||||
|
||||
|
||||
## MCU support
|
||||
|MCU |bsp|gpio|time|uart|pwm|adc|i2c|
|
||||
|---|---|---|---|---|---|---|---|
|
||||
|stm32g030c8 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32g070cB |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103c8 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103rb |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103ze |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103rc |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f401cc |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f411ce |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f407ze |√ | | | | | | |
|
||||
|stm32f407zg |√ | | | | | | |
|
||||
|stm32h750vb |√ | | | | | | |
|
||||
|stm32f051r8 |√ | | | | | | |
|
||||
|air32f103cb |√ |√ | √ | | | | |
|
||||
|ch582 |√ |√ |√ |√ | |√ |√ |
|
||||
|ch32v103r8t6 |√ |√ |√ | | | | |
|
||||
|cm32m101a |√ | | | | | | |
|
||||
|w806 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|apm32f030r8 |√ | | | | | | |
|
||||
|apm32e103vb |√ | | | | | | |
|
||||
|bl-706 |√ | | | | | | |
|
||||
|Raspberry Pico |√ | | | | | | |
|
||||
|ESP32C3 |√ |√ |√ | | | | |
|
||||
|TC264D |√ | | | | | | |
|
||||
|devc |√ | | | | | | |
|
||||
|visual-studio |√ | | | | | | |
|
||||
|EC600N |√ | | | | | | |
|
||||
|mm32f5277e9p |√ |√ | | | | | |
|
||||
|xr806(openharmony)|√ | | | | | | |
|
||||
|MCU |bsp|gpio|time|uart|pwm|adc|i2c|dac|
|
||||
|--- |---|--- |--- |--- |---|---|---|---|
|
||||
|stm32g030c8 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32g070cB |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103c8 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103rb |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103ze |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103rc |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f401cc |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f411ce |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f407ze |√ | | | | | | | |
|
||||
|stm32f407zg |√ | | | | | | | |
|
||||
|stm32h750vb |√ | | | | | | | |
|
||||
|stm32f051r8 |√ | | | | | | | |
|
||||
|air32f103cb |√ |√ |√ | | | | | |
|
||||
|ch582 |√ |√ |√ |√ | |√ |√ | |
|
||||
|ch32v103r8t6 |√ |√ |√ | | | | | |
|
||||
|cm32m101a |√ | | | | | | | |
|
||||
|w806 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|apm32f030r8 |√ | | | | | | | |
|
||||
|apm32e103vb |√ | | | | | | | |
|
||||
|bl-602 |√ |√ | | |√ |√ | |√ |
|
||||
|bl-706 |√ | | | | | | | |
|
||||
|Raspberry Pico |√ | | | | | | | |
|
||||
|ESP32C3 |√ |√ |√ | | | | | |
|
||||
|TC264D |√ | | | | | | | |
|
||||
|devc |√ | | | | | | | |
|
||||
|visual-studio |√ | | | | | | | |
|
||||
|EC600N |√ | | | | | | | |
|
||||
|mm32f5277e9p |√ |√ | | | | | | |
|
||||
|xr806(openharmony)|√ | | | | | | | |
|
||||
|
||||
|
||||
## Board support
|
||||
|
61
README_zh.md
61
README_zh.md
@ -109,36 +109,37 @@ http://pikascript.com
|
||||
# 2.平台支持列表
|
||||
|
||||
## MCU support
|
||||
|MCU |bsp|gpio|time|uart|pwm|adc|i2c|
|
||||
|---|---|---|---|---|---|---|---|
|
||||
|stm32g030c8 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32g070cB |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103c8 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103rb |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103ze |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103rc |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f401cc |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f411ce |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f407ze |√ | | | | | | |
|
||||
|stm32f407zg |√ | | | | | | |
|
||||
|stm32h750vb |√ | | | | | | |
|
||||
|stm32f051r8 |√ | | | | | | |
|
||||
|air32f103cb |√ |√ | √ | | | | |
|
||||
|ch582 |√ |√ |√ |√ | |√ |√ |
|
||||
|ch32v103r8t6 |√ |√ |√ | | | | |
|
||||
|cm32m101a |√ | | | | | | |
|
||||
|w806 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|apm32f030r8 |√ | | | | | | |
|
||||
|apm32e103vb |√ | | | | | | |
|
||||
|bl-706 |√ | | | | | | |
|
||||
|Raspberry Pico |√ | | | | | | |
|
||||
|ESP32C3 |√ |√ |√ | | | | |
|
||||
|TC264D |√ | | | | | | |
|
||||
|devc |√ | | | | | | |
|
||||
|visual-studio |√ | | | | | | |
|
||||
|EC600N |√ | | | | | | |
|
||||
|mm32f5277e9p |√ |√ | | | | | |
|
||||
|xr806(openharmony)|√ | | | | | | |
|
||||
|MCU |bsp|gpio|time|uart|pwm|adc|i2c|dac|
|
||||
|--- |---|--- |--- |--- |---|---|---|---|
|
||||
|stm32g030c8 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32g070cB |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103c8 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103rb |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103ze |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103rc |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f401cc |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f411ce |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f407ze |√ | | | | | | | |
|
||||
|stm32f407zg |√ | | | | | | | |
|
||||
|stm32h750vb |√ | | | | | | | |
|
||||
|stm32f051r8 |√ | | | | | | | |
|
||||
|air32f103cb |√ |√ |√ | | | | | |
|
||||
|ch582 |√ |√ |√ |√ | |√ |√ | |
|
||||
|ch32v103r8t6 |√ |√ |√ | | | | | |
|
||||
|cm32m101a |√ | | | | | | | |
|
||||
|w806 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|apm32f030r8 |√ | | | | | | | |
|
||||
|apm32e103vb |√ | | | | | | | |
|
||||
|bl-602 |√ |√ | | |√ |√ | |√ |
|
||||
|bl-706 |√ | | | | | | | |
|
||||
|Raspberry Pico |√ | | | | | | | |
|
||||
|ESP32C3 |√ |√ |√ | | | | | |
|
||||
|TC264D |√ | | | | | | | |
|
||||
|devc |√ | | | | | | | |
|
||||
|visual-studio |√ | | | | | | | |
|
||||
|EC600N |√ | | | | | | | |
|
||||
|mm32f5277e9p |√ |√ | | | | | | |
|
||||
|xr806(openharmony)|√ | | | | | | | |
|
||||
|
||||
|
||||
## Board support
|
||||
|
@ -1,30 +1,31 @@
|
||||
|MCU |bsp|gpio|time|uart|pwm|adc|i2c|
|
||||
|---|---|---|---|---|---|---|---|
|
||||
|stm32g030c8 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32g070cB |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103c8 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103rb |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103ze |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f103rc |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f401cc |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f411ce |√ |√ |√ |√ |√ |√ |√ |
|
||||
|stm32f407ze |√ | | | | | | |
|
||||
|stm32f407zg |√ | | | | | | |
|
||||
|stm32h750vb |√ | | | | | | |
|
||||
|stm32f051r8 |√ | | | | | | |
|
||||
|air32f103cb |√ |√ | √ | | | | |
|
||||
|ch582 |√ |√ |√ |√ | |√ |√ |
|
||||
|ch32v103r8t6 |√ |√ |√ | | | | |
|
||||
|cm32m101a |√ | | | | | | |
|
||||
|w806 |√ |√ |√ |√ |√ |√ |√ |
|
||||
|apm32f030r8 |√ | | | | | | |
|
||||
|apm32e103vb |√ | | | | | | |
|
||||
|bl-706 |√ | | | | | | |
|
||||
|Raspberry Pico |√ | | | | | | |
|
||||
|ESP32C3 |√ |√ |√ | | | | |
|
||||
|TC264D |√ | | | | | | |
|
||||
|devc |√ | | | | | | |
|
||||
|visual-studio |√ | | | | | | |
|
||||
|EC600N |√ | | | | | | |
|
||||
|mm32f5277e9p |√ |√ | | | | | |
|
||||
|xr806(openharmony)|√ | | | | | | |
|
||||
|MCU |bsp|gpio|time|uart|pwm|adc|i2c|dac|
|
||||
|--- |---|--- |--- |--- |---|---|---|---|
|
||||
|stm32g030c8 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32g070cB |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103c8 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103rb |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103ze |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f103rc |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f401cc |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f411ce |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|stm32f407ze |√ | | | | | | | |
|
||||
|stm32f407zg |√ | | | | | | | |
|
||||
|stm32h750vb |√ | | | | | | | |
|
||||
|stm32f051r8 |√ | | | | | | | |
|
||||
|air32f103cb |√ |√ |√ | | | | | |
|
||||
|ch582 |√ |√ |√ |√ | |√ |√ | |
|
||||
|ch32v103r8t6 |√ |√ |√ | | | | | |
|
||||
|cm32m101a |√ | | | | | | | |
|
||||
|w806 |√ |√ |√ |√ |√ |√ |√ | |
|
||||
|apm32f030r8 |√ | | | | | | | |
|
||||
|apm32e103vb |√ | | | | | | | |
|
||||
|bl-602 |√ |√ | | |√ |√ | |√ |
|
||||
|bl-706 |√ | | | | | | | |
|
||||
|Raspberry Pico |√ | | | | | | | |
|
||||
|ESP32C3 |√ |√ |√ | | | | | |
|
||||
|TC264D |√ | | | | | | | |
|
||||
|devc |√ | | | | | | | |
|
||||
|visual-studio |√ | | | | | | | |
|
||||
|EC600N |√ | | | | | | | |
|
||||
|mm32f5277e9p |√ |√ | | | | | | |
|
||||
|xr806(openharmony)|√ | | | | | | | |
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
AIR32F1==latest
|
||||
|
35
bsp/bl602/Makefile
Normal file
35
bsp/bl602/Makefile
Normal file
@ -0,0 +1,35 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := pikascript_bl602
|
||||
PROJECT_PATH := $(abspath .)
|
||||
PROJECT_BOARD := evb
|
||||
export PROJECT_PATH PROJECT_BOARD
|
||||
#CONFIG_TOOLPREFIX :=
|
||||
|
||||
-include ./proj_config.mk
|
||||
|
||||
ifeq ($(origin BL60X_SDK_PATH), undefined)
|
||||
BL60X_SDK_PATH_GUESS ?= $(shell pwd)
|
||||
BL60X_SDK_PATH ?= $(BL60X_SDK_PATH_GUESS)/..
|
||||
endif
|
||||
|
||||
COMPONENTS_BLSYS := bltime blfdt blmtd bloop loopadc looprt loopset
|
||||
COMPONENTS_VFS := romfs
|
||||
|
||||
INCLUDE_COMPONENTS += freertos_riscv_ram bl602 bl602_std newlibc hosal mbedtls_lts lwip vfs yloop utils cli blog blog_testc coredump
|
||||
INCLUDE_COMPONENTS += $(COMPONENTS_NETWORK)
|
||||
INCLUDE_COMPONENTS += $(COMPONENTS_BLSYS)
|
||||
INCLUDE_COMPONENTS += $(COMPONENTS_VFS)
|
||||
|
||||
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/boot
|
||||
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/pikascript
|
||||
|
||||
INCLUDE_COMPONENTS += boot
|
||||
INCLUDE_COMPONENTS += pikascript
|
||||
|
||||
CPPFLAGS += -Wno-format
|
||||
|
||||
include $(BL60X_SDK_PATH)/make_scripts_riscv/project.mk
|
70
bsp/bl602/README.md
Normal file
70
bsp/bl602/README.md
Normal file
@ -0,0 +1,70 @@
|
||||
# How to Compile
|
||||
|
||||
1. Install Wine
|
||||
|
||||
```
|
||||
sudo apt install wine
|
||||
```
|
||||
|
||||
2. Install SDK:
|
||||
> https://blog.csdn.net/Boantong_/article/details/125604649?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166617877716800182741996%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166617877716800182741996&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-3-125604649-null-null.nonecase&utm_term=wb2&spm=1018.2226.3001.4450
|
||||
|
||||
3.
|
||||
|
||||
``` bash
|
||||
mv pikascript_bl602 Ai-Thinker-Wb2
|
||||
cd Ai-Thinker-Wb2/pikascript_bl602
|
||||
sh make.sh
|
||||
```
|
||||
|
||||
# How to Flash
|
||||
> https://blog.csdn.net/Boantong_/article/details/125781602?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166617877716800182741996%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166617877716800182741996&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-125781602-null-null.nonecase&utm_term=wb2&spm=1018.2226.3001.4450
|
||||
|
||||
# IIC
|
||||
|
||||
``` c
|
||||
pika_dev* iic = pika_hal_open(PIKA_HAL_IIC, "IIC3");
|
||||
pika_hal_IIC_config iic_cfg = {0};
|
||||
iic_cfg.slave_addr = 0x12;
|
||||
iic_cfg.mem_addr_ena = PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE;
|
||||
iic_cfg.mem_addr = 0x00;
|
||||
iic_cfg.speed = 400000;
|
||||
uint32_t err = 0;
|
||||
pika_hal_ioctl(iic, PIKA_HAL_IOCTL_CONFIG, &iic_cfg);
|
||||
pika_hal_ioctl(iic, PIKA_HAL_IOCTL_ENABLE, NULL);
|
||||
uint8_t res = 0;
|
||||
err = pika_hal_read(iic, &res, 1);
|
||||
if (0 != err) {
|
||||
printf("read error, err=%d\r\n", err);
|
||||
}
|
||||
printf("IIC3 read reg=%02x, res=%02x\r\n", iic_cfg.mem_addr, res);
|
||||
```
|
||||
|
||||
log:
|
||||
```
|
||||
======[pikascript packages installed]======
|
||||
pikascript-core==v1.11.8 (2022/11/19 19:43:26)
|
||||
PikaStdDevice==latest
|
||||
PikaStdLib==v1.11.8
|
||||
===========================================
|
||||
hello pikascript
|
||||
IIC: Open IIC3 on SCL:P12, SDA:P11
|
||||
IIC: Config IIC0, speed:400000, address_width:0,master_or_slave: 1
|
||||
IIC: Enable IIC0 on SCL:P12, SDA:P11
|
||||
IIC: Read 1 bytes from 0x12
|
||||
IIC: Read 1 bytes from 0x12, mem_addr:0x00
|
||||
IIC3 read reg=00, res=e7
|
||||
>>> [ Info] In PikaSciprt Demo...
|
||||
======[pikascript packages installed]======
|
||||
pikascript-core==v1.11.8 (2022/11/19 19:43:26)
|
||||
PikaStdDevice==latest
|
||||
PikaStdLib==v1.11.8
|
||||
===========================================
|
||||
hello pikascript
|
||||
IIC: Open IIC3 on SCL:P12, SDA:P11
|
||||
IIC: Config IIC0, speed:400000, address_width:0,master_or_slave: 1
|
||||
IIC: Enable IIC0 on SCL:P12, SDA:P11
|
||||
IIC: Read 1 bytes from 0x12
|
||||
IIC: Read 1 bytes from 0x12, mem_addr:0x00
|
||||
IIC3 read reg=00, res=e7
|
||||
```
|
26
bsp/bl602/boot/bouffalo.mk
Normal file
26
bsp/bl602/boot/bouffalo.mk
Normal file
@ -0,0 +1,26 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
||||
include $(BL60X_SDK_PATH)/components/network/ble/ble_common.mk
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_PSM_RAM),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_PSRAM
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_CAMERA),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_CAMERA
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_BLSYNC),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_BLSYNC
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_VFS_SPI),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_VFS_SPI
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_VFS_ROMFS),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_VFS_ROMFS
|
||||
endif
|
9
bsp/bl602/boot/include/main_board.h
Normal file
9
bsp/bl602/boot/include/main_board.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef __MAIN_BOARD_H__
|
||||
#define __MAIN_BOARD_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t bl60x_board_get_factory_addr(void);
|
||||
int bl60x_board_cfg(uint8_t board_code);
|
||||
|
||||
#endif /*__MAIN_BOARD_H__*/
|
59
bsp/bl602/boot/main.c
Normal file
59
bsp/bl602/boot/main.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <aos/yloop.h>
|
||||
#include <bl_gpio.h>
|
||||
#include <cli.h>
|
||||
#include <hosal_uart.h>
|
||||
#include <stdio.h>
|
||||
#include <task.h>
|
||||
#include <vfs.h>
|
||||
#include "../pikascript/pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "pikaScript.h"
|
||||
|
||||
volatile PikaObj* root = NULL;
|
||||
static volatile char rxbuff[1024 * 10];
|
||||
static volatile int rxsize = 0;
|
||||
static volatile int rxbusy = 0;
|
||||
|
||||
char __platform_getchar() {
|
||||
char inbuf[2] = {0};
|
||||
int ret = -1;
|
||||
extern hosal_uart_dev_t uart_stdio;
|
||||
while (ret != 1) {
|
||||
ret = hosal_uart_receive(&uart_stdio, inbuf, 1);
|
||||
vTaskDelay(1);
|
||||
}
|
||||
return inbuf[0];
|
||||
}
|
||||
|
||||
/* file API */
|
||||
FILE* __platform_fopen(const char* filename, const char* modes) {
|
||||
return fopen(filename, modes);
|
||||
}
|
||||
|
||||
int __platform_fclose(FILE* stream) {
|
||||
return fclose(stream);
|
||||
}
|
||||
|
||||
size_t __platform_fwrite(const void* ptr, size_t size, size_t n, FILE* stream) {
|
||||
return fwrite(ptr, size, n, stream);
|
||||
}
|
||||
|
||||
size_t __platform_fread(void* ptr, size_t size, size_t n, FILE* stream) {
|
||||
return fread(ptr, size, n, stream);
|
||||
}
|
||||
|
||||
int __platform_fseek(FILE* stream, long offset, int whence) {
|
||||
return fseek(stream, offset, whence);
|
||||
}
|
||||
|
||||
long __platform_ftell(FILE* stream) {
|
||||
return ftell(stream);
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
bl_gpio_enable_output(4, 0, 0);
|
||||
bl_gpio_output_set(4, false);
|
||||
printf("[ Info] In PikaSciprt Demo...\r\n");
|
||||
root = pikaScriptInit();
|
||||
pikaScriptShell(root);
|
||||
}
|
5
bsp/bl602/boot/pika_config.h
Normal file
5
bsp/bl602/boot/pika_config.h
Normal file
@ -0,0 +1,5 @@
|
||||
#define __platform_printf printf
|
||||
#define PIKA_OPTIMIZE PIKA_OPTIMIZE_SPEED
|
||||
#define PIKA_SHELL_SAVE_FILE_ENABLE 1
|
||||
#define PIKA_SHELL_SAVE_FILE_NAME "/lfs/boot.py"
|
||||
#define PIKA_DEBUG_ENABLE 1
|
6
bsp/bl602/make.sh
Normal file
6
bsp/bl602/make.sh
Normal file
@ -0,0 +1,6 @@
|
||||
clear
|
||||
rm /mnt/d/pikascript_bl602.bin
|
||||
cd pikascript && wine rust-msc-latest-win10.exe
|
||||
cd -
|
||||
make -j
|
||||
cp build_out/pikascript_bl602.bin /mnt/d
|
18
bsp/bl602/pikascript/bouffalo.mk
Normal file
18
bsp/bl602/pikascript/bouffalo.mk
Normal file
@ -0,0 +1,18 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS += pikascript-core \
|
||||
pikascript-api
|
||||
|
||||
COMPONENT_SRCS :=
|
||||
|
||||
CFLAGS += -DPIKASCRIPT -DPIKA_CONFIG_ENABLE -DCONFIG_SYS_VFS_ENABLE=1 \
|
||||
-DLFS_YES_TRACE
|
||||
|
||||
COMPONENT_OBJS := $(patsubst %.c,%.o, $(COMPONENT_SRCS))
|
||||
|
||||
COMPONENT_SRCDIRS := pikascript-core \
|
||||
pikascript-api \
|
||||
pikascript-lib/BLIOT \
|
||||
pikascript-lib/PikaStdDevice \
|
||||
pikascript-lib/PikaStdLib
|
||||
|
||||
COMPONENT_ADD_LDFLAGS_HEAD = -Wl,--whole-archive
|
||||
COMPONENT_ADD_LDFLAGS_TAIL = -Wl,--no-whole-archive
|
9
bsp/bl602/pikascript/main.py
Normal file
9
bsp/bl602/pikascript/main.py
Normal file
@ -0,0 +1,9 @@
|
||||
import PikaStdLib
|
||||
import PikaStdDevice as std
|
||||
print('hello pikascript')
|
||||
mem = PikaStdLib.MemChecker()
|
||||
|
||||
dac = std.DAC()
|
||||
dac.setPin('P14')
|
||||
dac.enable()
|
||||
dac.write(1.3)
|
BIN
bsp/bl602/pikascript/pikaPackage.exe
Normal file
BIN
bsp/bl602/pikascript/pikaPackage.exe
Normal file
Binary file not shown.
4
bsp/bl602/pikascript/requestment.txt
Normal file
4
bsp/bl602/pikascript/requestment.txt
Normal file
@ -0,0 +1,4 @@
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v2.1.1
|
||||
BLIOT==v0.2.0
|
50
bsp/bl602/proj_config.mk
Normal file
50
bsp/bl602/proj_config.mk
Normal file
@ -0,0 +1,50 @@
|
||||
#
|
||||
#compiler flag config domain
|
||||
#
|
||||
#CONFIG_TOOLPREFIX :=
|
||||
#CONFIG_OPTIMIZATION_LEVEL_RELEASE := 1
|
||||
#CONFIG_M4_SOFTFP := 1
|
||||
|
||||
#
|
||||
#board config domain
|
||||
#
|
||||
CONFIG_BOARD_FLASH_SIZE := 2
|
||||
|
||||
#firmware config domain
|
||||
#
|
||||
|
||||
#set CONFIG_ENABLE_ACP to 1 to enable ACP, set to 0 or comment this line to disable
|
||||
#CONFIG_ENABLE_ACP:=1
|
||||
CONFIG_BL_IOT_FW_AP:=1
|
||||
CONFIG_BL_IOT_FW_AMPDU:=0
|
||||
CONFIG_BL_IOT_FW_AMSDU:=0
|
||||
CONFIG_BL_IOT_FW_P2P:=0
|
||||
CONFIG_ENABLE_PSM_RAM:=1
|
||||
#CONFIG_ENABLE_CAMERA:=1
|
||||
#CONFIG_ENABLE_BLSYNC:=1
|
||||
#CONFIG_ENABLE_VFS_SPI:=1
|
||||
CONFIG_ENABLE_VFS_ROMFS:=1
|
||||
CONFIG_EASYFLASH_ENABLE:=0
|
||||
|
||||
CONFIG_SYS_APP_TASK_STACK_SIZE:=4096
|
||||
CONFIG_SYS_APP_TASK_PRIORITY:=15
|
||||
CONFIG_BL602_USE_ROM_DRIVER:=1
|
||||
CONFIG_FREERTOS_TICKLESS_MODE:=0
|
||||
CONFIG_SYS_VFS_ENABLE:=1
|
||||
CONFIG_SYS_VFS_UART_ENABLE:=1
|
||||
CONFIG_SYS_AOS_CLI_ENABLE:=0
|
||||
CONFIG_SYS_AOS_LOOP_ENABLE:=1
|
||||
CONFIG_SYS_BLOG_ENABLE:=1
|
||||
CONFIG_SYS_DMA_ENABLE:=0
|
||||
CONFIG_SYS_USER_VFS_ROMFS_ENABLE:=0
|
||||
|
||||
CONFIG_BT_CENTRAL:=1
|
||||
CONFIG_BT_OBSERVER:=1
|
||||
CONFIG_BT_PERIPHERAL:=1
|
||||
CONFIG_BT_STACK_CLI:=1
|
||||
CONFIG_BT_WIFIPROV_SERVER:=1
|
||||
CONFIG_WIFI:=0
|
||||
|
||||
CONF_ENABLE_COREDUMP:=1
|
||||
|
||||
LOG_ENABLED_COMPONENTS:=blog_testc hosal loopset looprt bloop
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
CH582==v1.1.2
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
ESP32==v0.1.0
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
pika_lvgl==v0.3.2
|
||||
pika_lvgl==v0.4.1
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
|
@ -1,3 +1,3 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
Arm2D==v0.6.1
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -17,7 +17,7 @@
|
||||
<TargetCommonOption>
|
||||
<Device>STM32F103RB</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.3.0</PackID>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.4.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IROM(0x08000000,0x20000) IRAM(0x20000000,0x5000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
@ -187,6 +187,7 @@
|
||||
<RvdsVP>0</RvdsVP>
|
||||
<RvdsMve>0</RvdsMve>
|
||||
<RvdsCdeCp>0</RvdsCdeCp>
|
||||
<nBranchProt>0</nBranchProt>
|
||||
<hadIRAM2>0</hadIRAM2>
|
||||
<hadIROM2>0</hadIROM2>
|
||||
<StupSel>8</StupSel>
|
||||
@ -314,8 +315,8 @@
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>1</Optim>
|
||||
<oTime>1</oTime>
|
||||
<Optim>2</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
<Strict>0</Strict>
|
||||
@ -340,7 +341,7 @@
|
||||
<MiscControls></MiscControls>
|
||||
<Define>USE_HAL_DRIVER,STM32F103xB</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\SYSTEM\sys;..\SYSTEM\usart;..\SYSTEM\delay;..\Booter;..\Drivers\CORE;..\Drivers\HALLIB\STM32F1xx_HAL_Driver\Inc;..\PikaScript\pikascript-api;..\PikaScript\pikascript-core;..\PikaScript\pikascript-lib\PikaStdLib;..\PikaScript\pikascript-lib\PikaStdDevice;..\PikaScript\pikascript-lib\STM32F1</IncludePath>
|
||||
<IncludePath>..\SYSTEM\sys;..\SYSTEM\usart;..\SYSTEM\delay;..\Booter;..\Drivers\CORE;..\Drivers\HALLIB\STM32F1xx_HAL_Driver\Inc;..\PikaScript\pikascript-lib/PikaStdDevice;..\PikaScript\pikascript-lib/STM32F1;..\PikaScript\pikascript-lib/PikaStdLib;..\PikaScript\pikascript-api;..\PikaScript\pikascript-core</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@ -595,304 +596,169 @@
|
||||
<GroupName>pikascript-lib</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>PikaStdLib_MemChecker.c</FileName>
|
||||
<FileName>PikaStdDevice_IIC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdLib_MemChecker.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_SysObj.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdLib_SysObj.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_Time.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_Time.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_common.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\STM32F1\STM32F1_common.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_GPIO.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\STM32F1\STM32F1_GPIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_Time.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\STM32F1\STM32F1_Time.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_ADC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\STM32F1\STM32F1_ADC.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_IIC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\STM32F1\STM32F1_IIC.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_PWM.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\STM32F1\STM32F1_PWM.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_UART.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\STM32F1\STM32F1_UART.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_IIC.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_ADC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_ADC.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_ADC.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_BaseDev.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_BaseDev.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_GPIO.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_GPIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_IIC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_IIC.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_PWM.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_PWM.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_UART.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_UART.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_RangeObj.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdLib_RangeObj.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_StringObj.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdLib_StringObj.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_GPIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_CAN.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_CAN.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_CAN.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_Time.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_Time.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_UART.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_UART.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_PWM.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_PWM.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_SPI.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdDevice\PikaStdDevice_SPI.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdDevice/PikaStdDevice_SPI.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaDebuger_Debuger.c</FileName>
|
||||
<FileName>STM32F1_PWM.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaDebuger_Debuger.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/STM32F1/STM32F1_PWM.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_ADC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/STM32F1/STM32F1_ADC.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_IIC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/STM32F1/STM32F1_IIC.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_Time.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/STM32F1/STM32F1_Time.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_common.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/STM32F1/STM32F1_common.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_GPIO.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/STM32F1/STM32F1_GPIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_UART.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/STM32F1/STM32F1_UART.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_RangeObj.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdLib_RangeObj.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_Dict.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdData_Dict.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_List.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdData_List.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_String.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdData_String.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdData_Dict.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdTask_Task.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib\PikaStdLib\PikaStdTask_Task.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdTask_Task.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_StringObj.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdLib_StringObj.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_Tuple.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdData_Tuple.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_MemChecker.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdLib_MemChecker.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaDebuger_Debuger.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaDebuger_Debuger.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_ByteArray.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdData_ByteArray.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_String.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdData_String.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_Utils.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdData_Utils.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_List.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdData_List.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_SysObj.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_FILEIO.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-lib/PikaStdLib/PikaStdData_FILEIO.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>pikascript-api</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>PikaMain-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaMain-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>pikaScript.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\pikaScript.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-api/pikaScript.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_MemChecker-api.c</FileName>
|
||||
<FileName>__pikaBinding.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdLib_MemChecker-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_SysObj-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdLib_SysObj-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdLib-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_GPIO-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_GPIO-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_Time-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_Time-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_GPIO-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1_GPIO-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_lowLevel-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1_lowLevel-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_Time-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1_Time-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_ADC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_ADC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_IIC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_IIC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_PWM-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_PWM-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_UART-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_UART-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_ADC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1_ADC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_IIC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1_IIC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_PWM-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1_PWM-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32F1_UART-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\STM32F1_UART-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_RangeObj-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdLib_RangeObj-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_StringObj-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdLib_StringObj-api.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-api/__pikaBinding.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>__asset_pikaModules_py_a.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\__asset_pikaModules_py_a.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaDebug_Debuger-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaDebug_Debuger-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaDebug-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaDebug-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_ByteArray-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdData_ByteArray-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_Dict-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdData_Dict-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_List-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdData_List-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_String-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdData_String-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdData-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_CAN-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_CAN-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_SPI-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice_SPI-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdDevice-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_PikaObj-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdLib_PikaObj-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdTask_Task-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdTask_Task-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdTask-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\PikaScript\pikascript-api\PikaStdTask-api.c</FilePath>
|
||||
<FilePath>..\PikaScript\pikascript-api/__asset_pikaModules_py_a.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F4==v0.1.1
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v2.0.0
|
||||
STM32F4==v0.1.2
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v2.0.0
|
||||
STM32F4==v0.1.2
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F4==v0.1.1
|
||||
|
@ -1,5 +1,5 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.2
|
||||
STM32G0==v1.3.2
|
||||
PikaPiZero==v1.3.0
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
PikaStdDevice==v1.11.0
|
||||
W801Device==v1.1.1
|
||||
|
77
examples/aes/test_aes.py
Normal file
77
examples/aes/test_aes.py
Normal file
@ -0,0 +1,77 @@
|
||||
import aes
|
||||
|
||||
|
||||
raw = b"0102030405060708"
|
||||
|
||||
print("== aes 128 ecb test begin ==")
|
||||
a = aes.new(b"0102030405060708", aes.MODE_ECB)
|
||||
b = a.encrypt(raw)
|
||||
c = a.decrypt(b)
|
||||
print("encrypt:", b)
|
||||
print("decrypt:", c)
|
||||
del a
|
||||
del b
|
||||
del c
|
||||
print("== aes 128 ecb test end ==")
|
||||
|
||||
print("== aes 192 ecb test begin ==")
|
||||
a = aes.new(b"010203040506070811121314", aes.MODE_ECB)
|
||||
b = a.encrypt(raw)
|
||||
c = a.decrypt(b)
|
||||
print("encrypt:", b)
|
||||
print("decrypt:", c)
|
||||
del a
|
||||
del b
|
||||
del c
|
||||
print("== aes 192 ecb test end ==")
|
||||
|
||||
|
||||
print("== aes 256 ecb test begin ==")
|
||||
a = aes.new(b"01020304050607081112131415161718", aes.MODE_ECB)
|
||||
b = a.encrypt(raw)
|
||||
c = a.decrypt(b)
|
||||
print("encrypt:", b)
|
||||
print("decrypt:", c)
|
||||
del a
|
||||
del b
|
||||
del c
|
||||
print("== aes 256 ecb test end ==")
|
||||
|
||||
|
||||
raw = b"0102030405060708111213141516171821222324252627283132333435363738"
|
||||
|
||||
|
||||
print("== aes 128 cbc test begin ==")
|
||||
a = aes.new(b"0102030405060708", aes.MODE_CBC, iv=b"0102030405060708")
|
||||
b = a.encrypt(raw)
|
||||
c = a.decrypt(b)
|
||||
print("encrypt:", b)
|
||||
print("decrypt:", c)
|
||||
del a
|
||||
del b
|
||||
del c
|
||||
print("== aes 128 cbc test end ==")
|
||||
|
||||
print("== aes 192 cbc test begin ==")
|
||||
a = aes.new(b"010203040506070811121314", aes.MODE_CBC, iv=b"0102030405060708")
|
||||
b = a.encrypt(raw)
|
||||
c = a.decrypt(b)
|
||||
print("encrypt:", b)
|
||||
print("decrypt:", c)
|
||||
del a
|
||||
del b
|
||||
del c
|
||||
print("== aes 192 cbc test end ==")
|
||||
|
||||
|
||||
print("== aes 256 cbc test begin ==")
|
||||
a = aes.new(b"01020304050607081112131415161718",
|
||||
aes.MODE_CBC, iv=b"0102030405060708")
|
||||
b = a.encrypt(raw)
|
||||
c = a.decrypt(b)
|
||||
print("encrypt:", b)
|
||||
print("decrypt:", c)
|
||||
del a
|
||||
del b
|
||||
del c
|
||||
print("== aes 256 cbc test end ==")
|
0
package/BLIOT/BLIOT.pyi
Normal file
0
package/BLIOT/BLIOT.pyi
Normal file
143
package/BLIOT/pika_hal_BLIOT_ADC.c
Normal file
143
package/BLIOT/pika_hal_BLIOT_ADC.c
Normal file
@ -0,0 +1,143 @@
|
||||
#include <hosal_adc.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
|
||||
static uint8_t _pin2ch(uint32_t pin) {
|
||||
/********** BL602 ************
|
||||
* channel0 -----> gpio12
|
||||
* channel1 -----> gpio4
|
||||
* channel2 -----> gpio14
|
||||
* channel3 -----> gpio13
|
||||
* channel4 -----> gpio5
|
||||
* channel5 -----> gpio6
|
||||
* channel7 -----> gpio9
|
||||
* channel9 -----> gpio10
|
||||
* channel10 -----> gpio11
|
||||
* channel11 -----> gpio15
|
||||
*/
|
||||
switch (pin) {
|
||||
case 12:
|
||||
return 0;
|
||||
case 4:
|
||||
return 1;
|
||||
case 14:
|
||||
return 2;
|
||||
case 13:
|
||||
return 3;
|
||||
case 5:
|
||||
return 4;
|
||||
case 6:
|
||||
return 5;
|
||||
case 9:
|
||||
return 7;
|
||||
case 10:
|
||||
return 9;
|
||||
case 11:
|
||||
return 10;
|
||||
case 15:
|
||||
return 11;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_open(pika_dev* dev, char* name) {
|
||||
hosal_adc_dev_t* platform_adc = pikaMalloc(sizeof(hosal_adc_dev_t));
|
||||
memset(platform_adc, 0, sizeof(hosal_adc_dev_t));
|
||||
dev->platform_data = platform_adc;
|
||||
/* Support P1/P2 ... */
|
||||
if (name[0] == 'P') {
|
||||
platform_adc->config.pin = fast_atoi(name + 1);
|
||||
platform_adc->port = 0;
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("ADC: Open ADC on P%d\r\n", platform_adc->config.pin);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("Failed to open ADC: %s\r\n", name);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_close(pika_dev* dev) {
|
||||
hosal_adc_dev_t* platform_adc = (hosal_adc_dev_t*)dev->platform_data;
|
||||
if (NULL != platform_adc) {
|
||||
pikaFree(platform_adc, sizeof(hosal_adc_dev_t));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_ioctl_config(pika_dev* dev,
|
||||
pika_hal_ADC_config* cfg) {
|
||||
hosal_adc_dev_t* platform_adc = (hosal_adc_dev_t*)dev->platform_data;
|
||||
platform_adc->config.sampling_freq = cfg->sampling_freq;
|
||||
switch (cfg->continue_or_single) {
|
||||
case PIKA_HAL_ADC_CONTINUOU:
|
||||
platform_adc->config.mode = HOSAL_ADC_CONTINUE;
|
||||
break;
|
||||
case PIKA_HAL_ADC_SINGLE:
|
||||
platform_adc->config.mode = HOSAL_ADC_ONE_SHOT;
|
||||
break;
|
||||
default:
|
||||
platform_adc->config.mode = HOSAL_ADC_ONE_SHOT;
|
||||
break;
|
||||
}
|
||||
platform_adc->config.sample_resolution = cfg->sampling_resolution;
|
||||
cfg->max = 3200;
|
||||
cfg->vref = (pika_float)3.3;
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("ADC: Config ADC on P%d, freq: %d, mode: %d\r\n",
|
||||
platform_adc->config.pin,
|
||||
platform_adc->config.sampling_freq,
|
||||
platform_adc->config.mode);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
int ret = 0;
|
||||
hosal_adc_dev_t* platform_adc = (hosal_adc_dev_t*)dev->platform_data;
|
||||
ret = hosal_adc_value_get(platform_adc, _pin2ch(platform_adc->config.pin),
|
||||
0xFFFFFFFF);
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("ADC: Read ADC on P%d, channel: %d, value: %d\r\n",
|
||||
platform_adc->config.pin,
|
||||
_pin2ch(platform_adc->config.pin), ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
*(uint32_t*)buf = ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_write(pika_dev* dev, void* buf, size_t count) {
|
||||
/* Not support */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_ioctl_enable(pika_dev* dev) {
|
||||
hosal_adc_dev_t* platform_adc = (hosal_adc_dev_t*)dev->platform_data;
|
||||
if (!dev->is_enabled) {
|
||||
hosal_dma_init();
|
||||
hosal_adc_init(platform_adc);
|
||||
hosal_adc_add_channel(platform_adc, _pin2ch(platform_adc->config.pin));
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf(
|
||||
"ADC: Enable ADC on P%d, freq: %d, mode: %d, ch: %d\r\n",
|
||||
platform_adc->config.pin, platform_adc->config.sampling_freq,
|
||||
platform_adc->config.mode, _pin2ch(platform_adc->config.pin));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_ioctl_disable(pika_dev* dev) {
|
||||
hosal_adc_dev_t* platform_adc = (hosal_adc_dev_t*)dev->platform_data;
|
||||
if (dev->is_enabled) {
|
||||
hosal_adc_finalize(platform_adc);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
90
package/BLIOT/pika_hal_BLIOT_DAC.c
Normal file
90
package/BLIOT/pika_hal_BLIOT_DAC.c
Normal file
@ -0,0 +1,90 @@
|
||||
#include <hosal_dac.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
|
||||
int pika_hal_platform_DAC_open(pika_dev* dev, char* name) {
|
||||
hosal_dac_dev_t* platform_dac = pikaMalloc(sizeof(hosal_dac_dev_t));
|
||||
memset(platform_dac, 0, sizeof(hosal_dac_dev_t));
|
||||
dev->platform_data = platform_dac;
|
||||
/* Support P1/P2 ... */
|
||||
if (name[0] == 'P') {
|
||||
int pin = fast_atoi(name + 1);
|
||||
if (pin != 13 && pin != 14) {
|
||||
/* bl602, only support P13, P14*/
|
||||
__platform_printf("DAC only support P13, P14\r\n");
|
||||
return -1;
|
||||
}
|
||||
platform_dac->config.pin = pin;
|
||||
platform_dac->port = 0;
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("DAC: Open DAC on P%d\r\n", platform_dac->config.pin);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("Failed to open DAC: %s\r\n", name);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_close(pika_dev* dev) {
|
||||
hosal_dac_dev_t* platform_dac = (hosal_dac_dev_t*)dev->platform_data;
|
||||
if (NULL != platform_dac) {
|
||||
pikaFree(platform_dac, sizeof(hosal_dac_dev_t));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_ioctl_config(pika_dev* dev,
|
||||
pika_hal_DAC_config* cfg) {
|
||||
hosal_dac_dev_t* platform_dac = (hosal_dac_dev_t*)dev->platform_data;
|
||||
/* only support 8k,16k,32k */
|
||||
platform_dac->config.freq = cfg->speed;
|
||||
platform_dac->config.dma_enable = 0;
|
||||
cfg->max = 3300000;
|
||||
cfg->vref = (pika_float)3.3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
int ret = 0;
|
||||
hosal_dac_dev_t* platform_dac = (hosal_dac_dev_t*)dev->platform_data;
|
||||
ret = hosal_dac_get_value(platform_dac);
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("DAC: Read %d\r\n", ret);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
*(uint32_t*)buf = ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_write(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_dac_dev_t* platform_dac = (hosal_dac_dev_t*)dev->platform_data;
|
||||
#if PIKA_DEBUG_ENALBE
|
||||
__platform_printf("DAC: Write %d\r\n", *(uint32_t*)buf);
|
||||
#endif
|
||||
return hosal_dac_set_value(platform_dac, *(uint32_t*)buf);
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_ioctl_enable(pika_dev* dev) {
|
||||
hosal_dac_dev_t* platform_dac = (hosal_dac_dev_t*)dev->platform_data;
|
||||
if (!dev->is_enabled) {
|
||||
hosal_dac_init(platform_dac);
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("DAC: Enable DAC, freq: %d\r\n",
|
||||
platform_dac->config.freq);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_ioctl_disable(pika_dev* dev) {
|
||||
hosal_dac_dev_t* platform_dac = (hosal_dac_dev_t*)dev->platform_data;
|
||||
if (dev->is_enabled) {
|
||||
hosal_dac_finalize(platform_dac);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
105
package/BLIOT/pika_hal_BLIOT_GPIO.c
Normal file
105
package/BLIOT/pika_hal_BLIOT_GPIO.c
Normal file
@ -0,0 +1,105 @@
|
||||
#include <bl_gpio.h>
|
||||
#include <hosal_gpio.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
|
||||
int pika_hal_platform_GPIO_open(pika_dev* dev, char* name) {
|
||||
dev->platform_data = pikaMalloc(sizeof(hosal_gpio_dev_t));
|
||||
memset(dev->platform_data, 0, sizeof(hosal_gpio_dev_t));
|
||||
hosal_gpio_dev_t* platform_gpio = (hosal_gpio_dev_t*)dev->platform_data;
|
||||
/* Support P1/P2 ... */
|
||||
platform_gpio->port = fast_atoi(name + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_close(pika_dev* dev) {
|
||||
pikaFree(dev->platform_data, sizeof(hosal_gpio_dev_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_read(pika_dev* dev, void* buf, size_t count) {
|
||||
uint8_t value = 0;
|
||||
hosal_gpio_dev_t* platform_gpio = (hosal_gpio_dev_t*)dev->platform_data;
|
||||
hosal_gpio_input_get(platform_gpio, &value);
|
||||
uint32_t value_in = value;
|
||||
memcpy(buf, &value_in, sizeof(value_in));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_write(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_gpio_dev_t* platform_gpio = (hosal_gpio_dev_t*)dev->platform_data;
|
||||
uint32_t value_out = 0;
|
||||
memcpy(&value_out, buf, sizeof(value_out));
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("GPIO write port %d to %d\r\n", platform_gpio->port,
|
||||
value_out);
|
||||
#endif
|
||||
hosal_gpio_output_set(platform_gpio, value_out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_enable(pika_dev* dev) {
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("in pika_hal_platform_GPIO_ioctl_enable\r\n");
|
||||
#endif
|
||||
hosal_gpio_dev_t* platform_gpio = (hosal_gpio_dev_t*)dev->platform_data;
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("GPIO enable port %d, config:%d\r\n", platform_gpio->port,
|
||||
platform_gpio->config);
|
||||
#endif
|
||||
hosal_gpio_init(platform_gpio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_disable(pika_dev* dev) {
|
||||
hosal_gpio_dev_t* platform_gpio = (hosal_gpio_dev_t*)dev->platform_data;
|
||||
hosal_gpio_finalize(platform_gpio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_config(pika_dev* dev,
|
||||
pika_hal_GPIO_config* cfg) {
|
||||
hosal_gpio_dev_t* platform_gpio = (hosal_gpio_dev_t*)dev->platform_data;
|
||||
switch (cfg->dir) {
|
||||
case PIKA_HAL_GPIO_DIR_OUT:
|
||||
// printf("GPIO set port %d to output\r\n", platform_gpio->port);
|
||||
switch (cfg->pull) {
|
||||
case PIKA_HAL_GPIO_PULL_NONE:
|
||||
platform_gpio->config = OUTPUT_OPEN_DRAIN_NO_PULL;
|
||||
break;
|
||||
case PIKA_HAL_GPIO_PULL_UP:
|
||||
platform_gpio->config = OUTPUT_OPEN_DRAIN_PULL_UP;
|
||||
break;
|
||||
case PIKA_HAL_GPIO_PULL_DOWN:
|
||||
platform_gpio->config = OUTPUT_PUSH_PULL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PIKA_HAL_GPIO_DIR_IN:
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("GPIO set port %d to input\r\n",
|
||||
platform_gpio->port);
|
||||
#endif
|
||||
switch (cfg->pull) {
|
||||
case PIKA_HAL_GPIO_PULL_NONE:
|
||||
platform_gpio->config = INPUT_HIGH_IMPEDANCE;
|
||||
|
||||
case PIKA_HAL_GPIO_PULL_UP:
|
||||
platform_gpio->config = INPUT_PULL_UP;
|
||||
|
||||
case PIKA_HAL_GPIO_PULL_DOWN:
|
||||
/* not supported */
|
||||
return -1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
default:
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("GPIO set port %d to unknown\r\n",
|
||||
platform_gpio->port);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
175
package/BLIOT/pika_hal_BLIOT_IIC.c
Normal file
175
package/BLIOT/pika_hal_BLIOT_IIC.c
Normal file
@ -0,0 +1,175 @@
|
||||
#include <hosal_i2c.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
|
||||
int _num2scl_sda(int num, uint8_t* scl, uint8_t* sda) {
|
||||
/********** BL602 ************
|
||||
* IIC0 -----> SCL:P0, SDA: P1
|
||||
* IIC1 -----> SCL:P2, SDA: P3
|
||||
* IIC2 -----> SCL:P4, SDA: P5
|
||||
* IIC3 -----> SCL:P12, SDA: P11
|
||||
* IIC4 -----> SCL:P14, SDA: P17
|
||||
* IIC5 -----> SCL:P20, SDA: P21
|
||||
*/
|
||||
switch (num) {
|
||||
case 0:
|
||||
*scl = 0;
|
||||
*sda = 1;
|
||||
break;
|
||||
case 1:
|
||||
*scl = 2;
|
||||
*sda = 3;
|
||||
break;
|
||||
case 2:
|
||||
*scl = 4;
|
||||
*sda = 5;
|
||||
break;
|
||||
case 3:
|
||||
*scl = 12;
|
||||
*sda = 11;
|
||||
break;
|
||||
case 4:
|
||||
*scl = 14;
|
||||
*sda = 17;
|
||||
break;
|
||||
case 5:
|
||||
*scl = 20;
|
||||
*sda = 21;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Open IIC%d on SCL:P%d, SDA:P%d\r\n", num, *scl,
|
||||
*sda);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_open(pika_dev* dev, char* name) {
|
||||
hosal_i2c_dev_t* platform_i2c = pikaMalloc(sizeof(hosal_i2c_dev_t));
|
||||
memset(platform_i2c, 0, sizeof(hosal_i2c_dev_t));
|
||||
dev->platform_data = platform_i2c;
|
||||
/* Support IIC0, IIC1, IIC2 */
|
||||
if (name[0] == 'I' && name[1] == 'I' && name[2] == 'C') {
|
||||
int iic_num = fast_atoi(name + 3);
|
||||
platform_i2c->port = 0;
|
||||
if (0 == _num2scl_sda(iic_num, &platform_i2c->config.scl,
|
||||
&platform_i2c->config.sda)) {
|
||||
return 0;
|
||||
} else {
|
||||
__platform_printf("IIC: Open IIC%d failed\r\n", iic_num);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_close(pika_dev* dev) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
if (NULL != platform_i2c) {
|
||||
pikaFree(platform_i2c, sizeof(hosal_i2c_dev_t));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_ioctl_config(pika_dev* dev,
|
||||
pika_hal_IIC_config* cfg) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
if (!dev->is_enabled) {
|
||||
platform_i2c->config.freq = cfg->speed;
|
||||
switch (cfg->address_width) {
|
||||
case PIKA_HAL_IIC_ADDRESS_WIDTH_7BIT:
|
||||
platform_i2c->config.address_width =
|
||||
HOSAL_I2C_ADDRESS_WIDTH_7BIT;
|
||||
break;
|
||||
case PIKA_HAL_IIC_ADDRESS_WIDTH_10BIT:
|
||||
platform_i2c->config.address_width =
|
||||
HOSAL_I2C_ADDRESS_WIDTH_10BIT;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
switch (cfg->master_or_slave) {
|
||||
case PIKA_HAL_IIC_MASTER:
|
||||
platform_i2c->config.mode = HOSAL_I2C_MODE_MASTER;
|
||||
break;
|
||||
case PIKA_HAL_IIC_SLAVE:
|
||||
platform_i2c->config.mode = HOSAL_I2C_MODE_SLAVE;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf(
|
||||
"IIC: Config IIC%d, speed:%d, address_width:%d,master_or_slave: "
|
||||
"%d\r\n",
|
||||
platform_i2c->port, platform_i2c->config.freq,
|
||||
platform_i2c->config.address_width, platform_i2c->config.mode);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_ioctl_enable(pika_dev* dev) {
|
||||
if (!dev->is_enabled) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Enable IIC%d on SCL:P%d, SDA:P%d\r\n",
|
||||
platform_i2c->port, platform_i2c->config.scl,
|
||||
platform_i2c->config.sda);
|
||||
#endif
|
||||
hosal_i2c_init(platform_i2c);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_ioctl_disable(pika_dev* dev) {
|
||||
if (dev->is_enabled) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
hosal_i2c_finalize(platform_i2c);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_write(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
pika_hal_IIC_config* cfg = (pika_hal_IIC_config*)dev->ioctl_config;
|
||||
if (!cfg->mem_addr_ena) {
|
||||
return hosal_i2c_master_send(platform_i2c, cfg->slave_addr, buf, count,
|
||||
cfg->timeout);
|
||||
#ifdef PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Write %d bytes to 0x%02x\r\n", count,
|
||||
cfg->slave_addr);
|
||||
#endif
|
||||
} else {
|
||||
return hosal_i2c_mem_write(platform_i2c, cfg->slave_addr, cfg->mem_addr,
|
||||
cfg->mem_addr_size, buf, count,
|
||||
cfg->timeout);
|
||||
#ifdef PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Write %d bytes to 0x%02x, mem_addr:0x%02x\r\n",
|
||||
count, cfg->slave_addr, cfg->mem_addr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
pika_hal_IIC_config* cfg = (pika_hal_IIC_config*)dev->ioctl_config;
|
||||
if (!cfg->mem_addr_ena) {
|
||||
return hosal_i2c_master_recv(platform_i2c, cfg->slave_addr, buf, count,
|
||||
cfg->timeout);
|
||||
#ifdef PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Read %d bytes from 0x%02x\r\n", count,
|
||||
cfg->slave_addr);
|
||||
#endif
|
||||
} else {
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Read %d bytes from 0x%02x, mem_addr:0x%02x\r\n",
|
||||
count, cfg->slave_addr, cfg->mem_addr);
|
||||
#endif
|
||||
return hosal_i2c_mem_read(platform_i2c, cfg->slave_addr, cfg->mem_addr,
|
||||
cfg->mem_addr_size, buf, count, cfg->timeout);
|
||||
}
|
||||
}
|
94
package/BLIOT/pika_hal_BLIOT_PWM.c
Normal file
94
package/BLIOT/pika_hal_BLIOT_PWM.c
Normal file
@ -0,0 +1,94 @@
|
||||
#include <hosal_pwm.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
#define PWM_CHANNAL_MAX 5
|
||||
int pika_hal_platform_PWM_open(pika_dev* dev, char* name) {
|
||||
dev->platform_data = pikaMalloc(sizeof(hosal_pwm_dev_t));
|
||||
memset(dev->platform_data, 0, sizeof(hosal_pwm_dev_t));
|
||||
hosal_pwm_dev_t* platform_pwm = (hosal_pwm_dev_t*)dev->platform_data;
|
||||
/* support P0/P1 ... */
|
||||
if (name[0] == 'P') {
|
||||
platform_pwm->config.pin = fast_atoi(name + 1);
|
||||
platform_pwm->port = platform_pwm->config.pin % PWM_CHANNAL_MAX;
|
||||
} else {
|
||||
__platform_printf("Error: pwm name error.\r\n");
|
||||
__platform_printf("Require: Px (x: 0~24)\r\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_PWM_close(pika_dev* dev) {
|
||||
pikaFree(dev->platform_data, sizeof(hosal_pwm_dev_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_PWM_read(pika_dev* dev, void* buf, size_t count) {
|
||||
/* not support */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_PWM_write(pika_dev* dev, void* buf, size_t count) {
|
||||
/* not support */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_PWM_ioctl_enable(pika_dev* dev) {
|
||||
hosal_pwm_dev_t* platform_pwm = (hosal_pwm_dev_t*)dev->platform_data;
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("is enable %d\r\n", dev->is_enabled);
|
||||
#endif
|
||||
if (!dev->is_enabled) {
|
||||
// printf("pwm enable\r\n");
|
||||
hosal_pwm_init(platform_pwm);
|
||||
hosal_pwm_start(platform_pwm);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_PWM_ioctl_disable(pika_dev* dev) {
|
||||
hosal_pwm_dev_t* platform_pwm = (hosal_pwm_dev_t*)dev->platform_data;
|
||||
if (dev->is_enabled) {
|
||||
hosal_pwm_stop(platform_pwm);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define PERIOD_TO_FREQ(period) \
|
||||
((uint32_t)(pika_float)1000 * 1000 * 1000 / (pika_float)period)
|
||||
#define DUTY_TUO_DUTY_CYCLE(duty, period) \
|
||||
(uint32_t)((pika_float)duty * (pika_float)10000 / (pika_float)period)
|
||||
|
||||
int pika_hal_platform_PWM_ioctl_config(pika_dev* dev,
|
||||
pika_hal_PWM_config* cfg) {
|
||||
hosal_pwm_dev_t* platform_pwm = (hosal_pwm_dev_t*)dev->platform_data;
|
||||
uint32_t freq = PERIOD_TO_FREQ(cfg->period);
|
||||
uint32_t duty_cycle = DUTY_TUO_DUTY_CYCLE(cfg->duty, cfg->period);
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("freq: %d, duty_cycle: %d\r\n", freq, duty_cycle);
|
||||
#endif
|
||||
/* not enabled */
|
||||
if (!dev->is_enabled) {
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("not enabled, just config\r\n");
|
||||
#endif
|
||||
// MHz
|
||||
platform_pwm->config.freq = freq;
|
||||
// 0 ~ 10000(0 ~ 100%)
|
||||
platform_pwm->config.duty_cycle = duty_cycle;
|
||||
return 0;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("enabled, change config\r\n");
|
||||
#endif
|
||||
/* enabled */
|
||||
if (platform_pwm->config.freq != freq ||
|
||||
platform_pwm->config.duty_cycle != duty_cycle) {
|
||||
hosal_pwm_config_t para;
|
||||
para.duty_cycle = duty_cycle;
|
||||
para.freq = freq;
|
||||
hosal_pwm_para_chg(platform_pwm, para);
|
||||
}
|
||||
return 0;
|
||||
}
|
129
package/BLIOT/pika_hal_BLIOT_SPI.c
Normal file
129
package/BLIOT/pika_hal_BLIOT_SPI.c
Normal file
@ -0,0 +1,129 @@
|
||||
#include <hosal_spi.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
|
||||
static int _num2pin(int num, uint8_t* mosi, uint8_t* miso, uint8_t* scli) {
|
||||
/*********************** BL602 **************************
|
||||
* SPI0 -----> MOSI:P20, MISO:P0, SCLK:P22
|
||||
*/
|
||||
switch (num) {
|
||||
case 0:
|
||||
*mosi = 20;
|
||||
*miso = 0;
|
||||
*scli = 22;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("SPI%d: mosi:%d, miso:%d, scli:%d\r\n", num, *mosi, *miso,
|
||||
*scli);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_open(pika_dev* dev, char* name) {
|
||||
hosal_spi_dev_t* platform_spi = pikaMalloc(sizeof(hosal_spi_dev_t));
|
||||
memset(platform_spi, 0, sizeof(hosal_spi_dev_t));
|
||||
dev->platform_data = platform_spi;
|
||||
/* Support SPI0, SPI1, SPI2 */
|
||||
if (name[0] == 'S' && name[1] == 'P' && name[2] == 'I') {
|
||||
int spi_num = fast_atoi(name + 3);
|
||||
platform_spi->port = 0;
|
||||
if (0 == _num2pin(spi_num, &platform_spi->config.pin_mosi,
|
||||
&platform_spi->config.pin_miso,
|
||||
&platform_spi->config.pin_clk)) {
|
||||
return 0;
|
||||
} else {
|
||||
__platform_printf("SPI: Open SPI%d failed\r\n", spi_num);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_close(pika_dev* dev) {
|
||||
hosal_spi_dev_t* platform_spi = (hosal_spi_dev_t*)dev->platform_data;
|
||||
if (NULL != platform_spi) {
|
||||
pikaFree(platform_spi, sizeof(hosal_spi_dev_t));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_ioctl_config(pika_dev* dev,
|
||||
pika_hal_SPI_config* cfg) {
|
||||
hosal_spi_dev_t* platform_spi = (hosal_spi_dev_t*)dev->platform_data;
|
||||
if (!dev->is_enabled) {
|
||||
platform_spi->port = 0;
|
||||
platform_spi->config.dma_enable = 0;
|
||||
platform_spi->config.freq = cfg->speed;
|
||||
platform_spi->p_arg = NULL;
|
||||
switch (cfg->master_or_slave) {
|
||||
case PIKA_HAL_SPI_MASTER:
|
||||
platform_spi->config.mode = HOSAL_SPI_MODE_MASTER;
|
||||
break;
|
||||
case PIKA_HAL_SPI_SLAVE:
|
||||
platform_spi->config.mode = HOSAL_SPI_MODE_SLAVE;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
switch (cfg->mode) {
|
||||
case PIKA_HAL_SPI_MODE_0:
|
||||
platform_spi->config.polar_phase = 0;
|
||||
break;
|
||||
case PIKA_HAL_SPI_MODE_1:
|
||||
platform_spi->config.polar_phase = 1;
|
||||
break;
|
||||
case PIKA_HAL_SPI_MODE_2:
|
||||
platform_spi->config.polar_phase = 2;
|
||||
break;
|
||||
case PIKA_HAL_SPI_MODE_3:
|
||||
platform_spi->config.polar_phase = 3;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("SPI: freq:%d, mode:%d, polar_phase:%d\r\n",
|
||||
platform_spi->config.freq, platform_spi->config.mode,
|
||||
platform_spi->config.polar_phase);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_ioctl_enable(pika_dev* dev) {
|
||||
if (!dev->is_enabled) {
|
||||
hosal_spi_dev_t* platform_spi = (hosal_spi_dev_t*)dev->platform_data;
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf(
|
||||
"SPI: Open SPI%d, freq:%d, mode:%d, polar_phase:%d\r\n",
|
||||
platform_spi->port, platform_spi->config.freq,
|
||||
platform_spi->config.mode, platform_spi->config.polar_phase);
|
||||
#endif
|
||||
hosal_spi_init(platform_spi);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_ioctl_disable(pika_dev* dev) {
|
||||
if (dev->is_enabled) {
|
||||
hosal_spi_dev_t* platform_spi = (hosal_spi_dev_t*)dev->platform_data;
|
||||
hosal_spi_finalize(platform_spi);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_write(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_spi_dev_t* platform_spi = (hosal_spi_dev_t*)dev->platform_data;
|
||||
pika_hal_SPI_config* cfg = (pika_hal_SPI_config*)dev->ioctl_config;
|
||||
return hosal_spi_send(platform_spi, buf, count, cfg->timeout);
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_read(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_spi_dev_t* platform_spi = (hosal_spi_dev_t*)dev->platform_data;
|
||||
pika_hal_SPI_config* cfg = (pika_hal_SPI_config*)dev->ioctl_config;
|
||||
return hosal_spi_recv(platform_spi, buf, count, cfg->timeout);
|
||||
}
|
@ -3,17 +3,8 @@ PikaStdDevice is a standard and abstract device module for PikaScript.
|
||||
|
||||
PikaStdDevice supplies the standard device API for users.
|
||||
|
||||
Users need to inherit from PikaStdDevice and override the abstract methods, which is with the `@abstractmethod` decorator.
|
||||
Document: https://pikadoc.readthedocs.io/en/latest/PikaStdDevice%20%E6%A0%87%E5%87%86%E8%AE%BE%E5%A4%87.html
|
||||
|
||||
For example, the STM32F1 device module: https://gitee.com/Lyon1998/pikascript/blob/master/package/STM32F1/STM32F1.pyi
|
||||
|
||||
And for convenience, make a machine.pyi to inherit from STM32F1 device module for alias purpose.
|
||||
|
||||
For example:
|
||||
|
||||
- The machine.pyi for STM32F1:https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32f103c8/pikascript/machine.pyi
|
||||
|
||||
- The machine.pyi for STM32G0: https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32g070cb/pikascript/machine.pyi
|
||||
"""
|
||||
from PikaObj import *
|
||||
|
||||
@ -169,6 +160,24 @@ class ADC(BaseDev):
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class DAC(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setPin(self, pin: str):
|
||||
"""
|
||||
Use the name of the pin to select the DAC pin.
|
||||
example: `"PA0"`, `"PA1"` ...
|
||||
"""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the DAC."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the DAC."""
|
||||
|
||||
def write(self, val:float):
|
||||
"""write the DAC value."""
|
||||
|
||||
class UART(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
|
@ -27,14 +27,43 @@ void PikaStdDevice_ADC_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_ADC, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open ADC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open ADC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
return;
|
||||
}
|
||||
pika_hal_ADC_config cfg = {0};
|
||||
cfg.continue_or_single = PIKA_HAL_ADC_SINGLE;
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformRead(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ADC_config* cfg = (pika_hal_ADC_config*)dev->ioctl_config;
|
||||
uint32_t val_i = 0;
|
||||
pika_hal_read(dev, &val_i, sizeof(val_i));
|
||||
pika_float val = (pika_float)val_i / (pika_float)cfg->max * cfg->vref;
|
||||
val = val_i * obj_setFloat(self, "val", val);
|
||||
}
|
||||
|
48
package/PikaStdDevice/PikaStdDevice_DAC.c
Normal file
48
package/PikaStdDevice/PikaStdDevice_DAC.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include "PikaStdDevice_DAC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_DAC, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open DAC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_enable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_DAC_config cfg = {0};
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_disable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC___init__(PikaObj* self) {
|
||||
PikaStdDevice_DAC_init(self);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_write(PikaObj* self, pika_float val) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_DAC_config* cfg = (pika_hal_DAC_config*)dev->ioctl_config;
|
||||
uint32_t val_i = (val / cfg->vref) * cfg->max;
|
||||
pika_hal_write(dev, &val_i, sizeof val_i);
|
||||
}
|
@ -84,7 +84,8 @@ static pika_dev* _get_dev(PikaObj* self){
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_GPIO, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n", obj_getStr(self, "pin"));
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
|
@ -44,20 +44,6 @@ int PikaStdDevice_PWM_getFrequency(PikaObj* self) {
|
||||
return obj_getInt(self, "freq");
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
char* PikaStdDevice_PWM_getName(PikaObj* self) {
|
||||
return obj_getStr(self, "name");
|
||||
}
|
||||
@ -77,3 +63,46 @@ int PikaStdDevice_PWM_getChannel(PikaObj* self) {
|
||||
void PikaStdDevice_PWM_setFreq(PikaObj* self, int freq) {
|
||||
PikaStdDevice_PWM_setFrequency(self, freq);
|
||||
}
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_PWM, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open PWM '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
|
||||
pika_float duty = obj_getFloat(self, "duty"); // 0.0 ~ 1.0
|
||||
uint32_t freq = obj_getInt(self, "freq"); // Hz
|
||||
pika_hal_PWM_config cfg = {0};
|
||||
/* ns */
|
||||
cfg.duty = (uint32_t)(1000000000.0f / freq * duty);
|
||||
pika_hal_ioctl(_get_dev(self), PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
uint32_t freq = obj_getInt(self, "freq"); // Hz
|
||||
pika_float duty = obj_getFloat(self, "duty"); // 0.0 ~ 1.0
|
||||
pika_hal_PWM_config cfg = {0};
|
||||
/* ns */
|
||||
cfg.period = (uint32_t)(1000000000.0f / freq);
|
||||
cfg.duty = (uint32_t)(1000000000.0f / freq * duty);
|
||||
pika_hal_ioctl(_get_dev(self), PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
@ -27,20 +27,23 @@ static size_t _pika_hal_dev_config_size(PIKA_HAL_DEV_TYPE dev_type) {
|
||||
|
||||
pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name) {
|
||||
int ret = -1;
|
||||
pika_dev* dev = NULL;
|
||||
if (dev_type >= _PIKA_DEV_TYPE_MAX) {
|
||||
__platform_printf("Error: dev_type invalied.\r\n");
|
||||
goto __exit;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev_type);
|
||||
pika_dev* dev = (pika_dev*)pikaMalloc(sizeof(pika_dev));
|
||||
dev = (pika_dev*)pikaMalloc(sizeof(pika_dev));
|
||||
if (dev == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
memset(dev, 0, sizeof(pika_dev));
|
||||
dev->type = dev_type;
|
||||
dev->ioctl_config = pikaMalloc(_pika_hal_dev_config_size(dev_type));
|
||||
if (dev->ioctl_config == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
memset(dev->ioctl_config, 0, _pika_hal_dev_config_size(dev_type));
|
||||
ret = impl->open(dev, name);
|
||||
__exit:
|
||||
if (0 == ret) {
|
||||
@ -142,11 +145,19 @@ int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) {
|
||||
config_in = va_arg(args, void*);
|
||||
ret = _pika_hal_ioctl_merge_config(dev, config_in);
|
||||
va_end(args);
|
||||
}
|
||||
if (0 != ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
ret = impl->ioctl(dev, cmd_origin, dev->ioctl_config);
|
||||
if (ret == 0) {
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_ENABLE) {
|
||||
dev->is_enabled = 1;
|
||||
}
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_DISABLE) {
|
||||
dev->is_enabled = 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -160,12 +171,14 @@ int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) {
|
||||
} \
|
||||
} else { \
|
||||
/* use input value */ \
|
||||
src->item = dst->item; \
|
||||
dst->item = src->item; \
|
||||
}
|
||||
|
||||
int pika_hal_GPIO_ioctl_merge_config(pika_hal_GPIO_config* dst,
|
||||
pika_hal_GPIO_config* src) {
|
||||
// printf("before merge: dst->dir=%d, src->dir=%d\r\n", dst->dir, src->dir);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(dir, PIKA_HAL_GPIO_DIR_IN);
|
||||
// printf("after merge: dst->dir=%d, src->dir=%d\r\n", dst->dir, src->dir);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(pull, PIKA_HAL_GPIO_PULL_NONE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_GPIO_SPEED_10M);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_rising, NULL);
|
||||
@ -190,27 +203,46 @@ int pika_hal_SPI_ioctl_merge_config(pika_hal_SPI_config* dst,
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mode, PIKA_HAL_SPI_MODE_0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(data_width, PIKA_HAL_SPI_DATA_WIDTH_8);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_SPI_SPEED_2M);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_SPI_TIMEOUT_1000MS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_IIC_ioctl_merge_config(pika_hal_IIC_config* dst,
|
||||
pika_hal_IIC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(addr, 0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(address_width, PIKA_HAL_IIC_ADDRESS_WIDTH_7BIT);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(master_or_slave, PIKA_HAL_IIC_MASTER);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(slave_addr, 0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mem_addr_ena, PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mem_addr_size, PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT);
|
||||
dst->mem_addr = src->mem_addr;
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_IIC_SPEED_100K);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_IIC_TIMEOUT_1000MS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_PWM_ioctl_merge_config(pika_hal_PWM_config* dst,
|
||||
pika_hal_PWM_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(channel, PIKA_HAL_PWM_CHANNEL_0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(period, PIKA_HAL_PWM_PERIOD_1MS * 10);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(duty, PIKA_HAL_PWM_PERIOD_1MS * 5);
|
||||
// _IOCTL_CONFIG_USE_DEFAULT(duty, 0);
|
||||
dst->duty = src->duty;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_ADC_ioctl_merge_config(pika_hal_ADC_config* dst,
|
||||
pika_hal_ADC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(channel, PIKA_HAL_ADC_CHANNEL_0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(resolution, PIKA_HAL_ADC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_resolution, PIKA_HAL_ADC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_freq, PIKA_HAL_ADC_SAMPLING_FREQ_100);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(continue_or_single, PIKA_HAL_ADC_SINGLE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(vref, (pika_float)3.3);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 8192);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_DAC_ioctl_merge_config(pika_hal_DAC_config* dst,
|
||||
pika_hal_DAC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_DAC_SPEED_1K * 8);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_resolution, PIKA_HAL_DAC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(vref, (pika_float)3.3);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 3300000);
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define _PIKA_DEV_HAL_H
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
/*
|
||||
* pika_hal is a C Device HAL lib for PikaScript modules.
|
||||
@ -15,6 +16,7 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_DEV_TYPE type;
|
||||
PIKA_BOOL is_enabled;
|
||||
void* ioctl_config;
|
||||
void* platform_data;
|
||||
} pika_dev;
|
||||
@ -105,6 +107,21 @@ typedef struct {
|
||||
} pika_hal_UART_config;
|
||||
|
||||
typedef uint32_t PIKA_HAL_IIC_SLAVE_ADDR;
|
||||
typedef uint32_t PIKA_HAL_IIC_MEM_ADDR;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MEM_ADDR_SIZE {
|
||||
_PIKA_HAL_IIC_MEM_ADDR_SIZE_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT = 1,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_16BIT = 2,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_24BIT = 3,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_32BIT = 4,
|
||||
} PIKA_HAL_IIC_MEM_ADDR_SIZE;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MEM_ADDR_ENA {
|
||||
_PIKA_HAL_IIC_MEM_ADDR_ENA_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE,
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE,
|
||||
} PIKA_HAL_IIC_MEM_ADDR_ENA;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_IIC_SPEED_UNUSED = 0,
|
||||
@ -113,11 +130,57 @@ typedef enum {
|
||||
PIKA_HAL_IIC_SPEED_1M = 1000000,
|
||||
} PIKA_HAL_IIC_SPEED;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MASTER_OR_SLAVE {
|
||||
_PIKA_HAL_IIC_MASTER_OR_SLAVE_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MASTER,
|
||||
PIKA_HAL_IIC_SLAVE,
|
||||
} PIKA_HAL_IIC_MASTER_OR_SLAVE;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_ADDRESS_WIDTH {
|
||||
_PIKA_HAL_IIC_ADDRESS_WIDTH_UNUSED = 0,
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH_7BIT = 7,
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH_10BIT = 10,
|
||||
} PIKA_HAL_IIC_ADDRESS_WIDTH;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_TIMEOUT {
|
||||
_PIKA_HAL_IIC_TIMEOUT_UNUSED = 0,
|
||||
PIKA_HAL_IIC_TIMEOUT_1MS = 1,
|
||||
PIKA_HAL_IIC_TIMEOUT_2MS = 2,
|
||||
PIKA_HAL_IIC_TIMEOUT_5MS = 5,
|
||||
PIKA_HAL_IIC_TIMEOUT_10MS = 10,
|
||||
PIKA_HAL_IIC_TIMEOUT_20MS = 20,
|
||||
PIKA_HAL_IIC_TIMEOUT_50MS = 50,
|
||||
PIKA_HAL_IIC_TIMEOUT_100MS = 100,
|
||||
PIKA_HAL_IIC_TIMEOUT_200MS = 200,
|
||||
PIKA_HAL_IIC_TIMEOUT_500MS = 500,
|
||||
PIKA_HAL_IIC_TIMEOUT_1000MS = 1000,
|
||||
} PIKA_HAL_IIC_TIMEOUT;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_IIC_SLAVE_ADDR addr;
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH address_width;
|
||||
PIKA_HAL_IIC_MASTER_OR_SLAVE master_or_slave;
|
||||
PIKA_HAL_IIC_SLAVE_ADDR slave_addr;
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA mem_addr_ena;
|
||||
PIKA_HAL_IIC_MEM_ADDR mem_addr;
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE mem_addr_size;
|
||||
PIKA_HAL_IIC_SPEED speed;
|
||||
PIKA_HAL_IIC_TIMEOUT timeout;
|
||||
} pika_hal_IIC_config;
|
||||
|
||||
typedef enum PIKA_HAL_SPI_TIMEOUT {
|
||||
_PIKA_HAL_SPI_TIMEOUT_UNUSED = 0,
|
||||
PIKA_HAL_SPI_TIMEOUT_1MS = 1,
|
||||
PIKA_HAL_SPI_TIMEOUT_2MS = 2,
|
||||
PIKA_HAL_SPI_TIMEOUT_5MS = 5,
|
||||
PIKA_HAL_SPI_TIMEOUT_10MS = 10,
|
||||
PIKA_HAL_SPI_TIMEOUT_20MS = 20,
|
||||
PIKA_HAL_SPI_TIMEOUT_50MS = 50,
|
||||
PIKA_HAL_SPI_TIMEOUT_100MS = 100,
|
||||
PIKA_HAL_SPI_TIMEOUT_200MS = 200,
|
||||
PIKA_HAL_SPI_TIMEOUT_500MS = 500,
|
||||
PIKA_HAL_SPI_TIMEOUT_1000MS = 1000,
|
||||
} PIKA_HAL_SPI_TIMEOUT;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_LSB_OR_MSB_UNUSED = 0,
|
||||
PIKA_HAL_SPI_LSB,
|
||||
@ -161,22 +224,9 @@ typedef struct {
|
||||
PIKA_HAL_SPI_MODE mode;
|
||||
PIKA_HAL_SPI_DATA_WIDTH data_width;
|
||||
PIKA_HAL_SPI_SPEED speed;
|
||||
PIKA_HAL_SPI_TIMEOUT timeout;
|
||||
} pika_hal_SPI_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_ADC_CHANNEL_UNUSED = 0,
|
||||
PIKA_HAL_ADC_CHANNEL_0,
|
||||
PIKA_HAL_ADC_CHANNEL_1,
|
||||
PIKA_HAL_ADC_CHANNEL_2,
|
||||
PIKA_HAL_ADC_CHANNEL_3,
|
||||
PIKA_HAL_ADC_CHANNEL_4,
|
||||
PIKA_HAL_ADC_CHANNEL_5,
|
||||
PIKA_HAL_ADC_CHANNEL_6,
|
||||
PIKA_HAL_ADC_CHANNEL_7,
|
||||
PIKA_HAL_ADC_CHANNEL_TEMP,
|
||||
PIKA_HAL_ADC_CHANNEL_VBAT,
|
||||
} PIKA_HAL_ADC_CHANNEL;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_ADC_RESOLUTION_UNUSED = 0,
|
||||
PIKA_HAL_ADC_RESOLUTION_8 = 8,
|
||||
@ -186,11 +236,65 @@ typedef enum {
|
||||
PIKA_HAL_ADC_RESOLUTION_16 = 16,
|
||||
} PIKA_HAL_ADC_RESOLUTION;
|
||||
|
||||
typedef enum PIKA_HAL_ADC_SAMPLING_FREQ {
|
||||
_PIKA_HAL_ADC_SAMPLING_FREQ_UNUSED = 0,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_100 = 100,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_1K = 1000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_10K = 10000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_100K = 100000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_1M = 1000000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_10M = 10000000,
|
||||
} PIKA_HAL_ADC_SAMPLING_FREQ;
|
||||
|
||||
typedef enum PIKA_HAL_ADC_CONTINUOU_OR_SINGLE {
|
||||
_PIKA_HAL_ADC_CONTINUOU_OR_SINGLE_UNUSED = 0,
|
||||
PIKA_HAL_ADC_SINGLE,
|
||||
PIKA_HAL_ADC_CONTINUOU,
|
||||
} PIKA_HAL_ADC_CONTINUOU_OR_SINGLE;
|
||||
|
||||
typedef pika_float PIKA_HAL_ADC_VREF;
|
||||
typedef uint32_t PIKA_HAL_ADC_MAX;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_ADC_CHANNEL channel;
|
||||
PIKA_HAL_ADC_RESOLUTION resolution;
|
||||
PIKA_HAL_ADC_RESOLUTION sampling_resolution;
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ sampling_freq;
|
||||
PIKA_HAL_ADC_CONTINUOU_OR_SINGLE continue_or_single;
|
||||
PIKA_HAL_ADC_MAX max;
|
||||
PIKA_HAL_ADC_VREF vref;
|
||||
} pika_hal_ADC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_DAC_RESOLUTION_UNUSED = 0,
|
||||
PIKA_HAL_DAC_RESOLUTION_8 = 8,
|
||||
PIKA_HAL_DAC_RESOLUTION_10 = 10,
|
||||
PIKA_HAL_DAC_RESOLUTION_12 = 12,
|
||||
PIKA_HAL_DAC_RESOLUTION_14 = 14,
|
||||
PIKA_HAL_DAC_RESOLUTION_16 = 16,
|
||||
} PIKA_HAL_DAC_RESOLUTION;
|
||||
|
||||
typedef enum PIKA_HAL_DAC_SPEED {
|
||||
_PIKA_HAL_DAC_SPEED_UNUSED = 0,
|
||||
PIKA_HAL_DAC_SPEED_100 = 100,
|
||||
PIKA_HAL_DAC_SPEED_1K = 1000,
|
||||
PIKA_HAL_DAC_SPEED_10K = 10000,
|
||||
PIKA_HAL_DAC_SPEED_100K = 100000,
|
||||
PIKA_HAL_DAC_SPEED_1M = 1000000,
|
||||
PIKA_HAL_DAC_SPEED_10M = 10000000,
|
||||
PIKA_HAL_DAC_SPEED_20M = 20000000,
|
||||
PIKA_HAL_DAC_SPEED_50M = 50000000,
|
||||
PIKA_HAL_DAC_SPEED_100M = 100000000,
|
||||
} PIKA_HAL_DAC_SPEED;
|
||||
|
||||
typedef pika_float PIKA_HAL_DAC_VREF;
|
||||
typedef uint32_t PIKA_HAL_DAC_MAX;
|
||||
|
||||
typedef struct pika_hal_DAC_config {
|
||||
PIKA_HAL_DAC_RESOLUTION sampling_resolution;
|
||||
PIKA_HAL_DAC_SPEED speed;
|
||||
PIKA_HAL_DAC_MAX max;
|
||||
PIKA_HAL_DAC_VREF vref;
|
||||
} pika_hal_DAC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_DAC_UNUSED = 0,
|
||||
PIKA_HAL_PWM_CHANNEL_0,
|
||||
@ -218,7 +322,6 @@ typedef enum {
|
||||
} PIKA_HAL_PWM_DUTY;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_PWM_CHANNEL channel;
|
||||
PIKA_HAL_PWM_PERIOD period;
|
||||
PIKA_HAL_PWM_DUTY duty;
|
||||
} pika_hal_PWM_config;
|
||||
|
@ -7,6 +7,7 @@ pika_hal_table_add(UART)
|
||||
pika_hal_table_add(IIC)
|
||||
pika_hal_table_add(SPI)
|
||||
pika_hal_table_add(ADC)
|
||||
pika_hal_table_add(DAC)
|
||||
pika_hal_table_add(PWM)
|
||||
|
||||
/* clang-format on */
|
||||
|
@ -133,6 +133,7 @@ class String:
|
||||
def split(self, s: str) -> List: ...
|
||||
def replace(self, old: str, new: str) -> str: ...
|
||||
def strip(self, *chrs) -> str: ...
|
||||
def format(self, *vars) -> str: ...
|
||||
|
||||
|
||||
class ByteArray:
|
||||
@ -155,7 +156,7 @@ class ByteArray:
|
||||
|
||||
class FILEIO:
|
||||
def init(self, path: str, mode: str) -> int: ...
|
||||
def read(self, size: int) -> any: ...
|
||||
def read(self, *size) -> any: ...
|
||||
def write(self, s: any) -> int: ...
|
||||
def close(self): ...
|
||||
def seek(self, offset: int, *fromwhere) -> int: ...
|
||||
|
@ -1,12 +1,37 @@
|
||||
#include "PikaStdData_FILEIO.h"
|
||||
#include <stdio.h>
|
||||
#include "PikaCompiler.h"
|
||||
#include "PikaStdData_List.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t* addr;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
} PIKAFS_FILE;
|
||||
|
||||
int PikaStdData_FILEIO_init(PikaObj* self, char* path, char* mode) {
|
||||
if (obj_isArgExist(self, "_f")) {
|
||||
/* already initialized */
|
||||
return 0;
|
||||
}
|
||||
if (strIsStartWith(path, "pikafs/")) {
|
||||
PIKAFS_FILE* f = (PIKAFS_FILE*)pikaMalloc(sizeof(PIKAFS_FILE));
|
||||
memset(f, 0, sizeof(PIKAFS_FILE));
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
uint8_t* library_bytes = obj_getPtr((PikaObj*)__pikaMain, "@libraw");
|
||||
if (NULL == library_bytes) {
|
||||
return 1;
|
||||
}
|
||||
char* file_name = path + 7;
|
||||
if (PIKA_RES_OK != _loadModuleDataWithName(library_bytes, file_name,
|
||||
&f->addr, &f->size)) {
|
||||
return 1;
|
||||
}
|
||||
obj_setInt(self, "pikafs", PIKA_TRUE);
|
||||
obj_setPtr(self, "_f", f);
|
||||
obj_setStr(self, "_mode", mode);
|
||||
return 0;
|
||||
}
|
||||
FILE* f = __platform_fopen(path, mode);
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
@ -17,27 +42,63 @@ int PikaStdData_FILEIO_init(PikaObj* self, char* path, char* mode) {
|
||||
}
|
||||
|
||||
void PikaStdData_FILEIO_close(PikaObj* self) {
|
||||
if (PIKA_TRUE == obj_getInt(self, "pikafs")) {
|
||||
PIKAFS_FILE* f = obj_getPtr(self, "_f");
|
||||
if (NULL == f) {
|
||||
return;
|
||||
}
|
||||
pikaFree(f, sizeof(PIKAFS_FILE));
|
||||
obj_setPtr(self, "_f", NULL);
|
||||
return;
|
||||
}
|
||||
FILE* f = obj_getPtr(self, "_f");
|
||||
if (f == NULL) {
|
||||
if (NULL == f) {
|
||||
return;
|
||||
}
|
||||
__platform_fclose(f);
|
||||
obj_setPtr(self, "_f", NULL);
|
||||
}
|
||||
|
||||
Arg* PikaStdData_FILEIO_read(PikaObj* self, int size) {
|
||||
size_t _pikafs_fread(void* buf, size_t size, size_t count, PIKAFS_FILE* f) {
|
||||
if (f->pos >= f->size) {
|
||||
return 0;
|
||||
}
|
||||
if (f->pos + size * count > f->size) {
|
||||
count = (f->size - f->pos) / size;
|
||||
}
|
||||
__platform_memcpy(buf, f->addr + f->pos, size * count);
|
||||
f->pos += size * count;
|
||||
return count;
|
||||
}
|
||||
|
||||
Arg* PikaStdData_FILEIO_read(PikaObj* self, PikaTuple* size_) {
|
||||
int size = 0;
|
||||
if (pikaTuple_getSize(size_) == 0) {
|
||||
size = -1;
|
||||
} else {
|
||||
size = pikaTuple_getInt(size_, 0);
|
||||
}
|
||||
if (size <= 0) {
|
||||
/* read all */
|
||||
size = PIKA_READ_FILE_BUFF_SIZE;
|
||||
}
|
||||
Arg* buf_arg = arg_newBytes(NULL, size);
|
||||
uint8_t* buf = arg_getBytes(buf_arg);
|
||||
int n = 0;
|
||||
/* read */
|
||||
if (PIKA_TRUE == obj_getInt(self, "pikafs")) {
|
||||
PIKAFS_FILE* f = obj_getPtr(self, "_f");
|
||||
if (NULL == f) {
|
||||
return NULL;
|
||||
}
|
||||
n = _pikafs_fread(buf, 1, size, f);
|
||||
} else {
|
||||
FILE* f = obj_getPtr(self, "_f");
|
||||
if (f == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
Arg* buf_arg = arg_newBytes(NULL, size);
|
||||
uint8_t* buf = arg_getBytes(buf_arg);
|
||||
/* read */
|
||||
int n = __platform_fread(buf, 1, size, f);
|
||||
n = __platform_fread(buf, 1, size, f);
|
||||
}
|
||||
if (n < size) {
|
||||
/* EOF */
|
||||
buf[n] = '\0';
|
||||
@ -57,6 +118,9 @@ Arg* PikaStdData_FILEIO_read(PikaObj* self, int size) {
|
||||
}
|
||||
|
||||
int PikaStdData_FILEIO_write(PikaObj* self, Arg* s) {
|
||||
if (PIKA_TRUE == obj_getInt(self, "pikafs")) {
|
||||
return 1;
|
||||
}
|
||||
FILE* f = obj_getPtr(self, "_f");
|
||||
int res = -1;
|
||||
if (f == NULL) {
|
||||
@ -66,6 +130,12 @@ int PikaStdData_FILEIO_write(PikaObj* self, Arg* s) {
|
||||
}
|
||||
char* mode = obj_getStr(self, "_mode");
|
||||
if (strIsContain(mode, 'b')) {
|
||||
if (arg_getType(s) != ARG_TYPE_BYTES) {
|
||||
__platform_printf(
|
||||
"TypeError: a bytes-like object is required, not 'str'\r\n");
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_INVALID_PARAM);
|
||||
return -1;
|
||||
}
|
||||
/* binary */
|
||||
res = __platform_fwrite(arg_getBytes(s), 1, arg_getBytesSize(s), f);
|
||||
} else {
|
||||
|
@ -810,3 +810,8 @@ char* _strlwr(char* str) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char* PikaStdData_String_format(PikaObj* self, PikaTuple* vars) {
|
||||
/* 'test{}'.format(123) */
|
||||
return NULL;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ Arg* PikaStdData_Tuple___next__(PikaObj* self) {
|
||||
}
|
||||
|
||||
Arg* PikaStdData_Tuple___getitem__(PikaObj* self, Arg* __key) {
|
||||
return PikaStdData_Tuple_get(self, obj_getInt(self, "__key"));
|
||||
return PikaStdData_Tuple_get(self, arg_getInt(__key));
|
||||
}
|
||||
|
||||
void PikaStdData_Tuple___del__(PikaObj* self) {
|
||||
|
@ -115,6 +115,10 @@ class SysObj:
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def input(*info) -> str: ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def help(name: str): ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("0")
|
||||
class RangeObj:
|
||||
|
@ -671,3 +671,10 @@ char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
|
||||
arg_deinit(cfg.context);
|
||||
return res;
|
||||
}
|
||||
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
void PikaStdLib_SysObj_help(PikaObj* self, char* name) {
|
||||
if (strEqu(name, "modules")) {
|
||||
obj_printModules((PikaObj*)__pikaMain);
|
||||
}
|
||||
}
|
||||
|
7
package/aes/_aes.pyi
Normal file
7
package/aes/_aes.pyi
Normal file
@ -0,0 +1,7 @@
|
||||
class AES:
|
||||
MODE_ECB: int
|
||||
MODE_CBC: int
|
||||
def __init__(self): ...
|
||||
def new(self, password:any, mode:int, iv:any): ...
|
||||
def encrypt(self, msg:any) -> any: ...
|
||||
def decrypt(self, msg:any) -> any: ...
|
149
package/aes/_aes_AES.c
Normal file
149
package/aes/_aes_AES.c
Normal file
@ -0,0 +1,149 @@
|
||||
#include "_aes_AES.h"
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
enum {
|
||||
MODE_ECB,
|
||||
MODE_CBC,
|
||||
} pika_aes_t;
|
||||
|
||||
void _aes_AES___init__(PikaObj* self) {
|
||||
obj_setInt(self, "MODE_ECB", MODE_ECB);
|
||||
obj_setInt(self, "MODE_CBC", MODE_CBC);
|
||||
}
|
||||
|
||||
void _aes_AES_new(PikaObj* self, Arg* password, int mode, Arg* iv) {
|
||||
ArgType t;
|
||||
mbedtls_aes_context context;
|
||||
|
||||
t = arg_getType(password);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
t = arg_getType(iv);
|
||||
if (ARG_TYPE_NONE != t) {
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
} else {
|
||||
size_t len = arg_getBytesSize(iv);
|
||||
if (len != 16) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
} else {
|
||||
obj_setBytes(self, "_iv", arg_getBytes(iv), len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obj_setBytes(self, "_password", arg_getBytes(password),
|
||||
arg_getBytesSize(password));
|
||||
obj_setInt(self, "_mode", mode);
|
||||
mbedtls_aes_init(&context);
|
||||
obj_setStruct(self, "context", context);
|
||||
}
|
||||
|
||||
Arg* _aes_AES_encrypt(PikaObj* self, Arg* msg) {
|
||||
ArgType t;
|
||||
|
||||
t = arg_getType(msg);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
uint8_t* data = arg_getBytes(msg);
|
||||
uint8_t data_len = arg_getBytesSize(msg);
|
||||
uint8_t mode = obj_getInt(self, "_mode");
|
||||
void* context = obj_getStruct(self, "context");
|
||||
uint8_t* password = obj_getBytes(self, "_password");
|
||||
uint8_t password_len = obj_getBytesSize(self, "_password");
|
||||
uint8_t* iv = obj_getBytes(self, "_iv");
|
||||
uint8_t iv_in[16];
|
||||
|
||||
if (obj_getBytes(self, "_buff") != NULL) {
|
||||
obj_removeArg(self, "_buff");
|
||||
}
|
||||
|
||||
obj_setBytes(self, "_buff", NULL, data_len * sizeof(uint8_t));
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
|
||||
if (mode == MODE_CBC) {
|
||||
if (iv != NULL) {
|
||||
__platform_memcpy(iv_in, iv, 16);
|
||||
} else {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_aes_setkey_enc((mbedtls_aes_context*)context, password,
|
||||
password_len * 8);
|
||||
|
||||
switch (mode) {
|
||||
case MODE_ECB:
|
||||
mbedtls_aes_crypt_ecb((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_ENCRYPT, data, buff);
|
||||
break;
|
||||
case MODE_CBC:
|
||||
mbedtls_aes_crypt_cbc((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_ENCRYPT, data_len, iv_in, data,
|
||||
buff);
|
||||
break;
|
||||
default:
|
||||
__platform_printf("[%s]not support mode\r\n", __FUNCTION__);
|
||||
obj_setErrorCode(self, -3); // not support now
|
||||
break;
|
||||
}
|
||||
return arg_newBytes(buff, data_len);
|
||||
}
|
||||
|
||||
Arg* _aes_AES_decrypt(PikaObj* self, Arg* msg) {
|
||||
ArgType t;
|
||||
|
||||
t = arg_getType(msg);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
uint8_t* data = arg_getBytes(msg);
|
||||
uint8_t data_len = arg_getBytesSize(msg);
|
||||
void* context = obj_getStruct(self, "context");
|
||||
uint8_t mode = obj_getInt(self, "_mode");
|
||||
uint8_t* password = obj_getBytes(self, "_password");
|
||||
uint8_t password_len = obj_getBytesSize(self, "_password");
|
||||
uint8_t* iv = obj_getBytes(self, "_iv");
|
||||
uint8_t iv_in[16];
|
||||
|
||||
if (obj_getBytes(self, "_buff") != NULL) {
|
||||
obj_removeArg(self, "_buff");
|
||||
}
|
||||
|
||||
obj_setBytes(self, "_buff", NULL, data_len * sizeof(uint8_t));
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
|
||||
if (mode == MODE_CBC) {
|
||||
if (iv != NULL) {
|
||||
__platform_memcpy(iv_in, iv, 16);
|
||||
} else {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_aes_setkey_dec((mbedtls_aes_context*)context, password,
|
||||
password_len * 8);
|
||||
|
||||
switch (mode) {
|
||||
case MODE_ECB:
|
||||
mbedtls_aes_crypt_ecb((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_DECRYPT, data, buff);
|
||||
break;
|
||||
case MODE_CBC:
|
||||
mbedtls_aes_crypt_cbc((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_DECRYPT, data_len, iv_in, data,
|
||||
buff);
|
||||
break;
|
||||
default:
|
||||
__platform_printf("[%s]not support mode\r\n", __FUNCTION__);
|
||||
obj_setErrorCode(self, -3); // not support now
|
||||
break;
|
||||
}
|
||||
return arg_newBytes(buff, data_len);
|
||||
}
|
9
package/aes/aes.py
Normal file
9
package/aes/aes.py
Normal file
@ -0,0 +1,9 @@
|
||||
import _aes
|
||||
|
||||
MODE_ECB = _aes.AES.MODE_ECB
|
||||
MODE_CBC = _aes.AES.MODE_CBC
|
||||
|
||||
def new(password:any, mode:int, iv=None) -> _aes.AES:
|
||||
aes = _aes.AES()
|
||||
aes.new(password, mode, iv)
|
||||
return aes
|
@ -73,7 +73,8 @@ releases = [
|
||||
"v1.11.4 4cfb0931f92ca9881963b415d5e8cb7bac33f9f8",
|
||||
"v1.11.5 83afef1906204a7e3f9b773aa8b4bdd46cea4ab9",
|
||||
"v1.11.6 338d385be718d8d11f02aa022103a4b4e9404527",
|
||||
"v1.11.7 50b995c5e4a5beb02220c989f592affba8a9cf89"
|
||||
"v1.11.7 97b8268a31f195092a9ec1d848fbe49168c42c19",
|
||||
"v1.11.8 1a66a70893702174294214d227aee3ec8e4498af"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -139,7 +140,8 @@ releases = [
|
||||
"v1.11.4 4cfb0931f92ca9881963b415d5e8cb7bac33f9f8",
|
||||
"v1.11.5 83afef1906204a7e3f9b773aa8b4bdd46cea4ab9",
|
||||
"v1.11.6 338d385be718d8d11f02aa022103a4b4e9404527",
|
||||
"v1.11.7 50b995c5e4a5beb02220c989f592affba8a9cf89"
|
||||
"v1.11.7 97b8268a31f195092a9ec1d848fbe49168c42c19",
|
||||
"v1.11.8 1a66a70893702174294214d227aee3ec8e4498af"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -167,7 +169,9 @@ releases = [
|
||||
"v1.11.2 95642575a3e17e4c52e28cdbfbef900e02db61e0",
|
||||
"v1.11.7 b7112610bb29109fd7268bf7162004561d73daa1",
|
||||
"v1.11.8 58ff9fe16688be2e77ed220604aa8b1271b72d80",
|
||||
"v2.0.0 e89c585f46ee98811611ea56d5abfc618a41ee3b"
|
||||
"v2.0.0 e89c585f46ee98811611ea56d5abfc618a41ee3b",
|
||||
"v2.1.0 852daad3c9a95dbce54dbf1d2cdb5b2321826b4f",
|
||||
"v2.1.1 5eadba95fa573e3409f65c6392804d3c60d627ac"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -437,3 +441,14 @@ releases = [
|
||||
[[packages]]
|
||||
name = "hmac"
|
||||
releases = [ "v1.0.0 ca8fe36d68be16722317860394fdf78c620e3e2d" ]
|
||||
|
||||
[[packages]]
|
||||
name = "BLIOT"
|
||||
releases = [
|
||||
"v0.1.0 4599ce8681d293a5cc7682115205ab5e85e9b5e8",
|
||||
"v0.2.0 eee8e1848eed77f3ebed777230104ebb4dfc3263"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
name = "aes"
|
||||
releases = [ "v0.0.1 5c45cba0c39d447fbe7a4a082ee3170188c3bcb7" ]
|
||||
|
@ -17,7 +17,7 @@ PikaObj *__pikaMain;
|
||||
PikaObj *pikaScriptInit(void){
|
||||
__platform_printf("======[pikascript packages installed]======\r\n");
|
||||
pks_printVersion();
|
||||
__platform_printf("PikaStdLib==v1.11.7
|
||||
__platform_printf("PikaStdLib==v1.11.8
|
||||
__platform_printf("pika_lvgl==latest\r\n");
|
||||
__platform_printf("===========================================\r\n");
|
||||
__pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
|
@ -1,3 +1,3 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
pika_lvgl==latest
|
@ -1,3 +1,2 @@
|
||||
sh api-make.sh
|
||||
sh only_make.sh
|
||||
cp config/pika_config_default.h config/pika_config.h
|
||||
|
@ -21,3 +21,6 @@ def test_raise(): ...
|
||||
class ProxyTest:
|
||||
def __getattribute__(self, __name: str) -> any: ...
|
||||
def __setattr__(self, __name: str, __value: any): ...
|
||||
|
||||
class _test:
|
||||
def __init__(self):...
|
||||
|
@ -133,6 +133,7 @@ class String:
|
||||
def split(self, s: str) -> List: ...
|
||||
def replace(self, old: str, new: str) -> str: ...
|
||||
def strip(self, *chrs) -> str: ...
|
||||
def format(self, *vars) -> str: ...
|
||||
|
||||
|
||||
class ByteArray:
|
||||
@ -155,7 +156,7 @@ class ByteArray:
|
||||
|
||||
class FILEIO:
|
||||
def init(self, path: str, mode: str) -> int: ...
|
||||
def read(self, size: int) -> any: ...
|
||||
def read(self, *size) -> any: ...
|
||||
def write(self, s: any) -> int: ...
|
||||
def close(self): ...
|
||||
def seek(self, offset: int, *fromwhere) -> int: ...
|
||||
|
@ -3,17 +3,8 @@ PikaStdDevice is a standard and abstract device module for PikaScript.
|
||||
|
||||
PikaStdDevice supplies the standard device API for users.
|
||||
|
||||
Users need to inherit from PikaStdDevice and override the abstract methods, which is with the `@abstractmethod` decorator.
|
||||
Document: https://pikadoc.readthedocs.io/en/latest/PikaStdDevice%20%E6%A0%87%E5%87%86%E8%AE%BE%E5%A4%87.html
|
||||
|
||||
For example, the STM32F1 device module: https://gitee.com/Lyon1998/pikascript/blob/master/package/STM32F1/STM32F1.pyi
|
||||
|
||||
And for convenience, make a machine.pyi to inherit from STM32F1 device module for alias purpose.
|
||||
|
||||
For example:
|
||||
|
||||
- The machine.pyi for STM32F1:https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32f103c8/pikascript/machine.pyi
|
||||
|
||||
- The machine.pyi for STM32G0: https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32g070cb/pikascript/machine.pyi
|
||||
"""
|
||||
from PikaObj import *
|
||||
|
||||
@ -169,6 +160,24 @@ class ADC(BaseDev):
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class DAC(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setPin(self, pin: str):
|
||||
"""
|
||||
Use the name of the pin to select the DAC pin.
|
||||
example: `"PA0"`, `"PA1"` ...
|
||||
"""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the DAC."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the DAC."""
|
||||
|
||||
def write(self, val:float):
|
||||
"""write the DAC value."""
|
||||
|
||||
class UART(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
|
@ -115,6 +115,10 @@ class SysObj:
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def input(*info) -> str: ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def help(name: str): ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("0")
|
||||
class RangeObj:
|
||||
|
7
port/linux/package/pikascript/_aes.pyi
Normal file
7
port/linux/package/pikascript/_aes.pyi
Normal file
@ -0,0 +1,7 @@
|
||||
class AES:
|
||||
MODE_ECB: int
|
||||
MODE_CBC: int
|
||||
def __init__(self): ...
|
||||
def new(self, password:any, mode:int, iv:any): ...
|
||||
def encrypt(self, msg:any) -> any: ...
|
||||
def decrypt(self, msg:any) -> any: ...
|
9
port/linux/package/pikascript/aes.py
Normal file
9
port/linux/package/pikascript/aes.py
Normal file
@ -0,0 +1,9 @@
|
||||
import _aes
|
||||
|
||||
MODE_ECB = _aes.AES.MODE_ECB
|
||||
MODE_CBC = _aes.AES.MODE_CBC
|
||||
|
||||
def new(password:any, mode:int, iv=None) -> _aes.AES:
|
||||
aes = _aes.AES()
|
||||
aes.new(password, mode, iv)
|
||||
return aes
|
@ -5,7 +5,7 @@ import GTestTask, TempDevTest
|
||||
import cb_test
|
||||
import configparser
|
||||
import test_module1, test_cmodule, test_module4, import_test
|
||||
import hashlib, hmac
|
||||
import hashlib, hmac, aes
|
||||
|
||||
hashlib.sha256(b"123456")
|
||||
|
||||
|
1
port/linux/package/pikascript/pika.studio
Normal file
1
port/linux/package/pikascript/pika.studio
Normal file
@ -0,0 +1 @@
|
||||
<args>--add-file ../../test/assets/widget_config.ini --add-file ../../test/assets/test.txt</args>
|
@ -63,3 +63,7 @@ void GTestTask_ProxyTest___setattr__(PikaObj* self,
|
||||
void GTestTask_test_raise(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
}
|
||||
|
||||
void GTestTask__test___init__(PikaObj *self){
|
||||
obj_setStr(self, "a", NULL);
|
||||
}
|
||||
|
@ -27,14 +27,43 @@ void PikaStdDevice_ADC_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_ADC, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open ADC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open ADC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
return;
|
||||
}
|
||||
pika_hal_ADC_config cfg = {0};
|
||||
cfg.continue_or_single = PIKA_HAL_ADC_SINGLE;
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformRead(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ADC_config* cfg = (pika_hal_ADC_config*)dev->ioctl_config;
|
||||
uint32_t val_i = 0;
|
||||
pika_hal_read(dev, &val_i, sizeof(val_i));
|
||||
pika_float val = (pika_float)val_i / (pika_float)cfg->max * cfg->vref;
|
||||
val = val_i * obj_setFloat(self, "val", val);
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
#include "PikaStdDevice_DAC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_DAC, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open DAC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_enable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_DAC_config cfg = {0};
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_disable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC___init__(PikaObj* self) {
|
||||
PikaStdDevice_DAC_init(self);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_write(PikaObj* self, pika_float val) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_DAC_config* cfg = (pika_hal_DAC_config*)dev->ioctl_config;
|
||||
uint32_t val_i = (val / cfg->vref) * cfg->max;
|
||||
pika_hal_write(dev, &val_i, sizeof val_i);
|
||||
}
|
@ -84,7 +84,8 @@ static pika_dev* _get_dev(PikaObj* self){
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_GPIO, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n", obj_getStr(self, "pin"));
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
|
@ -44,20 +44,6 @@ int PikaStdDevice_PWM_getFrequency(PikaObj* self) {
|
||||
return obj_getInt(self, "freq");
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
char* PikaStdDevice_PWM_getName(PikaObj* self) {
|
||||
return obj_getStr(self, "name");
|
||||
}
|
||||
@ -77,3 +63,46 @@ int PikaStdDevice_PWM_getChannel(PikaObj* self) {
|
||||
void PikaStdDevice_PWM_setFreq(PikaObj* self, int freq) {
|
||||
PikaStdDevice_PWM_setFrequency(self, freq);
|
||||
}
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_PWM, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open PWM '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
|
||||
pika_float duty = obj_getFloat(self, "duty"); // 0.0 ~ 1.0
|
||||
uint32_t freq = obj_getInt(self, "freq"); // Hz
|
||||
pika_hal_PWM_config cfg = {0};
|
||||
/* ns */
|
||||
cfg.duty = (uint32_t)(1000000000.0f / freq * duty);
|
||||
pika_hal_ioctl(_get_dev(self), PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
uint32_t freq = obj_getInt(self, "freq"); // Hz
|
||||
pika_float duty = obj_getFloat(self, "duty"); // 0.0 ~ 1.0
|
||||
pika_hal_PWM_config cfg = {0};
|
||||
/* ns */
|
||||
cfg.period = (uint32_t)(1000000000.0f / freq);
|
||||
cfg.duty = (uint32_t)(1000000000.0f / freq * duty);
|
||||
pika_hal_ioctl(_get_dev(self), PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
@ -27,20 +27,23 @@ static size_t _pika_hal_dev_config_size(PIKA_HAL_DEV_TYPE dev_type) {
|
||||
|
||||
pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name) {
|
||||
int ret = -1;
|
||||
pika_dev* dev = NULL;
|
||||
if (dev_type >= _PIKA_DEV_TYPE_MAX) {
|
||||
__platform_printf("Error: dev_type invalied.\r\n");
|
||||
goto __exit;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev_type);
|
||||
pika_dev* dev = (pika_dev*)pikaMalloc(sizeof(pika_dev));
|
||||
dev = (pika_dev*)pikaMalloc(sizeof(pika_dev));
|
||||
if (dev == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
memset(dev, 0, sizeof(pika_dev));
|
||||
dev->type = dev_type;
|
||||
dev->ioctl_config = pikaMalloc(_pika_hal_dev_config_size(dev_type));
|
||||
if (dev->ioctl_config == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
memset(dev->ioctl_config, 0, _pika_hal_dev_config_size(dev_type));
|
||||
ret = impl->open(dev, name);
|
||||
__exit:
|
||||
if (0 == ret) {
|
||||
@ -142,11 +145,19 @@ int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) {
|
||||
config_in = va_arg(args, void*);
|
||||
ret = _pika_hal_ioctl_merge_config(dev, config_in);
|
||||
va_end(args);
|
||||
}
|
||||
if (0 != ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
ret = impl->ioctl(dev, cmd_origin, dev->ioctl_config);
|
||||
if (ret == 0) {
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_ENABLE) {
|
||||
dev->is_enabled = 1;
|
||||
}
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_DISABLE) {
|
||||
dev->is_enabled = 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -160,12 +171,14 @@ int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) {
|
||||
} \
|
||||
} else { \
|
||||
/* use input value */ \
|
||||
src->item = dst->item; \
|
||||
dst->item = src->item; \
|
||||
}
|
||||
|
||||
int pika_hal_GPIO_ioctl_merge_config(pika_hal_GPIO_config* dst,
|
||||
pika_hal_GPIO_config* src) {
|
||||
// printf("before merge: dst->dir=%d, src->dir=%d\r\n", dst->dir, src->dir);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(dir, PIKA_HAL_GPIO_DIR_IN);
|
||||
// printf("after merge: dst->dir=%d, src->dir=%d\r\n", dst->dir, src->dir);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(pull, PIKA_HAL_GPIO_PULL_NONE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_GPIO_SPEED_10M);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_rising, NULL);
|
||||
@ -190,27 +203,46 @@ int pika_hal_SPI_ioctl_merge_config(pika_hal_SPI_config* dst,
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mode, PIKA_HAL_SPI_MODE_0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(data_width, PIKA_HAL_SPI_DATA_WIDTH_8);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_SPI_SPEED_2M);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_SPI_TIMEOUT_1000MS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_IIC_ioctl_merge_config(pika_hal_IIC_config* dst,
|
||||
pika_hal_IIC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(addr, 0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(address_width, PIKA_HAL_IIC_ADDRESS_WIDTH_7BIT);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(master_or_slave, PIKA_HAL_IIC_MASTER);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(slave_addr, 0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mem_addr_ena, PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mem_addr_size, PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT);
|
||||
dst->mem_addr = src->mem_addr;
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_IIC_SPEED_100K);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_IIC_TIMEOUT_1000MS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_PWM_ioctl_merge_config(pika_hal_PWM_config* dst,
|
||||
pika_hal_PWM_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(channel, PIKA_HAL_PWM_CHANNEL_0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(period, PIKA_HAL_PWM_PERIOD_1MS * 10);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(duty, PIKA_HAL_PWM_PERIOD_1MS * 5);
|
||||
// _IOCTL_CONFIG_USE_DEFAULT(duty, 0);
|
||||
dst->duty = src->duty;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_ADC_ioctl_merge_config(pika_hal_ADC_config* dst,
|
||||
pika_hal_ADC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(channel, PIKA_HAL_ADC_CHANNEL_0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(resolution, PIKA_HAL_ADC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_resolution, PIKA_HAL_ADC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_freq, PIKA_HAL_ADC_SAMPLING_FREQ_100);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(continue_or_single, PIKA_HAL_ADC_SINGLE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(vref, (pika_float)3.3);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 8192);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_DAC_ioctl_merge_config(pika_hal_DAC_config* dst,
|
||||
pika_hal_DAC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_DAC_SPEED_1K * 8);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_resolution, PIKA_HAL_DAC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(vref, (pika_float)3.3);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 3300000);
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define _PIKA_DEV_HAL_H
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
/*
|
||||
* pika_hal is a C Device HAL lib for PikaScript modules.
|
||||
@ -15,6 +16,7 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_DEV_TYPE type;
|
||||
PIKA_BOOL is_enabled;
|
||||
void* ioctl_config;
|
||||
void* platform_data;
|
||||
} pika_dev;
|
||||
@ -105,6 +107,21 @@ typedef struct {
|
||||
} pika_hal_UART_config;
|
||||
|
||||
typedef uint32_t PIKA_HAL_IIC_SLAVE_ADDR;
|
||||
typedef uint32_t PIKA_HAL_IIC_MEM_ADDR;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MEM_ADDR_SIZE {
|
||||
_PIKA_HAL_IIC_MEM_ADDR_SIZE_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT = 1,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_16BIT = 2,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_24BIT = 3,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_32BIT = 4,
|
||||
} PIKA_HAL_IIC_MEM_ADDR_SIZE;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MEM_ADDR_ENA {
|
||||
_PIKA_HAL_IIC_MEM_ADDR_ENA_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE,
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE,
|
||||
} PIKA_HAL_IIC_MEM_ADDR_ENA;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_IIC_SPEED_UNUSED = 0,
|
||||
@ -113,11 +130,57 @@ typedef enum {
|
||||
PIKA_HAL_IIC_SPEED_1M = 1000000,
|
||||
} PIKA_HAL_IIC_SPEED;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MASTER_OR_SLAVE {
|
||||
_PIKA_HAL_IIC_MASTER_OR_SLAVE_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MASTER,
|
||||
PIKA_HAL_IIC_SLAVE,
|
||||
} PIKA_HAL_IIC_MASTER_OR_SLAVE;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_ADDRESS_WIDTH {
|
||||
_PIKA_HAL_IIC_ADDRESS_WIDTH_UNUSED = 0,
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH_7BIT = 7,
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH_10BIT = 10,
|
||||
} PIKA_HAL_IIC_ADDRESS_WIDTH;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_TIMEOUT {
|
||||
_PIKA_HAL_IIC_TIMEOUT_UNUSED = 0,
|
||||
PIKA_HAL_IIC_TIMEOUT_1MS = 1,
|
||||
PIKA_HAL_IIC_TIMEOUT_2MS = 2,
|
||||
PIKA_HAL_IIC_TIMEOUT_5MS = 5,
|
||||
PIKA_HAL_IIC_TIMEOUT_10MS = 10,
|
||||
PIKA_HAL_IIC_TIMEOUT_20MS = 20,
|
||||
PIKA_HAL_IIC_TIMEOUT_50MS = 50,
|
||||
PIKA_HAL_IIC_TIMEOUT_100MS = 100,
|
||||
PIKA_HAL_IIC_TIMEOUT_200MS = 200,
|
||||
PIKA_HAL_IIC_TIMEOUT_500MS = 500,
|
||||
PIKA_HAL_IIC_TIMEOUT_1000MS = 1000,
|
||||
} PIKA_HAL_IIC_TIMEOUT;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_IIC_SLAVE_ADDR addr;
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH address_width;
|
||||
PIKA_HAL_IIC_MASTER_OR_SLAVE master_or_slave;
|
||||
PIKA_HAL_IIC_SLAVE_ADDR slave_addr;
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA mem_addr_ena;
|
||||
PIKA_HAL_IIC_MEM_ADDR mem_addr;
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE mem_addr_size;
|
||||
PIKA_HAL_IIC_SPEED speed;
|
||||
PIKA_HAL_IIC_TIMEOUT timeout;
|
||||
} pika_hal_IIC_config;
|
||||
|
||||
typedef enum PIKA_HAL_SPI_TIMEOUT {
|
||||
_PIKA_HAL_SPI_TIMEOUT_UNUSED = 0,
|
||||
PIKA_HAL_SPI_TIMEOUT_1MS = 1,
|
||||
PIKA_HAL_SPI_TIMEOUT_2MS = 2,
|
||||
PIKA_HAL_SPI_TIMEOUT_5MS = 5,
|
||||
PIKA_HAL_SPI_TIMEOUT_10MS = 10,
|
||||
PIKA_HAL_SPI_TIMEOUT_20MS = 20,
|
||||
PIKA_HAL_SPI_TIMEOUT_50MS = 50,
|
||||
PIKA_HAL_SPI_TIMEOUT_100MS = 100,
|
||||
PIKA_HAL_SPI_TIMEOUT_200MS = 200,
|
||||
PIKA_HAL_SPI_TIMEOUT_500MS = 500,
|
||||
PIKA_HAL_SPI_TIMEOUT_1000MS = 1000,
|
||||
} PIKA_HAL_SPI_TIMEOUT;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_LSB_OR_MSB_UNUSED = 0,
|
||||
PIKA_HAL_SPI_LSB,
|
||||
@ -161,22 +224,9 @@ typedef struct {
|
||||
PIKA_HAL_SPI_MODE mode;
|
||||
PIKA_HAL_SPI_DATA_WIDTH data_width;
|
||||
PIKA_HAL_SPI_SPEED speed;
|
||||
PIKA_HAL_SPI_TIMEOUT timeout;
|
||||
} pika_hal_SPI_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_ADC_CHANNEL_UNUSED = 0,
|
||||
PIKA_HAL_ADC_CHANNEL_0,
|
||||
PIKA_HAL_ADC_CHANNEL_1,
|
||||
PIKA_HAL_ADC_CHANNEL_2,
|
||||
PIKA_HAL_ADC_CHANNEL_3,
|
||||
PIKA_HAL_ADC_CHANNEL_4,
|
||||
PIKA_HAL_ADC_CHANNEL_5,
|
||||
PIKA_HAL_ADC_CHANNEL_6,
|
||||
PIKA_HAL_ADC_CHANNEL_7,
|
||||
PIKA_HAL_ADC_CHANNEL_TEMP,
|
||||
PIKA_HAL_ADC_CHANNEL_VBAT,
|
||||
} PIKA_HAL_ADC_CHANNEL;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_ADC_RESOLUTION_UNUSED = 0,
|
||||
PIKA_HAL_ADC_RESOLUTION_8 = 8,
|
||||
@ -186,11 +236,65 @@ typedef enum {
|
||||
PIKA_HAL_ADC_RESOLUTION_16 = 16,
|
||||
} PIKA_HAL_ADC_RESOLUTION;
|
||||
|
||||
typedef enum PIKA_HAL_ADC_SAMPLING_FREQ {
|
||||
_PIKA_HAL_ADC_SAMPLING_FREQ_UNUSED = 0,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_100 = 100,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_1K = 1000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_10K = 10000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_100K = 100000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_1M = 1000000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_10M = 10000000,
|
||||
} PIKA_HAL_ADC_SAMPLING_FREQ;
|
||||
|
||||
typedef enum PIKA_HAL_ADC_CONTINUOU_OR_SINGLE {
|
||||
_PIKA_HAL_ADC_CONTINUOU_OR_SINGLE_UNUSED = 0,
|
||||
PIKA_HAL_ADC_SINGLE,
|
||||
PIKA_HAL_ADC_CONTINUOU,
|
||||
} PIKA_HAL_ADC_CONTINUOU_OR_SINGLE;
|
||||
|
||||
typedef pika_float PIKA_HAL_ADC_VREF;
|
||||
typedef uint32_t PIKA_HAL_ADC_MAX;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_ADC_CHANNEL channel;
|
||||
PIKA_HAL_ADC_RESOLUTION resolution;
|
||||
PIKA_HAL_ADC_RESOLUTION sampling_resolution;
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ sampling_freq;
|
||||
PIKA_HAL_ADC_CONTINUOU_OR_SINGLE continue_or_single;
|
||||
PIKA_HAL_ADC_MAX max;
|
||||
PIKA_HAL_ADC_VREF vref;
|
||||
} pika_hal_ADC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_DAC_RESOLUTION_UNUSED = 0,
|
||||
PIKA_HAL_DAC_RESOLUTION_8 = 8,
|
||||
PIKA_HAL_DAC_RESOLUTION_10 = 10,
|
||||
PIKA_HAL_DAC_RESOLUTION_12 = 12,
|
||||
PIKA_HAL_DAC_RESOLUTION_14 = 14,
|
||||
PIKA_HAL_DAC_RESOLUTION_16 = 16,
|
||||
} PIKA_HAL_DAC_RESOLUTION;
|
||||
|
||||
typedef enum PIKA_HAL_DAC_SPEED {
|
||||
_PIKA_HAL_DAC_SPEED_UNUSED = 0,
|
||||
PIKA_HAL_DAC_SPEED_100 = 100,
|
||||
PIKA_HAL_DAC_SPEED_1K = 1000,
|
||||
PIKA_HAL_DAC_SPEED_10K = 10000,
|
||||
PIKA_HAL_DAC_SPEED_100K = 100000,
|
||||
PIKA_HAL_DAC_SPEED_1M = 1000000,
|
||||
PIKA_HAL_DAC_SPEED_10M = 10000000,
|
||||
PIKA_HAL_DAC_SPEED_20M = 20000000,
|
||||
PIKA_HAL_DAC_SPEED_50M = 50000000,
|
||||
PIKA_HAL_DAC_SPEED_100M = 100000000,
|
||||
} PIKA_HAL_DAC_SPEED;
|
||||
|
||||
typedef pika_float PIKA_HAL_DAC_VREF;
|
||||
typedef uint32_t PIKA_HAL_DAC_MAX;
|
||||
|
||||
typedef struct pika_hal_DAC_config {
|
||||
PIKA_HAL_DAC_RESOLUTION sampling_resolution;
|
||||
PIKA_HAL_DAC_SPEED speed;
|
||||
PIKA_HAL_DAC_MAX max;
|
||||
PIKA_HAL_DAC_VREF vref;
|
||||
} pika_hal_DAC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_DAC_UNUSED = 0,
|
||||
PIKA_HAL_PWM_CHANNEL_0,
|
||||
@ -218,7 +322,6 @@ typedef enum {
|
||||
} PIKA_HAL_PWM_DUTY;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_PWM_CHANNEL channel;
|
||||
PIKA_HAL_PWM_PERIOD period;
|
||||
PIKA_HAL_PWM_DUTY duty;
|
||||
} pika_hal_PWM_config;
|
||||
|
@ -7,6 +7,7 @@ pika_hal_table_add(UART)
|
||||
pika_hal_table_add(IIC)
|
||||
pika_hal_table_add(SPI)
|
||||
pika_hal_table_add(ADC)
|
||||
pika_hal_table_add(DAC)
|
||||
pika_hal_table_add(PWM)
|
||||
|
||||
/* clang-format on */
|
||||
|
@ -1,12 +1,37 @@
|
||||
#include "PikaStdData_FILEIO.h"
|
||||
#include <stdio.h>
|
||||
#include "PikaCompiler.h"
|
||||
#include "PikaStdData_List.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t* addr;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
} PIKAFS_FILE;
|
||||
|
||||
int PikaStdData_FILEIO_init(PikaObj* self, char* path, char* mode) {
|
||||
if (obj_isArgExist(self, "_f")) {
|
||||
/* already initialized */
|
||||
return 0;
|
||||
}
|
||||
if (strIsStartWith(path, "pikafs/")) {
|
||||
PIKAFS_FILE* f = (PIKAFS_FILE*)pikaMalloc(sizeof(PIKAFS_FILE));
|
||||
memset(f, 0, sizeof(PIKAFS_FILE));
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
uint8_t* library_bytes = obj_getPtr((PikaObj*)__pikaMain, "@libraw");
|
||||
if (NULL == library_bytes) {
|
||||
return 1;
|
||||
}
|
||||
char* file_name = path + 7;
|
||||
if (PIKA_RES_OK != _loadModuleDataWithName(library_bytes, file_name,
|
||||
&f->addr, &f->size)) {
|
||||
return 1;
|
||||
}
|
||||
obj_setInt(self, "pikafs", PIKA_TRUE);
|
||||
obj_setPtr(self, "_f", f);
|
||||
obj_setStr(self, "_mode", mode);
|
||||
return 0;
|
||||
}
|
||||
FILE* f = __platform_fopen(path, mode);
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
@ -17,27 +42,63 @@ int PikaStdData_FILEIO_init(PikaObj* self, char* path, char* mode) {
|
||||
}
|
||||
|
||||
void PikaStdData_FILEIO_close(PikaObj* self) {
|
||||
if (PIKA_TRUE == obj_getInt(self, "pikafs")) {
|
||||
PIKAFS_FILE* f = obj_getPtr(self, "_f");
|
||||
if (NULL == f) {
|
||||
return;
|
||||
}
|
||||
pikaFree(f, sizeof(PIKAFS_FILE));
|
||||
obj_setPtr(self, "_f", NULL);
|
||||
return;
|
||||
}
|
||||
FILE* f = obj_getPtr(self, "_f");
|
||||
if (f == NULL) {
|
||||
if (NULL == f) {
|
||||
return;
|
||||
}
|
||||
__platform_fclose(f);
|
||||
obj_setPtr(self, "_f", NULL);
|
||||
}
|
||||
|
||||
Arg* PikaStdData_FILEIO_read(PikaObj* self, int size) {
|
||||
size_t _pikafs_fread(void* buf, size_t size, size_t count, PIKAFS_FILE* f) {
|
||||
if (f->pos >= f->size) {
|
||||
return 0;
|
||||
}
|
||||
if (f->pos + size * count > f->size) {
|
||||
count = (f->size - f->pos) / size;
|
||||
}
|
||||
__platform_memcpy(buf, f->addr + f->pos, size * count);
|
||||
f->pos += size * count;
|
||||
return count;
|
||||
}
|
||||
|
||||
Arg* PikaStdData_FILEIO_read(PikaObj* self, PikaTuple* size_) {
|
||||
int size = 0;
|
||||
if (pikaTuple_getSize(size_) == 0) {
|
||||
size = -1;
|
||||
} else {
|
||||
size = pikaTuple_getInt(size_, 0);
|
||||
}
|
||||
if (size <= 0) {
|
||||
/* read all */
|
||||
size = PIKA_READ_FILE_BUFF_SIZE;
|
||||
}
|
||||
Arg* buf_arg = arg_newBytes(NULL, size);
|
||||
uint8_t* buf = arg_getBytes(buf_arg);
|
||||
int n = 0;
|
||||
/* read */
|
||||
if (PIKA_TRUE == obj_getInt(self, "pikafs")) {
|
||||
PIKAFS_FILE* f = obj_getPtr(self, "_f");
|
||||
if (NULL == f) {
|
||||
return NULL;
|
||||
}
|
||||
n = _pikafs_fread(buf, 1, size, f);
|
||||
} else {
|
||||
FILE* f = obj_getPtr(self, "_f");
|
||||
if (f == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
Arg* buf_arg = arg_newBytes(NULL, size);
|
||||
uint8_t* buf = arg_getBytes(buf_arg);
|
||||
/* read */
|
||||
int n = __platform_fread(buf, 1, size, f);
|
||||
n = __platform_fread(buf, 1, size, f);
|
||||
}
|
||||
if (n < size) {
|
||||
/* EOF */
|
||||
buf[n] = '\0';
|
||||
@ -57,6 +118,9 @@ Arg* PikaStdData_FILEIO_read(PikaObj* self, int size) {
|
||||
}
|
||||
|
||||
int PikaStdData_FILEIO_write(PikaObj* self, Arg* s) {
|
||||
if (PIKA_TRUE == obj_getInt(self, "pikafs")) {
|
||||
return 1;
|
||||
}
|
||||
FILE* f = obj_getPtr(self, "_f");
|
||||
int res = -1;
|
||||
if (f == NULL) {
|
||||
@ -66,6 +130,12 @@ int PikaStdData_FILEIO_write(PikaObj* self, Arg* s) {
|
||||
}
|
||||
char* mode = obj_getStr(self, "_mode");
|
||||
if (strIsContain(mode, 'b')) {
|
||||
if (arg_getType(s) != ARG_TYPE_BYTES) {
|
||||
__platform_printf(
|
||||
"TypeError: a bytes-like object is required, not 'str'\r\n");
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_INVALID_PARAM);
|
||||
return -1;
|
||||
}
|
||||
/* binary */
|
||||
res = __platform_fwrite(arg_getBytes(s), 1, arg_getBytesSize(s), f);
|
||||
} else {
|
||||
|
@ -810,3 +810,8 @@ char* _strlwr(char* str) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char* PikaStdData_String_format(PikaObj* self, PikaTuple* vars) {
|
||||
/* 'test{}'.format(123) */
|
||||
return NULL;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ Arg* PikaStdData_Tuple___next__(PikaObj* self) {
|
||||
}
|
||||
|
||||
Arg* PikaStdData_Tuple___getitem__(PikaObj* self, Arg* __key) {
|
||||
return PikaStdData_Tuple_get(self, obj_getInt(self, "__key"));
|
||||
return PikaStdData_Tuple_get(self, arg_getInt(__key));
|
||||
}
|
||||
|
||||
void PikaStdData_Tuple___del__(PikaObj* self) {
|
||||
|
@ -671,3 +671,10 @@ char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
|
||||
arg_deinit(cfg.context);
|
||||
return res;
|
||||
}
|
||||
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
void PikaStdLib_SysObj_help(PikaObj* self, char* name) {
|
||||
if (strEqu(name, "modules")) {
|
||||
obj_printModules((PikaObj*)__pikaMain);
|
||||
}
|
||||
}
|
||||
|
149
port/linux/package/pikascript/pikascript-lib/aes/_aes_AES.c
Normal file
149
port/linux/package/pikascript/pikascript-lib/aes/_aes_AES.c
Normal file
@ -0,0 +1,149 @@
|
||||
#include "_aes_AES.h"
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
enum {
|
||||
MODE_ECB,
|
||||
MODE_CBC,
|
||||
} pika_aes_t;
|
||||
|
||||
void _aes_AES___init__(PikaObj* self) {
|
||||
obj_setInt(self, "MODE_ECB", MODE_ECB);
|
||||
obj_setInt(self, "MODE_CBC", MODE_CBC);
|
||||
}
|
||||
|
||||
void _aes_AES_new(PikaObj* self, Arg* password, int mode, Arg* iv) {
|
||||
ArgType t;
|
||||
mbedtls_aes_context context;
|
||||
|
||||
t = arg_getType(password);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
t = arg_getType(iv);
|
||||
if (ARG_TYPE_NONE != t) {
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
} else {
|
||||
size_t len = arg_getBytesSize(iv);
|
||||
if (len != 16) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
} else {
|
||||
obj_setBytes(self, "_iv", arg_getBytes(iv), len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obj_setBytes(self, "_password", arg_getBytes(password),
|
||||
arg_getBytesSize(password));
|
||||
obj_setInt(self, "_mode", mode);
|
||||
mbedtls_aes_init(&context);
|
||||
obj_setStruct(self, "context", context);
|
||||
}
|
||||
|
||||
Arg* _aes_AES_encrypt(PikaObj* self, Arg* msg) {
|
||||
ArgType t;
|
||||
|
||||
t = arg_getType(msg);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
uint8_t* data = arg_getBytes(msg);
|
||||
uint8_t data_len = arg_getBytesSize(msg);
|
||||
uint8_t mode = obj_getInt(self, "_mode");
|
||||
void* context = obj_getStruct(self, "context");
|
||||
uint8_t* password = obj_getBytes(self, "_password");
|
||||
uint8_t password_len = obj_getBytesSize(self, "_password");
|
||||
uint8_t* iv = obj_getBytes(self, "_iv");
|
||||
uint8_t iv_in[16];
|
||||
|
||||
if (obj_getBytes(self, "_buff") != NULL) {
|
||||
obj_removeArg(self, "_buff");
|
||||
}
|
||||
|
||||
obj_setBytes(self, "_buff", NULL, data_len * sizeof(uint8_t));
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
|
||||
if (mode == MODE_CBC) {
|
||||
if (iv != NULL) {
|
||||
__platform_memcpy(iv_in, iv, 16);
|
||||
} else {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_aes_setkey_enc((mbedtls_aes_context*)context, password,
|
||||
password_len * 8);
|
||||
|
||||
switch (mode) {
|
||||
case MODE_ECB:
|
||||
mbedtls_aes_crypt_ecb((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_ENCRYPT, data, buff);
|
||||
break;
|
||||
case MODE_CBC:
|
||||
mbedtls_aes_crypt_cbc((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_ENCRYPT, data_len, iv_in, data,
|
||||
buff);
|
||||
break;
|
||||
default:
|
||||
__platform_printf("[%s]not support mode\r\n", __FUNCTION__);
|
||||
obj_setErrorCode(self, -3); // not support now
|
||||
break;
|
||||
}
|
||||
return arg_newBytes(buff, data_len);
|
||||
}
|
||||
|
||||
Arg* _aes_AES_decrypt(PikaObj* self, Arg* msg) {
|
||||
ArgType t;
|
||||
|
||||
t = arg_getType(msg);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
uint8_t* data = arg_getBytes(msg);
|
||||
uint8_t data_len = arg_getBytesSize(msg);
|
||||
void* context = obj_getStruct(self, "context");
|
||||
uint8_t mode = obj_getInt(self, "_mode");
|
||||
uint8_t* password = obj_getBytes(self, "_password");
|
||||
uint8_t password_len = obj_getBytesSize(self, "_password");
|
||||
uint8_t* iv = obj_getBytes(self, "_iv");
|
||||
uint8_t iv_in[16];
|
||||
|
||||
if (obj_getBytes(self, "_buff") != NULL) {
|
||||
obj_removeArg(self, "_buff");
|
||||
}
|
||||
|
||||
obj_setBytes(self, "_buff", NULL, data_len * sizeof(uint8_t));
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
|
||||
if (mode == MODE_CBC) {
|
||||
if (iv != NULL) {
|
||||
__platform_memcpy(iv_in, iv, 16);
|
||||
} else {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_aes_setkey_dec((mbedtls_aes_context*)context, password,
|
||||
password_len * 8);
|
||||
|
||||
switch (mode) {
|
||||
case MODE_ECB:
|
||||
mbedtls_aes_crypt_ecb((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_DECRYPT, data, buff);
|
||||
break;
|
||||
case MODE_CBC:
|
||||
mbedtls_aes_crypt_cbc((mbedtls_aes_context*)context,
|
||||
MBEDTLS_AES_DECRYPT, data_len, iv_in, data,
|
||||
buff);
|
||||
break;
|
||||
default:
|
||||
__platform_printf("[%s]not support mode\r\n", __FUNCTION__);
|
||||
obj_setErrorCode(self, -3); // not support now
|
||||
break;
|
||||
}
|
||||
return arg_newBytes(buff, data_len);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
MajorVersion = "1"
|
||||
MinorVersion = "11"
|
||||
MicroVersion = "7"
|
||||
MicroVersion = "8"
|
||||
|
@ -1,5 +1,5 @@
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pikascript-core==v1.11.8
|
||||
PikaStdLib==v1.11.8
|
||||
pikaRTThread==v1.3.0
|
||||
pikaRTDevice==v1.1.0
|
||||
PikaStdDevice==v1.9.0
|
@ -35,17 +35,31 @@
|
||||
|
||||
const char magic_code_pyo[] = {0x0f, 'p', 'y', 'o'};
|
||||
|
||||
static PIKA_BOOL _check_magic_code_pyo(uint8_t* bytecode) {
|
||||
char* data = (char*)bytecode;
|
||||
if (data[0] == magic_code_pyo[0] && data[1] == magic_code_pyo[1] &&
|
||||
data[2] == magic_code_pyo[2] && data[3] == magic_code_pyo[3]) {
|
||||
return PIKA_TRUE;
|
||||
}
|
||||
return PIKA_FALSE;
|
||||
}
|
||||
|
||||
static uint8_t* arg_getBytecode(Arg* self) {
|
||||
uint8_t* bytecode_file = arg_getBytes(self);
|
||||
uint8_t* bytecode_start =
|
||||
bytecode_file + sizeof(magic_code_pyo) + sizeof(uint32_t);
|
||||
return bytecode_start;
|
||||
if (_check_magic_code_pyo(bytecode_file)) {
|
||||
return bytecode_file + sizeof(magic_code_pyo) + sizeof(uint32_t);
|
||||
}
|
||||
return bytecode_file;
|
||||
}
|
||||
|
||||
static size_t arg_getBytecodeSize(Arg* self) {
|
||||
size_t size_all = arg_getBytesSize(self);
|
||||
uint8_t* bytecode_file = arg_getBytes(self);
|
||||
if (_check_magic_code_pyo(bytecode_file)) {
|
||||
return size_all - sizeof(magic_code_pyo) - sizeof(uint32_t);
|
||||
}
|
||||
return size_all;
|
||||
}
|
||||
|
||||
/* const Pool output redirect */
|
||||
static void __handler_constPool_output_file(ConstPool* self, char* content) {
|
||||
@ -196,6 +210,10 @@ void LibObj_deinit(LibObj* self) {
|
||||
|
||||
/* add bytecode to lib, not copy the bytecode */
|
||||
void LibObj_dynamicLink(LibObj* self, char* module_name, uint8_t* bytecode) {
|
||||
if (strIsContain(module_name, '.')) {
|
||||
/* skip file */
|
||||
return;
|
||||
}
|
||||
if (!obj_isArgExist(self, module_name)) {
|
||||
obj_newObj(self, module_name, "", New_TinyObj);
|
||||
}
|
||||
@ -224,10 +242,27 @@ int LibObj_staticLinkFile(LibObj* self, char* input_file_name) {
|
||||
Args buffs = {0};
|
||||
/* read file */
|
||||
Arg* input_file_arg = arg_loadFile(NULL, input_file_name);
|
||||
if (NULL == input_file_arg) {
|
||||
__platform_printf("error: can't open file %s\r\n", input_file_name);
|
||||
return -1;
|
||||
}
|
||||
char* module_name = strsGetLastToken(&buffs, input_file_name, '/');
|
||||
|
||||
size_t module_name_len = strlen(module_name);
|
||||
|
||||
/* cut off '.py.o' */
|
||||
module_name[strlen(module_name) - (sizeof(".py.o") - 1)] = 0;
|
||||
if (module_name[module_name_len - 1] == 'o' &&
|
||||
module_name[module_name_len - 2] == '.' &&
|
||||
module_name[module_name_len - 3] == 'y' &&
|
||||
module_name[module_name_len - 4] == 'p' &&
|
||||
module_name[module_name_len - 5] == '.') {
|
||||
module_name[module_name_len - 5] = 0;
|
||||
} else {
|
||||
// __platform_printf("linking raw %s:%s:%ld\r\n", input_file_name,
|
||||
// module_name, arg_getBytecodeSize(input_file_arg));
|
||||
/* replace . to | */
|
||||
module_name = strsReplace(&buffs, module_name, ".", "|");
|
||||
}
|
||||
|
||||
/* push bytecode */
|
||||
LibObj_staticLink(self, module_name, arg_getBytecode(input_file_arg),
|
||||
@ -268,17 +303,21 @@ static int32_t __foreach_handler_libWriteBytecode(Arg* argEach, Args* context) {
|
||||
|
||||
static int32_t __foreach_handler_libWriteIndex(Arg* argEach, Args* context) {
|
||||
FILE* out_file = args_getPtr(context, "out_file");
|
||||
Args buffs = {0};
|
||||
if (argType_isObject(arg_getType(argEach))) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
uint32_t bytecode_size = obj_getBytesSize(module_obj, "buff");
|
||||
char buff[LIB_INFO_BLOCK_SIZE - sizeof(uint32_t)] = {0};
|
||||
bytecode_size = aline_by(bytecode_size, sizeof(uint32_t));
|
||||
char* module_name = obj_getStr(module_obj, "name");
|
||||
module_name = strsReplace(&buffs, module_name, "|", ".");
|
||||
// __platform_printf(" %s:%d\r\n", module_name, bytecode_size);
|
||||
__platform_memcpy(buff, module_name, strGetSize(module_name));
|
||||
__platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE - sizeof(bytecode_size),
|
||||
out_file);
|
||||
__platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), out_file);
|
||||
}
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -328,7 +367,7 @@ int LibObj_saveLibraryFile(LibObj* self, char* output_file_name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
|
||||
static int _getModuleNum(uint8_t* library_bytes) {
|
||||
if (0 != ((intptr_t)library_bytes & 0x03)) {
|
||||
return PIKA_RES_ERR_UNALIGNED_PTR;
|
||||
}
|
||||
@ -352,19 +391,87 @@ int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
|
||||
LIB_VERSION_NUMBER, version_num);
|
||||
return PIKA_RES_ERR_INVALID_VERSION_NUMBER;
|
||||
}
|
||||
return module_num;
|
||||
}
|
||||
|
||||
static PIKA_RES _loadModuleDataWithIndex(uint8_t* library_bytes,
|
||||
int module_num,
|
||||
int module_index,
|
||||
char** name_p,
|
||||
uint8_t** addr_p,
|
||||
size_t* size) {
|
||||
uint8_t* bytecode_addr =
|
||||
library_bytes + LIB_INFO_BLOCK_SIZE * (module_num + 1);
|
||||
for (uint32_t i = 0; i < module_num; i++) {
|
||||
for (uint32_t i = 0; i < module_index + 1; i++) {
|
||||
char* module_name =
|
||||
(char*)(library_bytes + LIB_INFO_BLOCK_SIZE * (i + 1));
|
||||
LibObj_dynamicLink(self, module_name, bytecode_addr);
|
||||
// __platform_printf("loading module: %s\r\n", module_name);
|
||||
*name_p = module_name;
|
||||
*addr_p = bytecode_addr;
|
||||
uint32_t module_size =
|
||||
*(uint32_t*)(module_name + LIB_INFO_BLOCK_SIZE - sizeof(uint32_t));
|
||||
*size = module_size;
|
||||
bytecode_addr += module_size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PIKA_RES _loadModuleDataWithName(uint8_t* library_bytes,
|
||||
char* module_name,
|
||||
uint8_t** addr_p,
|
||||
size_t* size_p) {
|
||||
int module_num = _getModuleNum(library_bytes);
|
||||
if (module_num < 0) {
|
||||
return module_num;
|
||||
}
|
||||
for (int i = 0; i < module_num; i++) {
|
||||
char* name = NULL;
|
||||
uint8_t* addr = NULL;
|
||||
size_t size = 0;
|
||||
_loadModuleDataWithIndex(library_bytes, module_num, i, &name, &addr,
|
||||
&size);
|
||||
if (strEqu(module_name, name)) {
|
||||
*addr_p = addr;
|
||||
*size_p = size;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return PIKA_RES_ERR_ARG_NO_FOUND;
|
||||
}
|
||||
|
||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
|
||||
int module_num = _getModuleNum(library_bytes);
|
||||
if (module_num < 0) {
|
||||
/* load error */
|
||||
return module_num;
|
||||
}
|
||||
for (uint32_t i = 0; i < module_num; i++) {
|
||||
char* module_name = NULL;
|
||||
uint8_t* bytecode_addr = NULL;
|
||||
size_t bytecode_size = 0;
|
||||
_loadModuleDataWithIndex(library_bytes, module_num, i, &module_name,
|
||||
&bytecode_addr, &bytecode_size);
|
||||
LibObj_dynamicLink(self, module_name, bytecode_addr);
|
||||
}
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
int32_t __foreach_handler_printModule(Arg* argEach, Args* context) {
|
||||
if (argType_isObject(arg_getType(argEach))) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
char* module_name = obj_getStr(module_obj, "name");
|
||||
if (NULL != module_name) {
|
||||
__platform_printf(module_name);
|
||||
__platform_printf("\r\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LibObj_printModules(LibObj* self) {
|
||||
args_foreach(self->list, __foreach_handler_printModule, NULL);
|
||||
}
|
||||
|
||||
int LibObj_loadLibraryFile(LibObj* self, char* lib_file_name) {
|
||||
Arg* file_arg = arg_loadFile(NULL, lib_file_name);
|
||||
if (NULL == file_arg) {
|
||||
@ -458,9 +565,17 @@ PikaMaker* New_PikaMaker(void) {
|
||||
PikaMaker* self = New_TinyObj(NULL);
|
||||
obj_setStr(self, "pwd", "");
|
||||
obj_setInt(self, "err", 0);
|
||||
LibObj* lib = New_LibObj(NULL);
|
||||
obj_setPtr(self, "lib", lib);
|
||||
return self;
|
||||
}
|
||||
|
||||
void pikaMaker_deinit(PikaMaker* self) {
|
||||
LibObj* lib = obj_getPtr(self, "lib");
|
||||
LibObj_deinit(lib);
|
||||
obj_deinit(self);
|
||||
}
|
||||
|
||||
void pikaMaker_setPWD(PikaMaker* self, char* pwd) {
|
||||
obj_setStr(self, "pwd", pwd);
|
||||
}
|
||||
@ -688,9 +803,9 @@ PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||
return compile_err;
|
||||
}
|
||||
Args context = {0};
|
||||
LibObj* lib = New_LibObj(NULL);
|
||||
Args buffs = {0};
|
||||
__platform_printf(" linking %s...\n", lib_path);
|
||||
LibObj* lib = obj_getPtr(self, "lib");
|
||||
args_setPtr(&context, "@lib", lib);
|
||||
args_setPtr(&context, "__maker", self);
|
||||
args_foreach(self->list, __foreach_handler_linkCompiledModules, &context);
|
||||
@ -703,7 +818,6 @@ PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||
char* lib_file_path = strsAppend(&buffs, pwd, lib_path);
|
||||
LibObj_saveLibraryFile(lib, lib_file_path);
|
||||
Lib_loadLibraryFileToArray(lib_file_path, folder_path);
|
||||
LibObj_deinit(lib);
|
||||
strsDeinit(&buffs);
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
@ -715,3 +829,9 @@ PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name) {
|
||||
strsDeinit(&buffs);
|
||||
return res;
|
||||
}
|
||||
|
||||
PIKA_RES pikaMaker_linkRaw(PikaMaker* self, char* file_path) {
|
||||
LibObj* lib = obj_getPtr(self, "lib");
|
||||
LibObj_staticLinkFile(lib, file_path);
|
||||
return 0;
|
||||
}
|
||||
|
@ -30,6 +30,13 @@ PIKA_RES pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name);
|
||||
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path);
|
||||
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
|
||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
|
||||
void LibObj_printModules(LibObj* self);
|
||||
void pikaMaker_deinit(PikaMaker* self);
|
||||
PIKA_RES pikaMaker_linkRaw(PikaMaker* self, char* file_path);
|
||||
PIKA_RES _loadModuleDataWithName(uint8_t* library_bytes,
|
||||
char* module_name,
|
||||
uint8_t** addr_p,
|
||||
size_t* size_p);
|
||||
|
||||
#define LIB_VERSION_NUMBER 2
|
||||
#define LIB_INFO_BLOCK_SIZE 32
|
||||
|
@ -35,6 +35,9 @@
|
||||
#include "dataString.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
static volatile Arg* _help_modules_cmodule = NULL;
|
||||
static volatile PIKA_BOOL in_root_obj = PIKA_FALSE;
|
||||
|
||||
static enum shellCTRL __obj_shellLineHandler_REPL(PikaObj* self,
|
||||
char* input_line,
|
||||
ShellConfig* shell);
|
||||
@ -131,6 +134,11 @@ int32_t obj_deinit(PikaObj* self) {
|
||||
#if PIKA_EVENT_ENABLE
|
||||
VMSignal_deinit();
|
||||
#endif
|
||||
if (NULL != _help_modules_cmodule) {
|
||||
arg_deinit((Arg*)_help_modules_cmodule);
|
||||
_help_modules_cmodule = NULL;
|
||||
}
|
||||
__pikaMain = NULL;
|
||||
}
|
||||
return obj_deinit_no_del(self);
|
||||
}
|
||||
@ -180,14 +188,12 @@ PIKA_RES obj_setFloat(PikaObj* self, char* argPath, pika_float value) {
|
||||
}
|
||||
|
||||
PIKA_RES obj_setStr(PikaObj* self, char* argPath, char* str) {
|
||||
pika_assert(NULL != str);
|
||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||
if (NULL == obj) {
|
||||
return PIKA_RES_ERR_ARG_NO_FOUND;
|
||||
}
|
||||
char* name = strPointToLastToken(argPath, '.');
|
||||
args_setStr(obj->list, name, str);
|
||||
return PIKA_RES_OK;
|
||||
return args_setStr(obj->list, name, str);
|
||||
}
|
||||
|
||||
PIKA_RES obj_setNone(PikaObj* self, char* argPath) {
|
||||
@ -488,8 +494,11 @@ static int set_disp_mode(int fd, int option) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static volatile uint8_t logo_printed = 0;
|
||||
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
||||
in_root_obj = PIKA_TRUE;
|
||||
#if PIKA_POOL_ENABLE
|
||||
mem_pool_init();
|
||||
#endif
|
||||
@ -497,7 +506,15 @@ PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
||||
// set_disp_mode(STDIN_FILENO, 0);
|
||||
#endif
|
||||
PikaObj* newObj = newNormalObj(newObjFun);
|
||||
if (!logo_printed) {
|
||||
logo_printed = 1;
|
||||
__platform_printf("\r\n");
|
||||
__platform_printf("~~~/ POWERED BY \\~~~\r\n");
|
||||
__platform_printf("~ pikascript.com ~\r\n");
|
||||
__platform_printf("~~~~~~~~~~~~~~~~~~~~\r\n");
|
||||
}
|
||||
__pikaMain = newObj;
|
||||
in_root_obj = PIKA_FALSE;
|
||||
return newObj;
|
||||
}
|
||||
|
||||
@ -1390,10 +1407,24 @@ int32_t obj_newMetaObj(PikaObj* self, char* objName, NewFun newFunPtr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _append_help(char* name) {
|
||||
if (NULL == _help_modules_cmodule) {
|
||||
_help_modules_cmodule = (volatile Arg*)arg_newStr("");
|
||||
}
|
||||
Arg* _help = (Arg*)_help_modules_cmodule;
|
||||
_help = arg_strAppend(_help, name);
|
||||
_help = arg_strAppend(_help, "\r\n");
|
||||
_help_modules_cmodule = (volatile Arg*)_help;
|
||||
}
|
||||
|
||||
int32_t obj_newObj(PikaObj* self,
|
||||
char* objName,
|
||||
char* className,
|
||||
NewFun newFunPtr) {
|
||||
/* before init root object */
|
||||
if (in_root_obj) {
|
||||
_append_help(objName);
|
||||
}
|
||||
return obj_newMetaObj(self, objName, newFunPtr);
|
||||
}
|
||||
|
||||
@ -1438,9 +1469,16 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) {
|
||||
obj_newMetaObj(self, "@lib", New_LibObj);
|
||||
LibObj* lib = obj_getObj(self, "@lib");
|
||||
LibObj_loadLibrary(lib, library_bytes);
|
||||
obj_setPtr(self, "@libraw", library_bytes);
|
||||
return self;
|
||||
}
|
||||
|
||||
void obj_printModules(PikaObj* self) {
|
||||
LibObj* lib = obj_getObj(self, "@lib");
|
||||
__platform_printf(arg_getStr((Arg*)_help_modules_cmodule));
|
||||
LibObj_printModules(lib);
|
||||
}
|
||||
|
||||
PikaObj* obj_linkLibObj(PikaObj* self, LibObj* library) {
|
||||
obj_setPtr(self, "@lib", library);
|
||||
return self;
|
||||
|
@ -506,4 +506,6 @@ Arg* pks_eventLisener_sendSignalAwaitResult(PikaEventListener* self,
|
||||
uint32_t eventId,
|
||||
int eventSignal);
|
||||
|
||||
void obj_printModules(PikaObj* self);
|
||||
|
||||
#endif
|
||||
|
@ -2519,10 +2519,16 @@ exit:
|
||||
};
|
||||
|
||||
PIKA_RES Parser_linesToBytes(ByteCodeFrame* bf, char* py_lines) {
|
||||
#if PIKA_BYTECODE_ONLY_ENABLE
|
||||
__platform_printf("Error: In bytecode-only mode, can not parse python script.\r\n");
|
||||
__platform_printf(" Note: Please check PIKA_BYTECODE_ONLY_ENABLE config.\r\n");
|
||||
return PIKA_RES_ERR_SYNTAX_ERROR;
|
||||
#else
|
||||
if (1 == (uintptr_t)_Parser_linesToBytesOrAsm(NULL, bf, py_lines)) {
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
return PIKA_RES_ERR_SYNTAX_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
char* Parser_linesToAsm(Args* outBuffs, char* multi_line) {
|
||||
|
@ -79,24 +79,24 @@
|
||||
|
||||
typedef enum {
|
||||
PIKA_RES_OK = 0,
|
||||
PIKA_RES_ERR_RUNTIME_ERROR,
|
||||
PIKA_RES_ERR_ARG_NO_FOUND,
|
||||
PIKA_RES_ERR_UNKNOWN_INSTRUCTION,
|
||||
PIKA_RES_ERR_OUT_OF_RANGE,
|
||||
PIKA_RES_ERR_IO_ERROR,
|
||||
PIKA_RES_ERR_INSUFFICIENT_RESOURCE,
|
||||
PIKA_RES_ERR_INVALID_PARAM,
|
||||
PIKA_RES_ERR_INVALID_PTR,
|
||||
PIKA_RES_ERR_UNALIGNED_PTR,
|
||||
PIKA_RES_ERR_INVALID_VERSION_NUMBER,
|
||||
PIKA_RES_ERR_ILLEGAL_MAGIC_CODE,
|
||||
PIKA_RES_ERR_OPERATION_FAILED,
|
||||
PIKA_RES_ERR_UNKNOWN,
|
||||
PIKA_RES_ERR_SYNTAX_ERROR,
|
||||
PIKA_RES_ERR_IO,
|
||||
PIKA_RES_ERR_ASSERT,
|
||||
PIKA_RES_ERR_SIGNAL_EVENT_FULL,
|
||||
PIKA_RES_ERR_SIGNAL_EVENT_EMPTY,
|
||||
PIKA_RES_ERR_RUNTIME_ERROR = -1,
|
||||
PIKA_RES_ERR_ARG_NO_FOUND = -2,
|
||||
PIKA_RES_ERR_UNKNOWN_INSTRUCTION = -3,
|
||||
PIKA_RES_ERR_OUT_OF_RANGE = -4,
|
||||
PIKA_RES_ERR_IO_ERROR = -5,
|
||||
PIKA_RES_ERR_INSUFFICIENT_RESOURCE = -6,
|
||||
PIKA_RES_ERR_INVALID_PARAM = -7,
|
||||
PIKA_RES_ERR_INVALID_PTR = -8,
|
||||
PIKA_RES_ERR_UNALIGNED_PTR = -9,
|
||||
PIKA_RES_ERR_INVALID_VERSION_NUMBER = -10,
|
||||
PIKA_RES_ERR_ILLEGAL_MAGIC_CODE = -11,
|
||||
PIKA_RES_ERR_OPERATION_FAILED = -12,
|
||||
PIKA_RES_ERR_UNKNOWN = -13,
|
||||
PIKA_RES_ERR_SYNTAX_ERROR = -14,
|
||||
PIKA_RES_ERR_IO = -15,
|
||||
PIKA_RES_ERR_ASSERT = -16,
|
||||
PIKA_RES_ERR_SIGNAL_EVENT_FULL = -17,
|
||||
PIKA_RES_ERR_SIGNAL_EVENT_EMPTY = -18,
|
||||
} PIKA_RES;
|
||||
|
||||
/* clang-format off */
|
||||
|
525
src/PikaVM.c
525
src/PikaVM.c
@ -533,11 +533,11 @@ static Arg* VM_instruction_handler_SLC(PikaObj* self,
|
||||
char* data,
|
||||
Arg* arg_ret_reg) {
|
||||
#if PIKA_SYNTAX_SLICE_ENABLE
|
||||
int arg_num_input = VMState_getInputArgNum(vm);
|
||||
if (arg_num_input < 2) {
|
||||
int n_input = VMState_getInputArgNum(vm);
|
||||
if (n_input < 2) {
|
||||
return arg_newNull();
|
||||
}
|
||||
if (arg_num_input == 2) {
|
||||
if (n_input == 2) {
|
||||
Arg* key = stack_popArg_alloc(&vm->stack);
|
||||
Arg* obj = stack_popArg_alloc(&vm->stack);
|
||||
Arg* res = __vm_get(vm, self, key, obj);
|
||||
@ -545,7 +545,7 @@ static Arg* VM_instruction_handler_SLC(PikaObj* self,
|
||||
arg_deinit(obj);
|
||||
return res;
|
||||
}
|
||||
if (arg_num_input == 3) {
|
||||
if (n_input == 3) {
|
||||
Arg* end = stack_popArg_alloc(&vm->stack);
|
||||
Arg* start = stack_popArg_alloc(&vm->stack);
|
||||
Arg* obj = stack_popArg_alloc(&vm->stack);
|
||||
@ -848,9 +848,8 @@ Arg* obj_runMethodArg(PikaObj* self,
|
||||
&run_state);
|
||||
}
|
||||
|
||||
char* _keys_to_defult(char* type_list,
|
||||
static char* _kw_to_default_all(FunctionArgsInfo* f,
|
||||
char* arg_name,
|
||||
PikaDict* kws,
|
||||
int* argc,
|
||||
Arg* argv[]) {
|
||||
#if PIKA_NANO
|
||||
@ -859,17 +858,46 @@ char* _keys_to_defult(char* type_list,
|
||||
while (strIsContain(arg_name, '=')) {
|
||||
strPopLastToken(arg_name, '=');
|
||||
/* load default arg from kws */
|
||||
if (kws != NULL) {
|
||||
Arg* default_arg = pikaDict_getArg(kws, arg_name);
|
||||
if (f->kw != NULL) {
|
||||
Arg* default_arg = pikaDict_getArg(f->kw, arg_name);
|
||||
if (default_arg != NULL) {
|
||||
argv[(*argc)++] = arg_copy(default_arg);
|
||||
}
|
||||
}
|
||||
arg_name = strPopLastToken(type_list, ',');
|
||||
arg_name = strPopLastToken(f->type_list, ',');
|
||||
}
|
||||
return arg_name;
|
||||
}
|
||||
|
||||
static int _kw_to_pos_one(FunctionArgsInfo* f,
|
||||
char* arg_name,
|
||||
int* argc,
|
||||
Arg* argv[]) {
|
||||
if (f->kw == NULL) {
|
||||
return 0;
|
||||
}
|
||||
Arg* pos_arg = pikaDict_getArg(f->kw, arg_name);
|
||||
if (pos_arg == NULL) {
|
||||
return 0;
|
||||
}
|
||||
argv[(*argc)++] = arg_copy(pos_arg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _kw_to_pos_all(FunctionArgsInfo* f, int* argc, Arg* argv[]) {
|
||||
int arg_num_need = f->n_positional - f->n_positional_got;
|
||||
if (0 == arg_num_need) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < arg_num_need; i++) {
|
||||
char* arg_name = strPopLastToken(f->type_list, ',');
|
||||
pika_assert(f->kw != NULL);
|
||||
Arg* pos_arg = pikaDict_getArg(f->kw, arg_name);
|
||||
pika_assert(pos_arg != NULL);
|
||||
argv[(*argc)++] = arg_copy(pos_arg);
|
||||
}
|
||||
}
|
||||
|
||||
static void _loadLocalsFromArgv(Args* locals, int argc, Arg* argv[]) {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Arg* arg = argv[i];
|
||||
@ -877,143 +905,278 @@ static void _loadLocalsFromArgv(Args* locals, int argc, Arg* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
static void _type_list_parse(char* type_list,
|
||||
PIKA_BOOL* is_vars,
|
||||
PIKA_BOOL* is_keys,
|
||||
PIKA_BOOL* is_default,
|
||||
int8_t* num_pos,
|
||||
int8_t* num_default) {
|
||||
if (type_list[0] == 0) {
|
||||
*num_pos = 0;
|
||||
static void _type_list_parse(FunctionArgsInfo* f) {
|
||||
if (f->type_list[0] == 0) {
|
||||
f->n_positional = 0;
|
||||
return;
|
||||
}
|
||||
int8_t res = strCountSign(type_list, ',') + 1;
|
||||
int8_t x = strCountSign(type_list, '*');
|
||||
int8_t y = strCountSign(type_list, '=');
|
||||
int8_t res = strCountSign(f->type_list, ',') + 1;
|
||||
int8_t x = strCountSign(f->type_list, '*');
|
||||
int8_t y = strCountSign(f->type_list, '=');
|
||||
/* default */
|
||||
if (y > 0) {
|
||||
res -= y;
|
||||
*is_default = PIKA_TRUE;
|
||||
*num_default = y;
|
||||
f->is_default = PIKA_TRUE;
|
||||
f->n_default = y;
|
||||
}
|
||||
/* vars */
|
||||
if (x == 1) {
|
||||
*is_vars = PIKA_TRUE;
|
||||
*num_pos = res - 1;
|
||||
f->is_vars = PIKA_TRUE;
|
||||
f->n_positional = res - 1;
|
||||
return;
|
||||
}
|
||||
/* kw */
|
||||
if (x == 2) {
|
||||
*is_keys = 1;
|
||||
*num_pos = res - 1;
|
||||
f->is_keys = 1;
|
||||
f->n_positional = res - 1;
|
||||
return;
|
||||
}
|
||||
/* vars and kw */
|
||||
if (x == 3) {
|
||||
*is_vars = PIKA_TRUE;
|
||||
*is_keys = PIKA_TRUE;
|
||||
*num_pos = res - 2;
|
||||
f->is_vars = PIKA_TRUE;
|
||||
f->is_keys = PIKA_TRUE;
|
||||
f->n_positional = res - 2;
|
||||
return;
|
||||
}
|
||||
*num_pos = res;
|
||||
f->n_positional = res;
|
||||
return;
|
||||
}
|
||||
|
||||
static void _kw_push(PikaDict** kw_dict_p,
|
||||
PikaDict** kw_keys_p,
|
||||
Arg* call_arg,
|
||||
int i) {
|
||||
if (NULL == *kw_dict_p) {
|
||||
*kw_dict_p = New_pikaDict();
|
||||
static void _kw_push(FunctionArgsInfo* f, Arg* call_arg, int i) {
|
||||
if (NULL == f->kw) {
|
||||
f->kw = New_pikaDict();
|
||||
}
|
||||
if (NULL == *kw_keys_p) {
|
||||
*kw_keys_p = New_pikaDict();
|
||||
if (NULL == f->kw_keys) {
|
||||
f->kw_keys = New_pikaDict();
|
||||
}
|
||||
arg_setIsKeyword(call_arg, PIKA_FALSE);
|
||||
pikaDict_setArg(*kw_dict_p, call_arg);
|
||||
pikaDict_setArg(f->kw, call_arg);
|
||||
char kw_keys_index_buff[11] = {0};
|
||||
char* kw_keys_index = fast_itoa(kw_keys_index_buff, i);
|
||||
pikaDict_setArg(*kw_keys_p,
|
||||
pikaDict_setArg(f->kw_keys,
|
||||
arg_setInt(NULL, kw_keys_index, arg_getNameHash(call_arg)));
|
||||
}
|
||||
|
||||
static void _load_call_arg(VMState* vm,
|
||||
Arg* call_arg,
|
||||
FunctionArgsInfo* f,
|
||||
int* i,
|
||||
int* argc,
|
||||
Arg* argv[]) {
|
||||
/* load the kw arg */
|
||||
if (call_arg != NULL && arg_getIsKeyword(call_arg)) {
|
||||
_kw_push(f, call_arg, *i);
|
||||
return;
|
||||
}
|
||||
/* load variable arg */
|
||||
if (f->i_arg > f->n_positional) {
|
||||
if (f->is_vars) {
|
||||
pikaList_append(&(f->tuple)->super, call_arg);
|
||||
/* the append would copy the arg */
|
||||
if (NULL != call_arg) {
|
||||
arg_deinit(call_arg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
char* arg_name = strPopLastToken(f->type_list, ',');
|
||||
/* load default from pos */
|
||||
if (f->i_arg > f->n_positional) {
|
||||
if (f->is_default) {
|
||||
if (arg_name[strlen(arg_name) - 1] == '=') {
|
||||
/* found default arg*/
|
||||
arg_name[strlen(arg_name) - 1] = '\0';
|
||||
arg_setNameHash(call_arg, hash_time33EndWith(arg_name, ':'));
|
||||
argv[(*argc)++] = call_arg;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* load default from kw */
|
||||
arg_name = _kw_to_default_all(f, arg_name, argc, argv);
|
||||
/* load position arg */
|
||||
if (_kw_to_pos_one(f, arg_name, argc, argv)) {
|
||||
/* load pos from kw */
|
||||
(f->n_positional_got)++;
|
||||
/* restore the stack */
|
||||
(*i)--;
|
||||
stack_pushArg(&(vm->stack), call_arg);
|
||||
return;
|
||||
}
|
||||
/*load pos from pos */
|
||||
arg_setNameHash(call_arg, hash_time33EndWith(arg_name, ':'));
|
||||
argv[(*argc)++] = call_arg;
|
||||
(f->n_positional_got)++;
|
||||
}
|
||||
|
||||
static int _get_n_input_with_unpack(VMState* vm) {
|
||||
#if PIKA_NANO_ENABLE
|
||||
return VMState_getInputArgNum(vm);
|
||||
#else
|
||||
int n_input = VMState_getInputArgNum(vm);
|
||||
int get_star = 0;
|
||||
int unpack_num = 0;
|
||||
for (int i = 0; i < n_input; i++) {
|
||||
Arg* arg_check = stack_checkArg(&(vm->stack), i);
|
||||
if (NULL == arg_check) {
|
||||
break;
|
||||
}
|
||||
if (arg_getIsDoubleStarred(arg_check) || arg_getIsStarred(arg_check)) {
|
||||
get_star++;
|
||||
}
|
||||
}
|
||||
if (0 == get_star) {
|
||||
return n_input;
|
||||
}
|
||||
Stack stack_tmp = {0};
|
||||
stack_init(&stack_tmp);
|
||||
for (int i = 0; i < n_input; i++) {
|
||||
/* unpack starred arg */
|
||||
Arg* call_arg = stack_popArg_alloc(&(vm->stack));
|
||||
if (call_arg == NULL) {
|
||||
break;
|
||||
}
|
||||
if (arg_getIsStarred(call_arg)) {
|
||||
pika_assert(argType_isObject(arg_getType(call_arg)));
|
||||
PikaObj* obj = arg_getPtr(call_arg);
|
||||
/* clang-format off */
|
||||
PIKA_PYTHON(
|
||||
@l = __len__()
|
||||
)
|
||||
/* clang-format on */
|
||||
const uint8_t bytes[] = {
|
||||
0x08, 0x00, 0x00, 0x00, /* instruct array size */
|
||||
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x09, 0x00, /* instruct
|
||||
array */
|
||||
0x0c, 0x00, 0x00, 0x00, /* const pool size */
|
||||
0x00, 0x5f, 0x5f, 0x6c, 0x65, 0x6e, 0x5f, 0x5f, 0x00,
|
||||
0x40, 0x6c, 0x00, /* const pool */
|
||||
};
|
||||
pikaVM_runByteCode(obj, (uint8_t*)bytes);
|
||||
int len = obj_getInt(obj, "@l");
|
||||
for (int i_star_arg = len - 1; i_star_arg >= 0; i_star_arg--) {
|
||||
obj_setInt(obj, "@d", i_star_arg);
|
||||
/* clang-format off */
|
||||
PIKA_PYTHON(
|
||||
@a = __getitem__(@d)
|
||||
)
|
||||
/* clang-format on */
|
||||
const uint8_t bytes[] = {
|
||||
0x0c, 0x00, 0x00, 0x00, /* instruct array size */
|
||||
0x10, 0x81, 0x01, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x04,
|
||||
0x10, 0x00,
|
||||
/* instruct array */
|
||||
0x13, 0x00, 0x00, 0x00, /* const pool size */
|
||||
0x00, 0x40, 0x64, 0x00, 0x5f, 0x5f, 0x67, 0x65, 0x74, 0x69,
|
||||
0x74, 0x65, 0x6d, 0x5f, 0x5f, 0x00, 0x40, 0x61,
|
||||
0x00, /* const pool */
|
||||
};
|
||||
pikaVM_runByteCode(obj, (uint8_t*)bytes);
|
||||
Arg* arg_a = obj_getArg(obj, "@a");
|
||||
stack_pushArg(&stack_tmp, arg_copy(arg_a));
|
||||
unpack_num++;
|
||||
}
|
||||
goto __continue;
|
||||
}
|
||||
if (arg_getIsDoubleStarred(call_arg)) {
|
||||
pika_assert(argType_isObject(arg_getType(call_arg)));
|
||||
PikaObj* New_PikaStdData_Dict(Args * args);
|
||||
PikaObj* obj = arg_getPtr(call_arg);
|
||||
pika_assert(obj->constructor == New_PikaStdData_Dict);
|
||||
PikaDict* dict = obj_getPtr(obj, "dict");
|
||||
int i_item = 0;
|
||||
while (PIKA_TRUE) {
|
||||
Arg* item_val = args_getArgByidex(&dict->super, i_item);
|
||||
if (NULL == item_val) {
|
||||
break;
|
||||
}
|
||||
/* unpack as keyword arg */
|
||||
arg_setIsKeyword(item_val, 1);
|
||||
stack_pushArg(&stack_tmp, arg_copy(item_val));
|
||||
i_item++;
|
||||
}
|
||||
goto __continue;
|
||||
}
|
||||
stack_pushArg(&stack_tmp, arg_copy(call_arg));
|
||||
__continue:
|
||||
if (NULL != call_arg) {
|
||||
arg_deinit(call_arg);
|
||||
}
|
||||
}
|
||||
int n_input_new = stack_getTop(&stack_tmp);
|
||||
for (int i = 0; i < n_input_new; i++) {
|
||||
Arg* arg = stack_popArg_alloc(&stack_tmp);
|
||||
stack_pushArg(&(vm->stack), arg);
|
||||
}
|
||||
stack_deinit(&stack_tmp);
|
||||
return n_input_new;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define vars_or_keys_or_default (f.is_vars || f.is_keys || f.is_default)
|
||||
static int VMState_loadArgsFromMethodArg(VMState* vm,
|
||||
PikaObj* method_host_obj,
|
||||
Args* locals,
|
||||
Arg* method_arg,
|
||||
char* method_name,
|
||||
int arg_num_used) {
|
||||
int n_used) {
|
||||
Arg* argv[PIKA_ARG_NUM_MAX] = {0};
|
||||
int argc = 0;
|
||||
char _buffs1[PIKA_LINE_BUFF_SIZE] = {0};
|
||||
char* buffs1 = (char*)_buffs1;
|
||||
char _buffs2[PIKA_LINE_BUFF_SIZE] = {0};
|
||||
char* buffs2 = (char*)_buffs2;
|
||||
int8_t arg_num_pos = 0;
|
||||
int8_t arg_num_default = 0;
|
||||
int8_t arg_num = 0;
|
||||
int8_t arg_num_input = 0;
|
||||
PIKA_BOOL is_vars = PIKA_FALSE;
|
||||
PIKA_BOOL is_keys = PIKA_FALSE;
|
||||
PIKA_BOOL is_default = PIKA_FALSE;
|
||||
#define vars_or_keys_or_default (is_vars || is_keys || is_default)
|
||||
ArgType method_type = ARG_TYPE_UNDEF;
|
||||
PikaTuple* tuple = NULL;
|
||||
PikaDict* kw_dict = NULL;
|
||||
PikaDict* kw_keys = NULL;
|
||||
char* var_tuple_name = NULL;
|
||||
char* kw_dict_name = NULL;
|
||||
FunctionArgsInfo f = {0};
|
||||
char* type_list_buff = NULL;
|
||||
/* get method type list */
|
||||
char* type_list =
|
||||
methodArg_getTypeList(method_arg, buffs1, sizeof(_buffs1));
|
||||
if (NULL == type_list) {
|
||||
f.type_list = methodArg_getTypeList(method_arg, buffs1, sizeof(_buffs1));
|
||||
if (NULL == f.type_list) {
|
||||
__platform_printf(
|
||||
"OverflowError: type list is too long, please use bigger "
|
||||
"PIKA_LINE_BUFF_SIZE\r\n");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
method_type = arg_getType(method_arg);
|
||||
f.method_type = arg_getType(method_arg);
|
||||
|
||||
/* get arg_num_pos */
|
||||
_type_list_parse(type_list, &is_vars, &is_keys, &is_default, &arg_num_pos,
|
||||
&arg_num_default);
|
||||
if (method_type == ARG_TYPE_METHOD_OBJECT) {
|
||||
_type_list_parse(&f);
|
||||
if (f.method_type == ARG_TYPE_METHOD_OBJECT) {
|
||||
/* delete the 'self' */
|
||||
arg_num_pos--;
|
||||
f.n_positional--;
|
||||
}
|
||||
arg_num_input = VMState_getInputArgNum(vm);
|
||||
|
||||
f.n_input = _get_n_input_with_unpack(vm);
|
||||
|
||||
/* check arg num */
|
||||
if (method_type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
|
||||
method_type == ARG_TYPE_METHOD_CONSTRUCTOR || is_vars == PIKA_TRUE ||
|
||||
arg_num_used != 0) {
|
||||
if (f.method_type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
|
||||
f.method_type == ARG_TYPE_METHOD_CONSTRUCTOR ||
|
||||
f.is_vars == PIKA_TRUE || n_used != 0) {
|
||||
/* skip for constrctor */
|
||||
/* skip for variable args */
|
||||
/* arg_num_used != 0 means it is a factory method */
|
||||
/* n_used != 0 means it is a factory method */
|
||||
} else {
|
||||
/* check position arg num */
|
||||
if (!vars_or_keys_or_default) {
|
||||
if (arg_num_pos != arg_num_input) {
|
||||
if (f.n_positional != f.n_input) {
|
||||
VMState_setErrorCode(vm, PIKA_RES_ERR_INVALID_PARAM);
|
||||
__platform_printf(
|
||||
"TypeError: %s() takes %d positional argument but %d were "
|
||||
"given\r\n",
|
||||
method_name, arg_num_pos, arg_num_input);
|
||||
method_name, f.n_positional, f.n_input);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
#if !PIKA_NANO_ENABLE
|
||||
if (is_default) {
|
||||
int8_t arg_num_min = arg_num_pos;
|
||||
int8_t arg_num_max = arg_num_pos + arg_num_default;
|
||||
if (arg_num_input < arg_num_min || arg_num_input > arg_num_max) {
|
||||
if (f.is_default) {
|
||||
int8_t n_min = f.n_positional;
|
||||
int8_t n_max = f.n_positional + f.n_default;
|
||||
if (f.n_input < n_min || f.n_input > n_max) {
|
||||
VMState_setErrorCode(vm, PIKA_RES_ERR_INVALID_PARAM);
|
||||
__platform_printf(
|
||||
"TypeError: %s() takes from %d to %d positional arguments "
|
||||
"but %d were given\r\n",
|
||||
method_name, arg_num_min, arg_num_max, arg_num_input);
|
||||
method_name, n_min, n_max, f.n_input);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@ -1021,128 +1184,96 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
|
||||
}
|
||||
|
||||
if (vars_or_keys_or_default) {
|
||||
arg_num = arg_num_input;
|
||||
f.n_arg = f.n_input;
|
||||
} else {
|
||||
arg_num = arg_num_pos;
|
||||
f.n_arg = f.n_positional;
|
||||
}
|
||||
|
||||
/* create tuple/dict for vars/keys */
|
||||
if (vars_or_keys_or_default) {
|
||||
if (strGetSize(type_list) > sizeof(_buffs2)) {
|
||||
if (strGetSize(f.type_list) > sizeof(_buffs2)) {
|
||||
__platform_printf(
|
||||
"OverFlowError: please use bigger PIKA_LINE_BUFF_SIZE\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
type_list_buff = strCopy(buffs2, type_list);
|
||||
uint8_t arg_num_dec_any = strCountSign(type_list_buff, ',') + 1;
|
||||
for (int i = 0; i < arg_num_dec_any; i++) {
|
||||
type_list_buff = strCopy(buffs2, f.type_list);
|
||||
uint8_t n_typelist = strCountSign(type_list_buff, ',') + 1;
|
||||
for (int i = 0; i < n_typelist; i++) {
|
||||
char* arg_def = strPopLastToken(type_list_buff, ',');
|
||||
if (arg_def[0] == '*' && arg_def[1] != '*') {
|
||||
/* get variable tuple name */
|
||||
/* skip the '*' */
|
||||
var_tuple_name = arg_def + 1;
|
||||
f.var_tuple_name = arg_def + 1;
|
||||
/* create tuple */
|
||||
if (NULL == tuple) {
|
||||
tuple = New_pikaTuple();
|
||||
if (NULL == f.tuple) {
|
||||
f.tuple = New_pikaTuple();
|
||||
/* remove the format arg */
|
||||
strPopLastToken(type_list, ',');
|
||||
strPopLastToken(f.type_list, ',');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (arg_def[0] == '*' && arg_def[1] == '*') {
|
||||
/* get keyword dict name */
|
||||
kw_dict_name = arg_def + 2;
|
||||
kw_dict = New_pikaDict();
|
||||
kw_keys = New_pikaDict();
|
||||
/* get kw dict name */
|
||||
f.kw_dict_name = arg_def + 2;
|
||||
f.kw = New_pikaDict();
|
||||
f.kw_keys = New_pikaDict();
|
||||
/* remove the format arg */
|
||||
strPopLastToken(type_list, ',');
|
||||
strPopLastToken(f.type_list, ',');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* load pars */
|
||||
for (int i = 0; i < arg_num; i++) {
|
||||
int arg_index = arg_num - i;
|
||||
/* load args */
|
||||
for (int i = 0; i < f.n_arg; i++) {
|
||||
f.i_arg = f.n_arg - i;
|
||||
Arg* call_arg = stack_popArg_alloc(&(vm->stack));
|
||||
/* load the keyword arg */
|
||||
if (call_arg != NULL && arg_getIsKeyword(call_arg)) {
|
||||
_kw_push(&kw_dict, &kw_keys, call_arg, i);
|
||||
continue;
|
||||
}
|
||||
/* load variable arg */
|
||||
if (arg_index > arg_num_pos) {
|
||||
if (is_vars) {
|
||||
pikaList_append(&tuple->super, call_arg);
|
||||
/* the append would copy the arg */
|
||||
if (NULL != call_arg) {
|
||||
arg_deinit(call_arg);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
char* arg_name = strPopLastToken(type_list, ',');
|
||||
/* load default from pos */
|
||||
if (arg_index > arg_num_pos) {
|
||||
if (is_default) {
|
||||
if (arg_name[strlen(arg_name) - 1] == '=') {
|
||||
/* found default arg*/
|
||||
arg_name[strlen(arg_name) - 1] = '\0';
|
||||
arg_setNameHash(call_arg,
|
||||
hash_time33EndWith(arg_name, ':'));
|
||||
argv[argc++] = call_arg;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* load default from kw */
|
||||
arg_name = _keys_to_defult(type_list, arg_name, kw_dict, &argc, argv);
|
||||
/* load position arg */
|
||||
arg_setNameHash(call_arg, hash_time33EndWith(arg_name, ':'));
|
||||
argv[argc++] = call_arg;
|
||||
_load_call_arg(vm, call_arg, &f, &i, &argc, argv);
|
||||
}
|
||||
|
||||
/* only default */
|
||||
#if !PIKA_NANO_ENABLE
|
||||
if (strIsContain(type_list, '=')) {
|
||||
char* arg_name = strPopLastToken(type_list, ',');
|
||||
_keys_to_defult(type_list, arg_name, kw_dict, &argc, argv);
|
||||
if (strIsContain(f.type_list, '=')) {
|
||||
char* arg_name = strPopLastToken(f.type_list, ',');
|
||||
_kw_to_default_all(&f, arg_name, &argc, argv);
|
||||
}
|
||||
/* load kw to pos */
|
||||
_kw_to_pos_all(&f, &argc, argv);
|
||||
#endif
|
||||
|
||||
if (tuple != NULL) {
|
||||
pikaList_reverse(&tuple->super);
|
||||
if (f.tuple != NULL) {
|
||||
pikaList_reverse(&(f.tuple)->super);
|
||||
/* load variable tuple */
|
||||
PikaObj* New_PikaStdData_Tuple(Args * args);
|
||||
PikaObj* tuple_obj = newNormalObj(New_PikaStdData_Tuple);
|
||||
obj_setPtr(tuple_obj, "list", tuple);
|
||||
obj_setPtr(tuple_obj, "list", f.tuple);
|
||||
Arg* argi =
|
||||
arg_setPtr(NULL, var_tuple_name, ARG_TYPE_OBJECT, tuple_obj);
|
||||
arg_setPtr(NULL, f.var_tuple_name, ARG_TYPE_OBJECT, tuple_obj);
|
||||
argv[argc++] = argi;
|
||||
}
|
||||
|
||||
if (kw_dict != NULL) {
|
||||
if (NULL == kw_dict_name) {
|
||||
kw_dict_name = "__kwargs";
|
||||
if (f.kw != NULL) {
|
||||
if (NULL == f.kw_dict_name) {
|
||||
f.kw_dict_name = "__kwargs";
|
||||
}
|
||||
/* load keyword dict */
|
||||
/* load kw dict */
|
||||
PikaObj* New_PikaStdData_Dict(Args * args);
|
||||
PikaObj* dict_obj = newNormalObj(New_PikaStdData_Dict);
|
||||
obj_setPtr(dict_obj, "dict", kw_dict);
|
||||
obj_setPtr(dict_obj, "_keys", kw_keys);
|
||||
Arg* argi = arg_setPtr(NULL, kw_dict_name, ARG_TYPE_OBJECT, dict_obj);
|
||||
obj_setPtr(dict_obj, "dict", f.kw);
|
||||
obj_setPtr(dict_obj, "_keys", f.kw_keys);
|
||||
Arg* argi = arg_setPtr(NULL, f.kw_dict_name, ARG_TYPE_OBJECT, dict_obj);
|
||||
argv[argc++] = argi;
|
||||
}
|
||||
|
||||
/* load 'self' as the first arg when call object method */
|
||||
if (method_type == ARG_TYPE_METHOD_OBJECT) {
|
||||
if (f.method_type == ARG_TYPE_METHOD_OBJECT) {
|
||||
Arg* call_arg = arg_setRef(NULL, "self", method_host_obj);
|
||||
argv[argc++] = call_arg;
|
||||
}
|
||||
_loadLocalsFromArgv(locals, argc, argv);
|
||||
exit:
|
||||
return arg_num;
|
||||
return f.n_arg;
|
||||
}
|
||||
|
||||
void __vm_List_append(PikaObj* self, Arg* arg) {
|
||||
@ -1165,18 +1296,18 @@ static Arg* _vm_create_list_or_tuple(PikaObj* self,
|
||||
PIKA_BOOL is_list) {
|
||||
#if PIKA_BUILTIN_STRUCT_ENABLE
|
||||
NewFun constructor = is_list ? New_PikaStdData_List : New_PikaStdData_Tuple;
|
||||
uint8_t arg_num = VMState_getInputArgNum(vm);
|
||||
uint8_t n_arg = VMState_getInputArgNum(vm);
|
||||
PikaObj* list = newNormalObj(constructor);
|
||||
__vm_List___init__(list);
|
||||
Stack stack = {0};
|
||||
stack_init(&stack);
|
||||
/* load to local stack to change sort */
|
||||
for (int i = 0; i < arg_num; i++) {
|
||||
for (int i = 0; i < n_arg; i++) {
|
||||
Arg* arg = stack_popArg_alloc(&(vm->stack));
|
||||
pika_assert(arg != NULL);
|
||||
stack_pushArg(&stack, arg);
|
||||
}
|
||||
for (int i = 0; i < arg_num; i++) {
|
||||
for (int i = 0; i < n_arg; i++) {
|
||||
Arg* arg = stack_popArg_alloc(&stack);
|
||||
pika_assert(arg != NULL);
|
||||
__vm_List_append(list, arg);
|
||||
@ -1222,17 +1353,17 @@ static Arg* VM_instruction_handler_DCT(PikaObj* self,
|
||||
char* data,
|
||||
Arg* arg_ret_reg) {
|
||||
#if PIKA_BUILTIN_STRUCT_ENABLE
|
||||
uint8_t arg_num = VMState_getInputArgNum(vm);
|
||||
uint8_t n_arg = VMState_getInputArgNum(vm);
|
||||
PikaObj* dict = newNormalObj(New_PikaStdData_Dict);
|
||||
__vm_Dict___init__(dict);
|
||||
Stack stack = {0};
|
||||
stack_init(&stack);
|
||||
/* load to local stack to change sort */
|
||||
for (int i = 0; i < arg_num; i++) {
|
||||
for (int i = 0; i < n_arg; i++) {
|
||||
Arg* arg = stack_popArg_alloc(&(vm->stack));
|
||||
stack_pushArg(&stack, arg);
|
||||
}
|
||||
for (int i = 0; i < arg_num / 2; i++) {
|
||||
for (int i = 0; i < n_arg / 2; i++) {
|
||||
Arg* key_arg = stack_popArg_alloc(&stack);
|
||||
Arg* val_arg = stack_popArg_alloc(&stack);
|
||||
__vm_Dict_set(dict, val_arg, arg_getStr(key_arg));
|
||||
@ -1329,7 +1460,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
||||
PIKA_BOOL is_temp = PIKA_FALSE;
|
||||
PIKA_BOOL skip_init = PIKA_FALSE;
|
||||
char* sys_out;
|
||||
int arg_num_used = 0;
|
||||
int n_used = 0;
|
||||
arg_newReg(arg_reg1, 64);
|
||||
RunState sub_run_state = {.try_state = vm->run_state->try_state,
|
||||
.try_result = TRY_RESULT_NONE};
|
||||
@ -1387,24 +1518,24 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
||||
if (NULL == method_host && run_path[0] == '.') {
|
||||
/* get method host obj from stack */
|
||||
Arg* stack_tmp[PIKA_ARG_NUM_MAX] = {0};
|
||||
int arg_num = VMState_getInputArgNum(vm);
|
||||
if (arg_num > PIKA_ARG_NUM_MAX) {
|
||||
int n_arg = VMState_getInputArgNum(vm);
|
||||
if (n_arg > PIKA_ARG_NUM_MAX) {
|
||||
__platform_printf(
|
||||
"[ERROR] Too many args in RUN instruction, please use bigger "
|
||||
"#define PIKA_ARG_NUM_MAX\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arg_num; i++) {
|
||||
for (int i = 0; i < n_arg; i++) {
|
||||
stack_tmp[i] = stack_popArg_alloc(&(vm->stack));
|
||||
}
|
||||
host_arg = stack_tmp[arg_num - 1];
|
||||
host_arg = stack_tmp[n_arg - 1];
|
||||
method_host = _arg_to_obj(host_arg, &is_temp);
|
||||
if (NULL != method_host) {
|
||||
arg_num_used++;
|
||||
n_used++;
|
||||
}
|
||||
/* push back other args to stack */
|
||||
for (int i = arg_num - 2; i >= 0; i--) {
|
||||
for (int i = n_arg - 2; i >= 0; i--) {
|
||||
stack_pushArg(&(vm->stack), stack_tmp[i]);
|
||||
}
|
||||
}
|
||||
@ -1477,8 +1608,8 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
||||
sub_locals = New_PikaObj();
|
||||
|
||||
/* load args from vmState to sub_local->list */
|
||||
arg_num_used += VMState_loadArgsFromMethodArg(
|
||||
vm, obj_this, sub_locals->list, method, run_path, arg_num_used);
|
||||
n_used += VMState_loadArgsFromMethodArg(vm, obj_this, sub_locals->list,
|
||||
method, run_path, n_used);
|
||||
|
||||
/* load args failed */
|
||||
if (vm->error_code != 0) {
|
||||
@ -1514,7 +1645,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
||||
goto init_exit;
|
||||
}
|
||||
VMState_loadArgsFromMethodArg(vm, new_obj, sub_locals->list, method_arg,
|
||||
"__init__", arg_num_used);
|
||||
"__init__", n_used);
|
||||
/* load args failed */
|
||||
if (vm->error_code != 0) {
|
||||
goto init_exit;
|
||||
@ -1563,27 +1694,55 @@ exit:
|
||||
}
|
||||
|
||||
static char* __get_transferd_str(Args* buffs, char* str, size_t* iout_p) {
|
||||
char* str_rep = strsReplace(buffs, str, "\\n", "\n");
|
||||
str_rep = strsReplace(buffs, str_rep, "\\r", "\r");
|
||||
str_rep = strsReplace(buffs, str_rep, "\\t", "\t");
|
||||
str_rep = strsReplace(buffs, str_rep, "\\\\", "\\");
|
||||
|
||||
char* transfered_str = args_getBuff(buffs, strGetSize(str_rep));
|
||||
char* transfered_str = args_getBuff(buffs, strGetSize(str));
|
||||
size_t i_out = 0;
|
||||
size_t len = strGetSize(str_rep);
|
||||
size_t len = strGetSize(str);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
/* eg. replace '\x33' to '3' */
|
||||
if ((str_rep[i] == '\\') && (str_rep[i + 1] == 'x')) {
|
||||
if ((str[i] == '\\') && (str[i + 1] == 'x')) {
|
||||
char hex_str[] = "0x00";
|
||||
hex_str[2] = str_rep[i + 2];
|
||||
hex_str[3] = str_rep[i + 3];
|
||||
hex_str[2] = str[i + 2];
|
||||
hex_str[3] = str[i + 3];
|
||||
char hex = (char)strtoll(hex_str, NULL, 0);
|
||||
transfered_str[i_out++] = hex;
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
if (str[i] == '\\') {
|
||||
switch (str[i + 1]) {
|
||||
case 'r':
|
||||
transfered_str[i_out++] = '\r';
|
||||
break;
|
||||
case 'n':
|
||||
transfered_str[i_out++] = '\n';
|
||||
break;
|
||||
case 't':
|
||||
transfered_str[i_out++] = '\t';
|
||||
break;
|
||||
case 'b':
|
||||
transfered_str[i_out++] = '\b';
|
||||
break;
|
||||
case '\\':
|
||||
transfered_str[i_out++] = '\\';
|
||||
break;
|
||||
case '\'':
|
||||
transfered_str[i_out++] = '\'';
|
||||
break;
|
||||
case '\"':
|
||||
transfered_str[i_out++] = '\"';
|
||||
break;
|
||||
case '?':
|
||||
transfered_str[i_out++] = '\?';
|
||||
break;
|
||||
default:
|
||||
transfered_str[i_out++] = str[i];
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
/* normal char */
|
||||
transfered_str[i_out++] = str_rep[i];
|
||||
transfered_str[i_out++] = str[i];
|
||||
}
|
||||
*iout_p = i_out;
|
||||
return transfered_str;
|
||||
@ -1666,7 +1825,7 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self,
|
||||
}
|
||||
ArgType outArg_type = arg_getType(out_arg);
|
||||
if (VMState_getInvokeDeepthNow(vm) > 0) {
|
||||
/* in block, is a keyword arg */
|
||||
/* in block, is a kw arg */
|
||||
arg_setIsKeyword(out_arg, PIKA_TRUE);
|
||||
arg_setName(out_arg, arg_path);
|
||||
Arg* res = arg_copy_noalloc(out_arg, arg_ret_reg);
|
||||
@ -2097,6 +2256,11 @@ exit:
|
||||
}
|
||||
|
||||
static void _OPT_POW(OperatorInfo* op) {
|
||||
if (op->num == 1) {
|
||||
op->res = arg_copy(op->a2);
|
||||
arg_setIsDoubleStarred(op->res, 1);
|
||||
return;
|
||||
}
|
||||
if (op->t1 == ARG_TYPE_INT && op->t2 == ARG_TYPE_INT) {
|
||||
int res = 1;
|
||||
for (int i = 0; i < op->i2; i++) {
|
||||
@ -2173,6 +2337,11 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
||||
op.res = arg_setInt(op.res, "", op.f1 < op.f2);
|
||||
goto exit;
|
||||
case '*':
|
||||
if (op.num == 1) {
|
||||
op.res = arg_copy(op.a2);
|
||||
arg_setIsStarred(op.res, 1);
|
||||
goto exit;
|
||||
}
|
||||
if ((op.t1 == ARG_TYPE_FLOAT) || op.t2 == ARG_TYPE_FLOAT) {
|
||||
op.res = arg_setFloat(op.res, "", op.f1 * op.f2);
|
||||
goto exit;
|
||||
@ -2449,11 +2618,11 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self,
|
||||
Arg* arg1 = NULL;
|
||||
Arg* arg2 = NULL;
|
||||
Arg* res = NULL;
|
||||
int arg_num = VMState_getInputArgNum(vm);
|
||||
if (arg_num == 1) {
|
||||
int n_arg = VMState_getInputArgNum(vm);
|
||||
if (n_arg == 1) {
|
||||
arg1 = stack_popArg(&vm->stack, ®1);
|
||||
}
|
||||
if (arg_num == 2) {
|
||||
if (n_arg == 2) {
|
||||
arg2 = stack_popArg(&vm->stack, ®2);
|
||||
arg1 = stack_popArg(&vm->stack, ®1);
|
||||
}
|
||||
@ -2462,10 +2631,10 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self,
|
||||
stack_pushArg(&vm->stack, arg_newInt(PIKA_RES_ERR_ASSERT));
|
||||
res = VM_instruction_handler_RIS(self, vm, data, arg_ret_reg);
|
||||
if (vm->run_state->try_state == TRY_STATE_NONE) {
|
||||
if (arg_num == 1) {
|
||||
if (n_arg == 1) {
|
||||
__platform_printf("AssertionError\n");
|
||||
}
|
||||
if (arg_num == 2) {
|
||||
if (n_arg == 2) {
|
||||
__platform_printf("AssertionError: %s\n", arg_getStr(arg2));
|
||||
}
|
||||
}
|
||||
@ -3365,7 +3534,7 @@ PikaObj* pikaVM_runFile(PikaObj* self, char* file_name) {
|
||||
PikaMaker* maker = New_PikaMaker();
|
||||
pikaMaker_compileModuleWithDepends(maker, module_name);
|
||||
pikaMaker_linkCompiledModules(maker, "pikaModules_cache.py.a");
|
||||
obj_deinit(maker);
|
||||
pikaMaker_deinit(maker);
|
||||
__platform_printf("(pikascript) all succeed.\r\n\r\n");
|
||||
|
||||
pikaMemMaxReset();
|
||||
|
19
src/PikaVM.h
19
src/PikaVM.h
@ -83,6 +83,25 @@ struct VMState {
|
||||
RunState* run_state;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int8_t n_positional;
|
||||
int8_t n_positional_got;
|
||||
int8_t n_default;
|
||||
int8_t n_arg;
|
||||
int8_t i_arg;
|
||||
int8_t n_input;
|
||||
PIKA_BOOL is_vars;
|
||||
PIKA_BOOL is_keys;
|
||||
PIKA_BOOL is_default;
|
||||
ArgType method_type;
|
||||
PikaTuple* tuple;
|
||||
PikaDict* kw;
|
||||
PikaDict* kw_keys;
|
||||
char* var_tuple_name;
|
||||
char* kw_dict_name;
|
||||
char* type_list;
|
||||
} FunctionArgsInfo;
|
||||
|
||||
typedef struct OperatorInfo OperatorInfo;
|
||||
struct OperatorInfo {
|
||||
char* opt;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#define PIKA_VERSION_MAJOR 1
|
||||
#define PIKA_VERSION_MINOR 11
|
||||
#define PIKA_VERSION_MICRO 7
|
||||
#define PIKA_VERSION_MICRO 8
|
||||
|
||||
#define PIKA_EDIT_TIME "2022/11/19 19:43:26"
|
||||
#define PIKA_EDIT_TIME "2022/12/03 19:05:57"
|
||||
|
@ -172,7 +172,9 @@ Arg* arg_loadFile(Arg* self, char* filename);
|
||||
#define ARG_FLAG_SERIALIZED 0x01
|
||||
#define ARG_FLAG_KEYWORD 0x02
|
||||
#define ARG_FLAG_WEAK_REF 0x04
|
||||
#define ARG_FLAG_MAX 0x08
|
||||
#define ARG_FLAG_STARRED 0x08
|
||||
#define ARG_FLAG_DOUBLE_STARRED 0x10
|
||||
#define ARG_FLAG_MAX 0x18
|
||||
|
||||
static inline Arg* arg_getNext(Arg* self) {
|
||||
return self->_.next;
|
||||
@ -190,6 +192,7 @@ static inline uint32_t arg_getSize(Arg* self) {
|
||||
|
||||
static inline uint8_t arg_isSerialized(Arg* self) {
|
||||
pika_assert(NULL != self);
|
||||
pika_assert(self->flag <= ARG_FLAG_MAX);
|
||||
return self->flag & ARG_FLAG_SERIALIZED;
|
||||
}
|
||||
|
||||
@ -199,6 +202,7 @@ static inline void arg_setSerialized(Arg* self, uint8_t serialized) {
|
||||
}
|
||||
|
||||
static inline uint8_t arg_getIsKeyword(Arg* self) {
|
||||
pika_assert(self->flag <= ARG_FLAG_MAX);
|
||||
return self->flag & ARG_FLAG_KEYWORD;
|
||||
}
|
||||
|
||||
@ -208,6 +212,7 @@ static inline void arg_setIsKeyword(Arg* self, uint8_t isKeyword) {
|
||||
}
|
||||
|
||||
static inline uint8_t arg_getIsWeakRef(Arg* self) {
|
||||
pika_assert(self->flag <= ARG_FLAG_MAX);
|
||||
return self->flag & ARG_FLAG_WEAK_REF;
|
||||
}
|
||||
|
||||
@ -217,7 +222,28 @@ static inline void arg_setIsWeakRef(Arg* self, uint8_t isWeakRef) {
|
||||
(self->flag & ~ARG_FLAG_WEAK_REF) | (isWeakRef ? ARG_FLAG_WEAK_REF : 0);
|
||||
}
|
||||
|
||||
static inline void arg_setIsStarred(Arg* self, uint8_t isStarred) {
|
||||
self->flag =
|
||||
(self->flag & ~ARG_FLAG_STARRED) | (isStarred ? ARG_FLAG_STARRED : 0);
|
||||
}
|
||||
|
||||
static inline uint8_t arg_getIsStarred(Arg* self) {
|
||||
pika_assert(self->flag <= ARG_FLAG_MAX);
|
||||
return self->flag & ARG_FLAG_STARRED;
|
||||
}
|
||||
|
||||
static inline void arg_setIsDoubleStarred(Arg* self, uint8_t isDoubleStarred) {
|
||||
self->flag = (self->flag & ~ARG_FLAG_DOUBLE_STARRED) |
|
||||
(isDoubleStarred ? ARG_FLAG_DOUBLE_STARRED : 0);
|
||||
}
|
||||
|
||||
static inline uint8_t arg_getIsDoubleStarred(Arg* self) {
|
||||
pika_assert(self->flag <= ARG_FLAG_MAX);
|
||||
return self->flag & ARG_FLAG_DOUBLE_STARRED;
|
||||
}
|
||||
|
||||
static inline uint8_t* arg_getContent(Arg* self) {
|
||||
pika_assert(self->flag <= ARG_FLAG_MAX);
|
||||
pika_assert(NULL != self);
|
||||
return (arg_isSerialized(self)) ? (self)->content : ((self)->_.buffer);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user