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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (c) 2011,2012 Simon Schubert <[email protected]>.
  2. * Modifications by Jacob Alexander 2014-2015 <[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. #pragma once
  18. /**
  19. * Internal driver structures
  20. */
  21. /**
  22. * USB state machine
  23. * =================
  24. *
  25. * Device configuration states:
  26. *
  27. * Attached <-> Powered
  28. * Powered -(reset)-> Default
  29. * Default -(SET_ADDRESS)-> Address
  30. * Address -(SET_CONFIGURATION)-> Configured
  31. * Configured -(SET_CONFIGURATION 0)-> Address
  32. * Address -(SET_ADDRESS 0)-> Default
  33. * [Default, Configured, Address] -(reset)-> Default
  34. */
  35. // ----- Defines -----
  36. #ifndef USB_MAX_EP
  37. #define USB_MAX_EP 16
  38. #endif
  39. // ----- Structs -----
  40. struct usbd_ep_pipe_state_t {
  41. enum usb_ep_pingpong pingpong; /* next desc to use */
  42. enum usb_data01 data01;
  43. size_t transfer_size;
  44. size_t pos;
  45. uint8_t *data_buf;
  46. const uint8_t *copy_source;
  47. int short_transfer;
  48. ep_callback_t callback;
  49. void *callback_data;
  50. size_t ep_maxsize;
  51. /* constant */
  52. int ep_num;
  53. enum usb_ep_dir ep_dir;
  54. };
  55. struct usbd_ep_state_t {
  56. union {
  57. struct usbd_ep_pipe_state_t pipe[2];
  58. struct {
  59. struct usbd_ep_pipe_state_t rx;
  60. struct usbd_ep_pipe_state_t tx;
  61. };
  62. };
  63. };
  64. struct usbd_t {
  65. struct usbd_function_ctx_header functions;
  66. struct usbd_function control_function;
  67. const struct usbd_device *identity;
  68. int address;
  69. int config;
  70. enum usbd_dev_state {
  71. USBD_STATE_DISABLED = 0,
  72. USBD_STATE_DEFAULT,
  73. USBD_STATE_SETTING_ADDRESS,
  74. USBD_STATE_ADDRESS,
  75. USBD_STATE_CONFIGURED
  76. } state;
  77. enum usb_ctrl_req_dir ctrl_dir;
  78. struct usbd_ep_state_t ep_state[USB_MAX_EP];
  79. };
  80. extern struct usbd_t usb;
  81. // ----- Functions -----
  82. void usb_restart(void);
  83. void usb_enable(void);
  84. const struct usbd_config *usb_get_config_data(int config);