app_usbd_dummy.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "sdk_common.h"
  41. #if NRF_MODULE_ENABLED(APP_USBD_DUMMY)
  42. #include <string.h>
  43. #include <ctype.h>
  44. #include "app_usbd.h"
  45. #include "app_usbd_dummy.h"
  46. #include "app_usbd_string_desc.h"
  47. #include "nrf_gpio.h"
  48. /**
  49. * @defgroup app_usbd_dummy_internal USBD Dummy internals
  50. * @{
  51. * @ingroup app_usbd_dummy
  52. * @internal
  53. */
  54. #define NRF_LOG_MODULE_NAME usbd_dummy
  55. #if APP_USBD_DUMMY_CONFIG_LOG_ENABLED
  56. #define NRF_LOG_LEVEL APP_USBD_DUMMY_CONFIG_LOG_LEVEL
  57. #define NRF_LOG_INFO_COLOR APP_USBD_DUMMY_CONFIG_INFO_COLOR
  58. #define NRF_LOG_DEBUG_COLOR APP_USBD_DUMMY_CONFIG_DEBUG_COLOR
  59. #else //APP_USBD_DUMMY_CONFIG_LOG_ENABLED
  60. #define NRF_LOG_LEVEL 0
  61. #endif //APP_USBD_DUMMY_CONFIG_LOG_ENABLED
  62. #include "nrf_log.h"
  63. NRF_LOG_MODULE_REGISTER();
  64. /** @brief @ref app_usbd_class_methods_t::event_handler */
  65. static ret_code_t dummy_class_event_handler(app_usbd_class_inst_t const * p_inst,
  66. app_usbd_complex_evt_t const * p_event)
  67. {
  68. if((p_event->app_evt.type == APP_USBD_EVT_INST_APPEND) ||
  69. (p_event->app_evt.type == APP_USBD_EVT_INST_REMOVE))
  70. {
  71. return NRF_SUCCESS;
  72. }
  73. else
  74. {
  75. return NRF_ERROR_NOT_SUPPORTED;
  76. }
  77. }
  78. /** @brief @ref app_usbd_class_methods_t::feed_descriptors */
  79. static bool dummy_class_feed_descriptors(app_usbd_class_descriptor_ctx_t * p_ctx,
  80. app_usbd_class_inst_t const * p_inst,
  81. uint8_t * p_buff,
  82. size_t max_size)
  83. {
  84. static app_usbd_class_iface_conf_t const * p_cur_iface = 0;
  85. p_cur_iface = app_usbd_class_iface_get(p_inst, 0);
  86. APP_USBD_CLASS_DESCRIPTOR_BEGIN(p_ctx, p_buff, max_size)
  87. /* INTERFACE DESCRIPTOR */
  88. APP_USBD_CLASS_DESCRIPTOR_WRITE(sizeof(app_usbd_descriptor_iface_t)); // bLength
  89. APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DESCRIPTOR_INTERFACE); // bDescriptorType
  90. APP_USBD_CLASS_DESCRIPTOR_WRITE(app_usbd_class_iface_number_get(p_cur_iface)); // bInterfaceNumber
  91. APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bAlternateSetting
  92. APP_USBD_CLASS_DESCRIPTOR_WRITE(0); // bNumEndpoints
  93. APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DUMMY_CLASS); // bInterfaceClass
  94. APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DUMMY_SUBCLASS); // bInterfaceSubClass
  95. APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DUMMY_PROTOCOL); // bInterfaceProtocol
  96. APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // iInterface
  97. APP_USBD_CLASS_DESCRIPTOR_END();
  98. }
  99. const app_usbd_class_methods_t app_usbd_dummy_class_methods = {
  100. .event_handler = dummy_class_event_handler,
  101. .feed_descriptors = dummy_class_feed_descriptors,
  102. };
  103. #endif //NRF_MODULE_ENABLED(APP_USBD_DUMMY)