usb_application.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef USBSTACK_APPLICATION_H_
  2. #define USBSTACK_APPLICATION_H_
  3. /*
  4. * Tiny USB stack
  5. * Application level code
  6. *
  7. * Copyright (C) 2009-2016 Michael Buesch <m@bues.ch>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include "usb_config.h"
  19. #include "util.h"
  20. #include <stdint.h>
  21. struct usb_ctrl;
  22. #define USB_APP_UNHANDLED 0xFFu
  23. /** usb_app_reset - Reset all state */
  24. #if USB_APP_HAVE_RESET
  25. void usb_app_reset(void);
  26. #else
  27. static inline void usb_app_reset(void) { }
  28. #endif
  29. /** usb_app_highpower - Called when high-power permission changes.
  30. * @granted: If true, the device is granted more than 1 power unit (100mA),
  31. * but only up to the bMaxPower specified in the configuration descriptor.
  32. */
  33. #if USB_APP_HAVE_HIGHPOWER
  34. void usb_app_highpower(bool granted);
  35. #else
  36. static inline void usb_app_highpower(bool granted) { }
  37. #endif
  38. /** usb_app_control_rx - Handle a received EP0 frame in the app layer.
  39. * @ctl: The received control frame
  40. * @reply_buf: Buffer for reply. Buffer size is USBCFG_EP0_MAXSIZE.
  41. * On success, returns the number of bytes in reply_buf.
  42. * On failure, returns USB_APP_UNHANDLED. */
  43. #if USB_APP_HAVE_CTLSETUPRX
  44. uint8_t usb_app_control_setup_rx(struct usb_ctrl *ctl, uint8_t *reply_buf);
  45. #else
  46. static inline
  47. uint8_t usb_app_control_setup_rx(struct usb_ctrl *ctl, uint8_t *reply_buf)
  48. { return USB_APP_UNHANDLED; }
  49. #endif
  50. /** usb_app_ep1_rx - Handle a received EP1 frame in the app layer.
  51. * @data: The received frame
  52. * @size: The size of the received frame
  53. * @reply_buf: Buffer for reply. Buffer size is USBCFG_EP1_MAXSIZE.
  54. * On success, returns the number of bytes in reply_buf.
  55. * On failure, returns USB_APP_UNHANDLED. */
  56. #if USB_APP_HAVE_EP1RX
  57. uint8_t usb_app_ep1_rx(uint8_t *data, uint8_t size,
  58. uint8_t *reply_buf);
  59. #else
  60. static inline
  61. uint8_t usb_app_ep1_rx(uint8_t *data, uint8_t size,
  62. uint8_t *reply_buf)
  63. { return USB_APP_UNHANDLED; }
  64. #endif
  65. /** usb_app_ep1_tx_poll - Poll TX data for EP1.
  66. * @buffer: The buffer to write the data to.
  67. * The buffer size is USBCFG_EP1_MAXSIZE
  68. * Returns USB_APP_UNHANDLED, if there is no data, yet.
  69. */
  70. #if USB_APP_HAVE_EP1TXPOLL
  71. uint8_t usb_app_ep1_tx_poll(void *buffer);
  72. #else
  73. static inline
  74. uint8_t usb_app_ep1_tx_poll(void *buffer)
  75. { return USB_APP_UNHANDLED; }
  76. #endif
  77. /** usb_app_ep2_rx - Handle a received EP2 frame in the app layer.
  78. * @data: The received frame
  79. * @size: The size of the received frame
  80. * @reply_buf: Buffer for reply. Buffer size is USBCFG_EP2_MAXSIZE.
  81. * On success, returns the number of bytes in reply_buf.
  82. * On failure, returns USB_APP_UNHANDLED. */
  83. #if USB_APP_HAVE_EP2RX
  84. uint8_t usb_app_ep2_rx(uint8_t *data, uint8_t size,
  85. uint8_t *reply_buf);
  86. #else
  87. static inline
  88. uint8_t usb_app_ep2_rx(uint8_t *data, uint8_t size,
  89. uint8_t *reply_buf)
  90. { return USB_APP_UNHANDLED; }
  91. #endif
  92. /** usb_app_ep2_tx_poll - Poll TX data for EP2.
  93. * @buffer: The buffer to write the data to.
  94. * The buffer size is USBCFG_EP2_MAXSIZE
  95. * Returns USB_APP_UNHANDLED, if there is no data, yet.
  96. */
  97. #if USB_APP_HAVE_EP2TXPOLL
  98. uint8_t usb_app_ep2_tx_poll(void *buffer);
  99. #else
  100. static inline
  101. uint8_t usb_app_ep2_tx_poll(void *buffer)
  102. { return USB_APP_UNHANDLED; }
  103. #endif
  104. #endif /* USBSTACK_APPLICATION_H_ */