remove file but main.py and requsetment.txt

This commit is contained in:
lyon 2021-10-06 23:06:25 +08:00
parent da3bff6375
commit 086990710c
95 changed files with 0 additions and 6790 deletions

View File

@ -1,14 +0,0 @@
class TinyObj:
pass
class BaseObj(TinyObj):
pass
def print(val: any):
pass
def set(argPath: str, val: any):
pass

View File

@ -1,21 +0,0 @@
from PikaObj import *
import PikaStdLib
import STM32
class RGB(PikaStdLib.SysObj):
pin = STM32.GPIO()
def init():
pass
def enable():
pass
def red():
pass
def green():
pass
def blue():
pass
def white():
pass
def flow():
pass

View File

@ -1,149 +0,0 @@
from PikaObj import *
class GPIO(TinyObj):
def init():
pass
def setPin(pinName: str):
pass
def getPin() -> str:
pass
def setMode(mode: str):
pass
def getMode() -> str:
pass
def enable():
pass
def disable():
pass
def high():
pass
def low():
pass
# need be overrid
def platformHigh():
pass
# need override
def platformLow():
pass
# need override
def platformEnable():
pass
# need override
def platformDisable():
pass
# need override
def platformSetMode(mode: str):
pass
class Time(TinyObj):
# need override
def sleep_s(s: int):
pass
# need override
def sleep_ms(ms: int):
pass
class ADC(TinyObj):
def init():
pass
def setPin(pin: str):
pass
def enable():
pass
def read() -> float:
pass
# need override
def platformEnable(pin: str):
pass
# need override
def platformRead(pin: str) -> float:
pass
class UART(TinyObj):
def init():
pass
def setBaudRate(baudRate: int):
pass
def setId(id: int):
pass
def enable():
pass
def write(data: str):
pass
def read(length: int) -> str:
pass
# need override
def platformEnable(id: int, baudRate: int):
pass
# need override
def platformWrite(id: int, data: str):
pass
# need override
def platformRead(id: int, length: int) -> str:
pass
class PWM(TinyObj):
def init():
pass
def setPin(pin: str):
pass
def setFrequency(freq: int):
pass
def setDuty(duty: float):
pass
def enable():
pass
def getFrequency() -> int:
pass
def getDuty() -> float:
pass
# need override
def platformEnable(pin: str, freq: int, duty: float):
pass
# need override
def platformSetFrequency(pin: str, freq: int):
pass
# need override
def platformSetDuty(pin: str, duty: float):
pass

View File

@ -1,27 +0,0 @@
from PikaObj import *
class MemChecker(BaseObj):
def max():
pass
def now():
pass
def resetMax():
pass
class SysObj(BaseObj):
def type(argPath: str):
pass
def ls(objPath: str):
pass
def remove(argPath: str):
pass
def new(objPath: str, classPath: str):
pass

View File

@ -1,71 +0,0 @@
from typing import overload
import PikaStdDevice
class GPIO(PikaStdDevice.GPIO):
# override
def platformHigh():
pass
# override
def platformLow():
pass
# override
def platformEnable():
pass
# override
def platformDisable():
pass
# override
def platformSetMode(mode: str):
pass
class Time(PikaStdDevice.Time):
# override
def sleep_s(s: int):
pass
# override
def sleep_ms(ms: int):
pass
class ADC(PikaStdDevice.ADC):
# override
def platformEnable(pin: str):
pass
# override
def platformRead(pin: str) -> float:
pass
class UART(PikaStdDevice.UART):
# override
def platformEnable(id: int, baudRate: int):
pass
# override
def platformWrite(id: int, data: str):
pass
# override
def platformRead(id: int, length: int) -> str:
pass
class PWM(PikaStdDevice.PWM):
# override
def platformEnable(pin: str, freq: int, duty: float):
pass
# override
def platformSetFrequency(pin: str, freq: int):
pass
# override
def platformSetDuty(pin: str, duty: float):
pass

View File

@ -1,27 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaMain.h"
#include "PikaStdLib_SysObj.h"
#include "STM32_ADC.h"
#include "PikaStdLib_MemChecker.h"
#include "STM32_GPIO.h"
#include "STM32_PWM.h"
#include "PikaPiZero_RGB.h"
#include "STM32_Time.h"
#include "STM32_UART.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
PikaObj *New_PikaMain(Args *args){
PikaObj *self = New_PikaStdLib_SysObj(args);
obj_import(self, "STM32_ADC", New_STM32_ADC);
obj_import(self, "PikaStdLib_MemChecker", New_PikaStdLib_MemChecker);
obj_import(self, "STM32_GPIO", New_STM32_GPIO);
obj_import(self, "STM32_PWM", New_STM32_PWM);
obj_import(self, "PikaPiZero_RGB", New_PikaPiZero_RGB);
obj_import(self, "STM32_Time", New_STM32_Time);
obj_import(self, "STM32_UART", New_STM32_UART);
return self;
}

View File

@ -1,13 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaMain__H
#define __PikaMain__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaMain(Args *args);
#endif

View File

@ -1,51 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaPiZero_RGB.h"
#include "PikaStdLib_SysObj.h"
#include "STM32_GPIO.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaPiZero_RGB_blueMethod(PikaObj *self, Args *args){
PikaPiZero_RGB_blue(self);
}
void PikaPiZero_RGB_enableMethod(PikaObj *self, Args *args){
PikaPiZero_RGB_enable(self);
}
void PikaPiZero_RGB_flowMethod(PikaObj *self, Args *args){
PikaPiZero_RGB_flow(self);
}
void PikaPiZero_RGB_greenMethod(PikaObj *self, Args *args){
PikaPiZero_RGB_green(self);
}
void PikaPiZero_RGB_initMethod(PikaObj *self, Args *args){
PikaPiZero_RGB_init(self);
}
void PikaPiZero_RGB_redMethod(PikaObj *self, Args *args){
PikaPiZero_RGB_red(self);
}
void PikaPiZero_RGB_whiteMethod(PikaObj *self, Args *args){
PikaPiZero_RGB_white(self);
}
PikaObj *New_PikaPiZero_RGB(Args *args){
PikaObj *self = New_PikaStdLib_SysObj(args);
obj_import(self, "STM32_GPIO", New_STM32_GPIO);
obj_newObj(self, "pin", "STM32_GPIO");
class_defineMethod(self, "blue()", PikaPiZero_RGB_blueMethod);
class_defineMethod(self, "enable()", PikaPiZero_RGB_enableMethod);
class_defineMethod(self, "flow()", PikaPiZero_RGB_flowMethod);
class_defineMethod(self, "green()", PikaPiZero_RGB_greenMethod);
class_defineMethod(self, "init()", PikaPiZero_RGB_initMethod);
class_defineMethod(self, "red()", PikaPiZero_RGB_redMethod);
class_defineMethod(self, "white()", PikaPiZero_RGB_whiteMethod);
return self;
}

View File

@ -1,20 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaPiZero_RGB__H
#define __PikaPiZero_RGB__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaPiZero_RGB(Args *args);
void PikaPiZero_RGB_blue(PikaObj *self);
void PikaPiZero_RGB_enable(PikaObj *self);
void PikaPiZero_RGB_flow(PikaObj *self);
void PikaPiZero_RGB_green(PikaObj *self);
void PikaPiZero_RGB_init(PikaObj *self);
void PikaPiZero_RGB_red(PikaObj *self);
void PikaPiZero_RGB_white(PikaObj *self);
#endif

View File

@ -1,48 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaStdDevice_ADC.h"
#include "TinyObj.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaStdDevice_ADC_enableMethod(PikaObj *self, Args *args){
PikaStdDevice_ADC_enable(self);
}
void PikaStdDevice_ADC_initMethod(PikaObj *self, Args *args){
PikaStdDevice_ADC_init(self);
}
void PikaStdDevice_ADC_platformEnableMethod(PikaObj *self, Args *args){
char * pin = args_getStr(args, "pin");
PikaStdDevice_ADC_platformEnable(self, pin);
}
void PikaStdDevice_ADC_platformReadMethod(PikaObj *self, Args *args){
char * pin = args_getStr(args, "pin");
float res = PikaStdDevice_ADC_platformRead(self, pin);
method_returnFloat(args, res);
}
void PikaStdDevice_ADC_readMethod(PikaObj *self, Args *args){
float res = PikaStdDevice_ADC_read(self);
method_returnFloat(args, res);
}
void PikaStdDevice_ADC_setPinMethod(PikaObj *self, Args *args){
char * pin = args_getStr(args, "pin");
PikaStdDevice_ADC_setPin(self, pin);
}
PikaObj *New_PikaStdDevice_ADC(Args *args){
PikaObj *self = New_TinyObj(args);
class_defineMethod(self, "enable()", PikaStdDevice_ADC_enableMethod);
class_defineMethod(self, "init()", PikaStdDevice_ADC_initMethod);
class_defineMethod(self, "platformEnable(pin:str)", PikaStdDevice_ADC_platformEnableMethod);
class_defineMethod(self, "platformRead(pin:str)->float", PikaStdDevice_ADC_platformReadMethod);
class_defineMethod(self, "read()->float", PikaStdDevice_ADC_readMethod);
class_defineMethod(self, "setPin(pin:str)", PikaStdDevice_ADC_setPinMethod);
return self;
}

View File

@ -1,19 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaStdDevice_ADC__H
#define __PikaStdDevice_ADC__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaStdDevice_ADC(Args *args);
void PikaStdDevice_ADC_enable(PikaObj *self);
void PikaStdDevice_ADC_init(PikaObj *self);
void PikaStdDevice_ADC_platformEnable(PikaObj *self, char * pin);
float PikaStdDevice_ADC_platformRead(PikaObj *self, char * pin);
float PikaStdDevice_ADC_read(PikaObj *self);
void PikaStdDevice_ADC_setPin(PikaObj *self, char * pin);
#endif

View File

@ -1,88 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaStdDevice_GPIO.h"
#include "TinyObj.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaStdDevice_GPIO_disableMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_disable(self);
}
void PikaStdDevice_GPIO_enableMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_enable(self);
}
void PikaStdDevice_GPIO_getModeMethod(PikaObj *self, Args *args){
char * res = PikaStdDevice_GPIO_getMode(self);
method_returnStr(args, res);
}
void PikaStdDevice_GPIO_getPinMethod(PikaObj *self, Args *args){
char * res = PikaStdDevice_GPIO_getPin(self);
method_returnStr(args, res);
}
void PikaStdDevice_GPIO_highMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_high(self);
}
void PikaStdDevice_GPIO_initMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_init(self);
}
void PikaStdDevice_GPIO_lowMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_low(self);
}
void PikaStdDevice_GPIO_platformDisableMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_platformDisable(self);
}
void PikaStdDevice_GPIO_platformEnableMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_platformEnable(self);
}
void PikaStdDevice_GPIO_platformHighMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_platformHigh(self);
}
void PikaStdDevice_GPIO_platformLowMethod(PikaObj *self, Args *args){
PikaStdDevice_GPIO_platformLow(self);
}
void PikaStdDevice_GPIO_platformSetModeMethod(PikaObj *self, Args *args){
char * mode = args_getStr(args, "mode");
PikaStdDevice_GPIO_platformSetMode(self, mode);
}
void PikaStdDevice_GPIO_setModeMethod(PikaObj *self, Args *args){
char * mode = args_getStr(args, "mode");
PikaStdDevice_GPIO_setMode(self, mode);
}
void PikaStdDevice_GPIO_setPinMethod(PikaObj *self, Args *args){
char * pinName = args_getStr(args, "pinName");
PikaStdDevice_GPIO_setPin(self, pinName);
}
PikaObj *New_PikaStdDevice_GPIO(Args *args){
PikaObj *self = New_TinyObj(args);
class_defineMethod(self, "disable()", PikaStdDevice_GPIO_disableMethod);
class_defineMethod(self, "enable()", PikaStdDevice_GPIO_enableMethod);
class_defineMethod(self, "getMode()->str", PikaStdDevice_GPIO_getModeMethod);
class_defineMethod(self, "getPin()->str", PikaStdDevice_GPIO_getPinMethod);
class_defineMethod(self, "high()", PikaStdDevice_GPIO_highMethod);
class_defineMethod(self, "init()", PikaStdDevice_GPIO_initMethod);
class_defineMethod(self, "low()", PikaStdDevice_GPIO_lowMethod);
class_defineMethod(self, "platformDisable()", PikaStdDevice_GPIO_platformDisableMethod);
class_defineMethod(self, "platformEnable()", PikaStdDevice_GPIO_platformEnableMethod);
class_defineMethod(self, "platformHigh()", PikaStdDevice_GPIO_platformHighMethod);
class_defineMethod(self, "platformLow()", PikaStdDevice_GPIO_platformLowMethod);
class_defineMethod(self, "platformSetMode(mode:str)", PikaStdDevice_GPIO_platformSetModeMethod);
class_defineMethod(self, "setMode(mode:str)", PikaStdDevice_GPIO_setModeMethod);
class_defineMethod(self, "setPin(pinName:str)", PikaStdDevice_GPIO_setPinMethod);
return self;
}

View File

@ -1,27 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaStdDevice_GPIO__H
#define __PikaStdDevice_GPIO__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaStdDevice_GPIO(Args *args);
void PikaStdDevice_GPIO_disable(PikaObj *self);
void PikaStdDevice_GPIO_enable(PikaObj *self);
char * PikaStdDevice_GPIO_getMode(PikaObj *self);
char * PikaStdDevice_GPIO_getPin(PikaObj *self);
void PikaStdDevice_GPIO_high(PikaObj *self);
void PikaStdDevice_GPIO_init(PikaObj *self);
void PikaStdDevice_GPIO_low(PikaObj *self);
void PikaStdDevice_GPIO_platformDisable(PikaObj *self);
void PikaStdDevice_GPIO_platformEnable(PikaObj *self);
void PikaStdDevice_GPIO_platformHigh(PikaObj *self);
void PikaStdDevice_GPIO_platformLow(PikaObj *self);
void PikaStdDevice_GPIO_platformSetMode(PikaObj *self, char * mode);
void PikaStdDevice_GPIO_setMode(PikaObj *self, char * mode);
void PikaStdDevice_GPIO_setPin(PikaObj *self, char * pinName);
#endif

View File

@ -1,75 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaStdDevice_PWM.h"
#include "TinyObj.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaStdDevice_PWM_enableMethod(PikaObj *self, Args *args){
PikaStdDevice_PWM_enable(self);
}
void PikaStdDevice_PWM_getDutyMethod(PikaObj *self, Args *args){
float res = PikaStdDevice_PWM_getDuty(self);
method_returnFloat(args, res);
}
void PikaStdDevice_PWM_getFrequencyMethod(PikaObj *self, Args *args){
int res = PikaStdDevice_PWM_getFrequency(self);
method_returnInt(args, res);
}
void PikaStdDevice_PWM_initMethod(PikaObj *self, Args *args){
PikaStdDevice_PWM_init(self);
}
void PikaStdDevice_PWM_platformEnableMethod(PikaObj *self, Args *args){
float duty = args_getFloat(args, "duty");
int freq = args_getInt(args, "freq");
char * pin = args_getStr(args, "pin");
PikaStdDevice_PWM_platformEnable(self, duty, freq, pin);
}
void PikaStdDevice_PWM_platformSetDutyMethod(PikaObj *self, Args *args){
float duty = args_getFloat(args, "duty");
char * pin = args_getStr(args, "pin");
PikaStdDevice_PWM_platformSetDuty(self, duty, pin);
}
void PikaStdDevice_PWM_platformSetFrequencyMethod(PikaObj *self, Args *args){
int freq = args_getInt(args, "freq");
char * pin = args_getStr(args, "pin");
PikaStdDevice_PWM_platformSetFrequency(self, freq, pin);
}
void PikaStdDevice_PWM_setDutyMethod(PikaObj *self, Args *args){
float duty = args_getFloat(args, "duty");
PikaStdDevice_PWM_setDuty(self, duty);
}
void PikaStdDevice_PWM_setFrequencyMethod(PikaObj *self, Args *args){
int freq = args_getInt(args, "freq");
PikaStdDevice_PWM_setFrequency(self, freq);
}
void PikaStdDevice_PWM_setPinMethod(PikaObj *self, Args *args){
char * pin = args_getStr(args, "pin");
PikaStdDevice_PWM_setPin(self, pin);
}
PikaObj *New_PikaStdDevice_PWM(Args *args){
PikaObj *self = New_TinyObj(args);
class_defineMethod(self, "enable()", PikaStdDevice_PWM_enableMethod);
class_defineMethod(self, "getDuty()->float", PikaStdDevice_PWM_getDutyMethod);
class_defineMethod(self, "getFrequency()->int", PikaStdDevice_PWM_getFrequencyMethod);
class_defineMethod(self, "init()", PikaStdDevice_PWM_initMethod);
class_defineMethod(self, "platformEnable(pin:str,freq:int,duty:float)", PikaStdDevice_PWM_platformEnableMethod);
class_defineMethod(self, "platformSetDuty(pin:str,duty:float)", PikaStdDevice_PWM_platformSetDutyMethod);
class_defineMethod(self, "platformSetFrequency(pin:str,freq:int)", PikaStdDevice_PWM_platformSetFrequencyMethod);
class_defineMethod(self, "setDuty(duty:float)", PikaStdDevice_PWM_setDutyMethod);
class_defineMethod(self, "setFrequency(freq:int)", PikaStdDevice_PWM_setFrequencyMethod);
class_defineMethod(self, "setPin(pin:str)", PikaStdDevice_PWM_setPinMethod);
return self;
}

View File

@ -1,23 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaStdDevice_PWM__H
#define __PikaStdDevice_PWM__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaStdDevice_PWM(Args *args);
void PikaStdDevice_PWM_enable(PikaObj *self);
float PikaStdDevice_PWM_getDuty(PikaObj *self);
int PikaStdDevice_PWM_getFrequency(PikaObj *self);
void PikaStdDevice_PWM_init(PikaObj *self);
void PikaStdDevice_PWM_platformEnable(PikaObj *self, float duty, int freq, char * pin);
void PikaStdDevice_PWM_platformSetDuty(PikaObj *self, float duty, char * pin);
void PikaStdDevice_PWM_platformSetFrequency(PikaObj *self, int freq, char * pin);
void PikaStdDevice_PWM_setDuty(PikaObj *self, float duty);
void PikaStdDevice_PWM_setFrequency(PikaObj *self, int freq);
void PikaStdDevice_PWM_setPin(PikaObj *self, char * pin);
#endif

View File

@ -1,25 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaStdDevice_Time.h"
#include "TinyObj.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaStdDevice_Time_sleep_msMethod(PikaObj *self, Args *args){
int ms = args_getInt(args, "ms");
PikaStdDevice_Time_sleep_ms(self, ms);
}
void PikaStdDevice_Time_sleep_sMethod(PikaObj *self, Args *args){
int s = args_getInt(args, "s");
PikaStdDevice_Time_sleep_s(self, s);
}
PikaObj *New_PikaStdDevice_Time(Args *args){
PikaObj *self = New_TinyObj(args);
class_defineMethod(self, "sleep_ms(ms:int)", PikaStdDevice_Time_sleep_msMethod);
class_defineMethod(self, "sleep_s(s:int)", PikaStdDevice_Time_sleep_sMethod);
return self;
}

View File

@ -1,15 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaStdDevice_Time__H
#define __PikaStdDevice_Time__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaStdDevice_Time(Args *args);
void PikaStdDevice_Time_sleep_ms(PikaObj *self, int ms);
void PikaStdDevice_Time_sleep_s(PikaObj *self, int s);
#endif

View File

@ -1,70 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaStdDevice_UART.h"
#include "TinyObj.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaStdDevice_UART_enableMethod(PikaObj *self, Args *args){
PikaStdDevice_UART_enable(self);
}
void PikaStdDevice_UART_initMethod(PikaObj *self, Args *args){
PikaStdDevice_UART_init(self);
}
void PikaStdDevice_UART_platformEnableMethod(PikaObj *self, Args *args){
int baudRate = args_getInt(args, "baudRate");
int id = args_getInt(args, "id");
PikaStdDevice_UART_platformEnable(self, baudRate, id);
}
void PikaStdDevice_UART_platformReadMethod(PikaObj *self, Args *args){
int id = args_getInt(args, "id");
int length = args_getInt(args, "length");
char * res = PikaStdDevice_UART_platformRead(self, id, length);
method_returnStr(args, res);
}
void PikaStdDevice_UART_platformWriteMethod(PikaObj *self, Args *args){
char * data = args_getStr(args, "data");
int id = args_getInt(args, "id");
PikaStdDevice_UART_platformWrite(self, data, id);
}
void PikaStdDevice_UART_readMethod(PikaObj *self, Args *args){
int length = args_getInt(args, "length");
char * res = PikaStdDevice_UART_read(self, length);
method_returnStr(args, res);
}
void PikaStdDevice_UART_setBaudRateMethod(PikaObj *self, Args *args){
int baudRate = args_getInt(args, "baudRate");
PikaStdDevice_UART_setBaudRate(self, baudRate);
}
void PikaStdDevice_UART_setIdMethod(PikaObj *self, Args *args){
int id = args_getInt(args, "id");
PikaStdDevice_UART_setId(self, id);
}
void PikaStdDevice_UART_writeMethod(PikaObj *self, Args *args){
char * data = args_getStr(args, "data");
PikaStdDevice_UART_write(self, data);
}
PikaObj *New_PikaStdDevice_UART(Args *args){
PikaObj *self = New_TinyObj(args);
class_defineMethod(self, "enable()", PikaStdDevice_UART_enableMethod);
class_defineMethod(self, "init()", PikaStdDevice_UART_initMethod);
class_defineMethod(self, "platformEnable(id:int,baudRate:int)", PikaStdDevice_UART_platformEnableMethod);
class_defineMethod(self, "platformRead(id:int,length:int)->str", PikaStdDevice_UART_platformReadMethod);
class_defineMethod(self, "platformWrite(id:int,data:str)", PikaStdDevice_UART_platformWriteMethod);
class_defineMethod(self, "read(length:int)->str", PikaStdDevice_UART_readMethod);
class_defineMethod(self, "setBaudRate(baudRate:int)", PikaStdDevice_UART_setBaudRateMethod);
class_defineMethod(self, "setId(id:int)", PikaStdDevice_UART_setIdMethod);
class_defineMethod(self, "write(data:str)", PikaStdDevice_UART_writeMethod);
return self;
}

View File

@ -1,22 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaStdDevice_UART__H
#define __PikaStdDevice_UART__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaStdDevice_UART(Args *args);
void PikaStdDevice_UART_enable(PikaObj *self);
void PikaStdDevice_UART_init(PikaObj *self);
void PikaStdDevice_UART_platformEnable(PikaObj *self, int baudRate, int id);
char * PikaStdDevice_UART_platformRead(PikaObj *self, int id, int length);
void PikaStdDevice_UART_platformWrite(PikaObj *self, char * data, int id);
char * PikaStdDevice_UART_read(PikaObj *self, int length);
void PikaStdDevice_UART_setBaudRate(PikaObj *self, int baudRate);
void PikaStdDevice_UART_setId(PikaObj *self, int id);
void PikaStdDevice_UART_write(PikaObj *self, char * data);
#endif

View File

@ -1,28 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaStdLib_MemChecker.h"
#include "BaseObj.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaStdLib_MemChecker_maxMethod(PikaObj *self, Args *args){
PikaStdLib_MemChecker_max(self);
}
void PikaStdLib_MemChecker_nowMethod(PikaObj *self, Args *args){
PikaStdLib_MemChecker_now(self);
}
void PikaStdLib_MemChecker_resetMaxMethod(PikaObj *self, Args *args){
PikaStdLib_MemChecker_resetMax(self);
}
PikaObj *New_PikaStdLib_MemChecker(Args *args){
PikaObj *self = New_BaseObj(args);
class_defineMethod(self, "max()", PikaStdLib_MemChecker_maxMethod);
class_defineMethod(self, "now()", PikaStdLib_MemChecker_nowMethod);
class_defineMethod(self, "resetMax()", PikaStdLib_MemChecker_resetMaxMethod);
return self;
}

View File

@ -1,16 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaStdLib_MemChecker__H
#define __PikaStdLib_MemChecker__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaStdLib_MemChecker(Args *args);
void PikaStdLib_MemChecker_max(PikaObj *self);
void PikaStdLib_MemChecker_now(PikaObj *self);
void PikaStdLib_MemChecker_resetMax(PikaObj *self);
#endif

View File

@ -1,38 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaStdLib_SysObj.h"
#include "BaseObj.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void PikaStdLib_SysObj_lsMethod(PikaObj *self, Args *args){
char * objPath = args_getStr(args, "objPath");
PikaStdLib_SysObj_ls(self, objPath);
}
void PikaStdLib_SysObj_newMethod(PikaObj *self, Args *args){
char * classPath = args_getStr(args, "classPath");
char * objPath = args_getStr(args, "objPath");
PikaStdLib_SysObj_new(self, classPath, objPath);
}
void PikaStdLib_SysObj_removeMethod(PikaObj *self, Args *args){
char * argPath = args_getStr(args, "argPath");
PikaStdLib_SysObj_remove(self, argPath);
}
void PikaStdLib_SysObj_typeMethod(PikaObj *self, Args *args){
char * argPath = args_getStr(args, "argPath");
PikaStdLib_SysObj_type(self, argPath);
}
PikaObj *New_PikaStdLib_SysObj(Args *args){
PikaObj *self = New_BaseObj(args);
class_defineMethod(self, "ls(objPath:str)", PikaStdLib_SysObj_lsMethod);
class_defineMethod(self, "new(objPath:str,classPath:str)", PikaStdLib_SysObj_newMethod);
class_defineMethod(self, "remove(argPath:str)", PikaStdLib_SysObj_removeMethod);
class_defineMethod(self, "type(argPath:str)", PikaStdLib_SysObj_typeMethod);
return self;
}

View File

@ -1,17 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __PikaStdLib_SysObj__H
#define __PikaStdLib_SysObj__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_PikaStdLib_SysObj(Args *args);
void PikaStdLib_SysObj_ls(PikaObj *self, char * objPath);
void PikaStdLib_SysObj_new(PikaObj *self, char * classPath, char * objPath);
void PikaStdLib_SysObj_remove(PikaObj *self, char * argPath);
void PikaStdLib_SysObj_type(PikaObj *self, char * argPath);
#endif

View File

@ -1,26 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "STM32_ADC.h"
#include "PikaStdDevice_ADC.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void STM32_ADC_platformEnableMethod(PikaObj *self, Args *args){
char * pin = args_getStr(args, "pin");
STM32_ADC_platformEnable(self, pin);
}
void STM32_ADC_platformReadMethod(PikaObj *self, Args *args){
char * pin = args_getStr(args, "pin");
float res = STM32_ADC_platformRead(self, pin);
method_returnFloat(args, res);
}
PikaObj *New_STM32_ADC(Args *args){
PikaObj *self = New_PikaStdDevice_ADC(args);
class_defineMethod(self, "platformEnable(pin:str)", STM32_ADC_platformEnableMethod);
class_defineMethod(self, "platformRead(pin:str)->float", STM32_ADC_platformReadMethod);
return self;
}

View File

@ -1,15 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __STM32_ADC__H
#define __STM32_ADC__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_STM32_ADC(Args *args);
void STM32_ADC_platformEnable(PikaObj *self, char * pin);
float STM32_ADC_platformRead(PikaObj *self, char * pin);
#endif

View File

@ -1,39 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "STM32_GPIO.h"
#include "PikaStdDevice_GPIO.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void STM32_GPIO_platformDisableMethod(PikaObj *self, Args *args){
STM32_GPIO_platformDisable(self);
}
void STM32_GPIO_platformEnableMethod(PikaObj *self, Args *args){
STM32_GPIO_platformEnable(self);
}
void STM32_GPIO_platformHighMethod(PikaObj *self, Args *args){
STM32_GPIO_platformHigh(self);
}
void STM32_GPIO_platformLowMethod(PikaObj *self, Args *args){
STM32_GPIO_platformLow(self);
}
void STM32_GPIO_platformSetModeMethod(PikaObj *self, Args *args){
char * mode = args_getStr(args, "mode");
STM32_GPIO_platformSetMode(self, mode);
}
PikaObj *New_STM32_GPIO(Args *args){
PikaObj *self = New_PikaStdDevice_GPIO(args);
class_defineMethod(self, "platformDisable()", STM32_GPIO_platformDisableMethod);
class_defineMethod(self, "platformEnable()", STM32_GPIO_platformEnableMethod);
class_defineMethod(self, "platformHigh()", STM32_GPIO_platformHighMethod);
class_defineMethod(self, "platformLow()", STM32_GPIO_platformLowMethod);
class_defineMethod(self, "platformSetMode(mode:str)", STM32_GPIO_platformSetModeMethod);
return self;
}

View File

@ -1,18 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __STM32_GPIO__H
#define __STM32_GPIO__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_STM32_GPIO(Args *args);
void STM32_GPIO_platformDisable(PikaObj *self);
void STM32_GPIO_platformEnable(PikaObj *self);
void STM32_GPIO_platformHigh(PikaObj *self);
void STM32_GPIO_platformLow(PikaObj *self);
void STM32_GPIO_platformSetMode(PikaObj *self, char * mode);
#endif

View File

@ -1,35 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "STM32_PWM.h"
#include "PikaStdDevice_PWM.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void STM32_PWM_platformEnableMethod(PikaObj *self, Args *args){
float duty = args_getFloat(args, "duty");
int freq = args_getInt(args, "freq");
char * pin = args_getStr(args, "pin");
STM32_PWM_platformEnable(self, duty, freq, pin);
}
void STM32_PWM_platformSetDutyMethod(PikaObj *self, Args *args){
float duty = args_getFloat(args, "duty");
char * pin = args_getStr(args, "pin");
STM32_PWM_platformSetDuty(self, duty, pin);
}
void STM32_PWM_platformSetFrequencyMethod(PikaObj *self, Args *args){
int freq = args_getInt(args, "freq");
char * pin = args_getStr(args, "pin");
STM32_PWM_platformSetFrequency(self, freq, pin);
}
PikaObj *New_STM32_PWM(Args *args){
PikaObj *self = New_PikaStdDevice_PWM(args);
class_defineMethod(self, "platformEnable(pin:str,freq:int,duty:float)", STM32_PWM_platformEnableMethod);
class_defineMethod(self, "platformSetDuty(pin:str,duty:float)", STM32_PWM_platformSetDutyMethod);
class_defineMethod(self, "platformSetFrequency(pin:str,freq:int)", STM32_PWM_platformSetFrequencyMethod);
return self;
}

View File

@ -1,16 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __STM32_PWM__H
#define __STM32_PWM__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_STM32_PWM(Args *args);
void STM32_PWM_platformEnable(PikaObj *self, float duty, int freq, char * pin);
void STM32_PWM_platformSetDuty(PikaObj *self, float duty, char * pin);
void STM32_PWM_platformSetFrequency(PikaObj *self, int freq, char * pin);
#endif

View File

@ -1,25 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "STM32_Time.h"
#include "PikaStdDevice_Time.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void STM32_Time_sleep_msMethod(PikaObj *self, Args *args){
int ms = args_getInt(args, "ms");
STM32_Time_sleep_ms(self, ms);
}
void STM32_Time_sleep_sMethod(PikaObj *self, Args *args){
int s = args_getInt(args, "s");
STM32_Time_sleep_s(self, s);
}
PikaObj *New_STM32_Time(Args *args){
PikaObj *self = New_PikaStdDevice_Time(args);
class_defineMethod(self, "sleep_ms(ms:int)", STM32_Time_sleep_msMethod);
class_defineMethod(self, "sleep_s(s:int)", STM32_Time_sleep_sMethod);
return self;
}

View File

@ -1,15 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __STM32_Time__H
#define __STM32_Time__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_STM32_Time(Args *args);
void STM32_Time_sleep_ms(PikaObj *self, int ms);
void STM32_Time_sleep_s(PikaObj *self, int s);
#endif

View File

@ -1,35 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "STM32_UART.h"
#include "PikaStdDevice_UART.h"
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
void STM32_UART_platformEnableMethod(PikaObj *self, Args *args){
int baudRate = args_getInt(args, "baudRate");
int id = args_getInt(args, "id");
STM32_UART_platformEnable(self, baudRate, id);
}
void STM32_UART_platformReadMethod(PikaObj *self, Args *args){
int id = args_getInt(args, "id");
int length = args_getInt(args, "length");
char * res = STM32_UART_platformRead(self, id, length);
method_returnStr(args, res);
}
void STM32_UART_platformWriteMethod(PikaObj *self, Args *args){
char * data = args_getStr(args, "data");
int id = args_getInt(args, "id");
STM32_UART_platformWrite(self, data, id);
}
PikaObj *New_STM32_UART(Args *args){
PikaObj *self = New_PikaStdDevice_UART(args);
class_defineMethod(self, "platformEnable(id:int,baudRate:int)", STM32_UART_platformEnableMethod);
class_defineMethod(self, "platformRead(id:int,length:int)->str", STM32_UART_platformReadMethod);
class_defineMethod(self, "platformWrite(id:int,data:str)", STM32_UART_platformWriteMethod);
return self;
}

View File

@ -1,16 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#ifndef __STM32_UART__H
#define __STM32_UART__H
#include <stdio.h>
#include <stdlib.h>
#include "PikaObj.h"
PikaObj *New_STM32_UART(Args *args);
void STM32_UART_platformEnable(PikaObj *self, int baudRate, int id);
char * STM32_UART_platformRead(PikaObj *self, int id, int length);
void STM32_UART_platformWrite(PikaObj *self, char * data, int id);
#endif

File diff suppressed because one or more lines are too long

View File

@ -1,34 +0,0 @@
/* ******************************** */
/* Warning! Don't modify this file! */
/* ******************************** */
#include "PikaMain.h"
#include <stdio.h>
#include <stdlib.h>
PikaObj * pikaScriptInit(){
PikaObj * pikaMain = newRootObj("pikaMain", New_PikaMain);
obj_run(pikaMain, "time = STM32.Time()");
obj_run(pikaMain, "uart = STM32.UART()");
obj_run(pikaMain, "adc = STM32.ADC()");
obj_run(pikaMain, "pin = STM32.GPIO()");
obj_run(pikaMain, "pwm = STM32.PWM()");
obj_run(pikaMain, "uart = STM32.UART()");
obj_run(pikaMain, "rgb = PikaPiZero.RGB()");
obj_run(pikaMain, "mem = PikaStdLib.MemChecker()");
obj_run(pikaMain, "uart.init()");
obj_run(pikaMain, "uart.setId(1)");
obj_run(pikaMain, "uart.setBaudRate(115200)");
obj_run(pikaMain, "uart.enable()");
obj_run(pikaMain, "rgb.init()");
obj_run(pikaMain, "rgb.enable()");
obj_run(pikaMain, "print('hello 2')");
obj_run(pikaMain, "print('mem used max:')");
obj_run(pikaMain, "mem.max()");
obj_run(pikaMain, "while True:");
obj_run(pikaMain, " time.sleep_ms(10)");
obj_run(pikaMain, " rgb.flow()");
obj_run(pikaMain, " print('flowing...')");
obj_run(pikaMain, "");
return pikaMain;
}

View File

@ -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();
#endif

View File

@ -1,2 +0,0 @@
*kite*
*.o

View File

@ -1,160 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "BaseObj.h"
#include "PikaObj.h"
#include "TinyObj.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
static void* getClassPtr(PikaObj* classObj, char* classPath) {
char* ptrPath = classPath;
return obj_getPtr(classObj, ptrPath);
}
int32_t obj_newObjByFun(PikaObj* self,
char* objName,
char* className,
void* newFunPtr) {
/* class means subprocess init */
Args* buffs = New_strBuff();
/* class means subprocess init */
char* mataObjName = strsAppend(buffs, "[mate]", objName);
obj_setPtr(self, mataObjName, newFunPtr);
/* add void process Ptr, no inited */
args_setObjectWithClass(self->attributeList, objName, className, NULL);
args_deinit(buffs);
return 0;
}
int32_t sysObj_setObjbyClass(PikaObj* self, char* objName, char* classPath) {
/* class means subprocess init */
Args* buffs = New_strBuff();
PikaObj* classLoader = obj_getObj(self, "_clsld", 0);
void* newFunPtr = getClassPtr(classLoader, classPath);
/* class means subprocess init */
char* mataObjName = strsAppend(buffs, "[mate]", objName);
obj_setPtr(self, mataObjName, newFunPtr);
/* add void process Ptr, no inited */
args_setObjectWithClass(self->attributeList, objName, classPath, NULL);
args_deinit(buffs);
return 0;
}
static int32_t storeClassInfo(PikaObj* self,
Args* buffs,
char* classPath,
void* classPtr) {
int32_t res = 0;
PikaObj* classHost = obj_getObj(self, classPath, 1);
if (NULL == classHost) {
res = 1;
goto exit;
}
char* className = strsGetLastToken(buffs, classPath, '.');
char* classStoreName = className;
obj_setPtr(classHost, classStoreName, classPtr);
res = 0;
goto exit;
exit:
return res;
}
int32_t obj_import(PikaObj* self, char* className, NewFun classPtr) {
PikaObj* classLoader = obj_getObj(self, "_clsld", 0);
Args* buffs = New_args(NULL);
int32_t res = storeClassInfo(classLoader, buffs, className, classPtr);
args_deinit(buffs);
return res;
}
int32_t obj_newObj(PikaObj* self, char* objPath, char* classPath) {
PikaObj* classLoader = obj_getObj(self, "_clsld", 0);
Args* buffs = New_args(NULL);
int res = 0;
void* NewObjPtr = getClassPtr(classLoader, classPath);
if (NULL == NewObjPtr) {
res = 1;
goto exit;
}
PikaObj* objHost = obj_getObj(self, objPath, 1);
if (NULL == objHost) {
res = 2;
goto exit;
}
char* objName = strsGetLastToken(buffs, objPath, '.');
obj_newObjByFun(objHost, objName, classPath, NewObjPtr);
res = 0;
goto exit;
exit:
args_deinit(buffs);
return res;
}
static void print(PikaObj* self, Args* args) {
obj_setErrorCode(self, 0);
char* res = args_print(args, "val");
if (NULL == res) {
obj_setSysOut(self, "[error] print: can not print val");
obj_setErrorCode(self, 1);
return;
}
/* not empty */
obj_setSysOut(self, res);
}
static void set(PikaObj* self, Args* args) {
obj_setErrorCode(self, 0);
char* argPath = method_getStr(args, "argPath");
if (obj_isArgExist(self, argPath)) {
/* update arg */
char* valStr = args_print(args, "val");
int32_t res = obj_set(self, argPath, valStr);
if (1 == res) {
obj_setSysOut(self, "[error] set: arg no found.");
obj_setErrorCode(self, 1);
return;
}
if (2 == res) {
obj_setSysOut(self, "[error] set: type not match.");
obj_setErrorCode(self, 1);
return;
}
if (3 == res) {
obj_setSysOut(self, "[error] set: object not found.");
obj_setErrorCode(self, 1);
return;
}
return;
}
/* new arg */
Arg* val = args_getArg(args, "val");
Arg* newArg = arg_copy(val);
char* argName = strsGetLastToken(args, argPath, '.');
newArg = arg_setName(newArg, argName);
int32_t res = obj_setArg(self, argPath, newArg);
if (res == 1) {
obj_setSysOut(self, "[error] set: object not found.");
obj_setErrorCode(self, 1);
}
arg_deinit(newArg);
newArg = NULL;
return;
}
PikaObj* New_BaseObj(Args* args) {
PikaObj* self = New_TinyObj(args);
obj_setObjWithoutClass(self, "_clsld", New_TinyObj);
obj_getObj(self, "_clsld", 0);
class_defineMethod(self, "print(val:any)", print);
class_defineMethod(self, "set(argPath:str, val:any)", set);
return self;
}

View File

@ -1,19 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _PikaObj_baseObj__H
#define _PikaObj_baseObj__H
#include "PikaObj.h"
#include "TinyObj.h"
#include "dataMemory.h"
PikaObj* New_BaseObj(Args* args);
int32_t obj_newObj(PikaObj* self, char* objPath, char* classPath);
int32_t obj_import(PikaObj* self, char* className, NewFun classPtr);
int32_t obj_newObjByFun(PikaObj* self,
char* objName,
char* className,
void* newFunPtr);
#endif

View File

@ -1,88 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "PikaBlock.h"
#include <stdarg.h>
#include "PikaObj.h"
#include "TinyObj.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
void block_deinit(PikaObj* self) {
obj_deinit(self);
}
PikaObj* block_init(Args* args) {
PikaObj* self = New_TinyObj(args);
obj_setStr(self, "mode", "");
obj_setStr(self, "assert", "");
obj_setStr(self, "body", "");
obj_setInt(self, "lineSize", 0);
obj_setStr(self, "lineNow", "");
return self;
}
char* block_getBody(PikaObj* self) {
return obj_getStr(self, "body");
}
void block_setBody(PikaObj* self, char* body) {
obj_setStr(self, "body", body);
}
uint8_t block_checkAssert(PikaObj* self) {
Args* buffs = New_strBuff();
PikaObj* host = obj_getContext(self);
char* assert = block_getAssert(self);
obj_run(host, strsFormat(buffs, 32, "_res = %s", assert));
int res = obj_getInt(host, "_res");
obj_removeArg(host, "_res");
args_deinit(buffs);
return res;
}
uint16_t block_getLineSize(PikaObj* self) {
return obj_getInt(self, "lineSize");
}
void block_setAssert(PikaObj* self, char* assert) {
obj_setStr(self, "assert", assert);
}
char* block_getAssert(PikaObj* self) {
return obj_getStr(self, "assert");
}
void block_setMode(PikaObj* self, char* mode) {
obj_setStr(self, "mode", mode);
}
char* block_getMode(PikaObj* self) {
return obj_getStr(self, "mode");
}
void block_pushLine(PikaObj* self, char* line) {
Args* buffs = New_strBuff();
char* body = obj_getStr(self, "body");
body = strsAppend(buffs, body, line);
body = strsAppend(buffs, body, "\n");
obj_setStr(self, "body", body);
obj_setInt(self, "lineSize", obj_getInt(self, "lineSize") + 1);
args_deinit(buffs);
}
char* block_popLine(PikaObj* self) {
Args* buffs = New_strBuff();
char* body = obj_getStr(self, "body");
char* line = strsPopToken(buffs, body, '\n');
obj_setStr(self, "body", body);
obj_setStr(self, "lineNow", line);
obj_setInt(self, "lineSize", obj_getInt(self, "lineSize") - 1);
args_deinit(buffs);
return obj_getStr(self, "lineNow");
}

View File

@ -1,22 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _pikaBlock__H
#define _pikaBlock__H
#include "PikaObj.h"
void block_deinit(PikaObj* self);
PikaObj* block_init(Args* args);
char* block_popLine(PikaObj* self);
void block_pushLine(PikaObj* self, char* line);
char* block_getBody(PikaObj* self);
char* block_getAssert(PikaObj* self);
void block_setAssert(PikaObj* self, char* assert);
uint8_t block_checkAssert(PikaObj* self);
uint16_t block_getLineSize(PikaObj* self);
void block_setMode(PikaObj* self, char* mode);
char* block_getMode(PikaObj* self);
void block_setBody(PikaObj* self, char* body);
#endif

View File

@ -1,39 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "PikaIf.h"
#include <stdarg.h>
#include "PikaBlock.h"
#include "TinyObj.h"
#include "dataStrs.h"
void if_setAssert(PikaObj* self, char* line) {
Args* buffs = New_strBuff();
char* assert = strsRemovePrefix(buffs, line, "if ");
assert = strsGetFirstToken(buffs, assert, ':');
block_setAssert(self, assert);
block_setMode(self, "if");
args_deinit(buffs);
}
void if_pushLine(PikaObj* self, char* line) {
Args* buffs = New_strBuff();
char* bodyLine = strsRemovePrefix(buffs, line, " ");
block_pushLine(self, bodyLine);
goto exit;
exit:
args_deinit(buffs);
return;
}
void if_run(PikaObj* self) {
if (block_checkAssert(self)) {
PikaObj* host = obj_getContext(self);
while (0 != block_getLineSize(self)) {
char* line = block_popLine(self);
obj_run(host, line);
}
}
}

View File

@ -1,13 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _pikaIf__H
#define _pikaIf__H
#include "PikaObj.h"
void if_pushLine(PikaObj* self, char* line);
void if_setAssert(PikaObj* self, char* line);
void if_run(PikaObj* self);
#endif

View File

@ -1,296 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include <stdarg.h>
#include "PikaObj.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
static int32_t loadArgByType(PikaObj* self,
char* definedName,
char* definedType,
char* sourceArgPath,
Args* args) {
if (strEqu(definedType, "any")) {
if (0 == obj_getAnyArg(self, definedName, sourceArgPath, args)) {
return 0;
}
/* solve arg faild */
return 3;
}
if (strEqu(definedType, "str")) {
/* solve the string type */
char* directStr = strsGetDirectStr(args, sourceArgPath);
if (NULL != directStr) {
/* direct value */
args_setStr(args, definedName, directStr);
/* ok */
return 0;
}
/* reference value */
char* refStr = obj_getStr(self, sourceArgPath);
if (NULL == refStr) {
/* faild */
return 1;
}
args_setStr(args, definedName, refStr);
/* succeed */
return 0;
}
if (strEqu(definedType, "int")) {
/* solve the int32_t type */
args_setInt(args, definedName, 0);
if ((sourceArgPath[0] >= '0') && (sourceArgPath[0] <= '9')) {
/* direct value */
args_set(args, definedName, sourceArgPath);
/* succeed */
return 0;
}
/* reference value */
if (!obj_isArgExist(self, sourceArgPath)) {
/* can not get reference */
return 3;
}
int32_t referenceVal = obj_getInt(self, sourceArgPath);
args_setInt(args, definedName, referenceVal);
/* succeed */
return 0;
}
if (strEqu(definedType, "float")) {
/* solve the float type */
args_setFloat(args, definedName, 0);
if ((sourceArgPath[0] >= '0') && (sourceArgPath[0] <= '9')) {
/* direct value */
args_set(args, definedName, sourceArgPath);
/* succeed */
return 0;
}
/* reference value */
if (!obj_isArgExist(self, sourceArgPath)) {
/* can not get reference */
return 3;
}
float referenceVal = obj_getFloat(self, sourceArgPath);
args_setFloat(args, definedName, referenceVal);
/* succeed */
return 0;
}
if (strEqu(definedType, "pointer")) {
/* only support reference value */
if (!obj_isArgExist(self, sourceArgPath)) {
/* can not get reference */
return 3;
}
void* ptr = obj_getPtr(self, sourceArgPath);
args_setPtr(args, definedName, ptr);
return 0;
}
/* type match faild */
return 2;
}
char* getTypeVal(Args* buffs, char* typeToken) {
if (!strIsContain(typeToken, ':')) {
return strsCopy(buffs, "");
}
return strsGetLastToken(buffs, typeToken, ':');
}
static Args* getArgsByNameMatch(PikaObj* self, char* typeList, char* argList) {
Args* buffs = New_strBuff();
char* typeListBuff = strsCopy(buffs, typeList);
Args* args = New_args(NULL);
while (1) {
char* typeToken = strsPopToken(buffs, typeListBuff, ',');
/* poped all type from typeList */
if (0 == typeToken[0]) {
break;
}
char* typeName = strsGetFirstToken(buffs, typeToken, ':');
char* typeVal = getTypeVal(buffs, typeToken);
char* argListBuff = strsCopy(buffs, argList);
while (1) {
char* argToken = strsPopToken(buffs, argListBuff, ',');
char* argName = strsGetFirstToken(buffs, argToken, '=');
char* argVal = strsGetLastToken(buffs, argToken, '=');
if (0 == argToken[0]) {
/* arg poped finised */
break;
}
if (!strEqu(typeName, argName)) {
/* name not match */
continue;
}
if (0 != loadArgByType(self, typeName, typeVal, argVal, args)) {
args_deinit(args);
args_deinit(buffs);
return NULL;
}
}
}
args_deinit(buffs);
return args;
}
static Args* getArgsBySort(PikaObj* self, char* typeList, char* argList) {
Args* buffs = New_strBuff();
char* typeListBuff = strsCopy(buffs, typeList);
char* argListBuff = strsCopy(buffs, argList);
Args* args = New_args(NULL);
while (1) {
char* typeToken = strsPopToken(buffs, typeListBuff, ',');
char* argToken = strsPopToken(buffs, argListBuff, ',');
if ((0 == argToken[0]) || (0 == typeToken[0])) {
/* arg or type poped finised */
break;
}
char* typeName = strsGetFirstToken(buffs, typeToken, ':');
char* typeVal = getTypeVal(buffs, typeToken);
char* argPath = argToken;
if (0 != loadArgByType(self, typeName, typeVal, argPath, args)) {
args_deinit(args);
args_deinit(buffs);
return NULL;
}
}
args_deinit(buffs);
return args;
}
static Args* getArgsBySentence(PikaObj* self, char* typeList, char* argList) {
if (strIsContain(argList, '=')) {
return getArgsByNameMatch(self, typeList, argList);
}
return getArgsBySort(self, typeList, argList);
}
static char* getMethodDeclearation(PikaObj* obj, char* methodName) {
Args* buffs = New_strBuff();
char* methodDeclearationPath = strsAppend(buffs, "[md]", methodName);
char* res = obj_getStr(obj, methodDeclearationPath);
args_deinit(buffs);
return res;
}
static void* getMethodPtr(PikaObj* methodHost, char* methodName) {
Args* buffs = New_strBuff();
char* methodPtrPath = strsAppend(buffs, "[mp]", methodName);
void* res = obj_getPtr(methodHost, methodPtrPath);
args_deinit(buffs);
return res;
}
Args* obj_invoke(PikaObj* self, char* cmd) {
/* the Args returned need to be deinit */
Args* res = New_args(NULL);
args_setErrorCode(res, 0);
Args* buffs = New_strBuff();
char* methodToken = strsGetFirstToken(buffs, cmd, '(');
char* methodPath = methodToken;
Args* args = NULL;
PikaObj* methodHostObj = obj_getObj(self, methodPath, 1);
PikaObj* methodHostClass = NULL;
if (NULL == methodHostObj) {
/* error, not found object */
args_setErrorCode(res, 1);
args_setSysOut(res, "[error] runner: object no found.");
goto exit;
}
char* methodName = strsGetLastToken(buffs, methodPath, '.');
void* classPtr = obj_getPtr(methodHostObj, "_clsptr");
char* methodHostClassName =
strsAppend(buffs, "classObj-", obj_getName(methodHostObj));
methodHostClass =
obj_getClassObjByNewFun(methodHostObj, methodHostClassName, classPtr);
/* get method Ptr */
void (*methodPtr)(PikaObj * self, Args * args) =
getMethodPtr(methodHostClass, methodName);
char* methodDecInClass = getMethodDeclearation(methodHostClass, methodName);
/* assert method*/
if ((NULL == methodDecInClass) || (NULL == methodPtr)) {
/* error, method no found */
args_setErrorCode(res, 2);
args_setSysOut(res, "[error] runner: method no found.");
goto exit;
}
char* methodDec = strsCopy(buffs, methodDecInClass);
/* free method host class to save memory */
obj_deinit(methodHostClass);
methodHostClass = NULL;
/* get type list */
char* typeList = strsCut(buffs, methodDec, '(', ')');
if (typeList == NULL) {
/* typeList no found */
args_setErrorCode(res, 3);
args_setSysOut(res, "[error] runner: type list no found.");
goto exit;
}
/* get arg list */
char* argList = strsCut(buffs, cmd, '(', ')');
{
if (argList == NULL) {
/* argL List no found */
args_setErrorCode(res, 4);
args_setSysOut(res, "[error] runner: arg list no found.");
goto exit;
}
}
/* get return type */
char* returnType = strsGetLastToken(buffs, methodDec, ')');
/* get args */
args = getArgsBySentence(self, typeList, argList);
if (NULL == args) {
/* get args faild */
args_setErrorCode(res, 5);
args_setSysOut(res, "[error] runner: solve arg faild.");
goto exit;
}
obj_setErrorCode(methodHostObj, 0);
obj_setSysOut(methodHostObj, "");
/* run method */
methodPtr(methodHostObj, args);
/* transfer return type */
args_setStr(res, "returnType", returnType);
/* transfer return */
args_copyArgByName(args, "return", res);
/* transfer sysOut */
char* sysOut = obj_getSysOut(methodHostObj);
if (NULL != sysOut) {
args_setSysOut(res, sysOut);
}
/* transfer errCode */
if (0 != obj_getErrorCode(methodHostObj)) {
/* method error */
args_setErrorCode(res, 6);
}
goto exit;
exit:
if (NULL != buffs) {
args_deinit(buffs);
}
if (NULL != methodHostClass) {
obj_deinit(methodHostClass);
}
if (NULL != args) {
args_deinit(args);
}
return res;
}

View File

@ -1,9 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _invoke__H
#define _invoke__H
Args* obj_invoke(PikaObj* self, char* cmd);
#endif

View File

@ -1,783 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "PikaObj.h"
#include <stdarg.h>
#include "BaseObj.h"
#include "PikaBlock.h"
#include "PikaIf.h"
#include "PikaInvoke.h"
#include "PikaWhile.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
PikaObj* obj_getContext(PikaObj* self) {
return obj_getPtr(self, "_ctx");
}
void* getNewObjFunByClass(PikaObj* obj, char* classPath) {
PikaObj* classLoader = args_getPtr(obj->attributeList, "_clsld");
if (NULL == classLoader) {
return NULL;
}
void* (*newObjFun)(Args * initArgs) =
args_getPtr(classLoader->attributeList, classPath);
return newObjFun;
}
int32_t deinitEachSubObj(Arg* argEach, Args* handleArgs) {
if (NULL != handleArgs) {
/* error: tOhis handle not need handle args */
return 1;
}
char* type = arg_getType(argEach);
if (strIsStartWith(type, "_class")) {
PikaObj* subObj = arg_getPtr(argEach);
if (NULL != subObj) {
obj_deinit(subObj);
}
}
return 0;
}
void deinitAllSubObj(PikaObj* self) {
Args* args = self->attributeList;
args_foreach(args, deinitEachSubObj, NULL);
}
int32_t obj_deinit(PikaObj* self) {
deinitAllSubObj(self);
args_deinit(self->attributeList);
// DynMemPut(self->mem);
pikaFree(self, sizeof(PikaObj));
self = NULL;
return 0;
}
int32_t obj_enable(PikaObj* self) {
obj_setInt(self, "isEnable", 1);
return 0;
}
int32_t obj_disable(PikaObj* self) {
obj_setInt(self, "isEnable", 0);
return 0;
}
int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
/* [error] object no found */
return 1;
}
Args* buffs = New_strBuff();
char* name = strsGetLastToken(buffs, argPath, '.');
args_setInt(obj->attributeList, name, val);
args_deinit(buffs);
return 0;
}
int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return 1;
}
Args* buffs = New_strBuff();
char* name = strsGetLastToken(buffs, argPath, '.');
args_setPtr(obj->attributeList, name, pointer);
args_deinit(buffs);
return 0;
}
int32_t obj_setFloat(PikaObj* self, char* argPath, float value) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return 1;
}
Args* buffs = New_strBuff();
char* name = strsGetLastToken(buffs, argPath, '.');
args_setFloat(obj->attributeList, name, value);
args_deinit(buffs);
return 0;
}
int32_t obj_setStr(PikaObj* self, char* argPath, char* str) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return 1;
}
Args* buffs = New_strBuff();
char* name = strsGetLastToken(buffs, argPath, '.');
args_setStr(obj->attributeList, name, str);
args_deinit(buffs);
return 0;
}
int64_t obj_getInt(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return -999999999;
}
Args* buffs = New_strBuff();
char* argName = strsGetLastToken(buffs, argPath, '.');
int res = args_getInt(obj->attributeList, argName);
args_deinit(buffs);
return res;
}
Arg* obj_getArg(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return NULL;
}
Args* buffs = New_strBuff();
char* argName = strsGetLastToken(buffs, argPath, '.');
Arg* res = args_getArg(obj->attributeList, argName);
args_deinit(buffs);
return res;
}
int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg) {
/* setArg would copy arg */
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
/* object no found */
return 1;
}
args_copyArg(obj->attributeList, arg);
return 0;
}
void* obj_getPtr(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return NULL;
}
Args* buffs = New_strBuff();
char* argName = strsGetLastToken(buffs, argPath, '.');
void* res = args_getPtr(obj->attributeList, argName);
args_deinit(buffs);
return res;
}
float obj_getFloat(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return -999.999;
}
Args* buffs = New_strBuff();
char* argName = strsGetLastToken(buffs, argPath, '.');
float res = args_getFloat(obj->attributeList, argName);
args_deinit(buffs);
return res;
}
char* obj_getStr(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
return NULL;
}
Args* buffs = New_strBuff();
char* argName = strsGetLastToken(buffs, argPath, '.');
char* res = args_getStr(obj->attributeList, argName);
args_deinit(buffs);
return res;
}
int32_t obj_load(PikaObj* self, Args* args, char* name) {
args_copyArgByName(args, name, self->attributeList);
return 0;
}
int32_t obj_setObjWithoutClass(PikaObj* self, char* objName, void* newFun) {
/* class means subprocess init */
Args* buffs = New_strBuff();
char* mataObjName = strsAppend(buffs, "[mate]", objName);
obj_setPtr(self, mataObjName, newFun);
/* add void object Ptr, no inited */
args_setObjectWithClass(self->attributeList, objName, "none", NULL);
args_deinit(buffs);
return 0;
}
int32_t obj_addOther(PikaObj* self, char* subObjectName, void* new_ObjectFun) {
Args* initArgs = New_args(NULL);
args_setPtr(initArgs, "_ctx", self);
void* (*new_Object)(Args * initArgs) = (void* (*)(Args*))new_ObjectFun;
void* subObject = new_Object(initArgs);
obj_setPtr(self, subObjectName, subObject);
args_deinit(initArgs);
return 0;
}
int32_t obj_freeObj(PikaObj* self, char* objPath) {
PikaObj* obj = obj_getPtr(self, objPath);
obj_deinit(obj);
return 0;
}
int32_t obj_bind(PikaObj* self, char* type, char* name, void* pointer) {
args_bind(self->attributeList, type, name, pointer);
return 0;
}
char* obj_print(PikaObj* self, char* name) {
if (NULL == self) {
return NULL;
}
return args_print(self->attributeList, name);
}
int32_t obj_bindInt(PikaObj* self, char* name, int32_t* valPtr) {
args_bindInt(self->attributeList, name, valPtr);
return 0;
}
int32_t obj_bindFloat(PikaObj* self, char* name, float* valPtr) {
args_bindFloat(self->attributeList, name, valPtr);
return 0;
}
int32_t obj_bindString(PikaObj* self, char* name, char** valPtr) {
args_bindStr(self->attributeList, name, valPtr);
return 0;
}
int32_t obj_set(PikaObj* self, char* argPath, char* valStr) {
PikaObj* obj = obj_getObj(self, argPath, 1);
if (NULL == obj) {
/* cant get object */
return 3;
}
Args* buffs = New_strBuff();
char* argName = strsGetLastToken(buffs, argPath, '.');
int32_t res = args_set(obj->attributeList, argName, valStr);
args_deinit(buffs);
if (res == 1) {
/* do not get arg */
return 1;
}
if (res == 2) {
/* type not match */
return 2;
}
/* succeed */
return 0;
}
PikaObj* obj_getClassObjByNewFun(PikaObj* context,
char* name,
NewFun newClassFun) {
Args* initArgs = New_args(NULL);
args_setPtr(initArgs, "_ctx", context);
args_setStr(initArgs, "_n", name);
PikaObj* thisClass = newClassFun(initArgs);
obj_setPtr(thisClass, "_clsptr", newClassFun);
args_deinit(initArgs);
return thisClass;
}
char* obj_getClassPath(PikaObj* objHost, Args* buffs, char* objName) {
Arg* objArg = obj_getArg(objHost, objName);
char* objType = arg_getType(objArg);
char* classPath = strsRemovePrefix(buffs, objType, "_class-");
return classPath;
}
void* getNewClassObjFunByName(PikaObj* obj, char* name) {
Args* buffs = New_strBuff();
char* classPath = strsAppend(buffs, "[mate]", name);
/* init the subprocess */
void* (*newClassObjFun)(Args * initArgs) =
args_getPtr(obj->attributeList, classPath);
args_deinit(buffs);
return newClassObjFun;
}
int32_t removeEachMethodInfo(Arg* argNow, Args* argList) {
if (strIsStartWith(arg_getName(argNow), "[md]")) {
args_removeArg(argList, arg_getName(argNow));
return 0;
}
if (strIsStartWith(arg_getName(argNow), "[mp]")) {
args_removeArg(argList, arg_getName(argNow));
return 0;
}
return 0;
}
PikaObj* removeMethodInfo(PikaObj* thisClass) {
args_foreach(thisClass->attributeList, removeEachMethodInfo,
thisClass->attributeList);
return thisClass;
}
static void removeClassLoader(PikaObj* obj) {
PikaObj* classLoader = args_getPtr(obj->attributeList, "_clsld");
if (NULL != classLoader) {
obj_deinit(classLoader);
args_removeArg(obj->attributeList, "_clsld");
}
}
PikaObj* newRootObj(char* name, NewFun newObjFun) {
PikaObj* thisClass = obj_getClassObjByNewFun(NULL, name, newObjFun);
PikaObj* newObj = removeMethodInfo(thisClass);
return newObj;
}
PikaObj* initObj(PikaObj* obj, char* name) {
PikaObj* res = NULL;
NewFun newObjFun = getNewClassObjFunByName(obj, name);
Args* buffs = New_args(NULL);
if (NULL == newObjFun) {
/* no such object */
res = NULL;
goto exit;
}
PikaObj* thisClass = obj_getClassObjByNewFun(obj, name, newObjFun);
PikaObj* newObj = removeMethodInfo(thisClass);
/* delete [mate]<objName> */
obj_removeArg(obj, strsAppend(buffs, "[mate]", name));
/* delete "_clsld" object */
removeClassLoader(newObj);
char* type = args_getType(obj->attributeList, name);
args_setPtrWithType(obj->attributeList, name, type, newObj);
res = obj_getPtr(obj, name);
goto exit;
exit:
args_deinit(buffs);
return res;
}
PikaObj* obj_getObjDirect(PikaObj* self, char* name) {
if (NULL == self) {
return NULL;
}
/* check subprocess */
if (NULL == args_getPtr(self->attributeList, name)) {
/* no inited subprocess, check subprocess init fun*/
return initObj(self, name);
}
/* finded subscribe, check type*/
char* type = args_getType(self->attributeList, name);
if (!strIsStartWith(type, "_class")) {
/* type error, could not found subprocess */
return NULL;
}
return obj_getPtr(self, name);
}
PikaObj* obj_getObj(PikaObj* self, char* objPath, int32_t keepDeepth) {
Args* buffs = New_strBuff();
char* objPathBuff = strsCopy(buffs, objPath);
int32_t tokenNum = strGetTokenNum(objPath, '.');
PikaObj* obj = self;
for (int32_t i = 0; i < tokenNum - keepDeepth; i++) {
char* token = strsPopToken(buffs, objPathBuff, '.');
obj = obj_getObjDirect(obj, token);
if (obj == NULL) {
goto exit;
}
}
goto exit;
exit:
args_deinit(buffs);
return obj;
}
char* obj_getName(PikaObj* self) {
return obj_getStr(self, "_n");
}
void loadMethodInfo(PikaObj* methodHost,
char* methodName,
char* methodDeclearation,
void* methodPtr) {
Args* buffs = New_strBuff();
char* methodPtrPath = strsAppend(buffs, "[mp]", methodName);
char* methodDeclearationPath = strsAppend(buffs, "[md]", methodName);
obj_setPtr(methodHost, methodPtrPath, methodPtr);
obj_setStr(methodHost, methodDeclearationPath, methodDeclearation);
args_deinit(buffs);
}
int32_t class_defineMethod(PikaObj* self,
char* declearation,
void (*methodPtr)(PikaObj* self, Args* args)) {
int32_t size = strGetSize(declearation);
int32_t res = 0;
Args* buffs = New_strBuff();
char* cleanDeclearation =
strDeleteChar(args_getBuff(buffs, size), declearation, ' ');
char* methodPath =
strGetFirstToken(args_getBuff(buffs, size), cleanDeclearation, '(');
PikaObj* methodHost = obj_getObj(self, methodPath, 1);
if (NULL == methodHost) {
/* no found method object */
res = 1;
goto exit;
}
char* methodName = strsGetLastToken(buffs, methodPath, '.');
loadMethodInfo(methodHost, methodName, cleanDeclearation, methodPtr);
res = 0;
goto exit;
exit:
args_deinit(buffs);
return res;
}
static void transferReturnVal(PikaObj* self,
char* returnType,
char* returnName,
Args* args) {
if (strEqu("->int", returnType)) {
int returnVal = args_getInt(args, "return");
obj_setInt(self, returnName, returnVal);
return;
}
if (strEqu("->float", returnType)) {
float returnVal = args_getFloat(args, "return");
obj_setFloat(self, returnName, returnVal);
return;
}
if (strEqu("->str", returnType)) {
char* returnVal = args_getStr(args, "return");
obj_setStr(self, returnName, returnVal);
return;
}
}
char* getRightCmd(Args* buffs, char* cmd) {
char* right = NULL;
char* cmdBuff = strsCopy(buffs, cmd);
if (strIsContain(cmd, '(')) {
cmdBuff = strsGetFirstToken(buffs, cmdBuff, '(');
}
if (strIsContain(cmdBuff, '=')) {
cmdBuff = strsCopy(buffs, cmd);
strsPopToken(buffs, cmdBuff, '=');
right = cmdBuff;
} else {
right = cmd;
}
return right;
}
uint8_t obj_getAnyArg(PikaObj* self,
char* targetArgName,
char* sourceArgPath,
Args* targetArgs) {
if (0 == args_setLiteral(targetArgs, targetArgName, sourceArgPath)) {
return 0;
}
if (0 == obj_getRefArg(self, targetArgName, sourceArgPath, targetArgs)) {
return 0;
}
/* solve arg faild */
return 3;
}
uint8_t obj_getRefArg(PikaObj* self,
char* targetArgName,
char* sourceArgPath,
Args* targetArgs) {
/* get reference arg */
Arg* arg = obj_getArg(self, sourceArgPath);
if (arg == NULL) {
/* can not get arg */
return 3;
}
Arg* argCopied = arg_copy(arg);
argCopied = arg_setName(argCopied, targetArgName);
args_setArg(targetArgs, argCopied);
return 0;
}
Args* getRightRes(PikaObj* self, char* cmd) {
Args* buffs = New_strBuff();
Args* res = NULL;
if (strIsContain(cmd, '(') && strIsContain(cmd, ')')) {
res = obj_invoke(self, cmd);
goto exit;
}
res = New_args(NULL);
args_setSysOut(res, "");
char* value = cmd;
int err = obj_getAnyArg(self, "return", value, res);
if (err != 0) {
args_setSysOut(res, "[error] get value faild.");
args_setErrorCode(res, 1);
goto exit;
}
char* returnType = args_getType(res, "return");
returnType = strsAppend(buffs, "->", returnType);
args_setStr(res, "returnType", returnType);
goto exit;
exit:
args_deinit(buffs);
return res;
}
Args* obj_runScript(PikaObj* self, char* cmd) {
Args* buffs = New_strBuff();
Args* res = NULL;
cmd = strsGetCleanCmd(buffs, cmd);
/* get right cmd */
char* right = getRightCmd(buffs, cmd);
/* get res from right cmd */
res = getRightRes(self, right);
if (NULL != res) {
if (0 != args_getErrorCode(res)) {
goto exit;
}
}
/* check res */
if (NULL == res) {
res = New_args(NULL);
args_setErrorCode(res, 1);
args_setSysOut(res, "[error] solve script format faild!");
goto exit;
}
/* transfer return */
if (strIsContain(cmd, '=')) {
char* returnName = strsGetFirstToken(buffs, cmd, '=');
returnName = strsDeleteChar(buffs, returnName, ' ');
char* returnType = args_getStr(res, "returnType");
transferReturnVal(self, returnType, returnName, res);
}
exit:
args_deinit(buffs);
return res;
}
Args* obj_runDirect(PikaObj* self, char* cmd) {
Args* buffs = New_strBuff();
Args* res = NULL;
cmd = strsDeleteChar(buffs, cmd, '\n');
/* in block */
if (NULL != obj_getArg(self, "_isInBlock")) {
PikaObj* block = obj_getObj(self, "_block", 0);
if (strIsStartWith(cmd, " ")) {
if (strEqu(block_getMode(block), "if")) {
if_pushLine(block, cmd);
goto exit;
}
if (strEqu(block_getMode(block), "while")) {
while_pushLine(block, cmd);
goto exit;
}
goto exit;
}
/* the block is end */
else {
obj_removeArg(self, "_isInBlock");
if (strEqu(block_getMode(block), "if")) {
if_run(block);
}
if (strEqu(block_getMode(block), "while")) {
while_run(block);
}
obj_removeArg(self, "_block");
/* not finished */
}
}
/* if block */
if (strIsStartWith(cmd, "if ")) {
obj_setInt(self, "_isInBlock", 1);
obj_setObjWithoutClass(self, "_block", block_init);
PikaObj* block = obj_getObj(self, "_block", 0);
if_setAssert(block, cmd);
/* this line processed ok */
goto exit;
}
/* while block */
if (strIsStartWith(cmd, "while ")) {
obj_setInt(self, "_isInBlock", 1);
obj_setObjWithoutClass(self, "_block", block_init);
PikaObj* block = obj_getObj(self, "_block", 0);
while_setAssert(block, cmd);
/* this line processed ok */
goto exit;
}
/* check class */
if (strIsContain(cmd, '(') && strIsContain(cmd, ')') &&
strIsContain(cmd, '=')) {
/* check class */
char* classCmd = strsGetCleanCmd(buffs, cmd);
char* newObj = strsGetFirstToken(buffs, classCmd, '=');
char* classPath = strsGetLastToken(buffs, classCmd, '=');
classPath = strsGetFirstToken(buffs, classPath, '(');
/* replace . with _ */
for (int i = 0; i < strGetSize(classPath); i++) {
if ('.' == classPath[i]) {
classPath[i] = '_';
}
}
if (0 == obj_newObj(self, newObj, classPath)) {
goto exit;
}
}
/* run script */
if (strIsContain(cmd, '(') && strIsContain(cmd, ')')) {
res = obj_runScript(self, cmd);
goto exit;
}
/* run script */
if (strIsContain(cmd, '=')) {
res = obj_runScript(self, cmd);
goto exit;
}
exit:
/* check res */
if (NULL == res) {
res = New_args(NULL);
args_setErrorCode(res, 0);
args_setSysOut(res, "");
goto exit;
}
args_deinit(buffs);
return res;
}
int32_t obj_removeArg(PikaObj* self, char* argPath) {
PikaObj* objHost = obj_getObj(self, argPath, 1);
PikaObj* obj = obj_getObj(self, argPath, 0);
Args* buffs = New_strBuff();
if (NULL != obj) {
obj_deinit(obj);
}
int32_t err = 0;
if (NULL == objHost) {
/* [error] object no found */
err = 1;
goto exit;
}
char* argName = strsGetLastToken(buffs, argPath, '.');
int32_t res = args_removeArg(objHost->attributeList, argName);
if (1 == res) {
/*[error] not found arg*/
err = 2;
goto exit;
}
goto exit;
exit:
args_deinit(buffs);
return err;
}
int32_t obj_isArgExist(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObj(self, argPath, 1);
Args* buffs = New_strBuff();
int32_t res = 0;
if (NULL == obj) {
/* [error] object no found */
res = 1;
goto exit;
}
char* argName = strsGetLastToken(buffs, argPath, '.');
Arg* arg = args_getArg(obj->attributeList, argName);
if (NULL == arg) {
/* no found arg */
res = 0;
goto exit;
}
/* found arg */
res = 1;
goto exit;
exit:
args_deinit(buffs);
return res;
}
void obj_runNoRes(PikaObj* slef, char* cmd) {
/* unsafe, nothing would happend when error occord */
args_deinit(obj_runDirect(slef, cmd));
}
void obj_run(PikaObj* self, char* cmd) {
/* safe, stop when error occord and error info would be print32_t */
Args* res = obj_runDirect(self, cmd);
char* sysOut = args_getSysOut(res);
uint8_t errcode = args_getErrorCode(res);
obj_setSysOut(self, sysOut);
obj_setErrorCode(self, errcode);
if (!strEqu("", sysOut)) {
__platformPrintf("%s\r\n", sysOut);
}
if (0 != errcode) {
__platformPrintf("[info] input commond: %s\r\n", cmd);
while (1)
;
}
if (NULL != res) {
args_deinit(res);
}
}
void obj_setErrorCode(PikaObj* self, int32_t errCode) {
obj_setInt(self, "__errCode", errCode);
}
int32_t obj_getErrorCode(PikaObj* self) {
if (!obj_isArgExist(self, "__errCode")) {
return 0;
}
return obj_getInt(self, "__errCode");
}
void args_setErrorCode(Args* args, int32_t errCode) {
args_setInt(args, "__errCode", errCode);
}
int32_t args_getErrorCode(Args* args) {
if (!args_isArgExist(args, "__errCode")) {
return 0;
}
return args_getInt(args, "__errCode");
}
void obj_setSysOut(PikaObj* self, char* str) {
obj_setStr(self, "__sysOut", str);
}
char* obj_getSysOut(PikaObj* self) {
return obj_getStr(self, "__sysOut");
}
char* args_getSysOut(Args* args) {
return args_getStr(args, "__sysOut");
}
void args_setSysOut(Args* args, char* str) {
args_setStr(args, "__sysOut", str);
}
void obj_sysPrintf(PikaObj* self, char* fmt, ...) {
va_list args;
va_start(args, fmt);
char sysOut[128] = {0};
vsprintf(sysOut, fmt, args);
obj_setSysOut(self, sysOut);
va_end(args);
}

View File

@ -1,99 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _Process__H
#define _Process__H
#include "dataArgs.h"
#include "dataLink.h"
#include "dataMemory.h"
#include "method.h"
typedef struct PikaObj_t PikaObj;
typedef PikaObj* (*NewFun)(Args* args);
typedef PikaObj* (*InitFun)(PikaObj* self, Args* args);
struct PikaObj_t {
/* list */
Args* attributeList;
};
/* operation */
int32_t obj_deinit(PikaObj* self);
int32_t obj_init(PikaObj* self, Args* args);
int32_t obj_update(PikaObj* self);
int32_t obj_enable(PikaObj* self);
int32_t obj_disable(PikaObj* self);
// arg type operations
int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val);
int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer);
int32_t obj_setFloat(PikaObj* self, char* argPath, float value);
int32_t obj_setStr(PikaObj* self, char* argPath, char* str);
int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg);
void* obj_getPtr(PikaObj* self, char* argPath);
float obj_getFloat(PikaObj* self, char* argPath);
char* obj_getStr(PikaObj* self, char* argPath);
int64_t obj_getInt(PikaObj* self, char* argPath);
Arg* obj_getArg(PikaObj* self, char* argPath);
char* obj_getName(PikaObj* self);
// arg general operations
int32_t obj_bind(PikaObj* self, char* type, char* name, void* pointer);
int32_t obj_set(PikaObj* self, char* name, char* valStr);
int32_t obj_bindInt(PikaObj* self, char* name, int32_t* valPtr);
int32_t obj_bindFloat(PikaObj* self, char* name, float* valPtr);
int32_t obj_bindString(PikaObj* self, char* name, char** valPtr);
char* obj_print(PikaObj* self, char* name);
// args operations
int32_t obj_load(PikaObj* self, Args* args, char* name);
// subObject
int32_t obj_addOther(PikaObj* self, char* subObjectName, void* new_projcetFun);
int32_t obj_setObjWithoutClass(PikaObj* self,
char* subObjectName,
void* new_projcetFun);
PikaObj* obj_getObjDirect(PikaObj* self, char* name);
PikaObj* obj_getObj(PikaObj* self, char* processPathectory, int32_t deepth);
// subProcess
int32_t obj_freeObj(PikaObj* self, char* subObjectName);
/* method */
int32_t class_defineMethod(PikaObj* self,
char* declearation,
void (*methodPtr)(PikaObj* self, Args* args));
void obj_runNoRes(PikaObj* slef, char* cmd);
void obj_run(PikaObj* self, char* cmd);
Args* obj_runDirect(PikaObj* self, char* cmd);
int32_t obj_removeArg(PikaObj* self, char* argPath);
int32_t obj_isArgExist(PikaObj* self, char* argPath);
PikaObj* obj_getClassObjByNewFun(PikaObj* self, char* name, NewFun newClassFun);
PikaObj* newRootObj(char* name, NewFun newObjFun);
void obj_setErrorCode(PikaObj* self, int32_t errCode);
int32_t obj_getErrorCode(PikaObj* self);
void obj_setSysOut(PikaObj* self, char* str);
char* args_getSysOut(Args* args);
void args_setErrorCode(Args* args, int32_t errCode);
int32_t args_getErrorCode(Args* args);
void args_setSysOut(Args* args, char* str);
char* obj_getSysOut(PikaObj* self);
void obj_sysPrintf(PikaObj* self, char* fmt, ...);
PikaObj* obj_getContext(PikaObj* self);
uint8_t obj_getRefArg(PikaObj* self,
char* targetArgName,
char* sourceArgPath,
Args* targetArgs);
uint8_t obj_getAnyArg(PikaObj* self,
char* targetArgName,
char* sourceArgPath,
Args* targetArgs);
#endif

View File

@ -1,14 +0,0 @@
class TinyObj:
pass
class BaseObj(TinyObj):
pass
def print(val: any):
pass
def set(argPath: str, val: any):
pass

View File

@ -1,47 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include <stdarg.h>
#include "PikaBlock.h"
#include "PikaObj.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
void while_setAssert(PikaObj* self, char* line) {
Args* buffs = New_strBuff();
char* assert = strsRemovePrefix(buffs, line, "while ");
assert = strsGetFirstToken(buffs, assert, ':');
block_setAssert(self, assert);
block_setMode(self, "while");
args_deinit(buffs);
}
void while_pushLine(PikaObj* self, char* line) {
Args* buffs = New_strBuff();
char* bodyLine = strsRemovePrefix(buffs, line, " ");
block_pushLine(self, bodyLine);
goto exit;
exit:
args_deinit(buffs);
return;
}
void while_run(PikaObj* self) {
Args* buffs = New_strBuff();
char* body = strsCopy(buffs, block_getBody(self));
uint16_t lineSize = block_getLineSize(self);
while (block_checkAssert(self)) {
PikaObj* host = obj_getContext(self);
for (int i = 0; i < lineSize; i++) {
char* line = block_popLine(self);
obj_run(host, line);
}
block_setBody(self, body);
}
exit:
args_deinit(buffs);
}

View File

@ -1,14 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _pikaWhile__H
#define _pikaWhile__H
#include "PikaObj.h"
void while_setAssert(PikaObj* self, char* line);
void while_pushLine(PikaObj* self, char* line);
void while_run(PikaObj* self);
#endif

View File

@ -1 +0,0 @@
# PikaScript 运行时内核

View File

@ -1,34 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "PikaObj.h"
void _UpdateHandle(PikaObj* self) {
// override the handle function here
}
void _beforDinit(PikaObj* self) {
/* override in user code */
}
PikaObj* New_TinyObj(Args* args) {
PikaObj* self = pikaMalloc(sizeof(PikaObj));
/* List */
self->attributeList = New_args(NULL);
/* attribute */
obj_setPtr(self, "_ctx", self);
obj_setStr(self, "_n", "root");
/* load */
if (NULL != args) {
obj_load(self, args, "_n");
obj_load(self, args, "_ctx");
}
/* hard attribute */
return self;
}

View File

@ -1,10 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef __TYNYOBJ__H
#define __TYNYOBJ__H
#include "PikaObj.h"
PikaObj* New_TinyObj(Args* args);
#endif

View File

@ -1,327 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "dataArg.h"
#include <stdint.h>
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "stdlib.h"
void arg_deinit(Arg* self) {
arg_freeContent(self);
}
uint16_t arg_getTotleSize(Arg* self) {
return content_totleSize(self);
}
uint16_t content_sizeOffset(uint8_t* self) {
const uint8_t nextLength = sizeof(uint8_t*);
return nextLength;
}
uint16_t content_getSize(uint8_t* self) {
uint16_t size = 0;
// add 0x30 to avoid 0
size += self[content_sizeOffset(self) + 1];
size = (size << 8);
size += self[content_sizeOffset(self)];
return size;
}
void content_setNext(uint8_t* self, uint8_t* next) {
uint8_t* nextDir = self + content_nextOffset(self);
uint64_t pointerTemp = (uint64_t)next;
for (uint32_t i = 0; i < sizeof(uint8_t*); i++) {
// aboid \0
nextDir[i] = pointerTemp;
pointerTemp = pointerTemp >> 8;
}
}
uint8_t* content_init(char* name,
char* type,
uint8_t* content,
uint16_t size,
uint8_t* next) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
uint16_t nameSize = strGetSize(name);
uint16_t typeSize = strGetSize(type);
uint8_t* self = (uint8_t*)pikaMalloc(nextLength + sizeLength + nameSize +
1 + size + typeSize + 1);
uint8_t* nextDir = self;
uint8_t* sizeDir = nextDir + nextLength;
uint8_t* nameDir = sizeDir + sizeLength;
uint8_t* contentDir = nameDir + nameSize + 1;
uint8_t* typeDir = contentDir + size;
memcpy(nameDir, name, nameSize + 1);
memcpy(typeDir, type, typeSize + 1);
sizeDir[0] = size;
sizeDir[1] = size >> 8;
if (NULL != content) {
memcpy(contentDir, content, size);
} else {
memset(contentDir, 0, size);
}
uint64_t pointerTemp = (uint64_t)next;
for (uint32_t i = 0; i < sizeof(uint8_t*); i++) {
// aboid \0
nextDir[i] = pointerTemp;
pointerTemp = pointerTemp >> 8;
}
return self;
}
uint16_t content_totleSize(uint8_t* self) {
char* name = content_getName(self);
char* type = content_getType(self);
const uint8_t sizeLenth = 2;
const uint8_t nextLength = sizeof(uint8_t*);
uint16_t size = content_getSize(self);
return size + strGetSize(name) + 1 + strGetSize(type) + 1 + sizeLenth +
nextLength;
}
void arg_freeContent(Arg* self) {
if (NULL != self) {
content_deinit(self);
}
}
uint8_t content_nameOffset(uint8_t* self) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
return nextLength + sizeLength;
}
char* content_getName(uint8_t* self) {
return (char*)self + content_nameOffset(self);
}
uint8_t* content_deinit(uint8_t* self) {
uint16_t totleSize = content_totleSize(self);
pikaFree(self, totleSize);
return 0;
}
uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size) {
if (NULL == self) {
return content_init("", "", content, size, NULL);
}
char* name = content_getName(self);
char* type = content_getType(self);
uint8_t* next = content_getNext(self);
uint8_t* newContent = content_init(name, type, content, size, next);
content_deinit(self);
return newContent;
}
uint8_t* content_setName(uint8_t* self, char* name) {
if (NULL == self) {
return content_init(name, "", NULL, 0, NULL);
}
char* type = content_getType(self);
uint8_t* content = content_getContent(self);
uint16_t size = content_getSize(self);
uint8_t* next = content_getNext(self);
uint8_t* newContent = content_init(name, type, content, size, next);
content_deinit(self);
return newContent;
}
uint8_t* content_setType(uint8_t* self, char* type) {
if (NULL == self) {
return content_init("", type, NULL, 0, NULL);
}
char* name = content_getName(self);
uint8_t* content = content_getContent(self);
uint16_t size = content_getSize(self);
uint8_t* next = content_getNext(self);
uint8_t* newContent = content_init(name, type, content, size, next);
content_deinit(self);
return newContent;
}
Arg* arg_newContent(Arg* self, uint32_t size) {
uint8_t* newContent = content_init("", "", NULL, size, NULL);
arg_freeContent(self);
return newContent;
}
Arg* arg_setContent(Arg* self, uint8_t* content, uint32_t size) {
return content_setContent(self, content, size);
}
Arg* arg_setName(Arg* self, char* name) {
return content_setName(self, name);
}
Arg* arg_setType(Arg* self, char* type) {
return content_setType(self, type);
}
char* content_getType(uint8_t* self) {
return (char*)self + content_typeOffset(self);
}
uint16_t content_contentOffset(uint8_t* self) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
char* name = content_getName(self);
return nextLength + sizeLength + strGetSize(name) + 1;
}
uint16_t content_nextOffset(uint8_t* self) {
return 0;
}
uint8_t* content_getNext(uint8_t* self) {
uint8_t* nextDir = self + content_nextOffset(self);
uint8_t* next = NULL;
uint64_t pointerTemp = 0;
for (int32_t i = sizeof(uint8_t*); i > -1; i--) {
// avoid \0
uint8_t val = nextDir[i];
pointerTemp = (pointerTemp << 8);
pointerTemp += val;
}
next = (uint8_t*)pointerTemp;
return next;
}
uint8_t* content_getContent(uint8_t* self) {
return self + content_contentOffset(self);
}
uint8_t* arg_getContent(Arg* self) {
return content_getContent(self);
}
Arg* arg_setInt(Arg* self, char* name, int64_t val) {
int64_t int64Temp = val;
uint8_t contentBuff[8];
for (uint32_t i = 0; i < 4; i++) {
// add 0x30 to void \0
contentBuff[i] = int64Temp;
int64Temp = int64Temp >> 8;
}
return content_init(name, "int", contentBuff, 4, NULL);
}
Arg* arg_setFloat(Arg* self, char* name, float val) {
uint8_t contentBuff[4];
uint8_t* valPtr = (uint8_t*)&val;
for (uint32_t i = 0; i < 4; i++) {
// add 0x30 to void \0
contentBuff[i] = valPtr[i];
}
return content_init(name, "float", contentBuff, 4, NULL);
}
float arg_getFloat(Arg* self) {
if (NULL == arg_getContent(self)) {
return -999.999;
}
float valOut = 0;
uint8_t* valOutPtr = (uint8_t*)(&valOut);
uint8_t* valPtr = arg_getContent(self);
for (uint32_t i = 0; i < 4; i++) {
valOutPtr[i] = valPtr[i];
}
return valOut;
}
Arg* arg_setPtr(Arg* self, char* name, char* type, void* pointer) {
uint64_t pointerTemp = (uint64_t)pointer;
uint8_t contentBuff[8];
for (uint32_t i = 0; i < sizeof(uint8_t*); i++) {
// aboid \0
contentBuff[i] = pointerTemp;
pointerTemp = pointerTemp >> 8;
}
return content_init(name, type, contentBuff, sizeof(uint8_t*), NULL);
}
Arg* arg_setStr(Arg* self, char* name, char* string) {
return content_init(name, "str", (uint8_t*)string, strGetSize(string) + 1,
NULL);
}
int64_t arg_getInt(Arg* self) {
if (NULL == arg_getContent(self)) {
return -999999;
}
int64_t int64Temp = 0;
for (int32_t i = 3; i > -1; i--) {
// add 0x30 to avoid 0
int64Temp = (int64Temp << 8);
int64Temp += arg_getContent(self)[i];
}
return int64Temp;
}
void* arg_getPtr(Arg* self) {
void* pointer = NULL;
uint64_t pointerTemp = 0;
if (NULL == arg_getContent(self)) {
return NULL;
}
uint8_t* content = arg_getContent(self);
for (int32_t i = sizeof(uint8_t*) - 1; i > -1; i--) {
// avoid \0
uint8_t val = content[i];
pointerTemp = (pointerTemp << 8);
pointerTemp += val;
}
pointer = (void*)pointerTemp;
return pointer;
}
char* arg_getStr(Arg* self) {
return (char*)arg_getContent(self);
}
uint16_t content_typeOffset(uint8_t* self) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
uint16_t size = content_getSize(self);
char* name = content_getName(self);
uint16_t nameSize = strGetSize(name);
return nextLength + sizeLength + nameSize + 1 + size;
}
char* arg_getName(Arg* self) {
return content_getName(self);
}
char* arg_getType(Arg* self) {
return content_getType(self);
}
uint16_t arg_getContentSize(Arg* self) {
return content_getSize(self);
}
Arg* New_arg(void* voidPointer) {
return NULL;
}
Arg* arg_copy(Arg* argToBeCopy) {
Arg* argCopied = New_arg(NULL);
argCopied = arg_setContent(argCopied, arg_getContent(argToBeCopy),
arg_getContentSize(argToBeCopy));
argCopied = arg_setName(argCopied, arg_getName(argToBeCopy));
argCopied = arg_setType(argCopied, arg_getType(argToBeCopy));
return argCopied;
}

View File

@ -1,65 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _arg__H
#define _arg__H
#include "dataMemory.h"
typedef uint8_t Arg;
uint16_t content_typeOffset(uint8_t* content);
uint16_t content_contentOffset(uint8_t* content);
uint16_t content_sizeOffset(uint8_t* self);
uint16_t content_contentOffset(uint8_t* self);
uint16_t content_nextOffset(uint8_t* self);
uint8_t content_nameOffset(uint8_t* self);
char* content_getName(uint8_t* content);
char* content_getType(uint8_t* content);
uint8_t* content_getNext(uint8_t* self);
uint16_t content_getSize(uint8_t* self);
uint8_t* content_getContent(uint8_t* content);
uint16_t content_totleSize(uint8_t* self);
uint8_t* content_init(char* name,
char* type,
uint8_t* content,
uint16_t size,
uint8_t* next);
uint8_t* content_deinit(uint8_t* self);
uint8_t* content_setName(uint8_t* self, char* name);
uint8_t* content_setType(uint8_t* self, char* type);
uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size);
void content_setNext(uint8_t* self, uint8_t* next);
uint16_t arg_getTotleSize(Arg* self);
void arg_freeContent(Arg* self);
Arg* arg_setName(Arg* self, char* name);
Arg* arg_setContent(Arg* self, uint8_t* content, uint32_t size);
Arg* arg_newContent(Arg* self, uint32_t size);
Arg* arg_setType(Arg* self, char* type);
char* arg_getName(Arg* self);
char* arg_getType(Arg* self);
uint8_t* arg_getContent(Arg* self);
uint16_t arg_getContentSize(Arg* self);
Arg* arg_setInt(Arg* self, char* name, int64_t val);
Arg* arg_setFloat(Arg* self, char* name, float val);
Arg* arg_setPtr(Arg* self, char* name, char* type, void* pointer);
Arg* arg_setStr(Arg* self, char* name, char* string);
int64_t arg_getInt(Arg* self);
float arg_getFloat(Arg* self);
void* arg_getPtr(Arg* self);
char* arg_getStr(Arg* self);
Arg* arg_copy(Arg* argToBeCopy);
Arg* arg_init(Arg* self, void* voidPointer);
void arg_deinit(Arg* self);
Arg* New_arg(void* voidPointer);
#endif

View File

@ -1,502 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "dataArgs.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dataLink.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
void args_deinit(Args* self) {
link_deinit(self);
}
int32_t args_setFloat(Args* self, char* name, float argFloat) {
Arg* argNew = New_arg(NULL);
argNew = arg_setFloat(argNew, name, argFloat);
args_setArg(self, argNew);
return 0;
}
void* args_getPtr(Args* self, char* name) {
void* pointer = NULL;
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return NULL;
}
pointer = arg_getPtr(arg);
return pointer;
}
int32_t args_setPtr(Args* self, char* name, void* argPointer) {
int32_t errCode = 0;
Arg* argNew = New_arg(NULL);
argNew = arg_setPtr(argNew, name, "pointer", argPointer);
args_setArg(self, argNew);
return errCode;
}
int32_t args_setStr(Args* self, char* name, char* strIn) {
int32_t errCode = 0;
Arg* argNew = New_arg(NULL);
argNew = arg_setStr(argNew, name, strIn);
args_setArg(self, argNew);
return errCode;
}
void setArgDirect(Args* self, Arg* arg) {
link_addNode(self, arg);
}
char* args_getBuff(Args* self, int32_t size) {
Arg* argNew = New_arg(NULL);
argNew = arg_newContent(argNew, size + 1);
setArgDirect(self, argNew);
return (char*)arg_getContent(argNew);
}
char* args_getStr(Args* self, char* name) {
if (NULL == self) {
return NULL;
}
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return NULL;
}
if (NULL == arg_getContent(arg)) {
return NULL;
}
return (char*)arg_getContent(arg);
}
int32_t args_setInt(Args* self, char* name, int64_t int64In) {
Arg* argNew = New_arg(NULL);
argNew = arg_setInt(argNew, name, int64In);
args_setArg(self, argNew);
return 0;
}
int64_t args_getInt(Args* self, char* name) {
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return -999999999;
}
return arg_getInt(arg);
}
int32_t args_getSize(Args* self) {
return link_getSize(self);
}
char* args_getType(Args* self, char* name) {
Arg* arg = NULL;
arg = args_getArg(self, name);
if (NULL == arg) {
return NULL;
}
return arg_getType(arg);
}
float args_getFloat(Args* self, char* name) {
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return -999999999.0;
}
return arg_getFloat(arg);
}
int32_t args_copyArg(Args* self, Arg* argToBeCopy) {
if (NULL == argToBeCopy) {
return 1;
}
Arg* argCopied = arg_copy(argToBeCopy);
args_setArg(self, argCopied);
return 0;
}
int32_t args_copyArgByName(Args* self, char* name, Args* directArgs) {
Arg* argToBeCopy = args_getArg(self, name);
args_copyArg(directArgs, argToBeCopy);
return 0;
}
int32_t args_isArgExist(Args* self, char* name) {
if (NULL == name) {
return 0;
}
if (NULL != args_getArg(self, name)) {
return 1;
}
return 0;
}
int32_t updateArg(Args* self, Arg* argNew) {
LinkNode* nodeToUpdate = NULL;
LinkNode* nodeNow = self->firstNode;
LinkNode* priorNode = NULL;
char* name = arg_getName(argNew);
while (1) {
if (strEqu(content_getName(nodeNow), name)) {
nodeToUpdate = nodeNow;
break;
}
if (content_getNext(nodeNow) == NULL) {
// error, node no found
goto exit;
}
priorNode = nodeNow;
nodeNow = content_getNext(nodeNow);
}
nodeToUpdate = arg_setContent(nodeToUpdate, arg_getContent(argNew),
arg_getContentSize(argNew));
// update privior link, because arg_getContent would free origin pointer
if (NULL == priorNode) {
self->firstNode = nodeToUpdate;
goto exit;
}
content_setNext(priorNode, nodeToUpdate);
goto exit;
exit:
arg_deinit(argNew);
return 0;
}
int32_t args_setArg(Args* self, Arg* arg) {
char* name = arg_getName(arg);
if (!args_isArgExist(self, name)) {
setArgDirect(self, arg);
return 0;
}
updateArg(self, arg);
return 0;
}
LinkNode* args_getNode(Args* self, char* name) {
LinkNode* nodeNow = self->firstNode;
if (NULL == nodeNow) {
return NULL;
}
while (1) {
Arg* arg = nodeNow;
char* thisName = arg_getName(arg);
if (strEqu(name, thisName)) {
return nodeNow;
}
if (NULL == content_getNext(nodeNow)) {
return NULL;
}
nodeNow = content_getNext(nodeNow);
}
}
Arg* args_getArg(Args* self, char* name) {
LinkNode* node = args_getNode(self, name);
if (NULL == node) {
return NULL;
}
return node;
}
void args_bind(Args* self, char* type, char* name, void* pointer) {
Args* buffs = New_strBuff();
char* typeWithBind = strsAppend(buffs, "_bind-", type);
Arg* argNew = New_arg(NULL);
argNew = arg_setPtr(argNew, name, typeWithBind, pointer);
args_setArg(self, argNew);
args_deinit(buffs);
return;
}
void args_bindInt(Args* self, char* name, int32_t* intPtr) {
args_bind(self, "int", name, intPtr);
}
void args_bindFloat(Args* self, char* name, float* floatPtr) {
args_bind(self, "float", name, floatPtr);
}
void args_bindStr(Args* self, char* name, char** stringPtr) {
args_bind(self, "str", name, stringPtr);
}
char* getPrintSring(Args* self, char* name, char* valString) {
Args* buffs = New_strBuff();
char* printName = strsFormat(buffs, 128, "[printBuff]%s", name);
char* printString = strsCopy(buffs, valString);
args_setStr(self, printName, printString);
char* res = args_getStr(self, printName);
args_deinit(buffs);
return res;
}
char* getPrintStringFromInt(Args* self, char* name, int32_t val) {
Args* buffs = New_strBuff();
char* res = NULL;
char* valString = strsFormat(buffs, 32, "%d", val);
res = getPrintSring(self, name, valString);
args_deinit(buffs);
return res;
}
char* getPrintStringFromFloat(Args* self, char* name, float val) {
Args* buffs = New_strBuff();
char* res = NULL;
char* valString = strsFormat(buffs, 32, "%f", val);
res = getPrintSring(self, name, valString);
args_deinit(buffs);
return res;
}
char* getPrintStringFromPtr(Args* self, char* name, void* val) {
Args* buffs = New_strBuff();
char* res = NULL;
uint64_t intVal = (uint64_t)val;
char* valString = strsFormat(buffs, 32, "0x%llx", intVal);
res = getPrintSring(self, name, valString);
args_deinit(buffs);
return res;
}
char* args_print(Args* self, char* name) {
char* res = NULL;
char* type = args_getType(self, name);
Args* buffs = New_strBuff();
if (NULL == type) {
/* can not get arg */
res = NULL;
goto exit;
}
if (strEqu(type, "int")) {
int32_t val = args_getInt(self, name);
res = getPrintStringFromInt(self, name, val);
goto exit;
}
if (strEqu(type, "float")) {
float val = args_getFloat(self, name);
res = getPrintStringFromFloat(self, name, val);
goto exit;
}
if (strEqu(type, "str")) {
res = args_getStr(self, name);
goto exit;
}
if (strEqu(type, "pointer")) {
void* val = args_getPtr(self, name);
res = getPrintStringFromPtr(self, name, val);
goto exit;
}
char* bindTypePrefix = strsCopy(self, "_bind-");
if (strIsStartWith(type, bindTypePrefix)) {
char* typeWithoutBind = strsRemovePrefix(buffs, type, bindTypePrefix);
if (strEqu(typeWithoutBind, "int")) {
int32_t* valPtr = args_getPtr(self, name);
int32_t val = *valPtr;
res = getPrintStringFromInt(self, name, val);
goto exit;
}
if (strEqu(typeWithoutBind, "float")) {
float* valPtr = args_getPtr(self, name);
float val = *valPtr;
res = getPrintStringFromFloat(self, name, val);
goto exit;
}
if (strEqu(typeWithoutBind, "str")) {
// the value of &string is equal to string it self
char* string = args_getPtr(self, name);
res = string;
goto exit;
}
}
/* can not match type */
res = NULL;
goto exit;
exit:
args_deinit(buffs);
return res;
}
uint8_t args_setLiteral(Args* self, char* targetArgName, char* literal) {
Args* buffs = New_strBuff();
literal = strsGetCleanCmd(buffs, literal);
uint8_t err = 0;
char* directStr = strsGetDirectStr(self, literal);
/* get direct Str ok */
if (NULL != directStr) {
/* direct string value */
args_setStr(self, targetArgName, directStr);
/* ok */
err = 0;
goto exit;
}
/* match bool */
if (strEqu(literal, "True")) {
args_setInt(self, targetArgName, 1);
err = 0;
goto exit;
}
if (strEqu(literal, "False")) {
args_setInt(self, targetArgName, 0);
err = 0;
goto exit;
}
/* match num */
if ((literal[0] >= '0') && (literal[0] <= '9')) {
/* match float num */
if (strIsContain(literal, '.')) {
args_setFloat(self, targetArgName, 0);
args_set(self, targetArgName, literal);
/* succeed */
err = 0;
goto exit;
}
/* match int num */
args_setInt(self, targetArgName, 0);
args_set(self, targetArgName, literal);
/* succeed */
err = 0;
goto exit;
}
err = 1;
goto exit;
exit:
args_deinit(buffs);
return err;
}
int32_t args_set(Args* self, char* name, char* valStr) {
char* type = args_getType(self, name);
Args* buffs = New_strBuff();
int32_t err = 0;
if (NULL == type) {
/* do not get arg */
err = 1;
goto exit;
}
if (strEqu("int", type)) {
int32_t val = atoi(valStr);
args_setInt(self, name, val);
// operation succeed
err = 0;
goto exit;
}
if (strEqu("float", type)) {
float val = atof(valStr);
args_setFloat(self, name, val);
// operation succeed
err = 0;
goto exit;
}
if (strEqu("str", type)) {
args_setStr(self, name, valStr);
// operation succeed
err = 0;
goto exit;
}
char* bindTypePrefix = strsCopy(self, "_bind-");
if (strIsStartWith(type, bindTypePrefix)) {
char* typeWithoutBind = strsRemovePrefix(buffs, type, bindTypePrefix);
if (strEqu(typeWithoutBind, "int")) {
int32_t* valPtr = args_getPtr(self, name);
int32_t val = atoi(valStr);
*valPtr = val;
// operation succeed
err = 0;
goto exit;
}
if (strEqu(typeWithoutBind, "float")) {
float* valPtr = args_getPtr(self, name);
float val = atof(valStr);
*valPtr = val;
// operation succeed
err = 0;
goto exit;
}
if (strEqu(typeWithoutBind, "str")) {
char* stringBinded = args_getPtr(self, name);
/* size add 1 to copy the '\0' */
memcpy(stringBinded, valStr, strGetSize(valStr) + 1);
// operation succeed
err = 0;
goto exit;
}
}
/* type not match */
err = 2;
goto exit;
exit:
args_deinit(buffs);
return err;
}
int32_t args_setPtrWithType(Args* self, char* name, char* type, void* objPtr) {
Arg* argNew = New_arg(NULL);
argNew = arg_setPtr(argNew, name, type, objPtr);
args_setArg(self, argNew);
return 0;
}
int32_t args_setObjectWithClass(Args* self,
char* objName,
char* className,
void* objPtr) {
Args* buffs = New_strBuff();
char* typeWithClass = strsAppend(buffs, "_class-", className);
args_setPtrWithType(self, objName, typeWithClass, objPtr);
args_deinit(buffs);
return 0;
}
int32_t args_foreach(Args* self,
int32_t (*eachHandle)(Arg* argEach, Args* handleArgs),
Args* handleArgs) {
LinkNode* nodeNow = self->firstNode;
while (1) {
Arg* argNow = nodeNow;
if (NULL == argNow) {
continue;
}
LinkNode* nextNode = content_getNext(nodeNow);
eachHandle(argNow, handleArgs);
if (NULL == nextNode) {
break;
}
nodeNow = nextNode;
}
return 0;
}
int32_t args_removeArg(Args* self, char* name) {
Arg* argNow = args_getArg(self, name);
if (NULL == argNow) {
/* can not found arg */
return 1;
}
link_removeNode(self, argNow);
return 0;
}
Args* New_args(Args* args) {
Args* self = New_link(NULL);
return self;
}

View File

@ -1,71 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _dataArgs__H
#define _dataArgs__H
#include "dataArg.h"
#include "dataLink.h"
#include "dataMemory.h"
#include "dataString.h"
typedef Link Args;
/* operation */
void args_deinit(Args* self);
void args_init(Args* self, Args* args);
int32_t args_getSize(Args* self);
LinkNode* args_getNode(Args* self, char* name);
Arg* args_getArgByIndex(Args* self, int32_t index);
Arg* args_getArg(Args* self, char* name);
int32_t args_removeArg(Args* self, char* name);
int32_t args_setArg(Args* self, Arg* arg);
int32_t args_copyArgByName(Args* self, char* name, Args* directList);
int32_t args_copyArg(Args* self, Arg* argToBeCopy);
char* args_getType(Args* self, char* name);
int32_t args_isArgExist(Args* self, char* name);
int32_t args_setStr(Args* self, char* name, char* strIn);
int32_t args_setStrWithDefaultName(Args* self, char* strIn);
char* args_getStr(Args* self, char* name);
int32_t args_setFloatWithDefaultName(Args* self, float argFloat);
int32_t args_setFloat(Args* self, char* name, float argFloat);
float args_getFloat(Args* self, char* name);
int32_t args_setPtr(Args* self, char* name, void* argPointer);
void* args_getPtr(Args* self, char* name);
int32_t args_setInt(Args* self, char* name, int64_t int64In);
int64_t args_getInt(Args* self, char* name);
void args_bindInt(Args* self, char* name, int32_t* intPtr);
void args_bindFloat(Args* self, char* name, float* floatPtr);
void args_bindStr(Args* self, char* name, char** stringPtr);
/* arg general opeartion */
void args_bind(Args* self, char* type, char* name, void* pointer);
char* args_print(Args* self, char* name);
int32_t args_set(Args* self, char* name, char* valueStr);
int32_t args_setObjectWithClass(Args* self,
char* objectName,
char* className,
void* objectPtr);
int32_t args_setPtrWithType(Args* self,
char* objName,
char* type,
void* objPtr);
int32_t args_foreach(Args* self,
int32_t (*eachHandle)(Arg* argEach, Args* handleArgs),
Args* handleArgs);
char* args_getBuff(Args* self, int32_t size);
uint8_t args_setLiteral(Args* self, char* targetArgName, char* literal);
Args* New_args(Args* args);
#endif

View File

@ -1,87 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "dataLink.h"
#include "dataArg.h"
#include "dataLinkNode.h"
#include "dataMemory.h"
void link_deinit(Link* self) {
LinkNode* nowNode = self->firstNode;
while (NULL != nowNode) {
LinkNode* nodeNext = content_getNext(nowNode);
linkNode_deinit(nowNode);
nowNode = nodeNext;
}
// DynMemPut(self->mem);
pikaFree(self, sizeof(Link));
self = NULL;
}
void link_addNode(Link* self, void* content) {
// old first node become new second node
LinkNode* secondNode = self->firstNode;
self->firstNode = content;
// change the first node to new node
content_setNext(content, secondNode);
}
void link_removeNode(Link* self, void* content) {
LinkNode* nodeToDelete = NULL;
LinkNode* nodeNow = self->firstNode;
LinkNode* priorNode = NULL;
while (1) {
if (nodeNow == content) {
nodeToDelete = nodeNow;
break;
}
if (nodeNow == NULL) {
// error, node no found
goto exit;
}
priorNode = nodeNow;
nodeNow = content_getNext(nodeNow);
}
LinkNode* nextNode = content_getNext(nodeToDelete);
if (nodeToDelete == self->firstNode) {
self->firstNode = content_getNext(nodeToDelete);
}
if (NULL == priorNode) {
self->firstNode = nextNode;
goto exit;
}
content_setNext(priorNode, nextNode);
goto exit;
// deinit the node
exit:
linkNode_deinit(nodeToDelete);
return;
}
int32_t link_getSize(Link* self) {
LinkNode* NowNode;
int32_t size = 0;
NowNode = self->firstNode;
while (NULL != NowNode) {
size++;
NowNode = content_getNext(NowNode);
}
return size;
}
void link_init(Link* self, void* args) {
self->firstNode = NULL;
}
Link* New_link(void* args) {
Link* self = pikaMalloc(sizeof(Link));
link_init(self, args);
return self;
}

View File

@ -1,24 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _link2__H
#define _link2__H
#include "dataLinkNode.h"
#include "dataMemory.h"
typedef struct Class_link Link;
struct Class_link {
LinkNode* firstNode;
};
void link_deinit(Link* self);
void link_init(Link* self, void* args);
void link_addNode(Link* self, void* content);
void link_removeNode(Link* self, void* content);
LinkNode* link_getNode(Link* self, int64_t id);
int32_t link_getSize(Link* self);
Link* New_link(void* args);
#endif

View File

@ -1,20 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "dataLinkNode.h"
#include "dataArg.h"
#include "dataMemory.h"
void linkNode_deinit(LinkNode* self) {
arg_deinit(self);
}
void linkNode_init(LinkNode* self, void* args) {
/* attribute */
}
LinkNode* New_linkNode(void* args) {
return NULL;
}

View File

@ -1,15 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef _linkNode__H
#define _linkNode__H
#include "dataMemory.h"
typedef uint8_t LinkNode;
void linkNode_deinit(LinkNode* self);
void linkNode_init(LinkNode* self, void* args);
LinkNode* New_linkNode(void* args);
#endif

View File

@ -1,44 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "dataMemory.h"
#include <stdint.h>
#include <stdlib.h>
PikaMemInfo pikaMemInfo = {0};
void* pikaMalloc(uint32_t size) {
pikaMemInfo.heapUsed += size;
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
}
__platformDisableIrqHandle();
void* mem = __platformMalloc(size);
__platformEnableIrqHandle();
if (NULL == mem) {
__platformPrintf("[error]: No heap space! Please reset the device.\r\n");
while (1) {
}
}
return mem;
}
void pikaFree(void* mem, uint32_t size) {
__platformDisableIrqHandle();
__platformFree(mem);
__platformEnableIrqHandle();
pikaMemInfo.heapUsed -= size;
}
uint16_t pikaMemNow(void) {
return pikaMemInfo.heapUsed;
}
uint16_t pikaMemMax(void) {
return pikaMemInfo.heapUsedMax;
}
void pikaMemMaxReset(void) {
pikaMemInfo.heapUsedMax = 0;
}

View File

@ -1,24 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef __MEMORY_H__
#define __MEMORY_H__
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "pikaPlatform.h"
typedef struct {
uint32_t heapUsed;
uint32_t heapUsedMax;
} PikaMemInfo;
void pikaFree(void* mem, uint32_t size);
void* pikaMalloc(uint32_t size);
uint16_t pikaMemNow(void);
uint16_t pikaMemMax(void);
void pikaMemMaxReset(void);
#endif

View File

@ -1,267 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "dataString.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* strAppendWithSize_unlimited(char* strOut, char* pData, int32_t Size) {
int32_t strOut_i = strGetSize(strOut);
for (int32_t i = 0; i < Size; i++) {
strOut[strOut_i + i] = pData[i];
}
strOut_i += Size;
// add \0 to the end of strOut
strOut[strOut_i] = 0;
return strOut;
}
char* strCut(char* strOut, char* strIn, char startSign, char endSign) {
int32_t Size = strGetSize(strIn);
int32_t isStart = 0;
int32_t isEnd = 0;
int32_t iOut = 0;
for (int32_t i = 0; i < Size; i++) {
if (!isStart && (strIn[i] == startSign)) {
isStart = 1;
continue;
}
if (isStart && (strIn[i] == endSign)) {
isEnd = 1;
break;
}
if (isStart) {
strOut[iOut] = strIn[i];
iOut++;
}
}
/* add \0 */
strOut[iOut] = 0;
if (isStart && isEnd) {
/* succeed */
return strOut;
}
/* faild */
return NULL;
}
char* strDeleteChar(char* strOut, char* strIn, char ch) {
int32_t iOut = 0;
for (int32_t i = 0; i < strGetSize(strIn); i++) {
if (ch == strIn[i]) {
continue;
}
strOut[iOut] = strIn[i];
iOut++;
}
/* add \0 */
strOut[iOut] = 0;
return strOut;
}
char* strDeleteEnter(char* str) {
return strDeleteChar(str, str, '\n');
}
char* strAppendWithSize(char* strOut, char* pData, int32_t Size) {
int32_t strOut_i = strGetSize(strOut);
for (int32_t i = 0; i < Size; i++) {
strOut[strOut_i + i] = pData[i];
}
strOut_i += Size;
// add \0 to the end of strOut
strOut[strOut_i] = 0;
return strOut;
}
int32_t strCountSign(char* strIn, char sign) {
int32_t count = 0;
for (int32_t i = 0; i < strGetSize(strIn); i++) {
if (sign == strIn[i]) {
count++;
}
}
return count;
}
int32_t strGetTokenNum(char* strIn, char sign) {
return strCountSign(strIn, sign) + 1;
}
uint32_t strGetSize(char* pData) {
return strlen(pData);
}
char* strAppend_unlimited(char* strOut, char* pData) {
uint32_t Size = 0;
Size = strGetSize(pData);
return strAppendWithSize_unlimited(strOut, pData, Size);
}
char* strGetLastLine(char *strOut, char *strIn){
int32_t size = strGetSize(strIn);
char sign = '\n';
uint32_t beginIndex = 0;
/* skip the latest '\n' */
for (int32_t i = size - 2; i > -1; i--) {
if (strIn[i] == sign) {
beginIndex = i + 1;
break;
}
}
memcpy(strOut, strIn + beginIndex, size - beginIndex);
strOut[size - beginIndex + 1] = 0;
return strOut;
}
char* strGetLastToken(char* strOut, char* strIn, char sign) {
int32_t size = strGetSize(strIn);
int32_t isGetSign = 0;
int32_t buffSize = 0;
for (int32_t i = size - 1; i > -1; i--) {
if (strIn[i] != sign) {
strOut[size - i - 1] = strIn[i];
buffSize++;
}
if (strIn[i] == sign) {
isGetSign = 1;
break;
}
}
int32_t i = 0;
for (i = 0; i < buffSize / 2; i++) {
char buff = strOut[i];
strOut[i] = strOut[buffSize - i - 1];
strOut[buffSize - i - 1] = buff;
}
strOut[buffSize] = 0;
return strOut;
}
char* strPopToken(char* strOut, char* strIn, char sign) {
int32_t getSign = 0;
int32_t iPoped = 0;
int32_t iOut = 0;
int32_t size = strGetSize(strIn);
int32_t i = 0;
for (i = 0; i < size; i++) {
if (getSign) {
strIn[iPoped++] = strIn[i];
continue;
}
if (strIn[i] != sign) {
strOut[iOut++] = strIn[i];
continue;
}
if (strIn[i] == sign) {
getSign = 1;
continue;
}
}
strOut[iOut] = 0;
strIn[iPoped] = 0;
return strOut;
}
char* strGetFirstToken(char* strOut, char* strIn, char sign) {
int32_t size = strGetSize(strIn);
for (int32_t i = 0; i < size; i++) {
if (strIn[i] != sign) {
strOut[i] = strIn[i];
}
if (strIn[i] == sign) {
break;
}
}
return strOut;
}
int32_t strGetToken(char* string, char** argv, char sign) {
int32_t argc = 0;
int32_t i = 0;
// arg_i point32_t to the arg operated now
int32_t arg_i = 0;
// if not found ' ', then put chars from CMD to argv_tem
int32_t char_i = 0;
for (i = 0; (i < strGetSize(string)); i++) {
if (string[i] != sign) {
argv[arg_i][char_i] = string[i];
char_i++;
}
if (string[i] == sign) {
// write '\0' to the end of argv
argv[arg_i][char_i] = 0;
arg_i++;
char_i = 0;
}
// write '\0' to the end of last argv
argv[arg_i][char_i] = 0;
}
argc = arg_i + 1;
return argc;
}
char* strAppend(char* strOut, char* pData) {
uint32_t Size = 0;
Size = strGetSize(pData);
return strAppendWithSize(strOut, pData, Size);
}
int32_t strIsStartWith(char* str, char* strStart) {
if (NULL == str || NULL == strStart) {
/* input is null */
return 0;
}
uint32_t size = strGetSize(strStart);
uint32_t CMDName_get = 1;
for (int32_t i = 0; i < size; i++) {
if (str[i] != strStart[i]) {
CMDName_get = 0;
}
}
return CMDName_get;
}
int32_t strEqu(char* str1, char* str2) {
return !strcmp(str1, str2);
}
char* strRemovePrefix(char* inputStr, char* prefix, char* outputStr) {
if (!strIsStartWith(inputStr, prefix)) {
return NULL;
}
for (int32_t i = strGetSize(prefix); i < strGetSize(inputStr); i++) {
outputStr[i - strGetSize(prefix)] = inputStr[i];
}
return outputStr;
}
char* strClear(char* str) {
for (int32_t i = 0; i < sizeof(str); i++) {
str[i] = 0;
}
return str;
}
int32_t strIsContain(char* str, char ch) {
for (int32_t i = 0; i < strGetSize(str); i++) {
if (str[i] == ch) {
return 1;
}
}
return 0;
}
char* strCopy(char* strBuff, char* strIn) {
memcpy(strBuff, strIn, strGetSize(strIn));
return strBuff;
}

View File

@ -1,38 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef __MY_TEST_TOOLS_H
#define __MY_TEST_TOOLS_H
#include <stdint.h>
/* size */
uint32_t strGetSize(char* pData);
/* append */
char* strAppend(char* strOut, char* pData);
char* strAppend_unlimited(char* strOut, char* pData);
char* strAppendWithSize(char* strOut, char* pData, int32_t Size);
/* cut */
char* strCut(char* strOut, char* strIn, char startSign, char endSign);
/* assert */
int32_t strIsStartWith(char* str, char* strStart);
int32_t strEqu(char* str1, char* str2);
/* delete */
char* strDeleteEnter(char* str);
char* strDeleteChar(char* strOut, char* strIn, char ch);
/* prefix */
char* strRemovePrefix(char* inputStr, char* prefix, char* outputStr);
/* token */
int32_t strGetToken(char* string, char** argv, char sign);
char* strPopToken(char* strOut, char* strIn, char sign);
int32_t strCountSign(char* strIn, char sign);
int32_t strGetTokenNum(char* strIn, char sign);
char* strGetFirstToken(char* strOut, char* strIn, char sign);
char* strGetLastToken(char* strOut, char* strIn, char sign);
char* strClear(char* str);
int32_t strIsContain(char* str, char ch);
char* strCopy(char* strBuff, char* strIn);
char* strGetLastLine(char *strOut, char *strIn);
#endif

View File

@ -1,105 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "dataStrs.h"
#include <stdarg.h>
#include <stdio.h>
#include "dataString.h"
Args* New_strBuff(void) {
return New_args(NULL);
}
char* strsRemovePrefix(Args* buffs, char* inputStr, char* prefix) {
int32_t size = strGetSize(inputStr);
char* buff = args_getBuff(buffs, size);
return strRemovePrefix(inputStr, prefix, buff);
}
char* strsGetDirectStr(Args* buffs, char* argPath) {
char* directStr = NULL;
directStr = strsCut(buffs, argPath, '"', '"');
if (NULL != directStr) {
return directStr;
}
directStr = strsCut(buffs, argPath, '\'', '\'');
if (NULL != directStr) {
return directStr;
}
return NULL;
}
char* strsAppend(Args* buffs, char* strOrigin, char* strToAppend) {
int32_t size = strGetSize(strOrigin) + strGetSize(strToAppend);
char* buff = args_getBuff(buffs, size);
char* strOut = strCopy(buff, strOrigin);
strAppend(strOut, strToAppend);
return strOut;
}
char* strsGetLastToken(Args* buffs, char* argPath, char sign) {
int32_t size = strGetSize(argPath);
char* buff = args_getBuff(buffs, size);
return strGetLastToken(buff, argPath, sign);
}
char* strsCut(Args* buffs, char* strIn, char startSign, char endSign) {
int32_t size = strGetSize(strIn);
char* buff = args_getBuff(buffs, size);
return strCut(buff, strIn, startSign, endSign);
}
char* strsDeleteChar(Args* buffs, char* strIn, char ch) {
int32_t size = strGetSize(strIn);
return strDeleteChar(args_getBuff(buffs, size), strIn, ch);
}
char* strsGetFirstToken(Args* buffs, char* strIn, char sign) {
int32_t size = strGetSize(strIn);
return strGetFirstToken(args_getBuff(buffs, size), strIn, sign);
}
char* strsPopToken(Args* buffs, char* tokens, char sign) {
int32_t size = strGetSize(tokens);
char* buff = args_getBuff(buffs, size);
return strPopToken(buff, tokens, sign);
}
char* strsCopy(Args* buffs, char* source) {
int32_t size = strGetSize(source);
char* buff = args_getBuff(buffs, size);
return strCopy(buff, source);
}
char* strsFormat(Args* buffs, uint16_t buffSize, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
char* res = args_getBuff(buffs, buffSize);
vsnprintf(res, buffSize, fmt, args);
va_end(args);
return res;
}
char* strsGetCleanCmd(Args* buffs, char* cmd) {
int32_t size = strGetSize(cmd);
char* strOut = args_getBuff(buffs, size);
int32_t iOut = 0;
char delChar = ' ';
int32_t isInStr = 0;
for (int32_t i = 0; i < strGetSize(cmd); i++) {
if ('\'' == cmd[i] || '\"' == cmd[i]) {
isInStr = !isInStr;
}
if ((delChar == cmd[i]) && (!isInStr)) {
/* do not load char */
continue;
}
strOut[iOut] = cmd[i];
iOut++;
}
/* add \0 */
strOut[iOut] = 0;
return strOut;
}

View File

@ -1,21 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef __STR_ARGS__H
#define __STR_ARGS__H
#include "dataArgs.h"
Args* New_strBuff(void);
char* strsGetFirstToken(Args* buffs, char* strIn, char sign);
char* strsGetLastToken(Args* buffs, char* arg_Path, char sign);
char* strsPopToken(Args* buffs, char* tokens, char sign);
char* strsCopy(Args* buffs, char* source);
char* strsDeleteChar(Args* buff, char* strIn, char ch);
char* strsCut(Args* buffs, char* strIn, char startSign, char endSign);
char* strsRemovePrefix(Args* buffs, char* inputStr, char* prefix);
char* strsAppend(Args* buffs, char* strOrigin, char* strAppend);
char* strsFormat(Args* buffs, uint16_t buffSize, const char* fmt, ...);
char* strsGetDirectStr(Args* buffs, char* argPath);
char* strsGetCleanCmd(Args* buffs, char* cmd);
#endif

View File

@ -1,30 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#include "PikaObj.h"
#include "dataArgs.h"
void method_returnStr(Args* args, char* val) {
args_setStr(args, "return", val);
}
void method_returnInt(Args* args, int32_t val) {
args_setInt(args, "return", val);
}
void method_returnFloat(Args* args, float val) {
args_setFloat(args, "return", val);
}
void method_returnPtr(Args* args, void* val) {
args_setPtr(args, "return", val);
}
int32_t method_getInt(Args* args, char* argName) {
return args_getInt(args, argName);
}
float method_getFloat(Args* args, char* argName) {
return args_getFloat(args, argName);
}
char* method_getStr(Args* args, char* argName) {
return args_getStr(args, argName);
}

View File

@ -1,16 +0,0 @@
/*
Author: lyon
Tencent QQ: 645275593
*/
#ifndef METHOD__H
#define METHOD__H
#include "dataArgs.h"
void method_returnStr(Args* args, char* val);
void method_returnInt(Args* args, int32_t val);
void method_returnFloat(Args* args, float val);
void method_returnPtr(Args* args, void* val);
int32_t method_getInt(Args* args, char* argName);
float method_getFloat(Args* args, char* argName);
char* method_getStr(Args* args, char* argName);
#endif

View File

@ -1,29 +0,0 @@
#include "pikaPlatform.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
PIKA_WEAK void __platformDisableIrqHandle() {
/* disable irq to support thread */
}
PIKA_WEAK void __platformEnableIrqHandle() {
/* disable irq to support thread */
}
PIKA_WEAK void* __platformMalloc(size_t size) {
return malloc(size);
}
PIKA_WEAK void __platformFree(void* ptr) {
return free(ptr);
}
PIKA_WEAK void __platformPrintf(char* fmt, ...) {
va_list args;
va_start(args, fmt);
char sysOut[128] = {0};
vprintf(fmt, args);
va_end(args);
}

View File

@ -1,19 +0,0 @@
#ifndef __PIKA_PALTFORM__H
#define __PIKA_PALTFORM__H
#include <stdlib.h>
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */
#define PIKA_WEAK __attribute__((weak))
#elif defined(__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
#define PIKA_WEAK __weak
#elif defined(__GNUC__) /* GNU GCC Compiler */
#define PIKA_WEAK __attribute__((weak))
#endif
void __platformPrintf(char* fmt, ...);
void* __platformMalloc(size_t size);
void __platformFree(void* ptr);
void __platformEnableIrqHandle();
void __platformDisableIrqHandle();
#endif

View File

@ -1,21 +0,0 @@
from PikaObj import *
import PikaStdLib
import STM32
class RGB(PikaStdLib.SysObj):
pin = STM32.GPIO()
def init():
pass
def enable():
pass
def red():
pass
def green():
pass
def blue():
pass
def white():
pass
def flow():
pass

View File

@ -1,95 +0,0 @@
#include "PikaPiZero_RGB.h"
#include <stdint.h>
#include "BaseObj.h"
#include "RGB_ASM.h"
#include "STM32_common.h"
#include "dataStrs.h"
void RGB_reset() {
GPIOB->BRR = GPIO_PIN_12; // reset
delay_us(50);
}
#define RED 0x000800
#define GREEN 0x080000
#define BLUE 0x000008
#define WHITE 0x080808
#define CUTDOWN 0x000000
void RGB_setVoid() {
__asm("nop");
}
void PikaPiZero_RGB_enable(PikaObj* self) {
obj_run(self, "pin.init()");
obj_run(self, "pin.setPin('PB12')");
obj_run(self, "pin.setMode('out')");
obj_run(self, "pin.enable()");
}
void PikaPiZero_RGB_init(PikaObj* self) {}
void PikaPiZero_RGB_red(PikaObj* self) {
RGB_set(RED);
RGB_set(RED);
RGB_set(RED);
RGB_set(RED);
}
void PikaPiZero_RGB_blue(PikaObj* self) {
RGB_set(BLUE);
RGB_set(BLUE);
RGB_set(BLUE);
RGB_set(BLUE);
}
void PikaPiZero_RGB_green(PikaObj* self) {
RGB_set(GREEN);
RGB_set(GREEN);
RGB_set(GREEN);
RGB_set(GREEN);
}
void PikaPiZero_RGB_white(PikaObj* self) {
RGB_set(WHITE);
RGB_set(WHITE);
RGB_set(WHITE);
RGB_set(WHITE);
}
void PikaPiZero_RGB_flow(PikaObj* self) {
if (!obj_isArgExist(self, "flowState")) {
obj_setInt(self, "flowState", 0);
}
int flowState = obj_getInt(self, "flowState");
if (0 == flowState) {
RGB_set(RED);
RGB_set(BLUE);
RGB_set(GREEN);
RGB_set(WHITE);
goto exit;
}
if (1 == flowState) {
RGB_set(BLUE);
RGB_set(GREEN);
RGB_set(WHITE);
RGB_set(RED);
goto exit;
}
if (2 == flowState) {
RGB_set(GREEN);
RGB_set(WHITE);
RGB_set(RED);
RGB_set(BLUE);
goto exit;
}
if (3 == flowState) {
RGB_set(WHITE);
RGB_set(RED);
RGB_set(BLUE);
RGB_set(GREEN);
goto exit;
}
exit:
obj_setInt(self, "flowState", (flowState + 1) % 4);
}

View File

@ -1,38 +0,0 @@
#include "RGB_ASM.h"
#include "STM32_common.h"
static void RGB_setUp() {
GPIOB->BSRR = GPIO_PIN_12; // set
int i;
i++;
i++;
i++;
i++;
i++;
i++;
i++;
i++;
GPIOB->BRR = GPIO_PIN_12; // reset
}
static void RGB_setDown() {
GPIOB->BSRR = GPIO_PIN_12; // set
int i;
i++;
i++;
i++;
GPIOB->BRR = GPIO_PIN_12;
}
void RGB_set(uint32_t G8R8B8) {
int i;
uint8_t byte = 0;
for (i = 23; i >= 0; i--) {
byte = ((G8R8B8 >> i) & 0x01);
if (byte) {
RGB_setUp();
} else {
RGB_setDown();
}
}
}

View File

@ -1,3 +0,0 @@
#include <stdint.h>
void RGB_set(uint32_t G8R8B8);

View File

@ -1,80 +0,0 @@
#include "BaseObj.h"
#include "PikaStdDevice_GPIO.h"
void PikaStdDevice_GPIO_init(PikaObj* self) {
obj_setInt(self, "isEnable", 0);
obj_setStr(self, "pin", "PA0");
obj_setStr(self, "mode", "out");
obj_setInt(self, "isOn", 0);
}
void PikaStdDevice_GPIO_disable(PikaObj* self) {
obj_setInt(self, "isEnable", 0);
obj_run(self, "platformDisable()");
}
void PikaStdDevice_GPIO_enable(PikaObj* self) {
obj_setInt(self, "isEnable", 1);
obj_run(self, "platformEnable()");
}
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_run(self, "platformLow()");
}
void PikaStdDevice_GPIO_high(PikaObj* self) {
obj_setInt(self, "isOn", 1);
obj_run(self, "platformHigh()");
}
void PikaStdDevice_GPIO_setMode(PikaObj* self, char* mode) {
obj_setStr(self, "mode", mode);
obj_run(self, "platformSetMode(mode)");
}
void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) {
obj_setStr(self, "pin", pinName);
}
void PikaStdDevice_GPIO_platformDisable(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformEnable(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformLow(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self, char* mode) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformOff(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}

View File

@ -1,149 +0,0 @@
from PikaObj import *
class GPIO(TinyObj):
def init():
pass
def setPin(pinName: str):
pass
def getPin() -> str:
pass
def setMode(mode: str):
pass
def getMode() -> str:
pass
def enable():
pass
def disable():
pass
def high():
pass
def low():
pass
# need be overrid
def platformHigh():
pass
# need override
def platformLow():
pass
# need override
def platformEnable():
pass
# need override
def platformDisable():
pass
# need override
def platformSetMode(mode: str):
pass
class Time(TinyObj):
# need override
def sleep_s(s: int):
pass
# need override
def sleep_ms(ms: int):
pass
class ADC(TinyObj):
def init():
pass
def setPin(pin: str):
pass
def enable():
pass
def read() -> float:
pass
# need override
def platformEnable(pin: str):
pass
# need override
def platformRead(pin: str) -> float:
pass
class UART(TinyObj):
def init():
pass
def setBaudRate(baudRate: int):
pass
def setId(id: int):
pass
def enable():
pass
def write(data: str):
pass
def read(length: int) -> str:
pass
# need override
def platformEnable(id: int, baudRate: int):
pass
# need override
def platformWrite(id: int, data: str):
pass
# need override
def platformRead(id: int, length: int) -> str:
pass
class PWM(TinyObj):
def init():
pass
def setPin(pin: str):
pass
def setFrequency(freq: int):
pass
def setDuty(duty: float):
pass
def enable():
pass
def getFrequency() -> int:
pass
def getDuty() -> float:
pass
# need override
def platformEnable(pin: str, freq: int, duty: float):
pass
# need override
def platformSetFrequency(pin: str, freq: int):
pass
# need override
def platformSetDuty(pin: str, duty: float):
pass

View File

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

View File

@ -1,52 +0,0 @@
#include "PikaStdDevice_PWM.h"
#include "BaseObj.h"
void PikaStdDevice_PWM_init(PikaObj* self) {
obj_setStr(self, "pin", "PA8");
obj_setInt(self, "freq", 1000);
obj_setFloat(self, "duty", 0.5f);
}
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_run(self, "platformSetFrequency(pin, freq)");
}
void PikaStdDevice_PWM_setDuty(PikaObj* self, float duty) {
obj_setFloat(self, "duty", duty);
obj_run(self, "platformSetDuty(pin, duty)");
}
void PikaStdDevice_PWM_enable(PikaObj* self) {
obj_run(self, "platformEnable(pin, freq, duty)");
}
float PikaStdDevice_PWM_getDuty(PikaObj* self) {
return obj_getFloat(self, "duty");
}
int PikaStdDevice_PWM_getFrequency(PikaObj* self) {
return obj_getInt(self, "freq");
}
void PikaStdDevice_PWM_platformEnable(PikaObj* self,
float dute,
int freq,
char* pin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self,
int freq,
char* pin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}

View File

@ -1,11 +0,0 @@
#include "PikaStdDevice_Time.h"
#include "BaseObj.h"
void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}

View File

@ -1,40 +0,0 @@
#include "PikaStdDevice_UART.h"
#include "BaseObj.h"
void PikaStdDevice_UART_enable(PikaObj* self) {
obj_run(self, "platformEnable(id, baudRate)");
}
void PikaStdDevice_UART_init(PikaObj* self) {
obj_setInt(self, "baudRate", 115200);
obj_setInt(self, "id", 1);
obj_setStr(self, "readBuff", "");
}
char* PikaStdDevice_UART_read(PikaObj* self, int length) {
obj_setInt(self, "length", length);
obj_run(self, "readData = platformRead(id, length)");
return obj_getStr(self, "readData");
}
void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) {
obj_setInt(self, "baudRate", baudRate);
}
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_run(self, "platformWrite(id, writeData)");
}
void PikaStdDevice_UART_platformEnable(PikaObj* self, int baudRate, int id) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
char* PikaStdDevice_UART_platformRead(PikaObj* self, int id, int length) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
return NULL;
}
void PikaStdDevice_UART_platformWrite(PikaObj* self, char* data, int id) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}

View File

@ -1,27 +0,0 @@
from PikaObj import *
class MemChecker(BaseObj):
def max():
pass
def now():
pass
def resetMax():
pass
class SysObj(BaseObj):
def type(argPath: str):
pass
def ls(objPath: str):
pass
def remove(argPath: str):
pass
def new(objPath: str, classPath: str):
pass

View File

@ -1,14 +0,0 @@
#include "BaseObj.h"
#include "dataStrs.h"
void PikaStdLib_MemChecker_max(PikaObj* self) {
obj_sysPrintf(self, "%0.2f kB", pikaMemMax() / 1024.0);
}
void PikaStdLib_MemChecker_now(PikaObj* self) {
obj_sysPrintf(self, "%0.2f kB", pikaMemNow() / 1024.0);
}
void PikaStdLib_MemChecker_resetMax(PikaObj* self) {
pikaMemMaxReset();
}

View File

@ -1,98 +0,0 @@
#include "BaseObj.h"
#include "dataStrs.h"
static int32_t __foreach_listEachArg(Arg* argEach, Args* handleArgs) {
Args* buffs = handleArgs;
if (NULL == handleArgs) {
/* error: not handleArgs input */
return 1;
}
char* argName = strsCopy(buffs, arg_getName(argEach));
if (strIsStartWith(argName, "[")) {
/* skip */
return 0;
}
char* stringOut = args_getStr(handleArgs, "stringOut");
if (NULL == stringOut) {
// stringOut no found
return 1;
}
stringOut = strsAppend(buffs, stringOut, argName);
stringOut = strsAppend(buffs, stringOut, " ");
args_setStr(handleArgs, "stringOut", stringOut);
return 0;
}
void PikaStdLib_SysObj_ls(PikaObj* self, char* objPath) {
obj_setErrorCode(self, 0);
Args* args = New_args(NULL);
args_setStr(args, "stringOut", "");
obj_setSysOut(self, "");
if (NULL == objPath) {
/* no input obj path, use current obj */
args_foreach(self->attributeList, __foreach_listEachArg, args);
obj_setSysOut(self, args_getStr(args, "stringOut"));
goto exit;
}
PikaObj* obj = obj_getObj(self, objPath, 0);
if (NULL == obj) {
/* do not find obj */
obj_setSysOut(self, "[error] list: object no found.");
obj_setErrorCode(self, 1);
goto exit;
}
/* list args */
args_foreach(obj->attributeList, __foreach_listEachArg, args);
obj_setSysOut(self, args_getStr(args, "stringOut"));
exit:
args_deinit(args);
}
void PikaStdLib_SysObj_new(PikaObj* self, char* classPath, char* objPath) {
int32_t res = obj_newObj(self, objPath, classPath);
if (1 == res) {
obj_setSysOut(self, "[error] new: class not found .");
obj_setErrorCode(self, 1);
return;
}
}
void PikaStdLib_SysObj_remove(PikaObj* self, char* argPath) {
obj_setErrorCode(self, 0);
int32_t res = obj_removeArg(self, argPath);
if (1 == res) {
obj_setSysOut(self, "[error] del: object no found.");
obj_setErrorCode(self, 1);
return;
}
if (2 == res) {
obj_setSysOut(self, "[error] del: arg not match.");
obj_setErrorCode(self, 2);
return;
}
}
void PikaStdLib_SysObj_type(PikaObj* self, char* argPath) {
if (NULL == argPath) {
/* no input obj path, use current obj */
PikaObj* objHost = obj_getContext(self);
Arg* objArg = obj_getArg(objHost, obj_getStr(self, "_n"));
if (NULL == objArg) {
obj_setSysOut(self, "[error] type: arg no found.");
obj_setErrorCode(self, 1);
return;
}
obj_setSysOut(self, arg_getType(objArg));
return;
}
Arg* arg = obj_getArg(self, argPath);
if (NULL == arg) {
obj_setSysOut(self, "[error] type: arg no found.");
obj_setErrorCode(self, 1);
return;
}
obj_setSysOut(self, arg_getType(arg));
}

View File

@ -1,71 +0,0 @@
from typing import overload
import PikaStdDevice
class GPIO(PikaStdDevice.GPIO):
# override
def platformHigh():
pass
# override
def platformLow():
pass
# override
def platformEnable():
pass
# override
def platformDisable():
pass
# override
def platformSetMode(mode: str):
pass
class Time(PikaStdDevice.Time):
# override
def sleep_s(s: int):
pass
# override
def sleep_ms(ms: int):
pass
class ADC(PikaStdDevice.ADC):
# override
def platformEnable(pin: str):
pass
# override
def platformRead(pin: str) -> float:
pass
class UART(PikaStdDevice.UART):
# override
def platformEnable(id: int, baudRate: int):
pass
# override
def platformWrite(id: int, data: str):
pass
# override
def platformRead(id: int, length: int) -> str:
pass
class PWM(PikaStdDevice.PWM):
# override
def platformEnable(pin: str, freq: int, duty: float):
pass
# override
def platformSetFrequency(pin: str, freq: int):
pass
# override
def platformSetDuty(pin: str, duty: float):
pass

View File

@ -1,167 +0,0 @@
#include "STM32_ADC.h"
#include <stdint.h>
#include "BaseObj.h"
#include "STM32_common.h"
#include "dataStrs.h"
ADC_HandleTypeDef pika_hadc1 = {0};
uint16_t Get_Adc(ADC_HandleTypeDef* hadc, uint32_t ch) {
ADC_ChannelConfTypeDef ADC_ChanConf;
ADC_ChanConf.Channel = ch;
ADC_ChanConf.Rank = ADC_REGULAR_RANK_1;
#if (defined STM32G070xx) || (defined STM32G030xx)
ADC_ChanConf.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
#endif
#ifdef STM32F103xB
ADC_ChanConf.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
#endif
HAL_ADC_ConfigChannel(hadc, &ADC_ChanConf);
HAL_ADC_Start(hadc);
HAL_ADC_PollForConversion(hadc, 10);
return (uint16_t)HAL_ADC_GetValue(hadc);
}
void STM32_ADC_platformEnable(PikaObj* self, char* pin) {
if (!strIsStartWith(pin, "PA")) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match adc pin.");
return;
}
/* MSP Init */
#if (defined STM32G070xx) || (defined STM32G030xx)
__HAL_RCC_ADC_CLK_ENABLE();
#endif
#ifdef STM32F103xB
__HAL_RCC_ADC1_CLK_ENABLE();
#endif
if (0 != enableClk(pin)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
return;
}
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = getGpioPin(pin);
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(getGpioPort(pin), &GPIO_InitStruct);
/* init ADC */
pika_hadc1.Instance = ADC1;
#if (defined STM32G070xx) || (defined STM32G030xx)
pika_hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
pika_hadc1.Init.Resolution = ADC_RESOLUTION_12B;
pika_hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
pika_hadc1.Init.LowPowerAutoWait = DISABLE;
pika_hadc1.Init.LowPowerAutoPowerOff = DISABLE;
#endif
pika_hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
pika_hadc1.Init.ContinuousConvMode = DISABLE;
pika_hadc1.Init.DiscontinuousConvMode = DISABLE;
pika_hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
pika_hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
pika_hadc1.Init.NbrOfConversion = 1;
#if (defined STM32G070xx) || (defined STM32G030xx)
pika_hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
pika_hadc1.Init.DMAContinuousRequests = DISABLE;
pika_hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
pika_hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5;
pika_hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5;
pika_hadc1.Init.OversamplingMode = DISABLE;
pika_hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
#endif
HAL_StatusTypeDef state = HAL_ADC_Init(&pika_hadc1);
if (state != HAL_OK) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] adc init faild.");
return;
}
/* Run the ADC calibration */
if (HAL_ADCEx_Calibration_Start(&pika_hadc1) != HAL_OK) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] adc calibratie faild.");
return;
}
}
uint32_t getChannel(char* pin) {
Args* buffs = New_strBuff();
uint32_t channel = 0;
pin = strsCopy(buffs, pin + 2);
if (strEqu(pin, "0")) {
channel = ADC_CHANNEL_0;
goto exit;
}
if (strEqu(pin, "1")) {
channel = ADC_CHANNEL_1;
goto exit;
}
if (strEqu(pin, "2")) {
channel = ADC_CHANNEL_2;
goto exit;
}
if (strEqu(pin, "3")) {
channel = ADC_CHANNEL_3;
goto exit;
}
if (strEqu(pin, "4")) {
channel = ADC_CHANNEL_4;
goto exit;
}
if (strEqu(pin, "5")) {
channel = ADC_CHANNEL_5;
goto exit;
}
if (strEqu(pin, "6")) {
channel = ADC_CHANNEL_6;
goto exit;
}
if (strEqu(pin, "7")) {
channel = ADC_CHANNEL_7;
goto exit;
}
if (strEqu(pin, "8")) {
channel = ADC_CHANNEL_8;
goto exit;
}
if (strEqu(pin, "9")) {
channel = ADC_CHANNEL_9;
goto exit;
}
if (strEqu(pin, "10")) {
channel = ADC_CHANNEL_10;
goto exit;
}
if (strEqu(pin, "11")) {
channel = ADC_CHANNEL_11;
goto exit;
}
if (strEqu(pin, "12")) {
channel = ADC_CHANNEL_12;
goto exit;
}
if (strEqu(pin, "13")) {
channel = ADC_CHANNEL_13;
goto exit;
}
if (strEqu(pin, "14")) {
channel = ADC_CHANNEL_14;
goto exit;
}
if (strEqu(pin, "15")) {
channel = ADC_CHANNEL_15;
goto exit;
}
exit:
args_deinit(buffs);
return channel;
}
float STM32_ADC_platformRead(PikaObj* self, char* pin) {
return 3.3f * Get_Adc(&pika_hadc1, getChannel(pin)) / 4096.0f;
}

View File

@ -1,137 +0,0 @@
#include <stdint.h>
#include "BaseObj.h"
#include "STM32_common.h"
#include "dataStrs.h"
#include <stdlib.h>
CodeHeap codeHeap;
void STM32_Code_Init() {
codeHeap.size = 0;
codeHeap.content = pikaMalloc(codeHeap.size + 1);
codeHeap.ena = 0;
}
uint8_t STM32_Code_reciveHandler(char* data, uint32_t rxSize) {
char buff[RX_BUFF_LENGTH] = {0};
if (0 == codeHeap.ena) {
char* strLine = strGetLastLine(buff, data);
if (strIsStartWith(strLine, "import ")) {
codeHeap.reciveTime = uwTick;
codeHeap.ena = 1;
data = strLine;
rxSize = strGetSize(strLine);
}
}
if (1 == codeHeap.ena) {
codeHeap.reciveTime = uwTick;
codeHeap.oldSize = codeHeap.size;
codeHeap.size += rxSize;
codeHeap.content = realloc(codeHeap.content , codeHeap.size + 1);
memcpy(codeHeap.content + codeHeap.oldSize, data, rxSize);
codeHeap.content[codeHeap.size] = 0;
/* reciving code */
return 1;
}
/* not work */
return 0;
}
uint32_t GetPage(uint32_t Addr) {
return (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
}
void STM32_Code_flashHandler() {
if (!codeHeap.ena){
/* recive not activate */
return;
}
if ( uwTick - codeHeap.reciveTime < 200 ){
/* still reciving */
return;
}
/* transmite is finished */
uint32_t FirstPage = 0, NbOfPages = 0;
uint32_t PageError = 0;
__IO uint32_t data32 = 0, MemoryProgramStatus = 0;
static FLASH_EraseInitTypeDef EraseInitStruct = {0};
printf("==============[Programer]==============\r\n");
printf("[info]: Recived byte: %d\r\n", codeHeap.size);
printf("[info]: Programing... \r\n");
HAL_FLASH_Unlock();
/* Get the 1st page to erase */
FirstPage = GetPage(FLASH_CODE_START_ADDR);
/* Get the number of pages to erase from 1st page */
NbOfPages = GetPage(FLASH_USER_END_ADDR) - FirstPage + 1;
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Page = FirstPage;
EraseInitStruct.NbPages = NbOfPages;
printf("[info]: Erasing flash... \r\n");
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK) {
printf("[error]: Erase faild! \r\n");
while (1) {
}
}
printf("[ OK ]: Erase flash ok! \r\n");
printf("[info]: Writing flash... \r\n");
uint32_t baseAddress = FLASH_CODE_START_ADDR;
uint32_t writeAddress = 0;
uint64_t writeData64 = 0;
while (writeAddress < codeHeap.size + 1) {
writeData64 = 0;
for (int i = 7; i >= 0; i--) {
char ch = codeHeap.content[writeAddress + i];
writeData64 = writeData64 << 8;
writeData64 += ch;
}
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,
baseAddress + writeAddress,
writeData64) == HAL_OK) {
writeAddress = writeAddress + 8;
} else {
printf("[error]: Write flash faild. \r\n");
while (1) {
}
}
}
HAL_FLASH_Lock();
printf("[ OK ]: Write flash ok! \r\n");
baseAddress = FLASH_CODE_START_ADDR;
MemoryProgramStatus = 0x0;
printf("[info]: Checking flash... \r\n");
char* codeInFlash = (char*)baseAddress;
printf("\r\n");
printf("----[code in flash]-----\r\n");
printf("%s", codeInFlash);
printf("----[code in flash]-----\r\n");
printf("\r\n");
if (!strEqu(codeInFlash, codeHeap.content)) {
printf("[error]: Check flash faild.\r\n");
printf("\r\n");
printf("\r\n\r\n");
printf("---------[code in heap]----------\r\n");
printf("\r\n");
printf("%s", codeHeap.content);
printf("\r\n\r\n");
printf("---------[code in heap]----------\r\n");
while (1) {
}
}
printf("[ OK ]: Checking flash ok! \r\n");
printf("[ OK ]: Programing ok! \r\n");
printf("[info]: Restarting... \r\n");
printf("==============[Programer]==============\r\n");
printf("\r\n");
HAL_NVIC_SystemReset();
}

View File

@ -1,142 +0,0 @@
#include "STM32_GPIO.h"
#include <stdint.h>
#include "BaseObj.h"
#include "STM32_common.h"
#include "dataStrs.h"
void STM32_GPIO_platformDisable(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
char* mode = obj_getStr(self, "mode");
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
HAL_GPIO_DeInit(gpioPort, gpioPin);
}
void STM32_GPIO_platformEnable(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
char* mode = obj_getStr(self, "mode");
if (0 != enableClk(pin)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
return;
}
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
uint32_t pinMode = getPinMode(mode);
if (NULL == pinMode) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio mode.");
}
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO*/
GPIO_InitStruct.Pin = gpioPin;
GPIO_InitStruct.Mode = pinMode;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
}
void STM32_GPIO_platformLow(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
}
void STM32_GPIO_platformHigh(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
}
void STM32_GPIO_platformSetMode(PikaObj* self, char* mode) {
char* pin = obj_getStr(self, "pin");
if (0 != enableClk(pin)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
return;
}
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
uint32_t pinMode = getPinMode(mode);
if (NULL == pinMode) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio mode.");
}
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO*/
GPIO_InitStruct.Pin = gpioPin;
GPIO_InitStruct.Mode = pinMode;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
}

View File

@ -1,366 +0,0 @@
#include "STM32_PWM.h"
#include <stdint.h>
#include "BaseObj.h"
#include "STM32_common.h"
#include "dataStrs.h"
#ifdef TIM1_EXIST
TIM_HandleTypeDef pika_tim1;
#endif
#ifdef TIM2_EXIST
TIM_HandleTypeDef pika_tim2;
#endif
#ifdef TIM3_EXIST
TIM_HandleTypeDef pika_tim3;
#endif
#ifdef TIM4_EXIST
TIM_HandleTypeDef pika_tim4;
#endif
#ifdef TIM14_EXIST
TIM_HandleTypeDef pika_tim14;
#endif
#ifdef TIM16_EXIST
TIM_HandleTypeDef pika_tim16;
#endif
#ifdef TIM17_EXIST
TIM_HandleTypeDef pika_tim17;
#endif
static TIM_HandleTypeDef* getTimHandle(char* pin) {
#ifdef TIM1_EXIST
if (strEqu("PA8", pin) || strEqu("PA9", pin) || strEqu("PA10", pin) ||
strEqu("PA11", pin)) {
return &pika_tim1;
}
#endif
#ifdef TIM2_EXIST
if (strEqu("PA0", pin) || strEqu("PA1", pin) || strEqu("PA2", pin) ||
strEqu("PA3", pin)) {
return &pika_tim2;
}
#endif
#ifdef TIM3_EXIST
if (strEqu("PA6", pin) || strEqu("PA7", pin) || strEqu("PB0", pin) ||
strEqu("PB1", pin)) {
return &pika_tim3;
}
#endif
#ifdef TIM4_EXIST
if (strEqu("PB6", pin) || strEqu("PB7", pin) || strEqu("PB8", pin) ||
strEqu("PB9", pin)) {
return &pika_tim3;
}
#endif
#ifdef TIM14_EXIST
if (strEqu("PA4", pin)) {
return &pika_tim14;
}
#endif
#ifdef TIM16_EXIST
if (strEqu("PD0", pin)) {
return &pika_tim16;
}
#endif
#ifdef TIM17_EXIST
if (strEqu("PD1", pin)) {
return &pika_tim17;
}
#endif
return NULL;
}
static TIM_TypeDef* getTimInstance(char* pin) {
#ifdef TIM1_EXIST
if (strEqu("PA8", pin) || strEqu("PA9", pin) || strEqu("PA10", pin) ||
strEqu("PA11", pin)) {
return TIM1;
}
#endif
#ifdef TIM2_EXIST
if (strEqu("PA0", pin) || strEqu("PA1", pin) || strEqu("PA2", pin) ||
strEqu("PA3", pin)) {
return TIM2;
}
#endif
#ifdef TIM3_EXIST
if (strEqu("PA6", pin) || strEqu("PA7", pin) || strEqu("PB0", pin) ||
strEqu("PB1", pin)) {
return TIM3;
}
#endif
#ifdef TIM4_EXIST
if (strEqu("PB6", pin) || strEqu("PB7", pin) || strEqu("PB8", pin) ||
strEqu("PB9", pin)) {
return TIM4;
}
#endif
#ifdef TIM14_EXIST
if (strEqu("PA4", pin)) {
return TIM14;
}
#endif
#ifdef TIM16_EXIST
if (strEqu("PD0", pin)) {
return TIM16;
}
#endif
#ifdef TIM17_EXIST_EXIST
if (strEqu("PD1", pin)) {
return TIM17;
}
#endif
return NULL;
}
#if (defined STM32G030xx) || (defined STM32G070xx)
static uint32_t getGPIO_AlternateForTim(TIM_TypeDef* timInstance) {
#ifdef TIM1_EXIST
if (TIM1 == timInstance) {
return GPIO_AF2_TIM1;
}
#endif
#ifdef TIM3_EXIST
if (TIM3 == timInstance) {
return GPIO_AF1_TIM3;
}
#endif
#ifdef TIM14_EXIST
if (TIM14 == timInstance) {
return GPIO_AF4_TIM14;
}
#endif
#ifdef TIM16_EXIST
if (TIM16 == timInstance) {
return GPIO_AF2_TIM16;
}
#endif
#ifdef TIM17_EXIST
if (TIM17 == timInstance) {
return GPIO_AF2_TIM17;
}
#endif
return 0;
}
#endif
static void PWM_TimClockEnable(TIM_TypeDef* timInstance) {
#ifdef TIM1_EXIST
if (TIM1 == timInstance) {
__HAL_RCC_TIM1_CLK_ENABLE();
return;
}
#endif
#ifdef TIM2_EXIST
if (TIM2 == timInstance) {
__HAL_RCC_TIM2_CLK_ENABLE();
return;
}
#endif
#ifdef TIM3_EXIST
if (TIM3 == timInstance) {
__HAL_RCC_TIM3_CLK_ENABLE();
return;
}
#endif
#ifdef TIM4_EXIST
if (TIM4 == timInstance) {
__HAL_RCC_TIM4_CLK_ENABLE();
return;
}
#endif
#ifdef TIM14_EXIST
if (TIM14 == timInstance) {
__HAL_RCC_TIM14_CLK_ENABLE();
return;
}
#endif
#ifdef TIM16_EXIST
if (TIM16 == timInstance) {
__HAL_RCC_TIM16_CLK_ENABLE();
return;
}
#endif
#ifdef TIM17_EXIST
if (TIM17 == timInstance) {
__HAL_RCC_TIM17_CLK_ENABLE();
return;
}
#endif
}
uint8_t PWM_MspInit(char* pin) {
TIM_TypeDef* timInstance = getTimInstance(pin);
if (NULL == timInstance) {
/* this Pin do not match any PWM generator */
return 1;
}
enableClk(pin);
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = getGpioPin(pin);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
#if (defined STM32G030xx) || (defined STM32G070xx)
GPIO_InitStruct.Alternate = getGPIO_AlternateForTim(timInstance);
#endif
HAL_GPIO_Init(getGpioPort(pin), &GPIO_InitStruct);
PWM_TimClockEnable(timInstance);
return 0;
}
uint32_t getTimChennel(char* pin) {
if (strEqu("PA8", pin) || strEqu("PA0", pin) || strEqu("PA6", pin) ||
strEqu("PB6", pin) || strEqu("PA4", pin) || strEqu("PD0", pin) ||
strEqu("PD1", pin)) {
return TIM_CHANNEL_1;
}
if (strEqu("PA9", pin) || strEqu("PA1", pin) || strEqu("PB7", pin) ||
strEqu("PA7", pin)) {
return TIM_CHANNEL_2;
}
if (strEqu("PA10", pin) || strEqu("PA2", pin) || strEqu("PB8", pin) ||
strEqu("PB0", pin)) {
return TIM_CHANNEL_3;
}
if (strEqu("PA11", pin) || strEqu("PA3", pin) || strEqu("PB9", pin) ||
strEqu("PB1", pin)) {
return TIM_CHANNEL_4;
}
/* Chennel not match */
return 99999;
}
void STM32_PWM_platformEnable(PikaObj* self, float duty, int freq, char* pin) {
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
if (0 != PWM_MspInit(pin)) {
obj_setSysOut(self, "[error]: init PWM port faild.");
obj_setErrorCode(self, 1);
return;
}
TIM_HandleTypeDef* pika_tim = getTimHandle(pin);
if (NULL == pika_tim) {
obj_setSysOut(self, "[error]: can not found PWM hardware.");
obj_setErrorCode(self, 1);
return;
}
pika_tim->Instance = getTimInstance(pin);
#if (defined STM32G030xx) || (defined STM32G070xx)
pika_tim->Init.Prescaler = 64 - 1;
#endif
#if (defined STM32F103xB)
pika_tim->Init.Prescaler = 72 - 1;
#endif
pika_tim->Init.CounterMode = TIM_COUNTERMODE_UP;
/* calculate period */
pika_tim->Init.Period = (uint32_t)((float)(1000 * 1000) / (float)freq) - 1;
pika_tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
pika_tim->Init.RepetitionCounter = 0;
pika_tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(pika_tim) != HAL_OK) {
obj_setSysOut(self, "[error]: init PWM faild.");
obj_setErrorCode(self, 1);
return;
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(pika_tim, &sClockSourceConfig) != HAL_OK) {
obj_setSysOut(self, "[error]: init PWM faild.");
obj_setErrorCode(self, 1);
return;
}
if (HAL_TIM_PWM_Init(pika_tim) != HAL_OK) {
obj_setSysOut(self, "[error]: init PWM faild.");
obj_setErrorCode(self, 1);
return;
}
if (HAL_TIM_OC_Init(pika_tim) != HAL_OK) {
obj_setSysOut(self, "[error]: init PWM faild.");
obj_setErrorCode(self, 1);
return;
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
#if (defined STM32G030xx) || (defined STM32G070xx)
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
#endif
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(pika_tim, &sMasterConfig) !=
HAL_OK) {
obj_setSysOut(self, "[error]: init PWM faild.");
obj_setErrorCode(self, 1);
return;
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
/* calculate pulse by duty and freq */
sConfigOC.Pulse = (uint32_t)(pika_tim->Init.Period * duty);
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(pika_tim, &sConfigOC, getTimChennel(pin)) !=
HAL_OK) {
obj_setSysOut(self, "[error]: init PWM faild.");
obj_setErrorCode(self, 1);
return;
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 0;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
#if (defined STM32G030xx) || (defined STM32G070xx)
sBreakDeadTimeConfig.BreakFilter = 0;
sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT;
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
sBreakDeadTimeConfig.Break2Filter = 0;
sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
#endif
if (HAL_TIMEx_ConfigBreakDeadTime(pika_tim, &sBreakDeadTimeConfig) !=
HAL_OK) {
obj_setSysOut(self, "[error]: init PWM faild.");
obj_setErrorCode(self, 1);
return;
}
HAL_TIM_PWM_Start(pika_tim, getTimChennel(pin));
}
void STM32_PWM_platformSetDuty(PikaObj* self, float duty, char* pin) {
TIM_HandleTypeDef* pika_tim = getTimHandle(pin);
if (NULL == pika_tim) {
obj_setSysOut(self, "[error]: can not found PWM hardware.");
obj_setErrorCode(self, 1);
return;
}
/* update duty in run time */
if (NULL != pika_tim->Instance) {
__HAL_TIM_SET_COMPARE(pika_tim, getTimChennel(pin),
(uint32_t)(pika_tim->Init.Period * duty));
}
}
void STM32_PWM_platformSetFrequency(PikaObj* self, int freq, char* pin) {
TIM_HandleTypeDef* pika_tim = getTimHandle(pin);
if (NULL == pika_tim) {
obj_setSysOut(self, "[error]: can not found PWM hardware.");
obj_setErrorCode(self, 1);
return;
}
/* update frequency in run time */
if (NULL != pika_tim->Instance) {
__HAL_TIM_SET_AUTORELOAD(
pika_tim, (uint32_t)((float)(1000 * 1000) / (float)freq) - 1);
float duty = obj_getFloat(self, "duty");
__HAL_TIM_SET_COMPARE(pika_tim, getTimChennel(pin),
(uint32_t)(pika_tim->Init.Period * duty));
}
}

View File

@ -1,14 +0,0 @@
#include "STM32_Time.h"
#include <stdint.h>
#include "BaseObj.h"
#include "STM32_common.h"
void STM32_Time_sleep_ms(PikaObj* self, int ms) {
HAL_Delay(ms);
}
void STM32_Time_sleep_s(PikaObj* self, int s) {
for (int i = 0; i < s; i++) {
HAL_Delay(1000);
}
}

View File

@ -1,438 +0,0 @@
#include "STM32_UART.h"
#include <stdint.h>
#include "BaseObj.h"
#include "STM32_common.h"
#include "dataStrs.h"
#ifdef UART1_EXIST
pika_uart_t pika_uart1;
#endif
#ifdef UART2_EXIST
pika_uart_t pika_uart2;
#endif
#ifdef UART3_EXIST
pika_uart_t pika_uart3;
#endif
#ifdef UART4_EXIST
pika_uart_t pika_uart4;
#endif
static pika_uart_t* getPikaUart(uint8_t id) {
if (1 == id) {
return &pika_uart1;
}
if (2 == id) {
return &pika_uart2;
}
#ifdef UART3_EXIST
if (3 == id) {
return &pika_uart3;
}
#endif
#ifdef UART4_EXIST
if (4 == id) {
return &pika_uart4;
}
#endif
return NULL;
}
static void setUartObj(uint8_t id, PikaObj* obj) {
pika_uart_t* pika_uart = getPikaUart(id);
pika_uart->obj = obj;
}
static PikaObj* getUartObj(uint8_t id) {
pika_uart_t* pika_uart = getPikaUart(id);
if (NULL == pika_uart) {
return NULL;
}
return pika_uart->obj;
}
static USART_TypeDef* getUartInstance(uint8_t id) {
#ifdef UART1_EXIST
if (1 == id) {
return USART1;
}
#endif
#ifdef UART2_EXIST
if (2 == id) {
return USART2;
}
#endif
#ifdef UART3_EXIST
if (3 == id) {
return USART3;
}
#endif
#ifdef UART4_EXIST
if (4 == id) {
return USART4;
}
#endif
return NULL;
}
static uint8_t getUartId(UART_HandleTypeDef* huart) {
#ifdef UART1_EXIST
if (huart == &pika_uart1.huart) {
return 1;
}
#endif
#ifdef UART2_EXIST
if (huart == &pika_uart2.huart) {
return 2;
}
#endif
#ifdef UART3_EXIST
if (huart == &pika_uart3.huart) {
return 3;
}
#endif
#ifdef UART4_EXIST
if (huart == &pika_uart4.huart) {
return 4;
}
#endif
return 0;
}
static UART_HandleTypeDef* getUartHandle(uint8_t id) {
pika_uart_t* pika_uart = getPikaUart(id);
if (NULL == pika_uart) {
return NULL;
}
return &(pika_uart->huart);
}
static char* getUartRxBuff(uint8_t id) {
pika_uart_t* pika_uart = getPikaUart(id);
if (NULL == pika_uart) {
return NULL;
}
return pika_uart->rxBuff;
}
static uint8_t USART_UART_Init(uint32_t baudRate, uint8_t id) {
uint8_t errCode = 0;
UART_HandleTypeDef* huart = getUartHandle(id);
huart->Instance = getUartInstance(id);
if (NULL == huart->Instance) {
errCode = 5;
goto exit;
}
huart->Init.BaudRate = baudRate;
huart->Init.WordLength = UART_WORDLENGTH_8B;
huart->Init.StopBits = UART_STOPBITS_1;
huart->Init.Parity = UART_PARITY_NONE;
huart->Init.Mode = UART_MODE_TX_RX;
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart->Init.OverSampling = UART_OVERSAMPLING_16;
#if (defined STM32G070xx) || (defined STM32G030xx)
huart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart->Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
#endif
if (HAL_UART_Init(huart) != HAL_OK) {
errCode = 1;
goto exit;
}
#if (defined STM32G070xx) || (defined STM32G030xx)
if (HAL_UARTEx_SetTxFifoThreshold(huart, UART_TXFIFO_THRESHOLD_1_8) !=
HAL_OK) {
errCode = 2;
goto exit;
}
if (HAL_UARTEx_SetRxFifoThreshold(huart, UART_RXFIFO_THRESHOLD_1_8) !=
HAL_OK) {
errCode = 3;
goto exit;
}
if (HAL_UARTEx_DisableFifoMode(huart) != HAL_OK) {
errCode = 4;
goto exit;
}
#endif
exit:
return errCode;
}
static void UART_MspInit(UART_HandleTypeDef* uartHandle) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
#ifdef UART1_EXIST
if (uartHandle->Instance == USART1) {
/* USART1 clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
#if (defined STM32G070xx) || (defined STM32G030xx)
GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
#ifdef STM32F103xB
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
/* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
}
#endif
#ifdef UART2_EXIST
if (uartHandle->Instance == USART2) {
/* USART2 clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
#if (defined STM32G070xx) || (defined STM32G030xx)
GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
#ifdef STM32F103xB
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
/* USART2 interrupt Init */
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
}
#endif
#ifdef UART3_EXIST
if (uartHandle->Instance == USART3) {
/* USART3 clock enable */
__HAL_RCC_USART3_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USART3 GPIO Configuration
PA5 ------> USART3_TX
PB0 ------> USART3_RX
*/
#if (defined STM32G070xx)
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_USART3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_USART3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif
#ifdef STM32F103xB
/**USART3 GPIO Configuration
PB10 ------> USART3_TX
PB11 ------> USART3_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif
/* USART3 interrupt Init */
#if (defined STM32G070xx) || (defined STM32G030xx)
HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_4_IRQn);
#endif
#ifdef STM32F103xB
HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
#endif
}
#endif
#ifdef UART4_EXIST
#if (defined STM32G070xx)
if (uartHandle->Instance == USART4) {
/* USART4 clock enable */
__HAL_RCC_USART4_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART4 GPIO Configuration
PA0 ------> USART4_TX
PA1 ------> USART4_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_USART4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART4 interrupt Init */
HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_4_IRQn);
}
#endif
#endif
}
/* Msp handle interrupt */
#ifdef UART1_EXIST
void USART1_IRQHandler(void) {
HAL_UART_IRQHandler(&pika_uart1.huart);
}
#endif
#ifdef UART2_EXIST
void USART2_IRQHandler(void) {
HAL_UART_IRQHandler(&pika_uart2.huart);
}
#endif
#ifdef UART3_EXIST
#ifdef STM32F103xB
void USART3_IRQHandler(void) {
HAL_UART_IRQHandler(&pika_uart3.huart);
}
#endif
#endif
#if (defined UART3_EXIST) && (defined UART4_EXIST)
#if defined STM32G070xx
void USART3_4_IRQHandler(void) {
HAL_UART_IRQHandler(&pika_uart3.huart);
HAL_UART_IRQHandler(&pika_uart4.huart);
}
#endif
#endif
void STM32_UART_platformEnable(PikaObj* self, int baudRate, int id) {
#ifdef Code_ENABLE
STM32_Code_Init();
#endif
setUartObj(id, self);
UART_HandleTypeDef* huart = getUartHandle(id);
huart->Instance = getUartInstance(id);
UART_MspInit(huart);
int errCode = USART_UART_Init(baudRate, id);
if (0 != errCode) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] uart init faild.");
return;
}
HAL_UART_Receive_IT(getUartHandle(id), (uint8_t*)getUartRxBuff(id), 1);
}
char* STM32_UART_platformRead(PikaObj* self, int id, int length) {
Args* buffs = New_strBuff();
char* readBuff = NULL;
pika_uart_t* pika_uart = getPikaUart(id);
if (length >= pika_uart->rxBuffOffset) {
/* not enough str */
length = pika_uart->rxBuffOffset;
}
readBuff = args_getBuff(buffs, length);
memcpy(readBuff, pika_uart->rxBuff, length);
obj_setStr(self, "readBuff", readBuff);
readBuff = obj_getStr(self, "readBuff");
/* update rxBuff */
memcpy(pika_uart->rxBuff, pika_uart->rxBuff + length,
pika_uart->rxBuffOffset - length);
pika_uart->rxBuffOffset -= length;
pika_uart->rxBuff[pika_uart->rxBuffOffset] = 0;
UART_Start_Receive_IT(
&pika_uart->huart,
(uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
exit:
args_deinit(buffs);
return readBuff;
}
void STM32_UART_platformWrite(PikaObj* self, char* data, int id) {
HAL_UART_Transmit(getUartHandle(id), (uint8_t*)data, strGetSize(data), 100);
}
void STM32_UART_clearRxBuff(pika_uart_t* pika_uart) {
pika_uart->rxBuffOffset = 0;
pika_uart->rxBuff[pika_uart->rxBuffOffset] = 0;
UART_Start_Receive_IT(
&pika_uart->huart,
(uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
}
/* Recive Interrupt Handler */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
uint8_t id = getUartId(huart);
pika_uart_t* pika_uart = getPikaUart(id);
char inputChar = pika_uart->rxBuff[pika_uart->rxBuffOffset];
if ((id == 1) && ('\n' == inputChar)) {
#ifdef Code_ENABLE
uint8_t res = STM32_Code_reciveHandler(pika_uart->rxBuff,
pika_uart->rxBuffOffset + 1);
/* handler is working */
if (0 != res) {
STM32_UART_clearRxBuff(pika_uart);
return;
}
#endif
}
/* avoid recive buff overflow */
if (pika_uart->rxBuffOffset + 2 > RX_BUFF_LENGTH) {
memmove(pika_uart->rxBuff, pika_uart->rxBuff + 1, RX_BUFF_LENGTH);
UART_Start_Receive_IT(
huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
return;
}
/* recive next char */
pika_uart->rxBuffOffset++;
pika_uart->rxBuff[pika_uart->rxBuffOffset] = 0;
UART_Start_Receive_IT(
huart, (uint8_t*)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
}
/* support prinf */
int fputc(int ch, FILE* f) {
HAL_UART_Transmit(&pika_uart1.huart, (uint8_t*)&ch, 1, 0xffff);
return ch;
}
/* support scanf */
int fgetc(FILE* f) {
uint8_t ch = 0;
HAL_UART_Receive(&pika_uart1.huart, &ch, 1, 0xffff);
return ch;
}

View File

@ -1,168 +0,0 @@
#include "STM32_common.h"
#include "dataStrs.h"
void __platformDisableIrqHandle(){
__disable_irq();
}
void __platformEnableIrqHandle(){
__enable_irq();
}
void delay_unit(uint32_t delays) {
/* one unit is 1/64 us */
uint32_t startval, tickn, wait;
startval = SysTick->VAL;
tickn = HAL_GetTick();
if (delays > startval) {
while (HAL_GetTick() == tickn) {
}
wait = 64000 + startval - delays;
while (wait < SysTick->VAL) {
}
} else {
wait = startval - delays;
while (wait < SysTick->VAL && HAL_GetTick() == tickn) {
}
}
}
void delay_us(uint32_t udelay) {
uint32_t startval, tickn, delays, wait;
startval = SysTick->VAL;
tickn = HAL_GetTick();
delays = udelay * 64; // delay 1us when delays = 64
if (delays > startval) {
while (HAL_GetTick() == tickn) {
}
wait = 64000 + startval - delays;
while (wait < SysTick->VAL) {
}
} else {
wait = startval - delays;
while (wait < SysTick->VAL && HAL_GetTick() == tickn) {
}
}
}
GPIO_TypeDef* getGpioPort(char* pin) {
if (strIsStartWith(pin, "PA")) {
return GPIOA;
}
if (strIsStartWith(pin, "PB")) {
return GPIOB;
}
if (strIsStartWith(pin, "PC")) {
return GPIOC;
}
if (strIsStartWith(pin, "PD")) {
return GPIOD;
}
return NULL;
}
uint16_t getGpioPin(char* pin) {
Args* buffs = New_strBuff();
uint16_t gpioPin = 0;
pin = strsCopy(buffs, pin + 2);
if (strEqu(pin, "0")) {
gpioPin = GPIO_PIN_0;
goto exit;
}
if (strEqu(pin, "1")) {
gpioPin = GPIO_PIN_1;
goto exit;
}
if (strEqu(pin, "2")) {
gpioPin = GPIO_PIN_2;
goto exit;
}
if (strEqu(pin, "3")) {
gpioPin = GPIO_PIN_3;
goto exit;
}
if (strEqu(pin, "4")) {
gpioPin = GPIO_PIN_4;
goto exit;
}
if (strEqu(pin, "5")) {
gpioPin = GPIO_PIN_5;
goto exit;
}
if (strEqu(pin, "6")) {
gpioPin = GPIO_PIN_6;
goto exit;
}
if (strEqu(pin, "7")) {
gpioPin = GPIO_PIN_7;
goto exit;
}
if (strEqu(pin, "8")) {
gpioPin = GPIO_PIN_8;
goto exit;
}
if (strEqu(pin, "9")) {
gpioPin = GPIO_PIN_9;
goto exit;
}
if (strEqu(pin, "10")) {
gpioPin = GPIO_PIN_10;
goto exit;
}
if (strEqu(pin, "11")) {
gpioPin = GPIO_PIN_11;
goto exit;
}
if (strEqu(pin, "12")) {
gpioPin = GPIO_PIN_12;
goto exit;
}
if (strEqu(pin, "13")) {
gpioPin = GPIO_PIN_13;
goto exit;
}
if (strEqu(pin, "14")) {
gpioPin = GPIO_PIN_14;
goto exit;
}
if (strEqu(pin, "15")) {
gpioPin = GPIO_PIN_15;
goto exit;
}
exit:
args_deinit(buffs);
return gpioPin;
}
uint32_t getPinMode(char* mode) {
if (strEqu(mode, "out")) {
return GPIO_MODE_OUTPUT_PP;
}
if (strEqu(mode, "in")) {
return GPIO_MODE_INPUT;
}
return NULL;
}
uint8_t enableClk(char* pin) {
if (strIsStartWith(pin, "PA")) {
__HAL_RCC_GPIOA_CLK_ENABLE();
return 0;
}
if (strIsStartWith(pin, "PB")) {
__HAL_RCC_GPIOB_CLK_ENABLE();
return 0;
}
if (strIsStartWith(pin, "PC")) {
__HAL_RCC_GPIOC_CLK_ENABLE();
return 0;
}
if (strIsStartWith(pin, "PD")) {
__HAL_RCC_GPIOD_CLK_ENABLE();
return 0;
}
return 1;
}

View File

@ -1,83 +0,0 @@
#ifndef __STM32__COMMON__H
#define __STM32__COMMON__H
#include "PikaObj.h"
#ifdef STM32G070xx
#include "stm32g0xx_hal.h"
#define UART1_EXIST
#define UART2_EXIST
#define UART3_EXIST
#define UART4_EXIST
#define TIM1_EXIST
#define TIM3_EXIST
#define TIM14_EXIST
#define TIM16_EXIST
#define TIM17_EXIST
#define Code_ENABLE
#endif
#ifdef STM32F103xB
#include "stm32f1xx_hal.h"
#define UART1_EXIST
#define UART2_EXIST
#define UART3_EXIST
#define TIM1_EXIST
#define TIM2_EXIST
#define TIM3_EXIST
#define TIM4_EXIST
#endif
#ifdef STM32G030xx
#include "stm32g0xx_hal.h"
#define UART1_EXIST
#define UART2_EXIST
#define TIM1_EXIST
#define TIM3_EXIST
#define TIM14_EXIST
#define TIM16_EXIST
#define TIM17_EXIST
#define Code_ENABLE
#endif
#define RX_BUFF_LENGTH 64
#define FLASH_CODE_START_ADDR \
(FLASH_BASE + \
((FLASH_PAGE_NB - 1) * FLASH_PAGE_SIZE)) /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR \
(FLASH_BASE + FLASH_SIZE - 1) /* End @ of user Flash area */
uint32_t GetPage(uint32_t Addr);
#define DATA_64 ((uint64_t)0x1234567812345678)
#define DATA_32 ((uint32_t)0x12345678)
typedef struct {
UART_HandleTypeDef huart;
uint8_t id;
char rxBuff[RX_BUFF_LENGTH];
uint16_t rxBuffOffset;
PikaObj* obj;
} pika_uart_t;
typedef struct _CodeHeap{
char *content;
uint32_t size;
uint8_t ena;
uint32_t reciveTime;
uint32_t oldSize;
}CodeHeap;
GPIO_TypeDef* getGpioPort(char* pin);
uint16_t getGpioPin(char* pin);
uint32_t getPinMode(char* mode);
uint8_t enableClk(char* pin);
void delay_us(uint32_t delay);
void delay_unit(uint32_t delay);
void STM32_UART_clearRxBuff(pika_uart_t* pika_uart);
uint8_t STM32_Code_reciveHandler(char *data, uint32_t rxSize);
void STM32_Code_Init();
void STM32_Code_flashHandler();
#endif