add board_getchar() for non-blocking getchar()

This commit is contained in:
hathach 2022-11-21 16:28:54 +07:00
parent 460bef9dbb
commit a394273ed2
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
4 changed files with 16 additions and 8 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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