Appropriate subforum? 32U4 USB device firmware development question

I'm developing a simple USB printer device class emulator on 32u4. The task of 32u4 is to pretend to be a receipt printer to receive print data and forward to ESP32 for processing and that data are forwarded to a USB host that is connected to the actual printer. 32u4 could also receive occasional update on printer status from ESP32 so it will use this value when the USB host is asking for printer's status.

What I know is that 32u4 has dual fifo banks for each end point, say the EP1 OUT. I know that when one bank is filled ISR(USB_COM_vect) is called with EPINT1 bit set in UEINT. So I take each byte out of the fifo bank until it's empty and then I release the fifo bank with UEINTX=0x6B;. While I empty this bank, usb host may be filling up the other bank so I think the interrupt is called again when the other bank fills and I do the same, move data out of the bank and release the bank.

Here is my question: if I can't send the data in the bank to ESP32, say due to the actual printer not accepting data (producing NAKs) or ESP32 still processing data, I wish 32u4 to produce NAK to its usb host until it is able to forward data again. How do I go about doing that? My idea is that if 32u4 knows that it can't forward more data, it will just exit the ISR without doing anything. So now a second packet arrives and fill the second bank and causes another ISR. If the ISR continues to do nothing, then the 3rd packet from USB host will receive an NAK since both banks are now filled. And 32u4 will keep producing NAKs until either bank is emptied with UEINTX=0x6B; before accepting more packets. Am I thinking correctly?

From what I saw on USB, the actual printer produces a number of NAKs between some packets, sometimes 16 to 17 NAKs (shown on my USB sniffer as 16 or 17 polls). I suppose the printer is busy processing data or printing so NAKs at this quantity or even more are acceptable.

Go to avrfreaks.net and search for LUFA. Lots of discussion on AVR CPUS using ANSI-C code.

brillmindz1: I'm new to this forum so I'd like to know if this is an appropriate subforum for 32U4 USB device class development questions in general. I have Arduino boards with 32U4 but my development is not specific to Arduino. I would like to get better at writing USB device class code by understanding the 32U4 USB device facilities.

I've been reading 32U4's full documentation. I've also been modifying the USB core code in Arduino IDE. To make things easier for myself, I am using an earlier version of Arduino IDE that has no pluggable USB device code that complicated things quite a bit. I also stripped away the Arduino bootloader and USB CDC so I'm only using USB HID keyboard in one project and USB printer class that I developed in another project. Just to be clear, the Arduino USB device core code I'm modifying has "Copyright (c) 2010, Peter Barrett". I wonder if this forum has a collective knowledge of this core library. If this isn't something folks here use for USB device code development, then what do you use?

Thank you!

Was that YOUR question or was it MY question from a different thread? If you can't be bothered to type up your own question or place quotes around content you borrowed, don't expect getting much help here or elsewhere.

@liuzengqiang

It was a spammer who has been dispatched with gusto.

Bob.