Dozingfiretruck преди 4 години
родител
ревизия
d0fce57ff4
променени са 3 файла, в които са добавени 53 реда и са изтрити 10 реда
  1. 2 0
      app/port/luat_conf_bsp.h
  2. 33 9
      app/port/luat_uart_air101.c
  3. 18 1
      include/driver/wm_uart.h

+ 2 - 0
app/port/luat_conf_bsp.h

@@ -189,4 +189,6 @@
 
 #define LV_COLOR_16_SWAP   1
 
+#define LUAT__UART_TX_NEED_WAIT_DONE
+
 #endif

+ 33 - 9
app/port/luat_uart_air101.c

@@ -9,8 +9,10 @@
 #include "wm_uart.h"
 #include "wm_gpio_afsel.h"
 #include "stdio.h"
+
 //串口数量,编号从0开始
 #define MAX_DEVICE_COUNT TLS_UART_MAX
+
 //存放串口设备句柄
 static uint8_t serials_buff_len[MAX_DEVICE_COUNT] ={TLS_UART_RX_BUF_SIZE};
 extern struct tls_uart_port uart_port[TLS_UART_MAX];
@@ -59,6 +61,11 @@ static s16 uart_sent_cb(struct tls_uart_port *port)
     msg.arg2 = 0;
     msg.ptr = NULL;
     luat_msgbus_put(&msg, 1);
+    if (uart_port[port->uart_no].rs480.rs485_param_bit.is_485used){
+        if (uart_port[port->uart_no].rs480.rs485_param_bit.wait_time)
+            luat_timer_us_delay(uart_port[port->uart_no].rs480.rs485_param_bit.wait_time);
+        luat_gpio_set(uart_port[port->uart_no].rs480.rs485_pin, uart_port[port->uart_no].rs480.rs485_param_bit.rx_level);
+    }
     return 0;
 }
 
@@ -120,8 +127,16 @@ int luat_uart_setup(luat_uart_t *uart)
         uart->bufsz = 1024;
     serials_buff_len[uart->id] = uart->bufsz;
 
-    return ret;
+    uart_port[uart->id].rs480.rs485_param_bit.is_485used = (uart->pin485 > WM_IO_PB_31)?0:1;
+    uart_port[uart->id].rs480.rs485_pin = uart->pin485;
+    uart_port[uart->id].rs480.rs485_param_bit.rx_level = uart->rx_level;
+    uart_port[uart->id].rs480.rs485_param_bit.wait_time = uart->delay;
+
+    if (uart_port[uart->id].rs480.rs485_param_bit.is_485used){
+        luat_gpio_mode(uart_port[uart->id].rs480.rs485_pin, 0, 0, uart_port[uart->id].rs480.rs485_param_bit.rx_level);
+    }
 
+    return ret;
 }
 
 
@@ -129,10 +144,8 @@ int luat_uart_write(int uartid, void *data, size_t length)
 {
     int ret = 0;
     //printf("uid:%d,data:%s,length = %d\r\n",uartid, (char *)data, length);
-    if (!luat_uart_exist(uartid))
-    {
-        return 0;
-    }
+    if (!luat_uart_exist(uartid))return 0;
+    if (uart_port[uartid].rs480.rs485_param_bit.is_485used) luat_gpio_set(uart_port[uartid].rs480.rs485_pin, !uart_port[uartid].rs480.rs485_param_bit.rx_level);
     ret = tls_uart_write(uartid, data,length);
     ret = (ret == 0) ? length : 0;
     return ret;
@@ -151,10 +164,8 @@ int luat_uart_read(int uartid, void *buffer, size_t length)
 
 int luat_uart_close(int uartid)
 {
-    if (!luat_uart_exist(uartid))
-    {
-        return 0;
-    }
+    if (!luat_uart_exist(uartid))return 0;
+    uart_port[uartid].rs480.rs485_param_bit.is_485used = 0;
     // tls_uart_port_init(uartid,NULL,0);
     return 0;
 }
@@ -177,3 +188,16 @@ int luat_setup_cb(int uartid, int received, int sent)
 
     return 0;
 }
+
+int luat_uart_wait_485_tx_done(int uartid)
+{
+	int cnt = 0;
+    if (luat_uart_exist(uartid)){
+        if (uart_port[uartid].rs480.rs485_param_bit.is_485used){
+        if (uart_port[uartid].rs480.rs485_param_bit.wait_time)
+            luat_timer_us_delay(uart_port[uartid].rs480.rs485_param_bit.wait_time);
+        luat_gpio_set(uart_port[uartid].rs480.rs485_pin, uart_port[uartid].rs480.rs485_param_bit.rx_level);
+    }
+    }
+    return cnt;
+}

+ 18 - 1
include/driver/wm_uart.h

@@ -263,12 +263,29 @@ typedef struct TLS_UART_REGS
     u32 UR_RXW;                     /**< rx windows register */
 } TLS_UART_REGS_T;
 
-
+typedef struct
+{
+	// timer_t *rs485_timer;
+	union
+	{
+		u16 rs485_param;
+		struct
+		{
+			u16 wait_time:14;
+			u16 rx_level:1;
+			u16 is_485used:1;
+		}rs485_param_bit;
+	};
+	u8 rx_mark;
+	u8 rs485_pin;
+}rs480_info;
 /**
  * @typedef struct tls_uart_port
  */
 typedef struct tls_uart_port
 {
+    rs480_info rs480;
+
     u32 uart_no;                    /**< uart number: 0 or 1 */
 
     u32 uart_irq_no;             /**< uart interrupt number */