#include <string.h>
#include <stdlib.h>
#include "drivers/mss_uart/mss_uart.h"
#define RX_BUFF_SIZE 1
#define MAX_LENGTH 20
void processInput(uint8_t buffer[RX_BUFF_SIZE]);
void printNewLine();
uint8_t rx_buff[RX_BUFF_SIZE];
uint8_t newline[2] = "\r\n";
int c = 0;
uint8_t stopInput = 0;
uint8_t inputString[80];
int main( void )
{
const uint8_t opening[] = "\r\n-- Random software --\r\n";
const uint8_t stringComplete[] = "\r\nYou entered the following string: \r\n";
const uint8_t ending[] = "\r\nThat's it! \r\n";
MSS_UART_init
(
&g_mss_uart0,
MSS_UART_57600_BAUD,
MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT
);
// Say hello
MSS_UART_polled_tx( &g_mss_uart0, opening, sizeof(opening) );
// Loop till buffer is full or enter is pressed
while(stopInput == 0)
{
uint8_t rx_size = 0;
rx_size = MSS_UART_get_rx( &g_mss_uart0, rx_buff, sizeof(rx_buff) );
if (rx_size > 0)
{
processInput(rx_buff);
}
}
inputString[c] = '\0';
MSS_UART_polled_tx( &g_mss_uart0, stringComplete, sizeof(stringComplete) );
MSS_UART_polled_tx( &g_mss_uart0, inputString, c );
printNewLine();
int l = 0;
int currentChar;
for(l = 0; l < c; l++){
currentChar = inputString[l];
//MSS_UART_polled_tx( &g_mss_uart0, inputString[l], sizeof(inputString[l]) );
MSS_UART_polled_tx( &g_mss_uart0, currentChar, sizeof(currentChar) );
}
MSS_UART_polled_tx( &g_mss_uart0, ending, sizeof(ending) );
return 0;
}
void processInput(uint8_t buffer[RX_BUFF_SIZE]){
if(c < MAX_LENGTH){
if(buffer[0] == 13){ // Enter is pressed
stopInput = 1;
}else{
MSS_UART_polled_tx( &g_mss_uart0, buffer, sizeof(buffer) );
inputString[c] = buffer[0];
c++;
}
}else{ // Buffer is full
stopInput = 1;
}
}
void printNewLine(){
MSS_UART_polled_tx( &g_mss_uart0, newline, sizeof(newline));
}