-
Notifications
You must be signed in to change notification settings - Fork 0
/
current_test.c
68 lines (59 loc) · 1.9 KB
/
current_test.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
#include <p24FJ128GB206.h>
#include <stdint.h>
#include "config.h"
#include "common.h"
#include "usb.h"
#include "pin.h"
#include "timer.h"
#include "oc.h"
#include "md.h"
#define GET_CURRENT 1
#define GET_LAST 2
WORD CURRENT_CURRENT = (WORD) 0;
WORD LAST_CURRENT = (WORD) 0;
void VendorRequests(void) {
switch (USB_setup.bRequest) {
case GET_CURRENT:
BD[EP0IN].address[0] = CURRENT_CURRENT.b[0];
BD[EP0IN].address[1] = CURRENT_CURRENT.b[1];
BD[EP0IN].bytecount = 2; // set EP0 IN byte count to 4
BD[EP0IN].status = 0xC8; // send packet as DATA1, set UOWN bit
break;
case GET_LAST:
BD[EP0IN].address[0] = LAST_CURRENT.b[0];
BD[EP0IN].address[1] = LAST_CURRENT.b[1];
BD[EP0IN].bytecount = 2; // set EP0 IN byte count to 4
BD[EP0IN].status = 0xC8; // send packet as DATA1, set UOWN bit
break;
default:
USB_error_flags |= 0x01; // set Request Error Flag
}
}
void VendorRequestsIn(void) {
switch (USB_request.setup.bRequest) {
default:
USB_error_flags |= 0x01; // set Request Error Flag
}
}
void VendorRequestsOut(void) {
}
int16_t main(void) {
init_clock();
init_timer();
init_pin();
init_oc();
init_md();
pin_analogIn(&A[0]);
md_velocity(&md1, 0xF000, 1);
InitUSB(); // initialize the USB registers and serial interface engine
while (USB_USWSTAT!=CONFIG_STATE) { // while the peripheral is not configured...
LAST_CURRENT = CURRENT_CURRENT;
CURRENT_CURRENT.w = pin_read(&A[0]);
ServiceUSB(); // ...service USB requests
}
while (1) {
LAST_CURRENT = CURRENT_CURRENT;
CURRENT_CURRENT.w = pin_read(&A[0]);
ServiceUSB(); // service any pending USB requests
}
}