main.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2019 Ha Thach (tinyusb.org)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. * This file is part of the TinyUSB stack.
  25. */
  26. //--------------------------------------------------------------------+
  27. // INCLUDE
  28. //--------------------------------------------------------------------+
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include "board.h"
  33. #include "tusb.h"
  34. #include "mouse_host_app.h"
  35. #include "keyboard_host_app.h"
  36. #include "msc_host_app.h"
  37. #include "cdc_serial_host_app.h"
  38. //--------------------------------------------------------------------+
  39. // MACRO CONSTANT TYPEDEF
  40. //--------------------------------------------------------------------+
  41. //--------------------------------------------------------------------+
  42. // INTERNAL OBJECT & FUNCTION DECLARATION
  43. //--------------------------------------------------------------------+
  44. void print_greeting(void);
  45. //--------------------------------------------------------------------+
  46. // IMPLEMENTATION
  47. //--------------------------------------------------------------------+
  48. #if CFG_TUSB_OS == OPT_OS_NONE
  49. // like a real RTOS, this function is a main loop invoking each task in application and never return
  50. void os_none_start_scheduler(void)
  51. {
  52. while (1)
  53. {
  54. tusb_task();
  55. led_blinking_task(NULL);
  56. keyboard_host_app_task(NULL);
  57. mouse_host_app_task(NULL);
  58. msc_host_app_task(NULL);
  59. cdc_serial_host_app_task(NULL);
  60. }
  61. }
  62. #endif
  63. int main(void)
  64. {
  65. #if CFG_TUSB_OS == TUSB_OS_CMSIS_RTX
  66. osKernelInitialize(); // CMSIS RTX requires kernel init before any other OS functions
  67. #endif
  68. board_init();
  69. print_greeting();
  70. tusb_init();
  71. //------------- application task init -------------//
  72. led_blinking_init();
  73. keyboard_host_app_init();
  74. mouse_host_app_init();
  75. msc_host_app_init();
  76. cdc_serial_host_app_init();
  77. //------------- start OS scheduler (never return) -------------//
  78. #if CFG_TUSB_OS == OPT_OS_FREERTOS
  79. vTaskStartScheduler();
  80. #elif CFG_TUSB_OS == OPT_OS_NONE
  81. os_none_start_scheduler();
  82. #elif CFG_TUSB_OS == TUSB_OS_CMSIS_RTX
  83. osKernelStart();
  84. #else
  85. #error need to start RTOS schduler
  86. #endif
  87. return 0;
  88. }
  89. //--------------------------------------------------------------------+
  90. // HELPER FUNCTION
  91. //--------------------------------------------------------------------+
  92. void print_greeting(void)
  93. {
  94. char const * const rtos_name[] =
  95. {
  96. [OPT_OS_NONE] = "None",
  97. [OPT_OS_FREERTOS] = "FreeRTOS",
  98. };
  99. puts("\n\
  100. --------------------------------------------------------------------\n\
  101. - Host Demo (a tinyusb example)\n\
  102. - if you find any bugs or get any questions, feel free to file an\n\
  103. - issue at https://github.com/hathach/tinyusb\n\
  104. --------------------------------------------------------------------\n"
  105. );
  106. puts("This HOST demo is configured to support:");
  107. printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
  108. if (CFG_TUH_HUB ) puts(" - Hub (1 level only)");
  109. if (CFG_TUH_HID_MOUSE ) puts(" - HID Mouse");
  110. if (CFG_TUH_HID_KEYBOARD ) puts(" - HID Keyboard");
  111. if (CFG_TUH_MSC ) puts(" - Mass Storage");
  112. if (CFG_TUH_CDC ) puts(" - Communication Device Class");
  113. }