mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
use pikapackage for f103
This commit is contained in:
parent
f86ed42e98
commit
93934e84c7
BIN
example/stm32f103c8/pikascript/pikaPackage.exe
Normal file
BIN
example/stm32f103c8/pikascript/pikaPackage.exe
Normal file
Binary file not shown.
@ -15,14 +15,9 @@
|
||||
PikaObj *New_PikaMain(Args *args){
|
||||
PikaObj *self = New_PikaStdLib_SysObj(args);
|
||||
obj_import(self, "STM32_ADC", New_STM32_ADC);
|
||||
obj_newObj(self, "adc", "STM32_ADC");
|
||||
obj_import(self, "PikaStdLib_MemChecker", New_PikaStdLib_MemChecker);
|
||||
obj_newObj(self, "mem", "PikaStdLib_MemChecker");
|
||||
obj_import(self, "STM32_PWM", New_STM32_PWM);
|
||||
obj_newObj(self, "pwm", "STM32_PWM");
|
||||
obj_import(self, "STM32_Time", New_STM32_Time);
|
||||
obj_newObj(self, "time", "STM32_Time");
|
||||
obj_import(self, "STM32_UART", New_STM32_UART);
|
||||
obj_newObj(self, "uart", "STM32_UART");
|
||||
return self;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -7,13 +7,18 @@
|
||||
|
||||
PikaObj * pikaScriptInit(){
|
||||
PikaObj * pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
obj_run(pikaMain, "mem = PikaStdLib.MemChecker()");
|
||||
obj_run(pikaMain, "time = STM32.Time()");
|
||||
obj_run(pikaMain, "uart = STM32.UART()");
|
||||
obj_run(pikaMain, "uart.init()");
|
||||
obj_run(pikaMain, "uart.setBaudRate(115200)");
|
||||
obj_run(pikaMain, "uart.setId(1)");
|
||||
obj_run(pikaMain, "uart.enable()");
|
||||
obj_run(pikaMain, "adc = STM32.ADC()");
|
||||
obj_run(pikaMain, "adc.init()");
|
||||
obj_run(pikaMain, "adc.setPin('PA0')");
|
||||
obj_run(pikaMain, "adc.enable()");
|
||||
obj_run(pikaMain, "pwm = STM32.PWM()");
|
||||
obj_run(pikaMain, "pwm.init()");
|
||||
obj_run(pikaMain, "pwm.setPin('PA8')");
|
||||
obj_run(pikaMain, "pwm.setFrequency(2000)");
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "TinyObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _PikaObj_baseObj__H
|
||||
#define _PikaObj_baseObj__H
|
||||
#include "PikaObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "PikaBlock.h"
|
||||
#include <stdarg.h>
|
||||
#include "PikaObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _pikaBlock__H
|
||||
#define _pikaBlock__H
|
||||
#include "PikaObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "PikaIf.h"
|
||||
#include <stdarg.h>
|
||||
#include "PikaBlock.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _pikaIf__H
|
||||
#define _pikaIf__H
|
||||
#include "PikaObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "PikaObj.h"
|
||||
#include "dataArgs.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _invoke__H
|
||||
#define _invoke__H
|
||||
Args* obj_invoke(PikaObj* self, char* cmd);
|
||||
|
@ -1,5 +1,11 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "PikaObj.h"
|
||||
#include <stdarg.h>
|
||||
#include "BaseObj.h"
|
||||
#include "PikaBlock.h"
|
||||
#include "PikaIf.h"
|
||||
#include "PikaInvoke.h"
|
||||
@ -506,7 +512,8 @@ Args* getRightRes(PikaObj* self, char* cmd) {
|
||||
}
|
||||
res = New_args(NULL);
|
||||
args_setSysOut(res, "");
|
||||
int err = obj_getAnyArg(self, "return", cmd, 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);
|
||||
@ -609,6 +616,24 @@ Args* obj_runDirect(PikaObj* self, char* 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, ')')) {
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _Process__H
|
||||
#define _Process__H
|
||||
#include "dataArgs.h"
|
||||
|
14
example/stm32f103c8/pikascript/pikascript-core/PikaObj.py
Normal file
14
example/stm32f103c8/pikascript/pikascript-core/PikaObj.py
Normal file
@ -0,0 +1,14 @@
|
||||
class TinyObj:
|
||||
pass
|
||||
|
||||
|
||||
class BaseObj(TinyObj):
|
||||
pass
|
||||
|
||||
|
||||
def print(val: any):
|
||||
pass
|
||||
|
||||
|
||||
def set(argPath: str, val: any):
|
||||
pass
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "PikaBlock.h"
|
||||
#include "PikaObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _pikaWhile__H
|
||||
#define _pikaWhile__H
|
||||
#include "PikaObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "PikaObj.h"
|
||||
|
||||
void _UpdateHandle(PikaObj* self) {
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef __TYNYOBJ__H
|
||||
#define __TYNYOBJ__H
|
||||
#include "PikaObj.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "dataArg.h"
|
||||
|
||||
#include <stdint.h>
|
||||
@ -48,8 +53,8 @@ uint8_t* content_init(char* name,
|
||||
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* self = (uint8_t*)pikaMalloc(nextLength + sizeLength + nameSize +
|
||||
1 + size + typeSize + 1);
|
||||
|
||||
uint8_t* nextDir = self;
|
||||
uint8_t* sizeDir = nextDir + nextLength;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _arg__H
|
||||
#define _arg__H
|
||||
#include "dataMemory.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "dataArgs.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _dataArgs__H
|
||||
#define _dataArgs__H
|
||||
#include "dataArg.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "dataLink.h"
|
||||
#include "dataArg.h"
|
||||
#include "dataLinkNode.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _link2__H
|
||||
#define _link2__H
|
||||
#include "dataLinkNode.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "dataLinkNode.h"
|
||||
#include "dataArg.h"
|
||||
#include "dataMemory.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef _linkNode__H
|
||||
#define _linkNode__H
|
||||
#include "dataMemory.h"
|
||||
|
@ -1,17 +1,30 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "dataMemory.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
PikaMemInfo pikaMemInfo = {0};
|
||||
|
||||
__attribute__((weak)) void __pikaDisableIrqHandle(){
|
||||
/* disable irq to support thread */
|
||||
}
|
||||
__attribute__((weak)) void __pikaEnableIrqHandle(){
|
||||
/* disable irq to support thread */
|
||||
}
|
||||
void* pikaMalloc(uint32_t size) {
|
||||
pikaMemInfo.heapUsed += size;
|
||||
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
||||
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
||||
}
|
||||
__pikaDisableIrqHandle();
|
||||
void* mem = malloc(size);
|
||||
__pikaEnableIrqHandle();
|
||||
if (NULL == mem) {
|
||||
printf("[error]: No heap space!\r\n");
|
||||
printf("[error]: No heap space! Please reset the device.\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
@ -19,7 +32,9 @@ void* pikaMalloc(uint32_t size) {
|
||||
}
|
||||
|
||||
void pikaFree(void* mem, uint32_t size) {
|
||||
__pikaDisableIrqHandle();
|
||||
free(mem);
|
||||
__pikaEnableIrqHandle();
|
||||
pikaMemInfo.heapUsed -= size;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef __MEMORY_H__
|
||||
#define __MEMORY_H__
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "dataString.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@ -99,6 +104,24 @@ char* strAppend_unlimited(char* strOut, char* 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;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef __MY_TEST_TOOLS_H
|
||||
#define __MY_TEST_TOOLS_H
|
||||
#include <stdint.h>
|
||||
@ -28,5 +33,6 @@ 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
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "dataStrs.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef __STR_ARGS__H
|
||||
#define __STR_ARGS__H
|
||||
#include "dataArgs.h"
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#include "PikaObj.h"
|
||||
#include "dataArgs.h"
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
Author: lyon
|
||||
Tencent QQ: 645275593
|
||||
*/
|
||||
|
||||
#ifndef METHOD__H
|
||||
#define METHOD__H
|
||||
#include "dataArgs.h"
|
||||
|
@ -0,0 +1,149 @@
|
||||
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
|
@ -1,47 +1,52 @@
|
||||
#include "PikaStdDevice_PWM.h"
|
||||
#include "BaseObj.h"
|
||||
|
||||
void PikaStdDevice_PWM_init(PikaObj *self){
|
||||
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){
|
||||
void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setFrequency(PikaObj *self, int freq){
|
||||
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){
|
||||
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){
|
||||
void PikaStdDevice_PWM_enable(PikaObj* self) {
|
||||
obj_run(self, "platformEnable(pin, freq, duty)");
|
||||
}
|
||||
|
||||
float PikaStdDevice_PWM_getDuty(PikaObj *self){
|
||||
float PikaStdDevice_PWM_getDuty(PikaObj* self) {
|
||||
return obj_getFloat(self, "duty");
|
||||
}
|
||||
|
||||
int PikaStdDevice_PWM_getFrequency(PikaObj *self){
|
||||
int PikaStdDevice_PWM_getFrequency(PikaObj* self) {
|
||||
return obj_getInt(self, "freq");
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_platformEnable(PikaObj *self, float dute, int freq, char * pin){
|
||||
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){
|
||||
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){
|
||||
void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self,
|
||||
int freq,
|
||||
char* pin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
@ -29,12 +29,12 @@ 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){
|
||||
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){
|
||||
void PikaStdDevice_UART_platformWrite(PikaObj* self, char* data, int id) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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
|
71
example/stm32f103c8/pikascript/pikascript-lib/STM32/STM32.py
Normal file
71
example/stm32f103c8/pikascript/pikascript-lib/STM32/STM32.py
Normal file
@ -0,0 +1,71 @@
|
||||
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
|
@ -10,12 +10,12 @@ 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)
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
ADC_ChanConf.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
ADC_ChanConf.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
#endif
|
||||
#endif
|
||||
HAL_ADC_ConfigChannel(hadc, &ADC_ChanConf);
|
||||
HAL_ADC_Start(hadc);
|
||||
HAL_ADC_PollForConversion(hadc, 10);
|
||||
@ -29,13 +29,13 @@ void STM32_ADC_platformEnable(PikaObj* self, char* pin) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* MSP Init */
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
/* MSP Init */
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
__HAL_RCC_ADC1_CLK_ENABLE();
|
||||
#endif
|
||||
#endif
|
||||
if (0 != enableClk(pin)) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] not match gpio port.");
|
||||
@ -50,20 +50,20 @@ void STM32_ADC_platformEnable(PikaObj* self, char* pin) {
|
||||
|
||||
/* init ADC */
|
||||
pika_hadc1.Instance = ADC1;
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
#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
|
||||
#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)
|
||||
#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;
|
||||
@ -71,7 +71,7 @@ void STM32_ADC_platformEnable(PikaObj* self, char* pin) {
|
||||
pika_hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5;
|
||||
pika_hadc1.Init.OversamplingMode = DISABLE;
|
||||
pika_hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
HAL_StatusTypeDef state = HAL_ADC_Init(&pika_hadc1);
|
||||
if (state != HAL_OK) {
|
||||
|
137
example/stm32f103c8/pikascript/pikascript-lib/STM32/STM32_Code.c
Normal file
137
example/stm32f103c8/pikascript/pikascript-lib/STM32/STM32_Code.c
Normal file
@ -0,0 +1,137 @@
|
||||
#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();
|
||||
}
|
@ -137,6 +137,6 @@ void STM32_GPIO_platformSetMode(PikaObj* self, char* mode) {
|
||||
GPIO_InitStruct.Pin = gpioPin;
|
||||
GPIO_InitStruct.Mode = pinMode;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
|
||||
}
|
@ -5,186 +5,192 @@
|
||||
#include "dataStrs.h"
|
||||
|
||||
#ifdef TIM1_EXIST
|
||||
TIM_HandleTypeDef pika_tim1;
|
||||
TIM_HandleTypeDef pika_tim1;
|
||||
#endif
|
||||
#ifdef TIM2_EXIST
|
||||
TIM_HandleTypeDef pika_tim2;
|
||||
TIM_HandleTypeDef pika_tim2;
|
||||
#endif
|
||||
#ifdef TIM3_EXIST
|
||||
TIM_HandleTypeDef pika_tim3;
|
||||
TIM_HandleTypeDef pika_tim3;
|
||||
#endif
|
||||
#ifdef TIM4_EXIST
|
||||
TIM_HandleTypeDef pika_tim4;
|
||||
TIM_HandleTypeDef pika_tim4;
|
||||
#endif
|
||||
#ifdef TIM14_EXIST
|
||||
TIM_HandleTypeDef pika_tim14;
|
||||
TIM_HandleTypeDef pika_tim14;
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
TIM_HandleTypeDef pika_tim16;
|
||||
TIM_HandleTypeDef pika_tim16;
|
||||
#endif
|
||||
#ifdef TIM17_EXIST
|
||||
TIM_HandleTypeDef pika_tim17;
|
||||
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) ){
|
||||
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) ){
|
||||
#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) ){
|
||||
#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) ){
|
||||
#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) ){
|
||||
#endif
|
||||
#ifdef TIM14_EXIST
|
||||
if (strEqu("PA4", pin)) {
|
||||
return &pika_tim14;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if( strEqu("PD0", pin) ){
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if (strEqu("PD0", pin)) {
|
||||
return &pika_tim16;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM17_EXIST
|
||||
if( strEqu("PD1", pin) ){
|
||||
#endif
|
||||
#ifdef TIM17_EXIST
|
||||
if (strEqu("PD1", pin)) {
|
||||
return &pika_tim17;
|
||||
}
|
||||
#endif
|
||||
#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) ){
|
||||
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) ){
|
||||
#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) ){
|
||||
#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) ){
|
||||
#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) ){
|
||||
#endif
|
||||
#ifdef TIM14_EXIST
|
||||
if (strEqu("PA4", pin)) {
|
||||
return TIM14;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if( strEqu("PD0", pin) ){
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if (strEqu("PD0", pin)) {
|
||||
return TIM16;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM17_EXIST_EXIST
|
||||
if( strEqu("PD1", pin) ){
|
||||
#endif
|
||||
#ifdef TIM17_EXIST_EXIST
|
||||
if (strEqu("PD1", pin)) {
|
||||
return TIM17;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if (defined STM32G030xx) || (defined STM32G070xx)
|
||||
static uint32_t getGPIO_AlternateForTim(TIM_TypeDef *timInstance){
|
||||
#ifdef TIM1_EXIST
|
||||
if( TIM1 == timInstance ){
|
||||
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 ){
|
||||
#endif
|
||||
#ifdef TIM3_EXIST
|
||||
if (TIM3 == timInstance) {
|
||||
return GPIO_AF1_TIM3;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM14_EXIST
|
||||
if( TIM14 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM14_EXIST
|
||||
if (TIM14 == timInstance) {
|
||||
return GPIO_AF4_TIM14;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if( TIM16 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if (TIM16 == timInstance) {
|
||||
return GPIO_AF2_TIM16;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM17_EXIST
|
||||
if( TIM17 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM17_EXIST
|
||||
if (TIM17 == timInstance) {
|
||||
return GPIO_AF2_TIM17;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void PWM_TimClockEnable(TIM_TypeDef *timInstance){
|
||||
#ifdef TIM1_EXIST
|
||||
if( TIM1 == timInstance ){
|
||||
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 ){
|
||||
#endif
|
||||
#ifdef TIM2_EXIST
|
||||
if (TIM2 == timInstance) {
|
||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM3_EXIST
|
||||
if( TIM3 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM3_EXIST
|
||||
if (TIM3 == timInstance) {
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM4_EXIST
|
||||
if( TIM4 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM4_EXIST
|
||||
if (TIM4 == timInstance) {
|
||||
__HAL_RCC_TIM4_CLK_ENABLE();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM14_EXIST
|
||||
if( TIM14 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM14_EXIST
|
||||
if (TIM14 == timInstance) {
|
||||
__HAL_RCC_TIM14_CLK_ENABLE();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if( TIM16 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM16_EXIST
|
||||
if (TIM16 == timInstance) {
|
||||
__HAL_RCC_TIM16_CLK_ENABLE();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef TIM17_EXIST
|
||||
if( TIM17 == timInstance ){
|
||||
#endif
|
||||
#ifdef TIM17_EXIST
|
||||
if (TIM17 == timInstance) {
|
||||
__HAL_RCC_TIM17_CLK_ENABLE();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t PWM_MspInit(char* pin){
|
||||
TIM_TypeDef *timInstance = getTimInstance(pin);
|
||||
if (NULL == timInstance){
|
||||
uint8_t PWM_MspInit(char* pin) {
|
||||
TIM_TypeDef* timInstance = getTimInstance(pin);
|
||||
if (NULL == timInstance) {
|
||||
/* this Pin do not match any PWM generator */
|
||||
return 1;
|
||||
}
|
||||
@ -194,106 +200,97 @@ uint8_t PWM_MspInit(char* 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)
|
||||
#if (defined STM32G030xx) || (defined STM32G070xx)
|
||||
GPIO_InitStruct.Alternate = getGPIO_AlternateForTim(timInstance);
|
||||
#endif
|
||||
#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) ){
|
||||
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) ){
|
||||
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) ){
|
||||
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) ){
|
||||
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){
|
||||
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)){
|
||||
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){
|
||||
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
|
||||
#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.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){
|
||||
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){
|
||||
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){
|
||||
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){
|
||||
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)
|
||||
#if (defined STM32G030xx) || (defined STM32G070xx)
|
||||
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
||||
#endif
|
||||
#endif
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(pika_tim, &sMasterConfig) != HAL_OK){
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(pika_tim, &sMasterConfig) !=
|
||||
HAL_OK) {
|
||||
obj_setSysOut(self, "[error]: init PWM faild.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
@ -306,7 +303,8 @@ void STM32_PWM_platformEnable(PikaObj *self, float duty, int freq, char * pin){
|
||||
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){
|
||||
if (HAL_TIM_PWM_ConfigChannel(pika_tim, &sConfigOC, getTimChennel(pin)) !=
|
||||
HAL_OK) {
|
||||
obj_setSysOut(self, "[error]: init PWM faild.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
@ -318,7 +316,7 @@ void STM32_PWM_platformEnable(PikaObj *self, float duty, int freq, char * pin){
|
||||
sBreakDeadTimeConfig.DeadTime = 0;
|
||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||
#if (defined STM32G030xx) || (defined STM32G070xx)
|
||||
#if (defined STM32G030xx) || (defined STM32G070xx)
|
||||
sBreakDeadTimeConfig.BreakFilter = 0;
|
||||
sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT;
|
||||
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
|
||||
@ -326,8 +324,9 @@ void STM32_PWM_platformEnable(PikaObj *self, float duty, int freq, char * pin){
|
||||
sBreakDeadTimeConfig.Break2Filter = 0;
|
||||
sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT;
|
||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
#endif
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(pika_tim, &sBreakDeadTimeConfig) != HAL_OK){
|
||||
#endif
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(pika_tim, &sBreakDeadTimeConfig) !=
|
||||
HAL_OK) {
|
||||
obj_setSysOut(self, "[error]: init PWM faild.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
@ -335,30 +334,33 @@ void STM32_PWM_platformEnable(PikaObj *self, float duty, int freq, char * pin){
|
||||
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){
|
||||
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) );
|
||||
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){
|
||||
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);
|
||||
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) );
|
||||
__HAL_TIM_SET_COMPARE(pika_tim, getTimChennel(pin),
|
||||
(uint32_t)(pika_tim->Init.Period * duty));
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,23 @@
|
||||
#include "STM32_UART.h"
|
||||
#include <stdint.h>
|
||||
#include "BaseObj.h"
|
||||
#include "STM32_common.h"
|
||||
#include "dataStrs.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define RX_BUFF_LENGTH 64
|
||||
|
||||
struct _pika_uart_t {
|
||||
UART_HandleTypeDef huart;
|
||||
uint8_t id;
|
||||
char rxBuff[RX_BUFF_LENGTH];
|
||||
uint16_t rxBuffOffset;
|
||||
PikaObj *obj;
|
||||
};
|
||||
|
||||
typedef struct _pika_uart_t pika_uart_t;
|
||||
|
||||
#ifdef UART1_EXIST
|
||||
pika_uart_t pika_uart1;
|
||||
pika_uart_t pika_uart1;
|
||||
#endif
|
||||
#ifdef UART2_EXIST
|
||||
pika_uart_t pika_uart2;
|
||||
pika_uart_t pika_uart2;
|
||||
#endif
|
||||
#ifdef UART3_EXIST
|
||||
pika_uart_t pika_uart3;
|
||||
pika_uart_t pika_uart3;
|
||||
#endif
|
||||
#ifdef UART4_EXIST
|
||||
pika_uart_t pika_uart4;
|
||||
pika_uart_t pika_uart4;
|
||||
#endif
|
||||
|
||||
static pika_uart_t *getPikaUart(uint8_t id) {
|
||||
static pika_uart_t* getPikaUart(uint8_t id) {
|
||||
if (1 == id) {
|
||||
return &pika_uart1;
|
||||
}
|
||||
@ -49,20 +37,20 @@ static pika_uart_t *getPikaUart(uint8_t id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void setUartObj(uint8_t id, PikaObj *obj) {
|
||||
pika_uart_t *pika_uart = getPikaUart(id);
|
||||
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);
|
||||
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) {
|
||||
static USART_TypeDef* getUartInstance(uint8_t id) {
|
||||
#ifdef UART1_EXIST
|
||||
if (1 == id) {
|
||||
return USART1;
|
||||
@ -86,7 +74,7 @@ static USART_TypeDef *getUartInstance(uint8_t id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint8_t getUartId(UART_HandleTypeDef *huart) {
|
||||
static uint8_t getUartId(UART_HandleTypeDef* huart) {
|
||||
#ifdef UART1_EXIST
|
||||
if (huart == &pika_uart1.huart) {
|
||||
return 1;
|
||||
@ -110,16 +98,16 @@ static uint8_t getUartId(UART_HandleTypeDef *huart) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static UART_HandleTypeDef *getUartHandle(uint8_t id) {
|
||||
pika_uart_t *pika_uart = getPikaUart(id);
|
||||
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);
|
||||
static char* getUartRxBuff(uint8_t id) {
|
||||
pika_uart_t* pika_uart = getPikaUart(id);
|
||||
if (NULL == pika_uart) {
|
||||
return NULL;
|
||||
}
|
||||
@ -128,10 +116,9 @@ static char *getUartRxBuff(uint8_t id) {
|
||||
|
||||
static uint8_t USART_UART_Init(uint32_t baudRate, uint8_t id) {
|
||||
uint8_t errCode = 0;
|
||||
UART_HandleTypeDef *huart = getUartHandle(id);
|
||||
UART_HandleTypeDef* huart = getUartHandle(id);
|
||||
huart->Instance = getUartInstance(id);
|
||||
if(NULL == huart->Instance)
|
||||
{
|
||||
if (NULL == huart->Instance) {
|
||||
errCode = 5;
|
||||
goto exit;
|
||||
}
|
||||
@ -171,7 +158,7 @@ exit:
|
||||
return errCode;
|
||||
}
|
||||
|
||||
static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
static void UART_MspInit(UART_HandleTypeDef* uartHandle) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
#ifdef UART1_EXIST
|
||||
if (uartHandle->Instance == USART1) {
|
||||
@ -179,19 +166,19 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
PA10 ------> USART1_RX
|
||||
*/
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
/**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
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
@ -201,7 +188,7 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
#endif
|
||||
#endif
|
||||
/* USART1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||
@ -213,19 +200,19 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**USART2 GPIO Configuration
|
||||
PA2 ------> USART2_TX
|
||||
PA3 ------> USART2_RX
|
||||
*/
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
/**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
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
@ -235,7 +222,7 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
#endif
|
||||
#endif
|
||||
/* USART2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART2_IRQn);
|
||||
@ -248,11 +235,11 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**USART3 GPIO Configuration
|
||||
PA5 ------> USART3_TX
|
||||
PB0 ------> USART3_RX
|
||||
*/
|
||||
#if (defined STM32G070xx)
|
||||
/**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;
|
||||
@ -266,9 +253,9 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF4_USART3;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef STM32F103xB
|
||||
#ifdef STM32F103xB
|
||||
/**USART3 GPIO Configuration
|
||||
PB10 ------> USART3_TX
|
||||
PB11 ------> USART3_RX
|
||||
@ -282,21 +269,21 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* USART3 interrupt Init */
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
#if (defined STM32G070xx) || (defined STM32G030xx)
|
||||
HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART3_4_IRQn);
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
#endif
|
||||
#ifdef STM32F103xB
|
||||
HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART3_IRQn);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef UART4_EXIST
|
||||
#if (defined STM32G070xx)
|
||||
#if (defined STM32G070xx)
|
||||
if (uartHandle->Instance == USART4) {
|
||||
/* USART4 clock enable */
|
||||
__HAL_RCC_USART4_CLK_ENABLE();
|
||||
@ -317,35 +304,44 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART3_4_IRQn);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Msp handle interrupt */
|
||||
#ifdef UART1_EXIST
|
||||
void USART1_IRQHandler(void) { HAL_UART_IRQHandler(&pika_uart1.huart); }
|
||||
void USART1_IRQHandler(void) {
|
||||
HAL_UART_IRQHandler(&pika_uart1.huart);
|
||||
}
|
||||
#endif
|
||||
#ifdef UART2_EXIST
|
||||
void USART2_IRQHandler(void) { HAL_UART_IRQHandler(&pika_uart2.huart); }
|
||||
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
|
||||
#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) {
|
||||
#if defined STM32G070xx
|
||||
void USART3_4_IRQHandler(void) {
|
||||
HAL_UART_IRQHandler(&pika_uart3.huart);
|
||||
HAL_UART_IRQHandler(&pika_uart4.huart);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void STM32_UART_platformEnable(PikaObj *self, int baudRate, int id) {
|
||||
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);
|
||||
UART_HandleTypeDef* huart = getUartHandle(id);
|
||||
huart->Instance = getUartInstance(id);
|
||||
UART_MspInit(huart);
|
||||
int errCode = USART_UART_Init(baudRate, id);
|
||||
@ -354,13 +350,13 @@ void STM32_UART_platformEnable(PikaObj *self, int baudRate, int id) {
|
||||
obj_setSysOut(self, "[error] uart init faild.");
|
||||
return;
|
||||
}
|
||||
HAL_UART_Receive_IT(getUartHandle(id), (uint8_t *)getUartRxBuff(id), 1);
|
||||
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);
|
||||
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;
|
||||
@ -374,42 +370,68 @@ char *STM32_UART_platformRead(PikaObj *self, int id, int length) {
|
||||
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);
|
||||
(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_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) {
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
|
||||
uint8_t id = getUartId(huart);
|
||||
pika_uart_t *pika_uart = getPikaUart(id);
|
||||
pika_uart_t* pika_uart = getPikaUart(id);
|
||||
char inputChar = pika_uart->rxBuff[pika_uart->rxBuffOffset];
|
||||
|
||||
/* avoid recive buff overflow */
|
||||
if (pika_uart->rxBuffOffset + 1 < RX_BUFF_LENGTH) {
|
||||
pika_uart->rxBuffOffset++;
|
||||
}
|
||||
UART_Start_Receive_IT(
|
||||
huart, (uint8_t *)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
|
||||
goto exit;
|
||||
exit:
|
||||
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);
|
||||
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) {
|
||||
int fgetc(FILE* f) {
|
||||
uint8_t ch = 0;
|
||||
HAL_UART_Receive(&pika_uart1.huart, &ch, 1, 0xffff);
|
||||
return ch;
|
||||
|
@ -1,6 +1,44 @@
|
||||
#include "STM32_common.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
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;
|
||||
|
@ -1,41 +1,76 @@
|
||||
#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
|
||||
#include "stm32g0xx_hal.h"
|
||||
#define UART1_EXIST
|
||||
#define UART2_EXIST
|
||||
#define UART3_EXIST
|
||||
#define UART4_EXIST
|
||||
#endif
|
||||
|
||||
#ifdef STM32F103xB
|
||||
#include "stm32f1xx_hal.h"
|
||||
#define UART1_EXIST
|
||||
#define UART2_EXIST
|
||||
#define UART3_EXIST
|
||||
#define UART1_EXIST
|
||||
#define UART2_EXIST
|
||||
#define UART3_EXIST
|
||||
|
||||
#define TIM1_EXIST
|
||||
#define TIM2_EXIST
|
||||
#define TIM3_EXIST
|
||||
#define TIM4_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
|
||||
#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 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
|
4
example/stm32f103c8/pikascript/requestment.txt
Normal file
4
example/stm32f103c8/pikascript/requestment.txt
Normal file
@ -0,0 +1,4 @@
|
||||
pikascript-core==latest
|
||||
PikaStdLib==v1.0.1
|
||||
PikaStdDevice==v1.3.0
|
||||
STM32==latest
|
Binary file not shown.
Binary file not shown.
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
@ -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;
|
||||
}
|
||||
|
@ -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
|
@ -137,6 +137,6 @@ void STM32_GPIO_platformSetMode(PikaObj* self, char* mode) {
|
||||
GPIO_InitStruct.Pin = gpioPin;
|
||||
GPIO_InitStruct.Mode = pinMode;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
|
||||
}
|
@ -337,7 +337,9 @@ void USART3_4_IRQHandler(void) {
|
||||
#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);
|
||||
@ -397,6 +399,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
|
||||
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 */
|
||||
@ -404,6 +407,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
|
||||
STM32_UART_clearRxBuff(pika_uart);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* avoid recive buff overflow */
|
||||
if (pika_uart->rxBuffOffset + 2 > RX_BUFF_LENGTH) {
|
||||
|
@ -32,6 +32,7 @@
|
||||
#define TIM14_EXIST
|
||||
#define TIM16_EXIST
|
||||
#define TIM17_EXIST
|
||||
#define Code_ENABLE
|
||||
#endif
|
||||
|
||||
#define RX_BUFF_LENGTH 64
|
||||
|
Loading…
x
Reference in New Issue
Block a user