Ver código fonte

add board_getchar() for non-blocking getchar()

hathach 3 anos atrás
pai
commit
a394273ed2

+ 2 - 2
examples/host/msc_file_explorer/src/msc_app.c

@@ -76,13 +76,13 @@ void msc_app_task(void)
 {
   if (!_cli) return;
 
-  int ch = board_uart_getchar();
+  int ch = board_getchar();
   if ( ch > 0 )
   {
     while( ch > 0 )
     {
       embeddedCliReceiveChar(_cli, (char) ch);
-      ch = board_uart_getchar();
+      ch = board_getchar();
     }
     embeddedCliProcess(_cli);
   }

+ 7 - 0
hw/bsp/board.c

@@ -106,6 +106,7 @@ TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
   int rd = (int) SEGGER_RTT_Read(0, buf, count);
   return (rd > 0) ? rd : -1;
 }
+
 #endif
 
 #elif defined(LOGGER_SWO)
@@ -149,3 +150,9 @@ TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
 }
 
 #endif
+
+int board_getchar(void)
+{
+  char c;
+  return ( sys_read(0, &c, 1) > 0 ) ? (int) c : (-1);
+}

+ 2 - 6
hw/bsp/board.h

@@ -132,12 +132,8 @@ static inline void board_delay(uint32_t ms)
   }
 }
 
-// stdio getchar() is blocking, this is non-blocking version for uart
-static inline int board_uart_getchar(void)
-{
-  uint8_t c;
-  return ( board_uart_read(&c, 1) > 0 ) ? (int) c : (-1);
-}
+// stdio getchar() is blocking, this is non-blocking version
+int board_getchar(void);
 
 #ifdef __cplusplus
  }

+ 5 - 0
hw/bsp/rp2040/family.c

@@ -219,6 +219,11 @@ int board_uart_write(void const * buf, int len)
 #endif
 }
 
+int board_getchar(void)
+{
+  return getchar_timeout_us(0);
+}
+
 //--------------------------------------------------------------------+
 // USB Interrupt Handler
 // rp2040 implementation will install approriate handler when initializing