Просмотр исходного кода

update uart read for lpc18/43 for testing

hathach 3 лет назад
Родитель
Сommit
a6001fc8f2

+ 8 - 1
examples/device/board_test/src/main.c

@@ -56,7 +56,7 @@ int main(void)
   {
     uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
 
-    // Blink every interval ms
+    // Blink and print every interval ms
     if ( !(board_millis() - start_ms < interval_ms) )
     {
       board_uart_write(HELLO_STR, strlen(HELLO_STR));
@@ -66,6 +66,13 @@ int main(void)
       board_led_write(led_state);
       led_state = 1 - led_state; // toggle
     }
+
+    // echo
+    uint8_t ch;
+    if ( board_uart_read(&ch, 1) )
+    {
+      board_uart_write(&ch, 1);
+    }
   }
 
   return 0;

+ 4 - 2
hw/bsp/board.c

@@ -103,7 +103,8 @@ TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
 TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
 {
   (void) fhdl;
-  return SEGGER_RTT_Read(0, buf, count);
+  int rd = (int) SEGGER_RTT_Read(0, buf, count);
+  return (rd > 0) ? rd : -1;
 }
 #endif
 
@@ -143,7 +144,8 @@ TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
 TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
 {
   (void) fhdl;
-  return board_uart_read((uint8_t*) buf, (int) count);
+  int rd = board_uart_read((uint8_t*) buf, (int) count);
+  return (rd > 0) ? rd : -1;
 }
 
 #endif

+ 2 - 0
hw/bsp/board.h

@@ -66,9 +66,11 @@ void board_led_write(bool state);
 uint32_t board_button_read(void);
 
 // Get characters from UART
+// Return number of read bytes
 int board_uart_read(uint8_t* buf, int len);
 
 // Send characters to UART
+// Return number of sent bytes
 int board_uart_write(void const * buf, int len);
 
 #if CFG_TUSB_OS == OPT_OS_NONE

+ 1 - 3
hw/bsp/ea4357/ea4357.c

@@ -272,9 +272,7 @@ uint32_t board_button_read(void)
 
 int board_uart_read(uint8_t* buf, int len)
 {
-  //return UART_ReceiveByte(BOARD_UART_DEV);
-  (void) buf; (void) len;
-  return 0;
+  return Chip_UART_Read(UART_DEV, buf, len);
 }
 
 int board_uart_write(void const * buf, int len)

+ 1 - 3
hw/bsp/lpc18/family.c

@@ -141,9 +141,7 @@ uint32_t board_button_read(void)
 
 int board_uart_read(uint8_t* buf, int len)
 {
-  //return UART_ReceiveByte(BOARD_UART_PORT);
-  (void) buf; (void) len;
-  return 0;
+  return Chip_UART_Read(UART_DEV, buf, len);
 }
 
 int board_uart_write(void const * buf, int len)

+ 1 - 1
hw/bsp/rp2040/board.h

@@ -52,7 +52,7 @@
 #endif
 
 // VBUS enable pin and its active state
-// #define PIO_USB_VBUSEN_PIN    22
+#define PIO_USB_VBUSEN_PIN    22
 
 #ifndef PIO_USB_VBUSEN_STATE
 #define PIO_USB_VBUSEN_STATE  1