-
Notifications
You must be signed in to change notification settings - Fork 7
/
usb_endp.c
56 lines (51 loc) · 1.38 KB
/
usb_endp.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
#include "usb_endp.h"
#include "usb_cdc.h"
#include "ch554_platform.h"
#define MAX_PACKET_SIZE 64
// The buffer (Tx and Rx) must have an even address, size: 64 (0x42)
xdatabuf(EP1_ADDR, Ep1Buffer, 64);
// The buffer (Tx and Rx) must have an even address, size: 128 (0x84)
xdatabuf(EP2_ADDR, Ep2Buffer, EP2_SIZE + EP2_SIZE); // Rx + Tx
uint8_t USB_EP_HALT_SET(uint8_t ep) {
switch (ep) {
case 0x82:
UEP2_CTRL = UEP2_CTRL & (~bUEP_T_TOG) | UEP_T_RES_STALL;
return 0;
case 0x02:
UEP2_CTRL = UEP2_CTRL & (~bUEP_R_TOG) | UEP_R_RES_STALL;
return 0;
case 0x83:
UEP3_CTRL = UEP3_CTRL & (~bUEP_T_TOG) | UEP_T_RES_STALL;
return 0;
case 0x03:
UEP3_CTRL = UEP3_CTRL & (~bUEP_R_TOG) | UEP_R_RES_STALL;
return 0;
case 0x81:
UEP1_CTRL = UEP1_CTRL & (~bUEP_T_TOG) | UEP_T_RES_STALL;
return 0;
default:
return 0xFF;
}
}
uint8_t USB_EP_HALT_CLEAR(uint8_t ep) {
switch (ep)
{
case 0x82:
UEP2_CTRL = UEP2_CTRL & ~(bUEP_T_TOG | MASK_UEP_T_RES) | UEP_T_RES_NAK;
return 0;
case 0x02:
UEP2_CTRL = UEP2_CTRL & ~(bUEP_R_TOG | MASK_UEP_R_RES) | UEP_R_RES_ACK;
return 0;
case 0x83:
UEP3_CTRL = UEP3_CTRL & ~(bUEP_T_TOG | MASK_UEP_T_RES) | UEP_T_RES_NAK;
return 0;
case 0x03:
UEP3_CTRL = UEP3_CTRL & ~(bUEP_R_TOG | MASK_UEP_R_RES) | UEP_R_RES_ACK;
return 0;
case 0x81:
UEP1_CTRL = UEP1_CTRL & ~(bUEP_T_TOG | MASK_UEP_T_RES) | UEP_T_RES_NAK;
return 0;
default:
return 0xFF;
}
}