|
@@ -9,7 +9,9 @@ UsbRawDevice UsbRaw = UsbRawDevice();
|
9
|
9
|
UsbRawDevice::UsbRawDevice()
|
10
|
10
|
: _dataSend(0),
|
11
|
11
|
_dataSendLen(0),
|
12
|
|
- _callback(0)
|
|
12
|
+ _callback(0),
|
|
13
|
+ _dataReceivePos(0),
|
|
14
|
+ _dataReceiveLen(0)
|
13
|
15
|
{
|
14
|
16
|
}
|
15
|
17
|
|
|
@@ -49,6 +51,8 @@ void UsbRawDevice::setDataUsbNoMsg()
|
49
|
51
|
usbMsgLen_t UsbRawDevice::_usbFunctionSetup(usbRequest_t* rq)
|
50
|
52
|
{
|
51
|
53
|
_rq = *rq;
|
|
54
|
+ _dataReceiveLen = min((uchar)rq->wLength.word, USB_RAW_DEVICE_BUFFER_SIZE);
|
|
55
|
+ _dataReceivePos = 0;
|
52
|
56
|
if (_callback)
|
53
|
57
|
{
|
54
|
58
|
_callback(rq, this, 0, 0);
|
|
@@ -61,11 +65,19 @@ usbMsgLen_t UsbRawDevice::_usbFunctionSetup(usbRequest_t* rq)
|
61
|
65
|
|
62
|
66
|
uchar UsbRawDevice::_usbFunctionWrite(uchar *data, uchar len)
|
63
|
67
|
{
|
64
|
|
- if (_callback)
|
|
68
|
+ for (uchar i = 0; i < len && _dataReceivePos < _dataReceiveLen; ++i, ++_dataReceivePos)
|
|
69
|
+ {
|
|
70
|
+ _dataReceive[_dataReceivePos] = data[i];
|
|
71
|
+ }
|
|
72
|
+ if (_dataReceiveLen == _dataReceivePos)
|
65
|
73
|
{
|
66
|
|
- _callback(&_rq, this, data, len);
|
|
74
|
+ if (_callback)
|
|
75
|
+ {
|
|
76
|
+ _callback(&_rq, this, _dataReceive, _dataReceiveLen);
|
|
77
|
+ }
|
|
78
|
+ return 1;
|
67
|
79
|
}
|
68
|
|
- return 1;
|
|
80
|
+ return 0;
|
69
|
81
|
}
|
70
|
82
|
|
71
|
83
|
void UsbRawDevice::setCallback(void (*callback)(CALLBACK_ARGS))
|