esp32s2_bare_board/main/main_common.c

113 lines
3.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file main_common.c
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2024-12-04
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2024 impressionyang
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2024-12-04 <td>v1.0 <td>Alvin Young <td>首次创建
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "main_common.h"
#include <stdarg.h>
#include <stdlib.h>
#include "shell_port.h"
#include "main_app.h"
#include "imp_msg_queue.h"
#include "esp_log.h"
#include "shell_port.h"
#include "usb_setup.h"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
/// @brief 所有Task的命名集合名字长度不能超过configMAX_TASK_NAME_LEN = 16
char* imp_main_task_table[] = {
"idle", "main_task", "ext_trans_task", "display", "audio", "switch_key",
};
/* Private function(only *.c) -----------------------------------------------*/
char cdc_print_buf[1024] = { 0 };
uint8_t _imp_set_out_port(int argc, char** argv)
{
if (argc < 2) {
cdc_printf("too few arg\r\n");
return 1;
}
uint8_t type = atoi(argv[1]);
cdc_printf("set outport type %d\r\n", type);
imp_comp_out_port_ioctl(EM_IMP_OUT_PORT_CMD_SET_OUT_TYPE, (uint8_t*)&type,
1);
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
oport, _imp_set_out_port, set out port);
/* Exported functions --------------------------------------------------------*/
uint8_t imp_main_common_init()
{
cdc_usb_init();
imp_comp_out_port_init();
ESP_LOGI("app_main", "imp_comp_out_port_init ok");
imp_comp_out_port_ioctl(EM_IMP_OUT_PORT_CMD_SET_OUT_READ_FUNC,
(uint8_t*)cdc_usb_read_bytes, 0);
imp_comp_out_port_ioctl(EM_IMP_OUT_PORT_CMD_SET_OUT_WRIT_FUNC,
(uint8_t*)cdc_usb_writ_bytes, 0);
ESP_LOGI("app_main", "out port ok");
cdc_printf("out port ok\r\n");
vTaskDelay(10);
userShellInit();
vTaskDelay(10);
cdc_printf("imp_main_common_init ok\r\n");
return 0;
}
int cdc_printf(const char* fmt, ...)
{
va_list args;
int n = 0;
int idx = 0;
va_start(args, fmt);
n = vsnprintf(cdc_print_buf, sizeof(cdc_print_buf), fmt, args);
if (n > 64) {
while (idx < n) {
if (n - idx > 64) {
imp_comp_out_port_write(EM_IMP_OUT_PORT_TYPE_STRING,
(uint8_t*)cdc_print_buf + idx, 64);
idx += 64;
} else {
imp_comp_out_port_write(EM_IMP_OUT_PORT_TYPE_STRING,
(uint8_t*)cdc_print_buf + idx, n - idx);
idx += 64;
}
}
} else if (n > 0) {
imp_comp_out_port_write(EM_IMP_OUT_PORT_TYPE_STRING,
(uint8_t*)cdc_print_buf, n);
}
va_end(args);
return n;
}
/*
* EOF
*/