usb_desc_dfu.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * usb_desc_dfu.c
  3. *
  4. * Copyright (C) 2019 Sylvain Munaut
  5. * All rights reserved.
  6. *
  7. * LGPL v3+, see LICENSE.lgpl3
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. */
  23. #include <no2usb/usb_proto.h>
  24. #include <no2usb/usb.h>
  25. #define NULL ((void*)0)
  26. #define num_elem(a) (sizeof(a) / sizeof(a[0]))
  27. static const struct {
  28. struct usb_conf_desc conf;
  29. struct usb_intf_desc if_fpga;
  30. struct usb_dfu_desc dfu_fpga;
  31. struct usb_intf_desc if_riscv;
  32. struct usb_dfu_desc dfu_riscv;
  33. } __attribute__ ((packed)) _dfu_conf_desc = {
  34. .conf = {
  35. .bLength = sizeof(struct usb_conf_desc),
  36. .bDescriptorType = USB_DT_CONF,
  37. .wTotalLength = sizeof(_dfu_conf_desc),
  38. .bNumInterfaces = 1,
  39. .bConfigurationValue = 1,
  40. .iConfiguration = 4,
  41. .bmAttributes = 0x80,
  42. .bMaxPower = 0x32, /* 100 mA */
  43. },
  44. .if_fpga = {
  45. .bLength = sizeof(struct usb_intf_desc),
  46. .bDescriptorType = USB_DT_INTF,
  47. .bInterfaceNumber = 0,
  48. .bAlternateSetting = 0,
  49. .bNumEndpoints = 0,
  50. .bInterfaceClass = 0xfe,
  51. .bInterfaceSubClass = 0x01,
  52. .bInterfaceProtocol = 0x02,
  53. .iInterface = 5,
  54. },
  55. .dfu_fpga = {
  56. .bLength = sizeof(struct usb_dfu_desc),
  57. .bDescriptorType = USB_DT_DFU,
  58. .bmAttributes = 0x0d,
  59. .wDetachTimeOut = 1000,
  60. .wTransferSize = 4096,
  61. .bcdDFUVersion = 0x0101,
  62. },
  63. .if_riscv = {
  64. .bLength = sizeof(struct usb_intf_desc),
  65. .bDescriptorType = USB_DT_INTF,
  66. .bInterfaceNumber = 0,
  67. .bAlternateSetting = 1,
  68. .bNumEndpoints = 0,
  69. .bInterfaceClass = 0xfe,
  70. .bInterfaceSubClass = 0x01,
  71. .bInterfaceProtocol = 0x02,
  72. .iInterface = 6,
  73. },
  74. .dfu_riscv = {
  75. .bLength = sizeof(struct usb_dfu_desc),
  76. .bDescriptorType = USB_DT_DFU,
  77. .bmAttributes = 0x0d,
  78. .wDetachTimeOut = 1000,
  79. .wTransferSize = 4096,
  80. .bcdDFUVersion = 0x0101,
  81. },
  82. };
  83. static const struct usb_conf_desc * const _conf_desc_array[] = {
  84. &_dfu_conf_desc.conf,
  85. };
  86. static const struct usb_dev_desc _dev_desc = {
  87. .bLength = sizeof(struct usb_dev_desc),
  88. .bDescriptorType = USB_DT_DEV,
  89. .bcdUSB = 0x0200,
  90. .bDeviceClass = 0,
  91. .bDeviceSubClass = 0,
  92. .bDeviceProtocol = 0,
  93. .bMaxPacketSize0 = 64,
  94. #if defined(BOARD_ICE1USB)
  95. .idVendor = 0x1d50,
  96. .idProduct = 0x6144,
  97. #elif defined(BOARD_ICEPICK)
  98. .idVendor = 0x1d50,
  99. .idProduct = 0x6148,
  100. #elif defined(BOARD_E1TRACER)
  101. .idVendor = 0x1d50,
  102. .idProduct = 0x6150,
  103. #else
  104. .idVendor = 0x1d50,
  105. .idProduct = 0x6146,
  106. #endif
  107. .bcdDevice = 0x0004, /* v0.4 */
  108. .iManufacturer = 2,
  109. .iProduct = 3,
  110. .iSerialNumber = 1,
  111. .bNumConfigurations = num_elem(_conf_desc_array),
  112. };
  113. #include "usb_str_dfu.gen.h"
  114. const struct usb_stack_descriptors dfu_stack_desc = {
  115. .dev = &_dev_desc,
  116. .conf = _conf_desc_array,
  117. .n_conf = num_elem(_conf_desc_array),
  118. .str = _str_desc_array,
  119. .n_str = num_elem(_str_desc_array),
  120. };