usb.h 1.3 KB

123456789101112131415161718192021222324252627282930
  1. /* Minimal polled USB CDC-ACM device stack for ATmega8U2 (no LUFA, no interrupts) */
  2. #ifndef USB_H
  3. #define USB_H
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. #define USB_PACKET 64
  7. void usb_init(void);
  8. void usb_task(void); /* call often: reset + EP0 handling */
  9. bool usb_ready(void); /* true once host configured device */
  10. uint8_t usb_rx(uint8_t *buf); /* copy one OUT packet (<=64B), 0=none */
  11. void usb_tx(const uint8_t *buf, uint8_t n); /* send one IN packet (<=64B), drops on timeout */
  12. /* EP0 helpers for vendor requests (data stage may span several 32 B packets) */
  13. #define EP0_SIZE 32
  14. bool ep0_wait(uint8_t mask);
  15. void ep0_stall(void);
  16. void ep0_status_in(void); /* finish an OUT/no-data request */
  17. void ep0_status_out(void); /* finish an IN request */
  18. void ep0_send(const void *p, uint16_t len, uint16_t wlen, bool pgm); /* whole IN request */
  19. uint8_t ep0_rx(uint8_t *buf); /* next OUT data packet, 0xFF on abort/timeout */
  20. bool ep0_tx(const uint8_t *buf, uint8_t n); /* next IN data packet, false on abort */
  21. /* implemented by the application */
  22. void usb_vendor_request(uint8_t bmRT, uint8_t bReq, uint16_t wValue, uint16_t wIndex, uint16_t wLength);
  23. void usb_reset_hook(void); /* USB bus reset seen */
  24. #endif