dmitrystu / libusb_stm32

Lightweight USB device Stack for STM32 microcontrollers
Apache License 2.0
713 stars 163 forks source link

No seperate callback for in/out endpoint possible #48

Closed Seneral closed 4 years ago

Seneral commented 4 years ago

The demo makes clear that the following is expected to work:

usbd_reg_endpoint(dev, CDC_RXD_EP, cdc_rxonly);
usbd_reg_endpoint(dev, CDC_TXD_EP, cdc_txonly);

(where CDC_RXD_EP = 0x01, CDC_TXD_EP = 0x81). However, when the callbacks are stored, the in/out distinction is thrown away:

dev->endpoint[ep & 0x07] = callback;

Thus resulting in both endpoints having the same callback, despite expected to have their own.

Not entirely sure about this, how this relates to the endpoint limitation noted in the readme, since I haven't finished porting my code from HAL USB stack. But from the code I see no reason to not store and access the callbacks as follows:

dev->endpoint[((ep >> 4) & 0x08) | (ep & 0x07)]

For me not a big deal, as a workaround I can use a different base is for the in/out endpoints. Or even better, just differenciate between in/out in the shared handler using the passed full ep number

dmitrystu commented 4 years ago

Yes. There is one callback for each physical endpoint. I think this is a reasonable simplification. Another simplification is equality between physical and logical numbers for the endpoints. In the case of using a combined endpoint, TX/RX flow can be selected in accordance with the event passed into the callback.

dmitrystu commented 4 years ago

Also, the number of the endpoint passed into callback is a full logical endpoint number with direction bit.

dmitrystu commented 4 years ago

Yes. There is a bug in the demo code. I have changed endpoints with https://github.com/dmitrystu/libusb_stm32/commit/c280f0649ee2d1c8d83427a28f2f9d27083eac70 because of no enough endpoints in F4 otgfs. It will be fixed.

Seneral commented 4 years ago

Alright, thanks for the clarification. Finished porting and much happier with this library compared to HAL USB stack.