BV UART: add transceive command

This commit is contained in:
King Kévin 2018-01-25 11:31:27 +01:00
parent de4218147e
commit af7d13dfef
1 changed files with 48 additions and 4 deletions

View File

@ -261,11 +261,47 @@ static void busvoodoo_uart_command_transmit(void* argument)
static void busvoodoo_uart_command_receive(void* argument)
{
(void)argument; // we won't use the argument
while (true) {
char c = usart_recv_blocking(USART(BUSVOODOO_USART_ID)); // receive character
busvoodoo_led_blue(100); // enable blue LED to show reception
printf("%c", c); // print received character
printf("press any key to exit\n");
while (!user_input_available) { // check for user input to exit
if ((USART_SR(USART(BUSVOODOO_USART_ID)) & USART_SR_RXNE)) { // verify if data has been received
char c = usart_recv(USART(BUSVOODOO_USART_ID)); // receive character
busvoodoo_led_blue(100); // enable blue LED to show reception
printf("%c", c); // print received character
}
}
user_input_get(); // discard user input
printf("\n"); // get to next line
}
/** command to transmit and receive data
* @param[in] argument no argument required
*/
static void busvoodoo_uart_command_transceive(void* argument)
{
(void)argument; // we won't use the argument
printf("press 5 times escape to exit\n");
char last_c = 0; // last user character received
uint8_t esc_count = 0; // number of times escape has press received
while (esc_count<5) { // check for escape sequence
if (user_input_available) { // check if user wants to transmit something
char c = user_input_get(); // get user input
if (0x1b==c) { // user pressed escape
if (0x1b!=last_c) { // this is the first escape press
esc_count = 0;
}
last_c = c; // remember key press
esc_count++; // increment escape count
}
usart_send_blocking(USART(BUSVOODOO_USART_ID), c); // send user character
busvoodoo_led_red(100); // enable red LED to show transmission
}
if ((USART_SR(USART(BUSVOODOO_USART_ID)) & USART_SR_RXNE)) { // verify if data has been received
char c = usart_recv(USART(BUSVOODOO_USART_ID)); // receive character
busvoodoo_led_blue(100); // enable blue LED to show reception
printf("%c", c); // print received character
}
}
printf("\n"); // get to next line
}
static const struct menu_command_t busvoodoo_uart_commands[] = {
@ -285,6 +321,14 @@ static const struct menu_command_t busvoodoo_uart_commands[] = {
"word",
&busvoodoo_uart_command_transmit,
},
{
'x',
"transceive",
"transmit and receive data",
MENU_ARGUMENT_NONE,
NULL,
&busvoodoo_uart_command_transceive,
},
};
struct busvoodoo_mode_t busvoodoo_uart_mode = {