Skip to content

Commit

Permalink
make API subconfig a list of true config objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mjleehh committed Dec 24, 2024
1 parent a7ef268 commit 45dac5f
Show file tree
Hide file tree
Showing 31 changed files with 434 additions and 41 deletions.
2 changes: 1 addition & 1 deletion config/dependencies/dependencies.aem.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ direct_dependencies:
- espressif/mdns
- idf
- joltwallet/littlefs
manifest_hash: 64cc39553d03f9db8e71bdfaa46b2d0887d647fa8f4061a7b506d5ac581acabc
manifest_hash: 966cff0000a77c6a998f66e21811cdecf47aa8a98e0d34d488524b8364691f99
target: esp32
version: 2.0.0
2 changes: 1 addition & 1 deletion config/dependencies/dependencies.dada.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ direct_dependencies:
- espressif/mdns
- idf
- joltwallet/littlefs
manifest_hash: 64cc39553d03f9db8e71bdfaa46b2d0887d647fa8f4061a7b506d5ac581acabc
manifest_hash: 966cff0000a77c6a998f66e21811cdecf47aa8a98e0d34d488524b8364691f99
target: esp32s3
version: 2.0.0
2 changes: 1 addition & 1 deletion config/dependencies/dependencies.mk2.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ direct_dependencies:
- espressif/mdns
- idf
- joltwallet/littlefs
manifest_hash: 64cc39553d03f9db8e71bdfaa46b2d0887d647fa8f4061a7b506d5ac581acabc
manifest_hash: 966cff0000a77c6a998f66e21811cdecf47aa8a98e0d34d488524b8364691f99
target: esp32
version: 2.0.0
2 changes: 1 addition & 1 deletion config/dependencies/dependencies.str.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ direct_dependencies:
- espressif/mdns
- idf
- joltwallet/littlefs
manifest_hash: 64cc39553d03f9db8e71bdfaa46b2d0887d647fa8f4061a7b506d5ac581acabc
manifest_hash: 966cff0000a77c6a998f66e21811cdecf47aa8a98e0d34d488524b8364691f99
target: esp32
version: 2.0.0
2 changes: 1 addition & 1 deletion config/dependencies/dependencies.v1.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ direct_dependencies:
- espressif/mdns
- idf
- joltwallet/littlefs
manifest_hash: 64cc39553d03f9db8e71bdfaa46b2d0887d647fa8f4061a7b506d5ac581acabc
manifest_hash: 966cff0000a77c6a998f66e21811cdecf47aa8a98e0d34d488524b8364691f99
target: esp32
version: 2.0.0
2 changes: 1 addition & 1 deletion config/dependencies/dependencies.v2.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ direct_dependencies:
- espressif/mdns
- idf
- joltwallet/littlefs
manifest_hash: 64cc39553d03f9db8e71bdfaa46b2d0887d647fa8f4061a7b506d5ac581acabc
manifest_hash: 966cff0000a77c6a998f66e21811cdecf47aa8a98e0d34d488524b8364691f99
target: esp32
version: 2.0.0
4 changes: 3 additions & 1 deletion config/platforms/platform.aem.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"trigger1": 36
}
},
"apis": ["serial"],
"apis": [{
"type": "serial"
}],
"volume_control": true,
"file_system": "wrapper",
"display": {
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.bba1.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"trigger0": 39,
"trigger1": 36
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": null,
"network": true
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.bba2.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"trigger0": -1,
"trigger1": -1
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": null,
"network": true
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.bba2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"trigger0": -1,
"trigger1": -1
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": {
"type": "ssd1306_i2c",
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.dada.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"trigger0": -1,
"trigger1": -1
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": {
"type": "ssd1306_i2c",
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.dadax.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"trigger0": 39,
"trigger1": 36
},
"apis": ["serial"],
"apis": [{
"type": "serial"
}],
"file_system": "wrapper",
"display": null,
"network": false
Expand Down
7 changes: 6 additions & 1 deletion config/platforms/platform.desktop.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
"inputs": {
"type": "gui"
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
},
{
"type": "websocket"
}],
"file_system": "std",
"display": null,
"network": false
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.emu.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"trigger0": 39,
"trigger1": 36
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": null,
"network": true
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.mk2.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
"trigger0": 39,
"trigger1": 36
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": {
"type": "ssd1306_i2c",
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.simulator.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"inputs": {
"type": "gui"
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": null,
"network": false
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.str.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
"trigger0": 39,
"trigger1": 36
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"display": {
"type": "ssd1306_i2c",
"pins": {
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"trigger0": 39,
"trigger1": 36
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": null,
"network": true
Expand Down
4 changes: 3 additions & 1 deletion config/platforms/platform.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"trigger0": 39,
"trigger1": 36
},
"apis": ["wifi"],
"apis": [{
"type": "rest"
}],
"file_system": "wrapper",
"display": null,
"network": true
Expand Down
6 changes: 4 additions & 2 deletions ports/tbd_port_desktop/tbd_api_port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# configure source files
find_package(Boost 1.67.0 COMPONENTS system REQUIRED)
tbd_platform_apis("${TBD_PLATFORM_OBJ}" VAR api_list)
tbd_platform_api_types("${TBD_PLATFORM_OBJ}" VAR api_list)

if (wifi IN_LIST api_list)


if (rest IN_LIST api_list)
list(APPEND SRCS_FILES src/rest_api.cpp)
set(extra_libs INTERFACE simple-web-server)
endif()
Expand Down
6 changes: 3 additions & 3 deletions ports/tbd_port_esp32/tbd_api_port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## configure srcs ##
include(${PROJECT_DIR}/tools/cmake/build_config/platforms.cmake)

# network

Expand All @@ -17,9 +17,9 @@ endif()

# APIs

tbd_platform_apis("${TBD_PLATFORM_OBJ}" VAR api_list)
tbd_platform_api_types("${TBD_PLATFORM_OBJ}" VAR api_list)

if (wifi IN_LIST api_list)
if (rest IN_LIST api_list)
list(APPEND extra_srcs src/rest_api.cpp)
list(APPEND extra_components json esp_http_server)
endif()
Expand Down
14 changes: 5 additions & 9 deletions tbd/tbd_api/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ endif()

# api options

tbd_platform_apis("${TBD_PLATFORM_OBJ}" VAR api_list)
tbd_platform_api_types("${TBD_PLATFORM_OBJ}" VAR api_list)

set(wifi_flag TBD_API_WIFI=0)
set(rest_flag TBD_API_REST=0)
set(serial_flag TBD_API_SERIAL=0)
set(shell_flag TBD_API_SERIAL=0)

# the network module is only available on embedded devices if the 'wifi' api is present
if (wifi IN_LIST api_list AND "${TBD_TOOLCHAIN}" STREQUAL "esp32")
set(wifi_flag TBD_API_WIFI=1)

elseif (wifi IN_LIST api_list)
set(wifi_flag TBD_API_WIFI=1)
if (rest IN_LIST api_list)
set(rest_flag TBD_API_REST=1)
endif()

if (serial IN_LIST api_list)
Expand All @@ -48,7 +44,7 @@ add_library(tbd_api_common INTERFACE ${SRCS_FILES})
target_include_directories(tbd_api_common INTERFACE include)
target_compile_definitions(tbd_api_common
INTERFACE
${wifi_flag}
${rest_flag}
${network_flag}
${serial_flag}
${shell_flag}
Expand Down
2 changes: 1 addition & 1 deletion tbd/tbd_api/library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif()

# api srcs

tbd_platform_apis("${TBD_PLATFORM_OBJ}" VAR api_list)
tbd_platform_api_types("${TBD_PLATFORM_OBJ}" VAR api_list)

if (shell IN_LIST api_list)
file(GLOB microshell_srcs
Expand Down
2 changes: 1 addition & 1 deletion tbd/tbd_api/library/include/tbd/api/rest_api.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#if !TBD_API_WIFI
#if !TBD_API_REST
#error "RestApi module not available in config"
#endif

Expand Down
86 changes: 86 additions & 0 deletions tools/cmake/apis.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
include(${TBD_CMAKE_DIR}/helpers.cmake)
include(${TBD_CMAKE_DIR}/pinouts.cmake)


if ("${TBD_API_TYPES}" STREQUAL "")
file(GLOB api_files
${TBD_CMAKE_DIR}/apis/*.cmake
)
foreach(api_file ${api_files})
get_filename_component(api_name "${api_file}" NAME_WLE)
list(APPEND TBD_API_TYPES "${api_name}")
include("${api_file}")
endforeach()
endif()


#### api base class ####

# helper for accessing api fields
#
#
macro(tbd_api_attrs)
cmake_parse_arguments(arg "" "TYPE" "" ${ARGV})

if (DEFINED arg_KEYWORDS_MISSING_VALUES)
tbd_loge("missing argument value for ${arg_KEYWORDS_MISSING_VALUES}")
endif()

if (NOT arg_TYPE IN_LIST TBD_API_TYPES)
tbd_loge("unknown api type '${arg_TYPE}'")
endif()
endmacro()


# @brief constructor for all api types
#
# @arg TYPE [enum] type of api
#
function(tbd_api var_name)
tbd_api_attrs(${ARGN})
cmake_language(CALL "tbd_api_${arg_TYPE}" CHECK ${ARGN})

if (NOT "${var_name}" STREQUAL "CHECK")
set(${var_name} ${ARGN} PARENT_SCOPE)
endif()
endfunction()

## api properties ##

function(tbd_api_type api)
tbd_api_attrs(${api})
tbd_store_or_return("${arg_TYPE}" ${ARGN})
endfunction()

function(tbd_api_type_flags api)
tbd_api_attrs(${api})

tbd_flag_list_flags("${arg_TYPE}"
FLAGS ${TBD_API_TYPES}
NAMESPACE TBD_API_
VAR flags
)
tbd_store_or_return("${flags}" ${ARGN})
endfunction()

## api methods ##

function(tbd_api_print_info api)
tbd_api_attrs(${api})
cmake_language(CALL "tbd_api_${arg_TYPE}_print_info" "${api}")
endfunction()

function(tbd_api_load json_data)
string(JSON type GET "${json_data}" type)
if (NOT type IN_LIST TBD_API_TYPES)
tbd_loge("unknown api type '${type}'")
endif()

cmake_language(CALL "_tbd_api_${type}_load" "${json_data}" VAR specific)

tbd_api(new_api
TYPE "${type}"
${specific}
)
tbd_store_or_return("${new_api}" ${ARGN})
endfunction()
Loading

0 comments on commit 45dac5f

Please sign in to comment.