mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
Merge branch 'master' into mqttdev
This commit is contained in:
commit
5a16752b08
1
.github/workflows/CI.yml
vendored
1
.github/workflows/CI.yml
vendored
@ -25,6 +25,7 @@ jobs:
|
||||
sudo apt install liblua5.3-dev
|
||||
sudo apt install valgrind
|
||||
sudo apt install upx
|
||||
sudo apt install libmbedtls-dev
|
||||
|
||||
- name: install_google_benchmark
|
||||
run: |
|
||||
|
1
.github/workflows/TEST.yml
vendored
1
.github/workflows/TEST.yml
vendored
@ -25,6 +25,7 @@ jobs:
|
||||
sudo apt install liblua5.3-dev
|
||||
sudo apt install valgrind
|
||||
sudo apt install upx
|
||||
sudo apt install libmbedtls-dev
|
||||
|
||||
- name: install_google_benchmark
|
||||
run: git clone --branch v1.6.1 https://github.com/google/benchmark.git && cd benchmark && cmake -E make_directory "build" && cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../ && cmake --build "build" --config Release && sudo cmake --build "build" --config Release --target install
|
||||
|
@ -619,6 +619,7 @@ In addition to device drivers, developing custom Python modules for MCU is very
|
||||
|
||||
| Contribute log | Contributer |
|
||||
| --- | --- |
|
||||
| Donate:500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|
||||
| Donate:500¥ | [edmund_wz](https://gitee.com/edmund_wz) |
|
||||
| Donate:500¥ | [Meco Jianting Man](https://github.com/mysterywolf) |
|
||||
| Donate:500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|
||||
|
@ -619,6 +619,7 @@ while True:
|
||||
|
||||
| 贡献记录 | 贡献者 |
|
||||
| --- | --- |
|
||||
| Donate:500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|
||||
| Donate:500¥ | [edmund_wz](https://gitee.com/edmund_wz) |
|
||||
| Donate:500¥ | [Meco Jianting Man](https://github.com/mysterywolf) |
|
||||
| Donate:500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|
||||
|
@ -1,3 +1,4 @@
|
||||
| Donate:500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|
||||
| Donate:500¥ | [edmund_wz](https://gitee.com/edmund_wz) |
|
||||
| Donate:500¥ | [Meco Jianting Man](https://github.com/mysterywolf) |
|
||||
| Donate:500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
AIR32F1==latest
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
CH582==v1.1.2
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
ESP32==v0.1.0
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
pika_lvgl==v0.3.2
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
|
@ -1,3 +1,3 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
Arm2D==v0.6.1
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F1==v1.1.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F4==v0.1.1
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
STM32F4==v0.1.1
|
||||
|
@ -314,7 +314,7 @@
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>6</Optim>
|
||||
<Optim>7</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
@ -651,306 +651,6 @@
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>pikascript-api</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>STM32G0_GPIO-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_GPIO-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_CAN-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdDevice_CAN-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Arm2D-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/Arm2D-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>STM32G0_PWM-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_PWM-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>PikaPiZero_RGB-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaPiZero_RGB-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>pikaScript.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/pikaScript.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>Arm2D_Window-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/Arm2D_Window-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>PikaStdDevice_UART-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdDevice_UART-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdDevice-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>Arm2D_ElementList-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/Arm2D_ElementList-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>STM32G0_lowLevel-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_lowLevel-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaDebug-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaDebug-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>STM32G0_IIC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_IIC-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>PikaPiZero_Point-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaPiZero_Point-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32G0-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0-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>Arm2D_BackGround-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/Arm2D_BackGround-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaPiZero-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaPiZero-api.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>PikaStdLib_RangeObj-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdLib_RangeObj-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaMain-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaMain-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32G0_UART-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_UART-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32G0_Time-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_Time-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdData-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>PikaStdLib_StringObj-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdLib_StringObj-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaPiZero_LCD-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaPiZero_LCD-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>Arm2D_Element-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/Arm2D_Element-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>STM32G0_Task-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_Task-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdLib_MemChecker-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdLib_MemChecker-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Arm2D_Box-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/Arm2D_Box-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>PikaStdDevice_ADC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdDevice_ADC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdTask-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaStdTask-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaPiZero_KEY-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/PikaPiZero_KEY-api.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>STM32G0_ADC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api/STM32G0_ADC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_ADC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_ADC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_GPIO-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_GPIO-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_IIC-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_IIC-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_KEY-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_KEY-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_LCD-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_LCD-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_Point-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_Point-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_PWM-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_PWM-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_RGB-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_RGB-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_Task-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_Task-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_Time-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_Time-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine_UART-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine_UART-api.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>machine-api.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\machine-api.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>pikascript-lib</GroupName>
|
||||
<Files>
|
||||
@ -1204,6 +904,31 @@
|
||||
<FileType>4</FileType>
|
||||
<FilePath>..\pikascript\pikascript-lib/PikaPiZero/RGB_ASM.lib</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_ByteArray.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-lib\PikaStdLib\PikaStdData_ByteArray.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_FILEIO.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-lib\PikaStdLib\PikaStdData_FILEIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_Tuple.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-lib\PikaStdLib\PikaStdData_Tuple.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdData_Utils.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-lib\PikaStdLib\PikaStdData_Utils.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PikaStdDevice_BaseDev.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-lib\PikaStdDevice\PikaStdDevice_BaseDev.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@ -1251,6 +976,26 @@
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>pikascript-api</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>__asset_pikaModules_py_a.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\__asset_pikaModules_py_a.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>__pikaBinding.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\__pikaBinding.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>pikaScript.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\pikascript\pikascript-api\pikaScript.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>::CMSIS</GroupName>
|
||||
</Group>
|
||||
|
@ -1,6 +1,6 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
PikaStdDevice==v1.11.0
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.2
|
||||
STM32G0==v1.3.2
|
||||
PikaPiZero==v1.3.0
|
||||
Arm2D==v0.4.1
|
||||
Arm2D==v0.4.1
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
|
@ -1,2 +1,2 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
@ -1,4 +1,4 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
PikaStdDevice==v1.11.0
|
||||
W801Device==v1.1.1
|
||||
|
@ -83,3 +83,4 @@ RUN code-server --install-extension llvm-vs-code-extensions.vscode-clangd
|
||||
RUN code-server --install-extension vscodevim.vim
|
||||
RUN code-server --install-extension zhuangtongfa.material-theme
|
||||
RUN apt-get install clangd -y
|
||||
RUN apt-get install libmbedtls-dev -y
|
||||
|
@ -1,4 +1,4 @@
|
||||
bind-addr: 127.0.0.1:8080
|
||||
bind-addr: 0.0.0.1:8080
|
||||
auth: password
|
||||
password: pikadev
|
||||
cert: false
|
||||
|
10
examples/requests/requests_encode.py
Normal file
10
examples/requests/requests_encode.py
Normal file
@ -0,0 +1,10 @@
|
||||
import requests
|
||||
requests._append_params_to_url('http://www.rt-thread.com', {
|
||||
'a': 1,
|
||||
'b': 2
|
||||
})
|
||||
|
||||
requests._append_params_to_url('http://www.rt-thread.com', {
|
||||
'a': ' ',
|
||||
'b': '%',
|
||||
})
|
@ -1,70 +1,14 @@
|
||||
#include "LCD_Driver.h"
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
#include "LCD_Config.h"
|
||||
#include "pika_bsp.h"
|
||||
#include "main.h"
|
||||
#include "pika_bsp.h"
|
||||
/* config SPI mode, chocie one from three */
|
||||
// #define SPI_SOFT
|
||||
// #define SPI_HARD
|
||||
#define SPI_DMA
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
DMA_HandleTypeDef hdma_spi1_tx;
|
||||
void SPI_Write_u8(u8 Data);
|
||||
|
||||
void DMA1_Channel1_IRQHandler(void) {
|
||||
HAL_DMA_IRQHandler(&hdma_spi1_tx);
|
||||
}
|
||||
|
||||
static void MX_DMA_Init(void) {
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
}
|
||||
|
||||
void MX_SPI1_Init(void) {
|
||||
hspi1.Instance = SPI1;
|
||||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 10;
|
||||
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
||||
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
||||
HAL_SPI_Init(&hspi1);
|
||||
}
|
||||
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
hdma_spi1_tx.Instance = DMA1_Channel1;
|
||||
hdma_spi1_tx.Init.Request = DMA_REQUEST_SPI1_TX;
|
||||
hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_spi1_tx.Init.Mode = DMA_NORMAL;
|
||||
hdma_spi1_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
||||
HAL_DMA_Init(&hdma_spi1_tx);
|
||||
__HAL_LINKDMA(hspi, hdmatx, hdma_spi1_tx);
|
||||
}
|
||||
pika_dev* pika_hal_spi;
|
||||
|
||||
//液晶IO初始化配置
|
||||
void LCD_GPIO_Init(void) {
|
||||
@ -79,8 +23,6 @@ void LCD_GPIO_Init(void) {
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
#ifdef SPI_SOFT
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_2;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
@ -88,21 +30,7 @@ void LCD_GPIO_Init(void) {
|
||||
}
|
||||
|
||||
void SPI_WriteData_u8(u8* pData, uint32_t size) {
|
||||
#ifdef SPI_SOFT
|
||||
for (int i = 0; i < size; i++) {
|
||||
SPI_Write_u8(pData[i]);
|
||||
}
|
||||
#else
|
||||
#ifdef SPI_DMA
|
||||
/* wait spi ready */
|
||||
while (hspi1.hdmatx->State != HAL_DMA_STATE_READY ||
|
||||
hspi1.State != HAL_SPI_STATE_READY) {
|
||||
};
|
||||
HAL_SPI_Transmit_DMA(&hspi1, pData, size);
|
||||
#else
|
||||
HAL_SPI_Transmit(&hspi1, pData, size, HAL_MAX_DELAY);
|
||||
#endif
|
||||
#endif
|
||||
pika_hal_write(pika_hal_spi, pData, size);
|
||||
}
|
||||
|
||||
void SPI_WriteData_u16(u16* pData, uint32_t size) {
|
||||
@ -132,42 +60,33 @@ void SPI_Write_u8(u8 Data) {
|
||||
Data <<= 1;
|
||||
}
|
||||
#else
|
||||
// SPI_WriteData_u8(&Data, 1);
|
||||
HAL_SPI_Transmit(&hspi1, &Data, 1, HAL_MAX_DELAY);
|
||||
SPI_WriteData_u8(&Data, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
//向液晶屏写一个8位指令
|
||||
void LCD_WriteIndex(u8 Index) {
|
||||
// SPI 写命令时序开始
|
||||
LCD_CS_CLR;
|
||||
LCD_RS_CLR;
|
||||
SPI_Write_u8(Index);
|
||||
LCD_CS_SET;
|
||||
}
|
||||
|
||||
//向液晶屏写一个8位数据
|
||||
void LCD_Write_u8(u8 Data) {
|
||||
LCD_CS_CLR;
|
||||
LCD_RS_SET;
|
||||
SPI_Write_u8(Data);
|
||||
LCD_CS_SET;
|
||||
}
|
||||
|
||||
//向液晶屏写一个16位数据
|
||||
void LCD_Write_u16(u16 Data) {
|
||||
LCD_CS_CLR;
|
||||
LCD_RS_SET;
|
||||
SPI_Write_u8(Data >> 8); //写入高8位数据
|
||||
SPI_Write_u8(Data); //写入低8位数据
|
||||
LCD_CS_SET;
|
||||
}
|
||||
|
||||
void LCD_WriteData_u16(u16* pData, uint32_t size) {
|
||||
LCD_CS_CLR;
|
||||
LCD_RS_SET;
|
||||
SPI_WriteData_u16(pData, size); //写入高8位数据
|
||||
LCD_CS_SET;
|
||||
}
|
||||
|
||||
void LCD_WriteReg(u8 Index, u8 Data) {
|
||||
@ -185,12 +104,10 @@ void LCD_Reset(void) {
|
||||
// LCD Init For 1.44Inch LCD Panel with ST7735R.
|
||||
void LCD_Init(void) {
|
||||
LCD_GPIO_Init();
|
||||
#ifndef SPI_SOFT
|
||||
MX_DMA_Init();
|
||||
MX_SPI1_Init();
|
||||
#endif
|
||||
/* enable spi hal */
|
||||
pika_hal_spi = pika_hal_open(PIKA_HAL_SPI, "spi1");
|
||||
pika_hal_ioctl(pika_hal_spi, PIKA_HAL_IOCTL_ENABLE);
|
||||
LCD_Reset(); // Reset before LCD Init.
|
||||
|
||||
// LCD Init For 1.8Inch LCD Panel with ST7735S.
|
||||
LCD_WriteIndex(0x11); // Sleep exit
|
||||
delay_ms(120);
|
||||
@ -293,7 +210,6 @@ void LCD_SetRegion(u16 x_start, u16 y_start, u16 x_end, u16 y_end) {
|
||||
data[1] = (X_OFFSET + x_start) & 0XFF;
|
||||
data[2] = (X_OFFSET + x_end) >> 8;
|
||||
data[3] = (X_OFFSET + x_end) & 0XFF;
|
||||
LCD_CS_CLR;
|
||||
LCD_RS_SET;
|
||||
SPI_WriteData_u8(data, sizeof(data));
|
||||
LCD_WriteIndex(0x2b);
|
||||
@ -301,7 +217,6 @@ void LCD_SetRegion(u16 x_start, u16 y_start, u16 x_end, u16 y_end) {
|
||||
data[1] = (Y_OFFSET + y_start) & 0XFF;
|
||||
data[2] = (Y_OFFSET + y_end) >> 8;
|
||||
data[3] = (Y_OFFSET + y_end) & 0XFF;
|
||||
LCD_CS_CLR;
|
||||
LCD_RS_SET;
|
||||
SPI_WriteData_u8(data, sizeof(data));
|
||||
LCD_WriteIndex(0x2c);
|
||||
@ -331,19 +246,10 @@ void LCD_DrawPoint(u16 x, u16 y, u16 Data) {
|
||||
void LCD_DrawRegin(u16 x_start, u16 y_start, u16 x_end, u16 y_end, u16* pData) {
|
||||
u32 size = (x_end - x_start) * (y_end - y_start) * 2;
|
||||
LCD_SetRegion(x_start, y_start, x_end - 1, y_end - 1);
|
||||
LCD_CS_CLR;
|
||||
LCD_RS_SET;
|
||||
SPI_WriteData_u16(pData, size);
|
||||
#ifdef SPI_DMA
|
||||
/* wait spi ready */
|
||||
while (hspi1.hdmatx->State != HAL_DMA_STATE_READY ||
|
||||
hspi1.State != HAL_SPI_STATE_READY) {
|
||||
};
|
||||
#endif
|
||||
LCD_CS_SET;
|
||||
}
|
||||
|
||||
|
||||
#define BUFF_SIZE (X_MAX_PIXEL)
|
||||
void LCD_Clear(u16 Color) {
|
||||
unsigned int i, m;
|
||||
@ -357,7 +263,7 @@ void LCD_Clear(u16 Color) {
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_Fill(u16 x0,u16 y0,u16 hight,u16 wight,u16 color){
|
||||
void LCD_Fill(u16 x0, u16 y0, u16 hight, u16 wight, u16 color) {
|
||||
unsigned int i, y;
|
||||
u16 data[BUFF_SIZE];
|
||||
for (i = 0; i < BUFF_SIZE; i++) {
|
||||
|
@ -66,7 +66,7 @@
|
||||
//液晶控制口置1操作语句宏定义
|
||||
#define LCD_SCL_SET LCD_CTRLA->BSRR = LCD_SCL
|
||||
#define LCD_SDA_SET LCD_CTRLA->BSRR = LCD_SDA
|
||||
#define LCD_CS_SET LCD_CTRLB->BSRR = LCD_CS
|
||||
#define LCD_CS_SET LCD_CTRLB->BSRR = LCD_CS
|
||||
|
||||
#define LCD_RS_SET LCD_CTRLA->BSRR = LCD_RS
|
||||
#define LCD_RST_SET LCD_CTRLA->BSRR = LCD_RST
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_ADC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_ADC_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "dataStrs.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 10, 4)
|
||||
#error "This library requires PikaScript version 1.10.4 or higher"
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "PikaStdDevice_CAN.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_CAN___init__(PikaObj* self) {}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_GPIO.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
@ -8,6 +9,7 @@ void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isOn", 0);
|
||||
obj_setStr(self, "pull", "none");
|
||||
obj_setInt(self, "id", -999);
|
||||
obj_setPtr(self, "pika_dev", NULL);
|
||||
}
|
||||
|
||||
int PikaStdDevice_GPIO_getId(PikaObj* self) {
|
||||
@ -75,38 +77,70 @@ void PikaStdDevice_GPIO_setPull(PikaObj* self, char* pull) {
|
||||
}
|
||||
}
|
||||
|
||||
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_GPIO, obj_getStr(self, "pin"));
|
||||
if(NULL == dev){
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n", obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) {
|
||||
obj_setStr(self, "pin", pinName);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformLow(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 0;
|
||||
pika_hal_write(dev, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 1;
|
||||
pika_hal_write(dev, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformOff(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
char* mode = obj_getStr(self, "mode");
|
||||
pika_hal_GPIO_config cfg = {0};
|
||||
if(strEqu(mode, "in")){
|
||||
cfg.dir = PIKA_HAL_GPIO_DIR_IN;
|
||||
}else{
|
||||
cfg.dir = PIKA_HAL_GPIO_DIR_OUT;
|
||||
}
|
||||
pika_dev* dev = _get_dev(self);
|
||||
char* pull = obj_getStr(self, "pull");
|
||||
if (strEqu(pull, "up")){
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_UP;
|
||||
}
|
||||
if (strEqu(pull, "down")){
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_DOWN;
|
||||
}
|
||||
if (strEqu(pull, "none")) {
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_NONE;
|
||||
}
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformRead(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 0;
|
||||
pika_hal_read(dev, &val, sizeof(val));
|
||||
obj_setInt(self, "readBuff", val);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "PikaStdDevice_IIC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_IIC_init(PikaObj* self) {
|
||||
obj_setInt(self, "deviceAddr", 0);
|
||||
obj_setStr(self, "SCLpin", "PA0");
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_PWM.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_PWM_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "none");
|
||||
@ -19,20 +20,20 @@ void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) {
|
||||
|
||||
void PikaStdDevice_PWM_setFrequency(PikaObj* self, int freq) {
|
||||
obj_setInt(self, "freq", freq);
|
||||
obj_runNativeMethod(self, "platformSetFrequency",NULL);
|
||||
obj_runNativeMethod(self, "platformSetFrequency", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setDuty(PikaObj* self, pika_float duty) {
|
||||
obj_setFloat(self, "duty", duty);
|
||||
obj_runNativeMethod(self, "platformSetDuty",NULL);
|
||||
obj_runNativeMethod(self, "platformSetDuty", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable",NULL);
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_disable(PikaObj *self){
|
||||
obj_runNativeMethod(self, "platformDisable",NULL);
|
||||
void PikaStdDevice_PWM_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
pika_float PikaStdDevice_PWM_getDuty(PikaObj* self) {
|
||||
@ -53,7 +54,7 @@ void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj *self){
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "PikaStdDevice_SPI.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_SPI___init__(PikaObj* self) {
|
||||
obj_setInt(self, "baudRate", 1000);
|
||||
obj_setInt(self, "id", 0);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_Time.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#if defined(__linux)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@ -17,7 +18,7 @@ void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
|
||||
#endif
|
||||
}
|
||||
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
|
||||
#if defined(__linux)
|
||||
#if defined(__linux)
|
||||
sleep(s);
|
||||
#elif defined(_WIN32)
|
||||
Sleep(s * 1000);
|
||||
@ -42,7 +43,7 @@ void PikaStdDevice_Time_platformGetTick(PikaObj* self) {
|
||||
|
||||
//结构体时间类型定义(来源c标准库corect_wtime.h)
|
||||
//无论是16位整数还是32位整数都满足需求
|
||||
typedef struct _tm{
|
||||
typedef struct _tm {
|
||||
int tm_sec; // seconds after the minute - [0, 60] including leap second
|
||||
int tm_min; // minutes after the hour - [0, 59]
|
||||
int tm_hour; // hours since midnight - [0, 23]
|
||||
@ -137,7 +138,8 @@ pika_float time_time(PikaObj* self) {
|
||||
status_deal(res);
|
||||
} //异常处理
|
||||
//以浮点数返回时间,float
|
||||
return temp_timespec.tv_sec + (pika_float)temp_timespec.tv_nsec / 1000000000;
|
||||
return temp_timespec.tv_sec +
|
||||
(pika_float)temp_timespec.tv_nsec / 1000000000;
|
||||
}
|
||||
|
||||
//标准time_ns()方法,返回以整数表示的从 epoch 开始的纳秒数的时间值。
|
||||
@ -568,9 +570,9 @@ pika_float PikaStdDevice_Time_time(PikaObj* self) {
|
||||
)
|
||||
/* clang-format on */
|
||||
const uint8_t bytes[] = {
|
||||
0x04, 0x00, /* instruct array size */
|
||||
0x04, 0x00, 0x00, 0x00, /* instruct array size */
|
||||
0x00, 0x82, 0x01, 0x00, /* instruct array */
|
||||
0x11, 0x00, /* const pool size */
|
||||
0x11, 0x00, 0x00, 0x00, /* const pool size */
|
||||
0x00, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d,
|
||||
0x47, 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x00, /* const pool */
|
||||
};
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include "PikaStdDevice_UART.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_UART_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_disable(PikaObj *self){
|
||||
void PikaStdDevice_UART_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
@ -25,7 +26,7 @@ char* PikaStdDevice_UART_read(PikaObj* self, int length) {
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
|
||||
Arg* PikaStdDevice_UART_readBytes(PikaObj *self, int length){
|
||||
Arg* PikaStdDevice_UART_readBytes(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_runNativeMethod(self, "platformReadBytes", NULL);
|
||||
return arg_copy(obj_getArg(self, "readData"));
|
||||
@ -42,7 +43,7 @@ void PikaStdDevice_UART_write(PikaObj* self, char* data) {
|
||||
obj_runNativeMethod(self, "platformWrite", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_writeBytes(PikaObj *self, uint8_t* data, int length){
|
||||
void PikaStdDevice_UART_writeBytes(PikaObj* self, uint8_t* data, int length) {
|
||||
obj_setBytes(self, "writeData", data, length);
|
||||
obj_runNativeMethod(self, "platformWriteBytes", NULL);
|
||||
}
|
||||
@ -57,14 +58,14 @@ void PikaStdDevice_UART_platformWrite(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformDisable(PikaObj *self){
|
||||
void PikaStdDevice_UART_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformReadBytes(PikaObj *self){
|
||||
void PikaStdDevice_UART_platformReadBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformWriteBytes(PikaObj *self){
|
||||
void PikaStdDevice_UART_platformWriteBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
215
package/PikaStdDevice/pika_hal.c
Normal file
215
package/PikaStdDevice/pika_hal.c
Normal file
@ -0,0 +1,215 @@
|
||||
#include "pika_hal.h"
|
||||
#include "PikaObj.h"
|
||||
|
||||
#define PIKA_HAL_TABLE_FILE_API
|
||||
#include "pika_hal_table.h"
|
||||
|
||||
static const pika_dev_impl pika_dev_impl_list[] = {
|
||||
#define PIKA_HAL_TABLE_IMPL
|
||||
#include "pika_hal_table.h"
|
||||
};
|
||||
|
||||
#define _PIKA_DEV_TYPE_MAX \
|
||||
(sizeof pika_dev_impl_list / sizeof pika_dev_impl_list[0])
|
||||
|
||||
static pika_dev_impl* _pika_dev_get_impl(PIKA_HAL_DEV_TYPE type) {
|
||||
if (type >= _PIKA_DEV_TYPE_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
return (pika_dev_impl*)&pika_dev_impl_list[type];
|
||||
}
|
||||
|
||||
static size_t _pika_hal_dev_config_size(PIKA_HAL_DEV_TYPE dev_type) {
|
||||
#define PIKA_HAL_TABLE_DEV_CONFIG_SIZE
|
||||
#include "pika_hal_table.h"
|
||||
return 0;
|
||||
}
|
||||
|
||||
pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name) {
|
||||
int ret = -1;
|
||||
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));
|
||||
if (dev == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
dev->type = dev_type;
|
||||
dev->ioctl_config = pikaMalloc(_pika_hal_dev_config_size(dev_type));
|
||||
if (dev->ioctl_config == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
ret = impl->open(dev, name);
|
||||
__exit:
|
||||
if (0 == ret) {
|
||||
return dev;
|
||||
}
|
||||
/* error */
|
||||
__platform_printf("Error: dev_open failed.\r\n");
|
||||
if (dev->ioctl_config) {
|
||||
pikaFree(dev->ioctl_config, _pika_hal_dev_config_size(dev_type));
|
||||
}
|
||||
if (dev) {
|
||||
pikaFree(dev, sizeof(pika_dev));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int pika_hal_close(pika_dev* dev) {
|
||||
int ret = -1;
|
||||
if (dev == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev->type);
|
||||
if (impl->close == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
ret = impl->close(dev);
|
||||
__exit:
|
||||
if (NULL != dev) {
|
||||
pikaFree(dev, sizeof(pika_dev));
|
||||
}
|
||||
if (NULL != dev->ioctl_config) {
|
||||
pikaFree(dev->ioctl_config, _pika_hal_dev_config_size(dev->type));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pika_hal_read(pika_dev* dev, void* buf, size_t len) {
|
||||
if (dev == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev->type);
|
||||
if (impl->read == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return impl->read(dev, buf, len);
|
||||
}
|
||||
|
||||
int pika_hal_write(pika_dev* dev, void* buf, size_t len) {
|
||||
if (dev == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev->type);
|
||||
if (impl->write == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return impl->write(dev, buf, len);
|
||||
}
|
||||
|
||||
static const int _pika_hal_cmd_arg_cnt[] = {
|
||||
[PIKA_HAL_IOCTL_CONFIG] = 1,
|
||||
[PIKA_HAL_IOCTL_ENABLE] = 0,
|
||||
[PIKA_HAL_IOCTL_DISABLE] = 0,
|
||||
};
|
||||
|
||||
#define _PIKA_HAL_CMD_ARG_CNT_MAX \
|
||||
(sizeof _pika_hal_cmd_arg_cnt / sizeof _pika_hal_cmd_arg_cnt[0])
|
||||
|
||||
static int _pika_hal_get_arg_cnt(PIKA_HAL_IOCTL_CMD cmd) {
|
||||
if (cmd >= _PIKA_HAL_CMD_ARG_CNT_MAX) {
|
||||
return -1;
|
||||
}
|
||||
return _pika_hal_cmd_arg_cnt[cmd];
|
||||
}
|
||||
|
||||
int _pika_hal_ioctl_merge_config(pika_dev* dev, void* config_in) {
|
||||
#define PIKA_HAL_TABLE_IOCTL_MERGE_CONFIG
|
||||
#include "pika_hal_table.h"
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) {
|
||||
int ret = -1;
|
||||
if (dev == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int arg_cnt = _pika_hal_get_arg_cnt(cmd);
|
||||
if (arg_cnt < 0) {
|
||||
return -1;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev->type);
|
||||
if (impl->ioctl == NULL) {
|
||||
return -1;
|
||||
}
|
||||
void* config_in = NULL;
|
||||
if (arg_cnt != 0) {
|
||||
va_list args;
|
||||
va_start(args, arg_cnt);
|
||||
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, dev->ioctl_config);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define _IOCTL_CONFIG_USE_DEFAULT(item, default) \
|
||||
if (src->item == 0) { \
|
||||
if (dst->item == 0) { \
|
||||
/* use default value */ \
|
||||
dst->item = default; \
|
||||
} else { \
|
||||
/* keep exist value */ \
|
||||
} \
|
||||
} else { \
|
||||
/* use input value */ \
|
||||
src->item = dst->item; \
|
||||
}
|
||||
|
||||
int pika_hal_GPIO_ioctl_merge_config(pika_hal_GPIO_config* dst,
|
||||
pika_hal_GPIO_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(dir, PIKA_HAL_GPIO_DIR_IN);
|
||||
_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);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_falling, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_UART_ioctl_merge_config(pika_hal_UART_config* dst,
|
||||
pika_hal_UART_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(baudrate, PIKA_HAL_UART_BAUDRATE_115200);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(data_bits, PIKA_HAL_UART_DATA_BITS_8);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(stop_bits, PIKA_HAL_UART_STOP_BITS_1);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(parity, PIKA_HAL_UART_PARITY_NONE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_rx, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_SPI_ioctl_merge_config(pika_hal_SPI_config* dst,
|
||||
pika_hal_SPI_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(lsb_or_msb, PIKA_HAL_SPI_MSB);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(master_or_slave, PIKA_HAL_SPI_MASTER);
|
||||
_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);
|
||||
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(speed, PIKA_HAL_IIC_SPEED_100K);
|
||||
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);
|
||||
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);
|
||||
return 0;
|
||||
}
|
242
package/PikaStdDevice/pika_hal.h
Normal file
242
package/PikaStdDevice/pika_hal.h
Normal file
@ -0,0 +1,242 @@
|
||||
#ifndef _PIKA_DEV_HAL_H
|
||||
#define _PIKA_DEV_HAL_H
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* pika_hal is a C Device HAL lib for PikaScript modules.
|
||||
* the API of pika_hal is similar to the posix file API.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
#define PIKA_HAL_TABLE_DEV_TYPE
|
||||
#include "pika_hal_table.h"
|
||||
} PIKA_HAL_DEV_TYPE;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_DEV_TYPE type;
|
||||
void* ioctl_config;
|
||||
void* platform_data;
|
||||
} pika_dev;
|
||||
|
||||
typedef enum {
|
||||
PIKA_HAL_IOCTL_CONFIG,
|
||||
PIKA_HAL_IOCTL_ENABLE,
|
||||
PIKA_HAL_IOCTL_DISABLE,
|
||||
} PIKA_HAL_IOCTL_CMD;
|
||||
|
||||
/* posix file like API */
|
||||
pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name);
|
||||
int pika_hal_close(pika_dev* dev);
|
||||
int pika_hal_read(pika_dev* dev, void* buf, size_t len);
|
||||
int pika_hal_write(pika_dev* dev, void* buf, size_t len);
|
||||
int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...);
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_GPIO_DIR_UNUSED = 0,
|
||||
PIKA_HAL_GPIO_DIR_IN,
|
||||
PIKA_HAL_GPIO_DIR_OUT,
|
||||
} PIKA_HAL_GPIO_DIR;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_GPIO_PULL_UNUSED = 0,
|
||||
PIKA_HAL_GPIO_PULL_NONE,
|
||||
PIKA_HAL_GPIO_PULL_UP,
|
||||
PIKA_HAL_GPIO_PULL_DOWN,
|
||||
} PIKA_HAL_GPIO_PULL;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_GPIO_SPEED_UNUSED = 0,
|
||||
PIKA_HAL_GPIO_SPEED_1M = 1000000,
|
||||
PIKA_HAL_GPIO_SPEED_2M = 2000000,
|
||||
PIKA_HAL_GPIO_SPEED_5M = 5000000,
|
||||
PIKA_HAL_GPIO_SPEED_10M = 10000000,
|
||||
PIKA_HAL_GPIO_SPEED_20M = 20000000,
|
||||
PIKA_HAL_GPIO_SPEED_50M = 50000000,
|
||||
PIKA_HAL_GPIO_SPEED_100M = 100000000,
|
||||
} PIKA_HAL_GPIO_SPEED;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_GPIO_DIR dir;
|
||||
PIKA_HAL_GPIO_PULL pull;
|
||||
PIKA_HAL_GPIO_SPEED speed;
|
||||
void (*event_callback_rising)(pika_dev* dev);
|
||||
void (*event_callback_falling)(pika_dev* dev);
|
||||
} pika_hal_GPIO_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_UART_BAUDRATE_UNUSED = 0,
|
||||
PIKA_HAL_UART_BAUDRATE_9600 = 9600,
|
||||
PIKA_HAL_UART_BAUDRATE_19200 = 19200,
|
||||
PIKA_HAL_UART_BAUDRATE_38400 = 38400,
|
||||
PIKA_HAL_UART_BAUDRATE_57600 = 57600,
|
||||
PIKA_HAL_UART_BAUDRATE_115200 = 115200,
|
||||
PIKA_HAL_UART_BAUDRATE_2000000 = 2000000,
|
||||
PIKA_HAL_UART_BAUDRATE_10000000 = 10000000,
|
||||
} PIKA_HAL_UART_BAUDRATE;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_UART_DATA_BITS_UNUSED = 0,
|
||||
PIKA_HAL_UART_DATA_BITS_5 = 5,
|
||||
PIKA_HAL_UART_DATA_BITS_6 = 6,
|
||||
PIKA_HAL_UART_DATA_BITS_7 = 7,
|
||||
PIKA_HAL_UART_DATA_BITS_8 = 8,
|
||||
} PIKA_HAL_UART_DATA_BITS;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_UART_STOP_BITS_UNUSED = 0,
|
||||
PIKA_HAL_UART_STOP_BITS_1 = 1,
|
||||
PIKA_HAL_UART_STOP_BITS_2 = 2,
|
||||
} PIKA_HAL_UART_STOP_BITS;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_UART_PARITY_UNUSED = 0,
|
||||
PIKA_HAL_UART_PARITY_NONE,
|
||||
PIKA_HAL_UART_PARITY_ODD,
|
||||
PIKA_HAL_UART_PARITY_EVEN,
|
||||
} PIKA_HAL_UART_PARITY;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_UART_BAUDRATE baudrate;
|
||||
PIKA_HAL_UART_DATA_BITS data_bits;
|
||||
PIKA_HAL_UART_STOP_BITS stop_bits;
|
||||
PIKA_HAL_UART_PARITY parity;
|
||||
void (*event_callback_rx)(pika_dev* dev);
|
||||
} pika_hal_UART_config;
|
||||
|
||||
typedef uint32_t PIKA_HAL_IIC_SLAVE_ADDR;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_IIC_SPEED_UNUSED = 0,
|
||||
PIKA_HAL_IIC_SPEED_100K = 100000,
|
||||
PIKA_HAL_IIC_SPEED_400K = 400000,
|
||||
PIKA_HAL_IIC_SPEED_1M = 1000000,
|
||||
} PIKA_HAL_IIC_SPEED;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_IIC_SLAVE_ADDR addr;
|
||||
PIKA_HAL_IIC_SPEED speed;
|
||||
} pika_hal_IIC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_LSB_OR_MSB_UNUSED = 0,
|
||||
PIKA_HAL_SPI_LSB,
|
||||
PIKA_HAL_SPI_MSB,
|
||||
} PIKA_HAL_SPI_LSB_OR_MSB;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_MASTER_OR_SLAVE_UNUSED = 0,
|
||||
PIKA_HAL_SPI_MASTER,
|
||||
PIKA_HAL_SPI_SLAVE,
|
||||
} PIKA_HAL_SPI_MASTER_OR_SLAVE;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_MODE_UNUSED = 0,
|
||||
PIKA_HAL_SPI_MODE_0,
|
||||
PIKA_HAL_SPI_MODE_1,
|
||||
PIKA_HAL_SPI_MODE_2,
|
||||
PIKA_HAL_SPI_MODE_3,
|
||||
} PIKA_HAL_SPI_MODE;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_DATA_UNUSED = 0,
|
||||
PIKA_HAL_SPI_DATA_WIDTH_8 = 8,
|
||||
PIKA_HAL_SPI_DATA_WIDTH_16 = 16,
|
||||
} PIKA_HAL_SPI_DATA_WIDTH;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_SPEED_UNUSED = 0,
|
||||
PIKA_HAL_SPI_SPEED_1M = 1000000,
|
||||
PIKA_HAL_SPI_SPEED_2M = 2000000,
|
||||
PIKA_HAL_SPI_SPEED_5M = 5000000,
|
||||
PIKA_HAL_SPI_SPEED_10M = 10000000,
|
||||
PIKA_HAL_SPI_SPEED_20M = 20000000,
|
||||
PIKA_HAL_SPI_SPEED_50M = 50000000,
|
||||
PIKA_HAL_SPI_SPEED_100M = 100000000,
|
||||
} PIKA_HAL_SPI_SPEED;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_SPI_LSB_OR_MSB lsb_or_msb;
|
||||
PIKA_HAL_SPI_MASTER_OR_SLAVE master_or_slave;
|
||||
PIKA_HAL_SPI_MODE mode;
|
||||
PIKA_HAL_SPI_DATA_WIDTH data_width;
|
||||
PIKA_HAL_SPI_SPEED speed;
|
||||
} 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,
|
||||
PIKA_HAL_ADC_RESOLUTION_10 = 10,
|
||||
PIKA_HAL_ADC_RESOLUTION_12 = 12,
|
||||
PIKA_HAL_ADC_RESOLUTION_14 = 14,
|
||||
PIKA_HAL_ADC_RESOLUTION_16 = 16,
|
||||
} PIKA_HAL_ADC_RESOLUTION;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_ADC_CHANNEL channel;
|
||||
PIKA_HAL_ADC_RESOLUTION resolution;
|
||||
} pika_hal_ADC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_DAC_UNUSED = 0,
|
||||
PIKA_HAL_PWM_CHANNEL_0,
|
||||
PIKA_HAL_PWM_CHANNEL_1,
|
||||
PIKA_HAL_PWM_CHANNEL_2,
|
||||
PIKA_HAL_PWM_CHANNEL_3,
|
||||
PIKA_HAL_PWM_CHANNEL_4,
|
||||
PIKA_HAL_PWM_CHANNEL_5,
|
||||
PIKA_HAL_PWM_CHANNEL_6,
|
||||
PIKA_HAL_PWM_CHANNEL_7,
|
||||
} PIKA_HAL_PWM_CHANNEL;
|
||||
|
||||
typedef enum {
|
||||
PIKA_HAL_PWM_PERIOD_1NS = 1,
|
||||
PIKA_HAL_PWM_PERIOD_1US = 1000,
|
||||
PIKA_HAL_PWM_PERIOD_1MS = 1000000,
|
||||
PIKA_HAL_PWM_PERIOD_1S = 1000000000,
|
||||
} PIKA_HAL_PWM_PERIOD;
|
||||
|
||||
typedef enum {
|
||||
PIKA_HAL_PWM_DUTY_1NS = 1,
|
||||
PIKA_HAL_PWM_DUTY_1US = 1000,
|
||||
PIKA_HAL_PWM_DUTY_1MS = 1000000,
|
||||
PIKA_HAL_PWM_DUTY_1S = 1000000000,
|
||||
} 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;
|
||||
|
||||
typedef struct pika_dev_impl {
|
||||
int (*open)(pika_dev* dev, char* name);
|
||||
int (*close)(pika_dev* dev);
|
||||
int (*read)(pika_dev* dev, void* buf, size_t count);
|
||||
int (*write)(pika_dev* dev, void* buf, size_t count);
|
||||
int (*ioctl)(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, void* cfg);
|
||||
} pika_dev_impl;
|
||||
|
||||
/* platform API */
|
||||
#define PIKA_HAL_TABLE_PLATFORM_API
|
||||
#include "pika_hal_table.h"
|
||||
|
||||
/* config merge headers */
|
||||
#define PIKA_HAL_TABLE_IOCTL_MERGE_CONFIG_HEADER
|
||||
#include "pika_hal_table.h"
|
||||
|
||||
#endif
|
12
package/PikaStdDevice/pika_hal_table.h
Normal file
12
package/PikaStdDevice/pika_hal_table.h
Normal file
@ -0,0 +1,12 @@
|
||||
#include "pika_hal_table_rule.h"
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
pika_hal_table_add(GPIO)
|
||||
pika_hal_table_add(UART)
|
||||
pika_hal_table_add(IIC)
|
||||
pika_hal_table_add(SPI)
|
||||
pika_hal_table_add(ADC)
|
||||
pika_hal_table_add(PWM)
|
||||
|
||||
/* clang-format on */
|
113
package/PikaStdDevice/pika_hal_table_rule.h
Normal file
113
package/PikaStdDevice/pika_hal_table_rule.h
Normal file
@ -0,0 +1,113 @@
|
||||
#undef pika_hal_table_add
|
||||
#if defined(PIKA_HAL_TABLE_FILE_API)
|
||||
#define pika_hal_table_add(dev_name) \
|
||||
PIKA_WEAK int pika_hal_platform_##dev_name##_open(pika_dev* dev, \
|
||||
char* name) { \
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \
|
||||
return -1; \
|
||||
} \
|
||||
PIKA_WEAK int pika_hal_platform_##dev_name##_close(pika_dev* dev) { \
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \
|
||||
return -1; \
|
||||
} \
|
||||
PIKA_WEAK int pika_hal_platform_##dev_name##_read(pika_dev* dev, \
|
||||
void* buf, size_t len) { \
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \
|
||||
return -1; \
|
||||
} \
|
||||
PIKA_WEAK int pika_hal_platform_##dev_name##_write( \
|
||||
pika_dev* dev, void* buf, size_t len) { \
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \
|
||||
return -1; \
|
||||
} \
|
||||
PIKA_WEAK int pika_hal_platform_##dev_name##_ioctl_enable(pika_dev* dev) { \
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \
|
||||
return -1; \
|
||||
} \
|
||||
PIKA_WEAK int pika_hal_platform_##dev_name##_ioctl_disable( \
|
||||
pika_dev* dev) { \
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \
|
||||
return -1; \
|
||||
} \
|
||||
PIKA_WEAK int pika_hal_platform_##dev_name##_ioctl_config( \
|
||||
pika_dev* dev, pika_hal_##dev_name##_config* cfg) { \
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR() \
|
||||
return -1; \
|
||||
} \
|
||||
int pika_hal_##dev_name##_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, \
|
||||
void* arg) { \
|
||||
if (NULL == dev) { \
|
||||
return -1; \
|
||||
} \
|
||||
switch (cmd) { \
|
||||
case PIKA_HAL_IOCTL_ENABLE: \
|
||||
return pika_hal_platform_##dev_name##_ioctl_enable(dev); \
|
||||
case PIKA_HAL_IOCTL_DISABLE: \
|
||||
return pika_hal_platform_##dev_name##_ioctl_disable(dev); \
|
||||
case PIKA_HAL_IOCTL_CONFIG: \
|
||||
return pika_hal_platform_##dev_name##_ioctl_config( \
|
||||
dev, (pika_hal_##dev_name##_config*)arg); \
|
||||
default: \
|
||||
return -1; \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(PIKA_HAL_TABLE_DEV_TYPE)
|
||||
#define pika_hal_table_add(dev_name) PIKA_HAL_##dev_name,
|
||||
#endif
|
||||
|
||||
#if defined(PIKA_HAL_TABLE_IMPL)
|
||||
#define pika_hal_table_add(dev_name) \
|
||||
[PIKA_HAL_##dev_name] = { \
|
||||
.open = pika_hal_platform_##dev_name##_open, \
|
||||
.close = pika_hal_platform_##dev_name##_close, \
|
||||
.read = pika_hal_platform_##dev_name##_read, \
|
||||
.write = pika_hal_platform_##dev_name##_write, \
|
||||
.ioctl = pika_hal_##dev_name##_ioctl, \
|
||||
},
|
||||
#endif
|
||||
|
||||
#if defined(PIKA_HAL_TABLE_PLATFORM_API)
|
||||
#define pika_hal_table_add(dev_name) \
|
||||
int pika_hal_platform_##dev_name##_open(pika_dev* dev, char* name); \
|
||||
int pika_hal_platform_##dev_name##_close(pika_dev* dev); \
|
||||
int pika_hal_platform_##dev_name##_read(pika_dev* dev, void* buf, \
|
||||
size_t len); \
|
||||
int pika_hal_platform_##dev_name##_write(pika_dev* dev, void* buf, \
|
||||
size_t len); \
|
||||
int pika_hal_platform_##dev_name##_ioctl_enable(pika_dev* dev); \
|
||||
int pika_hal_platform_##dev_name##_ioctl_disable(pika_dev* dev); \
|
||||
int pika_hal_platform_##dev_name##_ioctl_config( \
|
||||
pika_dev* dev, pika_hal_##dev_name##_config* cfg);
|
||||
#endif
|
||||
|
||||
#if defined(PIKA_HAL_TABLE_DEV_CONFIG_SIZE)
|
||||
#define pika_hal_table_add(dev_name) \
|
||||
if (dev_type == PIKA_HAL_##dev_name) { \
|
||||
return sizeof(pika_hal_##dev_name##_config); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PIKA_HAL_TABLE_IOCTL_MERGE_CONFIG)
|
||||
#define pika_hal_table_add(dev_name) \
|
||||
if (dev->type == PIKA_HAL_##dev_name) { \
|
||||
return pika_hal_##dev_name##_ioctl_merge_config(dev->ioctl_config, \
|
||||
config_in); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PIKA_HAL_TABLE_IOCTL_MERGE_CONFIG_HEADER)
|
||||
#define pika_hal_table_add(dev_name) \
|
||||
int pika_hal_##dev_name##_ioctl_merge_config( \
|
||||
pika_hal_##dev_name##_config* dst, pika_hal_##dev_name##_config* src);
|
||||
#endif
|
||||
|
||||
#undef PIKA_HAL_TABLE_FILE_API
|
||||
#undef PIKA_HAL_TABLE_DEV_TYPE
|
||||
#undef PIKA_HAL_TABLE_IMPL
|
||||
#undef PIKA_HAL_TABLE_PLATFORM_API
|
||||
#undef PIKA_HAL_TABLE_DEV_CONFIG_SIZE
|
||||
#undef PIKA_HAL_TABLE_IOCTL_MERGE_CONFIG
|
||||
#undef PIKA_HAL_TABLE_IOCTL_MERGE_CONFIG_HEADER
|
@ -9,7 +9,7 @@
|
||||
|
||||
Arg* PikaStdData_Dict_get(PikaObj* self, char* key) {
|
||||
PikaDict* dict = obj_getPtr(self, "dict");
|
||||
Arg* res = dict_getArg(dict, key);
|
||||
Arg* res = pikaDict_getArg(dict, key);
|
||||
if (NULL == res) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_RUNTIME_ERROR);
|
||||
__platform_printf("KeyError: %s\n", key);
|
||||
@ -28,8 +28,8 @@ void PikaStdData_Dict_set(PikaObj* self, char* key, Arg* arg) {
|
||||
void PikaStdData_Dict_remove(PikaObj* self, char* key) {
|
||||
PikaDict* dict = obj_getPtr(self, "dict");
|
||||
PikaDict* keys = obj_getPtr(self, "_keys");
|
||||
dict_removeArg(dict, dict_getArg(dict, key));
|
||||
dict_removeArg(keys, dict_getArg(keys, key));
|
||||
pikaDict_removeArg(dict, pikaDict_getArg(dict, key));
|
||||
pikaDict_removeArg(keys, pikaDict_getArg(keys, key));
|
||||
}
|
||||
|
||||
Arg* PikaStdData_Dict___iter__(PikaObj* self) {
|
||||
@ -60,9 +60,9 @@ Arg* PikaStdData_Dict___getitem__(PikaObj* self, Arg* __key) {
|
||||
void PikaStdData_Dict___del__(PikaObj* self) {
|
||||
PikaDict* dict = obj_getPtr(self, "dict");
|
||||
PikaDict* keys = obj_getPtr(self, "_keys");
|
||||
dict_deinit(dict);
|
||||
pikaDict_deinit(dict);
|
||||
if (NULL != keys) {
|
||||
dict_deinit(keys);
|
||||
pikaDict_deinit(keys);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,8 +227,8 @@ Arg* PikaStdData_dict_items___next__(PikaObj* self) {
|
||||
PikaObj* tuple = newNormalObj(New_PikaStdData_Tuple);
|
||||
PikaStdData_Tuple___init__(tuple);
|
||||
PikaList* list = obj_getPtr(tuple, "list");
|
||||
list_append(list, key);
|
||||
list_append(list, val);
|
||||
pikaList_append(list, key);
|
||||
pikaList_append(list, val);
|
||||
args_setInt(self->list, "__iter_i", __iter_i + 1);
|
||||
return arg_newObj(tuple);
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ int PikaStdData_FILEIO_seek(PikaObj* self, int offset, PikaTuple* fromwhere) {
|
||||
__platform_printf("Error: can't seek in file\n");
|
||||
return -1;
|
||||
}
|
||||
if (tuple_getSize(fromwhere) == 1) {
|
||||
int whence = tuple_getInt(fromwhere, 0);
|
||||
if (pikaTuple_getSize(fromwhere) == 1) {
|
||||
int whence = pikaTuple_getInt(fromwhere, 0);
|
||||
__platform_fseek(f, offset, whence);
|
||||
return __platform_ftell(f);
|
||||
}
|
||||
@ -167,8 +167,8 @@ void PikaStdData_FILEIO_writelines(PikaObj* self, PikaObj* lines) {
|
||||
__platform_printf("Error: can't write lines to file\n");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < list_getSize(list); i++) {
|
||||
char* line = list_getStr(list, i);
|
||||
for (size_t i = 0; i < pikaList_getSize(list); i++) {
|
||||
char* line = pikaList_getStr(list, i);
|
||||
Arg* arg_str = arg_newStr(line);
|
||||
PikaStdData_FILEIO_write(self, arg_str);
|
||||
arg_deinit(arg_str);
|
||||
|
@ -10,7 +10,7 @@ void PikaStdData_List_append(PikaObj* self, Arg* arg) {
|
||||
|
||||
void PikaStdData_List_set(PikaObj* self, int i, Arg* arg) {
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
if (PIKA_RES_OK != list_setArg(list, i, arg)) {
|
||||
if (PIKA_RES_OK != pikaList_setArg(list, i, arg)) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "Error: index exceeded lengh of list.");
|
||||
}
|
||||
@ -32,7 +32,7 @@ char* PikaStdData_List___str__(PikaObj* self) {
|
||||
|
||||
int i = 0;
|
||||
while (PIKA_TRUE) {
|
||||
Arg* item = list_getArg(list, i);
|
||||
Arg* item = pikaList_getArg(list, i);
|
||||
if (NULL == item) {
|
||||
break;
|
||||
}
|
||||
@ -58,7 +58,7 @@ char* PikaStdData_List___str__(PikaObj* self) {
|
||||
|
||||
void PikaStdData_List_reverse(PikaObj* self) {
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
list_reverse(list);
|
||||
pikaList_reverse(list);
|
||||
}
|
||||
|
||||
PikaObj* PikaStdData_List___add__(PikaObj* self, PikaObj* others) {
|
||||
@ -67,20 +67,20 @@ PikaObj* PikaStdData_List___add__(PikaObj* self, PikaObj* others) {
|
||||
PikaList* list_res = obj_getPtr(res, "list");
|
||||
PikaList* list1 = obj_getPtr(self, "list");
|
||||
PikaList* list2 = obj_getPtr(others, "list");
|
||||
for (size_t i = 0; i < list_getSize(list1); i++) {
|
||||
Arg* arg = list_getArg(list1, i);
|
||||
list_append(list_res, arg);
|
||||
for (size_t i = 0; i < pikaList_getSize(list1); i++) {
|
||||
Arg* arg = pikaList_getArg(list1, i);
|
||||
pikaList_append(list_res, arg);
|
||||
}
|
||||
for (size_t i = 0; i < list_getSize(list2); i++) {
|
||||
Arg* arg = list_getArg(list2, i);
|
||||
list_append(list_res, arg);
|
||||
for (size_t i = 0; i < pikaList_getSize(list2); i++) {
|
||||
Arg* arg = pikaList_getArg(list2, i);
|
||||
pikaList_append(list_res, arg);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void PikaStdData_List_insert(PikaObj *self, int i, Arg* arg){
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
if (PIKA_RES_OK != list_insert(list, i, arg)) {
|
||||
if (PIKA_RES_OK != pikaList_insert(list, i, arg)) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "Error: index exceeded lengh of list.");
|
||||
}
|
||||
@ -88,11 +88,11 @@ void PikaStdData_List_insert(PikaObj *self, int i, Arg* arg){
|
||||
|
||||
Arg* PikaStdData_List_pop(PikaObj *self){
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
return list_pop(list);
|
||||
return pikaList_pop(list);
|
||||
}
|
||||
|
||||
void PikaStdData_List_remove(PikaObj *self, Arg* val){
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
list_remove(list, val);
|
||||
pikaList_remove(list, val);
|
||||
}
|
||||
|
||||
|
@ -86,8 +86,12 @@ char* string_slice(Args* outBuffs, char* str, int start, int end) {
|
||||
if (start < 0) {
|
||||
start += string_len(str);
|
||||
}
|
||||
/* magic code, to the end */
|
||||
if (end == -99999) {
|
||||
end = string_len(str);
|
||||
}
|
||||
if (end < 0) {
|
||||
end += string_len(str) + 1;
|
||||
end += string_len(str);
|
||||
}
|
||||
for (int i = start; i < end; i++) {
|
||||
char char_buff[5] = {0};
|
||||
@ -286,12 +290,12 @@ int PikaStdData_String___len__(PikaObj* self) {
|
||||
char* PikaStdData_String_strip(PikaObj* self, PikaTuple* chrs) {
|
||||
Args buffs = {0};
|
||||
char to_strip = ' ';
|
||||
if (tuple_getSize(chrs) > 1) {
|
||||
if (pikaTuple_getSize(chrs) > 1) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_INVALID_PARAM);
|
||||
obj_setSysOut(self, "Error. Invalid param");
|
||||
}
|
||||
if (tuple_getSize(chrs) == 1) {
|
||||
char* ch_str = tuple_getStr(chrs, 0);
|
||||
if (pikaTuple_getSize(chrs) == 1) {
|
||||
char* ch_str = pikaTuple_getStr(chrs, 0);
|
||||
to_strip = ch_str[0];
|
||||
}
|
||||
char* str = strsCopy(&buffs, obj_getStr(self, "str"));
|
||||
@ -332,11 +336,11 @@ Arg* PikaStdData_String_encode(PikaObj* self, PikaTuple* encoding) {
|
||||
|
||||
#if PIKA_STRING_UTF8_ENABLE
|
||||
char* to_code = NULL;
|
||||
int argn = tuple_getSize(encoding);
|
||||
int argn = pikaTuple_getSize(encoding);
|
||||
if (argn < 1) {
|
||||
return arg_newBytes((uint8_t*)str, strGetSize(str));
|
||||
}
|
||||
Arg* arg_i = tuple_getArg(encoding, 0);
|
||||
Arg* arg_i = pikaTuple_getArg(encoding, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_STRING) {
|
||||
obj_setErrorCode(self, __LINE__);
|
||||
__platform_printf("Error invaliad arguments\r\n");
|
||||
|
@ -4,12 +4,12 @@
|
||||
|
||||
int PikaStdData_Tuple_len(PikaObj* self) {
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
return list_getSize(list);
|
||||
return pikaList_getSize(list);
|
||||
}
|
||||
|
||||
Arg* PikaStdData_Tuple_get(PikaObj* self, int i) {
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
return arg_copy(list_getArg(list, i));
|
||||
return arg_copy(pikaList_getArg(list, i));
|
||||
}
|
||||
|
||||
void PikaStdData_Tuple___init__(PikaObj* self) {
|
||||
@ -47,7 +47,7 @@ char* PikaStdData_Tuple___str__(PikaObj* self) {
|
||||
|
||||
int i = 0;
|
||||
while (PIKA_TRUE) {
|
||||
Arg* item = list_getArg(list, i);
|
||||
Arg* item = pikaList_getArg(list, i);
|
||||
if (NULL == item) {
|
||||
break;
|
||||
}
|
||||
@ -77,8 +77,8 @@ int PikaStdData_Tuple___len__(PikaObj* self) {
|
||||
|
||||
int PikaStdData_Tuple___contains__(PikaObj* self, Arg* val) {
|
||||
PikaList* list = obj_getPtr(self, "list");
|
||||
for (size_t i = 0; i < list_getSize(list); i++) {
|
||||
Arg* arg = list_getArg(list, i);
|
||||
for (size_t i = 0; i < pikaList_getSize(list); i++) {
|
||||
Arg* arg = pikaList_getArg(list, i);
|
||||
if (arg_isEqual(arg, val)) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -184,22 +184,22 @@ Arg* PikaStdLib_SysObj_range(PikaObj* self, PikaTuple* ax) {
|
||||
Arg* obj_arg = arg_newDirectObj(New_PikaStdLib_RangeObj);
|
||||
PikaObj* range_obj = arg_getPtr(obj_arg);
|
||||
RangeData range_data = {0};
|
||||
if (tuple_getSize(ax) == 1) {
|
||||
if (pikaTuple_getSize(ax) == 1) {
|
||||
int start = 0;
|
||||
int end = arg_getInt(tuple_getArg(ax, 0));
|
||||
int end = arg_getInt(pikaTuple_getArg(ax, 0));
|
||||
range_data.start = start;
|
||||
range_data.end = end;
|
||||
range_data.step = 1;
|
||||
} else if (tuple_getSize(ax) == 2) {
|
||||
int start = arg_getInt(tuple_getArg(ax, 0));
|
||||
int end = arg_getInt(tuple_getArg(ax, 1));
|
||||
} else if (pikaTuple_getSize(ax) == 2) {
|
||||
int start = arg_getInt(pikaTuple_getArg(ax, 0));
|
||||
int end = arg_getInt(pikaTuple_getArg(ax, 1));
|
||||
range_data.start = start;
|
||||
range_data.end = end;
|
||||
range_data.step = 1;
|
||||
} else if (tuple_getSize(ax) == 3) {
|
||||
int start = arg_getInt(tuple_getArg(ax, 0));
|
||||
int end = arg_getInt(tuple_getArg(ax, 1));
|
||||
int step = arg_getInt(tuple_getArg(ax, 2));
|
||||
} else if (pikaTuple_getSize(ax) == 3) {
|
||||
int start = arg_getInt(pikaTuple_getArg(ax, 0));
|
||||
int end = arg_getInt(pikaTuple_getArg(ax, 1));
|
||||
int step = arg_getInt(pikaTuple_getArg(ax, 2));
|
||||
range_data.start = start;
|
||||
range_data.end = end;
|
||||
range_data.step = step;
|
||||
@ -305,8 +305,8 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) {
|
||||
|
||||
Arg* PikaStdLib_SysObj_list(PikaObj* self, PikaTuple* val) {
|
||||
#if PIKA_BUILTIN_STRUCT_ENABLE
|
||||
if (1 == tuple_getSize(val)) {
|
||||
Arg* in = tuple_getArg(val, 0);
|
||||
if (1 == pikaTuple_getSize(val)) {
|
||||
Arg* in = pikaTuple_getArg(val, 0);
|
||||
obj_setArg(self, "__list", in);
|
||||
/* clang-format off */
|
||||
PIKA_PYTHON(
|
||||
@ -408,10 +408,10 @@ Arg* PikaStdLib_SysObj_bytes(PikaObj* self, Arg* val) {
|
||||
if (obj->constructor == New_PikaStdData_List ||
|
||||
obj->constructor == New_PikaStdData_Tuple) {
|
||||
PikaList* list = obj_getPtr(obj, "list");
|
||||
Arg* bytes = arg_newBytes(NULL, list_getSize(list));
|
||||
Arg* bytes = arg_newBytes(NULL, pikaList_getSize(list));
|
||||
uint8_t* bytes_raw = arg_getBytes(bytes);
|
||||
for (size_t i = 0; i < list_getSize(list); i++) {
|
||||
bytes_raw[i] = (uint8_t)list_getInt(list, i);
|
||||
for (size_t i = 0; i < pikaList_getSize(list); i++) {
|
||||
bytes_raw[i] = (uint8_t)pikaList_getInt(list, i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
@ -423,61 +423,89 @@ Arg* PikaStdLib_SysObj_bytes(PikaObj* self, Arg* val) {
|
||||
}
|
||||
|
||||
static char* __print_arg(PikaObj* self, Arg* val) {
|
||||
obj_setErrorCode(self, 0);
|
||||
Args buffs = {0};
|
||||
char* res = NULL;
|
||||
if (NULL == val) {
|
||||
goto __exit;
|
||||
}
|
||||
ArgType arg_type = arg_getType(val);
|
||||
if (NULL != val) {
|
||||
if (arg_getType(val) == ARG_TYPE_BYTES) {
|
||||
return __printBytes(self, val);
|
||||
}
|
||||
if (arg_getType(val) == ARG_TYPE_NONE) {
|
||||
return "None";
|
||||
}
|
||||
if (arg_type == ARG_TYPE_BYTES) {
|
||||
res = __printBytes(self, val);
|
||||
goto __exit;
|
||||
}
|
||||
if (arg_type == ARG_TYPE_STRING) {
|
||||
res = arg_getStr(val);
|
||||
goto __exit;
|
||||
}
|
||||
if (arg_type == ARG_TYPE_NONE) {
|
||||
res = "None";
|
||||
goto __exit;
|
||||
}
|
||||
if (arg_type == ARG_TYPE_INT) {
|
||||
int64_t value = arg_getInt(val);
|
||||
res = strsFormat(&buffs, 32, "%lld", value);
|
||||
goto __exit;
|
||||
}
|
||||
if (arg_type == ARG_TYPE_FLOAT) {
|
||||
pika_float value = arg_getFloat(val);
|
||||
res = strsFormat(&buffs, 32, "%f", value);
|
||||
goto __exit;
|
||||
}
|
||||
if (arg_type == ARG_TYPE_POINTER ||
|
||||
arg_type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR) {
|
||||
void* value = arg_getPtr(val);
|
||||
res = strsFormat(&buffs, 32, "%p", value);
|
||||
goto __exit;
|
||||
}
|
||||
if (argType_isObject(arg_type)) {
|
||||
char* to_str = obj_toStr(arg_getPtr(val));
|
||||
if (NULL != to_str) {
|
||||
return obj_cacheStr(self, to_str);
|
||||
}
|
||||
res = obj_toStr(arg_getPtr(val));
|
||||
goto __exit;
|
||||
}
|
||||
Args* print_args = New_args(NULL);
|
||||
arg_setName(val, "val");
|
||||
args_setArg(print_args, arg_copy(val));
|
||||
char* res = args_print(print_args, "val");
|
||||
__exit:
|
||||
if (NULL == res) {
|
||||
obj_setSysOut(self, "Error: can not print val");
|
||||
obj_setErrorCode(self, 1);
|
||||
args_deinit(print_args);
|
||||
return NULL;
|
||||
}
|
||||
res = obj_cacheStr(self, res);
|
||||
args_deinit(print_args);
|
||||
if (NULL != res) {
|
||||
res = obj_cacheStr(self, res);
|
||||
}
|
||||
strsDeinit(&buffs);
|
||||
return res;
|
||||
}
|
||||
|
||||
void PikaStdLib_SysObj_print(PikaObj* self, PikaTuple* val, PikaDict* ops) {
|
||||
int arg_size = tuple_getSize(val);
|
||||
Arg* print_out_arg = arg_newStr("");
|
||||
int arg_size = pikaTuple_getSize(val);
|
||||
char* end = pikaDict_getStr(ops, "end");
|
||||
if (NULL == end) {
|
||||
/* default */
|
||||
end = "\r\n";
|
||||
}
|
||||
if (arg_size == 1) {
|
||||
arg_singlePrint(pikaTuple_getArg(val, 0), PIKA_FALSE, end);
|
||||
return;
|
||||
}
|
||||
Arg* print_out_arg = NULL;
|
||||
PIKA_BOOL is_get_print = PIKA_FALSE;
|
||||
for (int i = 0; i < arg_size; i++) {
|
||||
Arg* arg = tuple_getArg(val, i);
|
||||
Arg* arg = pikaTuple_getArg(val, i);
|
||||
char* item = __print_arg(self, arg);
|
||||
if (NULL != item) {
|
||||
is_get_print = PIKA_TRUE;
|
||||
if (NULL == print_out_arg) {
|
||||
print_out_arg = arg_newStr("");
|
||||
}
|
||||
print_out_arg = arg_strAppend(print_out_arg, item);
|
||||
if (i < arg_size - 1) {
|
||||
print_out_arg = arg_strAppend(print_out_arg, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
char* end = dict_getStr(ops, "end");
|
||||
if (NULL == end) {
|
||||
/* default */
|
||||
end = "\r\n";
|
||||
}
|
||||
if (PIKA_TRUE == is_get_print) {
|
||||
__platform_printf("%s%s", arg_getStr(print_out_arg), end);
|
||||
}
|
||||
arg_deinit(print_out_arg);
|
||||
if (NULL != print_out_arg) {
|
||||
arg_deinit(print_out_arg);
|
||||
}
|
||||
}
|
||||
|
||||
char* PikaStdLib_SysObj_cformat(PikaObj* self, char* fmt, PikaTuple* var) {
|
||||
@ -635,8 +663,8 @@ char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
|
||||
.handler = __obj_shellLineHandler_input,
|
||||
.fn_getchar = __platform_getchar,
|
||||
};
|
||||
if (tuple_getSize(info) > 0) {
|
||||
__platform_printf("%s", tuple_getStr(info, 0));
|
||||
if (pikaTuple_getSize(info) > 0) {
|
||||
__platform_printf("%s", pikaTuple_getStr(info, 0));
|
||||
}
|
||||
_temp__do_pikaScriptShell(self, &cfg);
|
||||
char* res = obj_cacheStr(self, arg_getStr(cfg.context));
|
||||
|
9
package/STM32G0/.vscode/settings.json
vendored
9
package/STM32G0/.vscode/settings.json
vendored
@ -1,9 +0,0 @@
|
||||
{
|
||||
"RTT_Studio.Build.Parallel_Jobs": "12",
|
||||
"RTT_Studio.Env_Location": "D:/RT-ThreadStudio/platform/env_released/env",
|
||||
"RTT_Studio.Toolchain_Location": "D:/RT-ThreadStudio/repo/Extract/ToolChain_Support_Packages/ARM/GNU_Tools_for_ARM_Embedded_Processors/5.4.1/bin",
|
||||
"RTT_Studio.Debuger.Bin_File": "D:/RT-ThreadStudio/repo/Extract/ToolChain_Support_Packages/ARM/GNU_Tools_for_ARM_Embedded_Processors/5.4.1/bin/arm-none-eabi-gdb.exe",
|
||||
"RTT_Studio.Debuger.J-Link.Location": "D:/RT-ThreadStudio/repo/Extract/Debugger_Support_Packages/SEGGER/J-Link/6.80d2",
|
||||
"RTT_Studio.Debuger.ST-Link.Location": "D:/RT-ThreadStudio/repo/Extract/Debugger_Support_Packages/STMicroelectronics/ST-LINK_Debugger/1.6.0",
|
||||
"RTT_Studio.Debuger.QEMU.Location": "D:/RT-ThreadStudio/repo/Extract/Debugger_Support_Packages/RealThread/QEMU/4.2.0.4"
|
||||
}
|
@ -4,30 +4,7 @@ import PikaStdDevice
|
||||
import PikaStdTask
|
||||
|
||||
|
||||
class GPIO(PikaStdDevice.GPIO):
|
||||
# override
|
||||
def platformHigh(self):
|
||||
pass
|
||||
|
||||
# override
|
||||
def platformLow(self):
|
||||
pass
|
||||
|
||||
# override
|
||||
def platformEnable(self):
|
||||
pass
|
||||
|
||||
# override
|
||||
def platformDisable(self):
|
||||
pass
|
||||
|
||||
# override
|
||||
def platformSetMode(self):
|
||||
pass
|
||||
|
||||
# override
|
||||
def platformRead(self):
|
||||
pass
|
||||
class GPIO(PikaStdDevice.GPIO): ...
|
||||
|
||||
|
||||
class Time(PikaStdDevice.Time):
|
||||
|
@ -4,158 +4,6 @@
|
||||
#include "STM32G0_common.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
void STM32G0_GPIO_platformDisable(PikaObj* self) {
|
||||
char* pin = obj_getStr(self, "pin");
|
||||
char* mode = obj_getStr(self, "mode");
|
||||
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
|
||||
|
||||
if (NULL == gpioPort) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
}
|
||||
|
||||
uint16_t gpioPin = GPIO_get_pin(pin);
|
||||
|
||||
if (0 == gpioPin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio pin.");
|
||||
}
|
||||
|
||||
LL_GPIO_DeInit(gpioPort);
|
||||
}
|
||||
|
||||
void STM32G0_GPIO_platformEnable(PikaObj* self) {
|
||||
char* pin = obj_getStr(self, "pin");
|
||||
char* mode = obj_getStr(self, "mode");
|
||||
|
||||
if (0 != GPIO_enable_clock(pin)) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
return;
|
||||
}
|
||||
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
|
||||
|
||||
if (NULL == gpioPort) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
}
|
||||
|
||||
uint16_t gpioPin = GPIO_get_pin(pin);
|
||||
|
||||
if (0 == gpioPin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio pin.");
|
||||
}
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
|
||||
|
||||
uint32_t pinMode = getPinMode(mode);
|
||||
|
||||
uint32_t gpioPull = GPIO_NOPULL;
|
||||
char* pull = obj_getStr(self, "pull");
|
||||
if (strEqu(pull, "up")) {
|
||||
gpioPull = GPIO_PULLUP;
|
||||
} else if (strEqu(pull, "down")) {
|
||||
gpioPull = GPIO_PULLDOWN;
|
||||
}
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/*Configure GPIO*/
|
||||
GPIO_InitStruct.Pin = gpioPin;
|
||||
GPIO_InitStruct.Mode = pinMode;
|
||||
GPIO_InitStruct.Pull = gpioPull;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
LL_GPIO_Init(gpioPort, &GPIO_InitStruct);
|
||||
}
|
||||
void STM32G0_GPIO_platformLow(PikaObj* self) {
|
||||
char* pin = obj_getStr(self, "pin");
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
|
||||
|
||||
if (NULL == gpioPort) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
}
|
||||
|
||||
uint16_t gpioPin = GPIO_get_pin(pin);
|
||||
|
||||
if (0 == gpioPin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio pin.");
|
||||
}
|
||||
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
|
||||
}
|
||||
void STM32G0_GPIO_platformHigh(PikaObj* self) {
|
||||
char* pin = obj_getStr(self, "pin");
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
|
||||
|
||||
if (NULL == gpioPort) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
}
|
||||
|
||||
uint16_t gpioPin = GPIO_get_pin(pin);
|
||||
|
||||
if (0 == gpioPin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio pin.");
|
||||
}
|
||||
LL_GPIO_SetOutputPin(gpioPort, gpioPin);
|
||||
}
|
||||
|
||||
void STM32G0_GPIO_platformSetMode(PikaObj* self) {
|
||||
char* pin = obj_getStr(self, "pin");
|
||||
char* mode = obj_getStr(self, "mode");
|
||||
if (0 != GPIO_enable_clock(pin)) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
return;
|
||||
}
|
||||
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
|
||||
|
||||
if (NULL == gpioPort) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
}
|
||||
|
||||
uint16_t gpioPin = GPIO_get_pin(pin);
|
||||
|
||||
if (0 == gpioPin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio pin.");
|
||||
}
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
|
||||
|
||||
uint32_t pinMode = getPinMode(mode);
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/*Configure GPIO*/
|
||||
GPIO_InitStruct.Pin = gpioPin;
|
||||
GPIO_InitStruct.Mode = pinMode;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
LL_GPIO_Init(gpioPort, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void STM32G0_GPIO_platformRead(PikaObj* self) {
|
||||
char* pin = obj_getStr(self, "pin");
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
|
||||
if (NULL == gpioPort) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
}
|
||||
uint16_t gpioPin = GPIO_get_pin(pin);
|
||||
if (0 == gpioPin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio pin.");
|
||||
}
|
||||
obj_setInt(self, "readBuff", LL_GPIO_IsInputPinSet(gpioPort, gpioPin));
|
||||
}
|
||||
|
||||
int STM32G0_lowLevel_readPin(PikaObj* self, char* pin) {
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(pin);
|
||||
|
277
package/STM32G0/pika_hal_STM32G0.c
Normal file
277
package/STM32G0/pika_hal_STM32G0.c
Normal file
@ -0,0 +1,277 @@
|
||||
#include <stdint.h>
|
||||
#include "BaseObj.h"
|
||||
#include "STM32G0_GPIO.h"
|
||||
#include "STM32G0_common.h"
|
||||
#include "dataStrs.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
typedef struct platform_data_GPIO {
|
||||
GPIO_TypeDef* gpioPort;
|
||||
uint16_t gpioPin;
|
||||
uint32_t pinMode;
|
||||
uint32_t gpioPull;
|
||||
} platform_data_GPIO;
|
||||
|
||||
int pika_hal_platform_GPIO_open(pika_dev* dev, char* name) {
|
||||
__platform_printf("Open: %s \r\n", name);
|
||||
GPIO_TypeDef* gpioPort = GPIO_get_Group(name);
|
||||
if (NULL == gpioPort) {
|
||||
__platform_printf("Error: get GPIO group failed.\r\n");
|
||||
return -1;
|
||||
}
|
||||
uint16_t gpioPin = GPIO_get_pin(name);
|
||||
if (0 == gpioPin) {
|
||||
__platform_printf("Error: get GPIO Pin failed.\r\n");
|
||||
return -1;
|
||||
}
|
||||
platform_data_GPIO* data = pikaMalloc(sizeof(platform_data_GPIO));
|
||||
data->gpioPin = gpioPin;
|
||||
data->gpioPort = gpioPort;
|
||||
dev->platform_data = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_close(pika_dev* dev) {
|
||||
if (NULL != dev->platform_data) {
|
||||
pikaFree(dev->platform_data, sizeof(platform_data_GPIO));
|
||||
dev->platform_data = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_read(pika_dev* dev, void* buf, size_t count) {
|
||||
platform_data_GPIO* data = dev->platform_data;
|
||||
uint32_t level = LL_GPIO_IsInputPinSet(data->gpioPort, data->gpioPin);
|
||||
if (level != 1 && level != 0) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(buf, &level, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_write(pika_dev* dev, void* buf, size_t count) {
|
||||
platform_data_GPIO* data = dev->platform_data;
|
||||
uint32_t level = 0;
|
||||
memcpy(&level, buf, count);
|
||||
if (level == 0) {
|
||||
LL_GPIO_ResetOutputPin(data->gpioPort, data->gpioPin);
|
||||
return 0;
|
||||
}
|
||||
if (level == 1) {
|
||||
LL_GPIO_SetOutputPin(data->gpioPort, data->gpioPin);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int _enable_gpio_clk(GPIO_TypeDef* gpio_group) {
|
||||
if (gpio_group == GPIOA) {
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
return 0;
|
||||
}
|
||||
if (gpio_group == GPIOB) {
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
return 0;
|
||||
}
|
||||
if (gpio_group == GPIOC) {
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_enable(pika_dev* dev) {
|
||||
platform_data_GPIO* data = dev->platform_data;
|
||||
|
||||
if (0 != _enable_gpio_clk(data->gpioPort)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
LL_GPIO_ResetOutputPin(data->gpioPort, data->gpioPin);
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/*Configure GPIO*/
|
||||
GPIO_InitStruct.Pin = data->gpioPin;
|
||||
GPIO_InitStruct.Mode = data->pinMode;
|
||||
GPIO_InitStruct.Pull = data->gpioPull;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
LL_GPIO_Init(data->gpioPort, &GPIO_InitStruct);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_disable(pika_dev* dev) {
|
||||
platform_data_GPIO* data = dev->platform_data;
|
||||
LL_GPIO_DeInit(data->gpioPort);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_config(pika_dev* dev,
|
||||
pika_hal_GPIO_config* cfg) {
|
||||
platform_data_GPIO* data = dev->platform_data;
|
||||
switch (cfg->dir) {
|
||||
case PIKA_HAL_GPIO_DIR_IN:
|
||||
data->pinMode = LL_GPIO_MODE_INPUT;
|
||||
case PIKA_HAL_GPIO_DIR_OUT:
|
||||
data->pinMode = LL_GPIO_MODE_OUTPUT;
|
||||
default:
|
||||
data->pinMode = LL_GPIO_MODE_OUTPUT;
|
||||
}
|
||||
switch (cfg->pull) {
|
||||
case PIKA_HAL_GPIO_PULL_UP:
|
||||
data->gpioPull = LL_GPIO_PULL_UP;
|
||||
case PIKA_HAL_GPIO_PULL_DOWN:
|
||||
data->gpioPull = LL_GPIO_PULL_DOWN;
|
||||
default:
|
||||
data->gpioPull = LL_GPIO_PULL_NO;
|
||||
}
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/*Configure GPIO*/
|
||||
GPIO_InitStruct.Pin = data->gpioPin;
|
||||
GPIO_InitStruct.Mode = data->pinMode;
|
||||
GPIO_InitStruct.Pull = data->gpioPull;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
LL_GPIO_Init(data->gpioPort, &GPIO_InitStruct);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct platform_data_SPI {
|
||||
SPI_HandleTypeDef* hspi;
|
||||
pika_dev* cs;
|
||||
} platform_data_SPI;
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
DMA_HandleTypeDef hdma_spi1_tx;
|
||||
|
||||
platform_data_SPI platform_data_SPI_spi1 = {
|
||||
.hspi = &hspi1,
|
||||
};
|
||||
|
||||
int pika_hal_platform_SPI_open(pika_dev* dev, char* name) {
|
||||
if (strEqu(name, "spi1")) {
|
||||
dev->platform_data = &platform_data_SPI_spi1;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_ioctl_config(pika_dev* dev,
|
||||
pika_hal_SPI_config* cfg) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define SPI_DMA
|
||||
|
||||
void MX_SPI1_Init(void) {
|
||||
hspi1.Instance = SPI1;
|
||||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 10;
|
||||
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
||||
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
||||
HAL_SPI_Init(&hspi1);
|
||||
}
|
||||
|
||||
static void MX_DMA_Init(void) {
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
}
|
||||
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
hdma_spi1_tx.Instance = DMA1_Channel1;
|
||||
hdma_spi1_tx.Init.Request = DMA_REQUEST_SPI1_TX;
|
||||
hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_spi1_tx.Init.Mode = DMA_NORMAL;
|
||||
hdma_spi1_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
||||
HAL_DMA_Init(&hdma_spi1_tx);
|
||||
__HAL_LINKDMA(hspi, hdmatx, hdma_spi1_tx);
|
||||
}
|
||||
|
||||
void DMA1_Channel1_IRQHandler(void) {
|
||||
HAL_DMA_IRQHandler(&hdma_spi1_tx);
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_ioctl_enable(pika_dev* dev) {
|
||||
platform_data_SPI* data = dev->platform_data;
|
||||
/* init GPIO CS */
|
||||
data->cs = pika_hal_open(PIKA_HAL_GPIO, "PB1");
|
||||
pika_hal_GPIO_config cfg = {
|
||||
.dir = PIKA_HAL_GPIO_DIR_OUT,
|
||||
.pull = PIKA_HAL_GPIO_PULL_NONE,
|
||||
};
|
||||
pika_hal_ioctl(data->cs, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
uint32_t val = 0;
|
||||
pika_hal_write(data->cs, &val, sizeof(val));
|
||||
/* init SPI */
|
||||
#ifndef SPI_SOFT
|
||||
MX_DMA_Init();
|
||||
MX_SPI1_Init();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_read(pika_dev* dev, void* buf, size_t count) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_write(pika_dev* dev, void* buf, size_t count) {
|
||||
#ifdef SPI_SOFT
|
||||
for (int i = 0; i < size; i++) {
|
||||
SPI_Write_u8(pData[i]);
|
||||
}
|
||||
#else
|
||||
#ifdef SPI_DMA
|
||||
/* wait spi ready */
|
||||
while (hspi1.hdmatx->State != HAL_DMA_STATE_READY ||
|
||||
hspi1.State != HAL_SPI_STATE_READY) {
|
||||
};
|
||||
HAL_SPI_Transmit_DMA(&hspi1, (uint8_t*)buf, count);
|
||||
/* wait spi ready */
|
||||
while (hspi1.hdmatx->State != HAL_DMA_STATE_READY ||
|
||||
hspi1.State != HAL_SPI_STATE_READY) {
|
||||
};
|
||||
#else
|
||||
HAL_SPI_Transmit(&hspi1, pData, size, HAL_MAX_DELAY);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_ioctl_disable(pika_dev* dev) {
|
||||
platform_data_SPI* data = dev->platform_data;
|
||||
uint32_t val = 1;
|
||||
pika_hal_write(data->cs, &val, sizeof(val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_SPI_close(pika_dev* dev) {
|
||||
platform_data_SPI* data = dev->platform_data;
|
||||
pika_hal_close(data->cs);
|
||||
return 0;
|
||||
}
|
6
package/hashlib/_hashlib.pyi
Normal file
6
package/hashlib/_hashlib.pyi
Normal file
@ -0,0 +1,6 @@
|
||||
class Hash:
|
||||
def new(self, mode: str, data:any): ...
|
||||
def update(self, data: any): ...
|
||||
def digest(self) -> any: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def copy(self): ...
|
233
package/hashlib/_hashlib_Hash.c
Normal file
233
package/hashlib/_hashlib_Hash.c
Normal file
@ -0,0 +1,233 @@
|
||||
#include "_hashlib_Hash.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
|
||||
enum {
|
||||
PIKA_HASHLIB_MD5 = 16,
|
||||
PIKA_HASHLIB_SHA1 = 20,
|
||||
PIKA_HASHLIB_SHA224 = 28,
|
||||
PIKA_HASHLIB_SHA256 = 32,
|
||||
PIKA_HASHLIB_SHA384 = 48,
|
||||
PIKA_HASHLIB_SHA512 = 64
|
||||
} pika_hashlib_t;
|
||||
|
||||
static void hashlib_to_hex(uint8_t* s, int l, uint8_t* d);
|
||||
|
||||
void _hashlib_Hash_new(PikaObj* self, char* mode, Arg* data) {
|
||||
ArgType t;
|
||||
t = arg_getType(data);
|
||||
if (ARG_TYPE_NONE != t) {
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
obj_setInt(self, "_digest_flags", 0); // flag
|
||||
obj_setBytes(self, "_buff", NULL, PIKA_HASHLIB_SHA512); // digest buff
|
||||
obj_setBytes(self, "_hexbuff", NULL,
|
||||
PIKA_HASHLIB_SHA512 * 2); // hexdigest buff
|
||||
|
||||
size_t data_len = arg_getBytesSize(data);
|
||||
uint8_t* data_h = arg_getBytes(data);
|
||||
|
||||
if (strcmp(mode, "md5") == 0 || strcmp(mode, "MD5") == 0) {
|
||||
mbedtls_md5_context context;
|
||||
mbedtls_md5_init(&context);
|
||||
mbedtls_md5_starts(&context);
|
||||
if (data_len > 0) {
|
||||
mbedtls_md5_update(&context, data_h, data_len);
|
||||
}
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HASHLIB_MD5);
|
||||
} else if (strcmp(mode, "sha1") == 0 || strcmp(mode, "SHA1") == 0) {
|
||||
mbedtls_sha1_context context;
|
||||
mbedtls_sha1_init(&context);
|
||||
mbedtls_sha1_starts(&context);
|
||||
if (data_len > 0) {
|
||||
mbedtls_sha1_update(&context, data_h,
|
||||
data_len);
|
||||
}
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HASHLIB_SHA1);
|
||||
} else if (strcmp(mode, "sha224") == 0 || strcmp(mode, "SHA224") == 0) {
|
||||
mbedtls_sha256_context context;
|
||||
mbedtls_sha256_init(&context);
|
||||
mbedtls_sha256_starts(&context, 1);
|
||||
if (data_len > 0) {
|
||||
mbedtls_sha256_update(&context, data_h,
|
||||
data_len);
|
||||
}
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HASHLIB_SHA224);
|
||||
} else if (strcmp(mode, "sha256") == 0 || strcmp(mode, "SHA256") == 0) {
|
||||
mbedtls_sha256_context context;
|
||||
mbedtls_sha256_init(&context);
|
||||
mbedtls_sha256_starts(&context, 0);
|
||||
if (data_len > 0) {
|
||||
mbedtls_sha256_update(&context, data_h,
|
||||
data_len);
|
||||
}
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HASHLIB_SHA256);
|
||||
} else if (strcmp(mode, "sha384") == 0 || strcmp(mode, "SHA384") == 0) {
|
||||
mbedtls_sha512_context context;
|
||||
mbedtls_sha512_init(&context);
|
||||
mbedtls_sha512_starts(&context, 1);
|
||||
if (data_len > 0) {
|
||||
mbedtls_sha512_update(&context, data_h,
|
||||
data_len);
|
||||
}
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HASHLIB_SHA384);
|
||||
} else if (strcmp(mode, "sha512") == 0 || strcmp(mode, "SHA512") == 0) {
|
||||
mbedtls_sha512_context context;
|
||||
mbedtls_sha512_init(&context);
|
||||
mbedtls_sha512_starts(&context, 0);
|
||||
if (data_len > 0) {
|
||||
mbedtls_sha512_update(&context, data_h,
|
||||
data_len);
|
||||
}
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HASHLIB_SHA512);
|
||||
} else {
|
||||
obj_setErrorCode(self, -1); // not support mode
|
||||
}
|
||||
}
|
||||
|
||||
void _hashlib_Hash_update(PikaObj* self, Arg* data) {
|
||||
if (ARG_TYPE_BYTES != arg_getType(data)) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
void* context = obj_getStruct(self, "context");
|
||||
size_t data_len = arg_getBytesSize(data);
|
||||
uint8_t* data_h = arg_getBytes(data);
|
||||
|
||||
if (data_len > 0) {
|
||||
switch (obj_getInt(self, "mode")) {
|
||||
case PIKA_HASHLIB_MD5:
|
||||
mbedtls_md5_update((mbedtls_md5_context*)context, data_h,
|
||||
data_len);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA1:
|
||||
mbedtls_sha1_update((mbedtls_sha1_context*)context, data_h,
|
||||
data_len);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA224:
|
||||
case PIKA_HASHLIB_SHA256:
|
||||
mbedtls_sha256_update((mbedtls_sha256_context*)context, data_h,
|
||||
data_len);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA384:
|
||||
case PIKA_HASHLIB_SHA512:
|
||||
mbedtls_sha512_update((mbedtls_sha512_context*)context, data_h,
|
||||
data_len);
|
||||
break;
|
||||
default:
|
||||
obj_setErrorCode(self, -1); // not support mode
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
Arg* _hashlib_Hash_digest(PikaObj* self) {
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
uint8_t flag = obj_getInt(self, "_digest_flags");
|
||||
|
||||
if (flag & 0x01) // already digest
|
||||
{
|
||||
return arg_newBytes(buff, obj_getInt(self, "mode"));
|
||||
} else {
|
||||
void* context = obj_getStruct(self, "context");
|
||||
uint8_t mode = obj_getInt(self, "mode");
|
||||
|
||||
switch (mode) {
|
||||
case PIKA_HASHLIB_MD5:
|
||||
mbedtls_md5_finish((mbedtls_md5_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA1:
|
||||
mbedtls_sha1_finish((mbedtls_sha1_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA224:
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA256:
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA384:
|
||||
mbedtls_sha512_finish((mbedtls_sha512_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA512:
|
||||
mbedtls_sha512_finish((mbedtls_sha512_context*)context, buff);
|
||||
break;
|
||||
default:
|
||||
obj_setErrorCode(self, -1); // not support mode
|
||||
return arg_newNull(); // will not actually return to the python
|
||||
break;
|
||||
}
|
||||
obj_setInt(self, "_digest_flags", flag | 0x01);
|
||||
return arg_newBytes(buff, mode);
|
||||
}
|
||||
}
|
||||
|
||||
char* _hashlib_Hash_hexdigest(PikaObj* self) {
|
||||
uint8_t* hexbuff = obj_getBytes(self, "_hexbuff");
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
uint8_t flag = obj_getInt(self, "_digest_flags");
|
||||
|
||||
if (flag & 0x01) { // already digest
|
||||
hashlib_to_hex(buff, obj_getInt(self, "mode"), hexbuff);
|
||||
obj_setInt(self, "_digest_flags", flag | 0x02); // set hexdigest flag
|
||||
} else if (flag & 0x02) { // already hexdigest
|
||||
|
||||
} else {
|
||||
void* context = obj_getStruct(self, "context");
|
||||
switch (obj_getInt(self, "mode")) {
|
||||
case PIKA_HASHLIB_MD5:
|
||||
mbedtls_md5_finish((mbedtls_md5_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA1:
|
||||
mbedtls_sha1_finish((mbedtls_sha1_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA224:
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA256:
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA384:
|
||||
mbedtls_sha512_finish((mbedtls_sha512_context*)context, buff);
|
||||
break;
|
||||
case PIKA_HASHLIB_SHA512:
|
||||
mbedtls_sha512_finish((mbedtls_sha512_context*)context, buff);
|
||||
break;
|
||||
default:
|
||||
obj_setErrorCode(self, -1); // not support mode
|
||||
break;
|
||||
}
|
||||
hashlib_to_hex(buff, obj_getInt(self, "mode"), hexbuff);
|
||||
obj_setInt(self, "_digest_flags",
|
||||
flag | 0x03); // set digest and hexdigest flags
|
||||
}
|
||||
return (char*)hexbuff;
|
||||
}
|
||||
|
||||
void _hashlib_Hash_copy(PikaObj* self) { // todo
|
||||
}
|
||||
|
||||
static const uint8_t hashlib_hex_table[] = {'0', '1', '2', '3', '4', '5',
|
||||
'6', '7', '8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F'};
|
||||
static void hashlib_to_hex(uint8_t* s, int l, uint8_t* d) {
|
||||
while (l--) {
|
||||
*(d++) = hashlib_hex_table[*s >> 4];
|
||||
*(d++) = hashlib_hex_table[*(s++) & 0x0f];
|
||||
}
|
||||
}
|
43
package/hashlib/hashlib.py
Normal file
43
package/hashlib/hashlib.py
Normal file
@ -0,0 +1,43 @@
|
||||
import _hashlib
|
||||
|
||||
|
||||
def new(mode: str) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new(mode, None)
|
||||
return hash
|
||||
|
||||
|
||||
def md5(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("md5", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha1(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha1", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha224(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha224", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha256(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha256", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha384(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha384", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha512(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha512", data)
|
||||
return hash
|
6
package/hmac/_hmac.pyi
Normal file
6
package/hmac/_hmac.pyi
Normal file
@ -0,0 +1,6 @@
|
||||
class HMAC:
|
||||
def new(self, key:any, msg:any, digestmod:str): ...
|
||||
def update(self, msg:any): ...
|
||||
def digest(self) -> any: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def copy(self): ...
|
306
package/hmac/_hmac_HMAC.c
Normal file
306
package/hmac/_hmac_HMAC.c
Normal file
@ -0,0 +1,306 @@
|
||||
#include "_hmac_HMAC.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
|
||||
enum {
|
||||
PIKA_HMAC_MD5 = 16,
|
||||
PIKA_HMAC_SHA1 = 20,
|
||||
PIKA_HMAC_SHA256 = 32
|
||||
} pika_hmac_t;
|
||||
|
||||
static void hmac_to_hex(uint8_t* s, int l, uint8_t* d);
|
||||
|
||||
void _hmac_HMAC_new(PikaObj* self, Arg* key, Arg* msg, char* digestmod) {
|
||||
ArgType t;
|
||||
t = arg_getType(key);
|
||||
if (ARG_TYPE_NONE != t) {
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
t = arg_getType(msg);
|
||||
if (ARG_TYPE_NONE != t) {
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
obj_setInt(self, "_digest_flags", 0); // flag
|
||||
obj_setBytes(self, "_buff", NULL, PIKA_HMAC_SHA256); // digest buff
|
||||
obj_setBytes(self, "_hexbuff", NULL,
|
||||
PIKA_HMAC_SHA256 * 2); // hexdigest buff
|
||||
obj_setBytes(self, "_k_ipad", NULL, 64); // key ipad
|
||||
obj_setBytes(self, "_k_opad", NULL, 64); // key opad
|
||||
|
||||
size_t key_len = arg_getBytesSize(key);
|
||||
uint8_t* key_data = arg_getBytes(key);
|
||||
size_t msg_len = arg_getBytesSize(msg);
|
||||
uint8_t* msg_data = arg_getBytes(msg);
|
||||
|
||||
uint8_t* k_ipad = obj_getBytes(self, "_k_ipad");
|
||||
uint8_t* k_opad = obj_getBytes(self, "_k_opad");
|
||||
|
||||
if (strcmp(digestmod, "hmac-md5") == 0 ||
|
||||
strcmp(digestmod, "HMAC-MD5") == 0) {
|
||||
mbedtls_md5_context context;
|
||||
|
||||
if (key_len > 64) {
|
||||
mbedtls_md5_init(&context);
|
||||
mbedtls_md5_starts(&context);
|
||||
mbedtls_md5_update(&context, key_data, key_len);
|
||||
mbedtls_md5_finish(&context, k_ipad);
|
||||
mbedtls_md5_free(&context);
|
||||
memcpy(k_opad, k_ipad, 64);
|
||||
} else {
|
||||
memcpy(k_ipad, key_data, key_len);
|
||||
memcpy(k_opad, key_data, key_len);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 64; i++) {
|
||||
k_ipad[i] ^= 0x36;
|
||||
k_opad[i] ^= 0x5c;
|
||||
}
|
||||
|
||||
mbedtls_md5_init(&context);
|
||||
mbedtls_md5_starts(&context);
|
||||
mbedtls_md5_update(&context, k_ipad, 64);
|
||||
if (msg_len > 0) {
|
||||
mbedtls_md5_update(&context, msg_data, msg_len);
|
||||
}
|
||||
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HMAC_MD5);
|
||||
} else if (strcmp(digestmod, "hmac-sha1") == 0 ||
|
||||
strcmp(digestmod, "HMAC-SHA1") == 0) {
|
||||
mbedtls_sha1_context context;
|
||||
|
||||
if (key_len > 64) {
|
||||
mbedtls_sha1_init(&context);
|
||||
mbedtls_sha1_starts(&context);
|
||||
mbedtls_sha1_update(&context, key_data, key_len);
|
||||
mbedtls_sha1_finish(&context, k_ipad);
|
||||
mbedtls_sha1_free(&context);
|
||||
memcpy(k_opad, k_ipad, 64);
|
||||
} else {
|
||||
memcpy(k_ipad, key_data, key_len);
|
||||
memcpy(k_opad, key_data, key_len);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 64; i++) {
|
||||
k_ipad[i] ^= 0x36;
|
||||
k_opad[i] ^= 0x5c;
|
||||
}
|
||||
|
||||
mbedtls_sha1_init(&context);
|
||||
mbedtls_sha1_starts(&context);
|
||||
mbedtls_sha1_update(&context, k_ipad, 64);
|
||||
if (msg_len > 0) {
|
||||
mbedtls_sha1_update(&context, msg_data, msg_len);
|
||||
}
|
||||
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HMAC_SHA1);
|
||||
} else if (strcmp(digestmod, "hmac-sha256") == 0 ||
|
||||
strcmp(digestmod, "HMAC-SHA256") == 0) {
|
||||
mbedtls_sha256_context context;
|
||||
|
||||
if (key_len > 64) {
|
||||
mbedtls_sha256_init(&context);
|
||||
mbedtls_sha256_starts(&context, 0);
|
||||
mbedtls_sha256_update(&context, key_data, key_len);
|
||||
mbedtls_sha256_finish(&context, k_ipad);
|
||||
mbedtls_sha256_free(&context);
|
||||
memcpy(k_opad, k_ipad, 64);
|
||||
} else {
|
||||
memcpy(k_ipad, key_data, key_len);
|
||||
memcpy(k_opad, key_data, key_len);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 64; i++) {
|
||||
k_ipad[i] ^= 0x36;
|
||||
k_opad[i] ^= 0x5c;
|
||||
}
|
||||
|
||||
mbedtls_sha256_init(&context);
|
||||
mbedtls_sha256_starts(&context, 0);
|
||||
mbedtls_sha256_update(&context, k_ipad, 64);
|
||||
if (msg_len > 0) {
|
||||
mbedtls_sha256_update(&context, msg_data, msg_len);
|
||||
}
|
||||
|
||||
obj_setStruct(self, "context", context);
|
||||
obj_setInt(self, "mode", PIKA_HMAC_SHA256);
|
||||
} else {
|
||||
obj_setErrorCode(self, -1); // not support mode
|
||||
}
|
||||
}
|
||||
|
||||
void _hmac_HMAC_update(PikaObj* self, Arg* msg) {
|
||||
ArgType t = arg_getType(msg);
|
||||
if (ARG_TYPE_BYTES != t) {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
|
||||
size_t msg_len = arg_getBytesSize(msg);
|
||||
uint8_t* msg_data = arg_getBytes(msg);
|
||||
void* context = obj_getStruct(self, "context");
|
||||
|
||||
if (msg_len > 0) {
|
||||
switch (obj_getInt(self, "mode")) {
|
||||
case PIKA_HMAC_MD5:
|
||||
mbedtls_md5_update((mbedtls_md5_context*)context, msg_data,
|
||||
msg_len);
|
||||
break;
|
||||
case PIKA_HMAC_SHA1:
|
||||
mbedtls_sha1_update((mbedtls_sha1_context*)context, msg_data,
|
||||
msg_len);
|
||||
break;
|
||||
case PIKA_HMAC_SHA256:
|
||||
mbedtls_sha256_update((mbedtls_sha256_context*)context,
|
||||
msg_data, msg_len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
obj_setErrorCode(self, -2); // io error
|
||||
}
|
||||
}
|
||||
|
||||
Arg* _hmac_HMAC_digest(PikaObj* self) {
|
||||
uint8_t* k_opad = obj_getBytes(self, "_k_opad");
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
uint8_t flag = obj_getInt(self, "_digest_flags");
|
||||
|
||||
if (flag & 0x01) // already digest
|
||||
{
|
||||
return arg_newBytes(buff, obj_getInt(self, "mode"));
|
||||
} else {
|
||||
void* context = obj_getStruct(self, "context");
|
||||
uint8_t mode = obj_getInt(self, "mode");
|
||||
switch (mode) {
|
||||
case PIKA_HMAC_MD5:
|
||||
mbedtls_md5_finish((mbedtls_md5_context*)context, buff);
|
||||
mbedtls_md5_free((mbedtls_md5_context*)context);
|
||||
|
||||
mbedtls_md5_init((mbedtls_md5_context*)context);
|
||||
mbedtls_md5_starts((mbedtls_md5_context*)context);
|
||||
mbedtls_md5_update((mbedtls_md5_context*)context, k_opad, 64);
|
||||
mbedtls_md5_update((mbedtls_md5_context*)context, buff,
|
||||
PIKA_HMAC_MD5);
|
||||
mbedtls_md5_finish((mbedtls_md5_context*)context, buff);
|
||||
mbedtls_md5_free((mbedtls_md5_context*)context);
|
||||
break;
|
||||
case PIKA_HMAC_SHA1:
|
||||
mbedtls_sha1_finish((mbedtls_sha1_context*)context, buff);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context*)context);
|
||||
|
||||
mbedtls_sha1_init((mbedtls_sha1_context*)context);
|
||||
mbedtls_sha1_starts((mbedtls_sha1_context*)context);
|
||||
mbedtls_sha1_update((mbedtls_sha1_context*)context, k_opad, 64);
|
||||
mbedtls_sha1_update((mbedtls_sha1_context*)context, buff,
|
||||
PIKA_HMAC_SHA1);
|
||||
mbedtls_sha1_finish((mbedtls_sha1_context*)context, buff);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context*)context);
|
||||
break;
|
||||
case PIKA_HMAC_SHA256:
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
mbedtls_sha256_free((mbedtls_sha256_context*)context);
|
||||
|
||||
mbedtls_sha256_init((mbedtls_sha256_context*)context);
|
||||
mbedtls_sha256_starts((mbedtls_sha256_context*)context, 0);
|
||||
mbedtls_sha256_update((mbedtls_sha256_context*)context, k_opad,
|
||||
64);
|
||||
mbedtls_sha256_update((mbedtls_sha256_context*)context, buff,
|
||||
PIKA_HMAC_SHA256);
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
mbedtls_sha256_free((mbedtls_sha256_context*)context);
|
||||
break;
|
||||
default:
|
||||
obj_setErrorCode(self, -1); // not support mode
|
||||
return arg_newNull(); // will not actually return to the python
|
||||
break;
|
||||
}
|
||||
obj_setInt(self, "_digest_flags", flag | 0x01);
|
||||
return arg_newBytes(buff, mode);
|
||||
}
|
||||
}
|
||||
|
||||
char* _hmac_HMAC_hexdigest(PikaObj* self) {
|
||||
uint8_t* buff = obj_getBytes(self, "_buff");
|
||||
uint8_t* hexbuff = obj_getBytes(self, "_hexbuff");
|
||||
uint8_t flag = obj_getInt(self, "_digest_flags");
|
||||
|
||||
if (flag & 0x01) { // already digest
|
||||
hmac_to_hex(buff, obj_getInt(self, "mode"), hexbuff);
|
||||
obj_setInt(self, "_digest_flags", flag | 0x02); // set hexdigest flag
|
||||
} else if (flag & 0x02) { // already hexdigest
|
||||
|
||||
} else {
|
||||
void* context = obj_getStruct(self, "context");
|
||||
uint8_t* k_opad = obj_getBytes(self, "_k_opad");
|
||||
|
||||
switch (obj_getInt(self, "mode")) {
|
||||
case PIKA_HMAC_MD5:
|
||||
mbedtls_md5_finish((mbedtls_md5_context*)context, buff);
|
||||
mbedtls_md5_free((mbedtls_md5_context*)context);
|
||||
|
||||
mbedtls_md5_init((mbedtls_md5_context*)context);
|
||||
mbedtls_md5_starts((mbedtls_md5_context*)context);
|
||||
mbedtls_md5_update((mbedtls_md5_context*)context, k_opad, 64);
|
||||
mbedtls_md5_update((mbedtls_md5_context*)context, buff,
|
||||
PIKA_HMAC_MD5);
|
||||
mbedtls_md5_finish((mbedtls_md5_context*)context, buff);
|
||||
mbedtls_md5_free((mbedtls_md5_context*)context);
|
||||
break;
|
||||
case PIKA_HMAC_SHA1:
|
||||
mbedtls_sha1_finish((mbedtls_sha1_context*)context, buff);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context*)context);
|
||||
|
||||
mbedtls_sha1_init((mbedtls_sha1_context*)context);
|
||||
mbedtls_sha1_starts((mbedtls_sha1_context*)context);
|
||||
mbedtls_sha1_update((mbedtls_sha1_context*)context, k_opad, 64);
|
||||
mbedtls_sha1_update((mbedtls_sha1_context*)context, buff,
|
||||
PIKA_HMAC_SHA1);
|
||||
mbedtls_sha1_finish((mbedtls_sha1_context*)context, buff);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context*)context);
|
||||
break;
|
||||
case PIKA_HMAC_SHA256:
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
mbedtls_sha256_free((mbedtls_sha256_context*)context);
|
||||
|
||||
mbedtls_sha256_init((mbedtls_sha256_context*)context);
|
||||
mbedtls_sha256_starts((mbedtls_sha256_context*)context, 0);
|
||||
mbedtls_sha256_update((mbedtls_sha256_context*)context, k_opad,
|
||||
64);
|
||||
mbedtls_sha256_update((mbedtls_sha256_context*)context, buff,
|
||||
PIKA_HMAC_SHA256);
|
||||
mbedtls_sha256_finish((mbedtls_sha256_context*)context, buff);
|
||||
mbedtls_sha256_free((mbedtls_sha256_context*)context);
|
||||
break;
|
||||
default:
|
||||
obj_setErrorCode(self, -1); // not support mode
|
||||
break;
|
||||
}
|
||||
hmac_to_hex(buff, PIKA_HMAC_MD5, hexbuff);
|
||||
obj_setInt(self, "_digest_flags",
|
||||
flag | 0x03); // set digest and hexdigest flags
|
||||
}
|
||||
return (char*)hexbuff;
|
||||
}
|
||||
|
||||
void _hmac_HMAC_copy(PikaObj* self) {}
|
||||
|
||||
static const uint8_t hmac_hex_table[] = {'0', '1', '2', '3', '4', '5',
|
||||
'6', '7', '8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F'};
|
||||
static void hmac_to_hex(uint8_t* s, int l, uint8_t* d) {
|
||||
while (l--) {
|
||||
*(d++) = hmac_hex_table[*s >> 4];
|
||||
*(d++) = hmac_hex_table[*(s++) & 0x0f];
|
||||
}
|
||||
}
|
7
package/hmac/hmac.py
Normal file
7
package/hmac/hmac.py
Normal file
@ -0,0 +1,7 @@
|
||||
import _hmac
|
||||
|
||||
def new(key:any, msg=None, digestmod="hmac-md5") -> _hmac.HMAC:
|
||||
hmac = _hmac.HMAC()
|
||||
hmac.new(key, msg, digestmod)
|
||||
return hmac
|
||||
|
@ -785,7 +785,7 @@ static int mqtt_suback_packet_handle(mqtt_client_t* c,
|
||||
static int mqtt_unsuback_packet_handle(mqtt_client_t* c,
|
||||
platform_timer_t* timer) {
|
||||
int rc = MQTT_FAILED_ERROR;
|
||||
message_handlers_t* msg_handler;
|
||||
message_handlers_t* msg_handler = NULL;
|
||||
uint16_t packet_id = 0;
|
||||
|
||||
rc = mqtt_is_connected(c);
|
||||
@ -1329,10 +1329,6 @@ int mqtt_release(mqtt_client_t* c) {
|
||||
platform_timer_init(&timer);
|
||||
platform_timer_cutdown(&timer, c->mqtt_cmd_timeout);
|
||||
|
||||
if (CLIENT_STATE_INITIALIZED == mqtt_get_client_state(c)) {
|
||||
mqtt_clean_session(c);
|
||||
}
|
||||
|
||||
/* wait for the clean session to complete */
|
||||
while ((CLIENT_STATE_INVALID != mqtt_get_client_state(c))) {
|
||||
// platform_timer_usleep(1000); // 1ms avoid compiler
|
||||
|
@ -83,8 +83,11 @@ PIKA_WEAK void platform_thread_start(platform_thread_t* thread) {
|
||||
|
||||
PIKA_WEAK void platform_thread_destroy(platform_thread_t* thread) {
|
||||
#ifdef __linux
|
||||
if (NULL != thread)
|
||||
if (NULL != thread){
|
||||
pthread_detach(thread->thread);
|
||||
platform_memory_free(thread);
|
||||
thread = NULL;
|
||||
}
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
if (NULL != thread)
|
||||
vTaskDelete(thread->thread);
|
||||
|
@ -434,7 +434,7 @@ void pika_lvgl_img_set_size_mode(PikaObj* self, int mode) {
|
||||
void pika_lvgl_img_dsc_t___init__(PikaObj* self, PikaObj* dsc_dict) {
|
||||
obj_setRef(self, "dsc_dict", dsc_dict);
|
||||
PikaDict* dsc_dict_ = obj_getPtr(dsc_dict, "dict");
|
||||
uint8_t* data = dict_getBytes(dsc_dict_, "data");
|
||||
uint8_t* data = pikaDict_getBytes(dsc_dict_, "data");
|
||||
unsigned char wtmp[4] = {'0'};
|
||||
unsigned char htmp[4] = {'0'};
|
||||
memcpy(&wtmp, data + 16, 4);
|
||||
@ -443,7 +443,7 @@ void pika_lvgl_img_dsc_t___init__(PikaObj* self, PikaObj* dsc_dict) {
|
||||
int h = ((int)(unsigned char)htmp[2]) * 256 + (int)(unsigned char)htmp[3];
|
||||
lv_img_dsc_t img_dsc = {
|
||||
.data = data,
|
||||
.data_size = dict_getInt(dsc_dict_, "data_size"),
|
||||
.data_size = pikaDict_getInt(dsc_dict_, "data_size"),
|
||||
.header =
|
||||
{
|
||||
.always_zero = 0,
|
||||
|
@ -28,8 +28,8 @@
|
||||
PikaObj* pika_lv_event_listener_g;
|
||||
Args* pika_lv_id_register_g;
|
||||
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 11, 5)
|
||||
#error "pikascript version must be greater than 1.11.5"
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 11, 7)
|
||||
#error "pikascript version must be greater than 1.11.7"
|
||||
#endif
|
||||
|
||||
void pika_lvgl_STATE___init__(PikaObj* self) {
|
||||
@ -195,7 +195,7 @@ void pika_lvgl_PALETTE___init__(PikaObj* self) {
|
||||
}
|
||||
|
||||
PikaObj* pika_lvgl_scr_act(PikaObj* self) {
|
||||
PikaObj* new_obj = newNormalObj(New_TinyObj);
|
||||
PikaObj* new_obj = newNormalObj(New_pika_lvgl_lv_obj);
|
||||
lv_obj_t* lv_obj = lv_scr_act();
|
||||
obj_setPtr(new_obj, "lv_obj", lv_obj);
|
||||
return new_obj;
|
||||
@ -215,8 +215,8 @@ void pika_lvgl_obj___init__(PikaObj* self, PikaTuple* parent) {
|
||||
class_defineConstructor(self, "FLAG", "", pika_lvgl_flag_tMethod);
|
||||
return;
|
||||
}
|
||||
if (tuple_getSize(parent) == 1) {
|
||||
parent_obj = tuple_getPtr(parent, 0);
|
||||
if (pikaTuple_getSize(parent) == 1) {
|
||||
parent_obj = pikaTuple_getPtr(parent, 0);
|
||||
lv_obj_t* lv_parent = obj_getPtr(parent_obj, "lv_obj");
|
||||
lv_obj_t* lv_obj = lv_obj_create(lv_parent);
|
||||
obj_setPtr(self, "lv_obj", lv_obj);
|
||||
|
@ -389,6 +389,7 @@ class lv_obj:
|
||||
|
||||
def set_id(self, id: str): ...
|
||||
def get_id(self) -> str: ...
|
||||
def clean(self): ...
|
||||
|
||||
|
||||
class indev_t:
|
||||
|
@ -328,4 +328,9 @@ void pika_lvgl_lv_obj_set_flex_grow(PikaObj *self, int value){
|
||||
lv_obj_set_flex_grow(lv_obj, value);
|
||||
}
|
||||
|
||||
void pika_lvgl_lv_obj_clean(PikaObj *self){
|
||||
lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj");
|
||||
lv_obj_clean(lv_obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
93
package/re/LICENCE
Normal file
93
package/re/LICENCE
Normal file
@ -0,0 +1,93 @@
|
||||
PCRE LICENCE
|
||||
------------
|
||||
|
||||
PCRE is a library of functions to support regular expressions whose syntax
|
||||
and semantics are as close as possible to those of the Perl 5 language.
|
||||
|
||||
Release 8 of PCRE is distributed under the terms of the "BSD" licence, as
|
||||
specified below. The documentation for PCRE, supplied in the "doc"
|
||||
directory, is distributed under the same terms as the software itself. The data
|
||||
in the testdata directory is not copyrighted and is in the public domain.
|
||||
|
||||
The basic library functions are written in C and are freestanding. Also
|
||||
included in the distribution is a set of C++ wrapper functions, and a
|
||||
just-in-time compiler that can be used to optimize pattern matching. These
|
||||
are both optional features that can be omitted when the library is built.
|
||||
|
||||
|
||||
THE BASIC LIBRARY FUNCTIONS
|
||||
---------------------------
|
||||
|
||||
Written by: Philip Hazel
|
||||
Email local part: Philip.Hazel
|
||||
Email domain: gmail.com
|
||||
|
||||
University of Cambridge Computing Service,
|
||||
Cambridge, England.
|
||||
|
||||
Copyright (c) 1997-2021 University of Cambridge
|
||||
All rights reserved.
|
||||
|
||||
|
||||
PCRE JUST-IN-TIME COMPILATION SUPPORT
|
||||
-------------------------------------
|
||||
|
||||
Written by: Zoltan Herczeg
|
||||
Email local part: hzmester
|
||||
Email domain: freemail.hu
|
||||
|
||||
Copyright(c) 2010-2021 Zoltan Herczeg
|
||||
All rights reserved.
|
||||
|
||||
|
||||
STACK-LESS JUST-IN-TIME COMPILER
|
||||
--------------------------------
|
||||
|
||||
Written by: Zoltan Herczeg
|
||||
Email local part: hzmester
|
||||
Email domain: freemail.hu
|
||||
|
||||
Copyright(c) 2009-2021 Zoltan Herczeg
|
||||
All rights reserved.
|
||||
|
||||
|
||||
THE C++ WRAPPER FUNCTIONS
|
||||
-------------------------
|
||||
|
||||
Contributed by: Google Inc.
|
||||
|
||||
Copyright (c) 2007-2012, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
|
||||
THE "BSD" LICENCE
|
||||
-----------------
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the University of Cambridge nor the name of Google
|
||||
Inc. nor the names of their contributors may be used to endorse or
|
||||
promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
End
|
@ -97,7 +97,7 @@ int *re_fullmatch2(pcre *re, const char *s, int len, int *out_vec_number, int op
|
||||
|
||||
if (!vec)
|
||||
goto e_er;
|
||||
opt &= ~PCRE_MULTILINE;
|
||||
// opt &= ~PCRE_MULTILINE;
|
||||
match:
|
||||
rc = pcre_exec(re, NULL, s, len, start_offset, 0, vec, group_n);
|
||||
if (rc == PCRE_ERROR_NOMATCH)
|
||||
|
@ -24,14 +24,14 @@
|
||||
}
|
||||
|
||||
#define tu_getNew(name, obj_name) \
|
||||
PikaTuple *name = New_tuple(); \
|
||||
PikaTuple *name = New_pikaTuple(); \
|
||||
Any obj_name = newNormalObj(New_PikaStdData_Tuple); \
|
||||
obj_setPtr(obj_name, "list", name);
|
||||
|
||||
#define tu_append(tup, val, type) \
|
||||
{ \
|
||||
Arg *_arg = arg_new##type(val); \
|
||||
list_append(&(tup)->super, _arg); \
|
||||
pikaList_append(&(tup)->super, _arg); \
|
||||
arg_deinit(_arg); \
|
||||
}
|
||||
#define li_append(list, val, type) \
|
||||
@ -167,10 +167,10 @@ char *re_sub(PikaObj *self,
|
||||
{
|
||||
int flags = PCRE_UTF8;
|
||||
int count = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -180,7 +180,7 @@ char *re_sub(PikaObj *self,
|
||||
}
|
||||
if (argn >= 2)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 1);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 1);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -228,10 +228,10 @@ PikaObj *re_subn(PikaObj *self,
|
||||
{
|
||||
int flags = PCRE_UTF8;
|
||||
int count = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -241,7 +241,7 @@ PikaObj *re_subn(PikaObj *self,
|
||||
}
|
||||
if (argn >= 2)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 1);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 1);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -285,10 +285,10 @@ PikaObj *re_split(PikaObj *self, char *pattern, char *subject, PikaTuple *val)
|
||||
{
|
||||
int flags = PCRE_UTF8;
|
||||
int max_split = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -298,7 +298,7 @@ PikaObj *re_split(PikaObj *self, char *pattern, char *subject, PikaTuple *val)
|
||||
}
|
||||
if (argn >= 2)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 1);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 1);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -385,10 +385,10 @@ void re_Match___init__args(PikaObj *self, char *sub, int *vec, int ven)
|
||||
char *re_Match_group(PikaObj *self, PikaTuple *val)
|
||||
{
|
||||
int n = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -452,7 +452,7 @@ PikaObj *re_Match_groups(PikaObj *self)
|
||||
{
|
||||
str_arg1 = arg_newStr("");
|
||||
}
|
||||
list_append(&(tup)->super, str_arg1);
|
||||
pikaList_append(&(tup)->super, str_arg1);
|
||||
arg_deinit(str_arg1);
|
||||
}
|
||||
return tup_obj;
|
||||
@ -460,10 +460,10 @@ PikaObj *re_Match_groups(PikaObj *self)
|
||||
PikaObj *re_Match_span(PikaObj *self, PikaTuple *val)
|
||||
{
|
||||
int group_n = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -599,10 +599,10 @@ char *re_Pattern_sub(PikaObj *self, char *repl, char *subjet, PikaTuple *val)
|
||||
{
|
||||
int flags = 0;
|
||||
int count = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -612,7 +612,7 @@ char *re_Pattern_sub(PikaObj *self, char *repl, char *subjet, PikaTuple *val)
|
||||
}
|
||||
if (argn >= 2)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 1);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 1);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -664,10 +664,10 @@ PikaObj *re_Pattern_subn(PikaObj *self, char *repl, char *subjet, PikaTuple *val
|
||||
return NULL;
|
||||
int flags = 0;
|
||||
int count = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -677,7 +677,7 @@ PikaObj *re_Pattern_subn(PikaObj *self, char *repl, char *subjet, PikaTuple *val
|
||||
}
|
||||
if (argn >= 2)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 1);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 1);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -702,10 +702,10 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
|
||||
pcre *re = obj_getPtr(self, "_re");
|
||||
int flags = PCRE_UTF8;
|
||||
int max_split = 0;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -715,7 +715,7 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
|
||||
}
|
||||
if (argn >= 2)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 1);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 1);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
@ -736,10 +736,10 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
|
||||
int _get_flags(PikaTuple *val)
|
||||
{
|
||||
int flags = PCRE_UTF8;
|
||||
int argn = tuple_getSize(val);
|
||||
int argn = pikaTuple_getSize(val);
|
||||
if (argn >= 1)
|
||||
{
|
||||
Arg *arg_i = tuple_getArg(val, 0);
|
||||
Arg *arg_i = pikaTuple_getArg(val, 0);
|
||||
if (arg_getType(arg_i) != ARG_TYPE_INT)
|
||||
{
|
||||
return -1;
|
||||
@ -936,7 +936,7 @@ PikaObj *__findall(void *pattern__or__re,
|
||||
b = malloc(length + 1);
|
||||
if (!b)
|
||||
goto e_er;
|
||||
tu = New_tuple();
|
||||
tu = New_pikaTuple();
|
||||
|
||||
for (int j = 1; j < brackets; j++)
|
||||
{
|
||||
@ -987,7 +987,7 @@ PikaObj *__subn(void *pattern__or__re,
|
||||
}
|
||||
if (s == subjet)
|
||||
{
|
||||
PikaTuple *yup = New_tuple();
|
||||
PikaTuple *yup = New_pikaTuple();
|
||||
tu_append(yup, s, Str);
|
||||
tu_append(yup, 0, Int);
|
||||
|
||||
@ -996,7 +996,7 @@ PikaObj *__subn(void *pattern__or__re,
|
||||
return tuple_obj;
|
||||
}
|
||||
|
||||
PikaTuple *yup = New_tuple();
|
||||
PikaTuple *yup = New_pikaTuple();
|
||||
tu_append(yup, s, Str);
|
||||
free(s);
|
||||
|
||||
|
@ -1,15 +1,13 @@
|
||||
#include "requests.h"
|
||||
#include "requests_Response.h"
|
||||
#include "_requests.h"
|
||||
#include <ctype.h>
|
||||
#include "_requests_Response.h"
|
||||
#include "webclient.h"
|
||||
|
||||
#define GET_HEADER_BUFSZ 1024
|
||||
#define GET_RESP_BUFSZ 1024
|
||||
|
||||
PikaObj* requests_request(PikaObj* self,
|
||||
char* method,
|
||||
char* url,
|
||||
PikaDict* kwargs) {
|
||||
PikaObj* response = newNormalObj(New_requests_Response);
|
||||
PikaObj* _requests_request(PikaObj* self, char* method, char* url) {
|
||||
PikaObj* response = newNormalObj(New__requests_Response);
|
||||
obj_setStr(response, "url", url);
|
||||
|
||||
struct webclient_session* session = RT_NULL;
|
||||
@ -88,10 +86,31 @@ __exit:
|
||||
return response;
|
||||
}
|
||||
|
||||
PikaObj* requests_get(PikaObj* self, char* url, PikaDict* kwargs) {
|
||||
return requests_request(self, "GET", url, kwargs);
|
||||
char to_hex(char code) {
|
||||
static char hex[] = "0123456789abcdef";
|
||||
return hex[code & 15];
|
||||
}
|
||||
|
||||
void requests___del__(PikaObj* self) {}
|
||||
char* _requests_urlencode(PikaObj* self, char* s) {
|
||||
obj_setBytes(self, "encodebuff", NULL, strlen(s) * 3 + 1);
|
||||
char* result = (char*)obj_getBytes(self, "encodebuff");
|
||||
char* p = result;
|
||||
while (*s) {
|
||||
if (isalnum(*s) || *s == '-' || *s == '_' || *s == '.' || *s == '~') {
|
||||
*p++ = *s;
|
||||
} else if (*s == ' ') {
|
||||
*p++ = '+';
|
||||
} else {
|
||||
*p++ = '%';
|
||||
*p++ = to_hex(*s >> 4);
|
||||
*p++ = to_hex(*s & 0xf);
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*p = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
void requests___init__(PikaObj* self) {}
|
||||
void _requests___del__(PikaObj* self) {}
|
||||
|
||||
void _requests___init__(PikaObj* self) {}
|
@ -8,10 +8,9 @@ class Response:
|
||||
def json(self) -> dict: ...
|
||||
|
||||
|
||||
def request(method: str, url: str, **kwargs) -> Response: ...
|
||||
def request(method: str, url: str) -> Response: ...
|
||||
|
||||
|
||||
def get(url: str, **kwargs) -> Response: ...
|
||||
def urlencode(s: str) -> str: ...
|
||||
|
||||
|
||||
def __init__(): ...
|
6
package/requests/_requests_Response.c
Normal file
6
package/requests/_requests_Response.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "_requests_Response.h"
|
||||
|
||||
PikaObj* _requests_Response_json(PikaObj* self) {
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
36
package/requests/requests.py
Normal file
36
package/requests/requests.py
Normal file
@ -0,0 +1,36 @@
|
||||
import _requests
|
||||
|
||||
|
||||
class Response(_requests.Response):
|
||||
...
|
||||
|
||||
|
||||
def _append_params_to_url(url: str, params: dict) -> str:
|
||||
if params is None:
|
||||
return url
|
||||
if '?' in url:
|
||||
url += '&'
|
||||
else:
|
||||
url += '?'
|
||||
for k, v in params.items():
|
||||
k = _requests.urlencode(str(k))
|
||||
v = _requests.urlencode(str(v))
|
||||
url += '%s=%s&' % (k, v)
|
||||
return url[:-1]
|
||||
|
||||
|
||||
def request(method: str, url: str, params=None) -> Response:
|
||||
url = _append_params_to_url(url, params)
|
||||
return _requests.request(method, url)
|
||||
|
||||
|
||||
def get(url: str, params=None) -> Response:
|
||||
return request('GET', url, params)
|
||||
|
||||
|
||||
def __init__():
|
||||
_requests.__init__()
|
||||
|
||||
|
||||
def __del__():
|
||||
_requests.__del__()
|
@ -1,6 +0,0 @@
|
||||
#include "requests_Response.h"
|
||||
|
||||
PikaObj* requests_Response_json(PikaObj* self) {
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
@ -72,7 +72,8 @@ releases = [
|
||||
"v1.11.3 7ccd70ffc9f0449c6f4b015681f0057c874bb5d8",
|
||||
"v1.11.4 4cfb0931f92ca9881963b415d5e8cb7bac33f9f8",
|
||||
"v1.11.5 83afef1906204a7e3f9b773aa8b4bdd46cea4ab9",
|
||||
"v1.11.6 338d385be718d8d11f02aa022103a4b4e9404527"
|
||||
"v1.11.6 338d385be718d8d11f02aa022103a4b4e9404527",
|
||||
"v1.11.7 50b995c5e4a5beb02220c989f592affba8a9cf89"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -137,7 +138,8 @@ releases = [
|
||||
"v1.11.3 7ccd70ffc9f0449c6f4b015681f0057c874bb5d8",
|
||||
"v1.11.4 4cfb0931f92ca9881963b415d5e8cb7bac33f9f8",
|
||||
"v1.11.5 83afef1906204a7e3f9b773aa8b4bdd46cea4ab9",
|
||||
"v1.11.6 338d385be718d8d11f02aa022103a4b4e9404527"
|
||||
"v1.11.6 338d385be718d8d11f02aa022103a4b4e9404527",
|
||||
"v1.11.7 50b995c5e4a5beb02220c989f592affba8a9cf89"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -162,7 +164,9 @@ releases = [
|
||||
"v1.10.3 11088f6b4ba3d5b545fe4bfdc8c27ab4fbe01936",
|
||||
"v1.10.4 f09ea25237cd35a27fd071198ff771c8b4a088ad",
|
||||
"v1.11.0 f8b529a956da57d8623247bea594e65469cac1c5",
|
||||
"v1.11.2 95642575a3e17e4c52e28cdbfbef900e02db61e0"
|
||||
"v1.11.2 95642575a3e17e4c52e28cdbfbef900e02db61e0",
|
||||
"v1.11.7 b7112610bb29109fd7268bf7162004561d73daa1",
|
||||
"v1.11.8 58ff9fe16688be2e77ed220604aa8b1271b72d80"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -186,7 +190,10 @@ releases = [ "v0.1.0 cd6dfbbb714228e7e0f147515d58450644e7dadf" ]
|
||||
|
||||
[[packages]]
|
||||
name = "re"
|
||||
releases = [ "v0.1.0 87da4d26d1ebf9525f66e9fe7acd5ea62f9b7f74" ]
|
||||
releases = [
|
||||
"v0.1.0 87da4d26d1ebf9525f66e9fe7acd5ea62f9b7f74",
|
||||
"v0.1.1 728e9dce9ad2c47d5ac16165a583a794043a2e2b"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
name = "socket"
|
||||
@ -242,7 +249,8 @@ releases = [
|
||||
"v0.3.2 ce221cf875ac5c533ceff3905313a8ef2906df75",
|
||||
"v0.3.3 556b3cd6eb8fa1c100f29bd8556ee48a0a60b055",
|
||||
"v0.3.4 fc7871f6ae32e6fd16c9e16587d02f8b93af1b5d",
|
||||
"v0.4.0 e6a839810a5a98dd36a6436259a05ab3e9b8c6c0"
|
||||
"v0.4.0 e6a839810a5a98dd36a6436259a05ab3e9b8c6c0",
|
||||
"v0.4.1 6f5c4bfae50fc5ae347609e58650f2d185171f9f"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -308,7 +316,9 @@ releases = [
|
||||
"v1.2.0 19e644a2ef411aa49016bf106f4be8beeb0827b1",
|
||||
"v1.3.0 9f3a52558338503571b37c034a12219566f27aa2",
|
||||
"v1.3.1 3119a938dac7a723be3775aaaff5bc337a165567",
|
||||
"v1.3.2 55164edbf2ab7e2e9e754663579e3c93040da8fa"
|
||||
"v1.3.2 55164edbf2ab7e2e9e754663579e3c93040da8fa",
|
||||
"v1.4.0 4611a62ecf25c614b516ccef059f0933d822c26c",
|
||||
"v1.5.0 24c8f7644e81d37855472ae5bbe984e32bcf0190"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -351,7 +361,8 @@ releases = [
|
||||
"v1.1.2 0052a28582ac8a85cc48e1d676d9a3be5cb1b93f",
|
||||
"v1.1.3 f755ec10042f4deefef1c5491f5e91a651f71a1b",
|
||||
"v1.2.0 9f3a52558338503571b37c034a12219566f27aa2",
|
||||
"v1.3.0 9d7b155af3260c0fc00be05598c807b71d7cc198"
|
||||
"v1.3.0 9d7b155af3260c0fc00be05598c807b71d7cc198",
|
||||
"v1.4.0 a567e7705f5049ec5bb44b4bcc7497666cb125b3"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
@ -408,13 +419,19 @@ releases = [
|
||||
|
||||
[[packages]]
|
||||
name = "mqtt"
|
||||
releases = [
|
||||
"v0.0.1 04a174a7d3e02d8861124214f5a3551eaab2bfee",
|
||||
]
|
||||
releases = [ "v0.0.1 04a174a7d3e02d8861124214f5a3551eaab2bfee" ]
|
||||
|
||||
[[packages]]
|
||||
name = "requests"
|
||||
releases = [ "v0.0.1 04a174a7d3e02d8861124214f5a3551eaab2bfee" ]
|
||||
|
||||
[[packages]]
|
||||
name = "hashlib"
|
||||
releases = [
|
||||
"v0.0.1 04a174a7d3e02d8861124214f5a3551eaab2bfee",
|
||||
"v1.0.0 ce05a5f03c4bfac536db60fe24f83705a1b58b02",
|
||||
"v1.0.1 a91c3698abce8a6624929243cfb7cc79badaa156"
|
||||
]
|
||||
|
||||
[[packages]]
|
||||
name = "hmac"
|
||||
releases = [ "v1.0.0 ca8fe36d68be16722317860394fdf78c620e3e2d" ]
|
||||
|
@ -17,7 +17,7 @@ PikaObj *__pikaMain;
|
||||
PikaObj *pikaScriptInit(void){
|
||||
__platform_printf("======[pikascript packages installed]======\r\n");
|
||||
pks_printVersion();
|
||||
__platform_printf("PikaStdLib==v1.11.6
|
||||
__platform_printf("PikaStdLib==v1.11.7
|
||||
__platform_printf("pika_lvgl==latest\r\n");
|
||||
__platform_printf("===========================================\r\n");
|
||||
__pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
|
@ -1,3 +1,3 @@
|
||||
pikascript-core==v1.11.6
|
||||
PikaStdLib==v1.11.6
|
||||
pikascript-core==v1.11.7
|
||||
PikaStdLib==v1.11.7
|
||||
pika_lvgl==latest
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
// "--gtest_filter=except.dict"
|
||||
// "--gtest_filter=pikaMain.slice_a90"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
8
port/linux/.vscode/settings.json
vendored
8
port/linux/.vscode/settings.json
vendored
@ -87,7 +87,13 @@
|
||||
"ctype.h": "c",
|
||||
"mqttclient.h": "c",
|
||||
"_mqtt__mqtt.h": "c",
|
||||
"requests_response.h": "c"
|
||||
"requests_response.h": "c",
|
||||
"*.cfg": "c",
|
||||
"pika_hal.h": "c",
|
||||
"__instruction_def.h": "c",
|
||||
"pika_hal_def.h": "c",
|
||||
"pika_hal_table.h": "c",
|
||||
"pika_hal_table_rule.h": "c"
|
||||
},
|
||||
"python.formatting.provider": "autopep8",
|
||||
"C_Cpp.errorSquiggles": "Disabled"
|
||||
|
@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-sign-conversion -Wno-write-strings -Wno-implicit-fallthrough -Wno-sign-compare -Wno-cast-function-type -Wno-unused-function)
|
||||
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-sign-conversion -Wno-write-strings -Wno-implicit-fallthrough -Wno-sign-compare -Wno-cast-function-type -Wno-unused-function -Wno-varargs)
|
||||
OPTION(PIKA_CONFIG_ENABLE "pika config enable" OFF)
|
||||
IF(PIKA_CONFIG_ENABLE)
|
||||
ADD_DEFINITIONS(-DPIKA_CONFIG_ENABLE)
|
||||
|
1
port/linux/nano_lcov.sh
Normal file
1
port/linux/nano_lcov.sh
Normal file
@ -0,0 +1 @@
|
||||
cp config/pika_config_syntax_level_minimal.h config/pika_config.h && sh fast_test.sh && sh lcov.sh
|
@ -1,11 +1,11 @@
|
||||
#设置 BINARY 为项目名IndexProject
|
||||
set(BINARY ${CMAKE_PROJECT_NAME})
|
||||
|
||||
set(CMAKE_C_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations")
|
||||
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.c)
|
||||
set(SOURCES ${SOURCES})
|
||||
|
||||
# support <math.h>
|
||||
link_libraries(m lua5.3 pthread)
|
||||
link_libraries(m lua5.3 pthread mbedcrypto)
|
||||
|
||||
add_library(${BINARY}-core
|
||||
STATIC
|
||||
|
6
port/linux/package/pikascript/_hashlib.pyi
Normal file
6
port/linux/package/pikascript/_hashlib.pyi
Normal file
@ -0,0 +1,6 @@
|
||||
class Hash:
|
||||
def new(self, mode: str, data:any): ...
|
||||
def update(self, data: any): ...
|
||||
def digest(self) -> any: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def copy(self): ...
|
6
port/linux/package/pikascript/_hmac.pyi
Normal file
6
port/linux/package/pikascript/_hmac.pyi
Normal file
@ -0,0 +1,6 @@
|
||||
class HMAC:
|
||||
def new(self, key:any, msg:any, digestmod:str): ...
|
||||
def update(self, msg:any): ...
|
||||
def digest(self) -> any: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def copy(self): ...
|
@ -8,10 +8,9 @@ class Response:
|
||||
def json(self) -> dict: ...
|
||||
|
||||
|
||||
def request(method: str, url: str, **kwargs) -> Response: ...
|
||||
def request(method: str, url: str) -> Response: ...
|
||||
|
||||
|
||||
def get(url: str, **kwargs) -> Response: ...
|
||||
def urlencode(s: str) -> str: ...
|
||||
|
||||
|
||||
def __init__(): ...
|
2
port/linux/package/pikascript/cb_test.py
Normal file
2
port/linux/package/pikascript/cb_test.py
Normal file
@ -0,0 +1,2 @@
|
||||
def test():
|
||||
print('test')
|
43
port/linux/package/pikascript/hashlib.py
Normal file
43
port/linux/package/pikascript/hashlib.py
Normal file
@ -0,0 +1,43 @@
|
||||
import _hashlib
|
||||
|
||||
|
||||
def new(mode: str) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new(mode, None)
|
||||
return hash
|
||||
|
||||
|
||||
def md5(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("md5", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha1(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha1", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha224(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha224", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha256(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha256", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha384(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha384", data)
|
||||
return hash
|
||||
|
||||
|
||||
def sha512(data = None) -> _hashlib.Hash:
|
||||
hash = _hashlib.Hash()
|
||||
hash.new("sha512", data)
|
||||
return hash
|
7
port/linux/package/pikascript/hmac.py
Normal file
7
port/linux/package/pikascript/hmac.py
Normal file
@ -0,0 +1,7 @@
|
||||
import _hmac
|
||||
|
||||
def new(key:any, msg=None, digestmod="hmac-md5") -> _hmac.HMAC:
|
||||
hmac = _hmac.HMAC()
|
||||
hmac.new(key, msg, digestmod)
|
||||
return hmac
|
||||
|
@ -2,8 +2,12 @@ import PikaStdLib, PikaStdDevice, PikaMath, PikaDebug, PikaCV, PikaNN
|
||||
import random, re, modbus, socket, unittest, binascii, ctypes, requests, mqtt
|
||||
import pika_lua, pika_cjson, cjson_test
|
||||
import GTestTask, TempDevTest
|
||||
import cb_test
|
||||
import configparser
|
||||
import test_module1, test_cmodule, test_module4, import_test
|
||||
import hashlib, hmac
|
||||
|
||||
hashlib.sha256(b"123456")
|
||||
|
||||
mem = PikaStdLib.MemChecker()
|
||||
print('hello pikascript!')
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_ADC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_ADC_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "dataStrs.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 10, 4)
|
||||
#error "This library requires PikaScript version 1.10.4 or higher"
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "PikaStdDevice_CAN.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_CAN___init__(PikaObj* self) {}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_GPIO.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
@ -8,6 +9,7 @@ void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isOn", 0);
|
||||
obj_setStr(self, "pull", "none");
|
||||
obj_setInt(self, "id", -999);
|
||||
obj_setPtr(self, "pika_dev", NULL);
|
||||
}
|
||||
|
||||
int PikaStdDevice_GPIO_getId(PikaObj* self) {
|
||||
@ -75,38 +77,70 @@ void PikaStdDevice_GPIO_setPull(PikaObj* self, char* pull) {
|
||||
}
|
||||
}
|
||||
|
||||
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_GPIO, obj_getStr(self, "pin"));
|
||||
if(NULL == dev){
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n", obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) {
|
||||
obj_setStr(self, "pin", pinName);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformLow(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 0;
|
||||
pika_hal_write(dev, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 1;
|
||||
pika_hal_write(dev, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformOff(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
char* mode = obj_getStr(self, "mode");
|
||||
pika_hal_GPIO_config cfg = {0};
|
||||
if(strEqu(mode, "in")){
|
||||
cfg.dir = PIKA_HAL_GPIO_DIR_IN;
|
||||
}else{
|
||||
cfg.dir = PIKA_HAL_GPIO_DIR_OUT;
|
||||
}
|
||||
pika_dev* dev = _get_dev(self);
|
||||
char* pull = obj_getStr(self, "pull");
|
||||
if (strEqu(pull, "up")){
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_UP;
|
||||
}
|
||||
if (strEqu(pull, "down")){
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_DOWN;
|
||||
}
|
||||
if (strEqu(pull, "none")) {
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_NONE;
|
||||
}
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformRead(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 0;
|
||||
pika_hal_read(dev, &val, sizeof(val));
|
||||
obj_setInt(self, "readBuff", val);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "PikaStdDevice_IIC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_IIC_init(PikaObj* self) {
|
||||
obj_setInt(self, "deviceAddr", 0);
|
||||
obj_setStr(self, "SCLpin", "PA0");
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_PWM.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_PWM_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "none");
|
||||
@ -19,20 +20,20 @@ void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) {
|
||||
|
||||
void PikaStdDevice_PWM_setFrequency(PikaObj* self, int freq) {
|
||||
obj_setInt(self, "freq", freq);
|
||||
obj_runNativeMethod(self, "platformSetFrequency",NULL);
|
||||
obj_runNativeMethod(self, "platformSetFrequency", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setDuty(PikaObj* self, pika_float duty) {
|
||||
obj_setFloat(self, "duty", duty);
|
||||
obj_runNativeMethod(self, "platformSetDuty",NULL);
|
||||
obj_runNativeMethod(self, "platformSetDuty", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable",NULL);
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_disable(PikaObj *self){
|
||||
obj_runNativeMethod(self, "platformDisable",NULL);
|
||||
void PikaStdDevice_PWM_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
pika_float PikaStdDevice_PWM_getDuty(PikaObj* self) {
|
||||
@ -53,7 +54,7 @@ void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj *self){
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "PikaStdDevice_SPI.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_SPI___init__(PikaObj* self) {
|
||||
obj_setInt(self, "baudRate", 1000);
|
||||
obj_setInt(self, "id", 0);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_Time.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#if defined(__linux)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@ -17,7 +18,7 @@ void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
|
||||
#endif
|
||||
}
|
||||
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
|
||||
#if defined(__linux)
|
||||
#if defined(__linux)
|
||||
sleep(s);
|
||||
#elif defined(_WIN32)
|
||||
Sleep(s * 1000);
|
||||
@ -42,7 +43,7 @@ void PikaStdDevice_Time_platformGetTick(PikaObj* self) {
|
||||
|
||||
//结构体时间类型定义(来源c标准库corect_wtime.h)
|
||||
//无论是16位整数还是32位整数都满足需求
|
||||
typedef struct _tm{
|
||||
typedef struct _tm {
|
||||
int tm_sec; // seconds after the minute - [0, 60] including leap second
|
||||
int tm_min; // minutes after the hour - [0, 59]
|
||||
int tm_hour; // hours since midnight - [0, 23]
|
||||
@ -137,7 +138,8 @@ pika_float time_time(PikaObj* self) {
|
||||
status_deal(res);
|
||||
} //异常处理
|
||||
//以浮点数返回时间,float
|
||||
return temp_timespec.tv_sec + (pika_float)temp_timespec.tv_nsec / 1000000000;
|
||||
return temp_timespec.tv_sec +
|
||||
(pika_float)temp_timespec.tv_nsec / 1000000000;
|
||||
}
|
||||
|
||||
//标准time_ns()方法,返回以整数表示的从 epoch 开始的纳秒数的时间值。
|
||||
@ -568,9 +570,9 @@ pika_float PikaStdDevice_Time_time(PikaObj* self) {
|
||||
)
|
||||
/* clang-format on */
|
||||
const uint8_t bytes[] = {
|
||||
0x04, 0x00, 0x00, 0x00, /* instruct array size */
|
||||
0x04, 0x00, 0x00, 0x00, /* instruct array size */
|
||||
0x00, 0x82, 0x01, 0x00, /* instruct array */
|
||||
0x11, 0x00, 0x00, 0x00, /* const pool size */
|
||||
0x11, 0x00, 0x00, 0x00, /* const pool size */
|
||||
0x00, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d,
|
||||
0x47, 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x00, /* const pool */
|
||||
};
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include "PikaStdDevice_UART.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_UART_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_disable(PikaObj *self){
|
||||
void PikaStdDevice_UART_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
@ -25,7 +26,7 @@ char* PikaStdDevice_UART_read(PikaObj* self, int length) {
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
|
||||
Arg* PikaStdDevice_UART_readBytes(PikaObj *self, int length){
|
||||
Arg* PikaStdDevice_UART_readBytes(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_runNativeMethod(self, "platformReadBytes", NULL);
|
||||
return arg_copy(obj_getArg(self, "readData"));
|
||||
@ -42,7 +43,7 @@ void PikaStdDevice_UART_write(PikaObj* self, char* data) {
|
||||
obj_runNativeMethod(self, "platformWrite", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_writeBytes(PikaObj *self, uint8_t* data, int length){
|
||||
void PikaStdDevice_UART_writeBytes(PikaObj* self, uint8_t* data, int length) {
|
||||
obj_setBytes(self, "writeData", data, length);
|
||||
obj_runNativeMethod(self, "platformWriteBytes", NULL);
|
||||
}
|
||||
@ -57,14 +58,14 @@ void PikaStdDevice_UART_platformWrite(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformDisable(PikaObj *self){
|
||||
void PikaStdDevice_UART_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformReadBytes(PikaObj *self){
|
||||
void PikaStdDevice_UART_platformReadBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformWriteBytes(PikaObj *self){
|
||||
void PikaStdDevice_UART_platformWriteBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
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