summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2022-11-21 16:28:54 +0700
committerhathach <[email protected]>2022-11-21 16:28:54 +0700
commita394273ed28bdbd9ed5cf4ba94a99204bdd841e9 (patch)
treef60aeb1457d1002ad8ae48bcd6f17fea77d0896b
parent460bef9dbb40d1c6990c1bfd2f8da48978550932 (diff)
add board_getchar() for non-blocking getchar()
-rw-r--r--examples/host/msc_file_explorer/src/msc_app.c4
-rw-r--r--hw/bsp/board.c7
-rw-r--r--hw/bsp/board.h8
-rw-r--r--hw/bsp/rp2040/family.c5
4 files changed, 16 insertions, 8 deletions
diff --git a/examples/host/msc_file_explorer/src/msc_app.c b/examples/host/msc_file_explorer/src/msc_app.c
index b7c9212ee..aa193f3ce 100644
--- a/examples/host/msc_file_explorer/src/msc_app.c
+++ b/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);
}
diff --git a/hw/bsp/board.c b/hw/bsp/board.c
index a22b462d9..7e96735bd 100644
--- a/hw/bsp/board.c
+++ b/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);
+}
diff --git a/hw/bsp/board.h b/hw/bsp/board.h
index 52c64a1cc..0a10294d0 100644
--- a/hw/bsp/board.h
+++ b/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
}
diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c
index d78e2c754..26008168d 100644
--- a/hw/bsp/rp2040/family.c
+++ b/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