Skip to content

Commit

Permalink
support PlatformIO
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingcys committed Oct 21, 2024
1 parent add3600 commit f07d2be
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 11 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ ENDIF ()

include(${TOP_SOURCE_DIR}/tools/cmake/colors.cmake)
include(${TOP_SOURCE_DIR}/tools/cmake/util.cmake)
if(NOT DEFINED TOS_FRAMEWORK)
set(TOS_FRAMEWORK "base")
endif()
message(STATUS "[TOP] Using framework [${TOS_FRAMEWORK}].")
if(DEFINED TOS_PROJECT_PLATFORM)
set(PLATFORM_NAME ${TOS_PROJECT_PLATFORM})
set(PLATFORM_CHIP ${TOS_PROJECT_CHIP})
Expand Down Expand Up @@ -79,6 +83,13 @@ foreach(comp ${COMPONENT_LIST})
# message(STATUS "comp: ${comp}")
add_subdirectory("${TOP_SOURCE_DIR}/src/${comp}")
endforeach(comp)

# add arduino src
if(TOS_FRAMEWORK STREQUAL "arduino")
include(${TOP_SOURCE_DIR}/arduino-tuyaopen/CMakeLists.txt)
message(STATUS "[TOP] LD_FILE: ${LD_FILE}")
endif()

# message(STATUS "[TOP] COMPONENT_LIBS: ${COMPONENT_LIBS}")
# copy_public_include("${COMPONENT_PUBINC}" "${HEADER_DIR}")
list(APPEND HEADER_DIR ${PLATFORM_PUBINC})
Expand All @@ -105,6 +116,11 @@ set(EXAMPLE_LIB "tuyaapp")
list(APPEND PLATFORM_NEED_HDIR ${COMPONENT_PUBINC})
string(REPLACE ";" " " PLATFORM_NEED_HDIR "${PLATFORM_NEED_HDIR}")
set(PLATFORM_NEED_LIBS "${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB}")
if(TOS_FRAMEWORK STREQUAL "arduino")
if(PLATFORM_NAME STREQUAL "t2")
set(PLATFORM_NEED_LIBS "${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB} stdc++")
endif()
endif()
message(STATUS "[TOP] PLATFORM_NEED_LIBS: ${PLATFORM_NEED_LIBS}")
include(${TOS_PROJECT_ROOT}/CMakeLists.txt)
target_include_directories(${EXAMPLE_LIB}
Expand Down Expand Up @@ -150,6 +166,7 @@ add_custom_command(
${PLATFORM_PATH}

COMMAND
export OPEN_LD_FILE="${LD_FILE}" &&
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "build" "${PLATFORM_CHIP}"
Expand All @@ -164,6 +181,9 @@ add_custom_target(platform_clean
${PLATFORM_PATH}

COMMAND

COMMAND
export OPEN_LD_FILE="${LD_FILE}" &&
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "clean"
Expand Down
4 changes: 2 additions & 2 deletions apps/tuya_cloud/switch_demo/project_build.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[project:switch_demo_t2]
platform = t2
[project:switch_demo_t3]
platform = t3
32 changes: 32 additions & 0 deletions tools/app_template/arduino/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
##
# @file CMakeLists.txt
# @brief
#/

# APP_PATH
set(APP_PATH ${CMAKE_CURRENT_LIST_DIR})

# APP_NAME
get_filename_component(APP_NAME ${APP_PATH} NAME)

# APP_SRC
aux_source_directory(${APP_PATH}/src APP_SRC)

# APP_INC
set(APP_INC ${APP_PATH}/include)

########################################
# Target Configure
########################################
add_library(${EXAMPLE_LIB})
message(STATUS "EXAMPLE_LIB:${APP_PATH}")

target_sources(${EXAMPLE_LIB}
PRIVATE
${APP_SRC}
)

target_include_directories(${EXAMPLE_LIB}
PRIVATE
${APP_INC}
)
22 changes: 22 additions & 0 deletions tools/app_template/arduino/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
choice
prompt "Choice Arduino Board"
default ENABLE_ARDUINO_TUYA_T2

config ENABLE_ARDUINO_TUYA_T2
bool "ENABLE_ARDUINO_TUYA_T2"

config ENABLE_ARDUINO_TUYA_T3
bool "ENABLE_ARDUINO_TUYA_T3"
endchoice

if (ENABLE_ARDUINO_TUYA_T2)
config ARDUINO_BOARD
string
default "ARDUINO_TUYA_T2"
endif

if (ENABLE_ARDUINO_TUYA_T3)
config ARDUINO_BOARD
string
default "ARDUINO_TUYA_T3"
endif
3 changes: 3 additions & 0 deletions tools/app_template/arduino/project_build.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[project:###PROJECT_NAME###]
platform = ###PLATFORM_NAME###
framework = arduino
12 changes: 12 additions & 0 deletions tools/app_template/arduino/src/hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "Arduino.h"

void setup(void)
{
Serial.begin(115200);
}

void loop()
{
Serial.println("hello");
delay(1000);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[project:###PROJECT_NAME###]
platform = ###PLATFORM_NAME###
framework = base
File renamed without changes.
9 changes: 6 additions & 3 deletions tools/cmake/util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ endfunction()

function(list_subdirectories RETURN DIR)
file(GLOB_RECURSE subdirectories LIST_DIRECTORIES true "${DIR}/*")
set(non_hidden_subdirectories "")
set(non_hidden_subdirectories ${DIR})
foreach(subdir ${subdirectories})
if(IS_DIRECTORY "${subdir}" AND NOT subdir MATCHES "/[.]")
list(APPEND non_hidden_subdirectories "${subdir}")
if(IS_DIRECTORY "${subdir}")
get_filename_component(subdir_name ${subdir} NAME)
if(NOT ${subdir_name} MATCHES "^\\.")
list(APPEND non_hidden_subdirectories "${subdir}")
endif()
endif()
endforeach()
# message(STATUS "[UTIL] non_hidden_subdirectories:[${non_hidden_subdirectories}]")
Expand Down
61 changes: 55 additions & 6 deletions tos
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ function check_submodules()
cd - > /dev/null
}

function check_arduino()
{
ARDUINO_REPO="https://github.com/tuya/arduino-tuyaopen.git"
ARDUINO_PATH=$OPEN_SDK_ROOT/arduino-tuyaopen
cd $OPEN_SDK_ROOT
if [ -d $ARDUINO_PATH ]; then
show "" "Skip download, exist [$ARDUINO_PATH]."
show "${fore[yellow]}" "If you want to download it again, please remove it."
return 0
fi
git clone $ARDUINO_REPO
if [ ! "0" = "$?" ]; then
show "${fore[red]}" "Clone repo [$ARDUINO_REPO] failed, please try again."
if [ -d "$ARDUINO_PATH" ]; then
show "${fore[yellow]}" "Delete [$ARDUINO_PATH] first."
fi
exit 1
fi
cd $ARDUINO_PATH
TAG=`git describe --tags --abbrev=0`
git checkout $TAG
git submodule update --init
}

function version_exec()
{
show "" "1.0.0"
Expand Down Expand Up @@ -124,6 +148,17 @@ function download_platform_by_name()

function new_exec()
{
TEMPLATE_NAME=$1
if [ -z "$TEMPLATE_NAME" ]; then
TEMPLATE_NAME="base"
fi
TEMPLATE_PATH=$OPEN_SDK_ROOT/tools/app_template/$TEMPLATE_NAME
if [ ! -d $TEMPLATE_PATH ]; then
NOTE="No template named [$TEMPLATE_NAME] exists."
show "${fore[red]}" "$NOTE"
exit 1
fi

read -p "Input project name: " PROJ_NAME
if [ -z "$PROJ_NAME" ]; then
NOTE="Project name is empty."
Expand Down Expand Up @@ -158,7 +193,7 @@ commit: $PLATFORM_COMMIT
chip: $PLATFORM_CHIP" # end PLATFORM_STR
show "" "$PLATFORM_STR"

cp -a $OPEN_SDK_ROOT/tools/app_template $PROJECT_ROOT/$PROJ_NAME
cp -a $TEMPLATE_PATH $PROJECT_ROOT/$PROJ_NAME
sed -i "s/###PROJECT_NAME###/${PROJ_NAME}_${PLATFORM_NAME}/g" $PROJECT_ROOT/$PROJ_NAME/project_build.ini
sed -i "s/###PLATFORM_NAME###/$PLATFORM_NAME/g" $PROJECT_ROOT/$PROJ_NAME/project_build.ini
if [ -n "$PLATFORM_CHIP" ]; then
Expand Down Expand Up @@ -194,6 +229,13 @@ function build_exec()
RET=1
continue
fi
PROJECT_FRAMEWORK=$(echo "$PROJECT_INFO" | grep -oP '(?<=framework = ).*(?=$)')
if [ -z "$PROJECT_FRAMEWORK" ]; then
PROJECT_FRAMEWORK="base"
fi
if [ "$PROJECT_FRAMEWORK" = "arduino" ]; then
check_arduino
fi
PROJECT_CHIP=$(echo "$PROJECT_INFO" | grep -oP '(?<=chip = ).*(?=$)')

PLATFORM_PATH=$OPEN_SDK_ROOT/platform/$PROJECT_PLATFORM
Expand All @@ -208,15 +250,15 @@ function build_exec()
mkdir -p $PROJECT_ROOT/.build/$PROJ
cd $PROJECT_ROOT/.build/$PROJ
if [ -f "$PLATFORM_PATH/build_setup.sh" ]; then
$PLATFORM_PATH/build_setup.sh "${PROJ}" "${PROJECT_PLATFORM}" "${PROJECT_CHIP}"
$PLATFORM_PATH/build_setup.sh "${PROJ}" "${PROJECT_PLATFORM}" "${PROJECT_CHIP}" "${PROJECT_FRAMEWORK}"
fi
cmake $OPEN_SDK_ROOT -DTOS_PROJECT_NAME=$PROJ -DTOS_PROJECT_ROOT=$PROJECT_ROOT -DTOS_PROJECT_PLATFORM=$PROJECT_PLATFORM -DTOS_FRAMEWORK=$PROJECT_FRAMEWORK -DTOS_PROJECT_CHIP=$PROJECT_CHIP
make example
if [ ! "0" = "$?" ]; then
RET=1
fi
if [ -f "$PLATFORM_PATH/build_hock.sh" ]; then
$PLATFORM_PATH/build_hock.sh "${PROJ}" "${PROJECT_PLATFORM}" "${PROJECT_CHIP}"
$PLATFORM_PATH/build_hock.sh "${PROJ}" "${PROJECT_PLATFORM}" "${PROJECT_CHIP}" "${PROJECT_FRAMEWORK}"
fi
cd - > /dev/null
done
Expand Down Expand Up @@ -271,6 +313,10 @@ function menuconfig_exec()

PLATFORMS_DIR="$OPEN_SDK_ROOT/platform"
PLATFORM_PATH="${PLATFORMS_DIR}/${PROJECT_PLATFORM}"
if [ ! -d "$PLATFORM_PATH" ]; then
download_platform_by_name $PROJECT_PLATFORM $PROJECT_CHIP
fi

DOT_CONFIG_DIR="$PROJECT_ROOT/.build/$PROJ/cache"
KCONFIG_CATALOG="CatalogKconfig"
DOT_CONFIG="using.config"
Expand All @@ -281,6 +327,9 @@ function menuconfig_exec()

mkdir -p ${DOT_CONFIG_DIR}
cd ${DOT_CONFIG_DIR}
if [ ! -f $DOT_CONFIG ]; then
cp $PLATFORM_PATH/default.config $DOT_CONFIG
fi
python3 $KCONFIG_TOOLS/set_catalog_config.py -b $PLATFORM_PATH -s $OPEN_SDK_ROOT/src -a $PROJECT_ROOT -o $KCONFIG_CATALOG
bash ${KCONFIG_TOOLS}/run_menuconfig.sh "${KCONFIG_CATALOG}" "$DOT_CONFIG"
python3 ${KCONFIG_TOOLS}/conf2cmake.py -c "${DOT_CONFIG_DIR}/${DOT_CONFIG}" -o "${CMAKE_CONFIG}"
Expand Down Expand Up @@ -342,7 +391,7 @@ Usage: $OPEN_BUILD COMMAND [ARGS]...
Commands:
version - Show TOS verson
check - Check command and version
new - New project
new - New project [base(default) / auduino]
build - Build specific project or all projects
[name] (default build all project by project_build.ini)
clean - Clean specific project or all projects
Expand All @@ -366,7 +415,7 @@ case $1 in
check_exec
;;
new)
new_exec
new_exec $2
;;
build)
build_exec $2
Expand All @@ -375,7 +424,7 @@ case $1 in
clean_exec $2
;;
menuconfig)
menuconfig_exec
menuconfig_exec $2
;;
build_all)
build_all_exec $2
Expand Down

0 comments on commit f07d2be

Please sign in to comment.