diff --git a/.gitignore b/.gitignore index 8a8ad5f..5163390 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,5 @@ sdkconfig .idea/ dependencies.lock package-lock.json -**/priv_note.md -_priv_tools/ -project_components/wifi_manager/wifi_configuration.h -managed_components/ \ No newline at end of file +managed_components/ +version.txt \ No newline at end of file diff --git a/components/DAP/DAP_config.h b/components/DAP/DAP_config.h index 20f7b31..b80cad1 100644 --- a/components/DAP/DAP_config.h +++ b/components/DAP/DAP_config.h @@ -370,10 +370,10 @@ __STATIC_INLINE uint8_t DAP_GetProductFirmwareVersionString (char *str) { #define PIN_SWDIO _ // SPI MISO #define PIN_SWDIO_MOSI 7 // SPI MOSI #define PIN_SWCLK 6 - #define PIN_TDO 8 // device TDO -> Host Data Input - #define PIN_TDI 9 + #define PIN_TDO 3 // device TDO -> Host Data Input + #define PIN_TDI 5 #define PIN_nTRST 4 // optional - #define PIN_nRESET 5 + #define PIN_nRESET 10 #define PIN_LED_CONNECTED _ // won't be used #define PIN_LED_RUNNING _ // won't be used diff --git a/project_components/wifi_manager/CMakeLists.txt b/project_components/wifi_manager/CMakeLists.txt index fc12dae..4898152 100644 --- a/project_components/wifi_manager/CMakeLists.txt +++ b/project_components/wifi_manager/CMakeLists.txt @@ -11,7 +11,7 @@ file(GLOB SOURCES idf_component_register( SRCS ${SOURCES} INCLUDE_DIRS "." - PRIV_REQUIRES mdns esp_wifi esp_event api_router wt_storage + PRIV_REQUIRES mdns esp_wifi esp_event api_router wt_storage driver ) idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON) diff --git a/project_components/wt_system/CMakeLists.txt b/project_components/wt_system/CMakeLists.txt new file mode 100644 index 0000000..67195b1 --- /dev/null +++ b/project_components/wt_system/CMakeLists.txt @@ -0,0 +1,13 @@ +file(GLOB SOURCES *.c + ) + +idf_component_register( + SRCS ${SOURCES} + INCLUDE_DIRS "." + PRIV_REQUIRES + global_resource esp_app_format api_router +) + +string(TIMESTAMP CURRENT_DATE "%Y-%m-%d") +add_compile_definitions(FW_UPD_DATE="${CURRENT_DATE}") +idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON) diff --git a/project_components/wt_system/wt_system.c b/project_components/wt_system/wt_system.c new file mode 100644 index 0000000..0de1ad4 --- /dev/null +++ b/project_components/wt_system/wt_system.c @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2024 kerms + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "wt_system.h" +#include "wt_system_api.h" +#include +#include +#include +#include +#include + +#define TAG "WT_SYS" + +void wt_system_get_fm_info(wt_fm_info_t *fm_info) +{ + const esp_app_desc_t *app_desc = esp_app_get_description(); + strcpy(fm_info->fm_ver, app_desc->version); + memcpy(fm_info->upd_date, FW_UPD_DATE, sizeof(fm_info->upd_date) - 1); + fm_info->upd_date[sizeof(fm_info->upd_date) - 1] = '\0'; +} + +static void reboot_task(void *arg) +{ + ESP_LOGW(TAG, "reboot in 2 seconds"); + vTaskDelay(pdMS_TO_TICKS(2000)); + esp_restart(); +} + +void wt_system_reboot() +{ + xTaskCreatePinnedToCore(reboot_task, "reboot", 4096, NULL, 3, NULL, 0); +} + +static int wt_system_init(void) +{ + return 0; +} + +static const global_module_t module = { + .init = wt_system_init, + .module_id = SYSTEM_MODULE_ID +}; + +GLOBAL_MODULE_REGISTER(WT_SYSTEM, &module); diff --git a/project_components/wt_system/wt_system.h b/project_components/wt_system/wt_system.h new file mode 100644 index 0000000..ba5ca93 --- /dev/null +++ b/project_components/wt_system/wt_system.h @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2024 kerms + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef WT_SYSTEM_H_GUARD +#define WT_SYSTEM_H_GUARD + +#include "global_module.h" + +typedef struct wt_fm_info_t { + char fm_ver[32]; + char upd_date[11]; +} wt_fm_info_t; + +void wt_system_get_fm_info(wt_fm_info_t *fm_info); + +/** + * Trigger delayed reboot in 2 seconds + */ +void wt_system_reboot(); + + +#endif //WT_SYSTEM_H_GUARD \ No newline at end of file diff --git a/project_components/wt_system/wt_system_api.h b/project_components/wt_system/wt_system_api.h new file mode 100644 index 0000000..0719d77 --- /dev/null +++ b/project_components/wt_system/wt_system_api.h @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: 2024 kerms + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef WT_SYSTEM_API_H_GUARD +#define WT_SYSTEM_API_H_GUARD + +#define SYSTEM_MODULE_ID 6 + +typedef enum wt_system_cmd_t { + WT_SYS_GET_FM_INFO = 1, + WT_SYS_REBOOT = 2, +} wt_system_cmd_t; + + +#endif //WT_SYSTEM_API_H_GUARD \ No newline at end of file diff --git a/project_components/wt_system/wt_system_api_json.c b/project_components/wt_system/wt_system_api_json.c new file mode 100644 index 0000000..9c8f476 --- /dev/null +++ b/project_components/wt_system/wt_system_api_json.c @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2024 kerms + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "wt_system_api.h" +#include "wt_system.h" +#include "api_json_module.h" +#include "wt_system_json_utils.h" + + +static int sys_api_json_get_fm_info(api_json_req_t *req) +{ + wt_fm_info_t info; + wt_system_get_fm_info(&info); + req->out = wt_sys_json_ser_fm_info(&info); + return API_JSON_OK; +} + +static int on_json_req(uint16_t cmd, api_json_req_t *req, api_json_module_async_t *async) +{ + wt_system_cmd_t ota_cmd = cmd; + switch (ota_cmd) { + default: + break; + case WT_SYS_GET_FM_INFO: + return sys_api_json_get_fm_info(req); + case WT_SYS_REBOOT: + wt_system_reboot(); + return API_JSON_OK; + } + return API_JSON_UNSUPPORTED_CMD; +} + + +/* **** + * register module + * */ + +static int wt_sys_json_init(api_json_module_cfg_t *cfg) +{ + cfg->on_req = on_json_req; + cfg->module_id = SYSTEM_MODULE_ID; + return 0; +} + +API_JSON_MODULE_REGISTER(wt_sys_json_init) diff --git a/project_components/wt_system/wt_system_json_utils.c b/project_components/wt_system/wt_system_json_utils.c new file mode 100644 index 0000000..79c9b05 --- /dev/null +++ b/project_components/wt_system/wt_system_json_utils.c @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2024 kerms + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "wt_system_json_utils.h" + +static void wt_sys_json_add_header(cJSON *root, wt_system_cmd_t cmd) +{ + cJSON_AddNumberToObject(root, "cmd", cmd); + cJSON_AddNumberToObject(root, "module", SYSTEM_MODULE_ID); +} + +cJSON *wt_sys_json_ser_fm_info(wt_fm_info_t *info) +{ + cJSON *root = cJSON_CreateObject(); + wt_sys_json_add_header(root, WT_SYS_GET_FM_INFO); + cJSON_AddStringToObject(root, "fm_ver", info->fm_ver); + cJSON_AddStringToObject(root, "upd_date", info->upd_date); + return root; +} diff --git a/project_components/wt_system/wt_system_json_utils.h b/project_components/wt_system/wt_system_json_utils.h new file mode 100644 index 0000000..6cf4faf --- /dev/null +++ b/project_components/wt_system/wt_system_json_utils.h @@ -0,0 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2024 kerms + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef WT_SYSTEM_JSON_UTILS_H_GUARD +#define WT_SYSTEM_JSON_UTILS_H_GUARD + +#include "wt_system_api.h" +#include "wt_system.h" +#include + + +cJSON *wt_sys_json_ser_fm_info(wt_fm_info_t *info); + +#endif //WT_SYSTEM_JSON_UTILS_H_GUARD \ No newline at end of file