# CMake fragment for MicroPython port extmod component

set(MICROPY_MODULES_PORT_DIR ${CMAKE_CURRENT_LIST_DIR})

include("${CMAKE_CURRENT_LIST_DIR}/config.cmake")

set(MICROPY_INC_MODULES_PORT
    ${AOS_COMPONENTS_DIR}/osal_aos/include
    ${AOS_COMPONENTS_DIR}/ulog/include
)

if(MICROPY_PY_AIAGENT)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_AIAGENT=1)

    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/modaiagent.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/aiagent.c)
endif()

if(M5STACK_CORE2)
    set(BOARD_M5STACKCORE2 TRUE)
endif()

if(MICROPY_PY_ALIYUNIOT)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_ALIYUNIOT=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/modaliyunIoT.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_activeinfo.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_device.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_dynreg.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_gateway.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_mqtt.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_ntp.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT/module_aiot_upload.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aliyunIoT)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/data-model)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/dynreg)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/subdev)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/devinfo)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/ntp)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/components/mqtt-upload)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/linksdk/core)
 endif()

if(MICROPY_PY_BLE)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_BLE=1)
    list(APPEND MICROPY_DEF_MODULES_PORT CONFIG_BT=1)

    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble/modble.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble/bt_gatts_adapter.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble/bt_host_adapter.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ble)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ble_host/bt_host/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ble_host/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ble_host/include)
endif()

if(MICROPY_PY_HTTP)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_HTTP=1)
    if(ESP_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http/esp32/modhttp.c)
    endif()
    if(HAAS_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http/aos/modhttp.c)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http/aos/httpclient.c)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/http/include)
    endif()
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/network/http)
endif()

if(MICROPY_PY_MODBUS)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_MODBUS=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/modbus/modbus.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/mbmaster/include)
endif()

if(MICROPY_PY_KV)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_KV=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/kv/modkv.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/kv/include)
endif()

if(MICROPY_PY_OTA)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_OTA=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ota/modota.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ota/include)
endif()

if(MICROPY_PY_OSS)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_OSS=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/oss/modoss.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/oss/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/oss/src)
endif()

if(MICROPY_PY_UCLOUD_AI)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_UCLOUD_AI=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/aiagent.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/aiagent/modaiagent.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ai_agent/include)
endif()

if(MICROPY_PY_MINICV)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_MINICV=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/modminicv.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/datainput.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/imagecodec.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/imageproc.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/ml.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/ui.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/videocodec.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasDataInput.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasImageCodec.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasImageProc.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasML.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasUI.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/c/src/WrapperIHaasVideoCodec.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/core/src/HaasImageUtils.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasML.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasMLCloud.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasMLMnn.cpp)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/minicv/base/modules/ml/src/HaasMLOlda.cpp)
    list(APPEND MICROPY_INC_MODULES_PORT ${HAAS_ENGINE_DIR}/modules/minicv)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucloud_ai/include)
endif()

if(MICROPY_PY_UCAMERA)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_UCAMERA=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ucamera/moducamera.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucamera/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucamera/include/device/wifi)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ucamera/include/device/uart)
endif()

if(MICROPY_PY_DRIVER)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_DRIVER=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/moddriver.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/board_mgr.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/pwm.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/adc.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/timer.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/i2c.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/spi.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/uart.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/gpio.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/driver/wdt.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/amp_adapter/include/peripheral)
    if(HAAS_PLATFORM)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/peripheral/gpio/include)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/drivers/core/base/include)
    endif()
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/cjson/include)
endif()

if(MICROPY_PY_AUDIO)
    include("${MICROPY_MODULES_PORT_DIR}/audio/CMakeLists.txt")
endif()

if(MICROPY_PY_SNTP)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_SNTP=1)

    if(HAAS_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/sntp/aos/modsntp.c)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/sntp/include)
    elseif(ESP_PLATFORM)
        list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/sntp/esp32/modsntp.c)
    endif()
endif()

if(MICROPY_PY_DISPLAY)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_DISPLAY=1)
    list(APPEND MICROPY_DEF_MODULES_PORT LV_USE_SJPG=1)

    file(GLOB_RECURSE DISPLAY_SOURCES ${MICROPY_MODULES_PORT_DIR}/display/*.c)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${DISPLAY_SOURCES})

    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display)
    list(APPEND MICROPY_INC_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/display/esp32)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/little_ui)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/little_ui/3rdparty)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/little_ui/3rdparty/lvgl/src)

    if(MICROPY_PY_DISPLAY_LVGL)
        list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_DISPLAY_LVGL=1)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/little_ui/driver/axp192)
        list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/little_ui/driver/lvgl_esp32_drivers)
    endif()

    if(MICROPY_PY_DISPLAY_TFT)
        list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_DISPLAY_TFT=1)
    endif()

endif()

if(MICROPY_PY_LVGL)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_LVGL=1)
endif()

if(MICROPY_PY_BLECFG)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_BLECFG=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/netconfig/blecfg.c)
endif()

if(MICROPY_PY_NETMGR)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_NETMGR=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/netmgr/modnetmgr.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/uservice/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/netmgr/include)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/amp_adapter/include)
endif()

if(MICROPY_PY_ULOG)
    list(APPEND MICROPY_DEF_MODULES_PORT MICROPY_PY_ULOG=1)
    list(APPEND MICROPY_SOURCE_MODULES_PORT ${MICROPY_MODULES_PORT_DIR}/ulog/modulog.c)
    list(APPEND MICROPY_INC_MODULES_PORT ${AOS_COMPONENTS_DIR}/ulog/include)
endif()
