From 32d199b590045e842ebc0749d89f5648b90d2e5b Mon Sep 17 00:00:00 2001 From: weidonglin <527910874@qq.com> Date: Sat, 18 Sep 2021 20:49:17 +0800 Subject: [PATCH] create esp idf example Change-Id: I0cafa36d2d5c3fd661681c430efab616b6b13b57 --- example/esp_idf/CMakeLists.txt | 8 + example/esp_idf/main/CMakeLists.txt | 7 + example/esp_idf/main/esp_idf.c | 65 ++ example/esp_idf/main/test_cmds.c | 102 +++ example/esp_idf/sdkconfig | 1270 +++++++++++++++++++++++++++ 5 files changed, 1452 insertions(+) create mode 100755 example/esp_idf/CMakeLists.txt create mode 100755 example/esp_idf/main/CMakeLists.txt create mode 100755 example/esp_idf/main/esp_idf.c create mode 100755 example/esp_idf/main/test_cmds.c create mode 100644 example/esp_idf/sdkconfig diff --git a/example/esp_idf/CMakeLists.txt b/example/esp_idf/CMakeLists.txt new file mode 100755 index 0000000..97aa15b --- /dev/null +++ b/example/esp_idf/CMakeLists.txt @@ -0,0 +1,8 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(esp_idf) diff --git a/example/esp_idf/main/CMakeLists.txt b/example/esp_idf/main/CMakeLists.txt new file mode 100755 index 0000000..4bd2496 --- /dev/null +++ b/example/esp_idf/main/CMakeLists.txt @@ -0,0 +1,7 @@ +idf_component_register(SRCS "esp_idf.c" + "test_cmds.c" + "../../../src/xcmd.c" + "../../../src/xcmd_default_keys.c" + "../../../src/xcmd_default_cmds.c" + INCLUDE_DIRS "." + "../../../inc/") diff --git a/example/esp_idf/main/esp_idf.c b/example/esp_idf/main/esp_idf.c new file mode 100755 index 0000000..d90fd1f --- /dev/null +++ b/example/esp_idf/main/esp_idf.c @@ -0,0 +1,65 @@ +/* + * @Author: your name + * @Date: 2021-09-14 23:58:24 + * @LastEditTime: 2021-09-16 23:20:43 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: /xcmd/example/linux/linux_main.c + */ +#include +#include +#include +#include "xcmd.h" +#include "xcmd_default_keys.h" +#include "xcmd_default_cmds.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +extern void test_cmd_init(void); + +int cmd_get_char(unsigned char *ch) +{ + *ch = getc(stdin); + return 1; +} + +int cmd_put_char(unsigned char ch) +{ + putchar(ch); + return 1; +} + +int cmd_ctr_a(void* pv) +{ + xcmd_print("this is ctr+a\n"); + return 0; +} + +int cmd_ctr_c(void* pv) +{ + exit(0); +} + +static xcmd_key_t user_keys[] = +{ + {CTR_A, cmd_ctr_a, NULL}, + {CTR_C, cmd_ctr_c, NULL}, +}; + +void user_keys_init(void) +{ + xcmd_key_register(user_keys, sizeof(user_keys)/sizeof(xcmd_key_t)); +} + +void app_main(void) +{ + xcmd_init(cmd_get_char, cmd_put_char); + test_cmd_init(); + user_keys_init(); + + while(1) + { + xcmd_task(); + vTaskDelay(pdMS_TO_TICKS(10)); + } +} diff --git a/example/esp_idf/main/test_cmds.c b/example/esp_idf/main/test_cmds.c new file mode 100755 index 0000000..d2b88fa --- /dev/null +++ b/example/esp_idf/main/test_cmds.c @@ -0,0 +1,102 @@ +/* + * @Author: your name + * @Date: 2021-09-14 23:58:24 + * @LastEditTime: 2021-09-16 22:57:45 + * @LastEditors: your name + * @Description: In User Settings Edit + * @FilePath: /xcmd/example/linux/test_cmds.c + */ +#include "xcmd.h" +#include +#include +#include + +#define EXIT_MESSAGE() xcmd_print(g_cmder, "press \"q\" or \"Q\" to exit!\r\n") + +#define EXIT_CHECK() \ + do \ + (toupper(GET_CHAR()) == 'Q') \ + { \ + uint8_t c; \ + if (GET_CHAR(&c)) \ + { \ + switch (c) \ + case 'q': \ + case 'Q': \ + case 0x1B: \ + return; \ + } \ + } \ + while (0); + +static uint8_t param_check(int need, int argc, char*argv[]) +{ + uint8_t i,ret = 0; + if(need<(argc)) + { + ret = 1; + } + else + { + xcmd_print("err need %d but input %d:\r\n", need, argc-1); + xcmd_print("input= "); + for(i=0; i