mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
uart for g0 is ok, std device for uart is ok
This commit is contained in:
parent
c8a81fc21e
commit
a46f47c031
@ -1,40 +1,14 @@
|
||||
import PikaStdLib
|
||||
import STM32
|
||||
|
||||
mem = PikaStdLib.MemChecker()
|
||||
time = STM32.Time()
|
||||
|
||||
io1 = STM32.GPIO()
|
||||
io1.init()
|
||||
io1.setPin('PB4')
|
||||
io1.setMode('out')
|
||||
io1.enable()
|
||||
io1.low()
|
||||
|
||||
adc1 = STM32.ADC()
|
||||
adc1.init()
|
||||
adc1.setPin('PA1')
|
||||
adc1.enable()
|
||||
|
||||
uart1 = STM32.UART()
|
||||
uart1.init()
|
||||
uart1.setBaudRate(115200)
|
||||
uart1.setId(2)
|
||||
uart1.enable()
|
||||
|
||||
print('hello pikascript')
|
||||
print('mem.max :')
|
||||
mem.max()
|
||||
print('mem.now :')
|
||||
mem.now()
|
||||
uart = STM32.UART()
|
||||
uart.init()
|
||||
uart.setBaudRate(115200)
|
||||
uart.setId(1)
|
||||
uart.enable()
|
||||
|
||||
while True:
|
||||
io1.low()
|
||||
time.sleep_ms(500)
|
||||
io1.high()
|
||||
time.sleep_ms(500)
|
||||
val = adc1.read()
|
||||
print('adc1 value:')
|
||||
print(val)
|
||||
print('mem.max :')
|
||||
mem.max()
|
||||
readBuff = uart.read(2);
|
||||
print('read 2 char:')
|
||||
print(readBuff)
|
||||
|
@ -3,9 +3,6 @@
|
||||
/* ******************************** */
|
||||
#include "PikaMain.h"
|
||||
#include "PikaStdLib_SysObj.h"
|
||||
#include "STM32_ADC.h"
|
||||
#include "STM32_GPIO.h"
|
||||
#include "PikaStdLib_MemChecker.h"
|
||||
#include "STM32_Time.h"
|
||||
#include "STM32_UART.h"
|
||||
#include <stdio.h>
|
||||
@ -14,15 +11,9 @@
|
||||
|
||||
PikaObj *New_PikaMain(Args *args){
|
||||
PikaObj *self = New_PikaStdLib_SysObj(args);
|
||||
obj_import(self, "STM32_ADC", New_STM32_ADC);
|
||||
obj_newObj(self, "adc1", "STM32_ADC");
|
||||
obj_import(self, "STM32_GPIO", New_STM32_GPIO);
|
||||
obj_newObj(self, "io1", "STM32_GPIO");
|
||||
obj_import(self, "PikaStdLib_MemChecker", New_PikaStdLib_MemChecker);
|
||||
obj_newObj(self, "mem", "PikaStdLib_MemChecker");
|
||||
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, "uart1", "STM32_UART");
|
||||
obj_newObj(self, "uart", "STM32_UART");
|
||||
return self;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -7,33 +7,15 @@
|
||||
|
||||
PikaObj * pikaScriptInit(){
|
||||
PikaObj * pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
obj_run(pikaMain, "io1.init()");
|
||||
obj_run(pikaMain, "io1.setPin('PB4')");
|
||||
obj_run(pikaMain, "io1.setMode('out')");
|
||||
obj_run(pikaMain, "io1.enable()");
|
||||
obj_run(pikaMain, "io1.low()");
|
||||
obj_run(pikaMain, "adc1.init()");
|
||||
obj_run(pikaMain, "adc1.setPin('PA1')");
|
||||
obj_run(pikaMain, "adc1.enable()");
|
||||
obj_run(pikaMain, "uart1.init()");
|
||||
obj_run(pikaMain, "uart1.setBaudRate(115200)");
|
||||
obj_run(pikaMain, "uart1.setId(1)");
|
||||
obj_run(pikaMain, "uart1.enable()");
|
||||
obj_run(pikaMain, "print('hello pikascript')");
|
||||
obj_run(pikaMain, "print('mem.max :')");
|
||||
obj_run(pikaMain, "mem.max()");
|
||||
obj_run(pikaMain, "print('mem.now :')");
|
||||
obj_run(pikaMain, "mem.now()");
|
||||
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, "while True:");
|
||||
obj_run(pikaMain, " io1.low()");
|
||||
obj_run(pikaMain, " time.sleep_ms(500)");
|
||||
obj_run(pikaMain, " io1.high()");
|
||||
obj_run(pikaMain, " time.sleep_ms(500)");
|
||||
obj_run(pikaMain, " val = adc1.read()");
|
||||
obj_run(pikaMain, " print('adc1 value:')");
|
||||
obj_run(pikaMain, " print(val)");
|
||||
obj_run(pikaMain, " print('mem.max :')");
|
||||
obj_run(pikaMain, " mem.max()");
|
||||
obj_run(pikaMain, " readBuff = uart.read(2);");
|
||||
obj_run(pikaMain, " print('read 2 char:')");
|
||||
obj_run(pikaMain, " print(readBuff)");
|
||||
obj_run(pikaMain, "");
|
||||
return pikaMain;
|
||||
}
|
||||
|
@ -4,52 +4,51 @@
|
||||
#include "dataStrs.h"
|
||||
#include <stdint.h>
|
||||
|
||||
UART_HandleTypeDef pika_huart1;
|
||||
UART_HandleTypeDef pika_huart2;
|
||||
UART_HandleTypeDef pika_huart3;
|
||||
UART_HandleTypeDef pika_huart4;
|
||||
|
||||
#define RX_BUFF_LENGTH 256
|
||||
|
||||
char pika_huart1_rxBuff[RX_BUFF_LENGTH] = {0};
|
||||
char pika_huart2_rxBuff[RX_BUFF_LENGTH] = {0};
|
||||
char pika_huart3_rxBuff[RX_BUFF_LENGTH] = {0};
|
||||
char pika_huart4_rxBuff[RX_BUFF_LENGTH] = {0};
|
||||
struct _pika_uart_t
|
||||
{
|
||||
UART_HandleTypeDef huart;
|
||||
uint8_t id;
|
||||
char rxBuff[RX_BUFF_LENGTH];
|
||||
uint16_t rxBuffOffset;
|
||||
PikaObj *obj;
|
||||
};
|
||||
|
||||
PikaObj *pika_huart1_obj = NULL;
|
||||
PikaObj *pika_huart2_obj = NULL;
|
||||
PikaObj *pika_huart3_obj = NULL;
|
||||
PikaObj *pika_huart4_obj = NULL;
|
||||
typedef struct _pika_uart_t pika_uart_t;
|
||||
|
||||
pika_uart_t pika_uart1;
|
||||
pika_uart_t pika_uart2;
|
||||
pika_uart_t pika_uart3;
|
||||
pika_uart_t pika_uart4;
|
||||
|
||||
static pika_uart_t* getPikaUart(uint8_t id){
|
||||
if (1 == id){
|
||||
return &pika_uart1;
|
||||
}
|
||||
if (2 == id){
|
||||
return &pika_uart2;
|
||||
}
|
||||
if (3 == id){
|
||||
return &pika_uart3;
|
||||
}
|
||||
if (4 == id){
|
||||
return &pika_uart4;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void setUartObj(uint8_t id, PikaObj *obj) {
|
||||
if (1 == id) {
|
||||
pika_huart1_obj = obj;
|
||||
}
|
||||
if (2 == id) {
|
||||
pika_huart2_obj = obj;
|
||||
}
|
||||
if (3 == id) {
|
||||
pika_huart3_obj = obj;
|
||||
}
|
||||
if (4 == id) {
|
||||
pika_huart4_obj = obj;
|
||||
}
|
||||
pika_uart_t *pika_uart = getPikaUart(id);
|
||||
pika_uart->obj = obj;
|
||||
}
|
||||
|
||||
static PikaObj *getUartObj(uint8_t id) {
|
||||
if (1 == id) {
|
||||
return pika_huart1_obj;
|
||||
pika_uart_t *pika_uart = getPikaUart(id);
|
||||
if(NULL == pika_uart){
|
||||
return NULL;
|
||||
}
|
||||
if (2 == id) {
|
||||
return pika_huart2_obj;
|
||||
}
|
||||
if (3 == id) {
|
||||
return pika_huart3_obj;
|
||||
}
|
||||
if (4 == id) {
|
||||
return pika_huart4_obj;
|
||||
}
|
||||
return NULL;
|
||||
return pika_uart->obj;
|
||||
}
|
||||
|
||||
static USART_TypeDef *getUartInstance(uint8_t id) {
|
||||
@ -69,51 +68,35 @@ static USART_TypeDef *getUartInstance(uint8_t id) {
|
||||
}
|
||||
|
||||
static uint8_t getUartId(UART_HandleTypeDef *huart) {
|
||||
if (huart == &pika_huart1) {
|
||||
if (huart == &pika_uart1.huart) {
|
||||
return 1;
|
||||
}
|
||||
if (huart == &pika_huart2) {
|
||||
if (huart == &pika_uart2.huart) {
|
||||
return 2;
|
||||
}
|
||||
if (huart == &pika_huart3) {
|
||||
if (huart == &pika_uart3.huart) {
|
||||
return 3;
|
||||
}
|
||||
if (huart == &pika_huart4) {
|
||||
if (huart == &pika_uart4.huart) {
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static UART_HandleTypeDef *getUartHandle(uint8_t id) {
|
||||
if (1 == id) {
|
||||
return &pika_huart1;
|
||||
pika_uart_t *pika_uart = getPikaUart(id);
|
||||
if(NULL == pika_uart){
|
||||
return NULL;
|
||||
}
|
||||
if (2 == id) {
|
||||
return &pika_huart2;
|
||||
}
|
||||
if (3 == id) {
|
||||
return &pika_huart3;
|
||||
}
|
||||
if (4 == id) {
|
||||
return &pika_huart4;
|
||||
}
|
||||
return NULL;
|
||||
return &(pika_uart->huart);
|
||||
}
|
||||
|
||||
static char *getUartRxBuff(uint8_t id) {
|
||||
if (1 == id) {
|
||||
return pika_huart1_rxBuff;
|
||||
pika_uart_t *pika_uart = getPikaUart(id);
|
||||
if(NULL == pika_uart){
|
||||
return NULL;
|
||||
}
|
||||
if (2 == id) {
|
||||
return pika_huart2_rxBuff;
|
||||
}
|
||||
if (3 == id) {
|
||||
return pika_huart3_rxBuff;
|
||||
}
|
||||
if (4 == id) {
|
||||
return pika_huart4_rxBuff;
|
||||
}
|
||||
return NULL;
|
||||
return pika_uart->rxBuff;
|
||||
}
|
||||
|
||||
static uint8_t USART_UART_Init(uint32_t baudRate, uint8_t id) {
|
||||
@ -243,11 +226,11 @@ static void UART_MspInit(UART_HandleTypeDef *uartHandle) {
|
||||
}
|
||||
|
||||
/* Msp handle interrupt */
|
||||
void USART1_IRQHandler(void) { HAL_UART_IRQHandler(&pika_huart1); }
|
||||
void USART2_IRQHandler(void) { HAL_UART_IRQHandler(&pika_huart2); }
|
||||
void USART1_IRQHandler(void) { HAL_UART_IRQHandler(&pika_uart1.huart); }
|
||||
void USART2_IRQHandler(void) { HAL_UART_IRQHandler(&pika_uart2.huart); }
|
||||
void USART3_4_IRQHandler(void) {
|
||||
HAL_UART_IRQHandler(&pika_huart3);
|
||||
HAL_UART_IRQHandler(&pika_huart4);
|
||||
HAL_UART_IRQHandler(&pika_uart3.huart);
|
||||
HAL_UART_IRQHandler(&pika_uart4.huart);
|
||||
}
|
||||
|
||||
void STM32_UART_platformEnable(PikaObj *self, int baudRate, int id) {
|
||||
@ -264,7 +247,27 @@ void STM32_UART_platformEnable(PikaObj *self, int baudRate, int id) {
|
||||
HAL_UART_Receive_IT(getUartHandle(id), (uint8_t *)getUartRxBuff(id), 1);
|
||||
}
|
||||
|
||||
char *STM32_UART_platformRead(PikaObj *self, int id, int length) {}
|
||||
char *STM32_UART_platformRead(PikaObj *self, int id, int length) {
|
||||
Args *buffs= New_strBuff();
|
||||
char *readBuff = NULL;
|
||||
pika_uart_t * pika_uart = getPikaUart(id);
|
||||
if(length >= pika_uart->rxBuffOffset){
|
||||
/* not enough str */
|
||||
length = pika_uart->rxBuffOffset;
|
||||
}
|
||||
readBuff = args_getBuff(buffs, length);
|
||||
memcpy(readBuff, pika_uart->rxBuff, length);
|
||||
obj_setStr(self, "readBuff", readBuff);
|
||||
readBuff = obj_getStr(self, "readBuff");
|
||||
|
||||
/* update rxBuff */
|
||||
memcpy(pika_uart->rxBuff, pika_uart->rxBuff + length, pika_uart->rxBuffOffset - length);
|
||||
pika_uart->rxBuffOffset -= length;
|
||||
UART_Start_Receive_IT(&pika_uart->huart, (uint8_t *)(pika_uart->rxBuff + pika_uart->rxBuffOffset), 1);
|
||||
exit:
|
||||
args_deinit(buffs);
|
||||
return readBuff;
|
||||
}
|
||||
|
||||
void STM32_UART_platformWrite(PikaObj *self, char *data, int id) {
|
||||
HAL_UART_Transmit(getUartHandle(id), (uint8_t *)data, strGetSize(data), 100);
|
||||
@ -273,9 +276,13 @@ void STM32_UART_platformWrite(PikaObj *self, char *data, int id) {
|
||||
/* Recive Interrupt Handler */
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
uint8_t id = getUartId(huart);
|
||||
char *RxBuff = getUartRxBuff(id);
|
||||
uint16_t offSet = strGetSize(RxBuff);
|
||||
HAL_UART_Receive_IT(getUartHandle(id), (uint8_t *)(RxBuff + offSet), 1);
|
||||
pika_uart_t * pika_uart = getPikaUart(id);
|
||||
|
||||
/* 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:
|
||||
return;
|
||||
@ -289,7 +296,7 @@ exit:
|
||||
*/
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
HAL_UART_Transmit(&pika_huart1, (uint8_t *)&ch, 1, 0xffff);
|
||||
HAL_UART_Transmit(&pika_uart1.huart, (uint8_t *)&ch, 1, 0xffff);
|
||||
return ch;
|
||||
}
|
||||
|
||||
@ -302,6 +309,6 @@ int fputc(int ch, FILE *f)
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
uint8_t ch = 0;
|
||||
HAL_UART_Receive(&pika_huart1, &ch, 1, 0xffff);
|
||||
HAL_UART_Receive(&pika_uart1.huart, &ch, 1, 0xffff);
|
||||
return ch;
|
||||
}
|
@ -80,3 +80,35 @@ class ADC(TinyObj):
|
||||
# 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
|
||||
|
@ -1,81 +1,80 @@
|
||||
#include "BaseObj.h"
|
||||
#include "PikaStdDevice_GPIO.h"
|
||||
|
||||
void PikaStdDevice_GPIO_init(PikaObj *self){
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
obj_setStr(self, "mode", "out");
|
||||
obj_setInt(self, "isOn", 0);
|
||||
void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
obj_setStr(self, "mode", "out");
|
||||
obj_setInt(self, "isOn", 0);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_disable(PikaObj *self){
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
obj_run(self, "platformDisable()");
|
||||
void PikaStdDevice_GPIO_disable(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
obj_run(self, "platformDisable()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_enable(PikaObj *self){
|
||||
obj_setInt(self, "isEnable", 1);
|
||||
obj_run(self, "platformEnable()");
|
||||
void PikaStdDevice_GPIO_enable(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 1);
|
||||
obj_run(self, "platformEnable()");
|
||||
}
|
||||
|
||||
char *PikaStdDevice_GPIO_getMode(PikaObj *self){
|
||||
return obj_getStr(self, "mode");
|
||||
char* PikaStdDevice_GPIO_getMode(PikaObj* self) {
|
||||
return obj_getStr(self, "mode");
|
||||
}
|
||||
|
||||
char *PikaStdDevice_GPIO_getPin(PikaObj *self){
|
||||
return obj_getStr(self, "pin");
|
||||
char* PikaStdDevice_GPIO_getPin(PikaObj* self) {
|
||||
return obj_getStr(self, "pin");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_low(PikaObj *self)
|
||||
{
|
||||
obj_setInt(self, "isOn", 0);
|
||||
obj_run(self, "platformLow()");
|
||||
void PikaStdDevice_GPIO_low(PikaObj* self) {
|
||||
obj_setInt(self, "isOn", 0);
|
||||
obj_run(self, "platformLow()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_high(PikaObj *self){
|
||||
obj_setInt(self, "isOn", 1);
|
||||
obj_run(self, "platformHigh()");
|
||||
void PikaStdDevice_GPIO_high(PikaObj* self) {
|
||||
obj_setInt(self, "isOn", 1);
|
||||
obj_run(self, "platformHigh()");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setMode(PikaObj *self, char *mode){
|
||||
obj_setStr(self, "mode", mode);
|
||||
obj_run(self, "platformSetMode(mode)");
|
||||
void PikaStdDevice_GPIO_setMode(PikaObj* self, char* mode) {
|
||||
obj_setStr(self, "mode", mode);
|
||||
obj_run(self, "platformSetMode(mode)");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setPin(PikaObj *self, char *pinName){
|
||||
obj_setStr(self, "pin", pinName);
|
||||
void PikaStdDevice_GPIO_setPin(PikaObj* self, char* pinName) {
|
||||
obj_setStr(self, "pin", pinName);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformDisable(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_GPIO_platformDisable(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformEnable(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_GPIO_platformEnable(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
void PikaStdDevice_GPIO_platformLow(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_GPIO_platformLow(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformHigh(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformSetMode(PikaObj *self, char *mode){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self, char* mode) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformOff(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_GPIO_platformOff(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_platformOn(PikaObj *self){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
@ -1,30 +1,30 @@
|
||||
#include "BaseObj.h"
|
||||
#include "PikaStdDevice_ADC.h"
|
||||
#include "BaseObj.h"
|
||||
|
||||
void PikaStdDevice_ADC_enable(PikaObj *self){
|
||||
obj_run(self, "platformEnable(pin)");
|
||||
void PikaStdDevice_ADC_enable(PikaObj* self) {
|
||||
obj_run(self, "platformEnable(pin)");
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_init(PikaObj *self){
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
void PikaStdDevice_ADC_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "PA0");
|
||||
}
|
||||
|
||||
float PikaStdDevice_ADC_read(PikaObj *self){
|
||||
obj_run(self, "val = platformRead(pin)");
|
||||
return obj_getFloat(self, "val");
|
||||
float PikaStdDevice_ADC_read(PikaObj* self) {
|
||||
obj_run(self, "val = platformRead(pin)");
|
||||
return obj_getFloat(self, "val");
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_setPin(PikaObj *self, char * pin){
|
||||
obj_setStr(self, "pin", pin);
|
||||
void PikaStdDevice_ADC_setPin(PikaObj* self, char* pin) {
|
||||
obj_setStr(self, "pin", pin);
|
||||
}
|
||||
|
||||
void PikaStdDevice_ADC_platformEnable(PikaObj *self, char * pin){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_ADC_platformEnable(PikaObj* self, char* pin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
|
||||
float PikaStdDevice_ADC_platformRead(PikaObj *self, char * pin){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
return -1;
|
||||
float PikaStdDevice_ADC_platformRead(PikaObj* self, char* pin) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
return -1;
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
#include "BaseObj.h"
|
||||
#include "PikaStdDevice_Time.h"
|
||||
#include "BaseObj.h"
|
||||
|
||||
void PikaStdDeivce_Time_sleep_ms(PikaObj *self, int ms)
|
||||
{
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
void PikaStdDeivce_Time_sleep_s(PikaObj *self, int s)
|
||||
{
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#include "PikaStdDevice_UART.h"
|
||||
#include "BaseObj.h"
|
||||
|
||||
void PikaStdDevice_UART_enable(PikaObj* self) {
|
||||
obj_run(self, "platformEnable(id, baudRate)");
|
||||
}
|
||||
void PikaStdDevice_UART_init(PikaObj* self) {
|
||||
obj_setInt(self, "baudRate", 115200);
|
||||
obj_setInt(self, "id", 1);
|
||||
obj_setStr(self, "readBuff", "");
|
||||
}
|
||||
char* PikaStdDevice_UART_read(PikaObj* self, int length) {
|
||||
obj_setInt(self, "length", length);
|
||||
obj_run(self, "readData = platformRead(id, length)");
|
||||
return obj_getStr(self, "readData");
|
||||
}
|
||||
void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) {
|
||||
obj_setInt(self, "baudRate", baudRate);
|
||||
}
|
||||
void PikaStdDevice_UART_setId(PikaObj* self, int id) {
|
||||
obj_setInt(self, "id", id);
|
||||
}
|
||||
void PikaStdDevice_UART_write(PikaObj* self, char* data) {
|
||||
obj_setStr(self, "writeData", data);
|
||||
obj_run(self, "platformWrite(id, writeData)");
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformEnable(PikaObj* self, int baudRate, int id) {
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
||||
char * PikaStdDevice_UART_platformRead(PikaObj *self, int id, int length){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
return NULL;
|
||||
}
|
||||
void PikaStdDevice_UART_platformWrite(PikaObj *self, char * data, int id){
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||
}
|
@ -1,17 +1,14 @@
|
||||
#include "dataStrs.h"
|
||||
#include "BaseObj.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
void PikaStdLib_MemChecker_max(PikaObj *self)
|
||||
{
|
||||
obj_sysPrintf(self, "%0.2f kB", pikaMemMax() / 1024.0);
|
||||
void PikaStdLib_MemChecker_max(PikaObj* self) {
|
||||
obj_sysPrintf(self, "%0.2f kB", pikaMemMax() / 1024.0);
|
||||
}
|
||||
|
||||
void PikaStdLib_MemChecker_now(PikaObj *self)
|
||||
{
|
||||
obj_sysPrintf(self, "%0.2f kB", pikaMemNow() / 1024.0);
|
||||
void PikaStdLib_MemChecker_now(PikaObj* self) {
|
||||
obj_sysPrintf(self, "%0.2f kB", pikaMemNow() / 1024.0);
|
||||
}
|
||||
|
||||
void PikaStdLib_MemChecker_resetMax(PikaObj *self)
|
||||
{
|
||||
pikaMemMaxReset();
|
||||
void PikaStdLib_MemChecker_resetMax(PikaObj* self) {
|
||||
pikaMemMaxReset();
|
||||
}
|
||||
|
@ -1,114 +1,98 @@
|
||||
#include "dataStrs.h"
|
||||
#include "BaseObj.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
static int32_t __foreach_listEachArg(Arg *argEach, Args *handleArgs)
|
||||
{
|
||||
Args *buffs = handleArgs;
|
||||
if (NULL == handleArgs)
|
||||
{
|
||||
/* error: not handleArgs input */
|
||||
return 1;
|
||||
}
|
||||
static int32_t __foreach_listEachArg(Arg* argEach, Args* handleArgs) {
|
||||
Args* buffs = handleArgs;
|
||||
if (NULL == handleArgs) {
|
||||
/* error: not handleArgs input */
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *argName = strsCopy(buffs, arg_getName(argEach));
|
||||
if (strIsStartWith(argName, "["))
|
||||
{
|
||||
/* skip */
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *stringOut = args_getStr(handleArgs, "stringOut");
|
||||
if (NULL == stringOut)
|
||||
{
|
||||
// stringOut no found
|
||||
return 1;
|
||||
}
|
||||
|
||||
stringOut = strsAppend(buffs, stringOut, argName);
|
||||
stringOut = strsAppend(buffs, stringOut, " ");
|
||||
args_setStr(handleArgs, "stringOut", stringOut);
|
||||
char* argName = strsCopy(buffs, arg_getName(argEach));
|
||||
if (strIsStartWith(argName, "[")) {
|
||||
/* skip */
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* stringOut = args_getStr(handleArgs, "stringOut");
|
||||
if (NULL == stringOut) {
|
||||
// stringOut no found
|
||||
return 1;
|
||||
}
|
||||
|
||||
stringOut = strsAppend(buffs, stringOut, argName);
|
||||
stringOut = strsAppend(buffs, stringOut, " ");
|
||||
args_setStr(handleArgs, "stringOut", stringOut);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PikaStdLib_SysObj_ls(PikaObj *self, char *objPath)
|
||||
{
|
||||
obj_setErrorCode(self, 0);
|
||||
Args *args = New_args(NULL);
|
||||
args_setStr(args, "stringOut", "");
|
||||
obj_setSysOut(self, "");
|
||||
if (NULL == objPath)
|
||||
{
|
||||
/* no input obj path, use current obj */
|
||||
args_foreach(self->attributeList, __foreach_listEachArg, args);
|
||||
obj_setSysOut(self, args_getStr(args, "stringOut"));
|
||||
goto exit;
|
||||
}
|
||||
PikaObj *obj = obj_getObj(self, objPath, 0);
|
||||
if (NULL == obj)
|
||||
{
|
||||
/* do not find obj */
|
||||
obj_setSysOut(self, "[error] list: object no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
goto exit;
|
||||
}
|
||||
/* list args */
|
||||
args_foreach(obj->attributeList, __foreach_listEachArg, args);
|
||||
void PikaStdLib_SysObj_ls(PikaObj* self, char* objPath) {
|
||||
obj_setErrorCode(self, 0);
|
||||
Args* args = New_args(NULL);
|
||||
args_setStr(args, "stringOut", "");
|
||||
obj_setSysOut(self, "");
|
||||
if (NULL == objPath) {
|
||||
/* no input obj path, use current obj */
|
||||
args_foreach(self->attributeList, __foreach_listEachArg, args);
|
||||
obj_setSysOut(self, args_getStr(args, "stringOut"));
|
||||
goto exit;
|
||||
}
|
||||
PikaObj* obj = obj_getObj(self, objPath, 0);
|
||||
if (NULL == obj) {
|
||||
/* do not find obj */
|
||||
obj_setSysOut(self, "[error] list: object no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
goto exit;
|
||||
}
|
||||
/* list args */
|
||||
args_foreach(obj->attributeList, __foreach_listEachArg, args);
|
||||
obj_setSysOut(self, args_getStr(args, "stringOut"));
|
||||
exit:
|
||||
args_deinit(args);
|
||||
args_deinit(args);
|
||||
}
|
||||
|
||||
void PikaStdLib_SysObj_new(PikaObj *self, char *classPath, char *objPath)
|
||||
{
|
||||
int32_t res = obj_newObj(self, objPath, classPath);
|
||||
if (1 == res)
|
||||
{
|
||||
obj_setSysOut(self, "[error] new: class not found .");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
void PikaStdLib_SysObj_new(PikaObj* self, char* classPath, char* objPath) {
|
||||
int32_t res = obj_newObj(self, objPath, classPath);
|
||||
if (1 == res) {
|
||||
obj_setSysOut(self, "[error] new: class not found .");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PikaStdLib_SysObj_remove(PikaObj *self, char *argPath)
|
||||
{
|
||||
obj_setErrorCode(self, 0);
|
||||
int32_t res = obj_removeArg(self, argPath);
|
||||
if (1 == res)
|
||||
{
|
||||
obj_setSysOut(self, "[error] del: object no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
if (2 == res)
|
||||
{
|
||||
obj_setSysOut(self, "[error] del: arg not match.");
|
||||
obj_setErrorCode(self, 2);
|
||||
return;
|
||||
}
|
||||
void PikaStdLib_SysObj_remove(PikaObj* self, char* argPath) {
|
||||
obj_setErrorCode(self, 0);
|
||||
int32_t res = obj_removeArg(self, argPath);
|
||||
if (1 == res) {
|
||||
obj_setSysOut(self, "[error] del: object no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
if (2 == res) {
|
||||
obj_setSysOut(self, "[error] del: arg not match.");
|
||||
obj_setErrorCode(self, 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PikaStdLib_SysObj_type(PikaObj *self, char *argPath)
|
||||
{
|
||||
if (NULL == argPath)
|
||||
{
|
||||
/* no input obj path, use current obj */
|
||||
PikaObj *objHost = obj_getContext(self);
|
||||
Arg *objArg = obj_getArg(objHost, obj_getStr(self, "_n"));
|
||||
if (NULL == objArg)
|
||||
{
|
||||
obj_setSysOut(self, "[error] type: arg no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
obj_setSysOut(self, arg_getType(objArg));
|
||||
return;
|
||||
void PikaStdLib_SysObj_type(PikaObj* self, char* argPath) {
|
||||
if (NULL == argPath) {
|
||||
/* no input obj path, use current obj */
|
||||
PikaObj* objHost = obj_getContext(self);
|
||||
Arg* objArg = obj_getArg(objHost, obj_getStr(self, "_n"));
|
||||
if (NULL == objArg) {
|
||||
obj_setSysOut(self, "[error] type: arg no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
Arg *arg = obj_getArg(self, argPath);
|
||||
if (NULL == arg)
|
||||
{
|
||||
obj_setSysOut(self, "[error] type: arg no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
obj_setSysOut(self, arg_getType(arg));
|
||||
obj_setSysOut(self, arg_getType(objArg));
|
||||
return;
|
||||
}
|
||||
Arg* arg = obj_getArg(self, argPath);
|
||||
if (NULL == arg) {
|
||||
obj_setSysOut(self, "[error] type: arg no found.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return;
|
||||
}
|
||||
obj_setSysOut(self, arg_getType(arg));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user