-
Notifications
You must be signed in to change notification settings - Fork 56
/
uart.c
73 lines (67 loc) · 1.91 KB
/
uart.c
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
70
71
72
73
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "CH559.h"
#include "util.h"
#include "uart.h"
uint8_t __xdata uartRxBuff[64];
uint8_t __xdata rxPos = 0;
void processUart(){
while(RI){
RI=0;
uartRxBuff[rxPos] = SBUF;
if (uartRxBuff[rxPos]=='\n' || rxPos >= 64){
for (uint8_t i = 0; i < rxPos; i ++ )
{
printf( "0x%02X ",uartRxBuff[i]);
}
printf("\n");
if(uartRxBuff[0]=='k'){
//if(uartRxBuff[1]==0x61)LED=0;
//if(uartRxBuff[1]==0x73)LED=1;
if(uartRxBuff[1]=='b')runBootloader();
}
rxPos=0;
}else{
rxPos++;
}
}
}
void sendProtocolMSG(unsigned char msgtype, unsigned short length, unsigned char type, unsigned char device, unsigned char endpoint, unsigned char __xdata *msgbuffer){
unsigned short i;
putchar(0xFE);
putchar(length);
putchar((unsigned char)(length>>8));
putchar(msgtype);
putchar(type);
putchar(device);
putchar(endpoint);
putchar(0);
putchar(0);
putchar(0);
putchar(0);
for (i = 0; i < length; i++)
{
putchar(msgbuffer[i]);
}
putchar('\n');
}
void sendHidPollMSG(unsigned char msgtype, unsigned short length, unsigned char type, unsigned char device, unsigned char endpoint, unsigned char __xdata *msgbuffer,unsigned char idVendorL,unsigned char idVendorH,unsigned char idProductL,unsigned char idProductH){
unsigned short i;
putchar(0xFE);
putchar(length);
putchar((unsigned char)(length>>8));
putchar(msgtype);
putchar(type);
putchar(device);
putchar(endpoint);
putchar(idVendorL);
putchar(idVendorH);
putchar(idProductL);
putchar(idProductH);
for (i = 0; i < length; i++)
{
putchar(msgbuffer[i]);
}
putchar('\n');
}