11#include "PikaStdDevice_UART.h"
22#include "PikaStdDevice_common.h"
3- #include "pika_hal.h"
43
54void PikaStdDevice_UART_enable (PikaObj * self ) {
65 obj_runNativeMethod (self , "platformEnable" , NULL );
@@ -40,7 +39,6 @@ void PikaStdDevice_UART_init(PikaObj* self) {
4039 obj_setInt (self , "dataBits" , 8 );
4140 obj_setInt (self , "parity" , PIKA_HAL_UART_PARITY_NONE );
4241 obj_setInt (self , "stopBits" , PIKA_HAL_UART_STOP_BITS_1 );
43- obj_setInt (self , "enabled" , 0 );
4442}
4543
4644void PikaStdDevice_UART___init__ (PikaObj * self ) {
@@ -59,52 +57,24 @@ Arg* PikaStdDevice_UART_readBytes(PikaObj* self, int length) {
5957 return arg_copy (obj_getArg (self , "readData" ));
6058}
6159
62- int _config_update (PikaObj * self , pika_hal_UART_config * cfg ){
63- if (obj_getInt (self , "enabled" )) {
64- pika_debug ("UART %s config update.\r\n" , obj_getStr (self , "id" ));
65- int err = pika_hal_ioctl (obj_getPtr (self , "pika_dev" ),
66- PIKA_HAL_IOCTL_CONFIG , cfg );
67- if (err == 0 ) {
68- return 0 ;
69- }
70- pika_debug ("UART %s config update failed.\r\n" , obj_getStr (self , "id" ));
71- }
72- return -1 ;
73- }
74-
7560void PikaStdDevice_UART_setBaudRate (PikaObj * self , int baudRate ) {
7661 obj_setInt (self , "baudRate" , baudRate );
77- pika_hal_UART_config cfg = {0 };
78- cfg .baudrate = baudRate ;
79- _config_update (self , & cfg );
8062}
8163
8264void PikaStdDevice_UART_setFlowControl (PikaObj * self , int flowControl ) {
8365 obj_setInt (self , "flowControl" , flowControl );
84- pika_hal_UART_config cfg = {0 };
85- cfg .flow_control = flowControl ;
86- _config_update (self , & cfg );
8766}
8867
8968void PikaStdDevice_UART_setDataBits (PikaObj * self , int dataBits ) {
9069 obj_setInt (self , "dataBits" , dataBits );
91- pika_hal_UART_config cfg = {0 };
92- cfg .data_bits = dataBits ;
93- _config_update (self , & cfg );
9470}
9571
9672void PikaStdDevice_UART_setParity (PikaObj * self , int parity ) {
9773 obj_setInt (self , "parity" , parity );
98- pika_hal_UART_config cfg = {0 };
99- cfg .parity = parity ;
100- _config_update (self , & cfg );
10174}
10275
10376void PikaStdDevice_UART_setStopBits (PikaObj * self , int stopBits ) {
10477 obj_setInt (self , "stopBits" , stopBits );
105- pika_hal_UART_config cfg = {0 };
106- cfg .stop_bits = stopBits ;
107- _config_update (self , & cfg );
10878}
10979
11080void PikaStdDevice_UART_setId (PikaObj * self , int id ) {
@@ -191,7 +161,6 @@ void PikaStdDevice_UART_platformEnable(PikaObj* self) {
191161 (int )obj_getInt (self , "id" ));
192162 return ;
193163 }
194- obj_setInt (self , "enabled" , 1 );
195164}
196165
197166void PikaStdDevice_UART_platformRead (PikaObj * self ) {
@@ -217,12 +186,7 @@ void PikaStdDevice_UART_platformDisable(PikaObj* self) {
217186 (int )obj_getInt (self , "id" ));
218187 return ;
219188 }
220- if (0 != pika_hal_ioctl (dev , PIKA_HAL_IOCTL_DISABLE )){
221- __platform_printf ("Error: disable UART '%d' failed.\r\n" ,
222- (int )obj_getInt (self , "id" ));
223- return ;
224- }
225- obj_setInt (self , "enabled" , 0 );
189+ pika_hal_ioctl (dev , PIKA_HAL_IOCTL_DISABLE );
226190}
227191
228192void PikaStdDevice_UART_platformReadBytes (PikaObj * self ) {
0 commit comments