usart: add CONFIG_USER_ECHO option

This commit is contained in:
S.J.R. van Schaik 2017-08-03 17:09:51 +02:00
parent 9922994d1c
commit d5266221ef
2 changed files with 18 additions and 0 deletions

View file

@ -107,21 +107,28 @@ int console_getline(struct console *console_, char *buf, size_t n)
while (console_getc(&c, console_) == 0) { while (console_getc(&c, console_) == 0) {
switch (c) { switch (c) {
case '\r': case '\r':
#if CONFIG_USER_ECHO
usart_send_blocking(console->dev, '\r'); usart_send_blocking(console->dev, '\r');
#endif
return 0; return 0;
case 10: case 10:
case 127: case 127:
if (buf < p) { if (buf < p) {
#if CONFIG_USER_ECHO
usart_send_blocking(console->dev, '\010'); usart_send_blocking(console->dev, '\010');
usart_send_blocking(console->dev, ' '); usart_send_blocking(console->dev, ' ');
usart_send_blocking(console->dev, '\010'); usart_send_blocking(console->dev, '\010');
#endif
--p; --p;
} }
break; break;
default: default:
*p = c; *p = c;
#if CONFIG_USER_ECHO
usart_send_blocking(console->dev, c); usart_send_blocking(console->dev, c);
#endif
if (((size_t)p - (size_t)buf) < n) { if (((size_t)p - (size_t)buf) < n) {
++p; ++p;
@ -156,9 +163,11 @@ ssize_t console_read(struct console *console_, char *buf, size_t n)
case 10: case 10:
case 127: case 127:
if (buf < p) { if (buf < p) {
#if CONFIG_USER_ECHO
usart_send_blocking(console->dev, '\010'); usart_send_blocking(console->dev, '\010');
usart_send_blocking(console->dev, ' '); usart_send_blocking(console->dev, ' ');
usart_send_blocking(console->dev, '\010'); usart_send_blocking(console->dev, '\010');
#endif
--p; --p;
} }
@ -170,7 +179,9 @@ ssize_t console_read(struct console *console_, char *buf, size_t n)
goto out; goto out;
*p++ = '\n'; *p++ = '\n';
#if CONFIG_USER_ECHO
usart_send_blocking(console->dev, '\r'); usart_send_blocking(console->dev, '\r');
#endif
console_getc(&c, console_); console_getc(&c, console_);
goto out; goto out;
default: default:
@ -178,7 +189,9 @@ ssize_t console_read(struct console *console_, char *buf, size_t n)
goto out; goto out;
*p++ = c; *p++ = c;
#if CONFIG_USER_ECHO
usart_send_blocking(console->dev, c); usart_send_blocking(console->dev, c);
#endif
console_getc(&c, console_); console_getc(&c, console_);
break; break;
} }

View file

@ -204,11 +204,16 @@ int shell_write(struct console *con, size_t argc, const char **argv)
return -1; return -1;
} }
#if CONFIG_USER_ECHO
fprintf(con->fp, "> "); fprintf(con->fp, "> ");
#endif
while ((ret = console_read(con, data, sizeof data)) > 0) { while ((ret = console_read(con, data, sizeof data)) > 0) {
mufs_write(file, data, ret); mufs_write(file, data, ret);
#if CONFIG_USER_ECHO
fprintf(con->fp, "\n> "); fprintf(con->fp, "\n> ");
#endif
} }
mufs_close(file); mufs_close(file);