mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-03-15 19:31:43 +00:00
update pikapython kernal, install more packages
ignore -api
This commit is contained in:
parent
a66562ca53
commit
f8853eaa86
162 changed files with 32672 additions and 3119 deletions
1
examples/pikapython/.gitignore
vendored
Normal file
1
examples/pikapython/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
**/pikascript-api
|
|
@ -12,6 +12,16 @@ sdk_add_include_directories(.)
|
|||
sdk_add_include_directories(pikapython/pikascript-core)
|
||||
sdk_add_include_directories(pikapython/pikascript-api)
|
||||
|
||||
sdk_add_compile_definitions(
|
||||
PIKA_CONFIG_ENABLE=1
|
||||
# LWIP_DNS=1
|
||||
LV_LVGL_H_INCLUDE_SIMPLE=1
|
||||
PIKASCRIPT=1
|
||||
)
|
||||
|
||||
sdk_set_main_file(main.c)
|
||||
|
||||
set(APP_LDFLAGS_HEAD "-Wl,--whole-archive")
|
||||
set(APP_LDFLAGS_TAIL "-Wl,--no-whole-archive")
|
||||
|
||||
project(pikapython)
|
||||
|
|
125
examples/pikapython/FreeRTOSConfig.h
Executable file
125
examples/pikapython/FreeRTOSConfig.h
Executable file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
/*-----------------------------------------------------------
|
||||
* Application specific definitions.
|
||||
*
|
||||
* These definitions should be adjusted for your particular hardware and
|
||||
* application requirements.
|
||||
*
|
||||
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
|
||||
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
|
||||
*
|
||||
* See http://www.freertos.org/a00110.html.
|
||||
*----------------------------------------------------------*/
|
||||
#if defined(BL602) || defined(BL702) || defined(BL702L)
|
||||
#define configMTIME_BASE_ADDRESS (0x02000000UL + 0xBFF8UL)
|
||||
#define configMTIMECMP_BASE_ADDRESS (0x02000000UL + 0x4000UL)
|
||||
#else
|
||||
#if __riscv_xlen == 64
|
||||
#define configMTIME_BASE_ADDRESS (0)
|
||||
#define configMTIMECMP_BASE_ADDRESS ((0xE4000000UL) + 0x4000UL)
|
||||
#else
|
||||
#define configMTIME_BASE_ADDRESS ((0xE0000000UL) + 0xBFF8UL)
|
||||
#define configMTIMECMP_BASE_ADDRESS ((0xE0000000UL) + 0x4000UL)
|
||||
#endif
|
||||
#endif
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configCPU_CLOCK_HZ ((uint32_t)(1 * 1000 * 1000))
|
||||
#define configTICK_RATE_HZ (1000)
|
||||
#define configMAX_PRIORITIES (7)
|
||||
#define configMINIMAL_STACK_SIZE ((unsigned short)128) /* Only needs to be this high as some demo tasks also use this constant. In production only the idle task would use this. */
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)128 * 1024)
|
||||
#define configMAX_TASK_NAME_LEN (16)
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configIDLE_SHOULD_YIELD 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 8
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configUSE_MALLOC_FAILED_HOOK 1
|
||||
#define configUSE_APPLICATION_TASK_TAG 1
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
|
||||
#define configUSE_TICKLESS_IDLE 0
|
||||
#define configUSE_POSIX_ERRNO 1
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configMAX_CO_ROUTINE_PRIORITIES (2)
|
||||
|
||||
/* Software timer definitions. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)
|
||||
#define configTIMER_QUEUE_LENGTH 4
|
||||
#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE)
|
||||
/* Task priorities. Allow these to be overridden. */
|
||||
#ifndef uartPRIMARY_PRIORITY
|
||||
#define uartPRIMARY_PRIORITY (configMAX_PRIORITIES - 3)
|
||||
#endif
|
||||
/* Set the following definitions to 1 to include the API function, or zero
|
||||
to exclude the API function. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskCleanUpResources 1
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_eTaskGetState 1
|
||||
#define INCLUDE_xTimerPendFunctionCall 1
|
||||
#define INCLUDE_xTaskAbortDelay 1
|
||||
#define INCLUDE_xTaskGetHandle 1
|
||||
#define INCLUDE_xSemaphoreGetMutexHolder 1
|
||||
/* Normal assert() semantics without relying on the provision of an assert.h
|
||||
header file. */
|
||||
void vApplicationMallocFailedHook(void);
|
||||
void vAssertCalled(void);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define configASSERT(x) \
|
||||
if ((x) == 0) { \
|
||||
printf("file [%s]\r\n", __FILE__); \
|
||||
printf("func [%s]\r\n", __FUNCTION__); \
|
||||
printf("line [%d]\r\n", __LINE__); \
|
||||
printf("%s\r\n", (const char *)(#x)); \
|
||||
vAssertCalled(); \
|
||||
}
|
||||
#if (configUSE_TICKLESS_IDLE != 0)
|
||||
void vApplicationSleep(uint32_t xExpectedIdleTime);
|
||||
#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vApplicationSleep(xExpectedIdleTime)
|
||||
#endif
|
||||
// #define portUSING_MPU_WRAPPERS
|
||||
#endif /* FREERTOS_CONFIG_H */
|
|
@ -3,8 +3,9 @@ BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../..
|
|||
|
||||
export BL_SDK_BASE
|
||||
|
||||
CHIP ?= bl602
|
||||
BOARD ?= bl602dk
|
||||
CHIP ?= bl808
|
||||
BOARD ?= bl808dk
|
||||
CPU_ID ?=m0
|
||||
CROSS_COMPILE ?= riscv64-unknown-elf-
|
||||
|
||||
# add custom cmake definition
|
||||
|
|
780
examples/pikapython/lv_conf.h
Executable file
780
examples/pikapython/lv_conf.h
Executable file
|
@ -0,0 +1,780 @@
|
|||
/**
|
||||
* @file lv_conf.h
|
||||
* Configuration file for v8.2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copy this file as `lv_conf.h`
|
||||
* 1. simply next to the `lvgl` folder
|
||||
* 2. or any other places and
|
||||
* - define `LV_CONF_INCLUDE_SIMPLE`
|
||||
* - add the path as include path
|
||||
*/
|
||||
|
||||
/* clang-format off */
|
||||
#if 1 /*Set it to "1" to enable content*/
|
||||
|
||||
#ifndef LV_CONF_H
|
||||
#define LV_CONF_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lcd.h"
|
||||
|
||||
/*====================
|
||||
COLOR SETTINGS
|
||||
*====================*/
|
||||
|
||||
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
|
||||
#define LV_COLOR_DEPTH LCD_COLOR_DEPTH
|
||||
|
||||
/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/
|
||||
#define LV_COLOR_16_SWAP 0
|
||||
|
||||
/*Enable features to draw on transparent background.
|
||||
*It's required if opa, and transform_* style properties are used.
|
||||
*Can be also used if the UI is above another layer, e.g. an OSD menu or video player.*/
|
||||
#define LV_COLOR_SCREEN_TRANSP 1
|
||||
|
||||
/* Adjust color mix functions rounding. GPUs might calculate color mix (blending) differently.
|
||||
* 0: round down, 64: round up from x.75, 128: round up from half, 192: round up from x.25, 254: round up */
|
||||
#define LV_COLOR_MIX_ROUND_OFS 0
|
||||
|
||||
/*Images pixels with this color will not be drawn if they are chroma keyed)*/
|
||||
#define LV_COLOR_CHROMA_KEY lv_color_hex(0x00ff00) /*pure green*/
|
||||
|
||||
/*=========================
|
||||
MEMORY SETTINGS
|
||||
*=========================*/
|
||||
|
||||
/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
|
||||
#define LV_MEM_CUSTOM 1
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
|
||||
#define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/
|
||||
|
||||
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
|
||||
#define LV_MEM_ADR 0 /*0: unused*/
|
||||
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
|
||||
#if LV_MEM_ADR == 0
|
||||
#undef LV_MEM_POOL_INCLUDE
|
||||
#undef LV_MEM_POOL_ALLOC
|
||||
#endif
|
||||
|
||||
#else /*LV_MEM_CUSTOM*/
|
||||
#define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
|
||||
#define LV_MEM_CUSTOM_ALLOC malloc
|
||||
#define LV_MEM_CUSTOM_FREE free
|
||||
#define LV_MEM_CUSTOM_REALLOC realloc
|
||||
#endif /*LV_MEM_CUSTOM*/
|
||||
|
||||
/*Number of the intermediate memory buffer used during rendering and other internal processing mechanisms.
|
||||
*You will see an error log message if there wasn't enough buffers. */
|
||||
#define LV_MEM_BUF_MAX_NUM 16
|
||||
|
||||
/*Use the standard `memcpy` and `memset` instead of LVGL's own functions. (Might or might not be faster).*/
|
||||
#define LV_MEMCPY_MEMSET_STD 0
|
||||
|
||||
/*====================
|
||||
HAL SETTINGS
|
||||
*====================*/
|
||||
|
||||
/*Default display refresh period. LVG will redraw changed areas with this period time*/
|
||||
#define LV_DISP_DEF_REFR_PERIOD 20 /*[ms]*/
|
||||
|
||||
/*Input device read period in milliseconds*/
|
||||
#define LV_INDEV_DEF_READ_PERIOD 20 /*[ms]*/
|
||||
|
||||
/*Use a custom tick source that tells the elapsed time in milliseconds.
|
||||
*It removes the need to manually update the tick with `lv_tick_inc()`)*/
|
||||
#define LV_TICK_CUSTOM 1
|
||||
#if LV_TICK_CUSTOM
|
||||
#define LV_TICK_CUSTOM_INCLUDE "bflb_mtimer.h" /*Header for the system time function*/
|
||||
#define LV_TICK_CUSTOM_SYS_TIME_EXPR ((uint32_t)bflb_mtimer_get_time_ms()) /*Expression evaluating to current system time in ms*/
|
||||
#endif /*LV_TICK_CUSTOM*/
|
||||
|
||||
/*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings.
|
||||
*(Not so important, you can adjust it to modify default sizes and spaces)*/
|
||||
#define LV_DPI_DEF 130 /*[px/inch]*/
|
||||
|
||||
/*=======================
|
||||
* FEATURE CONFIGURATION
|
||||
*=======================*/
|
||||
|
||||
/*-------------
|
||||
* Drawing
|
||||
*-----------*/
|
||||
|
||||
/*Enable complex draw engine.
|
||||
*Required to draw shadow, gradient, rounded corners, circles, arc, skew lines, image transformations or any masks*/
|
||||
#define LV_DRAW_COMPLEX 1
|
||||
#if LV_DRAW_COMPLEX != 0
|
||||
|
||||
/*Allow buffering some shadow calculation.
|
||||
*LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer, where shadow size is `shadow_width + radius`
|
||||
*Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost*/
|
||||
#define LV_SHADOW_CACHE_SIZE 0
|
||||
|
||||
/* Set number of maximally cached circle data.
|
||||
* The circumference of 1/4 circle are saved for anti-aliasing
|
||||
* radius * 4 bytes are used per circle (the most often used radiuses are saved)
|
||||
* 0: to disable caching */
|
||||
#define LV_CIRCLE_CACHE_SIZE 4
|
||||
#endif /*LV_DRAW_COMPLEX*/
|
||||
|
||||
/**
|
||||
* "Simple layers" are used when a widget has `style_opa < 255` to buffer the widget into a layer
|
||||
* and blend it as an image with the given opacity.
|
||||
* Note that `bg_opa`, `text_opa` etc don't require buffering into layer)
|
||||
* The widget can be buffered in smaller chunks to avoid using large buffers.
|
||||
*
|
||||
* - LV_LAYER_SIMPLE_BUF_SIZE: [bytes] the optimal target buffer size. LVGL will try to allocate it
|
||||
* - LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE: [bytes] used if `LV_LAYER_SIMPLE_BUF_SIZE` couldn't be allocated.
|
||||
*
|
||||
* Both buffer sizes are in bytes.
|
||||
* "Transformed layers" (where transform_angle/zoom properties are used) use larger buffers
|
||||
* and can't be drawn in chunks. So these settings affects only widgets with opacity.
|
||||
*/
|
||||
#define LV_LAYER_SIMPLE_BUF_SIZE (24 * 1024)
|
||||
#define LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE (3 * 1024)
|
||||
|
||||
/*Default image cache size. Image caching keeps the images opened.
|
||||
*If only the built-in image formats are used there is no real advantage of caching. (I.e. if no new image decoder is added)
|
||||
*With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
|
||||
*However the opened images might consume additional RAM.
|
||||
*0: to disable caching*/
|
||||
#define LV_IMG_CACHE_DEF_SIZE 0
|
||||
|
||||
/*Number of stops allowed per gradient. Increase this to allow more stops.
|
||||
*This adds (sizeof(lv_color_t) + 1) bytes per additional stop*/
|
||||
#define LV_GRADIENT_MAX_STOPS 2
|
||||
|
||||
/*Default gradient buffer size.
|
||||
*When LVGL calculates the gradient "maps" it can save them into a cache to avoid calculating them again.
|
||||
*LV_GRAD_CACHE_DEF_SIZE sets the size of this cache in bytes.
|
||||
*If the cache is too small the map will be allocated only while it's required for the drawing.
|
||||
*0 mean no caching.*/
|
||||
#define LV_GRAD_CACHE_DEF_SIZE 0
|
||||
|
||||
/*Allow dithering the gradients (to achieve visual smooth color gradients on limited color depth display)
|
||||
*LV_DITHER_GRADIENT implies allocating one or two more lines of the object's rendering surface
|
||||
*The increase in memory consumption is (32 bits * object width) plus 24 bits * object width if using error diffusion */
|
||||
#define LV_DITHER_GRADIENT 0
|
||||
#if LV_DITHER_GRADIENT
|
||||
/*Add support for error diffusion dithering.
|
||||
*Error diffusion dithering gets a much better visual result, but implies more CPU consumption and memory when drawing.
|
||||
*The increase in memory consumption is (24 bits * object's width)*/
|
||||
#define LV_DITHER_ERROR_DIFFUSION 0
|
||||
#endif
|
||||
|
||||
/*Maximum buffer size to allocate for rotation.
|
||||
*Only used if software rotation is enabled in the display driver.*/
|
||||
#define LV_DISP_ROT_MAX_BUF (10*1024)
|
||||
|
||||
/*-------------
|
||||
* GPU
|
||||
*-----------*/
|
||||
|
||||
/*Use Arm's 2D acceleration library Arm-2D */
|
||||
#define LV_USE_GPU_ARM2D 0
|
||||
|
||||
/*Use STM32's DMA2D (aka Chrom Art) GPU*/
|
||||
#define LV_USE_GPU_STM32_DMA2D 0
|
||||
#if LV_USE_GPU_STM32_DMA2D
|
||||
/*Must be defined to include path of CMSIS header of target processor
|
||||
e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
|
||||
#define LV_GPU_DMA2D_CMSIS_INCLUDE
|
||||
#endif
|
||||
|
||||
/*Use SWM341's DMA2D GPU*/
|
||||
#define LV_USE_GPU_SWM341_DMA2D 0
|
||||
#if LV_USE_GPU_SWM341_DMA2D
|
||||
#define LV_GPU_SWM341_DMA2D_INCLUDE "SWM341.h"
|
||||
#endif
|
||||
|
||||
/*Use NXP's PXP GPU iMX RTxxx platforms*/
|
||||
#define LV_USE_GPU_NXP_PXP 0
|
||||
#if LV_USE_GPU_NXP_PXP
|
||||
/*1: Add default bare metal and FreeRTOS interrupt handling routines for PXP (lv_gpu_nxp_pxp_osa.c)
|
||||
* and call lv_gpu_nxp_pxp_init() automatically during lv_init(). Note that symbol SDK_OS_FREE_RTOS
|
||||
* has to be defined in order to use FreeRTOS OSA, otherwise bare-metal implementation is selected.
|
||||
*0: lv_gpu_nxp_pxp_init() has to be called manually before lv_init()
|
||||
*/
|
||||
#define LV_USE_GPU_NXP_PXP_AUTO_INIT 0
|
||||
#endif
|
||||
|
||||
/*Use NXP's VG-Lite GPU iMX RTxxx platforms*/
|
||||
#define LV_USE_GPU_NXP_VG_LITE 0
|
||||
|
||||
/*Use SDL renderer API*/
|
||||
#define LV_USE_GPU_SDL 0
|
||||
#if LV_USE_GPU_SDL
|
||||
#define LV_GPU_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
/*Texture cache size, 8MB by default*/
|
||||
#define LV_GPU_SDL_LRU_SIZE (1024 * 1024 * 8)
|
||||
/*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/
|
||||
#define LV_GPU_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
|
||||
#endif
|
||||
|
||||
#if (defined(BL808) || defined(BL606P))
|
||||
|
||||
#define LV_USE_GPU_LB_DMA2D 0
|
||||
#define LV_USE_GPU_LB_DMA2D_AUTO_INIT 1
|
||||
|
||||
#if defined(CPU_D0) && (LV_COLOR_DEPTH != 16 || LV_COLOR_SCREEN_TRANSP == 0)
|
||||
#define LV_USE_RV_VECTOR_EXT 1
|
||||
#else
|
||||
#define LV_USE_RV_VECTOR_EXT 0
|
||||
#endif
|
||||
#else
|
||||
#define LV_USE_GPU_LB_DMA2D 0
|
||||
#define LV_USE_GPU_LB_DMA2D_AUTO_INIT 0
|
||||
#define LV_USE_RV_VECTOR_EXT 0
|
||||
|
||||
#endif
|
||||
|
||||
/*-------------
|
||||
* Logging
|
||||
*-----------*/
|
||||
|
||||
/*Enable the log module*/
|
||||
#define LV_USE_LOG 1
|
||||
#if LV_USE_LOG
|
||||
|
||||
/*How important log should be added:
|
||||
*LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
|
||||
*LV_LOG_LEVEL_INFO Log important events
|
||||
*LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem
|
||||
*LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
|
||||
*LV_LOG_LEVEL_USER Only logs added by the user
|
||||
*LV_LOG_LEVEL_NONE Do not log anything*/
|
||||
#define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
|
||||
|
||||
/*1: Print the log with 'printf';
|
||||
*0: User need to register a callback with `lv_log_register_print_cb()`*/
|
||||
#define LV_LOG_PRINTF 0
|
||||
|
||||
/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
|
||||
#define LV_LOG_TRACE_MEM 1
|
||||
#define LV_LOG_TRACE_TIMER 1
|
||||
#define LV_LOG_TRACE_INDEV 1
|
||||
#define LV_LOG_TRACE_DISP_REFR 1
|
||||
#define LV_LOG_TRACE_EVENT 1
|
||||
#define LV_LOG_TRACE_OBJ_CREATE 1
|
||||
#define LV_LOG_TRACE_LAYOUT 1
|
||||
#define LV_LOG_TRACE_ANIM 1
|
||||
|
||||
#endif /*LV_USE_LOG*/
|
||||
|
||||
/*-------------
|
||||
* Asserts
|
||||
*-----------*/
|
||||
|
||||
/*Enable asserts if an operation is failed or an invalid data is found.
|
||||
*If LV_USE_LOG is enabled an error message will be printed on failure*/
|
||||
#define LV_USE_ASSERT_NULL 1 /*Check if the parameter is NULL. (Very fast, recommended)*/
|
||||
#define LV_USE_ASSERT_MALLOC 1 /*Checks is the memory is successfully allocated or no. (Very fast, recommended)*/
|
||||
#define LV_USE_ASSERT_STYLE 0 /*Check if the styles are properly initialized. (Very fast, recommended)*/
|
||||
#define LV_USE_ASSERT_MEM_INTEGRITY 0 /*Check the integrity of `lv_mem` after critical operations. (Slow)*/
|
||||
#define LV_USE_ASSERT_OBJ 0 /*Check the object's type and existence (e.g. not deleted). (Slow)*/
|
||||
|
||||
/*Add a custom handler when assert happens e.g. to restart the MCU*/
|
||||
#define LV_ASSERT_HANDLER_INCLUDE <stdint.h>
|
||||
#define LV_ASSERT_HANDLER while(1); /*Halt by default*/
|
||||
|
||||
/*-------------
|
||||
* Others
|
||||
*-----------*/
|
||||
|
||||
/*1: Show CPU usage and FPS count*/
|
||||
#define LV_USE_PERF_MONITOR 1
|
||||
#if LV_USE_PERF_MONITOR
|
||||
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
|
||||
#endif
|
||||
|
||||
/*1: Show the used memory and the memory fragmentation
|
||||
* Requires LV_MEM_CUSTOM = 0*/
|
||||
#define LV_USE_MEM_MONITOR 0
|
||||
#if LV_USE_MEM_MONITOR
|
||||
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
|
||||
#endif
|
||||
|
||||
/*1: Draw random colored rectangles over the redrawn areas*/
|
||||
#define LV_USE_REFR_DEBUG 0
|
||||
|
||||
/*Change the built in (v)snprintf functions*/
|
||||
#define LV_SPRINTF_CUSTOM 0
|
||||
#if LV_SPRINTF_CUSTOM
|
||||
#define LV_SPRINTF_INCLUDE <stdio.h>
|
||||
#define lv_snprintf snprintf
|
||||
#define lv_vsnprintf vsnprintf
|
||||
#else /*LV_SPRINTF_CUSTOM*/
|
||||
#define LV_SPRINTF_USE_FLOAT 0
|
||||
#endif /*LV_SPRINTF_CUSTOM*/
|
||||
|
||||
#define LV_USE_USER_DATA 1
|
||||
|
||||
/*Garbage Collector settings
|
||||
*Used if lvgl is bound to higher level language and the memory is managed by that language*/
|
||||
#define LV_ENABLE_GC 0
|
||||
#if LV_ENABLE_GC != 0
|
||||
#define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
|
||||
#endif /*LV_ENABLE_GC*/
|
||||
|
||||
/*=====================
|
||||
* COMPILER SETTINGS
|
||||
*====================*/
|
||||
|
||||
/*For big endian systems set to 1*/
|
||||
#define LV_BIG_ENDIAN_SYSTEM 0
|
||||
|
||||
/*Define a custom attribute to `lv_tick_inc` function*/
|
||||
#define LV_ATTRIBUTE_TICK_INC
|
||||
|
||||
/*Define a custom attribute to `lv_timer_handler` function*/
|
||||
#define LV_ATTRIBUTE_TIMER_HANDLER
|
||||
|
||||
/*Define a custom attribute to `lv_disp_flush_ready` function*/
|
||||
#define LV_ATTRIBUTE_FLUSH_READY
|
||||
|
||||
/*Required alignment size for buffers*/
|
||||
#define LV_ATTRIBUTE_MEM_ALIGN_SIZE 1
|
||||
|
||||
/*Will be added where memories needs to be aligned (with -Os data might not be aligned to boundary by default).
|
||||
* E.g. __attribute__((aligned(4)))*/
|
||||
#define LV_ATTRIBUTE_MEM_ALIGN
|
||||
|
||||
/*Attribute to mark large constant arrays for example font's bitmaps*/
|
||||
#define LV_ATTRIBUTE_LARGE_CONST
|
||||
|
||||
/*Compiler prefix for a big array declaration in RAM*/
|
||||
#define LV_ATTRIBUTE_LARGE_RAM_ARRAY
|
||||
|
||||
/*Place performance critical functions into a faster memory (e.g RAM)*/
|
||||
#define LV_ATTRIBUTE_FAST_MEM
|
||||
|
||||
/*Prefix variables that are used in GPU accelerated operations, often these need to be placed in RAM sections that are DMA accessible*/
|
||||
#define LV_ATTRIBUTE_DMA
|
||||
|
||||
/*Export integer constant to binding. This macro is used with constants in the form of LV_<CONST> that
|
||||
*should also appear on LVGL binding API such as Micropython.*/
|
||||
#define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning /*The default value just prevents GCC warning*/
|
||||
|
||||
/*Extend the default -32k..32k coordinate range to -4M..4M by using int32_t for coordinates instead of int16_t*/
|
||||
#define LV_USE_LARGE_COORD 0
|
||||
|
||||
/*==================
|
||||
* FONT USAGE
|
||||
*===================*/
|
||||
|
||||
/*Montserrat fonts with ASCII range and some symbols using bpp = 4
|
||||
*https://fonts.google.com/specimen/Montserrat*/
|
||||
#define LV_FONT_MONTSERRAT_8 0
|
||||
#define LV_FONT_MONTSERRAT_10 0
|
||||
#define LV_FONT_MONTSERRAT_12 0
|
||||
#define LV_FONT_MONTSERRAT_14 1
|
||||
#define LV_FONT_MONTSERRAT_16 0
|
||||
#define LV_FONT_MONTSERRAT_18 0
|
||||
#define LV_FONT_MONTSERRAT_20 0
|
||||
#define LV_FONT_MONTSERRAT_22 0
|
||||
#define LV_FONT_MONTSERRAT_24 0
|
||||
#define LV_FONT_MONTSERRAT_26 0
|
||||
#define LV_FONT_MONTSERRAT_28 0
|
||||
#define LV_FONT_MONTSERRAT_30 0
|
||||
#define LV_FONT_MONTSERRAT_32 0
|
||||
#define LV_FONT_MONTSERRAT_34 0
|
||||
#define LV_FONT_MONTSERRAT_36 0
|
||||
#define LV_FONT_MONTSERRAT_38 0
|
||||
#define LV_FONT_MONTSERRAT_40 0
|
||||
#define LV_FONT_MONTSERRAT_42 0
|
||||
#define LV_FONT_MONTSERRAT_44 0
|
||||
#define LV_FONT_MONTSERRAT_46 0
|
||||
#define LV_FONT_MONTSERRAT_48 0
|
||||
|
||||
/*Demonstrate special features*/
|
||||
#define LV_FONT_MONTSERRAT_12_SUBPX 0
|
||||
#define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /*bpp = 3*/
|
||||
#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /*Hebrew, Arabic, Persian letters and all their forms*/
|
||||
#define LV_FONT_SIMSUN_16_CJK 0 /*1000 most common CJK radicals*/
|
||||
|
||||
/*Pixel perfect monospace fonts*/
|
||||
#define LV_FONT_UNSCII_8 0
|
||||
#define LV_FONT_UNSCII_16 0
|
||||
|
||||
/*Optionally declare custom fonts here.
|
||||
*You can use these fonts as default font too and they will be available globally.
|
||||
*E.g. #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) LV_FONT_DECLARE(my_font_2)*/
|
||||
#define LV_FONT_CUSTOM_DECLARE
|
||||
|
||||
/*Always set a default font*/
|
||||
#define LV_FONT_DEFAULT &lv_font_montserrat_14
|
||||
|
||||
/*Enable handling large font and/or fonts with a lot of characters.
|
||||
*The limit depends on the font size, font face and bpp.
|
||||
*Compiler error will be triggered if a font needs it.*/
|
||||
#define LV_FONT_FMT_TXT_LARGE 0
|
||||
|
||||
/*Enables/disables support for compressed fonts.*/
|
||||
#define LV_USE_FONT_COMPRESSED 1
|
||||
|
||||
/*Enable subpixel rendering*/
|
||||
#define LV_USE_FONT_SUBPX 1
|
||||
#if LV_USE_FONT_SUBPX
|
||||
/*Set the pixel order of the display. Physical order of RGB channels. Doesn't matter with "normal" fonts.*/
|
||||
#define LV_FONT_SUBPX_BGR 0 /*0: RGB; 1:BGR order*/
|
||||
#endif
|
||||
|
||||
/*=================
|
||||
* TEXT SETTINGS
|
||||
*=================*/
|
||||
|
||||
/**
|
||||
* Select a character encoding for strings.
|
||||
* Your IDE or editor should have the same character encoding
|
||||
* - LV_TXT_ENC_UTF8
|
||||
* - LV_TXT_ENC_ASCII
|
||||
*/
|
||||
#define LV_TXT_ENC LV_TXT_ENC_UTF8
|
||||
|
||||
/*Can break (wrap) texts on these chars*/
|
||||
#define LV_TXT_BREAK_CHARS " ,.;:-_"
|
||||
|
||||
/*If a word is at least this long, will break wherever "prettiest"
|
||||
*To disable, set to a value <= 0*/
|
||||
#define LV_TXT_LINE_BREAK_LONG_LEN 0
|
||||
|
||||
/*Minimum number of characters in a long word to put on a line before a break.
|
||||
*Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/
|
||||
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3
|
||||
|
||||
/*Minimum number of characters in a long word to put on a line after a break.
|
||||
*Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/
|
||||
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3
|
||||
|
||||
/*The control character to use for signalling text recoloring.*/
|
||||
#define LV_TXT_COLOR_CMD "#"
|
||||
|
||||
/*Support bidirectional texts. Allows mixing Left-to-Right and Right-to-Left texts.
|
||||
*The direction will be processed according to the Unicode Bidirectional Algorithm:
|
||||
*https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/
|
||||
#define LV_USE_BIDI 0
|
||||
#if LV_USE_BIDI
|
||||
/*Set the default direction. Supported values:
|
||||
*`LV_BASE_DIR_LTR` Left-to-Right
|
||||
*`LV_BASE_DIR_RTL` Right-to-Left
|
||||
*`LV_BASE_DIR_AUTO` detect texts base direction*/
|
||||
#define LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_AUTO
|
||||
#endif
|
||||
|
||||
/*Enable Arabic/Persian processing
|
||||
*In these languages characters should be replaced with an other form based on their position in the text*/
|
||||
#define LV_USE_ARABIC_PERSIAN_CHARS 0
|
||||
|
||||
/*==================
|
||||
* WIDGET USAGE
|
||||
*================*/
|
||||
|
||||
/*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/
|
||||
|
||||
#define LV_USE_ARC 1
|
||||
|
||||
#define LV_USE_BAR 1
|
||||
|
||||
#define LV_USE_BTN 1
|
||||
|
||||
#define LV_USE_BTNMATRIX 1
|
||||
|
||||
#define LV_USE_CANVAS 1
|
||||
|
||||
#define LV_USE_CHECKBOX 1
|
||||
|
||||
#define LV_USE_DROPDOWN 1 /*Requires: lv_label*/
|
||||
|
||||
#define LV_USE_IMG 1 /*Requires: lv_label*/
|
||||
|
||||
#define LV_USE_LABEL 1
|
||||
#if LV_USE_LABEL
|
||||
#define LV_LABEL_TEXT_SELECTION 1 /*Enable selecting text of the label*/
|
||||
#define LV_LABEL_LONG_TXT_HINT 1 /*Store some extra info in labels to speed up drawing of very long texts*/
|
||||
#endif
|
||||
|
||||
#define LV_USE_LINE 1
|
||||
|
||||
#define LV_USE_ROLLER 1 /*Requires: lv_label*/
|
||||
#if LV_USE_ROLLER
|
||||
#define LV_ROLLER_INF_PAGES 7 /*Number of extra "pages" when the roller is infinite*/
|
||||
#endif
|
||||
|
||||
#define LV_USE_SLIDER 1 /*Requires: lv_bar*/
|
||||
|
||||
#define LV_USE_SWITCH 1
|
||||
|
||||
#define LV_USE_TEXTAREA 1 /*Requires: lv_label*/
|
||||
#if LV_USE_TEXTAREA != 0
|
||||
#define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/
|
||||
#endif
|
||||
|
||||
#define LV_USE_TABLE 1
|
||||
|
||||
/*==================
|
||||
* EXTRA COMPONENTS
|
||||
*==================*/
|
||||
|
||||
/*-----------
|
||||
* Widgets
|
||||
*----------*/
|
||||
#define LV_USE_ANIMIMG 1
|
||||
|
||||
#define LV_USE_CALENDAR 1
|
||||
#if LV_USE_CALENDAR
|
||||
#define LV_CALENDAR_WEEK_STARTS_MONDAY 0
|
||||
#if LV_CALENDAR_WEEK_STARTS_MONDAY
|
||||
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}
|
||||
#else
|
||||
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}
|
||||
#endif
|
||||
|
||||
#define LV_CALENDAR_DEFAULT_MONTH_NAMES {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
|
||||
#define LV_USE_CALENDAR_HEADER_ARROW 1
|
||||
#define LV_USE_CALENDAR_HEADER_DROPDOWN 1
|
||||
#endif /*LV_USE_CALENDAR*/
|
||||
|
||||
#define LV_USE_CHART 1
|
||||
|
||||
#define LV_USE_COLORWHEEL 1
|
||||
|
||||
#define LV_USE_IMGBTN 1
|
||||
|
||||
#define LV_USE_KEYBOARD 1
|
||||
|
||||
#define LV_USE_LED 1
|
||||
|
||||
#define LV_USE_LIST 1
|
||||
|
||||
#define LV_USE_MENU 1
|
||||
|
||||
#define LV_USE_METER 1
|
||||
|
||||
#define LV_USE_MSGBOX 1
|
||||
|
||||
#define LV_USE_SPAN 1
|
||||
#if LV_USE_SPAN
|
||||
/*A line text can contain maximum num of span descriptor */
|
||||
#define LV_SPAN_SNIPPET_STACK_SIZE 64
|
||||
#endif
|
||||
|
||||
#define LV_USE_SPINBOX 1
|
||||
|
||||
#define LV_USE_SPINNER 1
|
||||
|
||||
#define LV_USE_TABVIEW 1
|
||||
|
||||
#define LV_USE_TILEVIEW 1
|
||||
|
||||
#define LV_USE_WIN 1
|
||||
|
||||
/*-----------
|
||||
* Themes
|
||||
*----------*/
|
||||
|
||||
/*A simple, impressive and very complete theme*/
|
||||
#define LV_USE_THEME_DEFAULT 1
|
||||
#if LV_USE_THEME_DEFAULT
|
||||
|
||||
/*0: Light mode; 1: Dark mode*/
|
||||
#define LV_THEME_DEFAULT_DARK 0
|
||||
|
||||
/*1: Enable grow on press*/
|
||||
#define LV_THEME_DEFAULT_GROW 1
|
||||
|
||||
/*Default transition time in [ms]*/
|
||||
#define LV_THEME_DEFAULT_TRANSITION_TIME 80
|
||||
#endif /*LV_USE_THEME_DEFAULT*/
|
||||
|
||||
/*A very simple theme that is a good starting point for a custom theme*/
|
||||
#define LV_USE_THEME_BASIC 1
|
||||
|
||||
/*A theme designed for monochrome displays*/
|
||||
#define LV_USE_THEME_MONO 1
|
||||
|
||||
/*-----------
|
||||
* Layouts
|
||||
*----------*/
|
||||
|
||||
/*A layout similar to Flexbox in CSS.*/
|
||||
#define LV_USE_FLEX 1
|
||||
|
||||
/*A layout similar to Grid in CSS.*/
|
||||
#define LV_USE_GRID 1
|
||||
|
||||
/*---------------------
|
||||
* 3rd party libraries
|
||||
*--------------------*/
|
||||
|
||||
/*File system interfaces for common APIs */
|
||||
|
||||
/*API for fopen, fread, etc*/
|
||||
#define LV_USE_FS_STDIO 0
|
||||
#if LV_USE_FS_STDIO
|
||||
#define LV_FS_STDIO_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
|
||||
#define LV_FS_STDIO_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/
|
||||
#define LV_FS_STDIO_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
|
||||
#endif
|
||||
|
||||
/*API for open, read, etc*/
|
||||
#define LV_USE_FS_POSIX 0
|
||||
#if LV_USE_FS_POSIX
|
||||
#define LV_FS_POSIX_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
|
||||
#define LV_FS_POSIX_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/
|
||||
#define LV_FS_POSIX_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
|
||||
#endif
|
||||
|
||||
/*API for CreateFile, ReadFile, etc*/
|
||||
#define LV_USE_FS_WIN32 0
|
||||
#if LV_USE_FS_WIN32
|
||||
#define LV_FS_WIN32_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
|
||||
#define LV_FS_WIN32_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/
|
||||
#define LV_FS_WIN32_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
|
||||
#endif
|
||||
|
||||
/*API for FATFS (needs to be added separately). Uses f_open, f_read, etc*/
|
||||
#if defined(BL808) || defined(BL606P) || defined(BL616)
|
||||
#define LV_USE_FS_FATFS 0
|
||||
#else
|
||||
#define LV_USE_FS_FATFS 0
|
||||
#endif
|
||||
|
||||
#if LV_USE_FS_FATFS
|
||||
#define LV_FS_FATFS_LETTER 'S' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
|
||||
#define LV_FS_FATFS_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
|
||||
#endif
|
||||
|
||||
/*PNG decoder library*/
|
||||
#define LV_USE_PNG 1
|
||||
|
||||
/*BMP decoder library*/
|
||||
#define LV_USE_BMP 1
|
||||
|
||||
/* JPG + split JPG decoder library.
|
||||
* Split JPG is a custom format optimized for embedded systems. */
|
||||
#define LV_USE_SJPG 0
|
||||
|
||||
/*GIF decoder library*/
|
||||
#define LV_USE_GIF 0
|
||||
|
||||
/*QR code library*/
|
||||
#define LV_USE_QRCODE 0
|
||||
|
||||
/*FreeType library*/
|
||||
#define LV_USE_FREETYPE 0
|
||||
#if LV_USE_FREETYPE
|
||||
/*Memory used by FreeType to cache characters [bytes] (-1: no caching)*/
|
||||
#define LV_FREETYPE_CACHE_SIZE (16 * 1024)
|
||||
#if LV_FREETYPE_CACHE_SIZE >= 0
|
||||
/* 1: bitmap cache use the sbit cache, 0:bitmap cache use the image cache. */
|
||||
/* sbit cache:it is much more memory efficient for small bitmaps(font size < 256) */
|
||||
/* if font size >= 256, must be configured as image cache */
|
||||
#define LV_FREETYPE_SBIT_CACHE 0
|
||||
/* Maximum number of opened FT_Face/FT_Size objects managed by this cache instance. */
|
||||
/* (0:use system defaults) */
|
||||
#define LV_FREETYPE_CACHE_FT_FACES 0
|
||||
#define LV_FREETYPE_CACHE_FT_SIZES 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Rlottie library*/
|
||||
#define LV_USE_RLOTTIE 0
|
||||
|
||||
/*FFmpeg library for image decoding and playing videos
|
||||
*Supports all major image formats so do not enable other image decoder with it*/
|
||||
#define LV_USE_FFMPEG 0
|
||||
#if LV_USE_FFMPEG
|
||||
/*Dump input information to stderr*/
|
||||
#define LV_FFMPEG_DUMP_FORMAT 0
|
||||
#endif
|
||||
|
||||
/*-----------
|
||||
* Others
|
||||
*----------*/
|
||||
|
||||
/*1: Enable API to take snapshot for object*/
|
||||
#define LV_USE_SNAPSHOT 0
|
||||
|
||||
/*1: Enable Monkey test*/
|
||||
#define LV_USE_MONKEY 0
|
||||
|
||||
/*1: Enable grid navigation*/
|
||||
#define LV_USE_GRIDNAV 0
|
||||
|
||||
/*1: Enable lv_obj fragment*/
|
||||
#define LV_USE_FRAGMENT 0
|
||||
|
||||
/*1: Support using images as font in label or span widgets */
|
||||
#define LV_USE_IMGFONT 0
|
||||
|
||||
/*1: Enable a published subscriber based messaging system */
|
||||
#define LV_USE_MSG 0
|
||||
|
||||
/*1: Enable Pinyin input method*/
|
||||
/*Requires: lv_keyboard*/
|
||||
#define LV_USE_IME_PINYIN 0
|
||||
#if LV_USE_IME_PINYIN
|
||||
/*1: Use default thesaurus*/
|
||||
/*If you do not use the default thesaurus, be sure to use `lv_ime_pinyin` after setting the thesauruss*/
|
||||
#define LV_IME_PINYIN_USE_DEFAULT_DICT 1
|
||||
/*Set the maximum number of candidate panels that can be displayed*/
|
||||
/*This needs to be adjusted according to the size of the screen*/
|
||||
#define LV_IME_PINYIN_CAND_TEXT_NUM 6
|
||||
|
||||
/*Use 9 key input(k9)*/
|
||||
#define LV_IME_PINYIN_USE_K9_MODE 1
|
||||
#if LV_IME_PINYIN_USE_K9_MODE == 1
|
||||
#define LV_IME_PINYIN_K9_CAND_TEXT_NUM 3
|
||||
#endif // LV_IME_PINYIN_USE_K9_MODE
|
||||
#endif
|
||||
|
||||
/*==================
|
||||
* EXAMPLES
|
||||
*==================*/
|
||||
|
||||
/*Enable the examples to be built with the library*/
|
||||
#define LV_BUILD_EXAMPLES 1
|
||||
|
||||
/*===================
|
||||
* DEMO USAGE
|
||||
====================*/
|
||||
|
||||
/*Show some widget. It might be required to increase `LV_MEM_SIZE` */
|
||||
#define LV_USE_DEMO_WIDGETS 0
|
||||
#if LV_USE_DEMO_WIDGETS
|
||||
#define LV_DEMO_WIDGETS_SLIDESHOW 0
|
||||
#endif
|
||||
|
||||
/*Demonstrate the usage of encoder and keyboard*/
|
||||
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0
|
||||
|
||||
/*Benchmark your system*/
|
||||
#define LV_USE_DEMO_BENCHMARK 1
|
||||
#if LV_USE_DEMO_BENCHMARK
|
||||
/*Use RGB565A8 images with 16 bit color depth instead of ARGB8565*/
|
||||
#define LV_DEMO_BENCHMARK_RGB565A8 0
|
||||
#endif
|
||||
|
||||
/*Stress test for LVGL*/
|
||||
#define LV_USE_DEMO_STRESS 0
|
||||
|
||||
/*Music player demo*/
|
||||
#define LV_USE_DEMO_MUSIC 0
|
||||
#if LV_USE_DEMO_MUSIC
|
||||
#define LV_DEMO_MUSIC_SQUARE 0
|
||||
#define LV_DEMO_MUSIC_LANDSCAPE 0
|
||||
#define LV_DEMO_MUSIC_ROUND 0
|
||||
#define LV_DEMO_MUSIC_LARGE 0
|
||||
#define LV_DEMO_MUSIC_AUTO_PLAY 0
|
||||
#endif
|
||||
|
||||
/*--END OF LV_CONF_H--*/
|
||||
|
||||
#endif /*LV_CONF_H*/
|
||||
|
||||
#endif /*End of "Content enable"*/
|
|
@ -1,11 +1,193 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "./pikapython/pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "bflb_flash.h"
|
||||
#include "bflb_gpio.h"
|
||||
#include "bflb_uart.h"
|
||||
#include "board.h"
|
||||
#include "ff.h"
|
||||
#include "log.h"
|
||||
// #include "lwip/init.h"
|
||||
#include "pikaScript.h"
|
||||
#include "vlibc_stdio.h"
|
||||
#include "task.h"
|
||||
|
||||
#if defined(BL616)
|
||||
#include "bl616_glb.h"
|
||||
#elif defined(BL602)
|
||||
#include "bl602_glb.h"
|
||||
#elif defined(BL702)
|
||||
#include "bl702_glb.h"
|
||||
#elif defined(BL808)
|
||||
#include "bl808_glb.h"
|
||||
#endif
|
||||
|
||||
struct bflb_device_s* uartx = NULL;
|
||||
// static uint8_t freertos_heap[configTOTAL_HEAP_SIZE];
|
||||
|
||||
volatile FILE g_pika_app_flash_file = {0};
|
||||
volatile int g_pika_app_flash_pos = 0;
|
||||
#define _PIKA_APP_FLASH_ADDR 0x100000 // 1M
|
||||
#define _PIKA_APP_FLASH_SIZE 32 * 1024 // 32K
|
||||
|
||||
#define _PIKA_APP_FLASH_INITED 0xFE
|
||||
#define _PIKA_APP_FLASH_VOID 0xFF
|
||||
#define _PIKA_APP_FLASH_SAVED 0x0F
|
||||
|
||||
// static HeapRegion_t xHeapRegions[] = {
|
||||
// {(uint8_t*)freertos_heap, 0},
|
||||
// {NULL, 0}, /* Terminates the array. */
|
||||
// {NULL, 0} /* Terminates the array. */
|
||||
// };
|
||||
|
||||
static int _pika_app_check(void) {
|
||||
uint8_t buf = {0};
|
||||
FILE* f = pika_platform_fopen("app.pika", "rb");
|
||||
pika_platform_fread(&buf, 1, 1, f);
|
||||
if (buf == _PIKA_APP_FLASH_SAVED) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t _pika_app_buf[_PIKA_APP_FLASH_SIZE] = {0};
|
||||
static void consumer_task(void* pvParameters) {
|
||||
PikaObj* root = newRootObj("root", New_PikaMain);
|
||||
if (_pika_app_check()) {
|
||||
printf("Load app.pika from flash\r\n");
|
||||
FILE* f = pika_platform_fopen("app.pika", "rb");
|
||||
pika_platform_fread(_pika_app_buf, 1, _PIKA_APP_FLASH_SIZE, f);
|
||||
obj_linkLibrary(root, (uint8_t*)_pika_app_buf);
|
||||
obj_runModule(root, "main");
|
||||
} else {
|
||||
printf("Load app.pika from flash failed\r\n");
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(root, pikaModules_py_a);
|
||||
obj_runModule(root, "main");
|
||||
}
|
||||
pikaScriptShell(root);
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
static void _erise_app_task(void* pvParameters) {
|
||||
struct bflb_device_s* gpio = bflb_device_get_by_name("gpio");
|
||||
bflb_gpio_init(gpio, GPIO_PIN_2,
|
||||
GPIO_INPUT | GPIO_FLOAT | GPIO_SMT_EN | GPIO_DRV_0);
|
||||
int time = 0;
|
||||
while (1) {
|
||||
if (bflb_gpio_read(gpio, GPIO_PIN_2) == 1) {
|
||||
time++;
|
||||
if (time > 100) {
|
||||
printf("Erasing app.pika...\r\n");
|
||||
printf("Please release the button\r\n");
|
||||
for (uint32_t i = 1; i < (_PIKA_APP_FLASH_SIZE / 1024); i++) {
|
||||
bflb_flash_erase(_PIKA_APP_FLASH_ADDR + (i - 1) * 1024,
|
||||
i * 1024);
|
||||
}
|
||||
printf("Erase app.pika done\r\n");
|
||||
pika_platform_reboot();
|
||||
}
|
||||
} else {
|
||||
time = 0;
|
||||
}
|
||||
vTaskDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
board_init();
|
||||
pikaScriptInit();
|
||||
uartx = bflb_device_get_by_name("uart0");
|
||||
bflb_uart_feature_control(uartx, UART_CMD_SET_BAUD_RATE, 115200);
|
||||
// xHeapRegions[0].xSizeInBytes = configTOTAL_HEAP_SIZE;
|
||||
// vPortDefineHeapRegions(xHeapRegions);
|
||||
// printf("Heap size: %d\r\n", configTOTAL_HEAP_SIZE);
|
||||
|
||||
xTaskCreate(_erise_app_task, (char*)"erise_app_task", 8192, NULL,
|
||||
configMAX_PRIORITIES - 1, NULL);
|
||||
xTaskCreate(consumer_task, (char*)"consumer_task", 8192, NULL, 3, NULL);
|
||||
vTaskStartScheduler();
|
||||
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Platform Porting */
|
||||
|
||||
char pika_platform_getchar(void) {
|
||||
while (1) {
|
||||
int c = bflb_uart_getchar(uartx);
|
||||
if (c != -1) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int pika_platform_putchar(char ch) {
|
||||
bflb_uart_putchar(uartx, ch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pika_platform_reboot(void) {
|
||||
GLB_SW_System_Reset();
|
||||
}
|
||||
|
||||
void* pika_platform_malloc(size_t size) {
|
||||
return pvPortMalloc(size);
|
||||
}
|
||||
|
||||
void pika_platform_free(void* ptr) {
|
||||
return vPortFree(ptr);
|
||||
}
|
||||
|
||||
/* fopen */
|
||||
FILE* pika_platform_fopen(const char* filename, const char* modes) {
|
||||
if (strcmp("app.pika", filename) == 0) {
|
||||
g_pika_app_flash_pos = 0;
|
||||
FILE* fp = (FILE*)&g_pika_app_flash_file;
|
||||
if (strchr(modes, 'w') == NULL) {
|
||||
return fp;
|
||||
}
|
||||
for (uint32_t i = 1; i < (_PIKA_APP_FLASH_SIZE / 1024); i++) {
|
||||
bflb_flash_erase(_PIKA_APP_FLASH_ADDR + (i - 1) * 1024, i * 1024);
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* fwrite */
|
||||
size_t pika_platform_fwrite(const void* ptr,
|
||||
size_t size,
|
||||
size_t n,
|
||||
FILE* stream) {
|
||||
if (stream == (FILE*)&g_pika_app_flash_file) {
|
||||
bflb_flash_write(_PIKA_APP_FLASH_ADDR + g_pika_app_flash_pos,
|
||||
(uint8_t*)ptr, size * n);
|
||||
g_pika_app_flash_pos += size * n;
|
||||
return size * n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* fread */
|
||||
size_t pika_platform_fread(void* ptr, size_t size, size_t n, FILE* stream) {
|
||||
if (stream == (FILE*)&g_pika_app_flash_file) {
|
||||
bflb_flash_read(_PIKA_APP_FLASH_ADDR + g_pika_app_flash_pos,
|
||||
(uint8_t*)ptr, size * n);
|
||||
g_pika_app_flash_pos += size * n;
|
||||
return size * n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* fclose */
|
||||
int pika_platform_fclose(FILE* stream) {
|
||||
if (stream == (FILE*)&g_pika_app_flash_file) {
|
||||
for (uint32_t i = 1; i < 32; i++) {
|
||||
/* add EOF */
|
||||
pika_platform_fwrite("\0", 1, 1, stream);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
14
examples/pikapython/make.sh
Executable file
14
examples/pikapython/make.sh
Executable file
|
@ -0,0 +1,14 @@
|
|||
if [ $# == 0 ] ; then
|
||||
CMD=""
|
||||
fi
|
||||
if [ $# == 1 ] ; then
|
||||
if [ $1 == "bl618" ] ; then
|
||||
CMD="CHIP=bl616 BOARD=bl616dk"
|
||||
fi
|
||||
if [ $1 == "bl616" ] ; then
|
||||
CMD="CHIP=bl616 BOARD=bl616dk"
|
||||
fi
|
||||
fi
|
||||
cd pikapython && wine rust-msc-latest-win10.exe && cd -
|
||||
make -j $CMD
|
||||
cp build/build_out/*.bin /mnt/d
|
1
examples/pikapython/make_bl616.sh
Executable file
1
examples/pikapython/make_bl616.sh
Executable file
|
@ -0,0 +1 @@
|
|||
bash make.sh bl618
|
1
examples/pikapython/make_bl618.sh
Executable file
1
examples/pikapython/make_bl618.sh
Executable file
|
@ -0,0 +1 @@
|
|||
bash make.sh bl618
|
5
examples/pikapython/pika_config.h
Executable file
5
examples/pikapython/pika_config.h
Executable file
|
@ -0,0 +1,5 @@
|
|||
#define PIKA_LWIP_ENABLE 1
|
||||
#define PIKA_FREERTOS_ENABLE 1
|
||||
#define PIKA_THREAD_STACK_SIZE 4096
|
||||
#define PIKA_SHELL_SAVE_APP_ENABLE 1
|
||||
#define PIKA_STACK_BUFF_SIZE 512
|
0
examples/pikapython/pikapython/BLMCU.pyi
Executable file
0
examples/pikapython/pikapython/BLMCU.pyi
Executable file
157
examples/pikapython/pikapython/PikaMath.pyi
Executable file
157
examples/pikapython/pikapython/PikaMath.pyi
Executable file
|
@ -0,0 +1,157 @@
|
|||
from PikaObj import *
|
||||
|
||||
|
||||
class Operator(TinyObj):
|
||||
def plusInt(self, num1: int, num2: int) -> int: ...
|
||||
def plusFloat(self, num1: float, num2: float) -> float: ...
|
||||
def minusInt(self, num1: int, num2: int) -> int: ...
|
||||
def minusFloat(self, num1: float, num2: float) -> float: ...
|
||||
def equalInt(self, num1: int, num2: int) -> int: ...
|
||||
def equalFloat(self, num1: float, num2: float) -> int: ...
|
||||
def graterThanInt(self, num1: int, num2: int) -> int: ...
|
||||
def graterThanFloat(self, num1: float, num2: float) -> int: ...
|
||||
def lessThanInt(self, num1: int, num2: int) -> int: ...
|
||||
def lessThanFloat(self, num1: float, num2: float) -> int: ...
|
||||
def AND(self, flag1: int, flag2: int) -> int: ...
|
||||
def OR(self, flag1: int, flag2: int) -> int: ...
|
||||
def NOT(self, flag: int) -> int: ...
|
||||
def __str__(self) -> str: ...
|
||||
def __del__(self): ...
|
||||
|
||||
|
||||
class Math(TinyObj):
|
||||
pi: float
|
||||
e: float
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def ceil(self, x: float) -> int:
|
||||
pass
|
||||
|
||||
def fabs(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def floor(self, x: float) -> int:
|
||||
pass
|
||||
|
||||
def fmod(self, x: float, y: float) -> float:
|
||||
pass
|
||||
|
||||
def remainder(self, x: float, y: float) -> float:
|
||||
pass
|
||||
|
||||
def trunc(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
# 幂函数和对数函数
|
||||
|
||||
def exp(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def log(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def log2(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def log10(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def pow(self, x: float, y: float) -> float:
|
||||
pass
|
||||
|
||||
def sqrt(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
# 三角函数
|
||||
def acos(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def asin(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def atan(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def atan2(self, x: float, y: float) -> float:
|
||||
pass
|
||||
|
||||
def cos(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def sin(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def tan(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
# 角度转换
|
||||
def degrees(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def radians(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
# 双曲函数
|
||||
def cosh(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def sinh(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
def tanh(self, x: float) -> float:
|
||||
pass
|
||||
|
||||
|
||||
class Quaternion(TinyObj):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def set(self, x: float, y: float, z: float, w: float):
|
||||
"xi+yj+zk+w"
|
||||
pass
|
||||
|
||||
def get(self, key: int) -> float:
|
||||
pass
|
||||
|
||||
def add(self, quat: Quaternion):
|
||||
pass
|
||||
|
||||
def sub(self, quat: Quaternion):
|
||||
pass
|
||||
|
||||
def mul(self, quat: Quaternion):
|
||||
pass
|
||||
|
||||
def magnituded(self) -> float:
|
||||
pass
|
||||
|
||||
def magnitudedsquare(self) -> float:
|
||||
pass
|
||||
|
||||
def reverse(self):
|
||||
pass
|
||||
|
||||
def inverse(self):
|
||||
pass
|
||||
|
||||
def normalize(self):
|
||||
pass
|
||||
|
||||
def isnormalize(self) -> int:
|
||||
pass
|
||||
|
||||
def dot(self, quat: Quaternion) -> float:
|
||||
pass
|
||||
|
||||
def crossproduct(self, quat: Quaternion):
|
||||
pass
|
||||
|
||||
def fromEuler(self, yaw: float, pitch: float, roll: float, mode: int):
|
||||
"mode=1 is deg and mode=0 is rad"
|
||||
pass
|
||||
|
||||
def toEuler(self) -> list:
|
||||
"Z-Y-X"
|
||||
pass
|
490
examples/pikapython/pikapython/PikaStdDevice.pyi
Executable file
490
examples/pikapython/pikapython/PikaStdDevice.pyi
Executable file
|
@ -0,0 +1,490 @@
|
|||
"""
|
||||
PikaStdDevice is a standard and abstract device module for PikaScript.
|
||||
|
||||
PikaStdDevice supplies the standard device API for users.
|
||||
|
||||
Document: https://pikadoc.readthedocs.io/en/latest/PikaStdDevice%20%E6%A0%87%E5%87%86%E8%AE%BE%E5%A4%87.html
|
||||
|
||||
"""
|
||||
from PikaObj import *
|
||||
|
||||
|
||||
class GPIO(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setPin(self, pinName: str):
|
||||
"""
|
||||
Use the name of the pin to select the GPIO pin.
|
||||
|
||||
example: `"PA0"`, `"PA1"` ...
|
||||
"""
|
||||
|
||||
def setId(self, id: int):
|
||||
"""
|
||||
Use the id of the pin to select the GPIO pin.
|
||||
|
||||
example: 0, 1 ...
|
||||
"""
|
||||
|
||||
def getId(self) -> int:
|
||||
"""
|
||||
Get the id of the pin.
|
||||
"""
|
||||
|
||||
def getPin(self) -> str:
|
||||
"""
|
||||
Get the name of the pin.
|
||||
"""
|
||||
|
||||
def setMode(self, mode: str):
|
||||
"""
|
||||
Set the mode of the pin.
|
||||
example: "in", "out" ...
|
||||
"""
|
||||
|
||||
def getMode(self) -> str:
|
||||
"""
|
||||
Get the mode of the pin.
|
||||
"""
|
||||
|
||||
def setPull(self, pull: str):
|
||||
"""
|
||||
Set the pull of the pin.
|
||||
example: `"up"`, `"down"`, `"none"` ...
|
||||
"""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the pin."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the pin."""
|
||||
|
||||
def high(self):
|
||||
"""Set the pin to high."""
|
||||
|
||||
def low(self):
|
||||
"""Set the pin to low."""
|
||||
|
||||
def read(self) -> int:
|
||||
"""Read the pin value."""
|
||||
|
||||
|
||||
SIGNAL_RISING: int
|
||||
SIGNAL_FALLING: int
|
||||
SIGNAL_ANY: int
|
||||
|
||||
def setCallBack(self, eventCallBack: any, filter: int):
|
||||
"""
|
||||
Add a callback function to the pin.
|
||||
Example:
|
||||
``` python
|
||||
def cb1(signal):
|
||||
print("cb1", signal)
|
||||
io.setCallBack(cb1, io.SIGNAL_RISING)
|
||||
```
|
||||
"""
|
||||
|
||||
def close(self): ...
|
||||
|
||||
def platformHigh(self): ...
|
||||
|
||||
def platformLow(self): ...
|
||||
|
||||
def platformEnable(self): ...
|
||||
|
||||
def platformDisable(self): ...
|
||||
|
||||
def platformSetMode(self): ...
|
||||
|
||||
def platformRead(self): ...
|
||||
|
||||
|
||||
def Time() -> time:
|
||||
""" # use time module instead """
|
||||
|
||||
|
||||
class ADC(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setPin(self, pin: str):
|
||||
"""
|
||||
Use the name of the pin to select the ADC pin.
|
||||
example: `"PA0"`, `"PA1"` ...
|
||||
"""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the ADC."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the ADC."""
|
||||
|
||||
def read(self) -> float:
|
||||
"""Read the ADC value."""
|
||||
|
||||
def close(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformEnable(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformRead(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class DAC(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setPin(self, pin: str):
|
||||
"""
|
||||
Use the name of the pin to select the DAC pin.
|
||||
example: `"PA0"`, `"PA1"` ...
|
||||
"""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the DAC."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the DAC."""
|
||||
|
||||
def write(self, val: float):
|
||||
"""write the DAC value."""
|
||||
|
||||
def close(self): ...
|
||||
|
||||
|
||||
class UART:
|
||||
def __init__(self): ...
|
||||
|
||||
def setBaudRate(self, baudRate: int):
|
||||
"""Set the baud rate."""
|
||||
|
||||
def setId(self, id: int):
|
||||
"""Set the id of the UART."""
|
||||
|
||||
FLOW_CONTROL_NONE: int
|
||||
FLOW_CONTROL_RTS: int
|
||||
FLOW_CONTROL_CTS: int
|
||||
FLOW_CONTROL_RTS_CTS: int
|
||||
|
||||
def setFlowControl(self, flowControl: int):
|
||||
"""Set the flow control of the UART."""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the UART."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the UART."""
|
||||
|
||||
def write(self, data: str):
|
||||
"""Write string to the UART."""
|
||||
|
||||
def writeBytes(self, data: bytes, length: int):
|
||||
"""Write bytes to the UART."""
|
||||
|
||||
def read(self, length: int) -> str:
|
||||
"""Read string from the UART."""
|
||||
|
||||
def readBytes(self, length: int) -> bytes:
|
||||
"""Read bytes from the UART."""
|
||||
|
||||
def setPinTX(self, pin: str):
|
||||
"""
|
||||
Remap the TX pin.
|
||||
"""
|
||||
|
||||
def setPinRX(self, pin: str):
|
||||
"""
|
||||
Remap the RX pin.
|
||||
"""
|
||||
|
||||
def setPinCTS(self, pin: str):
|
||||
"""
|
||||
Remap the CTS pin.
|
||||
"""
|
||||
|
||||
def setPinRTS(self, pin: str):
|
||||
"""
|
||||
Remap the RTS pin.
|
||||
"""
|
||||
|
||||
def close(self): ...
|
||||
|
||||
SIGNAL_RX: int
|
||||
SIGNAL_TX: int
|
||||
|
||||
def setCallBack(self, eventCallBack: any, filter: int):
|
||||
"""
|
||||
Add a callback function to the pin.
|
||||
Example:
|
||||
``` python
|
||||
def cb1(signal):
|
||||
print(uart.read(-1))
|
||||
io.setCallBack(cb1, uart.SIGNAL_RX)
|
||||
```
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def platformEnable(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWrite(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWriteBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformRead(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformReadBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class IIC(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setPinSCL(self, pin: str):
|
||||
"""Set the SCL pin."""
|
||||
|
||||
def setPinSDA(self, pin: str):
|
||||
"""Set the SDA pin."""
|
||||
|
||||
def setDeviceAddr(self, addr: int):
|
||||
"""Set the device address."""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the IIC."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the IIC."""
|
||||
|
||||
def write(self, addr: int, data: str):
|
||||
"""Write string to the IIC."""
|
||||
|
||||
def writeBytes(self, addr: int, data: bytes, length: int):
|
||||
"""Write bytes to the IIC."""
|
||||
|
||||
def read(self, addr: int, length: int) -> str:
|
||||
"""Read string from the IIC."""
|
||||
|
||||
def readBytes(self, addr: int, length: int) -> bytes:
|
||||
"""Read bytes from the IIC."""
|
||||
|
||||
@abstractmethod
|
||||
def platformEnable(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWrite(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWriteBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformRead(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformReadBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class PWM(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setName(self, name: str):
|
||||
"""Use the device name to select the PWM pin.
|
||||
exmpale: `"PWM0"`, `"PWM1"` ...
|
||||
"""
|
||||
|
||||
def getName(self) -> str:
|
||||
"""Get the device name."""
|
||||
|
||||
def setChannel(self, ch: int):
|
||||
"""Set the channel."""
|
||||
|
||||
def getChannel(self) -> int:
|
||||
"""Get the channel."""
|
||||
|
||||
def setPin(self, pin: str):
|
||||
"""Use the name of the pin to select the PWM pin.
|
||||
example: `"PA0"`, `"PA1"` ...
|
||||
"""
|
||||
|
||||
def setFrequency(self, freq: int):
|
||||
"""Set the frequency."""
|
||||
|
||||
def setFreq(self, freq: int):
|
||||
"""Set the frequency."""
|
||||
|
||||
def setDuty(self, duty: float):
|
||||
"""Set the duty."""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the PWM."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the PWM."""
|
||||
|
||||
def getFrequency(self) -> int:
|
||||
"""Get the frequency."""
|
||||
|
||||
def getDuty(self) -> float:
|
||||
"""Get the duty."""
|
||||
|
||||
def close(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformEnable(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformSetFrequency(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformSetDuty(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class SPI(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setPinSCK(self, pin: str):
|
||||
"""Set the SCK pin."""
|
||||
|
||||
def setPinMOSI(self, pin: str):
|
||||
"""Set the MOSI pin."""
|
||||
|
||||
def setPinMISO(self, pin: str):
|
||||
"""Set the MISO pin."""
|
||||
|
||||
def setName(self, name: str):
|
||||
"""Use the device name to select the SPI pin.
|
||||
exmpale: `"SPI0"`, `"SPI1"` ...
|
||||
"""
|
||||
|
||||
def setId(self, id: int):
|
||||
"""Set the id of the SPI.
|
||||
example: `0`, `1` ...
|
||||
"""
|
||||
|
||||
def setPolarity(self, polarity: int):
|
||||
"""Set the polarity."""
|
||||
|
||||
def setPhase(self, phase: int):
|
||||
"""Set the phase."""
|
||||
|
||||
def setBaudRate(self, baudRate: int):
|
||||
"""Set the baud rate."""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the SPI."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the SPI."""
|
||||
|
||||
def write(self, data: str):
|
||||
"""Write string to the SPI."""
|
||||
|
||||
def writeBytes(self, data: bytes, length: int):
|
||||
"""Write bytes to the SPI."""
|
||||
|
||||
def read(self, length: int) -> str:
|
||||
"""Read string from the SPI."""
|
||||
|
||||
def readBytes(self, length: int) -> bytes:
|
||||
"""Read bytes from the SPI."""
|
||||
|
||||
@abstractmethod
|
||||
def platformEnable(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWrite(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWriteBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformRead(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformReadBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class CAN(BaseDev):
|
||||
def __init__(self): ...
|
||||
|
||||
def setName(self, name: str):
|
||||
"""Use the device name to select the CAN pin.
|
||||
exmpale: `"CAN0"`, `"CAN1"` ...
|
||||
"""
|
||||
|
||||
def setId(self, id: int):
|
||||
"""Use the id to select the CAN pin.
|
||||
example: `0`, `1` ...
|
||||
"""
|
||||
|
||||
def setBaudRate(self, baudRate: int):
|
||||
"""Set the baud rate."""
|
||||
|
||||
def setMode(self, mode: str):
|
||||
"""Set the mode.
|
||||
example: `"normal"`, `"loopback"`, `"silent"`, `"silent_loopback"`
|
||||
"""
|
||||
|
||||
def enable(self):
|
||||
"""Enable the CAN."""
|
||||
|
||||
def disable(self):
|
||||
"""Disable the CAN."""
|
||||
|
||||
def write(self, data: str):
|
||||
"""Write string to the CAN."""
|
||||
|
||||
def writeBytes(self, data: bytes, length: int):
|
||||
"""Write bytes to the CAN."""
|
||||
|
||||
def read(self, length: int) -> str:
|
||||
"""Read string from the CAN."""
|
||||
|
||||
def readBytes(self, length: int) -> bytes:
|
||||
"""Read bytes from the CAN."""
|
||||
|
||||
def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
|
||||
"""Add a filter."""
|
||||
|
||||
@abstractmethod
|
||||
def platformEnable(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWrite(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformWriteBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformRead(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformReadBytes(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def platformDisable(self): ...
|
||||
|
||||
|
||||
class BaseDev:
|
||||
@PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
|
||||
def addEventCallBack(self, eventCallback: any):
|
||||
""" Add an event callback. """
|
||||
|
||||
@abstractmethod
|
||||
@PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
|
||||
def platformGetEventId(self): ...
|
|
@ -19,6 +19,9 @@ class SysObj:
|
|||
@staticmethod
|
||||
def int(arg: any) -> int: ...
|
||||
|
||||
@staticmethod
|
||||
def bool(arg: any) -> bool: ...
|
||||
|
||||
@staticmethod
|
||||
def float(arg: any) -> float: ...
|
||||
|
||||
|
@ -55,6 +58,10 @@ class SysObj:
|
|||
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
||||
def dict(*val) -> any: ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
||||
def tuple(arg: any) -> any: ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def hex(val: int) -> str: ...
|
||||
|
@ -85,7 +92,7 @@ class SysObj:
|
|||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def dir(obj: object) -> list: ...
|
||||
def dir(obj: any) -> list: ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
|
||||
|
@ -119,6 +126,10 @@ class SysObj:
|
|||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def help(name: str): ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
def reboot(): ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("0")
|
||||
class RangeObj:
|
||||
|
|
32
examples/pikapython/pikapython/_modbus.pyi
Executable file
32
examples/pikapython/pikapython/_modbus.pyi
Executable file
|
@ -0,0 +1,32 @@
|
|||
class _ModBus:
|
||||
def setSlave(self, slave: int): ...
|
||||
|
||||
def serializeReadBits(self, addr: int, nb: int) -> int: ...
|
||||
def serializeReadInputBits(self, addr: int, nb: int) -> int: ...
|
||||
def serializeReadRegisters(self, addr: int, nb: int) -> int: ...
|
||||
def serializeReadInputRegisters(self, addr: int, nb: int) -> int: ...
|
||||
def serializeWriteBit(self, addr: int, status: int) -> int: ...
|
||||
def serializeWriteRegister(self, addr: int, value: int) -> int: ...
|
||||
def serializeMaskWriteRegister(self, addr: int, andMask: int, orMask: int) -> int: ...
|
||||
def serializeReportSlaveId(self) -> int: ...
|
||||
|
||||
def serializeWriteAndReadRegisters(self, writeAddr: int, writeNb: int, src: bytes, readAddr: int, readNb: int) -> int: ...
|
||||
def serializeWriteBits(self, addr: int, nb: int, src: bytes) -> int: ...
|
||||
def serializeWriteRegisters(self, addr: int, nb: int, src: bytes) -> int: ...
|
||||
|
||||
def deserializeWriteBit(self, msgLength: int) -> int: ...
|
||||
def deserializeWriteRegister(self, msgLength: int) -> int: ...
|
||||
def deserializeWriteBits(self, msgLength: int) -> int: ...
|
||||
def deserializeWriteRegisters(self, msgLength: int) -> int: ...
|
||||
def deserializeMaskWriteRegister(self, msgLength: int) -> int: ...
|
||||
def deserializeReadBits(self, msgLength: int) -> bytes: ...
|
||||
def deserializeReadInputBits(self, msgLength: int) -> bytes: ...
|
||||
def deserializeReadRegisters(self, msgLength: int) -> bytes: ...
|
||||
def deserializeReadInputRegisters(self, msgLength: int) -> bytes: ...
|
||||
def deserializeWriteAndReadRegisters(self, msgLength: int) -> bytes: ...
|
||||
def deserializeReportSlaveId(self, msgLength: int, maxDest: int) -> bytes: ...
|
||||
|
||||
def getSendBuff(self) -> bytes: ...
|
||||
def getReadBuff(self) -> bytes: ...
|
||||
def __init__rtu(self, sendBuffSize: int, readBuffSize: int): ...
|
||||
def __init__tcp(self, sendBuffSize: int, readBuffSize: int): ...
|
2
examples/pikapython/pikapython/_thread.pyi
Executable file
2
examples/pikapython/pikapython/_thread.pyi
Executable file
|
@ -0,0 +1,2 @@
|
|||
|
||||
def start_new_thread(function: any, args_: any): ...
|
52
examples/pikapython/pikapython/_time.pyi
Executable file
52
examples/pikapython/pikapython/_time.pyi
Executable file
|
@ -0,0 +1,52 @@
|
|||
from PikaObj import *
|
||||
|
||||
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def time(self) -> float:
|
||||
"""Get the current time."""
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def time_ns(self) -> int:
|
||||
"""Get the current time in nanoseconds."""
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def gmtime(self, unix_time: float):
|
||||
"""Convert unix time to struct_time."""
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def localtime(self, unix_time: float):
|
||||
"""Convert unix time to struct_time."""
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def mktime(self) -> int:
|
||||
"""Convert struct_time to unix time."""
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def asctime(self):
|
||||
"""Convert struct_time to string."""
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def ctime(self, unix_time: float):
|
||||
"""Convert unix time to string."""
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def sleep_s(self, s: int): ...
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def sleep_ms(self, ms: int): ...
|
||||
|
||||
|
||||
@abstractmethod
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def platformGetTick(): ...
|
2
examples/pikapython/pikapython/binascii.pyi
Executable file
2
examples/pikapython/pikapython/binascii.pyi
Executable file
|
@ -0,0 +1,2 @@
|
|||
def b2a_hex(val: any) -> bytes: ...
|
||||
def a2b_hex(val: str) -> bytes: ...
|
110
examples/pikapython/pikapython/configparser.py
Executable file
110
examples/pikapython/pikapython/configparser.py
Executable file
|
@ -0,0 +1,110 @@
|
|||
|
||||
class ConfigParser():
|
||||
content = ''
|
||||
config_dict = {}
|
||||
|
||||
def _parse(self):
|
||||
self.content = self.content.replace('\r', '')
|
||||
content = self.content
|
||||
lines = content.split('\n')
|
||||
for line in lines:
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
if line.startswith(';'):
|
||||
continue
|
||||
if line.startswith('['):
|
||||
section = line.replace('[', '')
|
||||
section = section.replace(']', '')
|
||||
self.config_dict[section] = {}
|
||||
continue
|
||||
|
||||
if line.strip() == '':
|
||||
continue
|
||||
|
||||
stmt = line.split('=')
|
||||
key = stmt[0].strip()
|
||||
value = _getvalue(stmt).strip()
|
||||
section_dict = self.config_dict[section]
|
||||
section_dict[key] = value
|
||||
|
||||
def sections(self):
|
||||
section_keys = self.config_dict.keys()
|
||||
sections = []
|
||||
for section_item in section_keys:
|
||||
sections.append(section_item)
|
||||
return sections
|
||||
|
||||
def options(self, section):
|
||||
section_dict = self.config_dict[section]
|
||||
option_keys = section_dict.keys()
|
||||
options = []
|
||||
for option_item in option_keys:
|
||||
options.append(option_item)
|
||||
return options
|
||||
|
||||
def get(self, section, option):
|
||||
section_dict = self.config_dict[section]
|
||||
return section_dict[option]
|
||||
|
||||
def set(self, section, option, value):
|
||||
section_dict = self.config_dict[section]
|
||||
section_dict[option] = value
|
||||
|
||||
# support config[key] = val
|
||||
def __setitem__(self, __key, __val):
|
||||
self.config_dict[__key] = __val
|
||||
|
||||
# support val = config[key]
|
||||
def __getitem__(self, __key):
|
||||
return self.config_dict[__key]
|
||||
|
||||
def items(self, section):
|
||||
section_dict = self.config_dict[section]
|
||||
section_keys = section_dict.keys()
|
||||
items = []
|
||||
for key in section_keys:
|
||||
val = section_dict[key]
|
||||
items.append([key, val])
|
||||
return items
|
||||
|
||||
def __str__(self):
|
||||
content = ''
|
||||
section_keys = self.config_dict.keys()
|
||||
for section_item in section_keys:
|
||||
content += '[' + section_item + ']\n'
|
||||
section_dict = self.config_dict[section_item]
|
||||
section_keys = section_dict.keys()
|
||||
for key in section_keys:
|
||||
val = section_dict[key]
|
||||
content += key + ' = ' + val + '\n'
|
||||
content += '\n'
|
||||
return content
|
||||
|
||||
def write(self, file_name):
|
||||
print('Error: write() method not implemented')
|
||||
raise
|
||||
self.content = self.__str__(self)
|
||||
print(self.content)
|
||||
|
||||
def read_string(self, content):
|
||||
self.content = content
|
||||
self._parse()
|
||||
|
||||
def read(self, file_name):
|
||||
print('Error: read() method not implemented')
|
||||
raise
|
||||
content = ''
|
||||
self.content = content
|
||||
self._parse()
|
||||
|
||||
def _getvalue(stmt):
|
||||
index = 0
|
||||
val = ''
|
||||
for item in stmt:
|
||||
if index > 0:
|
||||
if val != '':
|
||||
val += ('=' + item)
|
||||
else:
|
||||
val += item
|
||||
index = index + 1
|
||||
return val
|
18
examples/pikapython/pikapython/example.py
Executable file
18
examples/pikapython/pikapython/example.py
Executable file
|
@ -0,0 +1,18 @@
|
|||
import machine
|
||||
import time
|
||||
|
||||
def led_blink():
|
||||
led0 = machine.LED(0)
|
||||
led1 = machine.LED(1)
|
||||
for i in range(10):
|
||||
led0.on()
|
||||
led1.off()
|
||||
time.sleep(0.1)
|
||||
led0.off()
|
||||
led1.on()
|
||||
time.sleep(0.1)
|
||||
led0.off()
|
||||
led1.off()
|
||||
led0.close()
|
||||
led1.close()
|
||||
|
72
examples/pikapython/pikapython/json.py
Executable file
72
examples/pikapython/pikapython/json.py
Executable file
|
@ -0,0 +1,72 @@
|
|||
import pika_cjson as cjson
|
||||
|
||||
|
||||
def _cjson_encode(cjson: cjson.cJSON):
|
||||
if cjson == None:
|
||||
return None
|
||||
elif cjson.isInvalid():
|
||||
return None
|
||||
elif cjson.isFalse():
|
||||
return False
|
||||
elif cjson.isTrue():
|
||||
return True
|
||||
elif cjson.isNull():
|
||||
return None
|
||||
elif cjson.isNumber():
|
||||
return cjson.getValueDouble()
|
||||
elif cjson.isString():
|
||||
return cjson.getValueString()
|
||||
elif cjson.isArray():
|
||||
res = []
|
||||
for i in range(cjson.getArraySize()):
|
||||
res.append(_cjson_encode(cjson.getArrayItem(i)))
|
||||
return res
|
||||
elif cjson.isObject():
|
||||
res = {}
|
||||
child = cjson.getChild()
|
||||
for i in range(cjson.getArraySize()):
|
||||
key = child.getString()
|
||||
res[key] = _cjson_encode(child)
|
||||
child = child.getNext()
|
||||
return res
|
||||
elif cjson.isRaw():
|
||||
return cjson.getString()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def loads(json: str) -> dict:
|
||||
cj = cjson.Parse(json)
|
||||
return _cjson_encode(cj)
|
||||
|
||||
|
||||
def _cjson_decode(d: dict):
|
||||
if d == None:
|
||||
return cjson.Null()
|
||||
elif type(d) == int:
|
||||
return cjson.Number(d)
|
||||
elif type(d) == float:
|
||||
return cjson.Number(d)
|
||||
elif type(d) == bool:
|
||||
if d:
|
||||
return cjson.True_()
|
||||
else:
|
||||
return cjson.False_()
|
||||
elif type(d) == str:
|
||||
return cjson.String(d)
|
||||
elif type(d) == list:
|
||||
res = cjson.Array()
|
||||
for i in d:
|
||||
res.addItemToArray(_cjson_decode(i))
|
||||
return res
|
||||
elif type(d) == dict:
|
||||
res = cjson.Object()
|
||||
for k, v in d.items():
|
||||
res.addItemToObject(k, _cjson_decode(v))
|
||||
return res
|
||||
else:
|
||||
return cjson.Null()
|
||||
|
||||
|
||||
def dumps(d: dict) -> str:
|
||||
return _cjson_decode(d).print()
|
37
examples/pikapython/pikapython/machine.py
Executable file
37
examples/pikapython/pikapython/machine.py
Executable file
|
@ -0,0 +1,37 @@
|
|||
import PikaStdDevice
|
||||
|
||||
|
||||
class UART(PikaStdDevice.UART):
|
||||
pass
|
||||
|
||||
|
||||
class GPIO(PikaStdDevice.GPIO):
|
||||
pass
|
||||
|
||||
|
||||
class ADC(PikaStdDevice.ADC):
|
||||
pass
|
||||
|
||||
|
||||
class DAC(PikaStdDevice.DAC):
|
||||
pass
|
||||
|
||||
|
||||
class LED(GPIO):
|
||||
pin: str = None
|
||||
|
||||
def __init__(self, id: int):
|
||||
super().__init__()
|
||||
if id == 0:
|
||||
self.pin = 'P27'
|
||||
elif id == 1:
|
||||
self.pin = 'P28'
|
||||
self.setMode('out')
|
||||
self.enable()
|
||||
self.high()
|
||||
|
||||
def on(self):
|
||||
self.low()
|
||||
|
||||
def off(self):
|
||||
self.high()
|
|
@ -1 +1,17 @@
|
|||
import PikaStdLib
|
||||
import random
|
||||
import PikaStdData
|
||||
import configparser
|
||||
import pika_cjson
|
||||
import PikaMath
|
||||
import unittest
|
||||
import re
|
||||
import binascii
|
||||
import modbus
|
||||
import time
|
||||
import pika_lvgl
|
||||
import _thread
|
||||
import machine
|
||||
import example
|
||||
import json
|
||||
print('hello PikaPython!')
|
||||
|
|
99
examples/pikapython/pikapython/modbus.py
Executable file
99
examples/pikapython/pikapython/modbus.py
Executable file
|
@ -0,0 +1,99 @@
|
|||
import _modbus
|
||||
|
||||
|
||||
class ModBus(_modbus._ModBus):
|
||||
|
||||
def serializeWriteBits(self, addr: int, src: list) -> bytes:
|
||||
lenth = super().serializeWriteBits(addr, len(list), bytes(src))
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeWriteRegisters(self, addr: int, src: list) -> bytes:
|
||||
_src = bytes(2 * len(src))
|
||||
for i in range(len(src)):
|
||||
_src[2 * i] = src[i] % 256
|
||||
_src[2 * i + 1] = src[i] // 256
|
||||
lenth = super().serializeWriteRegisters(addr, len(src), _src)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeReadBits(self, addr: int, nb: int) -> bytes:
|
||||
lenth = super().serializeReadBits(addr, nb)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeReadInputBits(self, addr: int, nb: int) -> bytes:
|
||||
lenth = super().serializeReadInputBits(addr, nb)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeReadRegisters(self, addr: int, nb: int) -> bytes:
|
||||
lenth = super().serializeReadRegisters(addr, nb)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeReadInputRegisters(self, addr: int, nb: int) -> bytes:
|
||||
lenth = super().serializeReadInputRegisters(addr, nb)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeWriteBit(self, addr: int, status: int) -> bytes:
|
||||
lenth = super().serializeWriteBit(addr, status)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeWriteRegister(self, addr: int, value: int) -> bytes:
|
||||
lenth = super().serializeWriteRegister(addr, value)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeMaskWriteRegister(self,
|
||||
addr: int,
|
||||
andMask: int,
|
||||
orMask: int) -> bytes:
|
||||
lenth = super().serializeMaskWriteRegister(addr, andMask, orMask)
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def serializeReportSlaveId(self) -> int:
|
||||
lenth = super().serializeReportSlaveId()
|
||||
return self.sendBuff[0:lenth]
|
||||
|
||||
def deserializeReadRegisters(self, msg: bytes) -> list:
|
||||
self.readBuff = msg
|
||||
dest = super().deserializeReadRegisters(len(msg))
|
||||
ret = []
|
||||
for i in range(0, len(dest), 2):
|
||||
ret.append(int(dest[i]) + int(dest[i + 1]) * 256)
|
||||
return ret
|
||||
|
||||
def deserializeReadBits(self, msg: bytes) -> list:
|
||||
self.readBuff = msg
|
||||
length = len(msg)
|
||||
dest = super().deserializeReadBits(length)
|
||||
return list(dest)
|
||||
|
||||
def deserializeReadInputBits(self, msg: bytes) -> list:
|
||||
self.readBuff = msg
|
||||
length = len(msg)
|
||||
dest = super().deserializeReadInputBits(length)
|
||||
return list(dest)
|
||||
|
||||
def deserializeReadInputRegisters(self, msg: bytes) -> list:
|
||||
self.readBuff = msg
|
||||
length = len(msg)
|
||||
dest = super().deserializeReadInputRegisters(length)
|
||||
ret = []
|
||||
for i in range(0, len(dest), 2):
|
||||
ret.append(int(dest[i]) + int(dest[i + 1]) * 256)
|
||||
return ret
|
||||
|
||||
def deserializeWriteAndReadRegisters(self, msg: bytes) -> list:
|
||||
self.readBuff = msg
|
||||
length = len(msg)
|
||||
dest = super().deserializeWriteAndReadRegisters(length)
|
||||
ret = []
|
||||
for i in range(0, len(dest), 2):
|
||||
ret.append(int(dest[i]) + int(dest[i + 1]) * 256)
|
||||
return ret
|
||||
|
||||
|
||||
class ModBusRTU(ModBus):
|
||||
def __init__(self, sendBuffSize: int, readBuffSize: int):
|
||||
self.__init__rtu(sendBuffSize, readBuffSize)
|
||||
|
||||
|
||||
class ModBusTCP(ModBus):
|
||||
def __init__(self, sendBuffSize: int, readBuffSize: int):
|
||||
self.__init__tcp(sendBuffSize, readBuffSize)
|
91
examples/pikapython/pikapython/pika_cjson.pyi
Executable file
91
examples/pikapython/pikapython/pika_cjson.pyi
Executable file
|
@ -0,0 +1,91 @@
|
|||
from PikaObj import *
|
||||
|
||||
|
||||
class cJSON(TinyObj):
|
||||
cJSON_Invalid: int
|
||||
cJSON_False: int
|
||||
cJSON_True: int
|
||||
cJSON_NULL: int
|
||||
cJSON_Number: int
|
||||
cJSON_String: int
|
||||
cJSON_Array: int
|
||||
cJSON_Object: int
|
||||
cJSON_Raw: int
|
||||
def print(self) -> str: ...
|
||||
def __del__(self): ...
|
||||
def __init__(self): ...
|
||||
def getObjectItem(self, string: str) -> cJSON: ...
|
||||
def getArrayItem(self, index: int) -> cJSON: ...
|
||||
def getArraySize(self) -> int: ...
|
||||
def getType(self) -> int: ...
|
||||
def getNext(self) -> cJSON: ...
|
||||
def getPrev(self) -> cJSON: ...
|
||||
def getChild(self) -> cJSON: ...
|
||||
def getValueString(self) -> str: ...
|
||||
def getValueInt(self) -> int: ...
|
||||
def getValueDouble(self) -> float: ...
|
||||
def getString(self) -> str: ...
|
||||
def getValue(self) -> any: ...
|
||||
def isInvalid(self) -> int: ...
|
||||
def isFalse(self) -> int: ...
|
||||
def isTrue(self) -> int: ...
|
||||
def isBool(self) -> int: ...
|
||||
def isNull(self) -> int: ...
|
||||
def isNumber(self) -> int: ...
|
||||
def isString(self) -> int: ...
|
||||
def isArray(self) -> int: ...
|
||||
def isObject(self) -> int: ...
|
||||
def isRaw(self) -> int: ...
|
||||
def addItemToArray(self, item: cJSON): ...
|
||||
def addItemToObject(self, string: str, item: cJSON): ...
|
||||
|
||||
|
||||
def Parse(value: str) -> cJSON: ...
|
||||
|
||||
|
||||
class Null(cJSON):
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class True_(cJSON):
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class False_(cJSON):
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class Bool(cJSON):
|
||||
def __init__(self, bolean: int): ...
|
||||
|
||||
|
||||
class Number(cJSON):
|
||||
def __init__(self, num: float): ...
|
||||
|
||||
|
||||
class String(cJSON):
|
||||
def __init__(self, string: str): ...
|
||||
|
||||
|
||||
class Raw(cJSON):
|
||||
def __init__(self, raw: str): ...
|
||||
|
||||
|
||||
class Array(cJSON):
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class Object(cJSON):
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class StringReference(cJSON):
|
||||
def __init__(self, string: str): ...
|
||||
|
||||
|
||||
class ObjectReference(cJSON):
|
||||
def __init__(self, child: cJSON): ...
|
||||
|
||||
|
||||
class ArrayReference(cJSON):
|
||||
def __init__(self, child: cJSON): ...
|
574
examples/pikapython/pikapython/pika_lvgl.pyi
Executable file
574
examples/pikapython/pikapython/pika_lvgl.pyi
Executable file
|
@ -0,0 +1,574 @@
|
|||
from tkinter import HIDDEN
|
||||
from PikaObj import *
|
||||
|
||||
|
||||
def __init__(): ...
|
||||
|
||||
|
||||
class EVENT:
|
||||
ALL: int
|
||||
PRESSED: int
|
||||
PRESSING: int
|
||||
PRESS_LOST: int
|
||||
SHORT_CLICKED: int
|
||||
LONG_PRESSED: int
|
||||
LONG_PRESSED_REPEAT: int
|
||||
CLICKED: int
|
||||
RELEASED: int
|
||||
SCROLL_BEGIN: int
|
||||
SCROLL_END: int
|
||||
SCROLL: int
|
||||
GESTURE: int
|
||||
KEY: int
|
||||
FOCUSED: int
|
||||
DEFOCUSED: int
|
||||
LEAVE: int
|
||||
HIT_TEST: int
|
||||
COVER_CHECK: int
|
||||
REFR_EXT_DRAW_SIZE: int
|
||||
DRAW_MAIN_BEGIN: int
|
||||
DRAW_MAIN: int
|
||||
DRAW_MAIN_END: int
|
||||
DRAW_POST_BEGIN: int
|
||||
DRAW_POST: int
|
||||
DRAW_POST_END: int
|
||||
DRAW_PART_BEGIN: int
|
||||
DRAW_PART_END: int
|
||||
VALUE_CHANGED: int
|
||||
INSERT: int
|
||||
REFRESH: int
|
||||
READY: int
|
||||
CANCEL: int
|
||||
DELETE: int
|
||||
CHILD_CHANGED: int
|
||||
CHILD_CREATED: int
|
||||
CHILD_DELETED: int
|
||||
SCREEN_UNLOAD_START: int
|
||||
SCREEN_LOAD_START: int
|
||||
SCREEN_LOADED: int
|
||||
SCREEN_UNLOADED: int
|
||||
SIZE_CHANGED: int
|
||||
STYLE_CHANGED: int
|
||||
LAYOUT_CHANGED: int
|
||||
GET_SELF_SIZE: int
|
||||
PREPROCESS: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class ALIGN:
|
||||
DEFAULT: int
|
||||
TOP_LEFT: int
|
||||
TOP_MID: int
|
||||
TOP_RIGHT: int
|
||||
BOTTOM_LEFT: int
|
||||
BOTTOM_MID: int
|
||||
BOTTOM_RIGHT: int
|
||||
LEFT_MID: int
|
||||
RIGHT_MID: int
|
||||
CENTER: int
|
||||
OUT_TOP_LEFT: int
|
||||
OUT_TOP_MID: int
|
||||
OUT_TOP_RIGHT: int
|
||||
OUT_BOTTOM_LEFT: int
|
||||
OUT_BOTTOM_MID: int
|
||||
OUT_BOTTOM_RIGHT: int
|
||||
OUT_LEFT_TOP: int
|
||||
OUT_LEFT_MID: int
|
||||
OUT_LEFT_BOTTOM: int
|
||||
OUT_RIGHT_TOP: int
|
||||
OUT_RIGHT_MID: int
|
||||
OUT_RIGHT_BOTTOM: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class PALETTE:
|
||||
RED: int
|
||||
PINK: int
|
||||
PURPLE: int
|
||||
DEEP_PURPLE: int
|
||||
INDIGO: int
|
||||
BLUE: int
|
||||
LIGHT_BLUE: int
|
||||
CYAN: int
|
||||
TEAL: int
|
||||
GREEN: int
|
||||
LIGHT_GREEN: int
|
||||
LIME: int
|
||||
YELLOW: int
|
||||
AMBER: int
|
||||
ORANGE: int
|
||||
DEEP_ORANGE: int
|
||||
BROWN: int
|
||||
BLUE_GREY: int
|
||||
GREY: int
|
||||
NONE: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class OPA:
|
||||
TRANSP: int
|
||||
COVER: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class ANIM:
|
||||
OFF: int
|
||||
ON: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class STATE:
|
||||
DEFAULT: int
|
||||
CHECKED: int
|
||||
FOCUSED: int
|
||||
FOCUS_KEY: int
|
||||
EDITED: int
|
||||
HOVERED: int
|
||||
PRESSED: int
|
||||
SCROLLED: int
|
||||
DISABLED: int
|
||||
USER_1: int
|
||||
USER_2: int
|
||||
USER_3: int
|
||||
USER_4: int
|
||||
ANY: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class TEXT_DECOR:
|
||||
NONE: int
|
||||
UNDERLINE: int
|
||||
STRIKETHROUGH: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class lv_event:
|
||||
def get_code(self) -> int: ...
|
||||
def get_target(self) -> lv_obj: ...
|
||||
|
||||
|
||||
class lv_color_t:
|
||||
...
|
||||
|
||||
|
||||
def lv_color_hex(hex: int64) -> lv_color_t: ...
|
||||
|
||||
|
||||
class lv_timer_t:
|
||||
def set_period(period: int): ...
|
||||
def set_cb(cb: any): ...
|
||||
def _del(self): ...
|
||||
|
||||
|
||||
def palette_lighten(p: int, lvl: int) -> lv_color_t: ...
|
||||
def palette_main(p: int) -> lv_color_t: ...
|
||||
|
||||
|
||||
class style_t:
|
||||
def __init__(self): ...
|
||||
def init(self): ...
|
||||
def set_width(self, value: int): ...
|
||||
def set_min_width(self, value: int): ...
|
||||
def set_max_width(self, value: int): ...
|
||||
def set_height(self, value: int): ...
|
||||
def set_min_height(self, value: int): ...
|
||||
def set_max_height(self, value: int): ...
|
||||
def set_x(self, value: int): ...
|
||||
def set_y(self, value: int): ...
|
||||
def set_align(self, value: int): ...
|
||||
def set_transform_width(self, value: int): ...
|
||||
def set_transform_height(self, value: int): ...
|
||||
def set_translate_x(self, value: int): ...
|
||||
def set_translate_y(self, value: int): ...
|
||||
def set_transform_zoom(self, value: int): ...
|
||||
def set_transform_angle(self, value: int): ...
|
||||
def set_transform_pivot_x(self, value: int): ...
|
||||
def set_transform_pivot_y(self, value: int): ...
|
||||
def set_pad_top(self, value: int): ...
|
||||
def set_pad_bottom(self, value: int): ...
|
||||
def set_pad_left(self, value: int): ...
|
||||
def set_pad_right(self, value: int): ...
|
||||
def set_pad_row(self, value: int): ...
|
||||
def set_pad_column(self, value: int): ...
|
||||
def set_bg_color(self, value: lv_color_t): ...
|
||||
def set_bg_opa(self, value: int): ...
|
||||
def set_bg_grad_color(self, value: lv_color_t): ...
|
||||
def set_bg_grad_dir(self, value: int): ...
|
||||
def set_bg_main_stop(self, value: int): ...
|
||||
def set_bg_grad_stop(self, value: int): ...
|
||||
# def set_bg_grad(self, value: lv_grad_dsc_t):...
|
||||
def set_bg_dither_mode(self, value: int): ...
|
||||
def set_bg_img_src(self, value: bytes): ...
|
||||
def set_bg_img_opa(self, value: int): ...
|
||||
def set_bg_img_recolor(self, value: lv_color_t): ...
|
||||
def set_bg_img_recolor_opa(self, value: int): ...
|
||||
def set_bg_img_tiled(self, value: int): ...
|
||||
def set_border_color(self, value: lv_color_t): ...
|
||||
def set_border_opa(self, value: int): ...
|
||||
def set_border_width(self, value: int): ...
|
||||
def set_border_side(self, value: int): ...
|
||||
def set_border_post(self, value: int): ...
|
||||
def set_outline_width(self, value: int): ...
|
||||
def set_outline_color(self, value: lv_color_t): ...
|
||||
def set_outline_opa(self, value: int): ...
|
||||
def set_outline_pad(self, value: int): ...
|
||||
def set_shadow_width(self, value: int): ...
|
||||
def set_shadow_ofs_x(self, value: int): ...
|
||||
def set_shadow_ofs_y(self, value: int): ...
|
||||
def set_shadow_spread(self, value: int): ...
|
||||
def set_shadow_color(self, value: lv_color_t): ...
|
||||
def set_shadow_opa(self, value: int): ...
|
||||
def set_img_opa(self, value: int): ...
|
||||
def set_img_recolor(self, value: lv_color_t): ...
|
||||
def set_img_recolor_opa(self, value: int): ...
|
||||
def set_line_width(self, value: int): ...
|
||||
def set_line_dash_width(self, value: int): ...
|
||||
def set_line_dash_gap(self, value: int): ...
|
||||
def set_line_rounded(self, value: int): ...
|
||||
def set_line_color(self, value: lv_color_t): ...
|
||||
def set_line_opa(self, value: int): ...
|
||||
def set_arc_width(self, value: int): ...
|
||||
def set_arc_rounded(self, value: int): ...
|
||||
def set_arc_color(self, value: lv_color_t): ...
|
||||
def set_arc_opa(self, value: int): ...
|
||||
def set_arc_img_src(self, value: bytes): ...
|
||||
def set_text_color(self, value: lv_color_t): ...
|
||||
def set_text_opa(self, value: int): ...
|
||||
# def set_text_font(self, value: lv_font_t): ...
|
||||
def set_text_letter_space(self, value: int): ...
|
||||
def set_text_line_space(self, value: int): ...
|
||||
def set_text_decor(self, value: int): ...
|
||||
def set_text_align(self, value: int): ...
|
||||
def set_radius(self, value: int): ...
|
||||
def set_clip_corner(self, value: int): ...
|
||||
def set_opa(self, value: int): ...
|
||||
# def set_color_filter_dsc(self, value: lv_color_filter_dsc_t): ...
|
||||
def set_color_filter_opa(self, value: int): ...
|
||||
# def set_anim(self, value: lv_anim_t): ...
|
||||
def set_anim_time(self, value: int): ...
|
||||
def set_anim_speed(self, value: int): ...
|
||||
# def set_transition(self, value: lv_style_transition_dsc_t): ...
|
||||
def set_blend_mode(self, value: int): ...
|
||||
def set_layout(self, value: int): ...
|
||||
def set_base_dir(self, value: int): ...
|
||||
def reset(self): ...
|
||||
def register_prop(self, flag: int) -> int: ...
|
||||
def get_num_custom_props(self) -> int: ...
|
||||
def remove_prop(self, prop: int) -> int: ...
|
||||
# def set_prop(self, prop: int, value: lv_style_value_t): ...
|
||||
# def set_prop_meta(self, prop: int, meta: int): ...
|
||||
# def get_prop(self, prop: int, value: lv_style_value_t) -> int: ...
|
||||
# def transition_dsc_init(self, tr: lv_style_transition_dsc_t, props: int, path_cb: int, time: int, delay: int, user_data: int): ...
|
||||
# def prop_get_default(self, prop: int) -> lv_style_value_t: ...
|
||||
def is_empty(self) -> int: ...
|
||||
def set_size(self, value: int): ...
|
||||
def set_pad_all(self, value: int): ...
|
||||
def set_pad_hor(self, value: int): ...
|
||||
def set_pad_ver(self, value: int): ...
|
||||
def set_pad_gap(self, value: int): ...
|
||||
def prop_has_flag(self, prop: int, flag: int) -> int: ...
|
||||
def set_flex_flow(self, value: int): ...
|
||||
def set_flex_main_place(self, value: int): ...
|
||||
def set_flex_cross_place(self, value: int): ...
|
||||
def set_flex_track_place(self, value: int): ...
|
||||
def set_flex_grow(self, value: int): ...
|
||||
|
||||
|
||||
class LAYOUT_FLEX:
|
||||
value: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class SIZE:
|
||||
CONTENT: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class flag_t:
|
||||
HIDDEN: int
|
||||
CLICKABLE: int
|
||||
CLICK_FOCUSABLE: int
|
||||
CHECKABLE: int
|
||||
SCROLLABLE: int
|
||||
SCROLL_ELASTIC: int
|
||||
SCROLL_MOMENTUM: int
|
||||
SCROLL_ONE: int
|
||||
SCROLL_CHAIN_HOR: int
|
||||
SCROLL_CHAIN_VER: int
|
||||
SCROLL_CHAIN: int
|
||||
SCROLL_ON_FOCUS: int
|
||||
SCROLL_WITH_ARROW: int
|
||||
SNAPPABLE: int
|
||||
PRESS_LOCK: int
|
||||
EVENT_BUBBLE: int
|
||||
GESTURE_BUBBLE: int
|
||||
ADV_HITTEST: int
|
||||
IGNORE_LAYOUT: int
|
||||
FLOATING: int
|
||||
OVERFLOW_VISIBLE: int
|
||||
LAYOUT_1: int
|
||||
LAYOUT_2: int
|
||||
WIDGET_1: int
|
||||
WIDGET_2: int
|
||||
USER_1: int
|
||||
USER_2: int
|
||||
USER_3: int
|
||||
USER_4: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class FLEX_FLOW:
|
||||
ROW: int
|
||||
COLUMN: int
|
||||
ROW_WRAP: int
|
||||
ROW_REVERSE: int
|
||||
ROW_WRAP_REVERSE: int
|
||||
COLUMN_WRAP: int
|
||||
COLUMN_REVERSE: int
|
||||
COLUMN_WRAP_REVERSE: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class lv_obj:
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def add_state(self, state: int): ...
|
||||
def add_flag(self, flag: int): ...
|
||||
def clear_flag(self, flag: int): ...
|
||||
def add_event_cb(self, event_cb: any, filter: int, user_data: pointer): ...
|
||||
def add_style(self, style: style_t, selector: int): ...
|
||||
def set_pos(self, x: int, y: int): ...
|
||||
def set_x(self, x: int): ...
|
||||
def set_y(self, y: int): ...
|
||||
def set_size(self, w: int, h: int): ...
|
||||
def refr_size(self) -> int: ...
|
||||
def set_width(self, w: int): ...
|
||||
def set_height(self, h: int): ...
|
||||
def set_content_width(self, w: int): ...
|
||||
def set_content_height(self, h: int): ...
|
||||
def set_layout(self, layout: int): ...
|
||||
def is_layout_positioned(self) -> int: ...
|
||||
def mark_layout_as_dirty(self): ...
|
||||
def update_layout(self): ...
|
||||
def set_align(self, align: int): ...
|
||||
def align(self, align: int, x_ofs: int, y_ofs: int): ...
|
||||
def align_to(self, base: lv_obj, align: int, x_ofs: int, y_ofs: int): ...
|
||||
def center(self): ...
|
||||
# def get_coords(self, coords: lv_area_t): ...
|
||||
def get_x(self) -> int: ...
|
||||
def get_x2(self) -> int: ...
|
||||
def get_y(self) -> int: ...
|
||||
def get_y2(self) -> int: ...
|
||||
def get_x_aligned(self) -> int: ...
|
||||
def get_y_aligned(self) -> int: ...
|
||||
def get_width(self) -> int: ...
|
||||
def get_height(self) -> int: ...
|
||||
def get_content_width(self) -> int: ...
|
||||
def get_content_height(self) -> int: ...
|
||||
# def get_content_coords(self, area: lv_area_t): ...
|
||||
def get_self_width(self) -> int: ...
|
||||
def get_self_height(self) -> int: ...
|
||||
def refresh_self_size(self) -> int: ...
|
||||
def refr_pos(self): ...
|
||||
def move_to(self, x: int, y: int): ...
|
||||
def move_children_by(self, x_diff: int, y_diff: int,
|
||||
ignore_floating: int): ...
|
||||
|
||||
def transform_point(self, p: point_t, recursive: int, inv: int): ...
|
||||
# def get_transformed_area(self, area: lv_area_t, recursive: int, inv: int): ...
|
||||
# def invalidate_area(self, area: lv_area_t): ...
|
||||
def invalidate(self): ...
|
||||
# def area_is_visible(self, area: lv_area_t) -> int: ...
|
||||
def is_visible(self) -> int: ...
|
||||
def set_ext_click_area(self, size: int): ...
|
||||
# def get_click_area(self, area: lv_area_t): ...
|
||||
def hit_test(self, point: point_t) -> int: ...
|
||||
def set_flex_flow(self, flow: int): ...
|
||||
def set_flex_grow(self, value: int): ...
|
||||
def set_flex_align(self, main_place: int,
|
||||
cross_place: int, align: int): ...
|
||||
|
||||
def set_id(self, id: str): ...
|
||||
def get_id(self) -> str: ...
|
||||
def clean(self): ...
|
||||
|
||||
|
||||
class indev_t:
|
||||
def get_vect(self, point: point_t): ...
|
||||
|
||||
|
||||
class FLEX_ALIGN:
|
||||
START: int
|
||||
END: int
|
||||
CENTER: int
|
||||
SPACE_EVENLY: int
|
||||
SPACE_AROUND: int
|
||||
SPACE_BETWEEN: int
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class obj(lv_obj):
|
||||
FLAG: flag_t
|
||||
def __init__(self, *parent): ...
|
||||
|
||||
|
||||
def indev_get_act() -> indev_t: ...
|
||||
|
||||
|
||||
class point_t:
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
class arc(lv_obj):
|
||||
MODE_NORMAL: int
|
||||
MODE_SYMMETRICAL: int
|
||||
MODE_REVERSE: int
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_start_angle(self, start: int): ...
|
||||
def set_end_angle(self, angle: int): ...
|
||||
def set_angles(self, start: int, end: int): ...
|
||||
def set_bg_start_angle(self, start: int): ...
|
||||
def set_bg_end_angle(self, angle: int): ...
|
||||
def set_bg_angles(self, start: int, end: int): ...
|
||||
def set_rotation(self, rotation: int): ...
|
||||
def set_mode(self, mode: int): ...
|
||||
def set_value(self, value: int): ...
|
||||
def set_range(self, min: int, max: int): ...
|
||||
def set_change_rate(self, rate: int): ...
|
||||
def get_angle_start(self) -> int: ...
|
||||
def get_angle_end(self) -> int: ...
|
||||
def get_bg_angle_start(self) -> int: ...
|
||||
def get_bg_angle_end(self) -> int: ...
|
||||
def get_value(self) -> int: ...
|
||||
def get_min_value(self) -> int: ...
|
||||
def get_max_value(self) -> int: ...
|
||||
def get_mode(self) -> int: ...
|
||||
# def get_rotation(self) -> int: ...
|
||||
|
||||
|
||||
class bar(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_value(self, value: int, anim: int): ...
|
||||
def set_start_value(self, start_value: int, anim: int): ...
|
||||
def set_range(self, min: int, max: int): ...
|
||||
def set_mode(self, mode: int): ...
|
||||
def get_value(self) -> int: ...
|
||||
def get_start_value(self) -> int: ...
|
||||
def get_min_value(self) -> int: ...
|
||||
def get_max_value(self) -> int: ...
|
||||
def get_mode(self) -> int: ...
|
||||
|
||||
|
||||
class btn(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
|
||||
|
||||
class checkbox(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_text(self, txt: str): ...
|
||||
def set_text_static(self, txt: str): ...
|
||||
def get_text(self) -> str: ...
|
||||
|
||||
|
||||
class dropdown(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_text(self, txt: str): ...
|
||||
def set_options(self, options: str): ...
|
||||
def add_option(self, option: str, pos: int): ...
|
||||
def clear_options(self): ...
|
||||
def set_selected(self, sel_opt: int): ...
|
||||
def set_dir(self, dir: int): ...
|
||||
def set_symbol(self, symbol: str): ...
|
||||
def set_selected_hightlight(self, en: int): ...
|
||||
# def get_list(self) -> lv_obj: ...
|
||||
def get_text(self) -> str: ...
|
||||
def get_options(self) -> str: ...
|
||||
def get_selected(self) -> int: ...
|
||||
def get_option_cnt(self) -> int: ...
|
||||
def get_selected_str(self) -> str: ...
|
||||
def get_option_index(self, option: str) -> int: ...
|
||||
def get_symbol(self) -> str: ...
|
||||
def get_selected_highlight(self) -> int: ...
|
||||
def get_dir(self) -> int: ...
|
||||
def open(self): ...
|
||||
def close(self): ...
|
||||
def is_open(self) -> int: ...
|
||||
|
||||
|
||||
class label(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_text(self, txt: str): ...
|
||||
def set_long_mode(self, mode: int): ...
|
||||
def set_recolor(self, en: int): ...
|
||||
def set_style_text_align(self, value: int, selector: int): ...
|
||||
|
||||
|
||||
class roller(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_options(self, options: str, mode: int): ...
|
||||
def set_visible_row_count(self, row_cnt: int): ...
|
||||
|
||||
|
||||
class slider(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
|
||||
|
||||
class switch(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
|
||||
|
||||
class table(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_cell_value(self, row: int, col: int, txt: str): ...
|
||||
|
||||
|
||||
class img_dsc_t:
|
||||
def __init__(self, dsc_dict: dict): ...
|
||||
|
||||
|
||||
class img(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
"""
|
||||
void lv_img_set_src(lv_obj_t * obj, const void * src);
|
||||
void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x);
|
||||
void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y);
|
||||
void lv_img_set_angle(lv_obj_t * obj, int16_t angle);
|
||||
void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y);
|
||||
void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom);
|
||||
void lv_img_set_antialias(lv_obj_t * obj, bool antialias);
|
||||
void lv_img_set_size_mode(lv_obj_t * obj, lv_img_size_mode_t mode);
|
||||
const void * lv_img_get_src(lv_obj_t * obj);
|
||||
lv_coord_t lv_img_get_offset_x(lv_obj_t * obj);
|
||||
lv_coord_t lv_img_get_offset_y(lv_obj_t * obj);
|
||||
uint16_t lv_img_get_angle(lv_obj_t * obj);
|
||||
void lv_img_get_pivot(lv_obj_t * obj, lv_point_t * pivot);
|
||||
uint16_t lv_img_get_zoom(lv_obj_t * obj);
|
||||
bool lv_img_get_antialias(lv_obj_t * obj);
|
||||
lv_img_size_mode_t lv_img_get_size_mode(lv_obj_t * obj);
|
||||
"""
|
||||
|
||||
def set_src(self, src: img_dsc_t): ...
|
||||
def set_offset_x(self, x: int): ...
|
||||
def set_offset_y(self, y: int): ...
|
||||
def set_angle(self, angle: int): ...
|
||||
def set_pivot(self, x: int, y: int): ...
|
||||
def set_zoom(self, zoom: int): ...
|
||||
def set_antialias(self, antialias: int): ...
|
||||
def set_size_mode(self, mode: int): ...
|
||||
def get_src(self) -> img_dsc_t: ...
|
||||
def get_offset_x(self) -> int: ...
|
||||
def get_offset_y(self) -> int: ...
|
||||
def get_angle(self) -> int: ...
|
||||
# def get_pivot(self) -> lv_point: ...
|
||||
def get_zoom(self) -> int: ...
|
||||
def get_antialias(self) -> int: ...
|
||||
def get_size_mode(self) -> int: ...
|
||||
|
||||
|
||||
class textarea(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_one_line(en: int): ...
|
||||
|
||||
|
||||
def scr_act() -> lv_obj: ...
|
||||
def pct(x: int) -> int: ...
|
||||
def timer_create_basic() -> lv_timer_t: ...
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaDebug__H
|
||||
#define __PikaDebug__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaDebug(Args *args);
|
||||
|
||||
Arg* PikaDebug_Debuger(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaDebug_Debuger__H
|
||||
#define __PikaDebug_Debuger__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaDebug_Debuger(Args *args);
|
||||
|
||||
void PikaDebug_Debuger___init__(PikaObj *self);
|
||||
void PikaDebug_Debuger_set_trace(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaMain__H
|
||||
#define __PikaMain__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaMain(Args *args);
|
||||
|
||||
|
||||
#endif
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData__H
|
||||
#define __PikaStdData__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData(Args *args);
|
||||
|
||||
Arg* PikaStdData_ByteArray(PikaObj *self);
|
||||
Arg* PikaStdData_Dict(PikaObj *self);
|
||||
Arg* PikaStdData_FILEIO(PikaObj *self);
|
||||
Arg* PikaStdData_List(PikaObj *self);
|
||||
Arg* PikaStdData_String(PikaObj *self);
|
||||
Arg* PikaStdData_Tuple(PikaObj *self);
|
||||
Arg* PikaStdData_Utils(PikaObj *self);
|
||||
Arg* PikaStdData_dict_items(PikaObj *self);
|
||||
Arg* PikaStdData_dict_keys(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_ByteArray__H
|
||||
#define __PikaStdData_ByteArray__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_ByteArray(Args *args);
|
||||
|
||||
int PikaStdData_ByteArray___getitem__(PikaObj *self, int __key);
|
||||
void PikaStdData_ByteArray___init__(PikaObj *self, Arg* bytes);
|
||||
Arg* PikaStdData_ByteArray___iter__(PikaObj *self);
|
||||
Arg* PikaStdData_ByteArray___next__(PikaObj *self);
|
||||
void PikaStdData_ByteArray___setitem__(PikaObj *self, int __key, int __val);
|
||||
char* PikaStdData_ByteArray___str__(PikaObj *self);
|
||||
char* PikaStdData_ByteArray_decode(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_Dict__H
|
||||
#define __PikaStdData_Dict__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_Dict(Args *args);
|
||||
|
||||
int PikaStdData_Dict___contains__(PikaObj *self, Arg* val);
|
||||
void PikaStdData_Dict___del__(PikaObj *self);
|
||||
Arg* PikaStdData_Dict___getitem__(PikaObj *self, Arg* __key);
|
||||
void PikaStdData_Dict___init__(PikaObj *self);
|
||||
Arg* PikaStdData_Dict___iter__(PikaObj *self);
|
||||
int PikaStdData_Dict___len__(PikaObj *self);
|
||||
Arg* PikaStdData_Dict___next__(PikaObj *self);
|
||||
void PikaStdData_Dict___setitem__(PikaObj *self, Arg* __key, Arg* __val);
|
||||
char* PikaStdData_Dict___str__(PikaObj *self);
|
||||
Arg* PikaStdData_Dict_get(PikaObj *self, char* key);
|
||||
PikaObj* PikaStdData_Dict_items(PikaObj *self);
|
||||
PikaObj* PikaStdData_Dict_keys(PikaObj *self);
|
||||
void PikaStdData_Dict_remove(PikaObj *self, char* key);
|
||||
void PikaStdData_Dict_set(PikaObj *self, char* key, Arg* arg);
|
||||
void PikaStdData_Dict_update(PikaObj *self, PikaObj* other);
|
||||
|
||||
#endif
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_FILEIO__H
|
||||
#define __PikaStdData_FILEIO__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_FILEIO(Args *args);
|
||||
|
||||
void PikaStdData_FILEIO_close(PikaObj *self);
|
||||
int PikaStdData_FILEIO_init(PikaObj *self, char* path, char* mode);
|
||||
Arg* PikaStdData_FILEIO_read(PikaObj *self, PikaTuple* size);
|
||||
char* PikaStdData_FILEIO_readline(PikaObj *self);
|
||||
PikaObj* PikaStdData_FILEIO_readlines(PikaObj *self);
|
||||
int PikaStdData_FILEIO_seek(PikaObj *self, int offset, PikaTuple* fromwhere);
|
||||
int PikaStdData_FILEIO_tell(PikaObj *self);
|
||||
int PikaStdData_FILEIO_write(PikaObj *self, Arg* s);
|
||||
void PikaStdData_FILEIO_writelines(PikaObj *self, PikaObj* lines);
|
||||
|
||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_List__H
|
||||
#define __PikaStdData_List__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_List(Args *args);
|
||||
|
||||
PikaObj* PikaStdData_List___add__(PikaObj *self, PikaObj* others);
|
||||
void PikaStdData_List___init__(PikaObj *self);
|
||||
void PikaStdData_List___setitem__(PikaObj *self, Arg* __key, Arg* __val);
|
||||
char* PikaStdData_List___str__(PikaObj *self);
|
||||
void PikaStdData_List_append(PikaObj *self, Arg* arg);
|
||||
void PikaStdData_List_insert(PikaObj *self, int i, Arg* arg);
|
||||
Arg* PikaStdData_List_pop(PikaObj *self);
|
||||
void PikaStdData_List_remove(PikaObj *self, Arg* val);
|
||||
void PikaStdData_List_reverse(PikaObj *self);
|
||||
void PikaStdData_List_set(PikaObj *self, int i, Arg* arg);
|
||||
|
||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_String__H
|
||||
#define __PikaStdData_String__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_String(Args *args);
|
||||
|
||||
Arg* PikaStdData_String___getitem__(PikaObj *self, Arg* __key);
|
||||
void PikaStdData_String___init__(PikaObj *self, char* s);
|
||||
Arg* PikaStdData_String___iter__(PikaObj *self);
|
||||
int PikaStdData_String___len__(PikaObj *self);
|
||||
Arg* PikaStdData_String___next__(PikaObj *self);
|
||||
void PikaStdData_String___setitem__(PikaObj *self, Arg* __key, Arg* __val);
|
||||
char* PikaStdData_String___str__(PikaObj *self);
|
||||
Arg* PikaStdData_String_encode(PikaObj *self, PikaTuple* encoding);
|
||||
int PikaStdData_String_endswith(PikaObj *self, char* suffix);
|
||||
char* PikaStdData_String_format(PikaObj *self, PikaTuple* vars);
|
||||
char* PikaStdData_String_get(PikaObj *self);
|
||||
int PikaStdData_String_isalnum(PikaObj *self);
|
||||
int PikaStdData_String_isalpha(PikaObj *self);
|
||||
int PikaStdData_String_isdigit(PikaObj *self);
|
||||
int PikaStdData_String_islower(PikaObj *self);
|
||||
int PikaStdData_String_isspace(PikaObj *self);
|
||||
char* PikaStdData_String_replace(PikaObj *self, char* old, char* new);
|
||||
void PikaStdData_String_set(PikaObj *self, char* s);
|
||||
PikaObj* PikaStdData_String_split(PikaObj *self, char* s);
|
||||
int PikaStdData_String_startswith(PikaObj *self, char* prefix);
|
||||
char* PikaStdData_String_strip(PikaObj *self, PikaTuple* chrs);
|
||||
|
||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_Tuple__H
|
||||
#define __PikaStdData_Tuple__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_Tuple(Args *args);
|
||||
|
||||
int PikaStdData_Tuple___contains__(PikaObj *self, Arg* val);
|
||||
void PikaStdData_Tuple___del__(PikaObj *self);
|
||||
Arg* PikaStdData_Tuple___getitem__(PikaObj *self, Arg* __key);
|
||||
void PikaStdData_Tuple___init__(PikaObj *self);
|
||||
Arg* PikaStdData_Tuple___iter__(PikaObj *self);
|
||||
int PikaStdData_Tuple___len__(PikaObj *self);
|
||||
Arg* PikaStdData_Tuple___next__(PikaObj *self);
|
||||
char* PikaStdData_Tuple___str__(PikaObj *self);
|
||||
Arg* PikaStdData_Tuple_get(PikaObj *self, int i);
|
||||
int PikaStdData_Tuple_len(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_Utils__H
|
||||
#define __PikaStdData_Utils__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_Utils(Args *args);
|
||||
|
||||
Arg* PikaStdData_Utils_int_to_bytes(PikaObj *self, int val);
|
||||
|
||||
#endif
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_dict_items__H
|
||||
#define __PikaStdData_dict_items__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_dict_items(Args *args);
|
||||
|
||||
Arg* PikaStdData_dict_items___iter__(PikaObj *self);
|
||||
int PikaStdData_dict_items___len__(PikaObj *self);
|
||||
Arg* PikaStdData_dict_items___next__(PikaObj *self);
|
||||
char* PikaStdData_dict_items___str__(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdData_dict_keys__H
|
||||
#define __PikaStdData_dict_keys__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdData_dict_keys(Args *args);
|
||||
|
||||
Arg* PikaStdData_dict_keys___iter__(PikaObj *self);
|
||||
int PikaStdData_dict_keys___len__(PikaObj *self);
|
||||
Arg* PikaStdData_dict_keys___next__(PikaObj *self);
|
||||
char* PikaStdData_dict_keys___str__(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdLib__H
|
||||
#define __PikaStdLib__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdLib(Args *args);
|
||||
|
||||
Arg* PikaStdLib_MemChecker(PikaObj *self);
|
||||
Arg* PikaStdLib_RangeObj(PikaObj *self);
|
||||
Arg* PikaStdLib_StringObj(PikaObj *self);
|
||||
Arg* PikaStdLib_SysObj(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdLib_MemChecker__H
|
||||
#define __PikaStdLib_MemChecker__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdLib_MemChecker(Args *args);
|
||||
|
||||
pika_float PikaStdLib_MemChecker_getMax(PikaObj *self);
|
||||
pika_float PikaStdLib_MemChecker_getNow(PikaObj *self);
|
||||
void PikaStdLib_MemChecker_max(PikaObj *self);
|
||||
void PikaStdLib_MemChecker_now(PikaObj *self);
|
||||
void PikaStdLib_MemChecker_resetMax(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdLib_RangeObj__H
|
||||
#define __PikaStdLib_RangeObj__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdLib_RangeObj(Args *args);
|
||||
|
||||
Arg* PikaStdLib_RangeObj___next__(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdLib_StringObj__H
|
||||
#define __PikaStdLib_StringObj__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdLib_StringObj(Args *args);
|
||||
|
||||
Arg* PikaStdLib_StringObj___next__(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdLib_SysObj__H
|
||||
#define __PikaStdLib_SysObj__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdLib_SysObj(Args *args);
|
||||
|
||||
Arg* PikaStdLib_SysObj___getitem__(PikaObj *self, Arg* obj, Arg* key);
|
||||
Arg* PikaStdLib_SysObj___setitem__(PikaObj *self, Arg* obj, Arg* key, Arg* val);
|
||||
Arg* PikaStdLib_SysObj_bytes(PikaObj *self, Arg* val);
|
||||
char* PikaStdLib_SysObj_cformat(PikaObj *self, char* fmt, PikaTuple* var);
|
||||
char* PikaStdLib_SysObj_chr(PikaObj *self, int val);
|
||||
Arg* PikaStdLib_SysObj_dict(PikaObj *self, PikaTuple* val);
|
||||
PikaObj* PikaStdLib_SysObj_dir(PikaObj *self, PikaObj* obj);
|
||||
Arg* PikaStdLib_SysObj_eval(PikaObj *self, char* code);
|
||||
void PikaStdLib_SysObj_exec(PikaObj *self, char* code);
|
||||
void PikaStdLib_SysObj_exit(PikaObj *self);
|
||||
pika_float PikaStdLib_SysObj_float(PikaObj *self, Arg* arg);
|
||||
Arg* PikaStdLib_SysObj_getattr(PikaObj *self, PikaObj* obj, char* name);
|
||||
int PikaStdLib_SysObj_hasattr(PikaObj *self, PikaObj* obj, char* name);
|
||||
void PikaStdLib_SysObj_help(PikaObj *self, char* name);
|
||||
char* PikaStdLib_SysObj_hex(PikaObj *self, int val);
|
||||
int PikaStdLib_SysObj_id(PikaObj *self, Arg* obj);
|
||||
char* PikaStdLib_SysObj_input(PikaObj *self, PikaTuple* info);
|
||||
int PikaStdLib_SysObj_int(PikaObj *self, Arg* arg);
|
||||
Arg* PikaStdLib_SysObj_iter(PikaObj *self, Arg* arg);
|
||||
int PikaStdLib_SysObj_len(PikaObj *self, Arg* arg);
|
||||
Arg* PikaStdLib_SysObj_list(PikaObj *self, PikaTuple* val);
|
||||
PikaObj* PikaStdLib_SysObj_open(PikaObj *self, char* path, char* mode);
|
||||
int PikaStdLib_SysObj_ord(PikaObj *self, char* val);
|
||||
void PikaStdLib_SysObj_print(PikaObj *self, PikaTuple* val, PikaDict* ops);
|
||||
Arg* PikaStdLib_SysObj_range(PikaObj *self, PikaTuple* ax);
|
||||
void PikaStdLib_SysObj_setattr(PikaObj *self, PikaObj* obj, char* name, Arg* val);
|
||||
char* PikaStdLib_SysObj_str(PikaObj *self, Arg* arg);
|
||||
Arg* PikaStdLib_SysObj_type(PikaObj *self, Arg* arg);
|
||||
|
||||
#endif
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdTask__H
|
||||
#define __PikaStdTask__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdTask(Args *args);
|
||||
|
||||
Arg* PikaStdTask_Task(PikaObj *self);
|
||||
|
||||
#endif
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#ifndef __PikaStdTask_Task__H
|
||||
#define __PikaStdTask_Task__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
PikaObj *New_PikaStdTask_Task(Args *args);
|
||||
|
||||
void PikaStdTask_Task___init__(PikaObj *self);
|
||||
void PikaStdTask_Task_call_always(PikaObj *self, Arg* fun_todo);
|
||||
void PikaStdTask_Task_call_period_ms(PikaObj *self, Arg* fun_todo, int period_ms);
|
||||
void PikaStdTask_Task_call_when(PikaObj *self, Arg* fun_todo, Arg* fun_when);
|
||||
void PikaStdTask_Task_platformGetTick(PikaObj *self);
|
||||
void PikaStdTask_Task_run_forever(PikaObj *self);
|
||||
void PikaStdTask_Task_run_once(PikaObj *self);
|
||||
void PikaStdTask_Task_run_until_ms(PikaObj *self, int until_ms);
|
||||
|
||||
#endif
|
|
@ -1,14 +0,0 @@
|
|||
#include "PikaPlatform.h"
|
||||
/* warning: auto generated file, please do not modify */
|
||||
PIKA_BYTECODE_ALIGN const unsigned char pikaModules_py_a[] = {
|
||||
0x7f, 0x70, 0x79, 0x61, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x2c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x83, 0x01, 0x00,
|
||||
0x00, 0x02, 0x13, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x68, 0x65, 0x6c,
|
||||
0x6c, 0x6f, 0x20, 0x50, 0x69, 0x6b, 0x61, 0x50, 0x79, 0x74, 0x68, 0x6f,
|
||||
0x6e, 0x21, 0x00, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00,
|
||||
};
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* [Warning!] This file is auto-generated by pika compiler.
|
||||
* Do not edit it manually.
|
||||
* The source code is *.pyi file.
|
||||
* More details:
|
||||
* English Doc:
|
||||
* https://pikadoc.readthedocs.io/en/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
* Chinese Doc:
|
||||
* https://pikadoc.readthedocs.io/zh/latest/PikaScript%20%E6%A8%A1%E5%9D%97%E6%A6%82%E8%BF%B0.html
|
||||
*/
|
||||
|
||||
#include "PikaMain.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
volatile PikaObj *__pikaMain;
|
||||
PikaObj *pikaScriptInit(void){
|
||||
__platform_printf("======[pikascript packages installed]======\r\n");
|
||||
pks_printVersion();
|
||||
__platform_printf("PikaStdLib==v1.12.0\r\n");
|
||||
__platform_printf("===========================================\r\n");
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
__pikaMain = pikaMain;
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
||||
#if PIKA_INIT_STRING_ENABLE
|
||||
obj_run(pikaMain,
|
||||
"print('hello PikaPython!')\n"
|
||||
"\n");
|
||||
#else
|
||||
obj_runModule((PikaObj*)pikaMain, "main");
|
||||
#endif
|
||||
return pikaMain;
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
/* ******************************** */
|
||||
/* Warning! Don't modify this file! */
|
||||
/* ******************************** */
|
||||
#ifndef __pikaScript__H
|
||||
#define __pikaScript__H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "PikaObj.h"
|
||||
#include "PikaMain.h"
|
||||
|
||||
PikaObj * pikaScriptInit(void);
|
||||
|
||||
#endif
|
|
@ -35,6 +35,11 @@
|
|||
|
||||
const char magic_code_pyo[] = {0x0f, 'p', 'y', 'o'};
|
||||
|
||||
/*
|
||||
* @brief check magic code of pyo file
|
||||
* @param bytecode
|
||||
* @return PIKA_TRUE or PIKA_FALSE
|
||||
*/
|
||||
static PIKA_BOOL _check_magic_code_pyo(uint8_t* bytecode) {
|
||||
char* data = (char*)bytecode;
|
||||
if (data[0] == magic_code_pyo[0] && data[1] == magic_code_pyo[1] &&
|
||||
|
@ -44,6 +49,11 @@ static PIKA_BOOL _check_magic_code_pyo(uint8_t* bytecode) {
|
|||
return PIKA_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief get bytecode from bytes arg
|
||||
* @param self bytes arg
|
||||
* @return bytecode
|
||||
*/
|
||||
static uint8_t* arg_getBytecode(Arg* self) {
|
||||
uint8_t* bytecode_file = arg_getBytes(self);
|
||||
if (_check_magic_code_pyo(bytecode_file)) {
|
||||
|
@ -52,6 +62,11 @@ static uint8_t* arg_getBytecode(Arg* self) {
|
|||
return bytecode_file;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief get bytecode size from bytes arg
|
||||
* @param self bytes arg
|
||||
* @return bytecode size
|
||||
*/
|
||||
static size_t arg_getBytecodeSize(Arg* self) {
|
||||
size_t size_all = arg_getBytesSize(self);
|
||||
uint8_t* bytecode_file = arg_getBytes(self);
|
||||
|
@ -98,7 +113,8 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) {
|
|||
char void_ = 0;
|
||||
FILE* bytecode_f = pika_platform_fopen(output_file_name, "wb+");
|
||||
if (NULL == bytecode_f) {
|
||||
pika_platform_printf("Error: open file %s failed.\r\n", output_file_name);
|
||||
pika_platform_printf("Error: open file %s failed.\r\n",
|
||||
output_file_name);
|
||||
res = PIKA_RES_ERR_IO_ERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
@ -118,8 +134,7 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) {
|
|||
const_pool_size = bytecode_frame.const_pool.size;
|
||||
instruct_array_size = bytecode_frame.instruct_array.size;
|
||||
bytecode_size = const_pool_size + instruct_array_size +
|
||||
sizeof(const_pool_size) +
|
||||
sizeof(instruct_array_size);
|
||||
sizeof(const_pool_size) + sizeof(instruct_array_size);
|
||||
byteCodeFrame_deinit(&bytecode_frame);
|
||||
|
||||
/* step 2, write instruct array to file */
|
||||
|
@ -129,7 +144,7 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) {
|
|||
pika_platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), bytecode_f);
|
||||
/* write ins array size */
|
||||
pika_platform_fwrite(&instruct_array_size, 1, sizeof(instruct_array_size),
|
||||
bytecode_f);
|
||||
bytecode_f);
|
||||
byteCodeFrame_init(&bytecode_frame);
|
||||
bytecode_frame.const_pool.output_f = bytecode_f;
|
||||
bytecode_frame.instruct_array.output_f = bytecode_f;
|
||||
|
@ -140,7 +155,8 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) {
|
|||
byteCodeFrame_deinit(&bytecode_frame);
|
||||
|
||||
/* step 3, write const pool to file */
|
||||
pika_platform_fwrite(&const_pool_size, 1, sizeof(const_pool_size), bytecode_f);
|
||||
pika_platform_fwrite(&const_pool_size, 1, sizeof(const_pool_size),
|
||||
bytecode_f);
|
||||
void_ = 0;
|
||||
/* add \0 at the start */
|
||||
pika_platform_fwrite(&void_, 1, 1, bytecode_f);
|
||||
|
@ -225,7 +241,14 @@ void LibObj_dynamicLink(LibObj* self, char* module_name, uint8_t* bytecode) {
|
|||
obj_setPtr(module_obj, "bytecode", bytecode);
|
||||
}
|
||||
|
||||
/* add bytecode to lib, and copy the bytecode to the buff in the lib */
|
||||
/*
|
||||
* @brief add bytecode to lib, and copy the bytecode to the buff in the lib
|
||||
* @param self the lib obj
|
||||
* @param module_name the module name
|
||||
* @param bytecode the bytecode
|
||||
* @param size the size of the bytecode
|
||||
* @return error code
|
||||
*/
|
||||
int LibObj_staticLink(LibObj* self,
|
||||
char* module_name,
|
||||
uint8_t* bytecode,
|
||||
|
@ -316,14 +339,26 @@ static int32_t __foreach_handler_libWriteIndex(Arg* argEach, Args* context) {
|
|||
module_name = strsReplace(&buffs, module_name, "|", ".");
|
||||
// pika_platform_printf(" %s:%d\r\n", module_name, bytecode_size);
|
||||
pika_platform_memcpy(buff, module_name, strGetSize(module_name));
|
||||
pika_platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE - sizeof(bytecode_size),
|
||||
out_file);
|
||||
pika_platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), out_file);
|
||||
pika_platform_fwrite(
|
||||
buff, 1, LIB_INFO_BLOCK_SIZE - sizeof(bytecode_size), out_file);
|
||||
pika_platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size),
|
||||
out_file);
|
||||
}
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t __foreach_handler_libSumSize(Arg* argEach, Args* context) {
|
||||
if (argType_isObject(arg_getType(argEach))) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
uint32_t bytecode_size = obj_getBytesSize(module_obj, "buff");
|
||||
bytecode_size = aline_by(bytecode_size, sizeof(uint32_t));
|
||||
args_setInt(context, "sum_size",
|
||||
args_getInt(context, "sum_size") + bytecode_size);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t __foreach_handler_getModuleNum(Arg* argEach, Args* context) {
|
||||
if (argType_isObject(arg_getType(argEach))) {
|
||||
args_setInt(context, "module_num",
|
||||
|
@ -338,25 +373,41 @@ int LibObj_saveLibraryFile(LibObj* self, char* output_file_name) {
|
|||
Args context = {0};
|
||||
args_setPtr(&context, "out_file", out_file);
|
||||
args_setInt(&context, "module_num", 0);
|
||||
args_setInt(&context, "sum_size", 0);
|
||||
|
||||
/* write meta information */
|
||||
char buff[LIB_INFO_BLOCK_SIZE] = {0};
|
||||
args_foreach(self->list, __foreach_handler_getModuleNum, &context);
|
||||
|
||||
/* get sum size of pya */
|
||||
args_foreach(self->list, __foreach_handler_libSumSize, &context);
|
||||
|
||||
/* meta info */
|
||||
char magic_code[] = {0x7f, 'p', 'y', 'a'};
|
||||
char magic_code[] = {0x0f, 'p', 'y', 'a'};
|
||||
uint32_t version_num = LIB_VERSION_NUMBER;
|
||||
uint32_t module_num = args_getInt(&context, "module_num");
|
||||
uint32_t modules_size = args_getInt(&context, "sum_size") +
|
||||
(module_num + 1) * LIB_INFO_BLOCK_SIZE -
|
||||
sizeof(uint32_t) * 2;
|
||||
|
||||
/* write meta info */
|
||||
const uint32_t magic_code_offset = sizeof(uint32_t) * 0;
|
||||
const uint32_t version_offset = sizeof(uint32_t) * 1;
|
||||
const uint32_t module_num_offset = sizeof(uint32_t) * 2;
|
||||
const uint32_t magic_code_offset =
|
||||
sizeof(uint32_t) * PIKA_APP_MAGIC_CODE_OFFSET;
|
||||
const uint32_t modules_size_offset =
|
||||
sizeof(uint32_t) * PIKA_APP_MODULE_SIZE_OFFSET;
|
||||
const uint32_t version_offset = sizeof(uint32_t) * PIKA_APP_VERSION_OFFSET;
|
||||
const uint32_t module_num_offset =
|
||||
sizeof(uint32_t) * PIKA_APP_MODULE_NUM_OFFSET;
|
||||
|
||||
pika_platform_memcpy(buff + magic_code_offset, &magic_code, sizeof(uint32_t));
|
||||
pika_platform_memcpy(buff + magic_code_offset, &magic_code,
|
||||
sizeof(uint32_t));
|
||||
pika_platform_memcpy(buff + version_offset, &version_num, sizeof(uint32_t));
|
||||
/* write module_num to the file */
|
||||
pika_platform_memcpy(buff + module_num_offset, &module_num, sizeof(uint32_t));
|
||||
pika_platform_memcpy(buff + module_num_offset, &module_num,
|
||||
sizeof(uint32_t));
|
||||
/* write modules_size to the file */
|
||||
pika_platform_memcpy(buff + modules_size_offset, &modules_size,
|
||||
sizeof(uint32_t));
|
||||
/* aline to 32 bytes */
|
||||
pika_platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE, out_file);
|
||||
/* write module index to file */
|
||||
|
@ -378,11 +429,11 @@ static int _getModuleNum(uint8_t* library_bytes) {
|
|||
char* magic_code = (char*)library_bytes;
|
||||
|
||||
uint32_t* library_info = (uint32_t*)library_bytes;
|
||||
uint32_t version_num = library_info[1];
|
||||
uint32_t module_num = library_info[2];
|
||||
uint32_t version_num = library_info[PIKA_APP_VERSION_OFFSET];
|
||||
uint32_t module_num = library_info[PIKA_APP_MODULE_NUM_OFFSET];
|
||||
|
||||
/* check magic_code */
|
||||
if (!((magic_code[0] == 0x7f) && (magic_code[1] == 'p') &&
|
||||
if (!((magic_code[0] == 0x0f) && (magic_code[1] == 'p') &&
|
||||
(magic_code[2] == 'y') && (magic_code[3] == 'a'))) {
|
||||
pika_platform_printf("Error: invalid magic code.\r\n");
|
||||
return PIKA_RES_ERR_ILLEGAL_MAGIC_CODE;
|
||||
|
@ -479,14 +530,14 @@ int LibObj_loadLibraryFile(LibObj* self, char* lib_file_name) {
|
|||
Arg* file_arg = arg_loadFile(NULL, lib_file_name);
|
||||
if (NULL == file_arg) {
|
||||
pika_platform_printf("Error: Could not load library file '%s'\n",
|
||||
lib_file_name);
|
||||
lib_file_name);
|
||||
return PIKA_RES_ERR_IO_ERROR;
|
||||
}
|
||||
/* save file_arg as @lib_buf to libObj */
|
||||
obj_setArg_noCopy(self, "@lib_buf", file_arg);
|
||||
if (0 != LibObj_loadLibrary(self, arg_getBytes(file_arg))) {
|
||||
pika_platform_printf("Error: Could not load library from '%s'\n",
|
||||
lib_file_name);
|
||||
lib_file_name);
|
||||
return PIKA_RES_ERR_OPERATION_FAILED;
|
||||
}
|
||||
return PIKA_RES_OK;
|
||||
|
@ -503,7 +554,7 @@ int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) {
|
|||
int res = 0;
|
||||
if (NULL == file_arg) {
|
||||
pika_platform_printf("Error: Could not load file '%s'\n",
|
||||
origin_file_name);
|
||||
origin_file_name);
|
||||
return 1;
|
||||
}
|
||||
char* output_file_name = NULL;
|
||||
|
@ -512,8 +563,7 @@ int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) {
|
|||
output_file_name = strsReplace(&buffs, output_file_name, ".", "_");
|
||||
output_file_name = strsAppend(&buffs, output_file_name, ".c");
|
||||
|
||||
char* output_file_path = strsAppend(&buffs, out_folder, "/");
|
||||
output_file_path = strsAppend(&buffs, output_file_path, output_file_name);
|
||||
char* output_file_path = strsPathJoin(&buffs, out_folder, output_file_name);
|
||||
|
||||
FILE* fp = pika_platform_fopen(output_file_path, "wb+");
|
||||
char* array_name = strsGetLastToken(&buffs, origin_file_name, '/');
|
||||
|
@ -551,13 +601,13 @@ static PIKA_RES __Maker_compileModuleWithInfo(PikaMaker* self,
|
|||
Args buffs = {0};
|
||||
char* input_file_name = strsAppend(&buffs, module_name, ".py");
|
||||
char* input_file_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), input_file_name);
|
||||
strsPathJoin(&buffs, obj_getStr(self, "pwd"), input_file_name);
|
||||
pika_platform_printf(" compiling %s...\r\n", input_file_name);
|
||||
char* output_file_name = strsAppend(&buffs, module_name, ".py.o");
|
||||
char* output_file_path = NULL;
|
||||
output_file_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
|
||||
output_file_path = strsAppend(&buffs, output_file_path, output_file_name);
|
||||
strsPathJoin(&buffs, obj_getStr(self, "pwd"), "pikascript-api");
|
||||
output_file_path = strsPathJoin(&buffs, output_file_path, output_file_name);
|
||||
PIKA_RES res =
|
||||
pikaCompileFileWithOutputName(output_file_path, input_file_path);
|
||||
strsDeinit(&buffs);
|
||||
|
@ -573,16 +623,34 @@ PikaMaker* New_PikaMaker(void) {
|
|||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief: deinit PikaMaker
|
||||
* @param: self PikaMaker
|
||||
* @return: void
|
||||
*/
|
||||
void pikaMaker_deinit(PikaMaker* self) {
|
||||
LibObj* lib = obj_getPtr(self, "lib");
|
||||
LibObj_deinit(lib);
|
||||
obj_deinit(self);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief: set pwd
|
||||
* @param: self PikaMaker
|
||||
* @param: pwd
|
||||
* @return: void
|
||||
*/
|
||||
void pikaMaker_setPWD(PikaMaker* self, char* pwd) {
|
||||
obj_setStr(self, "pwd", pwd);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief: set state
|
||||
* @param: self PikaMaker
|
||||
* @param: module_name
|
||||
* @param: state
|
||||
* @return: void
|
||||
*/
|
||||
void pikaMaker_setState(PikaMaker* self, char* module_name, char* state) {
|
||||
obj_newMetaObj(self, module_name, New_TinyObj);
|
||||
PikaObj* module_obj = obj_getObj(self, module_name);
|
||||
|
@ -590,6 +658,12 @@ void pikaMaker_setState(PikaMaker* self, char* module_name, char* state) {
|
|||
obj_setStr(module_obj, "state", state);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief: compile module
|
||||
* @param: self PikaMaker
|
||||
* @param: module_name
|
||||
* @return: PIKA_RES
|
||||
*/
|
||||
PIKA_RES pikaMaker_compileModule(PikaMaker* self, char* module_name) {
|
||||
PIKA_RES res = __Maker_compileModuleWithInfo(self, module_name);
|
||||
/* update compile info */
|
||||
|
@ -609,8 +683,8 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
|
|||
ConstPool* const_pool = NULL;
|
||||
InstructArray* ins_array = NULL;
|
||||
char* module_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
|
||||
module_path = strsAppend(&buffs, module_path, module_name);
|
||||
strsPathJoin(&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
|
||||
module_path = strsPathJoin(&buffs, module_path, module_name);
|
||||
char* file_path = strsAppend(&buffs, module_path, ".py.o");
|
||||
Arg* file_arg = arg_loadFile(NULL, file_path);
|
||||
uint8_t offset_befor = 0;
|
||||
|
@ -633,7 +707,7 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
|
|||
char* imp_module_name =
|
||||
constPool_getByOffset(const_pool, ins_unit->const_pool_index);
|
||||
char* imp_module_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), imp_module_name);
|
||||
strsPathJoin(&buffs, obj_getStr(self, "pwd"), imp_module_name);
|
||||
/* check if compiled the module */
|
||||
if (obj_isArgExist(self, imp_module_name)) {
|
||||
/* module info is exist, do nothing */
|
||||
|
@ -648,15 +722,16 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
|
|||
strsAppend(&buffs, imp_module_path, ".py.o"), "rb");
|
||||
if (NULL != imp_file_pyo) {
|
||||
pika_platform_printf(" loading %s.py.o...\r\n",
|
||||
imp_module_path);
|
||||
imp_module_path);
|
||||
/* found *.py.o, push to compiled list */
|
||||
pikaMaker_setState(self, imp_module_name, "compiled");
|
||||
char* imp_api_path = strsAppend(
|
||||
char* imp_api_path = strsPathJoin(
|
||||
&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
|
||||
imp_api_path =
|
||||
strsAppend(&buffs, imp_api_path, imp_module_name);
|
||||
strsPathJoin(&buffs, imp_api_path, imp_module_name);
|
||||
FILE* imp_file_pyo_api = pika_platform_fopen(
|
||||
strsAppend(&buffs, imp_api_path, ".py.o"), "wb+");
|
||||
pika_assert(imp_file_pyo_api != NULL);
|
||||
/* copy imp_file_pyo to imp_api_path */
|
||||
uint8_t* buff = (uint8_t*)pika_platform_malloc(128);
|
||||
size_t read_size = 0;
|
||||
|
@ -665,7 +740,7 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
|
|||
pika_platform_fread(buff, 1, 128, imp_file_pyo);
|
||||
if (read_size > 0) {
|
||||
pika_platform_fwrite(buff, 1, read_size,
|
||||
imp_file_pyo_api);
|
||||
imp_file_pyo_api);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -712,7 +787,7 @@ int32_t __foreach_handler_printStates(Arg* argEach, Args* context) {
|
|||
if (argType_isObject(arg_getType(argEach))) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
pika_platform_printf("%s: %s\r\n", obj_getStr(module_obj, "name"),
|
||||
obj_getStr(module_obj, "state"));
|
||||
obj_getStr(module_obj, "state"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -752,6 +827,12 @@ char* pikaMaker_getFirstNocompiled(PikaMaker* self) {
|
|||
return obj_getStr(self, "res");
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief compile module with depends
|
||||
* @param self PikaMaker
|
||||
* @param module_name
|
||||
* @return PIKA_RES
|
||||
*/
|
||||
PIKA_RES pikaMaker_compileModuleWithDepends(PikaMaker* self,
|
||||
char* module_name) {
|
||||
PIKA_RES res = PIKA_RES_OK;
|
||||
|
@ -787,10 +868,10 @@ int32_t __foreach_handler_linkCompiledModules(Arg* argEach, Args* context) {
|
|||
char* state = obj_getStr(module_obj, "state");
|
||||
if (strEqu(state, "compiled")) {
|
||||
char* pwd = obj_getStr(maker, "pwd");
|
||||
char* folder_path = strsAppend(&buffs, pwd, "pikascript-api/");
|
||||
char* folder_path = strsPathJoin(&buffs, pwd, "pikascript-api/");
|
||||
char* module_file_name = strsAppend(&buffs, module_name, ".py.o");
|
||||
char* module_file_path =
|
||||
strsAppend(&buffs, folder_path, module_file_name);
|
||||
strsPathJoin(&buffs, folder_path, module_file_name);
|
||||
LibObj_staticLinkFile(lib, module_file_path);
|
||||
}
|
||||
}
|
||||
|
@ -798,8 +879,9 @@ int32_t __foreach_handler_linkCompiledModules(Arg* argEach, Args* context) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||
char* lib_path) {
|
||||
PIKA_RES _do_pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||
char* lib_path,
|
||||
PIKA_BOOL gen_c_array) {
|
||||
PIKA_RES compile_err = (PIKA_RES)obj_getInt(self, "err");
|
||||
if (PIKA_RES_OK != compile_err) {
|
||||
pika_platform_printf(" Error: compile failed, link aborted.\r\n");
|
||||
|
@ -814,27 +896,108 @@ PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
|||
args_foreach(self->list, __foreach_handler_linkCompiledModules, &context);
|
||||
args_deinit_stack(&context);
|
||||
char* pwd = obj_getStr(self, "pwd");
|
||||
char* lib_path_folder = strsCopy(&buffs, lib_path);
|
||||
strPopLastToken(lib_path_folder, '/');
|
||||
char* folder_path = strsAppend(&buffs, pwd, lib_path_folder);
|
||||
folder_path = strsAppend(&buffs, folder_path, "/");
|
||||
char* lib_file_path = strsAppend(&buffs, pwd, lib_path);
|
||||
char* lib_path_folder = strsPathGetFolder(&buffs, lib_path);
|
||||
char* folder_path = strsPathJoin(&buffs, pwd, lib_path_folder);
|
||||
char* lib_file_path = strsPathJoin(&buffs, pwd, lib_path);
|
||||
LibObj_saveLibraryFile(lib, lib_file_path);
|
||||
Lib_loadLibraryFileToArray(lib_file_path, folder_path);
|
||||
if (gen_c_array) {
|
||||
Lib_loadLibraryFileToArray(lib_file_path, folder_path);
|
||||
}
|
||||
strsDeinit(&buffs);
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name) {
|
||||
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||
char* lib_path) {
|
||||
return _do_pikaMaker_linkCompiledModulesFullPath(self, lib_path, PIKA_TRUE);
|
||||
}
|
||||
|
||||
PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
|
||||
char* lib_name,
|
||||
PIKA_BOOL gen_c_array) {
|
||||
Args buffs = {0};
|
||||
char* lib_file_path = strsAppend(&buffs, "pikascript-api/", lib_name);
|
||||
PIKA_RES res = pikaMaker_linkCompiledModulesFullPath(self, lib_file_path);
|
||||
char* lib_file_path = strsPathJoin(&buffs, "pikascript-api/", lib_name);
|
||||
PIKA_RES res = _do_pikaMaker_linkCompiledModulesFullPath(
|
||||
self, lib_file_path, gen_c_array);
|
||||
strsDeinit(&buffs);
|
||||
return res;
|
||||
}
|
||||
|
||||
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name) {
|
||||
return _do_pikaMaker_linkCompiledModules(self, lib_name, PIKA_TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief link raw file to library
|
||||
* @param self PikaMaker
|
||||
* @param file_path
|
||||
* @return PIKA_RES
|
||||
*/
|
||||
PIKA_RES pikaMaker_linkRaw(PikaMaker* self, char* file_path) {
|
||||
LibObj* lib = obj_getPtr(self, "lib");
|
||||
LibObj_staticLinkFile(lib, file_path);
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief open file from library
|
||||
* @param file_name
|
||||
* @param mode "r" or "rb"
|
||||
* @return pikafs_FILE* or NULL if failed
|
||||
*/
|
||||
pikafs_FILE* pikafs_fopen(char* file_name, char* mode) {
|
||||
pikafs_FILE* f = (pikafs_FILE*)pikaMalloc(sizeof(pikafs_FILE));
|
||||
memset(f, 0, sizeof(pikafs_FILE));
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
uint8_t* library_bytes = obj_getPtr((PikaObj*)__pikaMain, "@libraw");
|
||||
if (NULL == library_bytes) {
|
||||
return NULL;
|
||||
}
|
||||
if (PIKA_RES_OK !=
|
||||
_loadModuleDataWithName(library_bytes, file_name, &f->addr, &f->size)) {
|
||||
return NULL;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief read file
|
||||
* @param buf the buffer to read
|
||||
* @param size size of each item
|
||||
* @param count count of items
|
||||
* @param f file
|
||||
* @return read count
|
||||
*/
|
||||
int pikafs_fread(void* buf, size_t size, size_t count, pikafs_FILE* f) {
|
||||
if (f->pos >= f->size) {
|
||||
return 0;
|
||||
}
|
||||
if (f->pos + size * count > f->size) {
|
||||
count = (f->size - f->pos) / size;
|
||||
}
|
||||
__platform_memcpy(buf, f->addr + f->pos, size * count);
|
||||
f->pos += size * count;
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief write file
|
||||
* @param buf the buffer to write
|
||||
* @param size size of each item
|
||||
* @param count count of items
|
||||
* @param f file
|
||||
* @return write count or -1 if failed
|
||||
*/
|
||||
int pikafs_fwrite(void* buf, size_t size, size_t count, pikafs_FILE* file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief close file
|
||||
* @param f file
|
||||
* @return 0 if success
|
||||
*/
|
||||
int pikafs_fclose(pikafs_FILE* file) {
|
||||
pikaFree(file, sizeof(pikafs_FILE));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ char* pikaMaker_getFirstNocompiled(PikaMaker* self);
|
|||
PIKA_RES pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name);
|
||||
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path);
|
||||
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
|
||||
PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
|
||||
char* lib_name,
|
||||
PIKA_BOOL gen_c_array);
|
||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
|
||||
void LibObj_printModules(LibObj* self);
|
||||
void pikaMaker_deinit(PikaMaker* self);
|
||||
|
@ -38,7 +41,22 @@ PIKA_RES _loadModuleDataWithName(uint8_t* library_bytes,
|
|||
uint8_t** addr_p,
|
||||
size_t* size_p);
|
||||
|
||||
#define LIB_VERSION_NUMBER 2
|
||||
#define LIB_VERSION_NUMBER 3
|
||||
#define LIB_INFO_BLOCK_SIZE 32
|
||||
#define PIKA_APP_MAGIC_CODE_OFFSET 0
|
||||
#define PIKA_APP_MODULE_SIZE_OFFSET 1
|
||||
#define PIKA_APP_VERSION_OFFSET 2
|
||||
#define PIKA_APP_MODULE_NUM_OFFSET 3
|
||||
|
||||
typedef struct {
|
||||
uint8_t* addr;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
} pikafs_FILE;
|
||||
|
||||
pikafs_FILE* pikafs_fopen(char* file_name, char* mode);
|
||||
int pikafs_fread(void* buf, size_t size, size_t count, pikafs_FILE* file);
|
||||
int pikafs_fwrite(void* buf, size_t size, size_t count, pikafs_FILE* file);
|
||||
int pikafs_fclose(pikafs_FILE* file);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2023 Gorgon Meducer embedded_zhuroan@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -32,6 +33,7 @@
|
|||
#include "PikaPlatform.h"
|
||||
#include "dataArgs.h"
|
||||
#include "dataMemory.h"
|
||||
#include "dataQueue.h"
|
||||
#include "dataString.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
|
@ -113,6 +115,15 @@ static int32_t obj_deinit_no_del(PikaObj* self) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int obj_GC(PikaObj* self) {
|
||||
obj_refcntDec(self);
|
||||
int ref_cnt = obj_refcntNow(self);
|
||||
if (ref_cnt <= 0) {
|
||||
obj_deinit(self);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t obj_deinit(PikaObj* self) {
|
||||
Arg* del = obj_getMethodArg(self, "__del__");
|
||||
if (NULL != del) {
|
||||
|
@ -219,13 +230,23 @@ PIKA_RES obj_setBytes(PikaObj* self, char* argPath, uint8_t* src, size_t size) {
|
|||
int64_t obj_getInt(PikaObj* self, char* argPath) {
|
||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||
if (NULL == obj) {
|
||||
return -999999999;
|
||||
return _PIKA_INT_ERR;
|
||||
}
|
||||
char* argName = strPointToLastToken(argPath, '.');
|
||||
int64_t res = args_getInt(obj->list, argName);
|
||||
return res;
|
||||
}
|
||||
|
||||
PIKA_BOOL obj_getBool(PikaObj* self, char* argPath) {
|
||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||
if (NULL == obj) {
|
||||
return PIKA_FALSE;
|
||||
}
|
||||
char* argName = strPointToLastToken(argPath, '.');
|
||||
PIKA_BOOL res = args_getBool(obj->list, argName);
|
||||
return res;
|
||||
}
|
||||
|
||||
Arg* obj_getArg(PikaObj* self, char* argPath) {
|
||||
PIKA_BOOL is_temp = PIKA_FALSE;
|
||||
PikaObj* obj = obj_getHostObjWithIsTemp(self, argPath, &is_temp);
|
||||
|
@ -675,9 +696,9 @@ Method methodArg_getPtr(Arg* method_arg) {
|
|||
}
|
||||
|
||||
char* methodArg_getTypeList(Arg* method_arg, char* buffs, size_t size) {
|
||||
MethodProp* method_store = (MethodProp*)arg_getContent(method_arg);
|
||||
if (NULL != method_store->type_list) {
|
||||
return strcpy(buffs, method_store->type_list);
|
||||
MethodProp* prop = (MethodProp*)arg_getContent(method_arg);
|
||||
if (NULL != prop->type_list) {
|
||||
return strcpy(buffs, prop->type_list);
|
||||
}
|
||||
char* method_dec = methodArg_getDec(method_arg);
|
||||
pika_assert(strGetSize(method_dec) <= size);
|
||||
|
@ -692,6 +713,21 @@ char* methodArg_getTypeList(Arg* method_arg, char* buffs, size_t size) {
|
|||
return res;
|
||||
}
|
||||
|
||||
PikaObj* methodArg_getHostObj(Arg* method_arg) {
|
||||
MethodProp* prop = (MethodProp*)arg_getContent(method_arg);
|
||||
return prop->host_obj;
|
||||
}
|
||||
|
||||
int methodArg_setHostObj(Arg* method_arg, PikaObj* host_obj) {
|
||||
MethodProp* prop = (MethodProp*)arg_getContent(method_arg);
|
||||
if (prop->host_obj == NULL) {
|
||||
prop->host_obj = host_obj;
|
||||
// obj_refcntInc(host_obj);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* methodArg_getName(Arg* method_arg, char* buffs, size_t size) {
|
||||
MethodProp* method_store = (MethodProp*)arg_getContent(method_arg);
|
||||
if (NULL != method_store->name) {
|
||||
|
@ -764,6 +800,7 @@ static void obj_saveMethodInfo(PikaObj* self, MethodInfo* method_info) {
|
|||
.bytecode_frame = method_info->bytecode_frame,
|
||||
.def_context = method_info->def_context,
|
||||
.declareation = method_info->dec, // const
|
||||
.host_obj = NULL,
|
||||
};
|
||||
char* name = method_info->name;
|
||||
if (NULL == method_info->name) {
|
||||
|
@ -951,9 +988,174 @@ static void _putc_cmd(char KEY_POS, int pos) {
|
|||
}
|
||||
}
|
||||
|
||||
enum shellCTRL _do_obj_runChar(PikaObj* self,
|
||||
char inputChar,
|
||||
ShellConfig* shell) {
|
||||
#if PIKA_SHELL_FILTER_ENABLE
|
||||
typedef enum {
|
||||
__FILTER_NO_RESULT,
|
||||
__FILTER_FAIL_DROP_ONE,
|
||||
__FILTER_SUCCESS_GET_ALL_PEEKED,
|
||||
__FILTER_SUCCESS_DROP_ALL_PEEKED
|
||||
} FilterReturn;
|
||||
|
||||
PIKA_BOOL _filter_msg_hi_pika_handler(FilterItem* msg,
|
||||
PikaObj* self,
|
||||
ShellConfig* shell) {
|
||||
pika_platform_printf("Yes, I am here\r\n");
|
||||
return PIKA_TRUE;
|
||||
}
|
||||
|
||||
PIKA_BOOL _filter_msg_bye_pika_handler(FilterItem* msg,
|
||||
PikaObj* self,
|
||||
ShellConfig* shell) {
|
||||
pika_platform_printf("OK, see you\r\n");
|
||||
return PIKA_TRUE;
|
||||
}
|
||||
|
||||
#define __MSG_DECLARE
|
||||
#include "__default_filter_msg_table.h"
|
||||
|
||||
static const FilterItem g_default_filter_messages[] = {
|
||||
#define __MSG_TABLE
|
||||
#include "__default_filter_msg_table.h"
|
||||
};
|
||||
|
||||
static FilterReturn _do_message_filter(PikaObj* self,
|
||||
ShellConfig* shell,
|
||||
FilterItem* msg,
|
||||
uint_fast16_t count) {
|
||||
pika_assert(NULL != msg);
|
||||
pika_assert(count > 0);
|
||||
ByteQueue* queue = &shell->filter_fifo.queue;
|
||||
FilterReturn result = __FILTER_FAIL_DROP_ONE;
|
||||
|
||||
do {
|
||||
do {
|
||||
if (msg->ignore_mask & shell->filter_fifo.ignore_mask) {
|
||||
/* this message should be ignored */
|
||||
break;
|
||||
}
|
||||
|
||||
if (NULL == msg->message) {
|
||||
break;
|
||||
}
|
||||
|
||||
uint_fast16_t message_size = msg->size;
|
||||
if (!message_size) {
|
||||
break;
|
||||
}
|
||||
|
||||
byteQueue_resetPeek(queue);
|
||||
|
||||
/* do message comparison */
|
||||
uint8_t* src = (uint8_t*)msg->message;
|
||||
|
||||
if (msg->is_case_insensitive) {
|
||||
do {
|
||||
uint8_t byte;
|
||||
if (!byteQueue_peekOne(queue, &byte)) {
|
||||
result = __FILTER_NO_RESULT;
|
||||
break;
|
||||
}
|
||||
char letter = *src++;
|
||||
|
||||
if (letter >= 'A' && letter <= 'Z') {
|
||||
letter += 'a' - 'A';
|
||||
}
|
||||
|
||||
if (byte >= 'A' && byte <= 'Z') {
|
||||
byte += 'a' - 'A';
|
||||
}
|
||||
|
||||
if (letter != byte) {
|
||||
break;
|
||||
}
|
||||
} while (--message_size);
|
||||
} else {
|
||||
do {
|
||||
uint8_t byte;
|
||||
if (!byteQueue_peekOne(queue, &byte)) {
|
||||
result = __FILTER_NO_RESULT;
|
||||
break;
|
||||
}
|
||||
if (*src++ != byte) {
|
||||
break;
|
||||
}
|
||||
} while (--message_size);
|
||||
}
|
||||
|
||||
if (0 == message_size) {
|
||||
/* message match */
|
||||
if (NULL != msg->handler) {
|
||||
if (!msg->handler(msg, self, shell)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* message is handled */
|
||||
if (msg->is_visible) {
|
||||
return __FILTER_SUCCESS_GET_ALL_PEEKED;
|
||||
}
|
||||
return __FILTER_SUCCESS_DROP_ALL_PEEKED;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
msg++;
|
||||
} while (--count);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef dimof
|
||||
#define dimof(__array) (sizeof(__array) / sizeof(__array[0]))
|
||||
#endif
|
||||
|
||||
int16_t _do_stream_filter(PikaObj* self, ShellConfig* shell) {
|
||||
ByteQueue* queue = &shell->filter_fifo.queue;
|
||||
|
||||
FilterReturn result =
|
||||
_do_message_filter(self, shell, (FilterItem*)g_default_filter_messages,
|
||||
dimof(g_default_filter_messages));
|
||||
int16_t drop_count = 0;
|
||||
|
||||
switch (result) {
|
||||
case __FILTER_NO_RESULT:
|
||||
break;
|
||||
case __FILTER_FAIL_DROP_ONE:
|
||||
drop_count = 1;
|
||||
break;
|
||||
case __FILTER_SUCCESS_DROP_ALL_PEEKED:
|
||||
byteQueue_dropAllPeeked(queue);
|
||||
return 0;
|
||||
case __FILTER_SUCCESS_GET_ALL_PEEKED:
|
||||
drop_count = byteQueue_getPeekedNumber(queue);
|
||||
return drop_count;
|
||||
}
|
||||
|
||||
/* user registered message filter */
|
||||
if (NULL != shell->messages && shell->message_count) {
|
||||
result = _do_message_filter(self, shell, shell->messages,
|
||||
shell->message_count);
|
||||
switch (result) {
|
||||
case __FILTER_NO_RESULT:
|
||||
break;
|
||||
case __FILTER_FAIL_DROP_ONE:
|
||||
drop_count = 1;
|
||||
break;
|
||||
case __FILTER_SUCCESS_DROP_ALL_PEEKED:
|
||||
byteQueue_dropAllPeeked(&shell->filter_fifo.queue);
|
||||
return 0;
|
||||
case __FILTER_SUCCESS_GET_ALL_PEEKED:
|
||||
drop_count =
|
||||
byteQueue_getPeekedNumber(&shell->filter_fifo.queue);
|
||||
return drop_count;
|
||||
}
|
||||
}
|
||||
|
||||
return drop_count;
|
||||
}
|
||||
#endif
|
||||
|
||||
enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
|
||||
char inputChar,
|
||||
ShellConfig* shell) {
|
||||
char* input_line = NULL;
|
||||
enum shellCTRL ctrl = SHELL_CTRL_CONTINUE;
|
||||
#if !(defined(__linux) || defined(_WIN32))
|
||||
|
@ -1055,7 +1257,7 @@ enum shellCTRL _do_obj_runChar(PikaObj* self,
|
|||
goto exit;
|
||||
}
|
||||
if ((inputChar == '\r') || (inputChar == '\n')) {
|
||||
#if !(defined(__linux) || defined(_WIN32))
|
||||
#if !(defined(__linux) || defined(_WIN32) || PIKA_SHELL_NO_NEWLINE)
|
||||
pika_platform_printf("\r\n");
|
||||
#endif
|
||||
/* still in block */
|
||||
|
@ -1108,6 +1310,48 @@ exit:
|
|||
return ctrl;
|
||||
}
|
||||
|
||||
PIKA_WEAK
|
||||
enum shellCTRL _do_obj_runChar(PikaObj* self,
|
||||
char inputChar,
|
||||
ShellConfig* shell) {
|
||||
#if PIKA_SHELL_FILTER_ENABLE
|
||||
ByteQueue* queue = &(shell->filter_fifo.queue);
|
||||
|
||||
/* validation */
|
||||
if (NULL == queue->buffer) {
|
||||
/* need initialize first */
|
||||
byteQueue_init(queue, &shell->filter_fifo.buffer,
|
||||
sizeof(shell->filter_fifo.buffer), PIKA_FALSE);
|
||||
}
|
||||
|
||||
PIKA_BOOL result = byteQueue_writeOne(queue, inputChar);
|
||||
pika_assert(result != PIKA_FALSE);
|
||||
|
||||
int16_t byte_count;
|
||||
do {
|
||||
if (0 == byteQueue_peekAvailableCount(queue)) {
|
||||
break;
|
||||
}
|
||||
byte_count = _do_stream_filter(self, shell);
|
||||
int16_t n = byte_count;
|
||||
|
||||
while (n--) {
|
||||
PIKA_BOOL result = byteQueue_readOne(queue, (uint8_t*)&inputChar);
|
||||
pika_assert(result != PIKA_FALSE);
|
||||
|
||||
if (SHELL_CTRL_EXIT ==
|
||||
_inner_do_obj_runChar(self, inputChar, shell)) {
|
||||
return SHELL_CTRL_EXIT;
|
||||
}
|
||||
}
|
||||
} while (byte_count);
|
||||
|
||||
return SHELL_CTRL_CONTINUE;
|
||||
#else
|
||||
return _inner_do_obj_runChar(self, inputChar, shell);
|
||||
#endif
|
||||
}
|
||||
|
||||
enum shellCTRL obj_runChar(PikaObj* self, char inputChar) {
|
||||
ShellConfig* shell = args_getStruct(self->list, "@shcfg");
|
||||
if (NULL == shell) {
|
||||
|
@ -1124,6 +1368,22 @@ enum shellCTRL obj_runChar(PikaObj* self, char inputChar) {
|
|||
return _do_obj_runChar(self, inputChar, shell);
|
||||
}
|
||||
|
||||
static void _save_file(char* file_name, uint8_t* buff, size_t size) {
|
||||
pika_platform_printf("[ Info] Saving file to '%s'...\r\n", file_name);
|
||||
FILE* fp = pika_platform_fopen(file_name, "wb+");
|
||||
if (NULL == fp) {
|
||||
pika_platform_printf("[ Error] Open file '%s' error!\r\n", file_name);
|
||||
pika_platform_fclose(fp);
|
||||
} else {
|
||||
pika_platform_fwrite(buff, 1, size, fp);
|
||||
pika_platform_printf("[ Info] Writing %d bytes to '%s'...\r\n",
|
||||
(int)(size), file_name);
|
||||
pika_platform_fclose(fp);
|
||||
pika_platform_printf("[ OK ] Writing to '%s' succeed!\r\n",
|
||||
file_name);
|
||||
}
|
||||
}
|
||||
|
||||
void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
|
||||
/* init the shell */
|
||||
_obj_runChar_beforeRun(self, cfg);
|
||||
|
@ -1186,23 +1446,7 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
|
|||
(int)PIKA_READ_FILE_BUFF_SIZE,
|
||||
((float)len / (float)PIKA_READ_FILE_BUFF_SIZE));
|
||||
#if PIKA_SHELL_SAVE_FILE_ENABLE
|
||||
char* file_name = PIKA_SHELL_SAVE_FILE_NAME;
|
||||
pika_platform_printf("[ Info] Saving file to '%s'...\r\n",
|
||||
file_name);
|
||||
FILE* fp = pika_platform_fopen(file_name, "w+");
|
||||
if (NULL == fp) {
|
||||
pika_platform_printf("[ Error] Open file '%s' error!\r\n",
|
||||
file_name);
|
||||
pika_platform_fclose(fp);
|
||||
} else {
|
||||
pika_platform_fwrite(buff, 1, len, fp);
|
||||
pika_platform_printf(
|
||||
"[ Info] Writing %d bytes to '%s'...\r\n", (int)(len),
|
||||
file_name);
|
||||
pika_platform_fclose(fp);
|
||||
pika_platform_printf("[ OK ] Writing to '%s' succeed!\r\n",
|
||||
file_name);
|
||||
}
|
||||
_save_file(PIKA_SHELL_SAVE_FILE_PATH, (uint8_t*)buff, len);
|
||||
#endif
|
||||
pika_platform_printf("=============== [ Run] ===============\r\n");
|
||||
obj_run(self, (char*)buff);
|
||||
|
@ -1219,26 +1463,45 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
|
|||
|
||||
/* run xx.py.o */
|
||||
if (inputChar[0] == 'p' && inputChar[1] == 0x0f) {
|
||||
uint8_t magic_code[4] = {0x0f, 'p', 0x00, 0x00};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
/* eat 'yo' */
|
||||
cfg->fn_getchar();
|
||||
magic_code[2 + i] = cfg->fn_getchar();
|
||||
}
|
||||
uint32_t size = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
uint8_t* size_byte = (uint8_t*)&size;
|
||||
size_byte[i] = cfg->fn_getchar();
|
||||
}
|
||||
size += sizeof(uint32_t) * 2;
|
||||
uint8_t* buff = pikaMalloc(size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
/* save magic code and size */
|
||||
memcpy(buff, magic_code, sizeof(magic_code));
|
||||
memcpy(buff + sizeof(magic_code), &size, sizeof(size));
|
||||
|
||||
for (uint32_t i = sizeof(uint32_t) * 2; i < size; i++) {
|
||||
buff[i] = cfg->fn_getchar();
|
||||
}
|
||||
|
||||
pika_platform_printf(
|
||||
"\r\n=============== [Code] ===============\r\n");
|
||||
pika_platform_printf("[ Info] Bytecode size: %d\r\n", size);
|
||||
pika_platform_printf("=============== [ RUN] ===============\r\n");
|
||||
pikaVM_runByteCodeInconstant(self, buff);
|
||||
pikaFree(buff, size);
|
||||
return;
|
||||
"\r\n=============== [File] ===============\r\n");
|
||||
pika_platform_printf("[ Info] Recived size: %d\r\n", size);
|
||||
if (magic_code[3] == 'o') {
|
||||
#if PIKA_SHELL_SAVE_BYTECODE_ENABLE
|
||||
_save_file(PIKA_SHELL_SAVE_BYTECODE_PATH, (uint8_t*)buff, size);
|
||||
#endif
|
||||
pika_platform_printf(
|
||||
"=============== [ RUN] ===============\r\n");
|
||||
pikaVM_runByteCodeInconstant(self, buff);
|
||||
pikaFree(buff, size);
|
||||
return;
|
||||
}
|
||||
if (magic_code[3] == 'a') {
|
||||
_save_file(PIKA_SHELL_SAVE_APP_PATH, (uint8_t*)buff, size);
|
||||
pika_platform_printf(
|
||||
"=============== [REBOOT] ===============\r\n");
|
||||
pika_platform_reboot();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (SHELL_CTRL_EXIT == _do_obj_runChar(self, inputChar[0], cfg)) {
|
||||
|
@ -1337,6 +1600,13 @@ void method_returnInt(Args* args, int64_t val) {
|
|||
args_pushArg_name(args, "@rt", arg_newInt(val));
|
||||
}
|
||||
|
||||
void method_returnBool(Args* args, PIKA_BOOL val) {
|
||||
if (val == _PIKA_BOOL_ERR) {
|
||||
return;
|
||||
}
|
||||
args_pushArg_name(args, "@rt", arg_newBool(val));
|
||||
}
|
||||
|
||||
void method_returnFloat(Args* args, pika_float val) {
|
||||
args_pushArg_name(args, "@rt", arg_newFloat(val));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2023 Gorgon Meducer embedded_zhuroan@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -32,6 +33,7 @@
|
|||
#include "dataLink.h"
|
||||
#include "dataMemory.h"
|
||||
#include "dataStrs.h"
|
||||
#include "dataQueue.h"
|
||||
|
||||
typedef struct InstructUnit InstructUnit;
|
||||
struct InstructUnit {
|
||||
|
@ -135,6 +137,7 @@ typedef struct MethodProp {
|
|||
char* name;
|
||||
ByteCodeFrame* bytecode_frame;
|
||||
PikaObj* def_context;
|
||||
PikaObj* host_obj;
|
||||
char* declareation;
|
||||
} MethodProp;
|
||||
|
||||
|
@ -151,6 +154,7 @@ typedef PikaObj PikaMaker;
|
|||
|
||||
/* operation */
|
||||
int32_t obj_deinit(PikaObj* self);
|
||||
int obj_GC(PikaObj* self);
|
||||
int32_t obj_init(PikaObj* self, Args* args);
|
||||
int32_t obj_update(PikaObj* self);
|
||||
int32_t obj_enable(PikaObj* self);
|
||||
|
@ -171,6 +175,7 @@ void* obj_getPtr(PikaObj* self, char* argPath);
|
|||
pika_float obj_getFloat(PikaObj* self, char* argPath);
|
||||
char* obj_getStr(PikaObj* self, char* argPath);
|
||||
int64_t obj_getInt(PikaObj* self, char* argPath);
|
||||
PIKA_BOOL obj_getBool(PikaObj* self, char* argPath);
|
||||
Arg* obj_getArg(PikaObj* self, char* argPath);
|
||||
uint8_t* obj_getBytes(PikaObj* self, char* argPath);
|
||||
size_t obj_getBytesSize(PikaObj* self, char* argPath);
|
||||
|
@ -245,6 +250,7 @@ uint8_t obj_getAnyArg(PikaObj* self,
|
|||
|
||||
void method_returnStr(Args* args, char* val);
|
||||
void method_returnInt(Args* args, int64_t val);
|
||||
void method_returnBool(Args* args, PIKA_BOOL val);
|
||||
void method_returnFloat(Args* args, pika_float val);
|
||||
void method_returnPtr(Args* args, void* val);
|
||||
void method_returnObj(Args* args, void* val);
|
||||
|
@ -255,6 +261,8 @@ void method_returnArg(Args* args, Arg* arg);
|
|||
char* methodArg_getDec(Arg* method_arg);
|
||||
char* methodArg_getTypeList(Arg* method_arg, char* buffs, size_t size);
|
||||
char* methodArg_getName(Arg* method_arg, char* buffs, size_t size);
|
||||
int methodArg_setHostObj(Arg* method_arg, PikaObj* host_obj);
|
||||
PikaObj* methodArg_getHostObj(Arg* method_arg);
|
||||
ByteCodeFrame* methodArg_getBytecodeFrame(Arg* method_arg);
|
||||
Method methodArg_getPtr(Arg* method_arg);
|
||||
|
||||
|
@ -273,7 +281,40 @@ typedef struct ShellConfig ShellConfig;
|
|||
typedef enum shellCTRL (*sh_handler)(PikaObj*, char*, ShellConfig*);
|
||||
typedef char (*sh_getchar)(void);
|
||||
|
||||
|
||||
#if PIKA_SHELL_FILTER_ENABLE
|
||||
typedef struct FilterFIFO {
|
||||
ByteQueue queue;
|
||||
uint8_t ignore_mask;
|
||||
uint8_t buffer[PIKA_SHELL_FILTER_FIFO_SIZE];
|
||||
} FilterFIFO;
|
||||
|
||||
typedef struct FilterItem FilterItem;
|
||||
|
||||
typedef PIKA_BOOL FilterMessageHandler( FilterItem *msg,
|
||||
PikaObj* self,
|
||||
ShellConfig* shell);
|
||||
|
||||
struct FilterItem {
|
||||
FilterMessageHandler *handler;
|
||||
const uint8_t *message;
|
||||
uint16_t size;
|
||||
uint8_t is_visible : 1;
|
||||
uint8_t is_case_insensitive : 1;
|
||||
uint8_t : 6;
|
||||
uint8_t ignore_mask;
|
||||
uintptr_t target;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct ShellConfig {
|
||||
#if PIKA_SHELL_FILTER_ENABLE
|
||||
FilterFIFO filter_fifo;
|
||||
FilterItem *messages;
|
||||
uint16_t message_count;
|
||||
uint16_t : 16; /* padding to suppress warning*/
|
||||
#endif
|
||||
char* prefix;
|
||||
sh_handler handler;
|
||||
void* context;
|
||||
|
@ -306,11 +347,11 @@ Arg* arg_setRef(Arg* self, char* name, PikaObj* obj);
|
|||
Arg* arg_setObj(Arg* self, char* name, PikaObj* obj);
|
||||
|
||||
static inline Arg* arg_newObj(PikaObj* obj) {
|
||||
return arg_setObj(NULL, "", (obj));
|
||||
return arg_setObj(NULL, (char*)"", (obj));
|
||||
}
|
||||
|
||||
static inline Arg* arg_newRef(PikaObj* obj) {
|
||||
return arg_setRef(NULL, "", (obj));
|
||||
return arg_setRef(NULL, (char*)"", (obj));
|
||||
}
|
||||
|
||||
PikaObj* obj_importModuleWithByteCodeFrame(PikaObj* self,
|
||||
|
@ -389,14 +430,14 @@ static inline uint8_t obj_refcntNow(PikaObj* self) {
|
|||
#define obj_setStruct(PikaObj_p_self, char_p_name, struct_) \
|
||||
args_setStruct(((PikaObj_p_self)->list), char_p_name, struct_)
|
||||
|
||||
#define ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(_) \
|
||||
obj_setErrorCode(self, 1); \
|
||||
#define ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(_) \
|
||||
obj_setErrorCode(self, 1); \
|
||||
pika_platform_printf("Error: abstract method `%s()` need override.\r\n", \
|
||||
__FUNCTION__)
|
||||
__FUNCTION__)
|
||||
|
||||
char* obj_cacheStr(PikaObj* self, char* str);
|
||||
PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp);
|
||||
char* __printBytes(PikaObj* self, Arg* arg);
|
||||
Arg* arg_toStrArg(Arg* arg);
|
||||
|
||||
#define PIKASCRIPT_VERSION_TO_NUM(majer, minor, micro) \
|
||||
majer * 100 * 100 + minor * 100 + micro
|
||||
|
@ -516,5 +557,16 @@ Arg* pks_eventListener_sendSignalAwaitResult(PikaEventListener* self,
|
|||
int eventSignal);
|
||||
|
||||
void obj_printModules(PikaObj* self);
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
#define pika_debug(fmt, ...) \
|
||||
pika_platform_printf("PikaDBG: " fmt "\r\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define pika_debug(...) \
|
||||
do { \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
int pika_GIL_EXIT(void);
|
||||
int pika_GIL_ENTER(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -55,8 +55,9 @@ void Cursor_iterEnd(struct Cursor* cs);
|
|||
void Cursor_deinit(struct Cursor* cs);
|
||||
|
||||
/* Cursor high level api */
|
||||
char* Cursor_popToken(Args* buffs, char** stmt, char* devide);
|
||||
char* Cursor_popToken(Args* buffs, char** pStmt, char* devide);
|
||||
PIKA_BOOL Cursor_isContain(char* stmt, TokenType type, char* pyload);
|
||||
char* Cursor_splitCollect(Args* buffs, char* stmt, char* devide, int index);
|
||||
|
||||
char* Parser_linesToAsm(Args* outBuffs, char* multiLine);
|
||||
uint16_t TokenStream_getSize(char* tokenStream) {
|
||||
|
@ -66,15 +67,12 @@ uint16_t TokenStream_getSize(char* tokenStream) {
|
|||
return strCountSign(tokenStream, 0x1F) + 1;
|
||||
}
|
||||
|
||||
char* strsPopTokenWithSkip_byStr(Args* outBuffs,
|
||||
char* stmts,
|
||||
char* str,
|
||||
char skipStart,
|
||||
char skipEnd) {
|
||||
char* Cursor_popLastToken(Args* outBuffs, char** pStmt, char* str) {
|
||||
char* stmts = *pStmt;
|
||||
uint8_t divider_index = 0;
|
||||
Arg* keeped_arg = arg_newStr("");
|
||||
Arg* poped_arg = arg_newStr("");
|
||||
Cursor_forEachToken(cs, stmts) {
|
||||
Cursor_forEach(cs, stmts) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (cs.branket_deepth == 0) {
|
||||
if (strEqu(str, cs.token1.pyload)) {
|
||||
|
@ -84,7 +82,7 @@ char* strsPopTokenWithSkip_byStr(Args* outBuffs,
|
|||
Cursor_iterEnd(&cs);
|
||||
}
|
||||
Cursor_deinit(&cs);
|
||||
Cursor_forEachTokenExistPs(cs, stmts) {
|
||||
Cursor_forEachExistPs(cs, stmts) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (cs.iter_index < divider_index) {
|
||||
poped_arg = arg_strAppend(poped_arg, cs.token1.pyload);
|
||||
|
@ -95,21 +93,21 @@ char* strsPopTokenWithSkip_byStr(Args* outBuffs,
|
|||
Cursor_iterEnd(&cs);
|
||||
}
|
||||
Cursor_deinit(&cs);
|
||||
char* keeped = arg_getStr(keeped_arg);
|
||||
char* poped = strsCopy(outBuffs, arg_getStr(poped_arg));
|
||||
pika_platform_memcpy(stmts, keeped, strGetSize(keeped) + 1);
|
||||
char* keeped = strsCopy(outBuffs, arg_getStr(keeped_arg));
|
||||
char* poped = arg_getStr(poped_arg);
|
||||
pika_platform_memcpy(stmts, poped, strGetSize(poped) + 1);
|
||||
arg_deinit(poped_arg);
|
||||
arg_deinit(keeped_arg);
|
||||
return poped;
|
||||
return keeped;
|
||||
}
|
||||
|
||||
char* strsGetCleanCmd(Args* outBuffs, char* cmd) {
|
||||
char* Cursor_getCleanStmt(Args* outBuffs, char* cmd) {
|
||||
pika_assert(cmd != NULL);
|
||||
int32_t size = strGetSize(cmd);
|
||||
/* lexer may generate more chars than input */
|
||||
char* strOut = args_getBuff(outBuffs, size * 2);
|
||||
int32_t iOut = 0;
|
||||
Cursor_forEachToken(cs, cmd) {
|
||||
Cursor_forEach(cs, cmd) {
|
||||
Cursor_iterStart(&cs);
|
||||
for (uint16_t k = 0; k < strGetSize(cs.token1.pyload); k++) {
|
||||
strOut[iOut] = cs.token1.pyload[k];
|
||||
|
@ -144,7 +142,7 @@ static char* Cursor_removeTokensBetween(Args* outBuffs,
|
|||
Args buffs = {0};
|
||||
uint8_t block_deepth = 0;
|
||||
char* output = "";
|
||||
Cursor_forEachToken(cs, input) {
|
||||
Cursor_forEach(cs, input) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (strEqu(token_pyload1, cs.token1.pyload)) {
|
||||
if (block_deepth == 0) {
|
||||
|
@ -193,7 +191,7 @@ static enum StmtType Lexer_matchStmtType(char* right) {
|
|||
PIKA_BOOL is_get_dict = PIKA_FALSE;
|
||||
PIKA_BOOL is_get_import = PIKA_FALSE;
|
||||
PIKA_BOOL is_get_chain = PIKA_FALSE;
|
||||
Cursor_forEachToken(cs, rightWithoutSubStmt) {
|
||||
Cursor_forEach(cs, rightWithoutSubStmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
/* collect type */
|
||||
if (strEqu(cs.token1.pyload, " import ")) {
|
||||
|
@ -798,7 +796,7 @@ static char* _solveEqualLevelOperator(Args* buffs,
|
|||
char* op2,
|
||||
char* stmt) {
|
||||
if ((strEqu(operator, op1)) || (strEqu(operator, op2))) {
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (strEqu(cs.token1.pyload, op1)) {
|
||||
operator= strsCopy(buffs, op1);
|
||||
|
@ -826,7 +824,7 @@ char* Lexer_getOperator(Args* outBuffs, char* stmt) {
|
|||
|
||||
// use parse state foreach to get operator
|
||||
for (uint32_t i = 0; i < sizeof(operators) / 9; i++) {
|
||||
Cursor_forEachToken(cs, tokenStream) {
|
||||
Cursor_forEach(cs, tokenStream) {
|
||||
Cursor_iterStart(&cs);
|
||||
// get operator
|
||||
if (strEqu(cs.token2.pyload, (char*)operators[i])) {
|
||||
|
@ -842,7 +840,7 @@ char* Lexer_getOperator(Args* outBuffs, char* stmt) {
|
|||
|
||||
/* solve the iuuse of "~-1" */
|
||||
if (strEqu(operator, "-")) {
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (strEqu(cs.token2.pyload, "-")) {
|
||||
if (cs.token1.type == TOKEN_operator) {
|
||||
|
@ -980,11 +978,11 @@ PIKA_BOOL Cursor_isContain(char* stmt, TokenType type, char* pyload) {
|
|||
return res;
|
||||
}
|
||||
|
||||
char* Cursor_popToken(Args* buffs, char** tokenStream, char* devide) {
|
||||
char* Cursor_popToken(Args* buffs, char** pStmt, char* devide) {
|
||||
Arg* out_item = arg_newStr("");
|
||||
Arg* tokenStream_after = arg_newStr("");
|
||||
PIKA_BOOL is_find_devide = PIKA_FALSE;
|
||||
Cursor_forEachToken(cs, *tokenStream) {
|
||||
Cursor_forEach(cs, *pStmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (!is_find_devide) {
|
||||
if ((cs.branket_deepth == 0 && strEqu(cs.token1.pyload, devide)) ||
|
||||
|
@ -1010,10 +1008,39 @@ char* Cursor_popToken(Args* buffs, char** tokenStream, char* devide) {
|
|||
char* token_after_str = strsCopy(buffs, arg_getStr(tokenStream_after));
|
||||
arg_deinit(tokenStream_after);
|
||||
/* update tokenStream */
|
||||
*tokenStream = token_after_str;
|
||||
*pStmt = token_after_str;
|
||||
return out_item_str;
|
||||
}
|
||||
|
||||
char* Cursor_splitCollect(Args* buffs, char* stmt, char* devide, int index) {
|
||||
Arg* aOut = arg_newStr("");
|
||||
int expect_branket = 0;
|
||||
if (devide[0] == '(' || devide[0] == '[' || devide[0] == '{') {
|
||||
expect_branket = 1;
|
||||
}
|
||||
int i = 0;
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (cs.branket_deepth == expect_branket &&
|
||||
strEqu(cs.token1.pyload, devide)) {
|
||||
i++;
|
||||
Cursor_iterEnd(&cs);
|
||||
continue;
|
||||
}
|
||||
if (i == index) {
|
||||
aOut = arg_strAppend(aOut, cs.token1.pyload);
|
||||
}
|
||||
Cursor_iterEnd(&cs);
|
||||
}
|
||||
Cursor_deinit(&cs);
|
||||
/* if not found, return origin string */
|
||||
if (i == 0) {
|
||||
arg_deinit(aOut);
|
||||
aOut = arg_newStr(stmt);
|
||||
}
|
||||
return strsCacheArg(buffs, aOut);
|
||||
}
|
||||
|
||||
static void Slice_getPars(Args* outBuffs,
|
||||
char* inner,
|
||||
char** pStart,
|
||||
|
@ -1029,7 +1056,7 @@ static void Slice_getPars(Args* outBuffs,
|
|||
|
||||
/* slice */
|
||||
uint8_t colon_i = 0;
|
||||
Cursor_forEachToken(cs, inner) {
|
||||
Cursor_forEach(cs, inner) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (strEqu(cs.token1.pyload, ":") && cs.branket_deepth == 0) {
|
||||
colon_i++;
|
||||
|
@ -1093,7 +1120,7 @@ char* Suger_leftSlice(Args* outBuffs, char* right, char** left_p) {
|
|||
/* exit when not match
|
||||
(symble|iteral)'['
|
||||
*/
|
||||
Cursor_forEachToken(cs, left) {
|
||||
Cursor_forEach(cs, left) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (strEqu(cs.token2.pyload, "[")) {
|
||||
if (TOKEN_symbol == cs.token1.type ||
|
||||
|
@ -1114,7 +1141,7 @@ char* Suger_leftSlice(Args* outBuffs, char* right, char** left_p) {
|
|||
}
|
||||
|
||||
/* matched [] */
|
||||
Cursor_forEachTokenExistPs(cs, left) {
|
||||
Cursor_forEachExistPs(cs, left) {
|
||||
Cursor_iterStart(&cs);
|
||||
/* found '[' */
|
||||
if ((TOKEN_devider == cs.token2.type) &&
|
||||
|
@ -1188,7 +1215,7 @@ char* Suger_format(Args* outBuffs, char* right) {
|
|||
}
|
||||
|
||||
PIKA_BOOL is_format = PIKA_FALSE;
|
||||
Cursor_forEachToken(ps1, right) {
|
||||
Cursor_forEach(ps1, right) {
|
||||
Cursor_iterStart(&ps1);
|
||||
if (ps1.branket_deepth == 0 && strEqu(ps1.token1.pyload, "%")) {
|
||||
is_format = PIKA_TRUE;
|
||||
|
@ -1208,7 +1235,7 @@ char* Suger_format(Args* outBuffs, char* right) {
|
|||
PIKA_BOOL is_out_vars = PIKA_FALSE;
|
||||
Args buffs = {0};
|
||||
char* fmt = NULL;
|
||||
Cursor_forEachToken(cs, right) {
|
||||
Cursor_forEach(cs, right) {
|
||||
char* item = "";
|
||||
Cursor_iterStart(&cs);
|
||||
if (PIKA_FALSE == is_in_format) {
|
||||
|
@ -1311,7 +1338,7 @@ uint8_t Suger_selfOperator(Args* outbuffs,
|
|||
}
|
||||
/* found self operator */
|
||||
is_left_exist = 1;
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if ((strEqu(cs.token1.pyload, "*=")) ||
|
||||
(strEqu(cs.token1.pyload, "/=")) ||
|
||||
|
@ -1384,7 +1411,7 @@ char* Parser_popSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
|
|||
char* stmt = *stmt_p;
|
||||
PIKA_BOOL is_get_substmt = PIKA_FALSE;
|
||||
Args buffs = {0};
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (is_get_substmt) {
|
||||
/* get new stmt */
|
||||
|
@ -1421,7 +1448,7 @@ char* Parser_popSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
|
|||
char* Parser_popLastSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
|
||||
uint8_t last_stmt_i = 0;
|
||||
char* stmt = *stmt_p;
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (strIsStartWith(cs.token1.pyload, delimiter)) {
|
||||
/* found delimiter */
|
||||
|
@ -1447,7 +1474,7 @@ char* Parser_popLastSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
|
|||
Arg* mainStmt = arg_newStr("");
|
||||
Arg* lastStmt = arg_newStr("");
|
||||
{
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (cs.iter_index < last_stmt_i) {
|
||||
mainStmt = arg_strAppend(mainStmt, cs.token1.pyload);
|
||||
|
@ -1548,7 +1575,7 @@ char* Suger_not_in(Args* out_buffs, char* line) {
|
|||
}
|
||||
|
||||
/* stmt1 not in stmt2 => not stmt1 in stmt2 */
|
||||
Cursor_forEachToken(cs, line) {
|
||||
Cursor_forEach(cs, line) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (!got_not_in) {
|
||||
if (strEqu(cs.token1.pyload, " not ") &&
|
||||
|
@ -1583,7 +1610,7 @@ __exit:
|
|||
|
||||
AST* AST_parseStmt(AST* ast, char* stmt) {
|
||||
Args buffs = {0};
|
||||
char* assignment = strsGetFirstToken(&buffs, stmt, '(');
|
||||
char* assignment = Cursor_splitCollect(&buffs, stmt, "(", 0);
|
||||
char* method = NULL;
|
||||
char* ref = NULL;
|
||||
char* str = NULL;
|
||||
|
@ -1601,7 +1628,7 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
|||
left = strsCopy(&buffs, "");
|
||||
right = strsCopy(&buffs, "");
|
||||
uint8_t is_meet_equ = 0;
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_forEach(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (!is_meet_equ && strEqu(cs.token1.pyload, "=") &&
|
||||
cs.token1.type == TOKEN_operator) {
|
||||
|
@ -1630,7 +1657,8 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
|||
|
||||
/* set left */
|
||||
if (isLeftExist) {
|
||||
AST_setNodeAttr(ast, (char*)"left", left);
|
||||
char* left_without_hint = Cursor_splitCollect(&buffs, left, ":", 0);
|
||||
AST_setNodeAttr(ast, (char*)"left", left_without_hint);
|
||||
}
|
||||
/* match statment type */
|
||||
enum StmtType stmtType = Lexer_matchStmtType(right);
|
||||
|
@ -1649,9 +1677,8 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
|||
}
|
||||
AST_setNodeAttr(ast, (char*)"operator", operator);
|
||||
char* rightBuff = strsCopy(&buffs, right);
|
||||
char* subStmt1 =
|
||||
strsPopTokenWithSkip_byStr(&buffs, rightBuff, operator, '(', ')');
|
||||
char* subStmt2 = rightBuff;
|
||||
char* subStmt2 = Cursor_popLastToken(&buffs, &rightBuff, operator);
|
||||
char* subStmt1 = rightBuff;
|
||||
AST_parseSubStmt(ast, subStmt1);
|
||||
AST_parseSubStmt(ast, subStmt2);
|
||||
goto exit;
|
||||
|
@ -1689,7 +1716,10 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
|||
method = strsGetFirstToken(&buffs, right, '(');
|
||||
AST_setNodeAttr(ast, (char*)"method", method);
|
||||
char* subStmts = strsCut(&buffs, right, '(', ')');
|
||||
pika_assert(NULL != subStmts);
|
||||
if (NULL == subStmts) {
|
||||
result = PIKA_RES_ERR_SYNTAX_ERROR;
|
||||
goto exit;
|
||||
}
|
||||
/* add ',' at the end */
|
||||
subStmts = strsAppend(&buffs, subStmts, ",");
|
||||
while (1) {
|
||||
|
@ -1751,21 +1781,25 @@ exit:
|
|||
return ast;
|
||||
}
|
||||
|
||||
static int32_t Parser_getPyLineBlockDeepth(char* line) {
|
||||
static int32_t _getSpaceNum(char* line) {
|
||||
uint32_t size = strGetSize(line);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
if (line[i] != ' ') {
|
||||
uint32_t spaceNum = i;
|
||||
if (0 == spaceNum % 4) {
|
||||
return spaceNum / 4;
|
||||
}
|
||||
/* space Num is not 4N, error*/
|
||||
return -1;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t Parser_getPyLineBlockDeepth(char* line) {
|
||||
int32_t spaceNum = _getSpaceNum(line);
|
||||
if (0 == spaceNum % 4) {
|
||||
return spaceNum / 4;
|
||||
}
|
||||
/* space Num is not 4N, error*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* Parser_removeAnnotation(char* line) {
|
||||
uint8_t is_annotation_exit = 0;
|
||||
uint8_t is_in_single_quotes = 0;
|
||||
|
@ -1805,50 +1839,59 @@ char* Parser_removeAnnotation(char* line) {
|
|||
return line;
|
||||
}
|
||||
|
||||
char* _defGetDefault(Args* outBuffs, char** dec_out) {
|
||||
char* _defGetDefault(Args* outBuffs, char** psDeclearOut) {
|
||||
#if PIKA_NANO_ENABLE
|
||||
return "";
|
||||
#endif
|
||||
Args buffs = {0};
|
||||
char* dec_str = strsCopy(&buffs, *dec_out);
|
||||
char* fn_name = strsGetFirstToken(&buffs, dec_str, '(');
|
||||
Arg* dec_arg = arg_strAppend(arg_newStr(fn_name), "(");
|
||||
Arg* default_arg = arg_newStr("");
|
||||
char* arg_list = strsCut(&buffs, dec_str, '(', ')');
|
||||
char* default_out = NULL;
|
||||
pika_assert(NULL != arg_list);
|
||||
int arg_num = strCountSign(arg_list, ',') + 1;
|
||||
for (int i = 0; i < arg_num; i++) {
|
||||
char* arg_str = strsPopToken(&buffs, &arg_list, ',');
|
||||
char* sDeclear = strsCopy(&buffs, *psDeclearOut);
|
||||
char* sFnName = strsGetFirstToken(&buffs, sDeclear, '(');
|
||||
Arg* aDeclear = arg_strAppend(arg_newStr(sFnName), "(");
|
||||
Arg* aDefault = arg_newStr("");
|
||||
char* sArgList = strsCut(&buffs, sDeclear, '(', ')');
|
||||
char* sDefaultOut = NULL;
|
||||
pika_assert(NULL != sArgList);
|
||||
int argNum = strCountSign(sArgList, ',') + 1;
|
||||
for (int i = 0; i < argNum; i++) {
|
||||
char* sItem = strsPopToken(&buffs, &sArgList, ',');
|
||||
char* sDefaultVal = NULL;
|
||||
char* sDefaultKey = NULL;
|
||||
int is_default = 0;
|
||||
if (strIsContain(arg_str, '=')) {
|
||||
default_arg = arg_strAppend(default_arg, arg_str);
|
||||
default_arg = arg_strAppend(default_arg, ",");
|
||||
arg_str = strsPopToken(&buffs, &arg_str, '=');
|
||||
if (strIsContain(sItem, '=')) {
|
||||
/* has default value */
|
||||
sDefaultVal = Cursor_splitCollect(&buffs, sItem, "=", 1);
|
||||
sDefaultKey = Cursor_splitCollect(&buffs, sItem, "=", 0);
|
||||
sDefaultKey = Cursor_splitCollect(&buffs, sDefaultKey, ":", 0);
|
||||
aDefault = arg_strAppend(aDefault, sDefaultKey);
|
||||
aDefault = arg_strAppend(aDefault, "=");
|
||||
aDefault = arg_strAppend(aDefault, sDefaultVal);
|
||||
aDefault = arg_strAppend(aDefault, ",");
|
||||
is_default = 1;
|
||||
} else {
|
||||
sDefaultKey = sItem;
|
||||
}
|
||||
dec_arg = arg_strAppend(dec_arg, arg_str);
|
||||
aDeclear = arg_strAppend(aDeclear, sDefaultKey);
|
||||
if (is_default) {
|
||||
dec_arg = arg_strAppend(dec_arg, "=");
|
||||
aDeclear = arg_strAppend(aDeclear, "=");
|
||||
}
|
||||
dec_arg = arg_strAppend(dec_arg, ",");
|
||||
aDeclear = arg_strAppend(aDeclear, ",");
|
||||
}
|
||||
strPopLastToken(arg_getStr(dec_arg), ',');
|
||||
dec_arg = arg_strAppend(dec_arg, ")");
|
||||
*dec_out = strsCopy(outBuffs, arg_getStr(dec_arg));
|
||||
default_out = strsCopy(outBuffs, arg_getStr(default_arg));
|
||||
strPopLastToken(default_out, ',');
|
||||
arg_deinit(dec_arg);
|
||||
arg_deinit(default_arg);
|
||||
strPopLastToken(arg_getStr(aDeclear), ',');
|
||||
aDeclear = arg_strAppend(aDeclear, ")");
|
||||
*psDeclearOut = strsCopy(outBuffs, arg_getStr(aDeclear));
|
||||
sDefaultOut = strsCopy(outBuffs, arg_getStr(aDefault));
|
||||
strPopLastToken(sDefaultOut, ',');
|
||||
arg_deinit(aDeclear);
|
||||
arg_deinit(aDefault);
|
||||
strsDeinit(&buffs);
|
||||
return default_out;
|
||||
return sDefaultOut;
|
||||
}
|
||||
|
||||
static char* Suger_multiReturn(Args* out_buffs, char* line) {
|
||||
#if PIKA_NANO_ENABLE
|
||||
return line;
|
||||
#endif
|
||||
Cursor_forEachToken(cs, line) {
|
||||
Cursor_forEach(cs, line) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (cs.branket_deepth == 0 && strEqu(cs.token1.pyload, ",")) {
|
||||
line = strsFormat(out_buffs, strGetSize(line) + 3, "(%s)", line);
|
||||
|
@ -1950,7 +1993,7 @@ AST* AST_parseLine_withBlockStack_withBlockDeepth(char* line,
|
|||
if (strIsStartWith(line_start, "for ")) {
|
||||
Args* list_buffs = New_strBuff();
|
||||
char* line_buff = strsCopy(list_buffs, line_start + 4);
|
||||
line_buff = strsGetCleanCmd(list_buffs, line_buff);
|
||||
line_buff = Cursor_getCleanStmt(list_buffs, line_buff);
|
||||
if (strCountSign(line_buff, ':') < 1) {
|
||||
args_deinit(list_buffs);
|
||||
obj_deinit(ast);
|
||||
|
@ -2054,7 +2097,7 @@ AST* AST_parseLine_withBlockStack_withBlockDeepth(char* line,
|
|||
if (strIsStartWith(line_start, "global ")) {
|
||||
stmt = "";
|
||||
char* global_list = line_start + 7;
|
||||
global_list = strsGetCleanCmd(&buffs, global_list);
|
||||
global_list = Cursor_getCleanStmt(&buffs, global_list);
|
||||
AST_setNodeAttr(ast, "global", global_list);
|
||||
goto block_matched;
|
||||
}
|
||||
|
@ -2067,7 +2110,7 @@ AST* AST_parseLine_withBlockStack_withBlockDeepth(char* line,
|
|||
} else {
|
||||
del_dir = line_start + sizeof("del ") - 1;
|
||||
}
|
||||
del_dir = strsGetCleanCmd(&buffs, del_dir);
|
||||
del_dir = Cursor_getCleanStmt(&buffs, del_dir);
|
||||
AST_setNodeAttr(ast, "del", del_dir);
|
||||
goto block_matched;
|
||||
}
|
||||
|
@ -2079,7 +2122,7 @@ AST* AST_parseLine_withBlockStack_withBlockDeepth(char* line,
|
|||
ast = NULL;
|
||||
goto exit;
|
||||
}
|
||||
declare = strsGetCleanCmd(&buffs, declare);
|
||||
declare = Cursor_getCleanStmt(&buffs, declare);
|
||||
if (!strIsContain(declare, '(') || !strIsContain(declare, ')')) {
|
||||
obj_deinit(ast);
|
||||
ast = NULL;
|
||||
|
@ -2102,7 +2145,7 @@ AST* AST_parseLine_withBlockStack_withBlockDeepth(char* line,
|
|||
ast = NULL;
|
||||
goto exit;
|
||||
}
|
||||
declare = strsGetCleanCmd(&buffs, declare);
|
||||
declare = Cursor_getCleanStmt(&buffs, declare);
|
||||
AST_setNodeBlock(ast, "class");
|
||||
AST_setNodeAttr(ast, "declare", declare);
|
||||
stack_pushStr(block_stack, "class");
|
||||
|
@ -2115,7 +2158,7 @@ block_matched:
|
|||
ast = NULL;
|
||||
goto exit;
|
||||
}
|
||||
stmt = strsGetCleanCmd(&buffs, stmt);
|
||||
stmt = Cursor_getCleanStmt(&buffs, stmt);
|
||||
ast = AST_parseStmt(ast, stmt);
|
||||
goto exit;
|
||||
exit:
|
||||
|
@ -2178,7 +2221,7 @@ static PIKA_BOOL _check_is_multi_assign(char* arg_list) {
|
|||
return PIKA_FALSE;
|
||||
#endif
|
||||
PIKA_BOOL res = PIKA_FALSE;
|
||||
Cursor_forEachToken(cs, arg_list) {
|
||||
Cursor_forEach(cs, arg_list) {
|
||||
Cursor_iterStart(&cs);
|
||||
if ((cs.branket_deepth == 0 && strEqu(cs.token1.pyload, ","))) {
|
||||
res = PIKA_TRUE;
|
||||
|
@ -2195,6 +2238,7 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) {
|
|||
#endif
|
||||
Args buffs = {0};
|
||||
char* line_out = line;
|
||||
int space_num = _getSpaceNum(line);
|
||||
PIKA_BOOL is_assign = PIKA_FALSE;
|
||||
Arg* stmt = arg_newStr("");
|
||||
Arg* out_list = arg_newStr("");
|
||||
|
@ -2203,7 +2247,7 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) {
|
|||
char* line_item = NULL;
|
||||
char* out_list_str = NULL;
|
||||
int out_num = 0;
|
||||
Cursor_forEachToken(cs, line) {
|
||||
Cursor_forEach(cs, line) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (cs.branket_deepth == 0 && strEqu(cs.token1.pyload, "=")) {
|
||||
is_assign = PIKA_TRUE;
|
||||
|
@ -2231,6 +2275,11 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) {
|
|||
|
||||
line_item =
|
||||
strsFormat(&buffs, PIKA_LINE_BUFF_SIZE, "$tmp= %s\n", arg_getStr(stmt));
|
||||
|
||||
/* add space */
|
||||
for (int i = 0; i < space_num; i++) {
|
||||
line_out_arg = arg_strAppend(line_out_arg, " ");
|
||||
}
|
||||
line_out_arg = arg_strAppend(line_out_arg, line_item);
|
||||
|
||||
out_list_str = arg_getStr(out_list);
|
||||
|
@ -2241,9 +2290,17 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) {
|
|||
}
|
||||
char* line_item = strsFormat(&buffs, PIKA_LINE_BUFF_SIZE,
|
||||
"%s = $tmp[%d]\n", item, out_num);
|
||||
/* add space */
|
||||
for (int i = 0; i < space_num; i++) {
|
||||
line_out_arg = arg_strAppend(line_out_arg, " ");
|
||||
}
|
||||
line_out_arg = arg_strAppend(line_out_arg, line_item);
|
||||
out_num++;
|
||||
}
|
||||
/* add space */
|
||||
for (int i = 0; i < space_num; i++) {
|
||||
line_out_arg = arg_strAppend(line_out_arg, " ");
|
||||
}
|
||||
line_out_arg = arg_strAppend(line_out_arg, "del $tmp");
|
||||
|
||||
line_out = strsCopy(out_buffs, arg_getStr(line_out_arg));
|
||||
|
@ -2503,7 +2560,7 @@ static char* _Parser_linesToBytesOrAsm(Args* outBuffs,
|
|||
line_connection_arg = arg_strAppend(line_connection_arg, line);
|
||||
goto next_line;
|
||||
}
|
||||
Cursor_forEachToken(c, line) {
|
||||
Cursor_forEach(c, line) {
|
||||
Cursor_iterStart(&c);
|
||||
Cursor_iterEnd(&c);
|
||||
}
|
||||
|
@ -2774,10 +2831,6 @@ char* AST_genAsm(AST* ast, Args* outBuffs) {
|
|||
pikaAsm = strsAppend(outBuffs, pikaAsm, (char*)"0 GER \n");
|
||||
pikaAsm = strsAppend(outBuffs, pikaAsm, (char*)"0 JEZ 2\n");
|
||||
}
|
||||
|
||||
if (strEqu(block_type, "except")) {
|
||||
pikaAsm = strsAppend(outBuffs, pikaAsm, (char*)"0 SER 0\n");
|
||||
}
|
||||
#endif
|
||||
/* goto the while start when exit while block */
|
||||
if (strEqu(block_type, "for")) {
|
||||
|
|
|
@ -106,19 +106,19 @@ char* Parser_linesToArray(char* lines);
|
|||
char* instructUnit_fromAsmLine(Args* outBuffs, char* pikaAsm);
|
||||
ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* bf, char* pikaAsm);
|
||||
|
||||
#define Cursor_forEach(cursor) \
|
||||
#define _Cursor_forEach(cursor) \
|
||||
_Cursor_beforeIter(&cursor); \
|
||||
for (int __i = 0; __i < cursor.length; __i++)
|
||||
|
||||
#define Cursor_forEachTokenExistPs(cursor, tokenStream) \
|
||||
#define Cursor_forEachExistPs(cursor, stmt) \
|
||||
/* init parserStage */ \
|
||||
_Cursor_init(&cursor); \
|
||||
_Cursor_parse(&cursor, tokenStream); \
|
||||
Cursor_forEach(cursor)
|
||||
_Cursor_parse(&cursor, stmt); \
|
||||
_Cursor_forEach(cursor)
|
||||
|
||||
#define Cursor_forEachToken(cursor, tokenStream) \
|
||||
#define Cursor_forEach(cursor, stmt) \
|
||||
struct Cursor cursor; \
|
||||
Cursor_forEachTokenExistPs(cursor, tokenStream)
|
||||
Cursor_forEachExistPs(cursor, stmt)
|
||||
|
||||
uint16_t TokenStream_getSize(char* tokenStream);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* This file is part of the PikaScript project.
|
||||
* http://github.com/pikastech/pikascript
|
||||
*
|
||||
|
@ -28,6 +28,12 @@
|
|||
#include "PikaPlatform.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(_WIN32) && !defined(CROSS_BUILD)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
void pikaFree(void* mem, uint32_t size);
|
||||
void* pikaMalloc(uint32_t size);
|
||||
|
||||
PIKA_WEAK void pika_platform_disable_irq_handle(void) {
|
||||
/* disable irq to support thread */
|
||||
|
@ -74,8 +80,29 @@ PIKA_WEAK uint8_t pika_is_locked_pikaMemory(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
PIKA_WEAK int64_t pika_platform_getTick(void) {
|
||||
#if PIKA_FREERTOS_ENABLE
|
||||
static uint32_t platform_uptime_ms(void) {
|
||||
#if (configTICK_RATE_HZ == 1000)
|
||||
return (uint32_t)xTaskGetTickCount();
|
||||
#else
|
||||
TickType_t tick = 0u;
|
||||
|
||||
tick = xTaskGetTickCount() * 1000;
|
||||
return (uint32_t)((tick + configTICK_RATE_HZ - 1) / configTICK_RATE_HZ);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
PIKA_WEAK int64_t pika_platform_get_tick(void) {
|
||||
#if PIKA_FREERTOS_ENABLE
|
||||
return platform_uptime_ms();
|
||||
#elif defined(__linux)
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int pika_platform_vsprintf(char* buff, char* fmt, va_list args) {
|
||||
|
@ -215,6 +242,7 @@ PIKA_WEAK size_t pika_platform_fwrite(const void* ptr,
|
|||
size_t size,
|
||||
size_t n,
|
||||
FILE* stream) {
|
||||
pika_assert(NULL != stream);
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return fwrite(ptr, size, n, stream);
|
||||
#else
|
||||
|
@ -270,21 +298,26 @@ PIKA_WEAK PIKA_BOOL pika_hook_arg_cache_filter(void* self) {
|
|||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_delay(void) {
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return;
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
vTaskDelay(1);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_sleep_ms(uint32_t ms) {
|
||||
#if defined(__linux)
|
||||
usleep(ms * 1000);
|
||||
#elif defined(_WIN32) && !defined(CROSS_BUILD)
|
||||
Sleep(ms);
|
||||
#else
|
||||
pika_platform_printf(
|
||||
"Error: pika_platform_sleep_ms need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_sleep_s(uint32_t s) {
|
||||
pika_platform_printf(
|
||||
"Error: pika_platform_sleep_s need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Thread Support */
|
||||
|
@ -301,11 +334,11 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
|
|||
void* (*thread_entry)(void*);
|
||||
|
||||
thread_entry = (void* (*)(void*))entry;
|
||||
thread = pika_platform_malloc(sizeof(pika_platform_thread_t));
|
||||
thread = pikaMalloc(sizeof(pika_platform_thread_t));
|
||||
|
||||
res = pthread_create(&thread->thread, NULL, thread_entry, param);
|
||||
if (res != 0) {
|
||||
pika_platform_free(thread);
|
||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||
}
|
||||
|
||||
thread->mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
|
||||
|
@ -316,14 +349,14 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
|
|||
BaseType_t err;
|
||||
pika_platform_thread_t* thread;
|
||||
|
||||
thread = pika_platform_malloc(sizeof(pika_platform_thread_t));
|
||||
thread = pikaMalloc(sizeof(pika_platform_thread_t));
|
||||
|
||||
(void)tick;
|
||||
|
||||
err = xTaskCreate(entry, name, stack_size, param, priority, thread->thread);
|
||||
|
||||
if (pdPASS != err) {
|
||||
pika_platform_free(thread);
|
||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -334,6 +367,17 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
|
|||
#endif
|
||||
}
|
||||
|
||||
uint64_t pika_platform_thread_self(void) {
|
||||
#ifdef __linux
|
||||
return (uint64_t)pthread_self();
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
return (uint64_t)xTaskGetCurrentTaskHandle();
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_startup(pika_platform_thread_t* thread) {
|
||||
(void)thread;
|
||||
}
|
||||
|
@ -366,13 +410,28 @@ PIKA_WEAK void pika_platform_thread_destroy(pika_platform_thread_t* thread) {
|
|||
#ifdef __linux
|
||||
if (NULL != thread) {
|
||||
pthread_detach(thread->thread);
|
||||
pika_platform_free(thread);
|
||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||
thread = NULL;
|
||||
return;
|
||||
}
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
if (NULL != thread)
|
||||
if (NULL != thread) {
|
||||
vTaskDelete(thread->thread);
|
||||
pika_platform_memory_free(thread);
|
||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_exit(pika_platform_thread_t* thread) {
|
||||
#ifdef __linux
|
||||
return pika_platform_thread_destroy(thread);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
vTaskDelete(NULL); // test on esp32c3
|
||||
// vTaskDelete(thread->thread);
|
||||
return;
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
|
@ -438,20 +497,7 @@ PIKA_WEAK int pika_platform_thread_mutex_destroy(
|
|||
#endif
|
||||
}
|
||||
|
||||
#if PIKA_FREERTOS_ENABLE
|
||||
static uint32_t platform_uptime_ms(void) {
|
||||
#if (configTICK_RATE_HZ == 1000)
|
||||
return (uint32_t)xTaskGetTickCount();
|
||||
#else
|
||||
TickType_t tick = 0u;
|
||||
|
||||
tick = xTaskGetTickCount() * 1000;
|
||||
return (uint32_t)((tick + configTICK_RATE_HZ - 1) / configTICK_RATE_HZ);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
PIKA_WEAK void pika_platform_timer_init(pika_platform_timer_t* timer) {
|
||||
PIKA_WEAK void pika_platform_thread_timer_init(pika_platform_timer_t* timer) {
|
||||
#ifdef __linux
|
||||
timer->time = (struct timeval){0, 0};
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
|
@ -461,8 +507,8 @@ PIKA_WEAK void pika_platform_timer_init(pika_platform_timer_t* timer) {
|
|||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_timer_cutdown(pika_platform_timer_t* timer,
|
||||
unsigned int timeout) {
|
||||
PIKA_WEAK void pika_platform_thread_timer_cutdown(pika_platform_timer_t* timer,
|
||||
unsigned int timeout) {
|
||||
#ifdef __linux
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
|
@ -476,7 +522,8 @@ PIKA_WEAK void pika_platform_timer_cutdown(pika_platform_timer_t* timer,
|
|||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK char pika_platform_timer_is_expired(pika_platform_timer_t* timer) {
|
||||
PIKA_WEAK char pika_platform_thread_timer_is_expired(
|
||||
pika_platform_timer_t* timer) {
|
||||
#ifdef __linux
|
||||
struct timeval now, res;
|
||||
gettimeofday(&now, NULL);
|
||||
|
@ -490,7 +537,7 @@ PIKA_WEAK char pika_platform_timer_is_expired(pika_platform_timer_t* timer) {
|
|||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int pika_platform_timer_remain(pika_platform_timer_t* timer) {
|
||||
PIKA_WEAK int pika_platform_thread_timer_remain(pika_platform_timer_t* timer) {
|
||||
#ifdef __linux
|
||||
struct timeval now, res;
|
||||
gettimeofday(&now, NULL);
|
||||
|
@ -509,7 +556,7 @@ PIKA_WEAK int pika_platform_timer_remain(pika_platform_timer_t* timer) {
|
|||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK unsigned long pika_platform_timer_now(void) {
|
||||
PIKA_WEAK unsigned long pika_platform_thread_timer_now(void) {
|
||||
#ifdef __linux
|
||||
return (unsigned long)time(NULL);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
|
@ -520,7 +567,7 @@ PIKA_WEAK unsigned long pika_platform_timer_now(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_timer_usleep(unsigned long usec) {
|
||||
PIKA_WEAK void pika_platform_thread_timer_usleep(unsigned long usec) {
|
||||
#ifdef __linux
|
||||
usleep(usec);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
|
@ -536,3 +583,7 @@ PIKA_WEAK void pika_platform_timer_usleep(unsigned long usec) {
|
|||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_reboot(void) {
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* This file is part of the PikaScript project.
|
||||
* http://github.com/pikastech/pikascript
|
||||
*
|
||||
|
@ -44,7 +44,7 @@
|
|||
#if PIKA_ASSERT_ENABLE
|
||||
#define pika_assert(expr) \
|
||||
if(!(expr)) { \
|
||||
pika_platform_printf("Assertion \"%s\" failed, in function: %s(). \r\n (at %s:%d)\n", #expr, __FUNCTION__, __FILE__, __LINE__); \
|
||||
pika_platform_printf((char*)"Assertion \"%s\" failed, in function: %s(). \r\n (at %s:%d)\n", #expr, __FUNCTION__, __FILE__, __LINE__); \
|
||||
abort(); \
|
||||
}
|
||||
#else
|
||||
|
@ -101,15 +101,19 @@ typedef enum {
|
|||
PIKA_RES_ERR_ASSERT = -16,
|
||||
PIKA_RES_ERR_SIGNAL_EVENT_FULL = -17,
|
||||
PIKA_RES_ERR_SIGNAL_EVENT_EMPTY = -18,
|
||||
PIKA_RES_ERR_INDEX = -19,
|
||||
} PIKA_RES;
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/* pikascript bool type */
|
||||
typedef enum {
|
||||
PIKA_TRUE = 1,
|
||||
PIKA_FALSE = 0,
|
||||
} PIKA_BOOL;
|
||||
#define PIKA_BOOL int64_t
|
||||
#define PIKA_TRUE 1
|
||||
#define PIKA_FALSE 0
|
||||
#define _PIKA_BOOL_ERR -1
|
||||
|
||||
#define _PIKA_INT_ERR (-999999999)
|
||||
#define _PIKA_FLOAT_ERR (-999999999.0)
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
|
@ -175,11 +179,9 @@ void pika_platform_error_handle(void);
|
|||
/* panic */
|
||||
void pika_platform_panic_handle(void);
|
||||
|
||||
void pika_platform_thread_delay(void);
|
||||
int64_t pika_platform_getTick(void);
|
||||
int64_t pika_platform_get_tick(void);
|
||||
|
||||
void pika_platform_sleep_ms(uint32_t ms);
|
||||
void pika_platform_sleep_s(uint32_t s);
|
||||
|
||||
void pika_hook_instruct(void);
|
||||
PIKA_BOOL pika_hook_arg_cache_filter(void* self);
|
||||
|
@ -206,8 +208,8 @@ typedef struct pika_platform_thread {
|
|||
pthread_cond_t cond;
|
||||
} pika_platform_thread_t;
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
typedef struct pika_platform_thread {
|
||||
TaskHandle_t thread;
|
||||
} pika_platform_thread_t;
|
||||
|
@ -223,25 +225,34 @@ pika_platform_thread_t* pika_platform_thread_init(const char* name,
|
|||
unsigned int stack_size,
|
||||
unsigned int priority,
|
||||
unsigned int tick);
|
||||
uint64_t pika_platform_thread_self(void);
|
||||
void pika_platform_thread_delay(void);
|
||||
void pika_platform_thread_startup(pika_platform_thread_t* thread);
|
||||
void pika_platform_thread_stop(pika_platform_thread_t* thread);
|
||||
void pika_platform_thread_start(pika_platform_thread_t* thread);
|
||||
void pika_platform_thread_destroy(pika_platform_thread_t* thread);
|
||||
void pika_platform_thread_exit(pika_platform_thread_t* thread);
|
||||
|
||||
#ifdef __linux
|
||||
#include <pthread.h>
|
||||
typedef struct pika_platform_thread_mutex {
|
||||
pthread_mutex_t mutex;
|
||||
volatile int is_init;
|
||||
volatile int is_first_lock;
|
||||
} pika_platform_thread_mutex_t;
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
typedef struct pika_platform_thread_mutex {
|
||||
SemaphoreHandle_t mutex;
|
||||
volatile int is_init;
|
||||
volatile int is_first_lock;
|
||||
} pika_platform_thread_mutex_t;
|
||||
#else
|
||||
typedef struct pika_platform_thread_mutex {
|
||||
void* platform_data;
|
||||
volatile int is_init;
|
||||
volatile int is_first_lock;
|
||||
} pika_platform_thread_mutex_t;
|
||||
#endif
|
||||
|
||||
|
@ -257,8 +268,8 @@ typedef struct pika_platform_timer {
|
|||
struct timeval time;
|
||||
} pika_platform_timer_t;
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
typedef struct pika_platform_timer {
|
||||
uint32_t time;
|
||||
} pika_platform_timer_t;
|
||||
|
@ -268,13 +279,14 @@ typedef struct pika_platform_timer {
|
|||
} pika_platform_timer_t;
|
||||
#endif
|
||||
|
||||
void pika_platform_timer_init(pika_platform_timer_t* timer);
|
||||
void pika_platform_timer_cutdown(pika_platform_timer_t* timer,
|
||||
unsigned int timeout);
|
||||
char pika_platform_timer_is_expired(pika_platform_timer_t* timer);
|
||||
int pika_platform_timer_remain(pika_platform_timer_t* timer);
|
||||
unsigned long pika_platform_timer_now(void);
|
||||
void pika_platform_timer_usleep(unsigned long usec);
|
||||
void pika_platform_thread_timer_init(pika_platform_timer_t* timer);
|
||||
void pika_platform_thread_timer_cutdown(pika_platform_timer_t* timer,
|
||||
unsigned int timeout);
|
||||
char pika_platform_thread_timer_is_expired(pika_platform_timer_t* timer);
|
||||
int pika_platform_thread_timer_remain(pika_platform_timer_t* timer);
|
||||
unsigned long pika_platform_thread_timer_now(void);
|
||||
void pika_platform_thread_timer_usleep(unsigned long usec);
|
||||
void pika_platform_reboot(void);
|
||||
|
||||
#define WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_) \
|
||||
pika_platform_printf("Error: weak function `%s()` need override.\r\n", \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* This file is part of the PikaScript project.
|
||||
* http://github.com/pikastech/pikascript
|
||||
*
|
||||
|
@ -48,20 +48,112 @@ volatile VMSignal PikaVMSignal = {.signal_ctrl = VM_SIGNAL_CTRL_NONE,
|
|||
#endif
|
||||
};
|
||||
|
||||
static pika_platform_thread_mutex_t pikavm_global_lock = {0};
|
||||
|
||||
int pika_GIL_ENTER(void) {
|
||||
if (!pikavm_global_lock.is_init) {
|
||||
return 0;
|
||||
}
|
||||
int ret = pika_platform_thread_mutex_lock(&pikavm_global_lock);
|
||||
pika_debug("pika_GIL_ENTER");
|
||||
if (!pikavm_global_lock.is_first_lock) {
|
||||
pikavm_global_lock.is_first_lock = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pika_GIL_EXIT(void) {
|
||||
if (!pikavm_global_lock.is_init) {
|
||||
return 0;
|
||||
}
|
||||
pika_debug("pika_GIL_EXIT");
|
||||
return pika_platform_thread_mutex_unlock(&pikavm_global_lock);
|
||||
}
|
||||
|
||||
int _VM_lock_init(void) {
|
||||
if (pikavm_global_lock.is_init) {
|
||||
return 0;
|
||||
}
|
||||
int ret = pika_platform_thread_mutex_init(&pikavm_global_lock);
|
||||
if (0 == ret) {
|
||||
pikavm_global_lock.is_init = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _VM_is_first_lock(void) {
|
||||
return pikavm_global_lock.is_first_lock;
|
||||
}
|
||||
|
||||
int _VMEvent_getVMCnt(void) {
|
||||
return PikaVMSignal.vm_cnt;
|
||||
}
|
||||
|
||||
#if PIKA_EVENT_ENABLE
|
||||
static PIKA_BOOL _cq_isEmpty(volatile EventCQ* cq) {
|
||||
static PIKA_BOOL _ecq_isEmpty(volatile EventCQ* cq) {
|
||||
return (PIKA_BOOL)(cq->head == cq->tail);
|
||||
}
|
||||
|
||||
static PIKA_BOOL _cq_isFull(volatile EventCQ* cq) {
|
||||
static PIKA_BOOL _ecq_isFull(volatile EventCQ* cq) {
|
||||
return (PIKA_BOOL)((cq->tail + 1) % PIKA_EVENT_LIST_SIZE == cq->head);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PIKA_SETJMP_ENABLE
|
||||
|
||||
static PIKA_BOOL _jcq_isEmpty(volatile JmpBufCQ* cq) {
|
||||
return (PIKA_BOOL)(cq->head == cq->tail);
|
||||
}
|
||||
|
||||
static PIKA_BOOL _jcq_isFull(volatile JmpBufCQ* cq) {
|
||||
return (PIKA_BOOL)((cq->tail + 1) % PIKA_JMP_BUF_LIST_SIZE == cq->head);
|
||||
}
|
||||
|
||||
static jmp_buf* _jcq_pop(volatile JmpBufCQ* cq) {
|
||||
if (_jcq_isEmpty(cq)) {
|
||||
return NULL;
|
||||
}
|
||||
jmp_buf* buf = cq->buf[cq->head];
|
||||
cq->head = (cq->head + 1) % PIKA_JMP_BUF_LIST_SIZE;
|
||||
return buf;
|
||||
}
|
||||
|
||||
static jmp_buf* _jcq_check_pop(volatile JmpBufCQ* cq) {
|
||||
if (_jcq_isEmpty(cq)) {
|
||||
return NULL;
|
||||
}
|
||||
return cq->buf[cq->head];
|
||||
}
|
||||
|
||||
static PIKA_RES _jcq_push(volatile JmpBufCQ* cq, jmp_buf* pos) {
|
||||
if (_jcq_isFull(cq)) {
|
||||
return -1;
|
||||
}
|
||||
cq->buf[cq->tail] = pos;
|
||||
cq->tail = (cq->tail + 1) % PIKA_JMP_BUF_LIST_SIZE;
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
static PIKA_RES _jcq_remove(volatile JmpBufCQ* cq, jmp_buf* pos) {
|
||||
if (_jcq_isEmpty(cq)) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = cq->head; i != cq->tail;
|
||||
i = (i + 1) % PIKA_JMP_BUF_LIST_SIZE) {
|
||||
if (cq->buf[i] == pos) {
|
||||
/* move */
|
||||
for (int j = i; j != cq->tail;
|
||||
j = (j + 1) % PIKA_JMP_BUF_LIST_SIZE) {
|
||||
cq->buf[j] = cq->buf[(j + 1) % PIKA_JMP_BUF_LIST_SIZE];
|
||||
}
|
||||
cq->tail = (cq->tail - 1) % PIKA_JMP_BUF_LIST_SIZE;
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void _VMEvent_deinit(void) {
|
||||
#if !PIKA_EVENT_ENABLE
|
||||
pika_platform_printf("PIKA_EVENT_ENABLE is not enable");
|
||||
|
@ -88,7 +180,7 @@ PIKA_RES __eventListener_pushEvent(PikaEventListener* lisener,
|
|||
pika_platform_panic_handle();
|
||||
#else
|
||||
/* push to event_cq_buff */
|
||||
if (_cq_isFull(&PikaVMSignal.cq)) {
|
||||
if (_ecq_isFull(&PikaVMSignal.cq)) {
|
||||
arg_deinit(eventData);
|
||||
return PIKA_RES_ERR_SIGNAL_EVENT_FULL;
|
||||
}
|
||||
|
@ -120,7 +212,7 @@ PIKA_RES __eventListener_popEvent(PikaEventListener** lisener_p,
|
|||
pika_platform_panic_handle();
|
||||
#else
|
||||
/* pop from event_cq_buff */
|
||||
if (_cq_isEmpty(&PikaVMSignal.cq)) {
|
||||
if (_ecq_isEmpty(&PikaVMSignal.cq)) {
|
||||
return PIKA_RES_ERR_SIGNAL_EVENT_EMPTY;
|
||||
}
|
||||
*id = PikaVMSignal.cq.id[PikaVMSignal.cq.head];
|
||||
|
@ -134,7 +226,7 @@ PIKA_RES __eventListener_popEvent(PikaEventListener** lisener_p,
|
|||
|
||||
void _VMEvent_pickupEvent(void) {
|
||||
#if !PIKA_EVENT_ENABLE
|
||||
pika_platform_printf("PIKA_EVENT_ENABLE is not enable");
|
||||
pika_platform_printf("PIKA_EVENT_ENABLE is not enable\r\n");
|
||||
pika_platform_panic_handle();
|
||||
#else
|
||||
PikaObj* event_lisener;
|
||||
|
@ -205,18 +297,31 @@ static int VMState_getInvokeDeepthNow(VMState* vm) {
|
|||
|
||||
static int32_t VMState_getAddrOffsetOfJmpBack(VMState* vm) {
|
||||
int offset = 0;
|
||||
int loop_deepth = -1;
|
||||
int blockDeepthGot = -1;
|
||||
int blockDeepthNow = VMState_getBlockDeepthNow(vm);
|
||||
|
||||
/* find loop deepth */
|
||||
while (1) {
|
||||
offset -= instructUnit_getSize();
|
||||
InstructUnit* ins_unit_now =
|
||||
InstructUnit* insUnitThis =
|
||||
VMState_getInstructUnitWithOffset(vm, offset);
|
||||
uint16_t invoke_deepth = instructUnit_getInvokeDeepth(ins_unit_now);
|
||||
enum Instruct ins = instructUnit_getInstruct(ins_unit_now);
|
||||
char* data = VMState_getConstWithInstructUnit(vm, ins_unit_now);
|
||||
if ((0 == invoke_deepth) && (JEZ == ins) && data[0] == '2') {
|
||||
loop_deepth = instructUnit_getBlockDeepth(ins_unit_now);
|
||||
uint16_t invokeDeepth = instructUnit_getInvokeDeepth(insUnitThis);
|
||||
enum Instruct ins = instructUnit_getInstruct(insUnitThis);
|
||||
char* data = VMState_getConstWithInstructUnit(vm, insUnitThis);
|
||||
if ((0 == invokeDeepth) && (JEZ == ins) && data[0] == '2') {
|
||||
InstructUnit* insUnitLast = VMState_getInstructUnitWithOffset(
|
||||
vm, offset - instructUnit_getSize());
|
||||
enum Instruct insLast = instructUnit_getInstruct(insUnitLast);
|
||||
/* skip try stmt */
|
||||
if (GER == insLast) {
|
||||
continue;
|
||||
}
|
||||
/* skip inner break */
|
||||
int blockDeepthThis = instructUnit_getBlockDeepth(insUnitThis);
|
||||
if (blockDeepthThis >= blockDeepthNow) {
|
||||
continue;
|
||||
}
|
||||
blockDeepthGot = instructUnit_getBlockDeepth(insUnitThis);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -224,12 +329,12 @@ static int32_t VMState_getAddrOffsetOfJmpBack(VMState* vm) {
|
|||
offset = 0;
|
||||
while (1) {
|
||||
offset += instructUnit_getSize();
|
||||
InstructUnit* ins_unit_now =
|
||||
InstructUnit* insUnitThis =
|
||||
VMState_getInstructUnitWithOffset(vm, offset);
|
||||
enum Instruct ins = instructUnit_getInstruct(ins_unit_now);
|
||||
char* data = VMState_getConstWithInstructUnit(vm, ins_unit_now);
|
||||
int block_deepth_now = instructUnit_getBlockDeepth(ins_unit_now);
|
||||
if ((block_deepth_now == loop_deepth) && (JMP == ins) &&
|
||||
enum Instruct ins = instructUnit_getInstruct(insUnitThis);
|
||||
char* data = VMState_getConstWithInstructUnit(vm, insUnitThis);
|
||||
int blockDeepthThis = instructUnit_getBlockDeepth(insUnitThis);
|
||||
if ((blockDeepthThis == blockDeepthGot) && (JMP == ins) &&
|
||||
data[0] == '-' && data[1] == '1') {
|
||||
return offset;
|
||||
}
|
||||
|
@ -404,6 +509,7 @@ Arg* __vm_get(VMState* vm, PikaObj* self, Arg* key, Arg* obj) {
|
|||
arg_obj = arg_getPtr(obj);
|
||||
}
|
||||
obj_setArg(arg_obj, "__key", key);
|
||||
obj_removeArg(arg_obj, "__res");
|
||||
/* clang-format off */
|
||||
PIKA_PYTHON(
|
||||
__res = __getitem__(__key)
|
||||
|
@ -486,8 +592,8 @@ Arg* _vm_slice(VMState* vm,
|
|||
if (start_i < 0) {
|
||||
start_i += len;
|
||||
}
|
||||
/* magit code, to the end */
|
||||
if (end_i == -99999) {
|
||||
/* megic code, to the end */
|
||||
if (end_i == VM_PC_EXIT) {
|
||||
end_i = len;
|
||||
}
|
||||
if (end_i < 0) {
|
||||
|
@ -587,6 +693,7 @@ static Arg* VM_instruction_handler_EXP(PikaObj* self,
|
|||
VMState* vm,
|
||||
char* data,
|
||||
Arg* arg_ret_reg) {
|
||||
vm->try_error_code = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -667,7 +774,7 @@ static Arg* VM_instruction_handler_REF(PikaObj* self,
|
|||
VMState* vm,
|
||||
char* data,
|
||||
Arg* arg_ret_reg) {
|
||||
PikaObj* host_object = NULL;
|
||||
PikaObj* host_obj = NULL;
|
||||
char* arg_path = data;
|
||||
char* arg_name = strPointToLastToken(arg_path, '.');
|
||||
PIKA_BOOL is_temp = PIKA_FALSE;
|
||||
|
@ -675,12 +782,12 @@ static Arg* VM_instruction_handler_REF(PikaObj* self,
|
|||
switch (data[0]) {
|
||||
case 'T':
|
||||
if (strEqu(arg_path, (char*)"True")) {
|
||||
return arg_setInt(arg_ret_reg, "", 1);
|
||||
return arg_setBool(arg_ret_reg, "", PIKA_TRUE);
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
if (strEqu(arg_path, (char*)"False")) {
|
||||
return arg_setInt(arg_ret_reg, "", 0);
|
||||
return arg_setBool(arg_ret_reg, "", PIKA_FALSE);
|
||||
}
|
||||
break;
|
||||
case 'N':
|
||||
|
@ -698,51 +805,44 @@ static Arg* VM_instruction_handler_REF(PikaObj* self,
|
|||
Arg* res = NULL;
|
||||
if (arg_path[0] == '.') {
|
||||
/* find host from stack */
|
||||
Arg* host_obj = stack_popArg_alloc(&(vm->stack));
|
||||
if (argType_isObject(arg_getType(host_obj))) {
|
||||
host_object = arg_getPtr(host_obj);
|
||||
res = arg_copy_noalloc(obj_getArg(host_object, arg_path + 1),
|
||||
Arg* host_arg = stack_popArg_alloc(&(vm->stack));
|
||||
if (argType_isObject(arg_getType(host_arg))) {
|
||||
host_obj = arg_getPtr(host_arg);
|
||||
res = arg_copy_noalloc(obj_getArg(host_obj, arg_path + 1),
|
||||
arg_ret_reg);
|
||||
}
|
||||
arg_deinit(host_obj);
|
||||
arg_deinit(host_arg);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* host_object is self */
|
||||
if (NULL == host_object) {
|
||||
if (!strIsContain(arg_path, '.')) {
|
||||
host_object = vm->locals;
|
||||
}
|
||||
}
|
||||
|
||||
/* find in local list first */
|
||||
if (NULL == host_object) {
|
||||
host_object = obj_getHostObjWithIsTemp(vm->locals, arg_path, &is_temp);
|
||||
if (NULL == host_obj) {
|
||||
host_obj = obj_getHostObjWithIsTemp(vm->locals, arg_path, &is_temp);
|
||||
}
|
||||
|
||||
/* find in global list */
|
||||
if (NULL == host_object) {
|
||||
host_object = obj_getHostObjWithIsTemp(vm->globals, arg_path, &is_temp);
|
||||
if (NULL == host_obj) {
|
||||
host_obj = obj_getHostObjWithIsTemp(vm->globals, arg_path, &is_temp);
|
||||
}
|
||||
|
||||
/* error cannot found host_object */
|
||||
if (NULL == host_object) {
|
||||
if (NULL == host_obj) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* proxy */
|
||||
if (NULL == res) {
|
||||
res = _proxy_getattribute(host_object, arg_name);
|
||||
res = _proxy_getattribute(host_obj, arg_name);
|
||||
}
|
||||
|
||||
/* find res in host */
|
||||
if (NULL == res) {
|
||||
res = args_getArg(host_object->list, arg_name);
|
||||
res = args_getArg(host_obj->list, arg_name);
|
||||
}
|
||||
|
||||
/* find res in host prop */
|
||||
if (NULL == res) {
|
||||
res = _obj_getProp(host_object, arg_name);
|
||||
res = _obj_getProp(host_obj, arg_name);
|
||||
}
|
||||
|
||||
/* find res in globlas */
|
||||
|
@ -750,21 +850,28 @@ static Arg* VM_instruction_handler_REF(PikaObj* self,
|
|||
res = args_getArg(vm->globals->list, arg_name);
|
||||
}
|
||||
|
||||
/* proxy */
|
||||
/* find res in globals prop */
|
||||
if (NULL == res) {
|
||||
res = _proxy_getattr(host_object, arg_name);
|
||||
res = _obj_getProp(vm->globals, arg_name);
|
||||
}
|
||||
|
||||
/* proxy */
|
||||
if (NULL == res) {
|
||||
res = _proxy_getattr(host_obj, arg_name);
|
||||
}
|
||||
exit:
|
||||
if (NULL == res) {
|
||||
VMState_setErrorCode(vm, PIKA_RES_ERR_ARG_NO_FOUND);
|
||||
pika_platform_printf("NameError: name '%s' is not defined\r\n",
|
||||
arg_path);
|
||||
} else {
|
||||
if (arg_getType(res) == ARG_TYPE_METHOD_OBJECT) {
|
||||
methodArg_setHostObj(res, host_obj);
|
||||
}
|
||||
res = arg_copy_noalloc(res, arg_ret_reg);
|
||||
}
|
||||
if (is_temp) {
|
||||
obj_deinit(host_object);
|
||||
obj_GC(host_obj);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -861,29 +968,40 @@ Arg* obj_runMethodArg(PikaObj* self,
|
|||
&run_state);
|
||||
}
|
||||
|
||||
static char* _kw_to_default_all(FunctionArgsInfo* f,
|
||||
char* arg_name,
|
||||
int* argc,
|
||||
Arg* argv[],
|
||||
Arg* call_arg) {
|
||||
#if PIKA_NANO
|
||||
static char* _kw_pos_to_default_all(FunctionArgsInfo* f,
|
||||
char* arg_name,
|
||||
int* argc,
|
||||
Arg* argv[],
|
||||
Arg* call_arg) {
|
||||
#if PIKA_NANO_ENABLE
|
||||
return arg_name;
|
||||
#endif
|
||||
int n_default_skip = 0;
|
||||
int n_default_skiped = 0;
|
||||
if (f->i_arg == f->n_arg) {
|
||||
n_default_skip = f->n_default - f->n_arg;
|
||||
}
|
||||
while (strIsContain(arg_name, '=')) {
|
||||
strPopLastToken(arg_name, '=');
|
||||
Arg* default_arg = NULL;
|
||||
Arg* kw_arg = NULL;
|
||||
/* load default arg from kws */
|
||||
if (f->kw != NULL) {
|
||||
default_arg = pikaDict_getArg(f->kw, arg_name);
|
||||
if (default_arg != NULL) {
|
||||
Arg* arg_new = arg_copy(default_arg);
|
||||
kw_arg = pikaDict_getArg(f->kw, arg_name);
|
||||
if (kw_arg != NULL) {
|
||||
Arg* arg_new = arg_copy(kw_arg);
|
||||
argv[(*argc)++] = arg_new;
|
||||
pikaDict_removeArg(f->kw, default_arg);
|
||||
pikaDict_removeArg(f->kw, kw_arg);
|
||||
}
|
||||
}
|
||||
if (f->kw == NULL || default_arg == NULL) {
|
||||
if (f->kw == NULL || kw_arg == NULL) {
|
||||
/* can not load defalut from kw */
|
||||
if (NULL != call_arg && f->is_default) {
|
||||
/* load pos to default with right order */
|
||||
if (n_default_skiped < n_default_skip) {
|
||||
n_default_skiped++;
|
||||
arg_name = strPopLastToken(f->type_list, ',');
|
||||
continue;
|
||||
}
|
||||
/* load default from pos */
|
||||
if (f->i_arg > f->n_positional) {
|
||||
arg_setNameHash(call_arg,
|
||||
|
@ -932,6 +1050,7 @@ static void _kw_to_pos_all(FunctionArgsInfo* f, int* argc, Arg* argv[]) {
|
|||
static void _loadLocalsFromArgv(Args* locals, int argc, Arg* argv[]) {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Arg* arg = argv[i];
|
||||
pika_assert(arg != NULL);
|
||||
args_setArg(locals, arg);
|
||||
}
|
||||
}
|
||||
|
@ -1012,7 +1131,7 @@ static void _load_call_arg(VMState* vm,
|
|||
}
|
||||
char* arg_name = strPopLastToken(f->type_list, ',');
|
||||
/* load default from kw */
|
||||
arg_name = _kw_to_default_all(f, arg_name, argc, argv, call_arg);
|
||||
arg_name = _kw_pos_to_default_all(f, arg_name, argc, argv, call_arg);
|
||||
if (((char*)1) == arg_name) {
|
||||
/* load default from pos */
|
||||
return;
|
||||
|
@ -1028,15 +1147,16 @@ static void _load_call_arg(VMState* vm,
|
|||
}
|
||||
/*load pos from pos */
|
||||
arg_setNameHash(call_arg, hash_time33EndWith(arg_name, ':'));
|
||||
pika_assert(call_arg != NULL);
|
||||
argv[(*argc)++] = call_arg;
|
||||
(f->n_positional_got)++;
|
||||
}
|
||||
|
||||
static int _get_n_input_with_unpack(VMState* vm) {
|
||||
static int _get_n_input_with_unpack(VMState* vm, int n_used) {
|
||||
#if PIKA_NANO_ENABLE
|
||||
return VMState_getInputArgNum(vm);
|
||||
#else
|
||||
int n_input = VMState_getInputArgNum(vm);
|
||||
int n_input = VMState_getInputArgNum(vm) - n_used;
|
||||
int get_star = 0;
|
||||
int unpack_num = 0;
|
||||
for (int i = 0; i < n_input; i++) {
|
||||
|
@ -1168,7 +1288,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
|
|||
f.n_positional--;
|
||||
}
|
||||
|
||||
f.n_input = _get_n_input_with_unpack(vm);
|
||||
f.n_input = _get_n_input_with_unpack(vm, n_used);
|
||||
|
||||
/* check arg num */
|
||||
if (f.method_type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
|
||||
|
@ -1258,7 +1378,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
|
|||
#if !PIKA_NANO_ENABLE
|
||||
if (strIsContain(f.type_list, '=')) {
|
||||
char* arg_name = strPopLastToken(f.type_list, ',');
|
||||
_kw_to_default_all(&f, arg_name, &argc, argv, NULL);
|
||||
_kw_pos_to_default_all(&f, arg_name, &argc, argv, NULL);
|
||||
}
|
||||
/* load kw to pos */
|
||||
_kw_to_pos_all(&f, &argc, argv);
|
||||
|
@ -1290,7 +1410,12 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
|
|||
|
||||
/* load 'self' as the first arg when call object method */
|
||||
if (f.method_type == ARG_TYPE_METHOD_OBJECT) {
|
||||
Arg* call_arg = arg_setRef(NULL, "self", method_host_obj);
|
||||
PikaObj* method_self = methodArg_getHostObj(method_arg);
|
||||
if (NULL == method_self) {
|
||||
method_self = method_host_obj;
|
||||
}
|
||||
Arg* call_arg = arg_setRef(NULL, "self", method_self);
|
||||
pika_assert(call_arg != NULL);
|
||||
argv[argc++] = call_arg;
|
||||
}
|
||||
_loadLocalsFromArgv(locals, argc, argv);
|
||||
|
@ -1497,8 +1622,8 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||
}
|
||||
|
||||
/* tuple or single arg */
|
||||
if (run_path[0] == 0) {
|
||||
if (VMState_getInputArgNum(vm) < 2) {
|
||||
if (NULL == run_path || run_path[0] == 0) {
|
||||
if (VMState_getInputArgNum(vm) == 1) {
|
||||
/* return arg directly */
|
||||
return_arg = stack_popArg(&(vm->stack), arg_ret_reg);
|
||||
goto exit;
|
||||
|
@ -1567,7 +1692,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||
method_host = obj_getHostObjWithIsTemp(vm->locals, run_path, &is_temp);
|
||||
}
|
||||
|
||||
/* get method host obj from local scope */
|
||||
/* get method host obj from global scope */
|
||||
if (NULL == method_host) {
|
||||
method_host = obj_getHostObjWithIsTemp(vm->globals, run_path, &is_temp);
|
||||
}
|
||||
|
@ -1606,6 +1731,9 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||
/* get method in global */
|
||||
if (NULL == method) {
|
||||
method = obj_getMethodArg_noalloc(vm->globals, run_path, &arg_reg1);
|
||||
if (method != NULL) {
|
||||
obj_this = vm->globals;
|
||||
}
|
||||
}
|
||||
|
||||
/* assert method exist */
|
||||
|
@ -1709,7 +1837,7 @@ exit:
|
|||
}
|
||||
if (NULL != method_host && is_temp) {
|
||||
/* class method */
|
||||
obj_deinit(method_host);
|
||||
obj_GC(method_host);
|
||||
}
|
||||
|
||||
return return_arg;
|
||||
|
@ -2074,6 +2202,9 @@ void operatorInfo_init(OperatorInfo* info,
|
|||
} else if (info->t1 == ARG_TYPE_FLOAT) {
|
||||
info->f1 = arg_getFloat(info->a1);
|
||||
info->i1 = (int64_t)info->f1;
|
||||
} else if (info->t1 == ARG_TYPE_BOOL) {
|
||||
info->i1 = arg_getBool(info->a1);
|
||||
info->f1 = (pika_float)info->i1;
|
||||
}
|
||||
}
|
||||
info->t2 = arg_getType(info->a2);
|
||||
|
@ -2084,6 +2215,9 @@ void operatorInfo_init(OperatorInfo* info,
|
|||
} else if (info->t2 == ARG_TYPE_FLOAT) {
|
||||
info->f2 = arg_getFloat(info->a2);
|
||||
info->i2 = (int64_t)info->f2;
|
||||
} else if (info->t2 == ARG_TYPE_BOOL) {
|
||||
info->i2 = arg_getBool(info->a2);
|
||||
info->f2 = (pika_float)info->i2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2263,14 +2397,18 @@ static void _OPT_EQU(OperatorInfo* op) {
|
|||
}
|
||||
goto exit;
|
||||
}
|
||||
/* default: int and float */
|
||||
if (argType_isCallable(op->t1) && argType_isCallable(op->t2)) {
|
||||
is_equ = (arg_getPtr(op->a1) == arg_getPtr(op->a2));
|
||||
goto exit;
|
||||
}
|
||||
/* default: int bool, and float */
|
||||
is_equ = ((op->f1 - op->f2) * (op->f1 - op->f2) < (pika_float)0.000001);
|
||||
goto exit;
|
||||
exit:
|
||||
if (op->opt[0] == '=') {
|
||||
op->res = arg_setInt(op->res, "", is_equ);
|
||||
op->res = arg_setBool(op->res, "", is_equ);
|
||||
} else {
|
||||
op->res = arg_setInt(op->res, "", !is_equ);
|
||||
op->res = arg_setBool(op->res, "", !is_equ);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -2354,7 +2492,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
|||
if (data[1] == 0) {
|
||||
switch (data[0]) {
|
||||
case '<':
|
||||
op.res = arg_setInt(op.res, "", op.f1 < op.f2);
|
||||
op.res = arg_setBool(op.res, "", op.f1 < op.f2);
|
||||
goto exit;
|
||||
case '*':
|
||||
if (op.num == 1) {
|
||||
|
@ -2416,9 +2554,9 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
|||
if (data[1] == 'i' && data[2] == 'n') {
|
||||
if (op.t1 == ARG_TYPE_STRING && op.t2 == ARG_TYPE_STRING) {
|
||||
if (strstr(arg_getStr(op.a2), arg_getStr(op.a1))) {
|
||||
op.res = arg_setInt(op.res, "", 1);
|
||||
op.res = arg_setBool(op.res, "", PIKA_TRUE);
|
||||
} else {
|
||||
op.res = arg_setInt(op.res, "", 0);
|
||||
op.res = arg_setBool(op.res, "", PIKA_FALSE);
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
|
@ -2446,7 +2584,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
|||
0x00, /* const pool */
|
||||
};
|
||||
pikaVM_runByteCode(obj2, (uint8_t*)bytes);
|
||||
op.res = arg_setInt(op.res, "", obj_getInt(obj2, "__res"));
|
||||
op.res = arg_setBool(op.res, "", obj_getInt(obj2, "__res"));
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
@ -2490,14 +2628,14 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
|||
goto exit;
|
||||
}
|
||||
if (data[0] == '>' && data[1] == '=') {
|
||||
op.res = arg_setInt(
|
||||
op.res = arg_setBool(
|
||||
op.res, "",
|
||||
(op.f1 > op.f2) ||
|
||||
((op.f1 - op.f2) * (op.f1 - op.f2) < (pika_float)0.000001));
|
||||
goto exit;
|
||||
}
|
||||
if (data[0] == '<' && data[1] == '=') {
|
||||
op.res = arg_setInt(
|
||||
op.res = arg_setBool(
|
||||
op.res, "",
|
||||
(op.f1 < op.f2) ||
|
||||
((op.f1 - op.f2) * (op.f1 - op.f2) < (pika_float)0.000001));
|
||||
|
@ -2527,17 +2665,17 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
|||
}
|
||||
if (data[0] == ' ' && data[1] == 'a' && data[2] == 'n' && data[3] == 'd' &&
|
||||
data[4] == ' ') {
|
||||
op.res = arg_setInt(op.res, "", op.i1 && op.i2);
|
||||
op.res = arg_setBool(op.res, "", op.i1 && op.i2);
|
||||
goto exit;
|
||||
}
|
||||
if (data[0] == ' ' && data[1] == 'o' && data[2] == 'r' && data[3] == ' ' &&
|
||||
data[4] == 0) {
|
||||
op.res = arg_setInt(op.res, "", op.i1 || op.i2);
|
||||
op.res = arg_setBool(op.res, "", op.i1 || op.i2);
|
||||
goto exit;
|
||||
}
|
||||
if (data[0] == ' ' && data[1] == 'n' && data[2] == 'o' && data[3] == 't' &&
|
||||
data[4] == ' ' && data[5] == 0) {
|
||||
op.res = arg_setInt(op.res, "", !op.i2);
|
||||
op.res = arg_setBool(op.res, "", !op.i2);
|
||||
goto exit;
|
||||
}
|
||||
exit:
|
||||
|
@ -2647,7 +2785,9 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self,
|
|||
arg1 = stack_popArg(&vm->stack, ®1);
|
||||
}
|
||||
/* assert failed */
|
||||
if (arg_getType(arg1) == ARG_TYPE_INT && arg_getInt(arg1) == 0) {
|
||||
if ((arg_getType(arg1) == ARG_TYPE_INT && arg_getInt(arg1) == 0) ||
|
||||
(arg_getType(arg1) == ARG_TYPE_BOOL &&
|
||||
arg_getBool(arg1) == PIKA_FALSE)) {
|
||||
stack_pushArg(&vm->stack, arg_newInt(PIKA_RES_ERR_ASSERT));
|
||||
res = VM_instruction_handler_RIS(self, vm, data, arg_ret_reg);
|
||||
if (vm->run_state->try_state == TRY_STATE_NONE) {
|
||||
|
@ -2784,12 +2924,12 @@ static Arg* VM_instruction_handler_IMP(PikaObj* self,
|
|||
|
||||
const VM_instruct_handler VM_instruct_handler_table[__INSTRCUTION_CNT] = {
|
||||
#define __INS_TABLE
|
||||
#include "__instruction_table.cfg"
|
||||
#include "__instruction_table.h"
|
||||
};
|
||||
|
||||
enum Instruct pikaVM_getInstructFromAsm(char* ins_str) {
|
||||
#define __INS_COMPIRE
|
||||
#include "__instruction_table.cfg"
|
||||
#include "__instruction_table.h"
|
||||
return NON;
|
||||
}
|
||||
|
||||
|
@ -3214,6 +3354,7 @@ void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
|
|||
self->const_pool.content_start =
|
||||
arg_getBytes(self->const_pool.arg_buff);
|
||||
}
|
||||
pika_assert(NULL != self->const_pool.content_start);
|
||||
}
|
||||
|
||||
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes) {
|
||||
|
@ -3280,7 +3421,7 @@ InstructUnit* instructArray_getNext(InstructArray* self) {
|
|||
|
||||
static char* instructUnit_getInstructStr(InstructUnit* self) {
|
||||
#define __INS_GET_INS_STR
|
||||
#include "__instruction_table.cfg"
|
||||
#include "__instruction_table.h"
|
||||
return "NON";
|
||||
}
|
||||
|
||||
|
@ -3393,7 +3534,7 @@ void VMState_solveUnusedStack(VMState* vm) {
|
|||
arg_deinit(arg);
|
||||
continue;
|
||||
}
|
||||
arg_singlePrint(arg, PIKA_TRUE, "\r\n");
|
||||
arg_print(arg, PIKA_TRUE, "\r\n");
|
||||
arg_deinit(arg);
|
||||
}
|
||||
}
|
||||
|
@ -3408,21 +3549,19 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState(
|
|||
pika_assert(NULL != run_state);
|
||||
int size = bytecode_frame->instruct_array.size;
|
||||
/* locals is the local scope */
|
||||
VMState vm = {
|
||||
.bytecode_frame = bytecode_frame,
|
||||
.locals = locals,
|
||||
.globals = globals,
|
||||
.jmp = 0,
|
||||
.pc = pc,
|
||||
.loop_deepth = 0,
|
||||
.error_code = PIKA_RES_OK,
|
||||
.line_error_code = PIKA_RES_OK,
|
||||
.try_error_code = PIKA_RES_OK,
|
||||
.run_state = run_state,
|
||||
.ins_cnt = 0,
|
||||
.in_super = PIKA_FALSE,
|
||||
.super_invoke_deepth = 0,
|
||||
};
|
||||
VMState vm = {.bytecode_frame = bytecode_frame,
|
||||
.locals = locals,
|
||||
.globals = globals,
|
||||
.jmp = 0,
|
||||
.pc = pc,
|
||||
.loop_deepth = 0,
|
||||
.error_code = PIKA_RES_OK,
|
||||
.line_error_code = PIKA_RES_OK,
|
||||
.try_error_code = PIKA_RES_OK,
|
||||
.run_state = run_state,
|
||||
.ins_cnt = 0,
|
||||
.in_super = PIKA_FALSE,
|
||||
.super_invoke_deepth = 0};
|
||||
stack_init(&(vm.stack));
|
||||
VMState_initReg(&vm);
|
||||
if (PikaVMSignal.vm_cnt == 0) {
|
||||
|
@ -3448,9 +3587,7 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState(
|
|||
pika_hook_instruct();
|
||||
}
|
||||
#endif
|
||||
#if PIKA_EVENT_ENABLE
|
||||
_VMEvent_pickupEvent();
|
||||
#endif
|
||||
_pikaVM_yield();
|
||||
if (0 != vm.error_code) {
|
||||
vm.line_error_code = vm.error_code;
|
||||
InstructUnit* head_ins_unit = this_ins_unit;
|
||||
|
@ -3544,19 +3681,31 @@ void byteCodeFrame_printAsArray(ByteCodeFrame* self) {
|
|||
|
||||
PikaObj* pikaVM_runFile(PikaObj* self, char* file_name) {
|
||||
Args buffs = {0};
|
||||
char* module_name = strsCopy(&buffs, file_name);
|
||||
char* module_name = strsPathGetFileName(&buffs, file_name);
|
||||
strPopLastToken(module_name, '.');
|
||||
|
||||
char* pwd = strsPathGetFolder(&buffs, file_name);
|
||||
pika_platform_printf("(pikascript) pika compiler:\r\n");
|
||||
PikaMaker* maker = New_PikaMaker();
|
||||
pikaMaker_setPWD(maker, pwd);
|
||||
pikaMaker_compileModuleWithDepends(maker, module_name);
|
||||
pikaMaker_linkCompiledModules(maker, "pikaModules_cache.py.a");
|
||||
_do_pikaMaker_linkCompiledModules(maker, "pikaModules_cache.py.a",
|
||||
PIKA_FALSE);
|
||||
pikaMaker_deinit(maker);
|
||||
pika_platform_printf("(pikascript) all succeed.\r\n\r\n");
|
||||
|
||||
pikaMemMaxReset();
|
||||
obj_linkLibraryFile(self, "pikascript-api/pikaModules_cache.py.a");
|
||||
char* libfile_path =
|
||||
strsPathJoin(&buffs, pwd, "pikascript-api/pikaModules_cache.py.a");
|
||||
obj_linkLibraryFile(self, libfile_path);
|
||||
self = pikaVM_runSingleFile(self, file_name);
|
||||
strsDeinit(&buffs);
|
||||
return self;
|
||||
}
|
||||
|
||||
void _pikaVM_yield(void) {
|
||||
#if PIKA_EVENT_ENABLE
|
||||
_VMEvent_pickupEvent();
|
||||
#endif
|
||||
pika_GIL_EXIT();
|
||||
pika_GIL_ENTER();
|
||||
}
|
||||
|
|
|
@ -31,10 +31,13 @@
|
|||
#include "dataQueue.h"
|
||||
#include "dataQueueObj.h"
|
||||
#include "dataStack.h"
|
||||
#if PIKA_SETJMP_ENABLE
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
enum Instruct {
|
||||
#define __INS_ENUM
|
||||
#include "__instruction_table.cfg"
|
||||
#include "__instruction_table.h"
|
||||
__INSTRCUTION_CNT,
|
||||
};
|
||||
|
||||
|
@ -45,7 +48,7 @@ typedef enum {
|
|||
VM_JMP_RAISE = -996,
|
||||
} VM_JMP;
|
||||
|
||||
typedef enum { VM_PC_EXIT = -99999 } VM_PC;
|
||||
#define VM_PC_EXIT (-99999)
|
||||
|
||||
typedef enum {
|
||||
TRY_STATE_NONE = 0,
|
||||
|
@ -132,6 +135,14 @@ typedef struct EventCQ {
|
|||
int tail;
|
||||
} EventCQ;
|
||||
|
||||
#if PIKA_SETJMP_ENABLE
|
||||
typedef struct JmpBufCQ {
|
||||
jmp_buf* buf[PIKA_JMP_BUF_LIST_SIZE];
|
||||
int head;
|
||||
int tail;
|
||||
} JmpBufCQ;
|
||||
#endif
|
||||
|
||||
typedef struct VMSignal VMSignal;
|
||||
struct VMSignal {
|
||||
VM_SIGNAL_CTRL signal_ctrl;
|
||||
|
@ -313,4 +324,7 @@ PIKA_RES __eventListener_pushEvent(PikaEventListener* lisener,
|
|||
Arg* eventData);
|
||||
int _VMEvent_getVMCnt(void);
|
||||
void _VMEvent_pickupEvent(void);
|
||||
void _pikaVM_yield(void);
|
||||
int _VM_lock_init(void);
|
||||
int _VM_is_first_lock(void);
|
||||
#endif
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
#define PIKA_VERSION_MINOR 12
|
||||
#define PIKA_VERSION_MICRO 0
|
||||
|
||||
#define PIKA_EDIT_TIME "2022/12/29 18:05:17"
|
||||
#define PIKA_EDIT_TIME "2023/02/18 20:34:52"
|
||||
|
|
69
examples/pikapython/pikapython/pikascript-core/__default_filter_msg_def.h
Executable file
69
examples/pikapython/pikapython/pikascript-core/__default_filter_msg_def.h
Executable file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of the PikaScript project.
|
||||
* http://github.com/pikastech/pikascript
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 GorgonMeducer ?? embedded_zhuoran@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#undef add_filter_msg
|
||||
#undef add_filter_item
|
||||
#undef __add_filter_msg
|
||||
#undef __add_filter_item
|
||||
#undef __NO_FILTER_HANLDER__
|
||||
|
||||
|
||||
#if defined(__MSG_TABLE)
|
||||
#define __add_filter_msg(__name, __msg, ...) \
|
||||
{ \
|
||||
.message = (const uint8_t []){__msg}, \
|
||||
.size = sizeof((const uint8_t []){__msg}) - 1, \
|
||||
.handler = _filter_msg_##__name##_handler, \
|
||||
__VA_ARGS__ \
|
||||
},
|
||||
#define __add_filter_item(__name, ...) \
|
||||
{ \
|
||||
.handler = _filter_msg_##__name##_handler, \
|
||||
__VA_ARGS__ \
|
||||
},
|
||||
#endif
|
||||
|
||||
#if defined(__MSG_DECLARE)
|
||||
#define __add_filter_msg(__name, __msg, ...) \
|
||||
PIKA_BOOL _filter_msg_##__name##_handler( FilterItem *msg, \
|
||||
PikaObj* self, \
|
||||
ShellConfig* shell);
|
||||
#define __add_filter_item(__name, ...) \
|
||||
PIKA_BOOL _filter_msg_##__name##_handler( FilterItem *msg, \
|
||||
PikaObj* self, \
|
||||
ShellConfig* shell);
|
||||
#endif
|
||||
|
||||
#undef __MSG_TABLE
|
||||
#undef __MSG_DECLARE
|
||||
|
||||
|
||||
#define add_filter_msg(__name, __msg, ...) \
|
||||
__add_filter_msg(__name, __msg, ##__VA_ARGS__)
|
||||
#define add_filter_item(__name, ...) \
|
||||
__add_filter_item(__name, ##__VA_ARGS__)
|
||||
#define __NO_FILTER_HANLDER__ .handler = NULL
|
74
examples/pikapython/pikapython/pikascript-core/__default_filter_msg_table.h
Executable file
74
examples/pikapython/pikapython/pikascript-core/__default_filter_msg_table.h
Executable file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* This file is part of the PikaScript project.
|
||||
* http://github.com/pikastech/pikascript
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 GorgonMeducer ?? embedded_zhuoran@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "__default_filter_msg_def.h"
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wunknown-warning-option"
|
||||
# pragma clang diagnostic ignored "-Winitializer-overrides"
|
||||
#endif
|
||||
|
||||
/* add your own message filter here with syntax:
|
||||
*
|
||||
* add_filter_msg(
|
||||
* <name>,
|
||||
* <string>,
|
||||
* [.is_visible = PIKA_TRUE,]
|
||||
* [.is_case_insensitive = PIKA_TRUE,]
|
||||
* [.ignore_mask = mask value,]
|
||||
* [.target = your own object address/value,]
|
||||
* )
|
||||
*/
|
||||
|
||||
add_filter_msg(hi_pika, "###Hi Pika")
|
||||
add_filter_msg(bye_pika, "###bye pika", .is_case_insensitive = PIKA_TRUE)
|
||||
|
||||
/* add your own message item here with syntax:
|
||||
*
|
||||
* add_filter_item(
|
||||
* <name>,
|
||||
* .message = (const uint8_t []){< num0, num1, ... >},
|
||||
* .size = <array size>,
|
||||
* [.is_visible = PIKA_TRUE,]
|
||||
* [.is_case_insensitive = PIKA_TRUE,]
|
||||
* [.ignore_mask = mask value,]
|
||||
* [.target = your own object address/value,]
|
||||
* )
|
||||
*
|
||||
* for example:
|
||||
*
|
||||
* add_filter_item(
|
||||
* example_array,
|
||||
* .message = (const uint8_t []){'a','b','c'},
|
||||
* .size = 3,
|
||||
* __NO_FILTER_HANLDER__,
|
||||
* )
|
||||
*/
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
98
examples/pikapython/pikapython/pikascript-core/__instruction_table.h
Executable file
98
examples/pikapython/pikapython/pikascript-core/__instruction_table.h
Executable file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* This file is part of the PikaScript project.
|
||||
* http://github.com/pikastech/pikascript
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 GorgonMeducer ?? embedded_zhuoran@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "__instruction_def.h"
|
||||
|
||||
//! just append ins to the end, insert ins would brake the pre-compiled
|
||||
//! bytecode.
|
||||
|
||||
/* none */
|
||||
def_ins(NON)
|
||||
/* get referance */
|
||||
def_ins(REF)
|
||||
/* run function */
|
||||
def_ins(RUN)
|
||||
/* string */
|
||||
def_ins(STR)
|
||||
/* output */
|
||||
def_ins(OUT)
|
||||
/* number */
|
||||
def_ins(NUM)
|
||||
/* jump */
|
||||
def_ins(JMP)
|
||||
/* jump qual zero */
|
||||
def_ins(JEZ)
|
||||
/* operator */
|
||||
def_ins(OPT)
|
||||
/* define */
|
||||
def_ins(DEF)
|
||||
/* return */
|
||||
def_ins(RET)
|
||||
/* not equal */
|
||||
def_ins(NEL)
|
||||
/* delete */
|
||||
def_ins(DEL)
|
||||
/* exist */
|
||||
def_ins(EST)
|
||||
/* break */
|
||||
def_ins(BRK)
|
||||
/* continue */
|
||||
def_ins(CTN)
|
||||
/* global */
|
||||
def_ins(GLB)
|
||||
/* run as */
|
||||
def_ins(RAS)
|
||||
/* new */
|
||||
def_ins(NEW)
|
||||
/* class */
|
||||
def_ins(CLS)
|
||||
/* bytes */
|
||||
def_ins(BYT)
|
||||
/* list */
|
||||
def_ins(LST)
|
||||
/* import */
|
||||
def_ins(IMP)
|
||||
/* try */
|
||||
def_ins(TRY)
|
||||
/* not try */
|
||||
def_ins(NTR)
|
||||
/* raise */
|
||||
def_ins(RIS)
|
||||
/* get error code */
|
||||
def_ins(GER)
|
||||
/* set error code */
|
||||
def_ins(SER)
|
||||
/* dict */
|
||||
def_ins(DCT)
|
||||
/* slice */
|
||||
def_ins(SLC)
|
||||
/* assert */
|
||||
def_ins(ASS)
|
||||
/* expect */
|
||||
def_ins(EXP)
|
||||
/* jump no zero */
|
||||
def_ins(JNZ)
|
|
@ -26,11 +26,16 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __PIKA_OOC_H__
|
||||
#define __PIKA_OOC_H__
|
||||
#if PIKA_PLOOC_ENABLE
|
||||
#include "../pikascript-lib/PLOOC/plooc_class.h"
|
||||
#else
|
||||
#define private_member(X) X
|
||||
/* non-reentrant part */
|
||||
#if !defined(PIKA_PLOOC_ENABLE) || !PIKA_PLOOC_ENABLE
|
||||
#define private_member(...) __VA_ARGS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* plooc_class.h should support reentrant */
|
||||
#if PIKA_PLOOC_ENABLE
|
||||
#include "../pikascript-lib/PLOOC/plooc_class.h"
|
||||
#endif
|
||||
|
|
|
@ -142,7 +142,7 @@ static Arg* _arg_set_hash(Arg* self,
|
|||
pika_platform_memcpy(arg_getContent(self), content, size);
|
||||
} else {
|
||||
pika_platform_memset(arg_getContent(self), 0,
|
||||
aline_by(size, sizeof(uint32_t)));
|
||||
aline_by(size, sizeof(uint32_t)));
|
||||
}
|
||||
pika_assert(self->flag < ARG_FLAG_MAX);
|
||||
return self;
|
||||
|
@ -243,7 +243,8 @@ Arg* arg_setBytes(Arg* self, char* name, uint8_t* src, size_t size) {
|
|||
|
||||
/* set init value */
|
||||
if (NULL != src) {
|
||||
pika_platform_memcpy((void*)((uintptr_t)dir + sizeof(size_t)), src, size);
|
||||
pika_platform_memcpy((void*)((uintptr_t)dir + sizeof(size_t)), src,
|
||||
size);
|
||||
}
|
||||
pika_assert(self->flag < ARG_FLAG_MAX);
|
||||
return self;
|
||||
|
@ -258,67 +259,98 @@ uint8_t* arg_getBytes(Arg* self) {
|
|||
return arg_getContent(self) + sizeof(size_t);
|
||||
}
|
||||
|
||||
char* __printBytes(PikaObj* self, Arg* arg) {
|
||||
Args buffs = {0};
|
||||
size_t bytes_size = arg_getBytesSize(arg);
|
||||
uint8_t* bytes = arg_getBytes(arg);
|
||||
Arg* str_arg = arg_newStr("b\'");
|
||||
for (size_t i = 0; i < bytes_size; i++) {
|
||||
char* str_item = strsFormat(&buffs, 16, "\\x%02x", bytes[i]);
|
||||
str_arg = arg_strAppend(str_arg, str_item);
|
||||
}
|
||||
str_arg = arg_strAppend(str_arg, "\'");
|
||||
char* str_res = obj_cacheStr(self, arg_getStr(str_arg));
|
||||
strsDeinit(&buffs);
|
||||
arg_deinit(str_arg);
|
||||
return str_res;
|
||||
}
|
||||
|
||||
void arg_printBytes(Arg* self, char* end) {
|
||||
PikaObj* obj = New_PikaObj();
|
||||
pika_platform_printf("%s%s", __printBytes(obj, self), end);
|
||||
obj_deinit(obj);
|
||||
}
|
||||
|
||||
void arg_singlePrint(Arg* self, PIKA_BOOL in_REPL, char* end) {
|
||||
ArgType type = arg_getType(self);
|
||||
if (ARG_TYPE_NONE == type) {
|
||||
pika_platform_printf("None%s", end);
|
||||
return;
|
||||
}
|
||||
if (argType_isObject(type)) {
|
||||
char* res = obj_toStr(arg_getPtr(self));
|
||||
pika_platform_printf("%s%s", res, end);
|
||||
return;
|
||||
Arg* arg_toStrArg(Arg* arg) {
|
||||
ArgType type = arg_getType(arg);
|
||||
char buff[PIKA_SPRINTF_BUFF_SIZE] = {0};
|
||||
if (type == ARG_TYPE_BYTES) {
|
||||
char buff_item[16] = {0};
|
||||
size_t bytes_size = arg_getBytesSize(arg);
|
||||
uint8_t* bytes = arg_getBytes(arg);
|
||||
Arg* str_arg = arg_newStr("b\'");
|
||||
for (size_t i = 0; i < bytes_size; i++) {
|
||||
pika_platform_snprintf(buff_item, 16, "\\x%02x", bytes[i]);
|
||||
char* str_item = (char*)buff_item;
|
||||
str_arg = arg_strAppend(str_arg, str_item);
|
||||
}
|
||||
str_arg = arg_strAppend(str_arg, "\'");
|
||||
return str_arg;
|
||||
}
|
||||
if (type == ARG_TYPE_INT) {
|
||||
#if PIKA_PRINT_LLD_ENABLE
|
||||
pika_platform_printf("%lld%s", (long long int)arg_getInt(self), end);
|
||||
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE, "%lld",
|
||||
(long long int)arg_getInt(arg));
|
||||
#else
|
||||
pika_platform_printf("%d%s", (int)arg_getInt(self), end);
|
||||
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE, "%d",
|
||||
(int)arg_getInt(arg));
|
||||
#endif
|
||||
return;
|
||||
return arg_newStr(buff);
|
||||
}
|
||||
if (type == ARG_TYPE_BOOL) {
|
||||
if (arg_getBool(arg)) {
|
||||
return arg_newStr("True");
|
||||
}
|
||||
return arg_newStr("False");
|
||||
}
|
||||
if (type == ARG_TYPE_FLOAT) {
|
||||
pika_platform_printf("%f%s", arg_getFloat(self), end);
|
||||
return;
|
||||
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE, "%f",
|
||||
arg_getFloat(arg));
|
||||
return arg_newStr(buff);
|
||||
}
|
||||
if (type == ARG_TYPE_STRING) {
|
||||
if (in_REPL) {
|
||||
pika_platform_printf("'%s'%s", arg_getStr(self), end);
|
||||
return;
|
||||
return arg_newStr(arg_getStr(arg));
|
||||
}
|
||||
if (type == ARG_TYPE_POINTER) {
|
||||
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE, "%p",
|
||||
arg_getPtr(arg));
|
||||
return arg_newStr(buff);
|
||||
}
|
||||
if (argType_isCallable(type)) {
|
||||
/* support basic type */
|
||||
if (type == ARG_TYPE_METHOD_NATIVE) {
|
||||
MethodProp* method_store = (MethodProp*)arg_getContent(arg);
|
||||
if (strEqu(method_store->name, "int") ||
|
||||
strEqu(method_store->name, "bool") ||
|
||||
strEqu(method_store->name, "float") ||
|
||||
strEqu(method_store->name, "str") ||
|
||||
strEqu(method_store->name, "bytes") ||
|
||||
strEqu(method_store->name, "list") ||
|
||||
strEqu(method_store->name, "dict") ||
|
||||
strEqu(method_store->name, "tuple")) {
|
||||
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE,
|
||||
"<class '%s'>", method_store->name);
|
||||
}
|
||||
return arg_newStr(buff);
|
||||
}
|
||||
pika_platform_printf("%s%s", arg_getStr(self), end);
|
||||
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE,
|
||||
"<class 'function'>");
|
||||
return arg_newStr(buff);
|
||||
}
|
||||
if (type == ARG_TYPE_NONE) {
|
||||
return arg_newStr("None");
|
||||
}
|
||||
if (argType_isObject(type)) {
|
||||
return arg_newStr(obj_toStr(arg_getPtr(arg)));
|
||||
}
|
||||
if (type == ARG_TYPE_OBJECT_META) {
|
||||
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE,
|
||||
"<mate object at %p>", arg_getPtr(arg));
|
||||
return arg_newStr(buff);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void arg_print(Arg* self, PIKA_BOOL in_REPL, char* end) {
|
||||
/* use arg_toStrArg() */
|
||||
Arg* str_arg = arg_toStrArg(self);
|
||||
if (NULL == str_arg) {
|
||||
return;
|
||||
}
|
||||
if (type == ARG_TYPE_BYTES) {
|
||||
arg_printBytes(self, end);
|
||||
return;
|
||||
}
|
||||
if (ARG_TYPE_POINTER == type || ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR) {
|
||||
pika_platform_printf("%p%s", arg_getPtr(self), end);
|
||||
return;
|
||||
if (in_REPL && arg_getType(self) == ARG_TYPE_STRING) {
|
||||
pika_platform_printf("'%s'%s", arg_getStr(str_arg), end);
|
||||
} else {
|
||||
pika_platform_printf("%s%s", arg_getStr(str_arg), end);
|
||||
}
|
||||
arg_deinit(str_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -370,6 +402,10 @@ Arg* arg_setInt(Arg* self, char* name, int64_t val) {
|
|||
return arg_set(self, name, ARG_TYPE_INT, (uint8_t*)&val, sizeof(val));
|
||||
}
|
||||
|
||||
Arg* arg_setBool(Arg* self, char* name, PIKA_BOOL val) {
|
||||
return arg_set(self, name, ARG_TYPE_BOOL, (uint8_t*)&val, sizeof(val));
|
||||
}
|
||||
|
||||
Arg* arg_setNull(Arg* self) {
|
||||
return arg_set(self, "", ARG_TYPE_NONE, NULL, 0);
|
||||
}
|
||||
|
@ -401,11 +437,19 @@ Arg* arg_setStr(Arg* self, char* name, char* string) {
|
|||
int64_t arg_getInt(Arg* self) {
|
||||
pika_assert(NULL != self);
|
||||
if (NULL == arg_getContent(self)) {
|
||||
return -999999;
|
||||
return _PIKA_INT_ERR;
|
||||
}
|
||||
return *(int64_t*)arg_getContent(self);
|
||||
}
|
||||
|
||||
PIKA_BOOL arg_getBool(Arg* self) {
|
||||
pika_assert(NULL != self);
|
||||
if (NULL == arg_getContent(self)) {
|
||||
return _PIKA_BOOL_ERR;
|
||||
}
|
||||
return *(PIKA_BOOL*)arg_getContent(self);
|
||||
}
|
||||
|
||||
void* arg_getPtr(Arg* self) {
|
||||
if (arg_getType(self) == ARG_TYPE_NONE) {
|
||||
return NULL;
|
||||
|
@ -427,15 +471,24 @@ Arg* New_arg(void* voidPointer) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void _arg_refcnt_fix(Arg* self) {
|
||||
ArgType arg_type = arg_getType(self);
|
||||
if (ARG_TYPE_OBJECT == arg_type) {
|
||||
obj_refcntInc((PikaObj*)arg_getPtr(self));
|
||||
}
|
||||
// if (ARG_TYPE_METHOD_OBJECT == arg_type) {
|
||||
// if (NULL != methodArg_getHostObj(self)) {
|
||||
// obj_refcntInc((PikaObj*)arg_getPtr(self));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Arg* arg_copy(Arg* arg_src) {
|
||||
if (NULL == arg_src) {
|
||||
return NULL;
|
||||
}
|
||||
pika_assert(arg_src->flag < ARG_FLAG_MAX);
|
||||
ArgType arg_type = arg_getType(arg_src);
|
||||
if (ARG_TYPE_OBJECT == arg_type) {
|
||||
obj_refcntInc((PikaObj*)arg_getPtr(arg_src));
|
||||
}
|
||||
_arg_refcnt_fix(arg_src);
|
||||
Arg* arg_dict = New_arg(NULL);
|
||||
arg_dict = arg_setContent(arg_dict, arg_getContent(arg_src),
|
||||
arg_getContentSize(arg_src));
|
||||
|
@ -457,10 +510,7 @@ Arg* arg_copy_noalloc(Arg* arg_src, Arg* arg_dict) {
|
|||
if (arg_getSize(arg_src) > arg_getSize(arg_dict)) {
|
||||
return arg_copy(arg_src);
|
||||
}
|
||||
ArgType arg_type = arg_getType(arg_src);
|
||||
if (ARG_TYPE_OBJECT == arg_type) {
|
||||
obj_refcntInc((PikaObj*)arg_getPtr(arg_src));
|
||||
}
|
||||
_arg_refcnt_fix(arg_src);
|
||||
arg_setSerialized(arg_dict, PIKA_FALSE);
|
||||
arg_dict = arg_setContent(arg_dict, arg_getContent(arg_src),
|
||||
arg_getContentSize(arg_src));
|
||||
|
@ -497,7 +547,7 @@ Arg* arg_append(Arg* self, void* new_content, size_t new_size) {
|
|||
}
|
||||
/* copy new content */
|
||||
pika_platform_memcpy(arg_getContent(new_arg) + old_size, new_content,
|
||||
new_size);
|
||||
new_size);
|
||||
if (self != new_arg) {
|
||||
arg_deinit(self);
|
||||
}
|
||||
|
@ -524,13 +574,15 @@ void arg_deinitHeap(Arg* self) {
|
|||
/* deinit sub object */
|
||||
if (ARG_TYPE_OBJECT == type) {
|
||||
PikaObj* subObj = arg_getPtr(self);
|
||||
obj_refcntDec(subObj);
|
||||
int ref_cnt = obj_refcntNow(subObj);
|
||||
if (ref_cnt <= 0) {
|
||||
obj_deinit(subObj);
|
||||
}
|
||||
obj_GC(subObj);
|
||||
return;
|
||||
}
|
||||
// if (ARG_TYPE_METHOD_OBJECT == type) {
|
||||
// PikaObj* hostObj = methodArg_getHostObj(self);
|
||||
// if (NULL != hostObj) {
|
||||
// obj_GC(hostObj);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/* load file as byte array */
|
||||
|
@ -592,7 +644,7 @@ PIKA_BOOL arg_isEqual(Arg* self, Arg* other) {
|
|||
}
|
||||
}
|
||||
if (0 != pika_platform_memcmp(arg_getContent(self), arg_getContent(other),
|
||||
arg_getContentSize(self))) {
|
||||
arg_getContentSize(self))) {
|
||||
return PIKA_FALSE;
|
||||
}
|
||||
return PIKA_TRUE;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* This file is part of the PikaScript project.
|
||||
* http://github.com/pikastech/pikascript
|
||||
*
|
||||
|
@ -36,6 +36,7 @@ typedef enum {
|
|||
ARG_TYPE_UNDEF = 0,
|
||||
ARG_TYPE_NONE,
|
||||
ARG_TYPE_INT,
|
||||
ARG_TYPE_BOOL,
|
||||
ARG_TYPE_FLOAT,
|
||||
ARG_TYPE_STRING,
|
||||
ARG_TYPE_BYTES,
|
||||
|
@ -100,10 +101,12 @@ static inline void arg_setType(Arg* self, ArgType type) {
|
|||
}
|
||||
|
||||
static inline Hash arg_getNameHash(Arg* self) {
|
||||
pika_assert(self != 0);
|
||||
return self->name_hash;
|
||||
}
|
||||
|
||||
static inline ArgType arg_getType(Arg* self) {
|
||||
pika_assert(self != 0);
|
||||
return (ArgType)self->type;
|
||||
}
|
||||
|
||||
|
@ -111,6 +114,7 @@ uint32_t arg_getContentSize(Arg* self);
|
|||
Hash hash_time33(char* str);
|
||||
|
||||
Arg* arg_setInt(Arg* self, char* name, int64_t val);
|
||||
Arg* arg_setBool(Arg* self, char* name, PIKA_BOOL val);
|
||||
Arg* arg_setFloat(Arg* self, char* name, pika_float val);
|
||||
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer);
|
||||
Arg* arg_setStr(Arg* self, char* name, char* string);
|
||||
|
@ -118,19 +122,23 @@ Arg* arg_setNull(Arg* self);
|
|||
Arg* arg_setBytes(Arg* self, char* name, uint8_t* src, size_t size);
|
||||
|
||||
static inline Arg* arg_newInt(int64_t val) {
|
||||
return arg_setInt(NULL, "", (val));
|
||||
return arg_setInt(NULL, (char*)"", (val));
|
||||
}
|
||||
|
||||
static inline Arg* arg_newBool(PIKA_BOOL val) {
|
||||
return arg_setBool(NULL, (char*)"", (val));
|
||||
}
|
||||
|
||||
static inline Arg* arg_newFloat(pika_float val) {
|
||||
return arg_setFloat(NULL, "", (val));
|
||||
return arg_setFloat(NULL, (char*)"", (val));
|
||||
}
|
||||
|
||||
static inline Arg* arg_newPtr(ArgType type, void* pointer) {
|
||||
return arg_setPtr(NULL, "", (type), (pointer));
|
||||
return arg_setPtr(NULL, (char*)"", (type), (pointer));
|
||||
}
|
||||
|
||||
static inline Arg* arg_newStr(char* string) {
|
||||
return arg_setStr(NULL, "", (string));
|
||||
return arg_setStr(NULL, (char*)"", (string));
|
||||
}
|
||||
|
||||
static inline Arg* arg_newNull() {
|
||||
|
@ -138,10 +146,11 @@ static inline Arg* arg_newNull() {
|
|||
}
|
||||
|
||||
static inline Arg* arg_newBytes(uint8_t* src, size_t size) {
|
||||
return arg_setBytes(NULL, "", (src), (size));
|
||||
return arg_setBytes(NULL, (char*)"", (src), (size));
|
||||
}
|
||||
|
||||
int64_t arg_getInt(Arg* self);
|
||||
PIKA_BOOL arg_getBool(Arg* self);
|
||||
pika_float arg_getFloat(Arg* self);
|
||||
void* arg_getPtr(Arg* self);
|
||||
char* arg_getStr(Arg* self);
|
||||
|
@ -165,8 +174,8 @@ Arg* arg_setHeapStruct(Arg* self,
|
|||
void* struct_deinit_fun);
|
||||
void* arg_getHeapStruct(Arg* self);
|
||||
void arg_deinitHeap(Arg* self);
|
||||
void arg_printBytes(Arg* self, char* end);
|
||||
void arg_singlePrint(Arg* self, PIKA_BOOL in_REPL, char* end);
|
||||
Arg* arg_toStrArg(Arg* arg);
|
||||
void arg_print(Arg* self, PIKA_BOOL in_REPL, char* end);
|
||||
Arg* arg_loadFile(Arg* self, char* filename);
|
||||
|
||||
#define ARG_FLAG_SERIALIZED 0x01
|
||||
|
|
|
@ -188,15 +188,29 @@ PIKA_RES args_setInt(Args* self, char* name, int64_t val) {
|
|||
int64_t args_getInt(Args* self, char* name) {
|
||||
Arg* arg = args_getArg(self, name);
|
||||
if (NULL == arg) {
|
||||
return -999999999;
|
||||
return _PIKA_INT_ERR;
|
||||
}
|
||||
ArgType arg_type = arg_getType(arg);
|
||||
if (arg_type == ARG_TYPE_INT) {
|
||||
return arg_getInt(arg);
|
||||
} else if (arg_type == ARG_TYPE_FLOAT) {
|
||||
return (int)arg_getFloat(arg);
|
||||
} else if (arg_type == ARG_TYPE_BOOL) {
|
||||
return arg_getBool(arg);
|
||||
}
|
||||
return -999999999;
|
||||
return _PIKA_INT_ERR;
|
||||
}
|
||||
|
||||
PIKA_BOOL args_getBool(Args* self, char* name) {
|
||||
Arg* arg = args_getArg(self, name);
|
||||
if (NULL == arg) {
|
||||
return _PIKA_BOOL_ERR;
|
||||
}
|
||||
ArgType arg_type = arg_getType(arg);
|
||||
if (arg_type == ARG_TYPE_BOOL) {
|
||||
return arg_getBool(arg);
|
||||
}
|
||||
return _PIKA_BOOL_ERR;
|
||||
}
|
||||
|
||||
int32_t args_getSize(Args* self) {
|
||||
|
@ -215,7 +229,7 @@ ArgType args_getType(Args* self, char* name) {
|
|||
pika_float args_getFloat(Args* self, char* name) {
|
||||
Arg* arg = args_getArg(self, name);
|
||||
if (NULL == arg) {
|
||||
return -999999999.0;
|
||||
return _PIKA_FLOAT_ERR;
|
||||
}
|
||||
ArgType arg_type = arg_getType(arg);
|
||||
if (arg_type == ARG_TYPE_FLOAT) {
|
||||
|
@ -223,7 +237,7 @@ pika_float args_getFloat(Args* self, char* name) {
|
|||
} else if (arg_type == ARG_TYPE_INT) {
|
||||
return (pika_float)arg_getInt(arg);
|
||||
}
|
||||
return -999999999.0;
|
||||
return _PIKA_FLOAT_ERR;
|
||||
}
|
||||
|
||||
PIKA_RES args_copyArg(Args* self, Arg* argToBeCopy) {
|
||||
|
@ -298,6 +312,8 @@ int32_t args_isArgExist(Args* self, char* name) {
|
|||
}
|
||||
|
||||
PIKA_RES __updateArg(Args* self, Arg* argNew) {
|
||||
pika_assert(NULL != self);
|
||||
pika_assert(NULL != argNew);
|
||||
LinkNode* nodeToUpdate = NULL;
|
||||
LinkNode* nodeNow = self->firstNode;
|
||||
LinkNode* priorNode = NULL;
|
||||
|
@ -345,6 +361,8 @@ exit:
|
|||
}
|
||||
|
||||
PIKA_RES args_setArg(Args* self, Arg* arg) {
|
||||
pika_assert(NULL != self);
|
||||
pika_assert(NULL != arg);
|
||||
if (PIKA_RES_OK == __updateArg(self, arg)) {
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ void* args_getPtr(Args* self, char* name);
|
|||
|
||||
PIKA_RES args_setInt(Args* self, char* name, int64_t int64In);
|
||||
int64_t args_getInt(Args* self, char* name);
|
||||
PIKA_BOOL args_getBool(Args* self, char* name);
|
||||
|
||||
char* args_print(Args* self, char* name);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "PikaPlatform.h"
|
||||
#include "PikaVersion.h"
|
||||
|
||||
/*! \NOTE: Make sure #include "plooc_class.h" is close to the class definition
|
||||
/*! \NOTE: Make sure #include "__pika_ooc.h" is close to the class definition
|
||||
*/
|
||||
#if defined(__DATA_MEMORY_CLASS_IMPLEMENT__)
|
||||
#define __PLOOC_CLASS_IMPLEMENT__
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2023 Gorgon Meducer embedded_zhuroan@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -24,7 +25,7 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#define __DATA_QUEUE_CLASS_IMPLEMENT__
|
||||
#include "dataQueue.h"
|
||||
#include "PikaPlatform.h"
|
||||
#include "dataArgs.h"
|
||||
|
@ -94,3 +95,132 @@ int32_t queue_pushStr(Queue* queue, char* str) {
|
|||
char* queue_popStr(Queue* queue) {
|
||||
return arg_getStr(__queue_popArg_noRmoveArg(queue));
|
||||
}
|
||||
|
||||
ByteQueue* byteQueue_init(ByteQueue* queue,
|
||||
void* buffer,
|
||||
uint_fast16_t size,
|
||||
PIKA_BOOL is_queue_full) {
|
||||
pika_assert(NULL != queue);
|
||||
pika_assert(NULL != buffer);
|
||||
pika_assert(size > 0);
|
||||
|
||||
pika_platform_memset(queue, 0, sizeof(ByteQueue));
|
||||
|
||||
queue->buffer = buffer;
|
||||
queue->buffer_size = size;
|
||||
if (is_queue_full) {
|
||||
queue->count = size;
|
||||
queue->peek_count = size;
|
||||
}
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
PIKA_BOOL byteQueue_readOne(ByteQueue* queue, uint8_t* byte_ptr) {
|
||||
pika_assert(NULL != queue);
|
||||
uint8_t byte;
|
||||
PIKA_BOOL result = PIKA_FALSE;
|
||||
|
||||
/* ------------------atomicity sensitive start---------------- */
|
||||
do {
|
||||
if ((queue->head == queue->tail) && (0 == queue->count)) {
|
||||
/* empty */
|
||||
break;
|
||||
}
|
||||
|
||||
byte = queue->buffer[queue->head++];
|
||||
queue->count--;
|
||||
if (queue->head >= queue->buffer_size) {
|
||||
queue->head = 0;
|
||||
}
|
||||
|
||||
/* reset peek */
|
||||
queue->peek_count = queue->count;
|
||||
queue->peek = queue->head;
|
||||
|
||||
if (NULL != byte_ptr) {
|
||||
*byte_ptr = byte;
|
||||
}
|
||||
result = PIKA_TRUE;
|
||||
} while (0);
|
||||
/* ------------------atomicity sensitive end ---------------- */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PIKA_BOOL byteQueue_peekOne(ByteQueue* queue, uint8_t* byte_ptr) {
|
||||
pika_assert(NULL != queue);
|
||||
uint8_t byte;
|
||||
PIKA_BOOL result = PIKA_FALSE;
|
||||
|
||||
/* ------------------atomicity sensitive start---------------- */
|
||||
do {
|
||||
if ((queue->peek == queue->tail) && (0 == queue->peek_count)) {
|
||||
/* empty */
|
||||
break;
|
||||
}
|
||||
|
||||
byte = queue->buffer[queue->peek++];
|
||||
queue->peek_count--;
|
||||
if (queue->peek >= queue->buffer_size) {
|
||||
queue->peek = 0;
|
||||
}
|
||||
|
||||
if (NULL != byte_ptr) {
|
||||
*byte_ptr = byte;
|
||||
}
|
||||
result = PIKA_TRUE;
|
||||
} while (0);
|
||||
/* ------------------atomicity sensitive end ---------------- */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void byteQueue_resetPeek(ByteQueue* queue) {
|
||||
pika_assert(NULL != queue);
|
||||
/* ------------------atomicity sensitive start---------------- */
|
||||
queue->peek_count = queue->count;
|
||||
queue->peek = queue->head;
|
||||
/* ------------------atomicity sensitive end ---------------- */
|
||||
}
|
||||
|
||||
uint_fast16_t byteQueue_getPeekedNumber(ByteQueue* queue) {
|
||||
return queue->count - queue->peek_count;
|
||||
}
|
||||
|
||||
uint_fast16_t byteQueue_peekAvailableCount(ByteQueue* queue) {
|
||||
return queue->peek_count;
|
||||
}
|
||||
|
||||
void byteQueue_dropAllPeeked(ByteQueue* queue) {
|
||||
pika_assert(NULL != queue);
|
||||
/* ------------------atomicity sensitive start---------------- */
|
||||
queue->count = queue->peek_count;
|
||||
queue->head = queue->peek;
|
||||
/* ------------------atomicity sensitive end ---------------- */
|
||||
}
|
||||
|
||||
PIKA_BOOL byteQueue_writeOne(ByteQueue* queue, uint8_t byte) {
|
||||
pika_assert(NULL != queue);
|
||||
PIKA_BOOL result = PIKA_FALSE;
|
||||
|
||||
/* ------------------atomicity sensitive start---------------- */
|
||||
do {
|
||||
if ((queue->head == queue->tail) && (0 != queue->count)) {
|
||||
/* full */
|
||||
break;
|
||||
}
|
||||
|
||||
queue->buffer[queue->tail++] = byte;
|
||||
queue->count++;
|
||||
queue->peek_count++;
|
||||
if (queue->tail >= queue->buffer_size) {
|
||||
queue->tail = 0;
|
||||
}
|
||||
|
||||
result = PIKA_TRUE;
|
||||
} while (0);
|
||||
/* ------------------atomicity sensitive end ---------------- */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2023 Gorgon Meducer embedded_zhuroan@hotmail.comByte
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -29,6 +30,29 @@
|
|||
#define __DATA_QUEUE__H
|
||||
#include "dataArgs.h"
|
||||
|
||||
/*! \NOTE: Make sure #include "__pika_ooc.h" is close to the class definition
|
||||
*/
|
||||
#if defined(__DATA_QUEUE_CLASS_IMPLEMENT__)
|
||||
#define __PLOOC_CLASS_IMPLEMENT__
|
||||
#undef __DATA_QUEUE_CLASS_IMPLEMENT__
|
||||
#endif
|
||||
#include "__pika_ooc.h"
|
||||
|
||||
typedef struct ByteQueue ByteQueue;
|
||||
struct ByteQueue {
|
||||
private_member(
|
||||
uint8_t *buffer;
|
||||
uint16_t buffer_size;
|
||||
|
||||
uint16_t head;
|
||||
uint16_t tail;
|
||||
uint16_t peek;
|
||||
|
||||
uint16_t count;
|
||||
uint16_t peek_count;
|
||||
)
|
||||
};
|
||||
|
||||
typedef Args Queue;
|
||||
Queue* New_queue(void);
|
||||
|
||||
|
@ -46,4 +70,17 @@ Arg* queue_popArg(Queue* queue);
|
|||
Arg* queue_popArg_notDeinitArg(Queue* queue);
|
||||
int32_t queue_deinit_stack(Queue* queue);
|
||||
void queue_init(Queue* queue);
|
||||
|
||||
ByteQueue *byteQueue_init( ByteQueue *queue,
|
||||
void *buffer,
|
||||
uint_fast16_t size,
|
||||
PIKA_BOOL is_queue_full);
|
||||
PIKA_BOOL byteQueue_readOne(ByteQueue *queue, uint8_t *byte_ptr);
|
||||
PIKA_BOOL byteQueue_peekOne(ByteQueue *queue, uint8_t *byte_ptr);
|
||||
void byteQueue_resetPeek(ByteQueue *queue);
|
||||
void byteQueue_dropAllPeeked(ByteQueue *queue);
|
||||
uint_fast16_t byteQueue_getPeekedNumber(ByteQueue *queue);
|
||||
uint_fast16_t byteQueue_peekAvailableCount(ByteQueue *queue);
|
||||
PIKA_BOOL byteQueue_writeOne(ByteQueue *queue, uint8_t byte);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "dataString.h"
|
||||
#include "PikaPlatform.h"
|
||||
#include "dataMemory.h"
|
||||
|
||||
char* strCut(char* strOut, char* strIn, char startSign, char endSign) {
|
||||
int32_t Size = strGetSize(strIn);
|
||||
|
@ -280,3 +281,97 @@ char* strGetLastLine(char* strOut, char* strIn) {
|
|||
strOut[size - beginIndex + 1] = 0;
|
||||
return strOut;
|
||||
}
|
||||
|
||||
int strPathFormat(char* input, char* output) {
|
||||
int len = strlen(input);
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (input[i] == '\\') {
|
||||
output[j++] = '/';
|
||||
} else {
|
||||
output[j++] = input[i];
|
||||
}
|
||||
}
|
||||
output[j] = '\0';
|
||||
return j;
|
||||
}
|
||||
|
||||
int strPathJoin(char* input1, char* input2, char* output) {
|
||||
/* format */
|
||||
size_t input1_len = strlen(input1);
|
||||
size_t input2_len = strlen(input2);
|
||||
/* if input1 is all space */
|
||||
if (input1_len == 0) {
|
||||
strPathFormat(input2, output);
|
||||
return 0;
|
||||
}
|
||||
char* input1_format = (char*)pikaMalloc(input1_len + 1);
|
||||
char* input2_format = (char*)pikaMalloc(input2_len + 1);
|
||||
strPathFormat(input1, input1_format);
|
||||
strPathFormat(input2, input2_format);
|
||||
/* join */
|
||||
int len1 = strlen(input1_format);
|
||||
int len2 = strlen(input2_format);
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (i = 0; i < len1; i++) {
|
||||
output[j++] = input1_format[i];
|
||||
}
|
||||
if (input1_format[len1 - 1] != '/') {
|
||||
output[j++] = '/';
|
||||
}
|
||||
if (input2_format[0] == '/') {
|
||||
i = 1;
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
for (; i < len2; i++) {
|
||||
output[j++] = input2_format[i];
|
||||
}
|
||||
output[j] = '\0';
|
||||
/* free */
|
||||
pikaFree(input1_format, input1_len + 1);
|
||||
pikaFree(input2_format, input2_len + 1);
|
||||
return j;
|
||||
}
|
||||
|
||||
int strPathGetFolder(char* input, char* output) {
|
||||
size_t input_len = strlen(input);
|
||||
char* input_format = (char*)pikaMalloc(input_len + 1);
|
||||
strPathFormat(input, input_format);
|
||||
int len = strlen(input_format);
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (input_format[i] == '/') {
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < j; i++) {
|
||||
output[i] = input_format[i];
|
||||
}
|
||||
output[i] = '\0';
|
||||
pikaFree(input_format, input_len + 1);
|
||||
return i;
|
||||
}
|
||||
|
||||
int strPathGetFileName(char* input, char* output) {
|
||||
size_t input_len = strlen(input);
|
||||
char* input_format = (char*)pikaMalloc(input_len + 1);
|
||||
strPathFormat(input, input_format);
|
||||
int len = strlen(input_format);
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (input_format[i] == '/') {
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
for (i = j + 1; i < len; i++) {
|
||||
output[i - j - 1] = input_format[i];
|
||||
}
|
||||
output[i - j - 1] = '\0';
|
||||
pikaFree(input_format, input_len + 1);
|
||||
return i - j - 1;
|
||||
}
|
||||
|
|
|
@ -63,4 +63,9 @@ char* strPopLastToken(char* strIn, char sign);
|
|||
char* strGetLastLine(char* strOut, char* strIn);
|
||||
char* strReplaceChar(char* strIn, char src, char dst);
|
||||
|
||||
int strPathFormat(char* input, char* output);
|
||||
int strPathJoin(char* input1, char* input2, char* output);
|
||||
int strPathGetFolder(char* input, char* output);
|
||||
int strPathGetFileName(char* input, char* output);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -200,3 +200,31 @@ char* strsGetLine(Args* buffs_p, char* code) {
|
|||
void strsDeinit(Args* buffs_p) {
|
||||
link_deinit_stack(buffs_p);
|
||||
}
|
||||
|
||||
char* strsPathFormat(Args* buffs_p, char* input) {
|
||||
int32_t size = strGetSize(input);
|
||||
char* buff = args_getBuff(buffs_p, size);
|
||||
strPathFormat(input, buff);
|
||||
return buff;
|
||||
}
|
||||
|
||||
char* strsPathJoin(Args* buffs_p, char* input1, char* input2) {
|
||||
int32_t size = strGetSize(input1) + strGetSize(input2) + 1;
|
||||
char* buff = args_getBuff(buffs_p, size);
|
||||
strPathJoin(input1, input2, buff);
|
||||
return buff;
|
||||
}
|
||||
|
||||
char* strsPathGetFolder(Args* buffs_p, char* input) {
|
||||
int32_t size = strGetSize(input);
|
||||
char* buff = args_getBuff(buffs_p, size);
|
||||
strPathGetFolder(input, buff);
|
||||
return buff;
|
||||
}
|
||||
|
||||
char* strsPathGetFileName(Args* buffs_p, char* input) {
|
||||
int32_t size = strGetSize(input);
|
||||
char* buff = args_getBuff(buffs_p, size);
|
||||
strPathGetFileName(input, buff);
|
||||
return buff;
|
||||
}
|
||||
|
|
|
@ -45,4 +45,10 @@ char* strsGetLine(Args* buffs, char* code);
|
|||
void strsDeinit(Args* buffs);
|
||||
char* strsCacheArg(Args* buffs_p, Arg* arg);
|
||||
char* strsReturnOut(Args* buffs, Args* outbuffs, char* str);
|
||||
|
||||
char* strsPathGetFileName(Args* buffs_p, char* input);
|
||||
char* strsPathGetFolder(Args* buffs_p, char* input);
|
||||
char* strsPathJoin(Args* buffs_p, char* input1, char* input2);
|
||||
char* strsPathFormat(Args* buffs_p, char* input);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
#define __platform_error_handle pika_platform_error_handle
|
||||
#define __platform_panic_handle pika_platform_panic_handle
|
||||
#define __platform_thread_delay pika_platform_thread_delay
|
||||
#define __platform_getTick pika_platform_getTick
|
||||
#define __platform_getTick pika_platform_get_tick
|
||||
#define pika_platform_getTick pika_platform_get_tick
|
||||
#define __platform_sleep_ms pika_platform_sleep_ms
|
||||
#define __platform_sleep_s pika_platform_sleep_s
|
||||
|
||||
|
@ -72,6 +73,13 @@
|
|||
#define pks_eventLisener_deinit pks_eventListener_deinit
|
||||
#define pks_eventLicener_removeEvent pks_eventListener_removeEvent
|
||||
|
||||
#define pika_platform_timer_init pika_platform_thread_timer_init
|
||||
#define pika_platform_timer_cutdown pika_platform_thread_timer_cutdown
|
||||
#define pika_platform_timer_is_expired pika_platform_thread_timer_is_expired
|
||||
#define pika_platform_timer_remain pika_platform_thread_timer_remain
|
||||
#define pika_platform_timer_now pika_platform_thread_timer_now
|
||||
#define pika_platform_timer_usleep pika_platform_thread_timer_usleep
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -65,11 +65,14 @@
|
|||
#define PIKA_SYNTAX_LEVEL PIKA_SYNTAX_LEVEL_MINIMAL
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef PIKA_STRING_UTF8_ENABLE
|
||||
#define PIKA_STRING_UTF8_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_FILTER_ENABLE
|
||||
#define PIKA_SHELL_FILTER_ENABLE 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* default optimize */
|
||||
|
@ -328,8 +331,32 @@
|
|||
#define PIKA_SHELL_SAVE_FILE_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_SAVE_FILE_NAME
|
||||
#define PIKA_SHELL_SAVE_FILE_NAME "pika_shell_save.py"
|
||||
#ifndef PIKA_SHELL_SAVE_FILE_PATH
|
||||
#define PIKA_SHELL_SAVE_FILE_PATH "app.py"
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_SAVE_BYTECODE_ENABLE
|
||||
#define PIKA_SHELL_SAVE_BYTECODE_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_SAVE_BYTECODE_PATH
|
||||
#define PIKA_SHELL_SAVE_BYTECODE_PATH "app.py.o"
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_SAVE_APP_ENABLE
|
||||
#define PIKA_SHELL_SAVE_APP_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_SAVE_APP_PATH
|
||||
#define PIKA_SHELL_SAVE_APP_PATH "app.pika"
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_FILTER_ENABLE
|
||||
#define PIKA_SHELL_FILTER_ENABLE 1
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_FILTER_FIFO_SIZE
|
||||
#define PIKA_SHELL_FILTER_FIFO_SIZE 32
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_EVENT_LIST_SIZE
|
||||
|
@ -352,6 +379,30 @@
|
|||
#define PIKA_LWIP_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SHELL_NO_NEWLINE
|
||||
#define PIKA_SHELL_NO_NEWLINE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_SETJMP_ENABLE
|
||||
#define PIKA_SETJMP_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_JMP_BUF_LIST_SIZE
|
||||
#define PIKA_JMP_BUF_LIST_SIZE 16
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_THREAD_STACK_SIZE
|
||||
#define PIKA_THREAD_STACK_SIZE 2048
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_THREAD_PRIO
|
||||
#define PIKA_THREAD_PRIO 5
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_THREAD_TICK
|
||||
#define PIKA_THREAD_TICK 50
|
||||
#endif
|
||||
|
||||
/* configuration validation */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
#include "../PikaStdDevice/pika_hal.h"
|
||||
#include "bflb_adc.h"
|
||||
|
||||
static int8_t _pin2ch(uint32_t pin) {
|
||||
switch (pin) {
|
||||
case 0:
|
||||
return ADC_CHANNEL_9;
|
||||
case 1:
|
||||
return ADC_CHANNEL_8;
|
||||
case 2:
|
||||
return ADC_CHANNEL_2;
|
||||
case 3:
|
||||
return ADC_CHANNEL_3;
|
||||
case 10:
|
||||
return ADC_CHANNEL_7;
|
||||
case 12:
|
||||
return ADC_CHANNEL_6;
|
||||
case 13:
|
||||
return ADC_CHANNEL_5;
|
||||
case 14:
|
||||
return ADC_CHANNEL_4;
|
||||
case 19:
|
||||
return ADC_CHANNEL_1;
|
||||
case 20:
|
||||
return ADC_CHANNEL_0;
|
||||
case 27:
|
||||
return ADC_CHANNEL_10;
|
||||
case 28:
|
||||
return ADC_CHANNEL_11;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct platform_adc_t {
|
||||
struct bflb_device_s* device;
|
||||
struct bflb_adc_config_s config;
|
||||
struct bflb_adc_channel_s channel;
|
||||
} platform_adc_t;
|
||||
|
||||
int pika_hal_platform_ADC_open(pika_dev* dev, char* name) {
|
||||
/* Support P1/P2 ... */
|
||||
if (name[0] == 'P') {
|
||||
int8_t ch = _pin2ch(fast_atoi(name + 1));
|
||||
if (ch < 0) {
|
||||
pika_platform_printf("ADC channel not support: %s \r\n", name);
|
||||
return -1;
|
||||
}
|
||||
platform_adc_t* platform_adc =
|
||||
(platform_adc_t*)pikaMalloc(sizeof(platform_adc_t));
|
||||
memset(platform_adc, 0, sizeof(platform_adc_t));
|
||||
dev->platform_data = platform_adc;
|
||||
platform_adc->channel.pos_chan = ch;
|
||||
platform_adc->channel.neg_chan = ADC_CHANNEL_GND;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_close(pika_dev* dev) {
|
||||
platform_adc_t* platform_adc = (platform_adc_t*)dev->platform_data;
|
||||
if (NULL != platform_adc) {
|
||||
pikaFree(platform_adc, sizeof(platform_adc_t));
|
||||
dev->platform_data = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_ioctl_config(pika_dev* dev,
|
||||
pika_hal_ADC_config* cfg) {
|
||||
platform_adc_t* platform_adc = (platform_adc_t*)dev->platform_data;
|
||||
platform_adc->config.clk_div = ADC_CLK_DIV_32;
|
||||
platform_adc->config.scan_conv_mode = true;
|
||||
platform_adc->config.vref = ADC_VREF_3P2V;
|
||||
switch (cfg->continue_or_single) {
|
||||
case PIKA_HAL_ADC_CONTINUOU:
|
||||
platform_adc->config.continuous_conv_mode = true;
|
||||
break;
|
||||
case PIKA_HAL_ADC_SINGLE:
|
||||
platform_adc->config.continuous_conv_mode = false;
|
||||
break;
|
||||
default:
|
||||
platform_adc->config.continuous_conv_mode = false;
|
||||
break;
|
||||
}
|
||||
switch (cfg->sampling_resolution) {
|
||||
case PIKA_HAL_ADC_RESOLUTION_12:
|
||||
platform_adc->config.resolution = ADC_RESOLUTION_12B;
|
||||
break;
|
||||
case PIKA_HAL_ADC_RESOLUTION_14:
|
||||
platform_adc->config.resolution = ADC_RESOLUTION_14B;
|
||||
break;
|
||||
case PIKA_HAL_ADC_RESOLUTION_16:
|
||||
platform_adc->config.resolution = ADC_RESOLUTION_16B;
|
||||
break;
|
||||
default:
|
||||
platform_adc->config.resolution = ADC_RESOLUTION_16B;
|
||||
break;
|
||||
}
|
||||
cfg->max = 3200;
|
||||
cfg->vref = (pika_float)3.3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
int ret = 0;
|
||||
platform_adc_t* platform_adc = (platform_adc_t*)dev->platform_data;
|
||||
bflb_adc_start_conversion(platform_adc->device);
|
||||
while (bflb_adc_get_count(platform_adc->device) < 1) {
|
||||
bflb_mtimer_delay_ms(1);
|
||||
}
|
||||
uint32_t raw_data = bflb_adc_read_raw(platform_adc->device);
|
||||
bflb_adc_stop_conversion(platform_adc->device);
|
||||
struct bflb_adc_result_s result;
|
||||
bflb_adc_parse_result(platform_adc->device, &raw_data, &result, 1);
|
||||
ret = result.millivolt;
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
*(uint32_t*)buf = ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_write(pika_dev* dev, void* buf, size_t count) {
|
||||
/* Not support */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_ioctl_enable(pika_dev* dev) {
|
||||
platform_adc_t* platform_adc = (platform_adc_t*)dev->platform_data;
|
||||
if (!dev->is_enabled) {
|
||||
bflb_adc_init(platform_adc->device, &platform_adc->config);
|
||||
bflb_adc_channel_config(platform_adc->device, &platform_adc->channel,
|
||||
1);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_ADC_ioctl_disable(pika_dev* dev) {
|
||||
platform_adc_t* platform_adc = (platform_adc_t*)dev->platform_data;
|
||||
if (dev->is_enabled) {
|
||||
bflb_adc_deinit(platform_adc->device);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
#include "../PikaStdDevice/pika_hal.h"
|
||||
#include "bflb_dac.h"
|
||||
|
||||
static int8_t _pin2ch(uint32_t pin) {
|
||||
switch (pin) {
|
||||
case 3:
|
||||
return DAC_CHANNEL_A;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct platform_dac_t {
|
||||
struct bflb_device_s* device;
|
||||
uint8_t channel;
|
||||
uint8_t clk_div;
|
||||
} platform_dac_t;
|
||||
|
||||
int pika_hal_platform_DAC_open(pika_dev* dev, char* name) {
|
||||
/* Support P1/P2 ... */
|
||||
if (name[0] == 'P') {
|
||||
int pin = fast_atoi(name + 1);
|
||||
int8_t ch = _pin2ch(pin);
|
||||
if (ch < 0) {
|
||||
pika_platform_printf("DAC channel not support: %s \r\n", name);
|
||||
return -1;
|
||||
}
|
||||
platform_dac_t* platform_dac = pikaMalloc(sizeof(platform_dac_t));
|
||||
memset(platform_dac, 0, sizeof(platform_dac_t));
|
||||
dev->platform_data = platform_dac;
|
||||
platform_dac->device = bflb_device_get_by_name("dac");
|
||||
platform_dac->channel = ch;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_close(pika_dev* dev) {
|
||||
if (dev->platform_data) {
|
||||
pikaFree(dev->platform_data, sizeof(platform_dac_t));
|
||||
dev->platform_data = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_ioctl_config(pika_dev* dev,
|
||||
pika_hal_DAC_config* cfg) {
|
||||
platform_dac_t* platform_dac = (platform_dac_t*)dev->platform_data;
|
||||
platform_dac->clk_div = DAC_CLK_DIV_16;
|
||||
cfg->max = 3300000;
|
||||
cfg->vref = (pika_float)3.3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_ioctl_enable(pika_dev* dev) {
|
||||
platform_dac_t* platform_dac = (platform_dac_t*)dev->platform_data;
|
||||
if (!dev->is_enabled) {
|
||||
bflb_dac_init(platform_dac->device, platform_dac->clk_div);
|
||||
bflb_dac_channel_enable(platform_dac->device, platform_dac->channel);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_write(pika_dev* dev, void* buf, size_t count) {
|
||||
platform_dac_t* platform_dac = (platform_dac_t*)dev->platform_data;
|
||||
uint32_t value = *(uint32_t*)buf;
|
||||
bflb_dac_set_value(platform_dac->device, platform_dac->channel, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_DAC_ioctl_disable(pika_dev* dev) {
|
||||
platform_dac_t* platform_dac = (platform_dac_t*)dev->platform_data;
|
||||
bflb_dac_channel_disable(platform_dac->device, platform_dac->channel);
|
||||
return 0;
|
||||
}
|
124
examples/pikapython/pikapython/pikascript-lib/BLMCU/pika_hal_BLMCU_GPIO.c
Executable file
124
examples/pikapython/pikapython/pikascript-lib/BLMCU/pika_hal_BLMCU_GPIO.c
Executable file
|
@ -0,0 +1,124 @@
|
|||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "bflb_gpio.h"
|
||||
|
||||
typedef struct platform_gpio_t {
|
||||
struct bflb_device_s* device;
|
||||
uint8_t pin;
|
||||
uint32_t config;
|
||||
} platform_gpio_t;
|
||||
|
||||
int pika_hal_platform_GPIO_open(pika_dev* dev, char* name) {
|
||||
dev->platform_data = pikaMalloc(sizeof(platform_gpio_t));
|
||||
memset(dev->platform_data, 0, sizeof(platform_gpio_t));
|
||||
platform_gpio_t* gpio = (platform_gpio_t*)dev->platform_data;
|
||||
/* Support P1/P2 ... */
|
||||
gpio->device = bflb_device_get_by_name("gpio");
|
||||
gpio->pin = fast_atoi(name + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_close(pika_dev* dev) {
|
||||
pikaFree(dev->platform_data, sizeof(platform_gpio_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_read(pika_dev* dev, void* buf, size_t count) {
|
||||
platform_gpio_t* gpio = (platform_gpio_t*)dev->platform_data;
|
||||
bool val = bflb_gpio_read(gpio->device, gpio->pin);
|
||||
*(uint32_t*)buf = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_write(pika_dev* dev, void* buf, size_t count) {
|
||||
platform_gpio_t* gpio = (platform_gpio_t*)dev->platform_data;
|
||||
bool val = *(uint32_t*)buf;
|
||||
if (val) {
|
||||
bflb_gpio_set(gpio->device, gpio->pin);
|
||||
} else {
|
||||
bflb_gpio_reset(gpio->device, gpio->pin);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_enable(pika_dev* dev) {
|
||||
platform_gpio_t* gpio = (platform_gpio_t*)dev->platform_data;
|
||||
bflb_gpio_init(gpio->device, gpio->pin, gpio->config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_disable(pika_dev* dev) {
|
||||
platform_gpio_t* gpio = (platform_gpio_t*)dev->platform_data;
|
||||
bflb_gpio_deinit(gpio->device, gpio->pin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _gpio_irq_hanlder(int irq, void* arg) {
|
||||
static int i = 0;
|
||||
// get the device
|
||||
pika_dev* dev = (pika_dev*)arg;
|
||||
// get the gpio
|
||||
platform_gpio_t* gpio = (platform_gpio_t*)dev->platform_data;
|
||||
// get the config
|
||||
pika_hal_GPIO_config* cfg = (pika_hal_GPIO_config*)dev->ioctl_config;
|
||||
// get the int status
|
||||
bool intstatus = bflb_gpio_get_intstatus(gpio->device, gpio->pin);
|
||||
if (intstatus) {
|
||||
// call the callback
|
||||
cfg->event_callback(dev, cfg->event_callback_filter);
|
||||
// clear the int status
|
||||
bflb_gpio_int_clear(gpio->device, gpio->pin);
|
||||
}
|
||||
}
|
||||
|
||||
int pika_hal_platform_GPIO_ioctl_config(pika_dev* dev,
|
||||
pika_hal_GPIO_config* cfg) {
|
||||
platform_gpio_t* gpio = (platform_gpio_t*)dev->platform_data;
|
||||
switch (cfg->dir) {
|
||||
case PIKA_HAL_GPIO_DIR_IN:
|
||||
gpio->config |= GPIO_INPUT;
|
||||
break;
|
||||
case PIKA_HAL_GPIO_DIR_OUT:
|
||||
gpio->config |= GPIO_OUTPUT;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
switch (cfg->pull) {
|
||||
case PIKA_HAL_GPIO_PULL_NONE:
|
||||
gpio->config |= GPIO_FLOAT;
|
||||
break;
|
||||
case PIKA_HAL_GPIO_PULL_UP:
|
||||
gpio->config |= GPIO_PULLUP;
|
||||
break;
|
||||
case PIKA_HAL_GPIO_PULL_DOWN:
|
||||
gpio->config |= GPIO_PULLDOWN;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* support event callback */
|
||||
if (NULL != cfg->event_callback &&
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE == cfg->event_callback_ena) {
|
||||
switch (cfg->event_callback_filter) {
|
||||
case PIKA_HAL_GPIO_EVENT_SIGNAL_RISING:
|
||||
gpio->config |= GPIO_INT_TRIG_MODE_SYNC_RISING_EDGE;
|
||||
break;
|
||||
case PIKA_HAL_GPIO_EVENT_SIGNAL_FALLING:
|
||||
gpio->config |= GPIO_INT_TRIG_MODE_SYNC_FALLING_EDGE;
|
||||
break;
|
||||
|
||||
default:
|
||||
__platform_printf(
|
||||
"Error: not supported event callback filter %d\r\n",
|
||||
cfg->event_callback_filter);
|
||||
return -1;
|
||||
}
|
||||
/* register the irq */
|
||||
bflb_gpio_int_mask(gpio->device, gpio->pin, false);
|
||||
bflb_irq_attach(gpio->device->irq_num, _gpio_irq_hanlder, dev);
|
||||
bflb_irq_enable(gpio->device->irq_num);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
153
examples/pikapython/pikapython/pikascript-lib/BLMCU/pika_hal_BLMCU_UART.c
Executable file
153
examples/pikapython/pikapython/pikascript-lib/BLMCU/pika_hal_BLMCU_UART.c
Executable file
|
@ -0,0 +1,153 @@
|
|||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "bflb_uart.h"
|
||||
|
||||
typedef struct platform_uart_t {
|
||||
struct bflb_device_s* device;
|
||||
struct bflb_uart_config_s config;
|
||||
} platform_uart_t;
|
||||
|
||||
int pika_hal_platform_UART_open(pika_dev* dev, char* name) {
|
||||
if (name[0] == 'U' && name[1] == 'A' && name[2] == 'R' && name[3] == 'T') {
|
||||
int UART_num = fast_atoi(name + 4);
|
||||
platform_uart_t* uart = pikaMalloc(sizeof(platform_uart_t));
|
||||
uart->device = bflb_device_get_by_id(BFLB_DEVICE_TYPE_UART, UART_num);
|
||||
dev->platform_data = uart;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_UART_close(pika_dev* dev) {
|
||||
pikaFree(dev->platform_data, sizeof(platform_uart_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _uart_irq_handler(int irq, void* arg) {
|
||||
pika_dev* dev = (pika_dev*)arg;
|
||||
platform_uart_t* uart = (platform_uart_t*)dev->platform_data;
|
||||
pika_hal_UART_config* cfg = (pika_hal_UART_config*)dev->ioctl_config;
|
||||
uint32_t intstatus = bflb_uart_get_intstatus(uart->device);
|
||||
if (intstatus) {
|
||||
cfg->event_callback(dev, cfg->event_callback_filter);
|
||||
bflb_uart_int_clear(uart->device, intstatus);
|
||||
}
|
||||
}
|
||||
|
||||
int pika_hal_platform_UART_ioctl_config(pika_dev* dev,
|
||||
pika_hal_UART_config* cfg) {
|
||||
platform_uart_t* uart = (platform_uart_t*)dev->platform_data;
|
||||
uart->config.baudrate = cfg->baudrate;
|
||||
switch (cfg->data_bits) {
|
||||
case PIKA_HAL_UART_DATA_BITS_5:
|
||||
uart->config.data_bits = UART_DATA_BITS_5;
|
||||
break;
|
||||
case PIKA_HAL_UART_DATA_BITS_6:
|
||||
uart->config.data_bits = UART_DATA_BITS_6;
|
||||
break;
|
||||
case PIKA_HAL_UART_DATA_BITS_7:
|
||||
uart->config.data_bits = UART_DATA_BITS_7;
|
||||
break;
|
||||
case PIKA_HAL_UART_DATA_BITS_8:
|
||||
uart->config.data_bits = UART_DATA_BITS_8;
|
||||
break;
|
||||
default:
|
||||
uart->config.data_bits = UART_DATA_BITS_8;
|
||||
break;
|
||||
}
|
||||
switch (cfg->parity) {
|
||||
case PIKA_HAL_UART_PARITY_NONE:
|
||||
uart->config.parity = UART_PARITY_NONE;
|
||||
break;
|
||||
case PIKA_HAL_UART_PARITY_ODD:
|
||||
uart->config.parity = UART_PARITY_ODD;
|
||||
break;
|
||||
case PIKA_HAL_UART_PARITY_EVEN:
|
||||
uart->config.parity = UART_PARITY_EVEN;
|
||||
break;
|
||||
default:
|
||||
uart->config.parity = UART_PARITY_NONE;
|
||||
break;
|
||||
}
|
||||
switch (cfg->stop_bits) {
|
||||
case PIKA_HAL_UART_STOP_BITS_1:
|
||||
uart->config.stop_bits = UART_STOP_BITS_1;
|
||||
break;
|
||||
case PIKA_HAL_UART_STOP_BITS_2:
|
||||
uart->config.stop_bits = UART_STOP_BITS_2;
|
||||
break;
|
||||
case PIKA_HAL_UART_STOP_BITS_1_5:
|
||||
uart->config.stop_bits = UART_STOP_BITS_1_5;
|
||||
break;
|
||||
default:
|
||||
uart->config.stop_bits = UART_STOP_BITS_1;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (cfg->flow_control) {
|
||||
case PIKA_HAL_UART_FLOW_CONTROL_NONE:
|
||||
uart->config.flow_ctrl = UART_FLOWCTRL_NONE;
|
||||
break;
|
||||
case PIKA_HAL_UART_FLOW_CONTROL_CTS:
|
||||
uart->config.flow_ctrl = UART_FLOWCTRL_CTS;
|
||||
break;
|
||||
case PIKA_HAL_UART_FLOW_CONTROL_RTS:
|
||||
uart->config.flow_ctrl = UART_FLOWCTRL_RTS;
|
||||
break;
|
||||
case PIKA_HAL_UART_FLOW_CONTROL_RTS_CTS:
|
||||
uart->config.flow_ctrl = UART_FLOWCTRL_RTS_CTS;
|
||||
break;
|
||||
default:
|
||||
uart->config.flow_ctrl = UART_FLOWCTRL_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* support event callback */
|
||||
if (NULL != cfg->event_callback &&
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE == cfg->event_callback_ena) {
|
||||
switch (cfg->event_callback_filter) {
|
||||
/* Configure UART to interrupt mode */
|
||||
case PIKA_HAL_UART_EVENT_SIGNAL_RX:
|
||||
bflb_uart_rxint_mask(uart->device, false);
|
||||
break;
|
||||
case PIKA_HAL_UART_EVENT_SIGNAL_TX:
|
||||
bflb_uart_txint_mask(uart->device, false);
|
||||
break;
|
||||
default:
|
||||
__platform_printf(
|
||||
"Error: not supported event callback filter %d\r\n",
|
||||
cfg->event_callback_filter);
|
||||
return -1;
|
||||
}
|
||||
bflb_irq_attach(uart->device->irq_num, _uart_irq_handler, dev);
|
||||
bflb_irq_enable(uart->device->irq_num);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_platform_UART_ioctl_enable(pika_dev* dev) {
|
||||
if (!dev->is_enabled) {
|
||||
platform_uart_t* uart = (platform_uart_t*)dev->platform_data;
|
||||
bflb_uart_init(uart->device, &uart->config);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_UART_ioctl_disable(pika_dev* dev) {
|
||||
if (dev->is_enabled) {
|
||||
platform_uart_t* uart = (platform_uart_t*)dev->platform_data;
|
||||
bflb_uart_deinit(uart->device);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pika_hal_platform_UART_write(pika_dev* dev, void* buf, size_t count) {
|
||||
platform_uart_t* uart = (platform_uart_t*)dev->platform_data;
|
||||
return bflb_uart_put(uart->device, buf, count);
|
||||
}
|
||||
|
||||
int pika_hal_platform_UART_read(pika_dev* dev, void* buf, size_t count) {
|
||||
platform_uart_t* uart = (platform_uart_t*)dev->platform_data;
|
||||
return bflb_uart_get(uart->device, buf, count);
|
||||
}
|
108
examples/pikapython/pikapython/pikascript-lib/PikaMath/PikaMath_Math.c
Executable file
108
examples/pikapython/pikapython/pikascript-lib/PikaMath/PikaMath_Math.c
Executable file
|
@ -0,0 +1,108 @@
|
|||
#include "PikaMath_Math.h"
|
||||
#include <math.h>
|
||||
|
||||
#define PI (3.141592653589793115997963468544185161590576171875l)
|
||||
#define E (2.718281828459045090795598298427648842334747314453125l)
|
||||
//初始化,填入π和e的值
|
||||
void PikaMath_Math___init__(PikaObj *self)
|
||||
{
|
||||
obj_setFloat(self, "pi", PI);
|
||||
obj_setFloat(self, "e", PI);
|
||||
}
|
||||
|
||||
pika_float PikaMath_Math_acos(PikaObj *self, pika_float x)
|
||||
{
|
||||
return acos(x);
|
||||
}
|
||||
pika_float PikaMath_Math_asin(PikaObj *self, pika_float x)
|
||||
{
|
||||
return asin(x);
|
||||
}
|
||||
pika_float PikaMath_Math_atan(PikaObj *self, pika_float x)
|
||||
{
|
||||
return atan(x);
|
||||
}
|
||||
pika_float PikaMath_Math_atan2(PikaObj *self, pika_float x, pika_float y)
|
||||
{
|
||||
return atan2(x,y);
|
||||
}
|
||||
int PikaMath_Math_ceil(PikaObj *self, pika_float x)
|
||||
{
|
||||
return ceil(x);
|
||||
}
|
||||
pika_float PikaMath_Math_cos(PikaObj *self, pika_float x)
|
||||
{
|
||||
return cos(x);
|
||||
}
|
||||
pika_float PikaMath_Math_cosh(PikaObj *self, pika_float x)
|
||||
{
|
||||
return cosh(x);
|
||||
}
|
||||
pika_float PikaMath_Math_degrees(PikaObj *self, pika_float x)
|
||||
{
|
||||
return x*180.0/PI;
|
||||
}
|
||||
pika_float PikaMath_Math_exp(PikaObj *self, pika_float x)
|
||||
{
|
||||
return exp(x);
|
||||
}
|
||||
pika_float PikaMath_Math_fabs(PikaObj *self, pika_float x)
|
||||
{
|
||||
return fabs(x);
|
||||
}
|
||||
int PikaMath_Math_floor(PikaObj *self, pika_float x)
|
||||
{
|
||||
return floor(x);
|
||||
}
|
||||
pika_float PikaMath_Math_fmod(PikaObj *self, pika_float x, pika_float y)
|
||||
{
|
||||
return fmod(x,y);
|
||||
}
|
||||
pika_float PikaMath_Math_log(PikaObj *self, pika_float x)
|
||||
{
|
||||
return log(x);
|
||||
}
|
||||
pika_float PikaMath_Math_log10(PikaObj *self, pika_float x)
|
||||
{
|
||||
return log10(x);
|
||||
}
|
||||
pika_float PikaMath_Math_log2(PikaObj *self, pika_float x)
|
||||
{
|
||||
return log2(x);
|
||||
}
|
||||
pika_float PikaMath_Math_pow(PikaObj *self, pika_float x, pika_float y)
|
||||
{
|
||||
return pow(x,y);
|
||||
}
|
||||
pika_float PikaMath_Math_radians(PikaObj *self, pika_float x)
|
||||
{
|
||||
return x*PI/180.0;
|
||||
}
|
||||
pika_float PikaMath_Math_remainder(PikaObj *self, pika_float x, pika_float y)
|
||||
{
|
||||
return remainder(x,y);
|
||||
}
|
||||
pika_float PikaMath_Math_sin(PikaObj *self, pika_float x)
|
||||
{
|
||||
return sin(x);
|
||||
}
|
||||
pika_float PikaMath_Math_sinh(PikaObj *self, pika_float x)
|
||||
{
|
||||
return sinh(x);
|
||||
}
|
||||
pika_float PikaMath_Math_sqrt(PikaObj *self, pika_float x)
|
||||
{
|
||||
return sqrt(x);
|
||||
}
|
||||
pika_float PikaMath_Math_tan(PikaObj *self, pika_float x)
|
||||
{
|
||||
return tan(x);
|
||||
}
|
||||
pika_float PikaMath_Math_tanh(PikaObj *self, pika_float x)
|
||||
{
|
||||
return tanh(x);
|
||||
}
|
||||
pika_float PikaMath_Math_trunc(PikaObj *self, pika_float x)
|
||||
{
|
||||
return trunc(x);
|
||||
}
|
54
examples/pikapython/pikapython/pikascript-lib/PikaMath/PikaMath_Operator.c
Executable file
54
examples/pikapython/pikapython/pikascript-lib/PikaMath/PikaMath_Operator.c
Executable file
|
@ -0,0 +1,54 @@
|
|||
#include "PikaMath_Operator.h"
|
||||
|
||||
int PikaMath_Operator_AND(PikaObj* self, int flag1, int flag2) {
|
||||
return flag1 && flag2;
|
||||
}
|
||||
int PikaMath_Operator_NOT(PikaObj* self, int flag) {
|
||||
return !flag;
|
||||
}
|
||||
int PikaMath_Operator_OR(PikaObj* self, int flag1, int flag2) {
|
||||
return flag1 || flag2;
|
||||
}
|
||||
int PikaMath_Operator_equalFloat(PikaObj* self, pika_float num1, pika_float num2) {
|
||||
return num1 == num2;
|
||||
}
|
||||
int PikaMath_Operator_equalInt(PikaObj* self, int num1, int num2) {
|
||||
return num1 == num2;
|
||||
}
|
||||
int PikaMath_Operator_graterThanFloat(PikaObj* self, pika_float num1, pika_float num2) {
|
||||
return num1 > num2;
|
||||
}
|
||||
int PikaMath_Operator_graterThanInt(PikaObj* self, int num1, int num2) {
|
||||
return num1 > num2;
|
||||
}
|
||||
int PikaMath_Operator_lessThanFloat(PikaObj* self, pika_float num1, pika_float num2) {
|
||||
return num1 < num2;
|
||||
}
|
||||
int PikaMath_Operator_lessThanInt(PikaObj* self, int num1, int num2) {
|
||||
return num1 < num2;
|
||||
}
|
||||
pika_float PikaMath_Operator_minusFloat(PikaObj* self, pika_float num1, pika_float num2) {
|
||||
return num1 - num2;
|
||||
}
|
||||
int PikaMath_Operator_minusInt(PikaObj* self, int num1, int num2) {
|
||||
return num1 - num2;
|
||||
}
|
||||
|
||||
pika_float PikaMath_Operator_plusFloat(PikaObj* self, pika_float num1, pika_float num2) {
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
int PikaMath_Operator_plusInt(PikaObj* self, int num1, int num2) {
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
char* PikaMath_Operator___str__(PikaObj *self){
|
||||
obj_setStr(self, "__buf", "test");
|
||||
return obj_getStr(self, "__buf");
|
||||
}
|
||||
|
||||
void PikaMath_Operator___del__(PikaObj *self){
|
||||
__platform_printf("del operator...\r\n");
|
||||
}
|
||||
|
||||
|
274
examples/pikapython/pikapython/pikascript-lib/PikaMath/PikaMath_Quaternion.c
Executable file
274
examples/pikapython/pikapython/pikascript-lib/PikaMath/PikaMath_Quaternion.c
Executable file
|
@ -0,0 +1,274 @@
|
|||
#include "PikaMath_Quaternion.h"
|
||||
#include "PikaStdData_List.h"
|
||||
#include "math.h"
|
||||
|
||||
void PikaMath_Quaternion___init__(PikaObj* self) {
|
||||
obj_setFloat(self, "x", 0.0);
|
||||
obj_setFloat(self, "y", 0.0);
|
||||
obj_setFloat(self, "z", 0.0);
|
||||
obj_setFloat(self, "w", 1.0);
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_set(PikaObj* self,
|
||||
pika_float x,
|
||||
pika_float y,
|
||||
pika_float z,
|
||||
pika_float w) {
|
||||
obj_setFloat(self, "x", x);
|
||||
obj_setFloat(self, "y", y);
|
||||
obj_setFloat(self, "z", z);
|
||||
obj_setFloat(self, "w", w);
|
||||
}
|
||||
|
||||
pika_float PikaMath_Quaternion_get(PikaObj* self, int key) {
|
||||
if (key == 0) {
|
||||
return obj_getFloat(self, "x");
|
||||
}
|
||||
if (key == 1) {
|
||||
return obj_getFloat(self, "y");
|
||||
}
|
||||
if (key == 2) {
|
||||
return obj_getFloat(self, "z");
|
||||
}
|
||||
if (key == 3) {
|
||||
return obj_getFloat(self, "w");
|
||||
} else {
|
||||
obj_setErrorCode(self, 1);
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_add(PikaObj* self, PikaObj* quat) {
|
||||
float x_ = obj_getFloat(quat, "x");
|
||||
float y_ = obj_getFloat(quat, "y");
|
||||
float z_ = obj_getFloat(quat, "z");
|
||||
float w_ = obj_getFloat(quat, "w");
|
||||
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
float x_sum = x + x_;
|
||||
float y_sum = y + y_;
|
||||
float z_sum = z + z_;
|
||||
float w_sum = w + w_;
|
||||
|
||||
obj_setFloat(self, "x", x_sum);
|
||||
obj_setFloat(self, "y", y_sum);
|
||||
obj_setFloat(self, "z", z_sum);
|
||||
obj_setFloat(self, "w", w_sum);
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_sub(PikaObj* self, PikaObj* quat) {
|
||||
float x_ = obj_getFloat(quat, "x");
|
||||
float y_ = obj_getFloat(quat, "y");
|
||||
float z_ = obj_getFloat(quat, "z");
|
||||
float w_ = obj_getFloat(quat, "w");
|
||||
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
float x_sub = x - x_;
|
||||
float y_sub = y - y_;
|
||||
float z_sub = z - z_;
|
||||
float w_sub = w - w_;
|
||||
|
||||
obj_setFloat(self, "x", x_sub);
|
||||
obj_setFloat(self, "y", y_sub);
|
||||
obj_setFloat(self, "z", z_sub);
|
||||
obj_setFloat(self, "w", w_sub);
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_mul(PikaObj* self, PikaObj* quat) {
|
||||
float x_ = obj_getFloat(quat, "x");
|
||||
float y_ = obj_getFloat(quat, "y");
|
||||
float z_ = obj_getFloat(quat, "z");
|
||||
float w_ = obj_getFloat(quat, "w");
|
||||
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
float x_mul = w * x_ + x * w_ - y * z_ + z * y_;
|
||||
float y_mul = w * y_ + y * w_ + x * z_ - z * x_;
|
||||
float z_mul = w * z_ + z * w_ - x * y_ + y * x_;
|
||||
float w_mul = w * w_ - x * x_ - y * y_ - z * z_;
|
||||
|
||||
obj_setFloat(self, "x", x_mul);
|
||||
obj_setFloat(self, "y", y_mul);
|
||||
obj_setFloat(self, "z", z_mul);
|
||||
obj_setFloat(self, "w", w_mul);
|
||||
}
|
||||
pika_float PikaMath_Quaternion_magnituded(PikaObj* self) {
|
||||
float magnituded = PikaMath_Quaternion_magnitudedsquare(self);
|
||||
|
||||
return pow(magnituded, 0.5);
|
||||
}
|
||||
pika_float PikaMath_Quaternion_magnitudedsquare(PikaObj* self) {
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
float magnitudedsquare = pow(x, 2) + pow(y, 2) + pow(z, 2) + pow(w, 2);
|
||||
|
||||
return magnitudedsquare;
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_reverse(PikaObj* self) {
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
obj_setFloat(self, "x", -x);
|
||||
obj_setFloat(self, "y", -y);
|
||||
obj_setFloat(self, "z", -z);
|
||||
obj_setFloat(self, "w", w);
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_inverse(PikaObj* self) {
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
float mag = PikaMath_Quaternion_magnitudedsquare(self);
|
||||
if (mag > 0.0001) {
|
||||
obj_setFloat(self, "x", -x / mag);
|
||||
obj_setFloat(self, "y", -y / mag);
|
||||
obj_setFloat(self, "z", -z / mag);
|
||||
obj_setFloat(self, "w", w / mag);
|
||||
} else {
|
||||
obj_setFloat(self, "x", 0.0);
|
||||
obj_setFloat(self, "y", 0.0);
|
||||
obj_setFloat(self, "z", 0.0);
|
||||
obj_setFloat(self, "w", 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_crossproduct(PikaObj* self, PikaObj* quat) {
|
||||
float x_ = obj_getFloat(quat, "x");
|
||||
float y_ = obj_getFloat(quat, "y");
|
||||
float z_ = obj_getFloat(quat, "z");
|
||||
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
|
||||
float x_cross = y * z_ - z * y_;
|
||||
float y_cross = z * x_ - x * z_;
|
||||
float z_cross = x * y_ - y * x_;
|
||||
|
||||
obj_setFloat(self, "x", x_cross);
|
||||
obj_setFloat(self, "y", y_cross);
|
||||
obj_setFloat(self, "z", z_cross);
|
||||
obj_setFloat(self, "w", 0.0);
|
||||
}
|
||||
|
||||
pika_float PikaMath_Quaternion_dot(PikaObj* self, PikaObj* quat) {
|
||||
float x_ = obj_getFloat(quat, "x");
|
||||
float y_ = obj_getFloat(quat, "y");
|
||||
float z_ = obj_getFloat(quat, "z");
|
||||
float w_ = obj_getFloat(quat, "w");
|
||||
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
return (x_ * x + y_ * y + z_ * z + w_ * w);
|
||||
}
|
||||
|
||||
void PikaMath_Quaternion_normalize(PikaObj* self) {
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
float mag = PikaMath_Quaternion_magnituded(self);
|
||||
if (mag > 0.0001) {
|
||||
obj_setFloat(self, "x", x / mag);
|
||||
obj_setFloat(self, "y", y / mag);
|
||||
obj_setFloat(self, "z", z / mag);
|
||||
obj_setFloat(self, "w", w / mag);
|
||||
} else {
|
||||
obj_setFloat(self, "x", 0.0);
|
||||
obj_setFloat(self, "y", 0.0);
|
||||
obj_setFloat(self, "z", 0.0);
|
||||
obj_setFloat(self, "w", 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
int PikaMath_Quaternion_isnormalize(PikaObj* self) {
|
||||
float mag = PikaMath_Quaternion_magnituded(self);
|
||||
|
||||
if (1.0 == mag) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define PI_DIV_180 (0.017453292519943296)
|
||||
#define DegToRad(x) ((x)*PI_DIV_180)
|
||||
|
||||
void PikaMath_Quaternion_fromEuler(PikaObj* self,
|
||||
pika_float yaw,
|
||||
pika_float pitch,
|
||||
pika_float roll,
|
||||
int mode) {
|
||||
if (mode) {
|
||||
pitch = DegToRad(pitch);
|
||||
roll = DegToRad(roll);
|
||||
yaw = DegToRad(yaw);
|
||||
}
|
||||
|
||||
float sinp = sin(pitch / 2);
|
||||
float siny = sin(yaw / 2);
|
||||
float sinr = sin(roll / 2);
|
||||
|
||||
float cosp = cos(pitch / 2);
|
||||
float cosy = cos(yaw / 2);
|
||||
float cosr = cos(roll / 2);
|
||||
|
||||
float x = sinr * cosp * cosy - cosr * sinp * siny;
|
||||
float y = cosr * sinp * cosy + sinr * cosp * siny;
|
||||
float z = cosr * cosp * siny - sinr * sinp * cosy;
|
||||
float w = cosr * cosp * cosy + sinr * sinp * siny;
|
||||
|
||||
obj_setFloat(self, "x", x);
|
||||
obj_setFloat(self, "y", y);
|
||||
obj_setFloat(self, "z", z);
|
||||
obj_setFloat(self, "w", w);
|
||||
}
|
||||
|
||||
PikaObj* PikaMath_Quaternion_toEuler(PikaObj* self) {
|
||||
float x = obj_getFloat(self, "x");
|
||||
float y = obj_getFloat(self, "y");
|
||||
float z = obj_getFloat(self, "z");
|
||||
float w = obj_getFloat(self, "w");
|
||||
|
||||
float roll = atan2(2 * (w * x + y * z), 1 - 2 * (x * x + y * y));
|
||||
float pitch = asin(2 * (w * y - z * x));
|
||||
float yaw = atan2(2 * (w * z + x * y), 1 - 2 * (y * y + z * z));
|
||||
|
||||
float rpy[3] = {roll, pitch, yaw};
|
||||
|
||||
PikaObj* list = newNormalObj(New_PikaStdData_List);
|
||||
PikaStdData_List___init__(list);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Arg* token_arg = arg_newFloat(rpy[i]);
|
||||
/* 添加到 list 对象 */
|
||||
PikaStdData_List_append(list, token_arg);
|
||||
/* 销毁 arg */
|
||||
arg_deinit(token_arg);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
#include "PikaStdDevice_ADC.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_ADC_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC___init__(PikaObj* self) {
|
||||
PikaStdDevice_ADC_init(self);
|
||||
}
|
||||
|
||||
pika_float PikaStdDevice_ADC_read(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformRead", NULL);
|
||||
return obj_getFloat(self, "val");
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_ADC, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open ADC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformEnable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open ADC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
return;
|
||||
}
|
||||
pika_hal_ADC_config cfg = {0};
|
||||
cfg.continue_or_single = PIKA_HAL_ADC_SINGLE;
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformDisable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformRead(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ADC_config* cfg = (pika_hal_ADC_config*)dev->ioctl_config;
|
||||
uint32_t val_i = 0;
|
||||
pika_hal_read(dev, &val_i, sizeof(val_i));
|
||||
pika_float val = (pika_float)val_i / (pika_float)cfg->max * cfg->vref;
|
||||
val = val_i * obj_setFloat(self, "val", val);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_close(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_close(dev);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
#include "PikaStdDevice_BaseDev.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 10, 4)
|
||||
#error "This library requires PikaScript version 1.10.4 or higher"
|
||||
#endif
|
||||
|
||||
PikaEventListener* g_pika_device_event_listener;
|
||||
|
||||
void PikaStdDevice_BaseDev_addEventCallBack(PikaObj* self, Arg* eventCallBack) {
|
||||
#if PIKA_EVENT_ENABLE
|
||||
obj_setArg(self, "eventCallBack", eventCallBack);
|
||||
/* init event_listener for the first time */
|
||||
if (NULL == g_pika_device_event_listener) {
|
||||
pks_eventListener_init(&g_pika_device_event_listener);
|
||||
}
|
||||
if (PIKA_RES_OK != obj_runNativeMethod(self, "platformGetEventId", NULL)) {
|
||||
obj_setErrorCode(self, 1);
|
||||
__platform_printf("Error: Method %s no found.\r\n",
|
||||
"platformGetEventId");
|
||||
}
|
||||
uint32_t eventId = obj_getInt(self, "eventId");
|
||||
pks_eventListener_registEvent(g_pika_device_event_listener, eventId, self);
|
||||
#else
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled.");
|
||||
#endif
|
||||
}
|
||||
|
||||
void PikaStdDevice_BaseDev_platformGetEventId(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
#include "PikaStdDevice_CAN.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_CAN___init__(PikaObj* self) {}
|
||||
|
||||
void PikaStdDevice_CAN_addFilter(PikaObj* self,
|
||||
int hdr,
|
||||
int id,
|
||||
int ide,
|
||||
int mask,
|
||||
int mode,
|
||||
int rtr) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_setId(PikaObj* self, int id) {
|
||||
obj_setInt(self, "id", id);
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_setMode(PikaObj* self, char* mode) {
|
||||
obj_setStr(self, "mode", mode);
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_setName(PikaObj* self, char* name) {
|
||||
obj_setStr(self, "name", name);
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_setBaudRate(PikaObj* self, int baudRate) {
|
||||
obj_setInt(self, "baudRate", baudRate);
|
||||
}
|
||||
|
||||
char* PikaStdDevice_CAN_read(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_runNativeMethod(self, "platformRead", NULL);
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
|
||||
Arg* PikaStdDevice_CAN_readBytes(PikaObj *self, int length){
|
||||
obj_setInt(self, "length", length);
|
||||
obj_runNativeMethod(self, "platformReadBytes", NULL);
|
||||
return arg_copy(obj_getArg(self, "readData"));
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_write(PikaObj* self, char* data) {
|
||||
obj_setStr(self, "writeData", data);
|
||||
obj_runNativeMethod(self, "platformWrite", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_writeBytes(PikaObj *self, uint8_t* data, int length){
|
||||
obj_setBytes(self, "writeData", data, length);
|
||||
obj_runNativeMethod(self, "platformWriteBytes", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_platformRead(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_platformWrite(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_platformReadBytes(PikaObj *self){
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_CAN_platformWriteBytes(PikaObj *self){
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#include "PikaStdDevice_DAC.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_DAC, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open DAC '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_enable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_DAC_config cfg = {0};
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_disable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC___init__(PikaObj* self) {
|
||||
PikaStdDevice_DAC_init(self);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_write(PikaObj* self, pika_float val) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_DAC_config* cfg = (pika_hal_DAC_config*)dev->ioctl_config;
|
||||
uint32_t val_i = (val / cfg->vref) * cfg->max;
|
||||
pika_hal_write(dev, &val_i, sizeof val_i);
|
||||
}
|
||||
|
||||
void PikaStdDevice_DAC_close(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_close(dev);
|
||||
}
|
172
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/PikaStdDevice_GPIO.c
Executable file
172
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/PikaStdDevice_GPIO.c
Executable file
|
@ -0,0 +1,172 @@
|
|||
#include "PikaStdDevice_GPIO.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
obj_setStr(self, "pin", "none");
|
||||
obj_setStr(self, "mode", "out");
|
||||
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) {
|
||||
return obj_getInt(self, "id");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setId(PikaObj* self, int id) {
|
||||
obj_setInt(self, "id", id);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO___init__(PikaObj* self) {
|
||||
PikaStdDevice_GPIO_init(self);
|
||||
obj_setInt(self, "SIGNAL_RISING", PIKA_HAL_GPIO_EVENT_SIGNAL_RISING);
|
||||
obj_setInt(self, "SIGNAL_FALLING", PIKA_HAL_GPIO_EVENT_SIGNAL_FALLING);
|
||||
obj_setInt(self, "SIGNAL_ANY", PIKA_HAL_GPIO_EVENT_SIGNAL_ANY);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_disable(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_enable(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 1);
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
char* PikaStdDevice_GPIO_getMode(PikaObj* self) {
|
||||
return obj_getStr(self, "mode");
|
||||
}
|
||||
|
||||
char* PikaStdDevice_GPIO_getPin(PikaObj* self) {
|
||||
return obj_getStr(self, "pin");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_low(PikaObj* self) {
|
||||
obj_setInt(self, "isOn", 0);
|
||||
obj_runNativeMethod(self, "platformLow", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_high(PikaObj* self) {
|
||||
obj_setInt(self, "isOn", 1);
|
||||
obj_runNativeMethod(self, "platformHigh", NULL);
|
||||
}
|
||||
|
||||
int PikaStdDevice_GPIO_read(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformRead", NULL);
|
||||
return obj_getInt(self, "readBuff");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setMode(PikaObj* self, char* mode) {
|
||||
if (strEqu(mode, "out") || strEqu(mode, "in")) {
|
||||
obj_setStr(self, "mode", mode);
|
||||
obj_runNativeMethod(self, "platformSetMode", NULL);
|
||||
} else {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] GPIO mode should be 'out' or 'in'.");
|
||||
}
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setPull(PikaObj* self, char* pull) {
|
||||
if (strEqu(pull, "up") || strEqu(pull, "down") || strEqu(pull, "none")) {
|
||||
obj_setStr(self, "pull", pull);
|
||||
} else {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self,
|
||||
"[error] GPIO pull should be 'up', 'down' or 'none'.");
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformEnable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformLow(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 0;
|
||||
pika_hal_write(dev, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 1;
|
||||
pika_hal_write(dev, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) {
|
||||
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) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
uint32_t val = 0;
|
||||
pika_hal_read(dev, &val, sizeof(val));
|
||||
obj_setInt(self, "readBuff", val);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setCallBack(PikaObj* self,
|
||||
Arg* eventCallback,
|
||||
int filter) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
#if PIKA_EVENT_ENABLE
|
||||
_PikaStdDevice_setCallBack(self, eventCallback, (uintptr_t)dev);
|
||||
/* regist event to pika_hal */
|
||||
pika_hal_GPIO_config cfg_cb = {0};
|
||||
cfg_cb.event_callback = (void*)_PikaStdDevice_event_handler;
|
||||
cfg_cb.event_callback_filter = filter;
|
||||
cfg_cb.event_callback_ena = PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE;
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg_cb);
|
||||
#else
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled.");
|
||||
#endif
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_close(PikaObj *self){
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_close(dev);
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
#include "PikaStdDevice_IIC.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_IIC_init(PikaObj* self) {
|
||||
obj_setInt(self, "deviceAddr", 0);
|
||||
obj_setStr(self, "SCLpin", "PA0");
|
||||
obj_setStr(self, "SDApin", "PA1");
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC___init__(PikaObj* self) {
|
||||
PikaStdDevice_IIC_init(self);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_setDeviceAddr(PikaObj* self, int addr) {
|
||||
obj_setInt(self, "deviceAddr", addr);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_setPinSCL(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "SCLpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_setPinSDA(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "SDApin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_write(PikaObj* self, int addr, char* data) {
|
||||
obj_setStr(self, "writeData", data);
|
||||
obj_setInt(self, "writeAddr", addr);
|
||||
obj_runNativeMethod(self, "platformWrite", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_writeBytes(PikaObj* self,
|
||||
int addr,
|
||||
uint8_t* data,
|
||||
int length) {
|
||||
obj_setBytes(self, "writeData", data, length);
|
||||
obj_setInt(self, "writeAddr", addr);
|
||||
obj_runNativeMethod(self, "platformWriteBytes", NULL);
|
||||
}
|
||||
|
||||
char* PikaStdDevice_IIC_read(PikaObj* self, int addr, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_setInt(self, "readAddr", addr);
|
||||
obj_runNativeMethod(self, "platformRead", NULL);
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
|
||||
Arg* PikaStdDevice_IIC_readBytes(PikaObj* self, int addr, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_setInt(self, "readAddr", addr);
|
||||
obj_runNativeMethod(self, "platformReadBytes", NULL);
|
||||
return arg_copy(obj_getArg(self, "readData"));
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformWrite(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformRead(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformReadBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformWriteBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
112
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/PikaStdDevice_PWM.c
Executable file
112
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/PikaStdDevice_PWM.c
Executable file
|
@ -0,0 +1,112 @@
|
|||
#include "PikaStdDevice_PWM.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_PWM_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "none");
|
||||
obj_setStr(self, "name", "none");
|
||||
obj_setInt(self, "freq", 1000);
|
||||
obj_setInt(self, "ch", 0);
|
||||
obj_setFloat(self, "duty", 0.5f);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM___init__(PikaObj* self) {
|
||||
PikaStdDevice_PWM_init(self);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setFrequency(PikaObj* self, int freq) {
|
||||
obj_setInt(self, "freq", freq);
|
||||
obj_runNativeMethod(self, "platformSetFrequency", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setDuty(PikaObj* self, pika_float duty) {
|
||||
obj_setFloat(self, "duty", duty);
|
||||
obj_runNativeMethod(self, "platformSetDuty", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
pika_float PikaStdDevice_PWM_getDuty(PikaObj* self) {
|
||||
return obj_getFloat(self, "duty");
|
||||
}
|
||||
|
||||
int PikaStdDevice_PWM_getFrequency(PikaObj* self) {
|
||||
return obj_getInt(self, "freq");
|
||||
}
|
||||
|
||||
char* PikaStdDevice_PWM_getName(PikaObj* self) {
|
||||
return obj_getStr(self, "name");
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setName(PikaObj* self, char* name) {
|
||||
obj_setStr(self, "name", name);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setChannel(PikaObj* self, int ch) {
|
||||
obj_setInt(self, "ch", ch);
|
||||
}
|
||||
|
||||
int PikaStdDevice_PWM_getChannel(PikaObj* self) {
|
||||
return obj_getInt(self, "ch");
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setFreq(PikaObj* self, int freq) {
|
||||
PikaStdDevice_PWM_setFrequency(self, freq);
|
||||
}
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
dev = pika_hal_open(PIKA_HAL_PWM, obj_getStr(self, "pin"));
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open PWM '%s' failed.\r\n",
|
||||
obj_getStr(self, "pin"));
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformEnable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self) {
|
||||
pika_float duty = obj_getFloat(self, "duty"); // 0.0 ~ 1.0
|
||||
uint32_t freq = obj_getInt(self, "freq"); // Hz
|
||||
pika_hal_PWM_config cfg = {0};
|
||||
/* ns */
|
||||
cfg.duty = (uint32_t)(1000000000.0f / freq * duty);
|
||||
pika_hal_ioctl(_get_dev(self), PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) {
|
||||
uint32_t freq = obj_getInt(self, "freq"); // Hz
|
||||
pika_float duty = obj_getFloat(self, "duty"); // 0.0 ~ 1.0
|
||||
pika_hal_PWM_config cfg = {0};
|
||||
/* ns */
|
||||
cfg.period = (uint32_t)(1000000000.0f / freq);
|
||||
cfg.duty = (uint32_t)(1000000000.0f / freq * duty);
|
||||
pika_hal_ioctl(_get_dev(self), PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformDisable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_close(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_close(dev);
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
#include "PikaStdDevice_SPI.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_SPI___init__(PikaObj* self) {
|
||||
obj_setInt(self, "baudRate", 1000);
|
||||
obj_setInt(self, "id", 0);
|
||||
obj_setStr(self, "name", "none");
|
||||
obj_setInt(self, "phase", 0);
|
||||
obj_setStr(self, "MISOpin", "none");
|
||||
obj_setStr(self, "MOSIpin", "none");
|
||||
obj_setStr(self, "SCKpin", "none");
|
||||
obj_setInt(self, "polarity", 0);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_write(PikaObj* self, char* data) {
|
||||
obj_setStr(self, "writeData", data);
|
||||
obj_runNativeMethod(self, "platformWrite", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_writeBytes(PikaObj* self, uint8_t* data, int length) {
|
||||
obj_setBytes(self, "writeData", data, length);
|
||||
obj_runNativeMethod(self, "platformWriteBytes", NULL);
|
||||
}
|
||||
|
||||
char* PikaStdDevice_SPI_read(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_runNativeMethod(self, "platformRead", NULL);
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
|
||||
Arg* PikaStdDevice_SPI_readBytes(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_runNativeMethod(self, "platformReadBytes", NULL);
|
||||
return arg_copy(obj_getArg(self, "readData"));
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setBaudRate(PikaObj* self, int baudRate) {
|
||||
obj_setInt(self, "baudRate", baudRate);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setId(PikaObj* self, int id) {
|
||||
obj_setInt(self, "id", id);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setName(PikaObj* self, char* name) {
|
||||
obj_setStr(self, "name", name);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setPhase(PikaObj* self, int phase) {
|
||||
obj_setInt(self, "phase", phase);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setPinMISO(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "MISOpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setPinMOSI(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "MOSIpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setPinSCK(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "SCKpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_setPolarity(PikaObj* self, int polarity) {
|
||||
obj_setInt(self, "polarity", polarity);
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_platformDisable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_platformEnable(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_platformWrite(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_platformRead(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_platformWriteBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
||||
|
||||
void PikaStdDevice_SPI_platformReadBytes(PikaObj* self) {
|
||||
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
||||
}
|
236
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/PikaStdDevice_UART.c
Executable file
236
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/PikaStdDevice_UART.c
Executable file
|
@ -0,0 +1,236 @@
|
|||
#include "PikaStdDevice_UART.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_UART_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_disable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformDisable", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_init(PikaObj* self) {
|
||||
/* const */
|
||||
obj_setInt(self, "FLOW_CONTROL_NONE", PIKA_HAL_UART_FLOW_CONTROL_NONE);
|
||||
obj_setInt(self, "FLOW_CONTROL_RTS", PIKA_HAL_UART_FLOW_CONTROL_RTS);
|
||||
obj_setInt(self, "FLOW_CONTROL_CTS", PIKA_HAL_UART_FLOW_CONTROL_CTS);
|
||||
obj_setInt(self, "FLOW_CONTROL_RTS_CTS",
|
||||
PIKA_HAL_UART_FLOW_CONTROL_RTS_CTS);
|
||||
|
||||
obj_setInt(self, "SIGNAL_RX", PIKA_HAL_UART_EVENT_SIGNAL_RX);
|
||||
obj_setInt(self, "SIGNAL_TX", PIKA_HAL_UART_EVENT_SIGNAL_TX);
|
||||
|
||||
obj_setInt(self, "baudRate", 115200);
|
||||
obj_setInt(self, "id", 1);
|
||||
obj_setStr(self, "readBuff", "");
|
||||
obj_setInt(self, "flowControl", PIKA_HAL_UART_FLOW_CONTROL_NONE);
|
||||
obj_setStr(self, "TXpin", "none");
|
||||
obj_setStr(self, "RXpin", "none");
|
||||
obj_setStr(self, "RTSpin", "none");
|
||||
obj_setStr(self, "CTSpin", "none");
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART___init__(PikaObj* self) {
|
||||
PikaStdDevice_UART_init(self);
|
||||
}
|
||||
|
||||
char* PikaStdDevice_UART_read(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_runNativeMethod(self, "platformRead", NULL);
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) {
|
||||
obj_setInt(self, "baudRate", baudRate);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setFlowControl(PikaObj* self, int flowControl) {
|
||||
obj_setInt(self, "flowControl", flowControl);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setId(PikaObj* self, int id) {
|
||||
obj_setInt(self, "id", id);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_write(PikaObj* self, char* data) {
|
||||
obj_setStr(self, "writeData", data);
|
||||
obj_runNativeMethod(self, "platformWrite", NULL);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_writeBytes(PikaObj* self, uint8_t* data, int length) {
|
||||
obj_setBytes(self, "writeData", data, length);
|
||||
obj_runNativeMethod(self, "platformWriteBytes", NULL);
|
||||
}
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
if (NULL != dev) {
|
||||
return dev;
|
||||
}
|
||||
int id = obj_getInt(self, "id");
|
||||
char id_str[32] = {0};
|
||||
sprintf(id_str, "UART%d", id);
|
||||
dev = pika_hal_open(PIKA_HAL_UART, id_str);
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open UART '%s' failed.\r\n", id_str);
|
||||
}
|
||||
obj_setPtr(self, "pika_dev", dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformEnable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open UART '%d' failed.\r\n",
|
||||
(int)obj_getInt(self, "id"));
|
||||
return;
|
||||
}
|
||||
pika_hal_UART_config cfg = {0};
|
||||
cfg.baudrate = obj_getInt(self, "baudRate");
|
||||
cfg.flow_control = obj_getInt(self, "flowControl");
|
||||
if (!strEqu(obj_getStr(self, "TXpin"), "none")) {
|
||||
cfg.TX = pika_hal_open(PIKA_HAL_GPIO, obj_getStr(self, "TXpin"));
|
||||
if (NULL == cfg.TX) {
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n",
|
||||
obj_getStr(self, "TXpin"));
|
||||
}
|
||||
}
|
||||
if (!strEqu(obj_getStr(self, "RXpin"), "none")) {
|
||||
cfg.RX = pika_hal_open(PIKA_HAL_GPIO, obj_getStr(self, "RXpin"));
|
||||
if (NULL == cfg.RX) {
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n",
|
||||
obj_getStr(self, "RXpin"));
|
||||
}
|
||||
}
|
||||
if (!strEqu(obj_getStr(self, "RTSpin"), "none")) {
|
||||
cfg.RTS = pika_hal_open(PIKA_HAL_GPIO, obj_getStr(self, "RTSpin"));
|
||||
if (NULL == cfg.RTS) {
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n",
|
||||
obj_getStr(self, "RTSpin"));
|
||||
}
|
||||
}
|
||||
if (!strEqu(obj_getStr(self, "CTSpin"), "none")) {
|
||||
cfg.CTS = pika_hal_open(PIKA_HAL_GPIO, obj_getStr(self, "CTSpin"));
|
||||
if (NULL == cfg.CTS) {
|
||||
__platform_printf("Error: open GPIO '%s' failed.\r\n",
|
||||
obj_getStr(self, "CTSpin"));
|
||||
}
|
||||
}
|
||||
int err = -1;
|
||||
err = pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
if (err != 0) {
|
||||
__platform_printf("Error: config UART '%d' failed.\r\n",
|
||||
(int)obj_getInt(self, "id"));
|
||||
return;
|
||||
}
|
||||
err = pika_hal_ioctl(dev, PIKA_HAL_IOCTL_ENABLE);
|
||||
if (err != 0) {
|
||||
__platform_printf("Error: enable UART '%d' failed.\r\n",
|
||||
(int)obj_getInt(self, "id"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformRead(PikaObj* self) {
|
||||
int len = obj_getInt(self, "length");
|
||||
obj_setBytes(self, "_readData", NULL, len + 1);
|
||||
char* buff = (char*)obj_getBytes(self, "_readData");
|
||||
pika_dev* dev = _get_dev(self);
|
||||
int len_get = pika_hal_read(dev, buff, len);
|
||||
buff[len_get] = 0;
|
||||
obj_setStr(self, "readData", buff);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformWrite(PikaObj* self) {
|
||||
char* data = obj_getStr(self, "writeData");
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_write(dev, data, strlen(data));
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformDisable(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
if (NULL == dev) {
|
||||
__platform_printf("Error: open UART '%d' failed.\r\n",
|
||||
(int)obj_getInt(self, "id"));
|
||||
return;
|
||||
}
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformReadBytes(PikaObj* self) {
|
||||
int len = obj_getInt(self, "length");
|
||||
obj_setBytes(self, "_readData", NULL, len + 1);
|
||||
uint8_t* buff = obj_getBytes(self, "_readData");
|
||||
pika_dev* dev = _get_dev(self);
|
||||
int len_get = pika_hal_read(dev, buff, len);
|
||||
obj_setBytes(self, "readData", buff, len_get);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformWriteBytes(PikaObj* self) {
|
||||
uint8_t* data = obj_getBytes(self, "writeData");
|
||||
int len = obj_getBytesSize(self, "writeData");
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_write(dev, data, len);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setCallBack(PikaObj* self,
|
||||
Arg* eventCallBack,
|
||||
int filter) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
#if PIKA_EVENT_ENABLE
|
||||
_PikaStdDevice_setCallBack(self, eventCallBack, (uintptr_t)dev);
|
||||
/* regist event to pika_hal */
|
||||
pika_hal_UART_config cfg_cb = {0};
|
||||
cfg_cb.event_callback = (void*)_PikaStdDevice_event_handler;
|
||||
cfg_cb.event_callback_filter = filter;
|
||||
cfg_cb.event_callback_ena = PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE;
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg_cb);
|
||||
#else
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled.");
|
||||
#endif
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_close(PikaObj* self) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_UART_config* cfg = (pika_hal_UART_config*)dev->ioctl_config;
|
||||
if (NULL != cfg->TX) {
|
||||
pika_hal_close(cfg->TX);
|
||||
cfg->TX = NULL;
|
||||
}
|
||||
if (NULL != cfg->RX) {
|
||||
pika_hal_close(cfg->RX);
|
||||
cfg->RX = NULL;
|
||||
}
|
||||
if (NULL != cfg->RTS) {
|
||||
pika_hal_close(cfg->RTS);
|
||||
cfg->RTS = NULL;
|
||||
}
|
||||
if (NULL != cfg->CTS) {
|
||||
pika_hal_close(cfg->CTS);
|
||||
cfg->CTS = NULL;
|
||||
}
|
||||
pika_hal_close(dev);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setPinCTS(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "CTSpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setPinRTS(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "RTSpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setPinRX(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "RXpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setPinTX(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "TXpin", pin);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#include "PikaStdDevice_common.h"
|
||||
|
||||
extern PikaEventListener* g_pika_device_event_listener;
|
||||
void _PikaStdDevice_event_handler(pika_dev* dev, int signal) {
|
||||
pks_eventListener_sendSignal(g_pika_device_event_listener, (uintptr_t)dev,
|
||||
signal);
|
||||
}
|
||||
|
||||
void _PikaStdDevice_setCallBack(PikaObj* self,
|
||||
Arg* eventCallback,
|
||||
uint32_t eventId) {
|
||||
obj_setArg(self, "eventCallBack", eventCallback);
|
||||
/* init event_listener for the first time */
|
||||
if (NULL == g_pika_device_event_listener) {
|
||||
pks_eventListener_init(&g_pika_device_event_listener);
|
||||
}
|
||||
/* regist event to event listener */
|
||||
pks_eventListener_registEvent(g_pika_device_event_listener, eventId, self);
|
||||
}
|
||||
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
PikaObj* PikaStdDevice_Time(PikaObj* self) {
|
||||
PikaObj* time = obj_getPtr((PikaObj*)__pikaMain, "time");
|
||||
if(NULL == time){
|
||||
obj_setErrorCode(self, -1);
|
||||
obj_setSysOut(self, "Error: please install and import 'time' module");
|
||||
return NULL;
|
||||
}
|
||||
obj_refcntInc(time);
|
||||
return time;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef _PIKA_STDDEVICE_COMMON_H
|
||||
#define _PIKA_STDDEVICE_COMMON_H
|
||||
#include "PikaObj.h"
|
||||
#include "PikaVM.h"
|
||||
#include "pika_hal.h"
|
||||
void _PikaStdDevice_setCallBack(PikaObj* self,
|
||||
Arg* eventCallback,
|
||||
uint32_t eventId);
|
||||
|
||||
void _PikaStdDevice_event_handler(pika_dev* dev, int signal);
|
||||
|
||||
#endif
|
310
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/pika_hal.c
Executable file
310
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/pika_hal.c
Executable file
|
@ -0,0 +1,310 @@
|
|||
#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) {
|
||||
if (NULL == name) {
|
||||
__platform_printf("Error: dev_open name is NULL.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
int ret = -1;
|
||||
pika_dev* dev = NULL;
|
||||
if (dev_type >= _PIKA_DEV_TYPE_MAX) {
|
||||
__platform_printf("Error: dev_type invalied.\r\n");
|
||||
goto __exit;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev_type);
|
||||
dev = (pika_dev*)pikaMalloc(sizeof(pika_dev));
|
||||
if (dev == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
memset(dev, 0, sizeof(pika_dev));
|
||||
dev->type = dev_type;
|
||||
dev->ioctl_config = pikaMalloc(_pika_hal_dev_config_size(dev_type));
|
||||
if (dev->ioctl_config == NULL) {
|
||||
goto __exit;
|
||||
}
|
||||
memset(dev->ioctl_config, 0, _pika_hal_dev_config_size(dev_type));
|
||||
ret = impl->open(dev, name);
|
||||
__exit:
|
||||
if (0 == ret) {
|
||||
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));
|
||||
dev->ioctl_config = NULL;
|
||||
}
|
||||
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->ioctl_config) {
|
||||
pikaFree(dev->ioctl_config, _pika_hal_dev_config_size(dev->type));
|
||||
dev->ioctl_config = NULL;
|
||||
}
|
||||
if (NULL != dev) {
|
||||
pikaFree(dev, sizeof(pika_dev));
|
||||
}
|
||||
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) {
|
||||
return _pika_hal_cmd_arg_cnt[PIKA_HAL_IOCTL_CONFIG];
|
||||
}
|
||||
|
||||
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;
|
||||
PIKA_HAL_IOCTL_CMD cmd_origin = cmd;
|
||||
if (dev == NULL) {
|
||||
return -1;
|
||||
}
|
||||
cmd = _pika_hal_get_arg_cnt(cmd_origin);
|
||||
if (cmd < 0) {
|
||||
return -1;
|
||||
}
|
||||
pika_dev_impl* impl = _pika_dev_get_impl(dev->type);
|
||||
if (impl->ioctl == NULL) {
|
||||
return -1;
|
||||
}
|
||||
void* arg_in = NULL;
|
||||
if (cmd != 0) {
|
||||
va_list args;
|
||||
va_start(args, cmd);
|
||||
arg_in = va_arg(args, void*);
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_CONFIG) {
|
||||
ret = _pika_hal_ioctl_merge_config(dev, arg_in);
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
va_end(args);
|
||||
if (0 != ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_CONFIG) {
|
||||
ret = impl->ioctl(dev, cmd_origin, dev->ioctl_config);
|
||||
} else {
|
||||
ret = impl->ioctl(dev, cmd_origin, arg_in);
|
||||
}
|
||||
if (ret == 0) {
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_ENABLE) {
|
||||
dev->is_enabled = 1;
|
||||
}
|
||||
if (cmd_origin == PIKA_HAL_IOCTL_DISABLE) {
|
||||
dev->is_enabled = 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#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 */ \
|
||||
dst->item = src->item; \
|
||||
}
|
||||
|
||||
#define _IOCTL_CONFIG_USE_DEFAULT_STR(item, default) \
|
||||
if (src->item[0] == '\0') { \
|
||||
if (dst->item[0] == '\0') { \
|
||||
/* use default value */ \
|
||||
strcpy(dst->item, default); \
|
||||
} else { \
|
||||
/* keep exist value */ \
|
||||
} \
|
||||
} else { \
|
||||
/* use input value */ \
|
||||
strcpy(dst->item, src->item); \
|
||||
}
|
||||
|
||||
int pika_hal_GPIO_ioctl_merge_config(pika_hal_GPIO_config* dst,
|
||||
pika_hal_GPIO_config* src) {
|
||||
// printf("before merge: dst->dir=%d, src->dir=%d\r\n", dst->dir, src->dir);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(dir, PIKA_HAL_GPIO_DIR_IN);
|
||||
// printf("after merge: dst->dir=%d, src->dir=%d\r\n", dst->dir, src->dir);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(pull, PIKA_HAL_GPIO_PULL_NONE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_GPIO_SPEED_10M);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_filter,
|
||||
PIKA_HAL_GPIO_EVENT_SIGNAL_RISING);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_ena,
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE);
|
||||
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(flow_control, PIKA_HAL_UART_FLOW_CONTROL_NONE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_filter,
|
||||
PIKA_HAL_UART_EVENT_SIGNAL_RX);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(event_callback_ena,
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(TX, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(RX, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(RTS, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(CTS, 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);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_SPI_TIMEOUT_1000MS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_SOFT_SPI_ioctl_merge_config(pika_hal_SOFT_SPI_config* dst,
|
||||
pika_hal_SOFT_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);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_SPI_TIMEOUT_1000MS);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(CS, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(SCK, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(MOSI, NULL);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(MISO, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_IIC_ioctl_merge_config(pika_hal_IIC_config* dst,
|
||||
pika_hal_IIC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(address_width, PIKA_HAL_IIC_ADDRESS_WIDTH_7BIT);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(master_or_slave, PIKA_HAL_IIC_MASTER);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(slave_addr, 0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mem_addr_ena, PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mem_addr_size, PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT);
|
||||
dst->mem_addr = src->mem_addr;
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_IIC_SPEED_100K);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(timeout, PIKA_HAL_IIC_TIMEOUT_1000MS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_PWM_ioctl_merge_config(pika_hal_PWM_config* dst,
|
||||
pika_hal_PWM_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(period, PIKA_HAL_PWM_PERIOD_1MS * 10);
|
||||
// _IOCTL_CONFIG_USE_DEFAULT(duty, 0);
|
||||
dst->duty = src->duty;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_ADC_ioctl_merge_config(pika_hal_ADC_config* dst,
|
||||
pika_hal_ADC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_resolution, PIKA_HAL_ADC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_freq, PIKA_HAL_ADC_SAMPLING_FREQ_100);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(continue_or_single, PIKA_HAL_ADC_SINGLE);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(vref, (pika_float)3.3);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 8192);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_DAC_ioctl_merge_config(pika_hal_DAC_config* dst,
|
||||
pika_hal_DAC_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(speed, PIKA_HAL_DAC_SPEED_1K * 8);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(sampling_resolution, PIKA_HAL_DAC_RESOLUTION_12);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(vref, (pika_float)3.3);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 3300000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_WIFI_ioctl_merge_config(pika_hal_WIFI_config* dst,
|
||||
pika_hal_WIFI_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mode, PIKA_HAL_WIFI_MODE_STA);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(channel, PIKA_HAL_WIFI_CHANNEL_0);
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max_connection, PIKA_HAL_WIFI_MAX_CONNECTION_4);
|
||||
_IOCTL_CONFIG_USE_DEFAULT_STR(ap_ssid, "pikapython.com");
|
||||
_IOCTL_CONFIG_USE_DEFAULT_STR(ap_bssid, "");
|
||||
_IOCTL_CONFIG_USE_DEFAULT_STR(ap_password, "pikapython.com");
|
||||
return 0;
|
||||
}
|
486
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/pika_hal.h
Executable file
486
examples/pikapython/pikapython/pikascript-lib/PikaStdDevice/pika_hal.h
Executable file
|
@ -0,0 +1,486 @@
|
|||
#ifndef _PIKA_DEV_HAL_H
|
||||
#define _PIKA_DEV_HAL_H
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "PikaObj.h"
|
||||
|
||||
/*
|
||||
* pika_hal is a C Device HAL lib for PikaScript modules.
|
||||
* 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;
|
||||
PIKA_BOOL is_enabled;
|
||||
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_WIFI_GET_ACTIVE,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_STATUS,
|
||||
PIKA_HAL_IOCTL_WIFI_SCAN,
|
||||
PIKA_HAL_IOCTL_WIFI_CONNECT,
|
||||
PIKA_HAL_IOCTL_WIFI_DISCONNECT,
|
||||
PIKA_HAL_IOCTL_WIFI_SET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_IFCONFIG,
|
||||
_ = 0xFFFFFFFF, // make sure it is 4 byte width
|
||||
} 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 enum {
|
||||
_PIKA_HAL_EVENT_CALLBACK_ENA_UNUSED = 0,
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE,
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA_DISABLE,
|
||||
} PIKA_HAL_EVENT_CALLBACK_ENA;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_GPIO_EVENT_SIGNAL_UNUSED = 0,
|
||||
PIKA_HAL_GPIO_EVENT_SIGNAL_RISING,
|
||||
PIKA_HAL_GPIO_EVENT_SIGNAL_FALLING,
|
||||
PIKA_HAL_GPIO_EVENT_SIGNAL_ANY,
|
||||
} PIKA_HAL_GPIO_EVENT_SIGNAL;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_GPIO_DIR dir;
|
||||
PIKA_HAL_GPIO_PULL pull;
|
||||
PIKA_HAL_GPIO_SPEED speed;
|
||||
void (*event_callback)(pika_dev* dev, PIKA_HAL_GPIO_EVENT_SIGNAL signal);
|
||||
PIKA_HAL_GPIO_EVENT_SIGNAL event_callback_filter;
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA event_callback_ena;
|
||||
} 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_1_5 = 3,
|
||||
} 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 enum {
|
||||
_PIKA_HAL_UART_EVENT_SIGNAL_UNUSED = 0,
|
||||
PIKA_HAL_UART_EVENT_SIGNAL_RX,
|
||||
PIKA_HAL_UART_EVENT_SIGNAL_TX,
|
||||
PIKA_HAL_UART_EVENT_SIGNAL_ANY,
|
||||
} PIKA_HAL_UART_EVENT_SIGNAL;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_UART_FLOW_CONTROL_UNUSED = 0,
|
||||
PIKA_HAL_UART_FLOW_CONTROL_NONE,
|
||||
PIKA_HAL_UART_FLOW_CONTROL_RTS,
|
||||
PIKA_HAL_UART_FLOW_CONTROL_CTS,
|
||||
PIKA_HAL_UART_FLOW_CONTROL_RTS_CTS,
|
||||
} PIKA_HAL_UART_FLOW_CONTROL;
|
||||
|
||||
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;
|
||||
PIKA_HAL_UART_FLOW_CONTROL flow_control;
|
||||
void (*event_callback)(pika_dev* dev, PIKA_HAL_UART_EVENT_SIGNAL signal);
|
||||
PIKA_HAL_UART_EVENT_SIGNAL event_callback_filter;
|
||||
PIKA_HAL_EVENT_CALLBACK_ENA event_callback_ena;
|
||||
pika_dev* TX;
|
||||
pika_dev* RX;
|
||||
pika_dev* RTS;
|
||||
pika_dev* CTS;
|
||||
} pika_hal_UART_config;
|
||||
|
||||
typedef uint32_t PIKA_HAL_IIC_SLAVE_ADDR;
|
||||
typedef uint32_t PIKA_HAL_IIC_MEM_ADDR;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MEM_ADDR_SIZE {
|
||||
_PIKA_HAL_IIC_MEM_ADDR_SIZE_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT = 1,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_16BIT = 2,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_24BIT = 3,
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE_32BIT = 4,
|
||||
} PIKA_HAL_IIC_MEM_ADDR_SIZE;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MEM_ADDR_ENA {
|
||||
_PIKA_HAL_IIC_MEM_ADDR_ENA_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE,
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE,
|
||||
} PIKA_HAL_IIC_MEM_ADDR_ENA;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_IIC_SPEED_UNUSED = 0,
|
||||
PIKA_HAL_IIC_SPEED_100K = 100000,
|
||||
PIKA_HAL_IIC_SPEED_400K = 400000,
|
||||
PIKA_HAL_IIC_SPEED_1M = 1000000,
|
||||
} PIKA_HAL_IIC_SPEED;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_MASTER_OR_SLAVE {
|
||||
_PIKA_HAL_IIC_MASTER_OR_SLAVE_UNUSED = 0,
|
||||
PIKA_HAL_IIC_MASTER,
|
||||
PIKA_HAL_IIC_SLAVE,
|
||||
} PIKA_HAL_IIC_MASTER_OR_SLAVE;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_ADDRESS_WIDTH {
|
||||
_PIKA_HAL_IIC_ADDRESS_WIDTH_UNUSED = 0,
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH_7BIT = 7,
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH_10BIT = 10,
|
||||
} PIKA_HAL_IIC_ADDRESS_WIDTH;
|
||||
|
||||
typedef enum PIKA_HAL_IIC_TIMEOUT {
|
||||
_PIKA_HAL_IIC_TIMEOUT_UNUSED = 0,
|
||||
PIKA_HAL_IIC_TIMEOUT_1MS = 1,
|
||||
PIKA_HAL_IIC_TIMEOUT_2MS = 2,
|
||||
PIKA_HAL_IIC_TIMEOUT_5MS = 5,
|
||||
PIKA_HAL_IIC_TIMEOUT_10MS = 10,
|
||||
PIKA_HAL_IIC_TIMEOUT_20MS = 20,
|
||||
PIKA_HAL_IIC_TIMEOUT_50MS = 50,
|
||||
PIKA_HAL_IIC_TIMEOUT_100MS = 100,
|
||||
PIKA_HAL_IIC_TIMEOUT_200MS = 200,
|
||||
PIKA_HAL_IIC_TIMEOUT_500MS = 500,
|
||||
PIKA_HAL_IIC_TIMEOUT_1000MS = 1000,
|
||||
} PIKA_HAL_IIC_TIMEOUT;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_IIC_ADDRESS_WIDTH address_width;
|
||||
PIKA_HAL_IIC_MASTER_OR_SLAVE master_or_slave;
|
||||
PIKA_HAL_IIC_SLAVE_ADDR slave_addr;
|
||||
PIKA_HAL_IIC_MEM_ADDR_ENA mem_addr_ena;
|
||||
PIKA_HAL_IIC_MEM_ADDR mem_addr;
|
||||
PIKA_HAL_IIC_MEM_ADDR_SIZE mem_addr_size;
|
||||
PIKA_HAL_IIC_SPEED speed;
|
||||
PIKA_HAL_IIC_TIMEOUT timeout;
|
||||
} pika_hal_IIC_config;
|
||||
|
||||
typedef enum PIKA_HAL_SPI_TIMEOUT {
|
||||
_PIKA_HAL_SPI_TIMEOUT_UNUSED = 0,
|
||||
PIKA_HAL_SPI_TIMEOUT_1MS = 1,
|
||||
PIKA_HAL_SPI_TIMEOUT_2MS = 2,
|
||||
PIKA_HAL_SPI_TIMEOUT_5MS = 5,
|
||||
PIKA_HAL_SPI_TIMEOUT_10MS = 10,
|
||||
PIKA_HAL_SPI_TIMEOUT_20MS = 20,
|
||||
PIKA_HAL_SPI_TIMEOUT_50MS = 50,
|
||||
PIKA_HAL_SPI_TIMEOUT_100MS = 100,
|
||||
PIKA_HAL_SPI_TIMEOUT_200MS = 200,
|
||||
PIKA_HAL_SPI_TIMEOUT_500MS = 500,
|
||||
PIKA_HAL_SPI_TIMEOUT_1000MS = 1000,
|
||||
} PIKA_HAL_SPI_TIMEOUT;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_SPI_LSB_OR_MSB_UNUSED = 0,
|
||||
PIKA_HAL_SPI_LSB,
|
||||
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_TIMEOUT timeout;
|
||||
} pika_hal_SPI_config;
|
||||
|
||||
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_TIMEOUT timeout;
|
||||
pika_dev* CS;
|
||||
pika_dev* SCK;
|
||||
pika_dev* MOSI;
|
||||
pika_dev* MISO;
|
||||
} pika_hal_SOFT_SPI_config;
|
||||
|
||||
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 enum PIKA_HAL_ADC_SAMPLING_FREQ {
|
||||
_PIKA_HAL_ADC_SAMPLING_FREQ_UNUSED = 0,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_100 = 100,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_1K = 1000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_10K = 10000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_100K = 100000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_1M = 1000000,
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ_10M = 10000000,
|
||||
} PIKA_HAL_ADC_SAMPLING_FREQ;
|
||||
|
||||
typedef enum PIKA_HAL_ADC_CONTINUOU_OR_SINGLE {
|
||||
_PIKA_HAL_ADC_CONTINUOU_OR_SINGLE_UNUSED = 0,
|
||||
PIKA_HAL_ADC_SINGLE,
|
||||
PIKA_HAL_ADC_CONTINUOU,
|
||||
} PIKA_HAL_ADC_CONTINUOU_OR_SINGLE;
|
||||
|
||||
typedef pika_float PIKA_HAL_ADC_VREF;
|
||||
typedef uint32_t PIKA_HAL_ADC_MAX;
|
||||
|
||||
typedef struct {
|
||||
PIKA_HAL_ADC_RESOLUTION sampling_resolution;
|
||||
PIKA_HAL_ADC_SAMPLING_FREQ sampling_freq;
|
||||
PIKA_HAL_ADC_CONTINUOU_OR_SINGLE continue_or_single;
|
||||
PIKA_HAL_ADC_MAX max;
|
||||
PIKA_HAL_ADC_VREF vref;
|
||||
} pika_hal_ADC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_DAC_RESOLUTION_UNUSED = 0,
|
||||
PIKA_HAL_DAC_RESOLUTION_8 = 8,
|
||||
PIKA_HAL_DAC_RESOLUTION_10 = 10,
|
||||
PIKA_HAL_DAC_RESOLUTION_12 = 12,
|
||||
PIKA_HAL_DAC_RESOLUTION_14 = 14,
|
||||
PIKA_HAL_DAC_RESOLUTION_16 = 16,
|
||||
} PIKA_HAL_DAC_RESOLUTION;
|
||||
|
||||
typedef enum PIKA_HAL_DAC_SPEED {
|
||||
_PIKA_HAL_DAC_SPEED_UNUSED = 0,
|
||||
PIKA_HAL_DAC_SPEED_100 = 100,
|
||||
PIKA_HAL_DAC_SPEED_1K = 1000,
|
||||
PIKA_HAL_DAC_SPEED_10K = 10000,
|
||||
PIKA_HAL_DAC_SPEED_100K = 100000,
|
||||
PIKA_HAL_DAC_SPEED_1M = 1000000,
|
||||
PIKA_HAL_DAC_SPEED_10M = 10000000,
|
||||
PIKA_HAL_DAC_SPEED_20M = 20000000,
|
||||
PIKA_HAL_DAC_SPEED_50M = 50000000,
|
||||
PIKA_HAL_DAC_SPEED_100M = 100000000,
|
||||
} PIKA_HAL_DAC_SPEED;
|
||||
|
||||
typedef pika_float PIKA_HAL_DAC_VREF;
|
||||
typedef uint32_t PIKA_HAL_DAC_MAX;
|
||||
|
||||
typedef struct pika_hal_DAC_config {
|
||||
PIKA_HAL_DAC_RESOLUTION sampling_resolution;
|
||||
PIKA_HAL_DAC_SPEED speed;
|
||||
PIKA_HAL_DAC_MAX max;
|
||||
PIKA_HAL_DAC_VREF vref;
|
||||
} pika_hal_DAC_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_DAC_UNUSED = 0,
|
||||
PIKA_HAL_PWM_CHANNEL_0,
|
||||
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_PERIOD period;
|
||||
PIKA_HAL_PWM_DUTY duty;
|
||||
} pika_hal_PWM_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_MODE_UNUSED = 0,
|
||||
PIKA_HAL_WIFI_MODE_STA,
|
||||
PIKA_HAL_WIFI_MODE_AP,
|
||||
} PIKA_HAL_WIFI_MODE;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_STATUS_UNUSED = 0,
|
||||
PIKA_HAL_WIFI_STATUS_IDLE,
|
||||
PIKA_HAL_WIFI_STATUS_CONNECTING,
|
||||
PIKA_HAL_WIFI_STATUS_WRONG_PASSWORD,
|
||||
PIKA_HAL_WIFI_STATUS_NO_AP_FOUND,
|
||||
PIKA_HAL_WIFI_STATUS_CONNECT_FAIL,
|
||||
PIKA_HAL_WIFI_STATUS_GOT_IP,
|
||||
} PIKA_HAL_WIFI_STATUS;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_CHANNEL_UNUSED = 0,
|
||||
PIKA_HAL_WIFI_CHANNEL_0,
|
||||
PIKA_HAL_WIFI_CHANNEL_1,
|
||||
PIKA_HAL_WIFI_CHANNEL_2,
|
||||
PIKA_HAL_WIFI_CHANNEL_3,
|
||||
PIKA_HAL_WIFI_CHANNEL_4,
|
||||
PIKA_HAL_WIFI_CHANNEL_5,
|
||||
PIKA_HAL_WIFI_CHANNEL_6,
|
||||
PIKA_HAL_WIFI_CHANNEL_7,
|
||||
PIKA_HAL_WIFI_CHANNEL_8,
|
||||
PIKA_HAL_WIFI_CHANNEL_9,
|
||||
PIKA_HAL_WIFI_CHANNEL_10,
|
||||
PIKA_HAL_WIFI_CHANNEL_11,
|
||||
} PIKA_HAL_WIFI_CHANNEL;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_MAX_CONNECTION = 0,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_1,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_2,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_3,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_4,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_5,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_6,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_7,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_8,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_9,
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION_10
|
||||
} PIKA_HAL_WIFI_MAX_CONNECTION;
|
||||
|
||||
#define PIKA_HAL_WIFI_PARAM_MAX_LEN 32
|
||||
typedef struct pika_hal_WIFI_config {
|
||||
PIKA_HAL_WIFI_MODE mode;
|
||||
PIKA_HAL_WIFI_CHANNEL channel;
|
||||
PIKA_HAL_WIFI_MAX_CONNECTION max_connection;
|
||||
char ap_ssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char ap_bssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char ap_password[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
} pika_hal_WIFI_config;
|
||||
|
||||
typedef struct pika_hal_WIFI_connect_config {
|
||||
char ssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char bssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char password[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
} pika_hal_WIFI_connect_config;
|
||||
|
||||
typedef struct pika_hal_WIFI_ifconfig {
|
||||
char ip[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char netmask[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char gateway[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char dns[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
} pika_hal_WIFI_ifconfig;
|
||||
|
||||
typedef struct pika_hal_WIFI_record {
|
||||
char ssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
uint8_t bssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
size_t bssid_len;
|
||||
int channel;
|
||||
int rssi;
|
||||
int authmode;
|
||||
} pika_hal_WIFI_record;
|
||||
|
||||
typedef struct pika_hal_WIFI_scan_result {
|
||||
int count;
|
||||
pika_hal_WIFI_record records[];
|
||||
} pika_hal_WIFI_scan_result;
|
||||
|
||||
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
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue