change printf retarget to make \n to \r\n automatically

This commit is contained in:
hathach 2013-07-19 12:05:25 +07:00
parent a522263a9d
commit 23f4d7356f
2 changed files with 26 additions and 7 deletions

View File

@ -51,7 +51,26 @@ int __sys_write (int iFileHandle, char *pcBuffer, int iLength)
(void) iFileHandle;
#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART
return board_uart_send((uint8_t*)pcBuffer, iLength);
// following code to make \n --> \r\n
int length = iLength;
char* p_newline_pos = memchr(pcBuffer, '\n', length);
while(p_newline_pos != NULL)
{
uint32_t chunk_len = p_newline_pos - pcBuffer;
board_uart_send((uint8_t*)pcBuffer, chunk_len);
board_uart_send(&"\r\n", 2);
pcBuffer += (chunk_len + 1);
length -= (chunk_len + 1);
p_newline_pos = memchr(pcBuffer, '\n', length);
}
board_uart_send((uint8_t*)pcBuffer, length);
return iLength;
#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO
uint32_t i;
for (i = 0; i<iLength; i++)

View File

@ -174,12 +174,12 @@ OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para)
//--------------------------------------------------------------------+
void print_greeting(void)
{
printf("\r\n\
--------------------------------------------------------------------\r\n\
- Host Demo (a tinyusb example)\r\n\
- if you find any bugs or get any questions, feel free to file an\r\n\
- issue at https://github.com/hathach/tinyusb\r\n\
--------------------------------------------------------------------\r\n\r\n"
printf("\n\
--------------------------------------------------------------------\n\
- Host Demo (a tinyusb example)\n\
- if you find any bugs or get any questions, feel free to file an\n\
- issue at https://github.com/hathach/tinyusb\n\
--------------------------------------------------------------------\n\n"
);
}