create esp idf example

Change-Id: I0cafa36d2d5c3fd661681c430efab616b6b13b57
This commit is contained in:
weidonglin 2021-09-18 20:49:17 +08:00
parent 8e5ab94a6d
commit 32d199b590
5 changed files with 1452 additions and 0 deletions

8
example/esp_idf/CMakeLists.txt Executable file
View File

@ -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)

View File

@ -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/")

65
example/esp_idf/main/esp_idf.c Executable file
View File

@ -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 <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#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));
}
}

102
example/esp_idf/main/test_cmds.c Executable file
View File

@ -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 <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#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<argc; i++)
{
if(argv[i] != NULL)
{
xcmd_print("%s ", argv[i]);
}
}
xcmd_print("\r\n");
ret = 0;
}
return ret;
}
static void cmd_echo(int argc, char* argv[])
{
if(param_check(1, argc, argv))
{
xcmd_print("%s\r\n", argv[1]);
}
}
static void cmd_example(int argc, char* argv[])
{
uint8_t i;
if(param_check(1, argc, argv))
{
if(strcmp(argv[1], "str") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%s\r\n", argv[i]);
}
}
if(strcmp(argv[1], "int") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%d\r\n", atoi(argv[i]));
}
}
if(strcmp(argv[1], "float") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%f\r\n", atof(argv[i]));
}
}
}
}
static xcmd_t cmds[] =
{
{"echo", cmd_echo, "echo anything", NULL},
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
};
void test_cmd_init(void)
{
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
}

1270
example/esp_idf/sdkconfig Normal file

File diff suppressed because it is too large Load Diff