5 #include "../regs/regs.h" 8 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 30 diepctl0.setSNAK(
true);
32 diepctl0.setEPENA(
true);
59 doeptsiz0.setSTUPCNT(1);
61 doeptsiz0.setPKTCNT(
true);
65 doeptsiz0.setXFRSIZ(64);
105 m_requestRecipients[0]->
processSetupRequest(&m_request, m_largeBuffer, &m_transferBufferLength, maxBufferLength);
108 m_requestRecipients[1]->
processSetupRequest(&m_request, m_largeBuffer, &m_transferBufferLength, maxBufferLength);
144 if (receiveSomeData() < 0) {
152 if (receiveSomeData() < 0) {
156 writePacket(
NULL, 0);
227 for (
int i = 0; i < m_receivedPacketSize; i += 4) {
230 m_receivedPacketSize = 0;
243 writePacket(m_largeBuffer + m_bufferOffset, m_transferBufferLength);
244 if (m_zeroLengthPacketNeeded) {
250 m_zeroLengthPacketNeeded =
false;
251 m_transferBufferLength = 0;
255 m_transferBufferLength = 0;
260 uint16_t Endpoint0::receiveSomeData() {
263 uint16_t sizeOfPacketRead = readPacket(m_largeBuffer + m_transferBufferLength, packetSize);
264 if (sizeOfPacketRead != packetSize) {
268 m_transferBufferLength += packetSize;
274 uint16_t buffer32Length =
MIN(length, m_receivedPacketSize);
278 for (i = buffer32Length; i >= 4; i -= 4) {
280 m_receivedPacketSize -= 4;
287 memcpy(buffer32, &extraData, i);
288 if (m_receivedPacketSize < 4) {
289 m_receivedPacketSize = 0;
291 m_receivedPacketSize -= 4;
294 return buffer32Length;
309 dieptsiz0.setPKTCNT(1);
311 dieptsiz0.setXFRSIZ(length);
319 for (
int i = length; i > 0; i -= 4) {
332 if (m_transferBufferLength
333 && m_transferBufferLength < m_request.
wLength()
336 m_zeroLengthPacketNeeded =
true;
339 m_zeroLengthPacketNeeded =
false;
bool processSetupRequest(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength, uint16_t transferBufferMaxLength)
void readAndDispatchSetupPacket()
void clearForOutTransactions(uint16_t wLength)
static constexpr int k_maxPacketSize
void set(Register< T > value) volatile
virtual void wholeDataReceivedCallback(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength)
constexpr volatile DIEPINT * DIEPINT(int i) const
void setMPSIZ(MPSIZ s) volatile
static constexpr int MaxTransferSize
virtual void wholeDataSentCallback(SetupPacket *request, uint8_t *transferBuffer, uint16_t *transferBufferLength)
RecipientType recipientType() const
void computeZeroLengthPacketNeeded()
void * memcpy(void *dst, const void *src, size_t n)