-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprint.c
More file actions
52 lines (42 loc) · 691 Bytes
/
print.c
File metadata and controls
52 lines (42 loc) · 691 Bytes
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
#include "ch.h"
#include "hal.h"
#include "print.h"
void print(char *p) {
while (*p) {
sdPut(&SERIAL_DRIVER, *p++);
}
}
void printn(uint32_t n) {
char buf[16], *p;
if (!n)
sdPut(&SERIAL_DRIVER, '0');
else {
p = buf;
while (n)
*p++ = (n % 10) + '0', n /= 10;
while (p > buf)
sdPut(&SERIAL_DRIVER, *--p);
}
}
void read(char * p) {
char c;
while ((c = sdGet(&SERIAL_DRIVER))!= 0){
if ((c == '\r') || (c == '\n')) {
break;
}
*p++ = c;
}
}
int readn(void) {
int n = 0;
char c;
while ((c = sdGet(&SERIAL_DRIVER))!= 0){
if ((c == '\r') || (c == '\n')) {
break;
}
if ((c >= '0') && (c <= '9')) {
n = n * 10 + (c - '0');
}
}
return n;
}