mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
update PikaStdDevice to latest
This commit is contained in:
parent
3a7c26cc99
commit
4188460560
@ -17,6 +17,9 @@ class GPIO(TinyObj):
|
||||
def getMode() -> str:
|
||||
pass
|
||||
|
||||
def setPull(pull:str):
|
||||
pass
|
||||
|
||||
def enable():
|
||||
pass
|
||||
|
||||
@ -29,6 +32,9 @@ class GPIO(TinyObj):
|
||||
def low():
|
||||
pass
|
||||
|
||||
def read()->int:
|
||||
pass
|
||||
|
||||
# need be overrid
|
||||
def platformHigh():
|
||||
pass
|
||||
@ -46,7 +52,11 @@ class GPIO(TinyObj):
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformSetMode(mode: str):
|
||||
def platformSetMode():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead():
|
||||
pass
|
||||
|
||||
|
||||
@ -74,11 +84,11 @@ class ADC(TinyObj):
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformEnable(pin: str):
|
||||
def platformEnable():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead(pin: str) -> float:
|
||||
def platformRead():
|
||||
pass
|
||||
|
||||
|
||||
@ -102,15 +112,50 @@ class UART(TinyObj):
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformEnable(id: int, baudRate: int):
|
||||
def platformEnable():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformWrite(id: int, data: str):
|
||||
def platformWrite():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead(id: int, length: int) -> str:
|
||||
def platformRead():
|
||||
pass
|
||||
|
||||
|
||||
class IIC(TinyObj):
|
||||
def init():
|
||||
pass
|
||||
|
||||
def setPinSCL(pin: str):
|
||||
pass
|
||||
|
||||
def setPinSDA(pin: str):
|
||||
pass
|
||||
|
||||
def setDeviceAddr(addr: int):
|
||||
pass
|
||||
|
||||
def enable():
|
||||
pass
|
||||
|
||||
def write(addr: int, data: str):
|
||||
pass
|
||||
|
||||
def read(addr: int, length: int) -> str:
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformEnable():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformWrite():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead():
|
||||
pass
|
||||
|
||||
|
||||
@ -137,13 +182,13 @@ class PWM(TinyObj):
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformEnable(pin: str, freq: int, duty: float):
|
||||
def platformEnable():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformSetFrequency(pin: str, freq: int):
|
||||
def platformSetFrequency():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformSetDuty(pin: str, duty: float):
|
||||
def platformSetDuty():
|
||||
pass
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include "BaseObj.h"
|
||||
#include "PikaStdDevice_GPIO.h"
|
||||
|
||||
|
||||
void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
obj_setStr(self, "mode", "out");
|
||||
obj_setInt(self, "isOn", 0);
|
||||
obj_setStr(self, "pull", "none");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_disable(PikaObj* self) {
|
||||
@ -36,12 +38,31 @@ void PikaStdDevice_GPIO_high(PikaObj* self) {
|
||||
obj_run(self, "platformHigh()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setMode(PikaObj* self, char* mode) {
|
||||
obj_setStr(self, "mode", mode);
|
||||
obj_run(self, "platformSetMode(mode)");
|
||||
int PikaStdDevice_GPIO_read(PikaObj *self){
|
||||
obj_run(self, "platformRead()");
|
||||
return obj_getInt(self, "readBuff");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) {
|
||||
void PikaStdDevice_GPIO_setMode(PikaObj* self, char* mode) {
|
||||
if(strEqu(mode, "out")||strEqu(mode, "in")){
|
||||
obj_setStr(self, "mode", mode);
|
||||
obj_run(self, "platformSetMode()");
|
||||
}else{
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] GPIO mode should be 'out' or 'in'.");
|
||||
}
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setPull(PikaObj *self, char * pull){
|
||||
if(strEqu(pull, "up")||strEqu(pull, "down")||strEqu(pull, "none")){
|
||||
obj_setStr(self, "pull", pull);
|
||||
}else{
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] GPIO pull should be 'up', 'down' or 'none'.");
|
||||
}
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setPin(PikaObj* self, char *pinName) {
|
||||
obj_setStr(self, "pin", pinName);
|
||||
}
|
||||
|
||||
@ -64,7 +85,7 @@ void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self, char* mode) {
|
||||
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
@ -78,3 +99,8 @@ void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformRead(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
@ -0,0 +1,194 @@
|
||||
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 setPull(pull:str):
|
||||
pass
|
||||
|
||||
def enable():
|
||||
pass
|
||||
|
||||
def disable():
|
||||
pass
|
||||
|
||||
def high():
|
||||
pass
|
||||
|
||||
def low():
|
||||
pass
|
||||
|
||||
def read()->int:
|
||||
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():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead():
|
||||
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():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead():
|
||||
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():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformWrite():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead():
|
||||
pass
|
||||
|
||||
|
||||
class IIC(TinyObj):
|
||||
def init():
|
||||
pass
|
||||
|
||||
def setPinSCL(pin: str):
|
||||
pass
|
||||
|
||||
def setPinSDA(pin: str):
|
||||
pass
|
||||
|
||||
def setDeviceAddr(addr: int):
|
||||
pass
|
||||
|
||||
def enable():
|
||||
pass
|
||||
|
||||
def write(addr: int, data: str):
|
||||
pass
|
||||
|
||||
def read(addr: int, length: int) -> str:
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformEnable():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformWrite():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformRead():
|
||||
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():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformSetFrequency():
|
||||
pass
|
||||
|
||||
# need override
|
||||
def platformSetDuty():
|
||||
pass
|
@ -2,7 +2,7 @@
|
||||
#include "BaseObj.h"
|
||||
|
||||
void PikaStdDevice_ADC_enable(PikaObj* self) {
|
||||
obj_run(self, "platformEnable(pin)");
|
||||
obj_run(self, "platformEnable()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_init(PikaObj* self) {
|
||||
@ -10,21 +10,20 @@ void PikaStdDevice_ADC_init(PikaObj* self) {
|
||||
}
|
||||
|
||||
float PikaStdDevice_ADC_read(PikaObj* self) {
|
||||
obj_run(self, "val = platformRead(pin)");
|
||||
obj_run(self, "platformRead()");
|
||||
return obj_getFloat(self, "val");
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_setPin(PikaObj* self, char* pin) {
|
||||
void PikaStdDevice_ADC_setPin(PikaObj* self, char *pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformEnable(PikaObj* self, char* pin) {
|
||||
void PikaStdDevice_ADC_platformEnable(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
float PikaStdDevice_ADC_platformRead(PikaObj* self, char* pin) {
|
||||
void PikaStdDevice_ADC_platformRead(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
#include "PikaStdDevice_IIC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
void PikaStdDevice_IIC_init(PikaObj *self){
|
||||
obj_run(self, "deviceAddr = 0");
|
||||
obj_run(self, "SCLpin = 'PA0'");
|
||||
obj_run(self, "SDApin = 'PA1'");
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_enable(PikaObj *self){
|
||||
obj_run(self, "platformEnable()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_setDeviceAddr(PikaObj *self, int addr){
|
||||
obj_setInt(self, "deviceAddr", addr);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_setPinSCL(PikaObj *self, char * pin){
|
||||
obj_setStr(self, "SCLpin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_setPinSDA(PikaObj *self, char * pin){
|
||||
obj_setStr(self, "SDApin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_write(PikaObj *self, int addr, char * data){
|
||||
obj_setStr(self, "writeData", data);
|
||||
obj_setInt(self, "writeAddr", addr);
|
||||
obj_run(self, "platformWrite()");
|
||||
}
|
||||
|
||||
char * PikaStdDevice_IIC_read(PikaObj *self, int addr, int length){
|
||||
obj_setInt(self, "length", length);
|
||||
obj_setInt(self, "readAddr", addr);
|
||||
obj_run(self, "platformRead()");
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformWrite(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformEnable(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_IIC_platformRead(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
@ -13,16 +13,16 @@ void PikaStdDevice_PWM_setPin(PikaObj* self, char* pin) {
|
||||
|
||||
void PikaStdDevice_PWM_setFrequency(PikaObj* self, int freq) {
|
||||
obj_setInt(self, "freq", freq);
|
||||
obj_run(self, "platformSetFrequency(pin, freq)");
|
||||
obj_run(self, "platformSetFrequency()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_setDuty(PikaObj* self, float duty) {
|
||||
obj_setFloat(self, "duty", duty);
|
||||
obj_run(self, "platformSetDuty(pin, duty)");
|
||||
obj_run(self, "platformSetDuty()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_PWM_enable(PikaObj* self) {
|
||||
obj_run(self, "platformEnable(pin, freq, duty)");
|
||||
obj_run(self, "platformEnable()");
|
||||
}
|
||||
|
||||
float PikaStdDevice_PWM_getDuty(PikaObj* self) {
|
||||
@ -33,20 +33,15 @@ 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) {
|
||||
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) {
|
||||
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) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
@ -8,4 +8,4 @@ void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
|
||||
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "BaseObj.h"
|
||||
|
||||
void PikaStdDevice_UART_enable(PikaObj* self) {
|
||||
obj_run(self, "platformEnable(id, baudRate)");
|
||||
obj_run(self, "platformEnable()");
|
||||
}
|
||||
void PikaStdDevice_UART_init(PikaObj* self) {
|
||||
obj_setInt(self, "baudRate", 115200);
|
||||
@ -11,7 +11,7 @@ void PikaStdDevice_UART_init(PikaObj* self) {
|
||||
}
|
||||
char* PikaStdDevice_UART_read(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_run(self, "readData = platformRead(id, length)");
|
||||
obj_run(self, "platformRead()");
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) {
|
||||
@ -22,19 +22,18 @@ void PikaStdDevice_UART_setId(PikaObj* self, int id) {
|
||||
}
|
||||
void PikaStdDevice_UART_write(PikaObj* self, char* data) {
|
||||
obj_setStr(self, "writeData", data);
|
||||
obj_run(self, "platformWrite(id, writeData)");
|
||||
obj_run(self, "platformWrite()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformEnable(PikaObj* self, int baudRate, int id) {
|
||||
void PikaStdDevice_UART_platformEnable(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
char* PikaStdDevice_UART_platformRead(PikaObj* self, int id, int length) {
|
||||
void PikaStdDevice_UART_platformRead(PikaObj* self) {
|
||||
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) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user