|
|
|
@ -145,57 +145,27 @@ int console_getline(struct console *console_, char *buf, size_t n) |
|
|
|
|
return -EAGAIN; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ssize_t console_read(struct console *console_, char *buf, size_t n) |
|
|
|
|
ssize_t console_read(struct console *console, char *buf, size_t n) |
|
|
|
|
{ |
|
|
|
|
struct usart_console *console = container_of(console_, |
|
|
|
|
struct usart_console, console); |
|
|
|
|
char *p = buf; |
|
|
|
|
char c; |
|
|
|
|
|
|
|
|
|
*buf = '\0'; |
|
|
|
|
|
|
|
|
|
while (console_peek(&c, console_, 1) == 0) { |
|
|
|
|
while (console_peek(&c, console, 1) == 0) { |
|
|
|
|
switch (c) { |
|
|
|
|
case '\004': |
|
|
|
|
if (buf < p) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
console_getc(&c, console_); |
|
|
|
|
console_getc(&c, console); |
|
|
|
|
return 0; |
|
|
|
|
case 10: |
|
|
|
|
case 127: |
|
|
|
|
if (buf < p) { |
|
|
|
|
#if CONFIG_USER_ECHO |
|
|
|
|
usart_send_blocking(console->dev, '\010'); |
|
|
|
|
usart_send_blocking(console->dev, ' '); |
|
|
|
|
usart_send_blocking(console->dev, '\010'); |
|
|
|
|
#endif |
|
|
|
|
--p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console_getc(&c, console_); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
case '\r': |
|
|
|
|
if (((size_t)p - (size_t)buf) >= n) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
*p++ = '\n'; |
|
|
|
|
#if CONFIG_USER_ECHO |
|
|
|
|
usart_send_blocking(console->dev, '\r'); |
|
|
|
|
usart_send_blocking(console->dev, '\n'); |
|
|
|
|
#endif |
|
|
|
|
console_getc(&c, console_); |
|
|
|
|
goto out; |
|
|
|
|
default: |
|
|
|
|
if (((size_t)p - (size_t)buf) >= n) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
*p++ = c; |
|
|
|
|
#if CONFIG_USER_ECHO |
|
|
|
|
usart_send_blocking(console->dev, c); |
|
|
|
|
#endif |
|
|
|
|
console_getc(&c, console_); |
|
|
|
|
console_getc(&c, console); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|