forked from psgroove/psgroove
-
Notifications
You must be signed in to change notification settings - Fork 3
/
usb_utils.c
66 lines (53 loc) · 1.22 KB
/
usb_utils.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
#include "usb_utils.h"
uint8_t interruptBufferIdx = 0;
uchar interruptBuffer[8];
void interruptWrite_Byte(uchar byte)
{
if (interruptBufferIdx < 8) {
interruptBuffer[interruptBufferIdx++] = byte;
}
}
void interruptWrite_Word(uint16_t word)
{
if (interruptBufferIdx < 7) {
interruptBuffer[interruptBufferIdx++] = word & 0xff;
interruptBuffer[interruptBufferIdx++] = word >> 8;
}
}
void sendInterruptBuffer(void)
{
usbSetInterrupt(interruptBuffer, interruptBufferIdx);
interruptBufferIdx = 0;
}
void resetDataToggle(void)
{
usbTxStatus1.buffer[0] = USB_INITIAL_DATATOKEN;
}
void pUsbSetInterrupt(const uchar *pData, uchar len)
{
memcpy_P(interruptBuffer, pData, len);
interruptBufferIdx = len;
sendInterruptBuffer();
}
uint8_t outBufferLen = 0;
uint8_t outBuffer[8];
void outBuffer_Write_Byte(uchar byte)
{
if (outBufferLen < 8) {
outBuffer[outBufferLen++] = byte;
}
}
void outBuffer_Write_Word(uint16_t word)
{
if (outBufferLen < 7) {
outBuffer[outBufferLen++] = word & 0xff;
outBuffer[outBufferLen++] = word >> 8;
}
}
usbMsgLen_t sendOutBuffer(void)
{
usbMsgLen_t len = outBufferLen;
outBufferLen = 0;
usbMsgPtr = outBuffer;
return len;
}