Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

usb-internal.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright (c) 2011,2012 Simon Schubert <[email protected]>.
  2. * Modifications by Jacob Alexander 2014 <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __USB_INTERNAL_H
  18. #define __USB_INTERNAL_H
  19. /**
  20. * Internal driver structures
  21. */
  22. /**
  23. * USB state machine
  24. * =================
  25. *
  26. * Device configuration states:
  27. *
  28. * Attached <-> Powered
  29. * Powered -(reset)-> Default
  30. * Default -(SET_ADDRESS)-> Address
  31. * Address -(SET_CONFIGURATION)-> Configured
  32. * Configured -(SET_CONFIGURATION 0)-> Address
  33. * Address -(SET_ADDRESS 0)-> Default
  34. * [Default, Configured, Address] -(reset)-> Default
  35. */
  36. // ----- Defines -----
  37. #ifndef USB_MAX_EP
  38. #define USB_MAX_EP 16
  39. #endif
  40. // ----- Structs -----
  41. struct usbd_ep_pipe_state_t {
  42. enum usb_ep_pingpong pingpong; /* next desc to use */
  43. enum usb_data01 data01;
  44. size_t transfer_size;
  45. size_t pos;
  46. uint8_t *data_buf;
  47. const uint8_t *copy_source;
  48. int short_transfer;
  49. ep_callback_t callback;
  50. void *callback_data;
  51. size_t ep_maxsize;
  52. /* constant */
  53. int ep_num;
  54. enum usb_ep_dir ep_dir;
  55. };
  56. struct usbd_ep_state_t {
  57. union {
  58. struct usbd_ep_pipe_state_t pipe[2];
  59. struct {
  60. struct usbd_ep_pipe_state_t rx;
  61. struct usbd_ep_pipe_state_t tx;
  62. };
  63. };
  64. };
  65. struct usbd_t {
  66. struct usbd_function_ctx_header functions;
  67. struct usbd_function control_function;
  68. const struct usbd_device *identity;
  69. int address;
  70. int config;
  71. enum usbd_dev_state {
  72. USBD_STATE_DISABLED = 0,
  73. USBD_STATE_DEFAULT,
  74. USBD_STATE_SETTING_ADDRESS,
  75. USBD_STATE_ADDRESS,
  76. USBD_STATE_CONFIGURED
  77. } state;
  78. enum usb_ctrl_req_dir ctrl_dir;
  79. struct usbd_ep_state_t ep_state[USB_MAX_EP];
  80. };
  81. extern struct usbd_t usb;
  82. // ----- Functions -----
  83. void usb_restart(void);
  84. void usb_enable(void);
  85. const struct usbd_config *usb_get_config_data(int config);
  86. #endif