usart: add CONFIG_USER_ECHO option

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 9922994d1c
commit d5266221ef
  1. 13
      source/platform/usart.c
  2. 5
      source/shell/mufs.c

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

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

Loading…
Cancel
Save