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
| int _write(int fd, char *ptr, int len);
void print_float(float value);
int _write(int fd, char *ptr, int len)
{
int i = 0;
/*
* write "len" of char from "ptr" to file id "fd"
* Return number of char written.
*
* Only work for STDOUT, STDIN, and STDERR
*/
if (fd > 2) { return -1; }
while (*ptr && (i < len))
{
HAL_UART_Transmit(&USARTx,ptr,sizeof(*ptr),10);
if (*ptr == '\n')
{
HAL_UART_Transmit(&USARTx,(uint8_t*)"\r",2,10);
}
i++;
ptr++;
}
return i;
}
void print_float(float value)
{
int tmp,tmp1,tmp2,tmp3;
tmp = (int)value;
tmp1=(int)((value-tmp)*10)%10;
tmp2=(int)((value-tmp)*100)%10;
tmp3=(int)((value-tmp)*1000)%10;
printf("%d.%d%d%d\n", tmp,tmp1,tmp2,tmp3);
}
|