-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcdc.c
84 lines (65 loc) · 1.79 KB
/
cdc.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
74
75
76
77
78
79
80
81
82
83
84
#include <fx2regs.h>
#include <fx2macros.h>
#include <delay.h>
#include "cdc.h"
#define SYNCDELAY SYNCDELAY4
volatile WORD cdc_queued_bytes = 0;
struct usb_cdc_line_coding cdc_current_line_coding = {
.bDTERate0 = LSB(2400),
.bDTERate1 = MSB(2400),
.bDTERate2 = 0,
.bDTERate3 = 0,
.bCharFormat = USB_CDC_1_STOP_BITS,
.bParityType = USB_CDC_NO_PARITY,
.bDataBits = 8
};
void cdc_receive_poll() {
if ( !(EP2468STAT & bmCDC_H2D_EP(EMPTY)) ) {
WORD bytes = MAKEWORD(CDC_H2D_EP(BCH),CDC_H2D_EP(BCL));
cdcuser_receive_data(CDC_H2D_EP(FIFOBUF), bytes);
CDC_H2D_EP(BCL) = 0x80; // Mark us ready to receive again.
}
// FIXME: Send the interrupt thingy
}
BOOL cdc_handle_command(BYTE cmd) {
int i;
BYTE* line_coding = (BYTE*)&cdc_current_line_coding;
DWORD baud_rate = 0;
switch(cmd) {
case USB_CDC_REQ_SET_LINE_CODING:
EUSB = 0 ;
SUDPTRCTL = 0x01;
EP0BCL = 0x00;
SUDPTRCTL = 0x00;
EUSB = 1;
while (EP0BCL != 7);
SYNCDELAY;
for (i=0;i<7;i++)
line_coding[i] = EP0BUF[i];
// FIXME: Make this following line work rather then the if statement chain!
// baud_rate = MAKEDWORD(
// MAKEWORD(cdc_current_line_coding.bDTERate3, cdc_current_line_coding.bDTERate2),
// MAKEWORD(cdc_current_line_coding.bDTERate1, cdc_current_line_coding.bDTERate0));
baud_rate = MAKEDWORD(
MAKEWORD(line_coding[3], line_coding[2]),
MAKEWORD(line_coding[1], line_coding[0]));
if (!cdcuser_set_line_rate(baud_rate))
; //EP0STALL();
return TRUE;
case USB_CDC_REQ_GET_LINE_CODING:
SUDPTRCTL = 0x01;
for (i=0;i<7;i++)
EP0BUF[i] = line_coding[i];
EP0BCH = 0x00;
SYNCDELAY;
EP0BCL = 7;
SYNCDELAY;
while (EP0CS & 0x02);
SUDPTRCTL = 0x00;
return TRUE;
case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
return TRUE;
default:
return FALSE;
}
}