CMakeLists.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. idf_build_get_property(target IDF_TARGET)
  2. set(srcs)
  3. set(includes_public)
  4. set(includes_private)
  5. set(compile_options)
  6. if(CONFIG_TINYUSB)
  7. if(target STREQUAL "esp32s3")
  8. set(tusb_mcu "OPT_MCU_ESP32S3")
  9. set(tusb_family "esp32sx")
  10. elseif(target STREQUAL "esp32s2")
  11. set(tusb_mcu "OPT_MCU_ESP32S2")
  12. set(tusb_family "esp32sx")
  13. else()
  14. # CONFIG_TINYUSB dependency has been garanteed by Kconfig logic,
  15. # So it's not possible that cmake goes here
  16. message(FATAL_ERROR "TinyUSB is not support on ${target}.")
  17. return()
  18. endif()
  19. list(APPEND compile_options
  20. "-DCFG_TUSB_MCU=${tusb_mcu}"
  21. "-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
  22. )
  23. idf_component_get_property(freertos_component_dir freertos COMPONENT_DIR)
  24. list(APPEND includes_private
  25. "tinyusb/hw/bsp/"
  26. "tinyusb/src/"
  27. "tinyusb/src/device"
  28. "additions/include_private"
  29. )
  30. list(APPEND includes_public
  31. "tinyusb/src/"
  32. "additions/include"
  33. # The FreeRTOS API include convention in tinyusb is different from esp-idf
  34. "${freertos_component_dir}/include/freertos"
  35. )
  36. list(APPEND srcs
  37. "tinyusb/src/portable/espressif/${tusb_family}/dcd_${tusb_family}.c"
  38. "tinyusb/src/class/cdc/cdc_device.c"
  39. "tinyusb/src/class/hid/hid_device.c"
  40. "tinyusb/src/class/midi/midi_device.c"
  41. "tinyusb/src/class/msc/msc_device.c"
  42. "tinyusb/src/class/vendor/vendor_device.c"
  43. "tinyusb/src/common/tusb_fifo.c"
  44. "tinyusb/src/device/usbd_control.c"
  45. "tinyusb/src/device/usbd.c"
  46. "tinyusb/src/tusb.c"
  47. "additions/src/descriptors_control.c"
  48. "additions/src/tinyusb.c"
  49. "additions/src/tusb_tasks.c"
  50. "additions/src/usb_descriptors.c"
  51. )
  52. # when no builtin class driver is enabled, an uint8_t data compared with `BUILTIN_DRIVER_COUNT` will always be false
  53. set_source_files_properties("tinyusb/src/device/usbd.c" PROPERTIES COMPILE_FLAGS "-Wno-type-limits")
  54. if(CONFIG_TINYUSB_CDC_ENABLED)
  55. list(APPEND srcs
  56. "additions/src/cdc.c"
  57. "additions/src/tusb_cdc_acm.c"
  58. "additions/src/tusb_console.c"
  59. "additions/src/vfs_tinyusb.c"
  60. )
  61. endif() # CONFIG_TINYUSB_CDC_ENABLED
  62. endif() # CONFIG_TINYUSB
  63. idf_component_register(SRCS ${srcs}
  64. INCLUDE_DIRS ${includes_public}
  65. PRIV_INCLUDE_DIRS ${includes_private}
  66. PRIV_REQUIRES "vfs" "usb"
  67. )
  68. if(CONFIG_TINYUSB)
  69. target_compile_options(${COMPONENT_LIB} PRIVATE ${compile_options})
  70. endif()