diff --git a/arduino/idf/CMakeLists.txt b/arduino/idf/CMakeLists.txt new file mode 100644 index 000000000..078cfe8cd --- /dev/null +++ b/arduino/idf/CMakeLists.txt @@ -0,0 +1,44 @@ +set(SOURCE_DIRS + src/dcc + src/executor + src/freertos_drivers/esp32 + src/freertos_drivers/arduino + src/openlcb + src/os + src/utils +) + +if(CONFIG_ENABLE_ARDUINO_DEPENDS) + list(APPEND SOURCE_DIRS src) +endif() + +set(IDF_DEPS + app_update + bootloader_support + driver + esp_adc + esp_app_format + esp_system + esp_wifi + espcoredump + hal + heap + vfs + mdns) + +idf_component_register(SRC_DIRS "${SOURCE_DIRS}" + INCLUDE_DIRS "src" + REQUIRES "${IDF_DEPS}") + +############################################################################### +# Suppress compilation warnings in OpenMRN +############################################################################### + +target_compile_options(${COMPONENT_LIB} PUBLIC $<$:-Wno-volatile>) +target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-type-limits) +target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-ignored-qualifiers) +target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-missing-field-initializers) +target_compile_options(${COMPONENT_LIB} PRIVATE $<$:-Wno-class-memaccess>) +target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-implicit-fallthrough) +target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=nonnull) +target_compile_options(${COMPONENT_LIB} PRIVATE $<$:-Wno-redundant-move>) diff --git a/arduino/idf/README.md b/arduino/idf/README.md new file mode 100644 index 000000000..7c73b939e --- /dev/null +++ b/arduino/idf/README.md @@ -0,0 +1,6 @@ +# OpenMRN Component for ESP-IDF + +This is an exported version of the OpenMRN library for usage as an ESP-IDF +component. + +More information about OpenMRN can be found [here](https://github.com/bakerstu/openmrn). \ No newline at end of file diff --git a/arduino/idf/library.properties b/arduino/idf/library.properties new file mode 100644 index 000000000..9dd8408fb --- /dev/null +++ b/arduino/idf/library.properties @@ -0,0 +1,11 @@ +name=OpenMRNIDF +version=1.0.2 +author=Stuart Baker, Mike Dunston, Balazs Racz +maintainer=Mike Dunston , Balazs Racz +includes=OpenMRNLite.h +sentence=Network protocol stack for model railroading: OpenLCB and LCC implementation. +paragraph=This library implements network protocols for model railroading. In the center is the OpenLCB protocol suite (Open Layout Control Bus), which has been adopted by the NMRA and referenced as LCC (Layout Command Control): a high-performance and highly extensible communications protocol suite for model railroad control. OpenMRN is one of the most extensible implementation of this protocol suite. The Lite version has been adapted to work with the programming model and drivers of the Arduino ecosystem. Currently supports esp32 and stm32 cores. +category=Communication +url=http://github.com/atanisoft/OpenMRNIDF +architectures=esp32 +dot_a_linkage=true diff --git a/arduino/libify.sh b/arduino/libify.sh index 9835914ba..d26d2892a 100755 --- a/arduino/libify.sh +++ b/arduino/libify.sh @@ -8,12 +8,14 @@ function usage() { echo - echo 'usage: libify.sh path/to/arduino/library/output path/to/openmrn [-f] [-l]' + echo 'usage: libify.sh path/to/arduino/library/output path/to/openmrn [-f] [-l] [-i] [-r]' echo 'exports OpenMRN code as an arduino library.' - echo 'example: libify.sh ~/Arduino/libraries/OpenMRN .. -l' + echo 'example: libify.sh ~/Arduino/libraries/OpenMRNLite .. -l' echo '(options must come after the path specification)' echo '-f will erase the target library before exporting.' echo '-l will create symlinks instead of copying files.' + echo '-i will create OpenMRNIDF repository instead of arduino.' + echo '-r will create relative symlinks. OpenMRNPath has to be a relative path from the library export directory back to openmrn, starting with ../' exit 1 } @@ -38,6 +40,7 @@ fi TARGET_LIB_DIR=$($REALPATH $1 2>/dev/null) OPENMRNPATH=$($REALPATH $2 2>/dev/null) +ORIGOMRNPATH="${2}" if [[ -z ${TARGET_LIB_DIR} ]]; then if [[ $1 ]]; then @@ -61,6 +64,7 @@ fi USE_LINK= VERBOSE= +TARGET_IDF= while [ "x$1" != "x" ] ; do case $1 in @@ -71,19 +75,58 @@ while [ "x$1" != "x" ] ; do -l) USE_LINK=-s ;; + -i) + TARGET_IDF=1 + ;; -v) VERBOSE=1 ;; + -r) + USE_LINK=-s + export RELATIVE=1 + OPENMRNPATH="${ORIGOMRNPATH}" + ;; esac shift done +# Creates a relative path to the toplevel of the directory. +# $1 is a directory path without trailing /, such as +# 'src/freertos_drivers/esp32" +# prints to stdout a relative path like "../../.." to get back to the toplevel +# from the given subdiretory. +function get_relative() { + if [ "x${RELATIVE}" == "x" ]; then + # print nothing + return + fi + if [ "x${1}" == "x." ] ; then + echo "./" + return + fi + SUB="$(echo $1 | sed s/[^/]//g)" + case ${SUB} in + "") + echo "../" + ;; + "/") + echo "../../" + ;; + "//") + echo "../../../" + ;; + *) + echo UNKNOWN SUBTREE "'"${SUB}"'" + esac +} + # Arguments: # $1 is the relative path in the library directory # $2... is the relative path in openmrn tree with the filename # Will create necessary directories internally. function copy_file() { - REL_DIR=$1 + REL_DIR="$1" + INVERSE_DIR="$(get_relative $1)" shift if [ "x$VERBOSE" != "x" ]; then echo "Creating ${TARGET_LIB_DIR}/${REL_DIR}" @@ -92,13 +135,13 @@ function copy_file() { pushd ${TARGET_LIB_DIR}/${REL_DIR} >/dev/null while [ "x$1" != "x" ] ; do if [ "x$VERBOSE" != "x" ]; then - echo "${OPENMRNPATH}/${1} ==> ${TARGET_LIB_DIR}/${REL_DIR}" + echo "${INVERSE_DIR}${OPENMRNPATH}/${1} ==> ${TARGET_LIB_DIR}/${REL_DIR}" fi if [[ "$OSTYPE" == "darwin"* ]]; then - cp -fa ${USE_LINK} ${OPENMRNPATH}/${1} . + cp -fa ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/${1} . else - cp -fax ${USE_LINK} ${OPENMRNPATH}/${1} . + cp -fax ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/${1} . fi shift @@ -118,22 +161,28 @@ function copy_dir() { pushd ${TARGET_LIB_DIR}/$1 >/dev/null if [ "x$VERBOSE" != "x" ]; then - echo "${OPENMRNPATH}/${2} ==> ${TARGET_LIB_DIR}/$1" + echo "${INVERSE_DIR}${OPENMRNPATH}/${2} ==> ${TARGET_LIB_DIR}/$1" fi if [[ "$OSTYPE" == "darwin"* ]]; then - cp -fa ${USE_LINK} ${OPENMRNPATH}/$2 . + cp -fa ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/$2 . else - cp -faxr ${USE_LINK} ${OPENMRNPATH}/$2 . + cp -faxr ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/$2 . fi popd >/dev/null } -copy_file . arduino/{library.json,library.properties,keywords.txt,README.md,LICENSE,CONTRIBUTING.md} -copy_dir . arduino/examples +if [ "x$TARGET_IDF" == "x" ]; then + copy_file . arduino/{library.json,library.properties,keywords.txt,README.md,LICENSE,CONTRIBUTING.md} + copy_dir . arduino/examples + copy_file src arduino/OpenMRNLite.{h,cpp} +else + copy_file . arduino/LICENSE arduino/idf/{CMakeLists.txt,README.md} + copy_file src arduino/idf/library.properties arduino/keywords.txt +fi -copy_file src arduino/OpenMRNLite.{h,cpp} arduino/CDIXMLGenerator.hxx \ +copy_file src arduino/CDIXMLGenerator.hxx \ include/{can_frame.h,nmranet_config.h,openmrn_features.h,i2c.h,i2c-dev.h} \ include/freertos/{bootloader_hal.h,can_ioctl.h,endian.h,freertos_includes.h,stropts.h} \ include/freertos_select/ifaddrs.h