esp32s2_bare_board/main/main_common.c
impressionyang fcbba56bd2 feat: 添加显示服务
feat: 添加u8g2功能文件和移植文件
2025-03-21 09:40:36 +08:00

106 lines
3.4 KiB
C
Raw 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"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
/// @brief 所有Task的命名集合名字长度不能超过configMAX_TASK_NAME_LEN = 16
char* imp_main_task_table[] = {
"idle",
"main_task",
"ext_trans_task",
"display",
};
/* Private function(only *.c) -----------------------------------------------*/
extern void cdc_acm_msc_init();
extern uint16_t cdc_usb_read_bytes(uint8_t* data, uint16_t len);
extern uint16_t cdc_usb_writ_bytes(uint8_t* data, uint16_t len);
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_acm_msc_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, ...)
{
int n;
char aBuffer[64] = { 0 };
va_list args;
va_start(args, fmt);
n = vsnprintf(aBuffer, sizeof(aBuffer), fmt, args);
if (n > (int)sizeof(aBuffer)) {
imp_comp_out_port_write(EM_IMP_OUT_PORT_TYPE_STRING, (uint8_t*)aBuffer,
sizeof(aBuffer));
} else if (n > 0) {
imp_comp_out_port_write(EM_IMP_OUT_PORT_TYPE_STRING, (uint8_t*)aBuffer,
n);
}
va_end(args);
return n;
}
/*
* EOF
*/