embkernel
 All Classes Functions Variables Typedefs Groups Pages
UsbRxStream.cpp
1 //------------------------------------------------------------------------------
2 //This file is part of milkLib.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #include "UsbRxStream.hpp"
7 #include "UsbDevice.hpp"
8 #include "UsbMacros.hpp"
9 #include "RtosInclude.hpp"
10 
11 UsbRxStream::UsbRxStream(uint8_t ep, size_t size) :
12  mBuffer(size) {
13  UsbDevice::registerOutCallback(ep, this);
14 }
15 
16 UsbRxStream::~UsbRxStream() {
17 }
18 
19 int UsbRxStream::read(void* buffer, int len, Rtos::TICK timeout) {
20  return mBuffer.read(buffer, len, timeout);
21 }
22 
23 int UsbRxStream::onDataOut(UsbDefs::PKT* pkt) {
24  int written = mBuffer.write(pkt->data.bytes, pkt->header.len, Rtos::convertMsToTick(100));
25  USB_ASSERT(written == pkt->header.len);
26  return written;
27 }