-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
145 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,75 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}) | ||
set(variant_dir variants/${BOARD}) | ||
elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) | ||
set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) | ||
else() | ||
message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}") | ||
endif() | ||
|
||
if (CONFIG_ARDUINO_API) | ||
add_subdirectory(cores) | ||
add_subdirectory(libraries) | ||
zephyr_include_directories(${variant_dir}) | ||
|
||
function(arduino_sources) | ||
if (IS_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/variants/${BOARD}) | ||
set(variant_dir variants/${BOARD}) | ||
elseif (IS_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) | ||
set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) | ||
else() | ||
message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}") | ||
endif() | ||
|
||
set(ext_name arduino) | ||
set(ext_bin ${ZEPHYR_BINARY_DIR}/${ext_name}.llext) | ||
set(ext_inc ${ZEPHYR_BINARY_DIR}/include/generated/${ext_name}_ext.inc) | ||
|
||
set(core_srcs | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/module_export.c | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrPrint.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrSerial.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrCommon.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/main.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/String.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Stream.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Common.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Print.cpp | ||
) | ||
|
||
if (CONFIG_SPI) | ||
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/SPI/SPI.cpp) | ||
endif() | ||
|
||
if (CONFIG_I2C) | ||
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/Wire/Wire.cpp) | ||
endif() | ||
|
||
if (CONFIG_CAN) | ||
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/CanMsgRingbuffer.cpp | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/CanMsg.cpp) | ||
endif() | ||
|
||
if (CONFIG_USB) | ||
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/PluggableUSB.cpp) | ||
endif() | ||
|
||
if (CONFIG_NET_IP) | ||
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/IPAddress.cpp) | ||
endif() | ||
|
||
add_llext_target(${ext_name}_ext | ||
OUTPUT ${ext_bin} | ||
SOURCES | ||
${core_srcs} | ||
${ARGV} | ||
) | ||
|
||
llext_include_directories(${ext_name}_ext | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/ | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/ | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/SPI/ | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/Wire/ | ||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${variant_dir} | ||
) | ||
|
||
generate_inc_file_for_target(app ${ext_bin} ${ext_inc}) | ||
endfunction() | ||
|
||
if(DEFINED CONFIG_ARDUINO_ENTRY) | ||
target_sources(app PRIVATE cores/arduino/main_loader.c) | ||
endif() | ||
|
||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2024 Arduino SA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL | ||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(app); | ||
|
||
#include <zephyr/llext/llext.h> | ||
#include <zephyr/llext/buf_loader.h> | ||
|
||
static const uint8_t llext_buf[] = { | ||
#include "arduino_ext.inc" | ||
}; | ||
|
||
int main(void) | ||
{ | ||
LOG_INF("Calling hello world as a module"); | ||
|
||
size_t llext_buf_len = ARRAY_SIZE(llext_buf); | ||
struct llext_buf_loader buf_loader = LLEXT_BUF_LOADER(llext_buf, llext_buf_len); | ||
struct llext_loader *ldr = &buf_loader.loader; | ||
|
||
struct llext_load_param ldr_parm = LLEXT_LOAD_PARAM_DEFAULT; | ||
struct llext *ext; | ||
int res; | ||
|
||
res = llext_load(ldr, "ext", &ext, &ldr_parm); | ||
if (res != 0) { | ||
LOG_ERR("Failed to load extension, return code %d\n", res); | ||
return res; | ||
} | ||
|
||
int (*arduino_main)() = llext_find_sym(&ext->exp_tab, "arduino_main"); | ||
|
||
if (arduino_main == NULL) { | ||
LOG_ERR("Failed to find symbol\n"); | ||
return -1; | ||
} | ||
|
||
arduino_main(); | ||
|
||
return llext_unload(&ext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <zephyr/llext/symbol.h> | ||
|
||
int arduino_main(void); | ||
|
||
LL_EXTENSION_SYMBOL(arduino_main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters