-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerial.c
More file actions
69 lines (61 loc) · 1.59 KB
/
Serial.c
File metadata and controls
69 lines (61 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ========================================
*
* Copyright 2016 John Harkins and Li He
* All Rights Reserved
*
* ========================================
*/
#include "serial.h"
extern int USBUART_GetChar();
extern void USBUART_PutString(char *str);
extern int USBUART_DataIsReady();
extern int USBUART_CDCIsReady();
extern int USBUART_GetConfiguration();
/*******************************************************************************
* Function Name: Serial_PutString
********************************************************************************
*
* Summary
* Sends data from str via USB UART to the host.
*
* Parameters:
* str - a string to be sent
*
* Return:
* None.
*
*******************************************************************************/
void Serial_PutString(char *str)
{
while (!USBUART_CDCIsReady());
USBUART_PutString(str);
}
/*******************************************************************************
* Function Name: Serial_GetString
********************************************************************************
*
* Summary
* Reads data from USB UART into str
*
* Parameters:
* str - the buffer to be read into
*
* Return:
* None.
*
*******************************************************************************/
void Serial_GetString(char *str)
{
int count = 0;
while (1) {
while (!USBUART_DataIsReady());
char c = USBUART_GetChar();
str[count] = c;
if (c == '\r') { // hit newline
str[count + 1] = '\0'; // add null terminator
return;
}
count++;
}
}
/* [] END OF FILE */