mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
add_files
This commit is contained in:
parent
654cdc7912
commit
0d4141a917
@ -1,5 +1,6 @@
|
||||
#include "PikaStdDevice_UART.h"
|
||||
#include "PikaStdDevice_common.h"
|
||||
#include "pika_hal.h"
|
||||
|
||||
void PikaStdDevice_UART_enable(PikaObj* self) {
|
||||
obj_runNativeMethod(self, "platformEnable", NULL);
|
||||
@ -39,6 +40,7 @@ void PikaStdDevice_UART_init(PikaObj* self) {
|
||||
obj_setInt(self, "dataBits", 8);
|
||||
obj_setInt(self, "parity", PIKA_HAL_UART_PARITY_NONE);
|
||||
obj_setInt(self, "stopBits", PIKA_HAL_UART_STOP_BITS_1);
|
||||
obj_setInt(self, "enabled", 0);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART___init__(PikaObj* self) {
|
||||
@ -57,24 +59,52 @@ Arg* PikaStdDevice_UART_readBytes(PikaObj* self, int length) {
|
||||
return arg_copy(obj_getArg(self, "readData"));
|
||||
}
|
||||
|
||||
int _config_update(PikaObj* self, pika_hal_UART_config* cfg){
|
||||
if (obj_getInt(self, "enabled")) {
|
||||
pika_debug("UART %s config update.\r\n", obj_getStr(self, "id"));
|
||||
int err = pika_hal_ioctl(obj_getPtr(self, "pika_dev"),
|
||||
PIKA_HAL_IOCTL_CONFIG, cfg);
|
||||
if (err == 0) {
|
||||
return 0;
|
||||
}
|
||||
pika_debug("UART %s config update failed.\r\n", obj_getStr(self, "id"));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setBaudRate(PikaObj* self, int baudRate) {
|
||||
obj_setInt(self, "baudRate", baudRate);
|
||||
pika_hal_UART_config cfg = {0};
|
||||
cfg.baudrate = baudRate;
|
||||
_config_update(self, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setFlowControl(PikaObj* self, int flowControl) {
|
||||
obj_setInt(self, "flowControl", flowControl);
|
||||
pika_hal_UART_config cfg = {0};
|
||||
cfg.flow_control = flowControl;
|
||||
_config_update(self, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setDataBits(PikaObj* self, int dataBits) {
|
||||
obj_setInt(self, "dataBits", dataBits);
|
||||
pika_hal_UART_config cfg = {0};
|
||||
cfg.data_bits = dataBits;
|
||||
_config_update(self, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setParity(PikaObj* self, int parity) {
|
||||
obj_setInt(self, "parity", parity);
|
||||
pika_hal_UART_config cfg = {0};
|
||||
cfg.parity = parity;
|
||||
_config_update(self, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setStopBits(PikaObj* self, int stopBits) {
|
||||
obj_setInt(self, "stopBits", stopBits);
|
||||
pika_hal_UART_config cfg = {0};
|
||||
cfg.stop_bits = stopBits;
|
||||
_config_update(self, &cfg);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_setId(PikaObj* self, int id) {
|
||||
@ -161,6 +191,7 @@ void PikaStdDevice_UART_platformEnable(PikaObj* self) {
|
||||
(int)obj_getInt(self, "id"));
|
||||
return;
|
||||
}
|
||||
obj_setInt(self, "enabled", 1);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformRead(PikaObj* self) {
|
||||
@ -186,7 +217,12 @@ void PikaStdDevice_UART_platformDisable(PikaObj* self) {
|
||||
(int)obj_getInt(self, "id"));
|
||||
return;
|
||||
}
|
||||
pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE);
|
||||
if (0!= pika_hal_ioctl(dev, PIKA_HAL_IOCTL_DISABLE)){
|
||||
__platform_printf("Error: disable UART '%d' failed.\r\n",
|
||||
(int)obj_getInt(self, "id"));
|
||||
return;
|
||||
}
|
||||
obj_setInt(self, "enabled", 0);
|
||||
}
|
||||
|
||||
void PikaStdDevice_UART_platformReadBytes(PikaObj* self) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user