mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
update port std
This commit is contained in:
parent
61c92b117c
commit
72fb6bd5ed
@ -1,6 +1,5 @@
|
||||
#include "PikaStdDevice_ADC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_ADC_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include "PikaStdDevice_BaseDev.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "dataStrs.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 10, 4)
|
||||
#error "This library requires PikaScript version 1.10.4 or higher"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "PikaStdDevice_CAN.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_CAN___init__(PikaObj* self) {}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "PikaStdDevice_DAC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
static pika_dev* _get_dev(PikaObj* self) {
|
||||
pika_dev* dev = obj_getPtr(self, "pika_dev");
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "PikaStdDevice_GPIO.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_GPIO_init(PikaObj* self) {
|
||||
obj_setInt(self, "isEnable", 0);
|
||||
@ -149,32 +148,15 @@ void PikaStdDevice_GPIO_platformRead(PikaObj* self) {
|
||||
obj_setInt(self, "readBuff", val);
|
||||
}
|
||||
|
||||
extern PikaEventListener* g_pika_device_event_listener;
|
||||
|
||||
void _pika_hal_GPIO_event_callback(pika_dev* dev,
|
||||
PIKA_HAL_GPIO_EVENT_SIGNAL signal) {
|
||||
pks_eventLisener_sendSignal(g_pika_device_event_listener, (uintptr_t)dev,
|
||||
signal);
|
||||
}
|
||||
|
||||
void PikaStdDevice_GPIO_setCallBack(PikaObj* self,
|
||||
Arg* eventCallBack,
|
||||
Arg* eventCallback,
|
||||
int filter) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
#if PIKA_EVENT_ENABLE
|
||||
obj_setArg(self, "eventCallBack", eventCallBack);
|
||||
/* init event_listener for the first time */
|
||||
if (NULL == g_pika_device_event_listener) {
|
||||
pks_eventLisener_init(&g_pika_device_event_listener);
|
||||
}
|
||||
/* use the pointer of dev as the event id */
|
||||
uint32_t eventId = (uintptr_t)dev;
|
||||
/* regist event to event listener */
|
||||
pks_eventLicener_registEvent(g_pika_device_event_listener, eventId, self);
|
||||
|
||||
_PikaStdDevice_setCallBack(self, eventCallback, (uintptr_t)dev);
|
||||
/* regist event to pika_hal */
|
||||
pika_hal_GPIO_config cfg_cb = {0};
|
||||
cfg_cb.event_callback = _pika_hal_GPIO_event_callback;
|
||||
cfg_cb.event_callback = (void*)_PikaStdDevice_event_handler;
|
||||
cfg_cb.event_callback_filter = filter;
|
||||
cfg_cb.event_callback_ena = PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE;
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg_cb);
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "PikaStdDevice_IIC.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_IIC_init(PikaObj* self) {
|
||||
obj_setInt(self, "deviceAddr", 0);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "PikaStdDevice_PWM.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_PWM_init(PikaObj* self) {
|
||||
obj_setStr(self, "pin", "none");
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "PikaStdDevice_SPI.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_SPI___init__(PikaObj* self) {
|
||||
obj_setInt(self, "baudRate", 1000);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "PikaStdDevice_Time.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
#if defined(__linux)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "PikaStdDevice_UART.h"
|
||||
#include "BaseObj.h"
|
||||
#include "pika_hal.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
|
||||
void PikaStdDevice_UART_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
@ -11,14 +10,19 @@ void PikaStdDevice_UART_disable(PikaObj* self) {
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_init(PikaObj* self) {
|
||||
obj_setInt(self, "baudRate", 115200);
|
||||
obj_setInt(self, "id", 1);
|
||||
obj_setStr(self, "readBuff", "");
|
||||
/* const */
|
||||
obj_setInt(self, "FLOW_CONTROL_NONE", PIKA_HAL_UART_FLOW_CONTROL_NONE);
|
||||
obj_setInt(self, "FLOW_CONTROL_RTS", PIKA_HAL_UART_FLOW_CONTROL_RTS);
|
||||
obj_setInt(self, "FLOW_CONTROL_CTS", PIKA_HAL_UART_FLOW_CONTROL_CTS);
|
||||
obj_setInt(self, "FLOW_CONTROL_RTS_CTS",
|
||||
PIKA_HAL_UART_FLOW_CONTROL_RTS_CTS);
|
||||
|
||||
obj_setInt(self, "SIGNAL_RX", PIKA_HAL_UART_EVENT_SIGNAL_RX);
|
||||
obj_setInt(self, "SIGNAL_TX", PIKA_HAL_UART_EVENT_SIGNAL_TX);
|
||||
|
||||
obj_setInt(self, "baudRate", 115200);
|
||||
obj_setInt(self, "id", 1);
|
||||
obj_setStr(self, "readBuff", "");
|
||||
obj_setInt(self, "flowControl", PIKA_HAL_UART_FLOW_CONTROL_NONE);
|
||||
}
|
||||
|
||||
@ -42,7 +46,7 @@ void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) {
|
||||
obj_setInt(self, "baudRate", baudRate);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setFlowControl(PikaObj *self, int flowControl){
|
||||
void PikaStdDevice_UART_setFlowControl(PikaObj* self, int flowControl) {
|
||||
obj_setInt(self, "flowControl", flowControl);
|
||||
}
|
||||
|
||||
@ -95,7 +99,8 @@ void PikaStdDevice_UART_platformRead(PikaObj* self) {
|
||||
obj_setBytes(self, "_readData", NULL, len + 1);
|
||||
char* buff = (char*)obj_getBytes(self, "_readData");
|
||||
pika_dev* dev = _get_dev(self);
|
||||
pika_hal_read(dev, buff, len);
|
||||
int len_get = pika_hal_read(dev, buff, len);
|
||||
buff[len_get] = 0;
|
||||
obj_setStr(self, "readData", buff);
|
||||
}
|
||||
|
||||
@ -133,4 +138,18 @@ void PikaStdDevice_UART_platformWriteBytes(PikaObj* self) {
|
||||
|
||||
void PikaStdDevice_UART_setCallBack(PikaObj* self,
|
||||
Arg* eventCallBack,
|
||||
int filter) {}
|
||||
int filter) {
|
||||
pika_dev* dev = _get_dev(self);
|
||||
#if PIKA_EVENT_ENABLE
|
||||
_PikaStdDevice_setCallBack(self, eventCallBack, (uintptr_t)dev);
|
||||
/* regist event to pika_hal */
|
||||
pika_hal_UART_config cfg_cb = {0};
|
||||
cfg_cb.event_callback = (void*)_PikaStdDevice_event_handler;
|
||||
cfg_cb.event_callback_filter = filter;
|
||||
cfg_cb.event_callback_ena = PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE;
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_CONFIG, &cfg_cb);
|
||||
#else
|
||||
obj_setErrorCode(self, 1);
|
||||
obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled.");
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user