From 6a9f9718821138ca0f667246406444bc957c2424 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 7 Apr 2020 13:42:48 +0700 Subject: [PATCH] add saola button pin support, esp32 build with board_test --- examples/device/board_test/CMakeLists.txt | 14 ++++++++++++++ examples/device/board_test/sdkconfig.defaults | 4 ++++ examples/device/board_test/src/CMakeLists.txt | 19 +++++++++++++++++++ examples/device/board_test/src/main.c | 7 +++++++ examples/device/board_test/src/tusb_config.h | 5 ++++- .../device/cdc_msc_freertos/CMakeLists.txt | 4 ++++ .../cdc_msc_freertos/src/CMakeLists.txt | 4 ---- hw/bsp/esp32s2_saola/esp32s2_saola.c | 12 ++++++++++-- 8 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 examples/device/board_test/CMakeLists.txt create mode 100644 examples/device/board_test/sdkconfig.defaults create mode 100644 examples/device/board_test/src/CMakeLists.txt diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt new file mode 100644 index 000000000..1d8f2fe32 --- /dev/null +++ b/examples/device/board_test/CMakeLists.txt @@ -0,0 +1,14 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +# example src directory +set(EXTRA_COMPONENT_DIRS "src") + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +project(board_test) diff --git a/examples/device/board_test/sdkconfig.defaults b/examples/device/board_test/sdkconfig.defaults new file mode 100644 index 000000000..34991d70c --- /dev/null +++ b/examples/device/board_test/sdkconfig.defaults @@ -0,0 +1,4 @@ +CONFIG_IDF_CMAKE=y +CONFIG_IDF_TARGET="esp32s2" +CONFIG_IDF_TARGET_ESP32S2=y + diff --git a/examples/device/board_test/src/CMakeLists.txt b/examples/device/board_test/src/CMakeLists.txt new file mode 100644 index 000000000..66746502c --- /dev/null +++ b/examples/device/board_test/src/CMakeLists.txt @@ -0,0 +1,19 @@ +idf_component_register(SRCS "main.c" + INCLUDE_DIRS "." + REQUIRES freertos soc) + +target_compile_options(${COMPONENT_TARGET} PUBLIC + "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" + "-DCFG_TUSB_OS=OPT_OS_FREERTOS" +) + +idf_component_get_property( FREERTOS_ORIG_INCLUDE_PATH freertos ORIG_INCLUDE_PATH) +target_include_directories(${COMPONENT_TARGET} PUBLIC + "${FREERTOS_ORIG_INCLUDE_PATH}" + "${TOP}/hw" + "${TOP}/src" +) + +target_sources(${COMPONENT_TARGET} PUBLIC + "${TOP}/hw/bsp/esp32s2_saola/esp32s2_saola.c" +) diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c index 584ff799d..71665550f 100644 --- a/examples/device/board_test/src/main.c +++ b/examples/device/board_test/src/main.c @@ -73,3 +73,10 @@ int main(void) return 0; } + +#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 +void app_main(void) +{ + main(); +} +#endif diff --git a/examples/device/board_test/src/tusb_config.h b/examples/device/board_test/src/tusb_config.h index 1a52cc348..0587d48e3 100644 --- a/examples/device/board_test/src/tusb_config.h +++ b/examples/device/board_test/src/tusb_config.h @@ -39,8 +39,11 @@ #error CFG_TUSB_MCU must be defined #endif +#ifndef CFG_TUSB_OS + #define CFG_TUSB_OS OPT_OS_NONE +#endif + #define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE -#define CFG_TUSB_OS OPT_OS_NONE // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/cdc_msc_freertos/CMakeLists.txt b/examples/device/cdc_msc_freertos/CMakeLists.txt index f2e711944..2f1f6a950 100644 --- a/examples/device/cdc_msc_freertos/CMakeLists.txt +++ b/examples/device/cdc_msc_freertos/CMakeLists.txt @@ -5,6 +5,10 @@ cmake_minimum_required(VERSION 3.5) # example src directory set(EXTRA_COMPONENT_DIRS "src") +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(cdc_msc_freertos) diff --git a/examples/device/cdc_msc_freertos/src/CMakeLists.txt b/examples/device/cdc_msc_freertos/src/CMakeLists.txt index 3d2010ed2..d24bc2e41 100644 --- a/examples/device/cdc_msc_freertos/src/CMakeLists.txt +++ b/examples/device/cdc_msc_freertos/src/CMakeLists.txt @@ -1,7 +1,3 @@ -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../../..") -get_filename_component(TOP "${TOP}" REALPATH) - idf_component_register(SRCS "main.c" "usb_descriptors.c" "msc_disk.c" INCLUDE_DIRS "." REQUIRES freertos soc) diff --git a/hw/bsp/esp32s2_saola/esp32s2_saola.c b/hw/bsp/esp32s2_saola/esp32s2_saola.c index 06590c684..16d054f75 100644 --- a/hw/bsp/esp32s2_saola/esp32s2_saola.c +++ b/hw/bsp/esp32s2_saola/esp32s2_saola.c @@ -32,7 +32,10 @@ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ -#define LED_PIN 21 +#define LED_PIN 21 + +#define BUTTON_PIN 0 +#define BUTTON_STATE_ACTIVE 0 // Initialize on-board peripherals : led, button, uart and USB void board_init(void) @@ -41,6 +44,11 @@ void board_init(void) gpio_pad_select_gpio(LED_PIN); gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT); + // Button + gpio_pad_select_gpio(BUTTON_PIN); + gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT); + gpio_set_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY); + // USB Controller Hal init usb_hal_context_t hal = { .use_external_phy = false // use built-in PHY @@ -58,7 +66,7 @@ void board_led_write(bool state) // a '1' means active (pressed), a '0' means inactive. uint32_t board_button_read(void) { - return 0; + return gpio_get_level(BUTTON_PIN) == BUTTON_STATE_ACTIVE; } // Get characters from UART