test: ✅ 通过对外输出接口进行打印和对接shell OK
feat: ✨ 增加对外控制输出 file: 📦 添加对外输出文件
This commit is contained in:
parent
5cbbdab731
commit
3b438fd8af
@ -84,12 +84,21 @@ uint8_t _main_task_wake_up_services()
|
|||||||
uint8_t imp_main_app_task()
|
uint8_t imp_main_app_task()
|
||||||
{
|
{
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
|
uint8_t msg_recv_ret = 0;
|
||||||
msg_q_handle = imp_msg_queue_create_handle(IMP_TASK_ID_MAIN_TASK);
|
msg_q_handle = imp_msg_queue_create_handle(IMP_TASK_ID_MAIN_TASK);
|
||||||
imp_msg_item_t msg_item = { 0 };
|
imp_msg_item_t msg_item = { 0 };
|
||||||
|
|
||||||
_main_task_wake_up_services();
|
_main_task_wake_up_services();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
|
// 10 ticks = 100ms
|
||||||
|
msg_recv_ret = imp_msg_queue_recv_msg(msg_q_handle, &msg_item, 10);
|
||||||
|
if (!msg_recv_ret) {
|
||||||
|
switch (msg_item.msg_type) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (print_en) {
|
if (print_en) {
|
||||||
cdc_printf("hello %d\r\n", i);
|
cdc_printf("hello %d\r\n", i);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ idf_component_register(
|
|||||||
"utilities/imp_types/"
|
"utilities/imp_types/"
|
||||||
"APP/main_app/"
|
"APP/main_app/"
|
||||||
"components/msq_queue"
|
"components/msq_queue"
|
||||||
|
"components/imp_out_port"
|
||||||
"services/ext_trans_service"
|
"services/ext_trans_service"
|
||||||
|
|
||||||
EXCLUDE_SRCS
|
EXCLUDE_SRCS
|
||||||
@ -37,6 +38,7 @@ idf_component_register(
|
|||||||
"APP/main_app/"
|
"APP/main_app/"
|
||||||
"utilities/imp_types/"
|
"utilities/imp_types/"
|
||||||
"components/msq_queue"
|
"components/msq_queue"
|
||||||
|
"components/imp_out_port"
|
||||||
"services/ext_trans_service"
|
"services/ext_trans_service"
|
||||||
|
|
||||||
LDFRAGMENTS
|
LDFRAGMENTS
|
||||||
|
|||||||
109
main/components/imp_out_port/imp_out_port.c
Normal file
109
main/components/imp_out_port/imp_out_port.c
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
* @file imp_out_port.c
|
||||||
|
* @author Alvin Young (impressionyang@outlook.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-12-18
|
||||||
|
*
|
||||||
|
* _ _
|
||||||
|
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
|
||||||
|
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
|
||||||
|
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
|
||||||
|
* /_/ /___/ /___/
|
||||||
|
* @copyright Copyright (c) 2024 impressionyang
|
||||||
|
*
|
||||||
|
* @par 修改日志:
|
||||||
|
* <table>
|
||||||
|
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||||
|
* <tr><td>2024-12-18 <td>v1.0 <td>Alvin Young <td>首次创建
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "imp_out_port.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* define --------------------------------------------------------------------*/
|
||||||
|
/* typedef -------------------------------------------------------------------*/
|
||||||
|
/* variables -----------------------------------------------------------------*/
|
||||||
|
static imp_comp_out_port_t handle = { 0 };
|
||||||
|
/* Private function(only *.c) -----------------------------------------------*/
|
||||||
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
|
||||||
|
uint8_t imp_comp_out_port_init()
|
||||||
|
{
|
||||||
|
// default out type string
|
||||||
|
handle.out_type = EM_IMP_OUT_PORT_TYPE_STRING;
|
||||||
|
handle.is_init = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t imp_comp_out_port_read(imp_comp_out_port_type_e type, uint8_t* data,
|
||||||
|
uint16_t data_len)
|
||||||
|
{
|
||||||
|
uint16_t read_ret = 0;
|
||||||
|
if (NULL == data || handle.is_init == 0 || handle.out_type != type) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle.trans_read) {
|
||||||
|
read_ret = handle.trans_read(data, data_len);
|
||||||
|
}
|
||||||
|
return read_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t imp_comp_out_port_write(imp_comp_out_port_type_e type, uint8_t* data,
|
||||||
|
uint16_t data_len)
|
||||||
|
{
|
||||||
|
uint16_t writ_ret = 0;
|
||||||
|
if (NULL == data || handle.is_init == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pretend write OK
|
||||||
|
if (handle.out_type != type) {
|
||||||
|
return data_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle.trans_writ) {
|
||||||
|
writ_ret = handle.trans_writ(data, data_len);
|
||||||
|
}
|
||||||
|
return writ_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t imp_comp_out_port_ioctl(imp_comp_out_port_cmd_e cmd, uint8_t* data,
|
||||||
|
uint16_t data_len)
|
||||||
|
{
|
||||||
|
char *hello_string = "hello";
|
||||||
|
if (NULL == data || handle.is_init == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case EM_IMP_OUT_PORT_CMD_SET_OUT_TYPE:
|
||||||
|
handle.out_type = *((imp_comp_out_port_type_e*)data);
|
||||||
|
break;
|
||||||
|
case EM_IMP_OUT_PORT_CMD_SET_OUT_WRIT_FUNC:
|
||||||
|
handle.trans_writ = (uint16_t(*)(uint8_t*, uint16_t))data;
|
||||||
|
handle.trans_writ((uint8_t *)hello_string, strlen(hello_string));
|
||||||
|
break;
|
||||||
|
case EM_IMP_OUT_PORT_CMD_SET_OUT_READ_FUNC:
|
||||||
|
handle.trans_read = (uint16_t(*)(uint8_t*, uint16_t))data;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t imp_comp_out_port_deinit()
|
||||||
|
{
|
||||||
|
memset(&handle, 0x00, sizeof(handle));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* EOF
|
||||||
|
*/
|
||||||
87
main/components/imp_out_port/imp_out_port.h
Normal file
87
main/components/imp_out_port/imp_out_port.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/**
|
||||||
|
* @file imp_out_port.h
|
||||||
|
* @author Alvin Young (impressionyang@outlook.com)
|
||||||
|
* @brief 所有对外的输出(串口、USB CDC、等等)都通过这个组件进行,通过ioctl控制输
|
||||||
|
* 出的设备选则和数据的对应接口(发送字符串或者命令流)
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-12-08
|
||||||
|
*
|
||||||
|
* _ _
|
||||||
|
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
|
||||||
|
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
|
||||||
|
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
|
||||||
|
* /_/ /___/ /___/
|
||||||
|
* @copyright Copyright (c) 2024 impressionyang
|
||||||
|
*
|
||||||
|
* @par 修改日志:
|
||||||
|
* <table>
|
||||||
|
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||||
|
* <tr><td>2024-12-08 <td>v1.0 <td>Alvin Young <td>首次创建
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __IMP_OUT_PORT_H__
|
||||||
|
#define __IMP_OUT_PORT_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* define --------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define IMP_COM_OUT_PORT_TRANS_TRHEADSHOLD (64)
|
||||||
|
|
||||||
|
/* typedef -------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
typedef enum __imp_comp_out_port_cmd_e__
|
||||||
|
{
|
||||||
|
EM_IMP_OUT_PORT_CMD_IDLE = 0x00,
|
||||||
|
EM_IMP_OUT_PORT_CMD_SET_OUT_TYPE,
|
||||||
|
EM_IMP_OUT_PORT_CMD_SET_OUT_WRIT_FUNC,
|
||||||
|
EM_IMP_OUT_PORT_CMD_SET_OUT_READ_FUNC,
|
||||||
|
} imp_comp_out_port_cmd_e;
|
||||||
|
|
||||||
|
typedef enum __imp_comp_out_port_type_e__
|
||||||
|
{
|
||||||
|
EM_IMP_OUT_PORT_TYPE_IDLE = 0x00,
|
||||||
|
EM_IMP_OUT_PORT_TYPE_STRING,
|
||||||
|
EM_IMP_OUT_PORT_TYPE_CONTROL,
|
||||||
|
} imp_comp_out_port_type_e;
|
||||||
|
|
||||||
|
/// @brief 对外输出的句柄
|
||||||
|
typedef struct __imp_comp_out_port_t__
|
||||||
|
{
|
||||||
|
/// @brief 是否初始化
|
||||||
|
uint8_t is_init;
|
||||||
|
/// @brief 输出的类型
|
||||||
|
imp_comp_out_port_type_e out_type;
|
||||||
|
uint16_t (*trans_writ)(uint8_t* data, uint16_t data_len);
|
||||||
|
uint16_t (*trans_read)(uint8_t* data, uint16_t data_len);
|
||||||
|
} imp_comp_out_port_t;
|
||||||
|
|
||||||
|
/* variables -----------------------------------------------------------------*/
|
||||||
|
/* Private function(only *.c) -----------------------------------------------*/
|
||||||
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
|
||||||
|
uint8_t imp_comp_out_port_init();
|
||||||
|
uint16_t imp_comp_out_port_read(imp_comp_out_port_type_e type, uint8_t* data,
|
||||||
|
uint16_t data_len);
|
||||||
|
uint16_t imp_comp_out_port_write(imp_comp_out_port_type_e type, uint8_t* data,
|
||||||
|
uint16_t data_len);
|
||||||
|
uint8_t imp_comp_out_port_ioctl(imp_comp_out_port_cmd_e cmd, uint8_t* data,
|
||||||
|
uint16_t data_len);
|
||||||
|
uint8_t imp_comp_out_port_deinit();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif //__IMP_OUT_PORT_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
* EOF
|
||||||
|
*/
|
||||||
@ -38,10 +38,7 @@ void app_main(void)
|
|||||||
{
|
{
|
||||||
_init_esp();
|
_init_esp();
|
||||||
vTaskDelay(10);
|
vTaskDelay(10);
|
||||||
cdc_acm_msc_init();
|
imp_main_common_init();
|
||||||
vTaskDelay(10);
|
|
||||||
userShellInit();
|
|
||||||
vTaskDelay(10);
|
|
||||||
cdc_printf("Hello world!\r\n");
|
cdc_printf("Hello world!\r\n");
|
||||||
|
|
||||||
/* Print chip information */
|
/* Print chip information */
|
||||||
@ -79,7 +76,6 @@ void app_main(void)
|
|||||||
// }
|
// }
|
||||||
cdc_printf("start run app:\r\n");
|
cdc_printf("start run app:\r\n");
|
||||||
|
|
||||||
|
|
||||||
imp_msg_queue_init();
|
imp_msg_queue_init();
|
||||||
xTaskCreate(imp_main_app_task, "main", 2048, NULL, 10, NULL);
|
xTaskCreate(imp_main_app_task, "main", 2048, NULL, 10, NULL);
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,10 @@
|
|||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main_common.h"
|
#include "main_common.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "shell_port.h"
|
||||||
|
#include "main_app.h"
|
||||||
|
#include "imp_msg_queue.h"
|
||||||
/* define --------------------------------------------------------------------*/
|
/* define --------------------------------------------------------------------*/
|
||||||
/* typedef -------------------------------------------------------------------*/
|
/* typedef -------------------------------------------------------------------*/
|
||||||
/* variables -----------------------------------------------------------------*/
|
/* variables -----------------------------------------------------------------*/
|
||||||
@ -33,7 +37,44 @@ char* imp_main_task_table[] = {
|
|||||||
"ext_trans_task",
|
"ext_trans_task",
|
||||||
};
|
};
|
||||||
/* Private function(only *.c) -----------------------------------------------*/
|
/* 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);
|
||||||
|
|
||||||
/* Exported functions --------------------------------------------------------*/
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
|
||||||
|
uint8_t imp_main_common_init()
|
||||||
|
{
|
||||||
|
cdc_acm_msc_init();
|
||||||
|
imp_comp_out_port_init();
|
||||||
|
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);
|
||||||
|
vTaskDelay(10);
|
||||||
|
userShellInit();
|
||||||
|
vTaskDelay(10);
|
||||||
|
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)) {
|
||||||
|
cdc_usb_writ_bytes((uint8_t*)aBuffer, sizeof(aBuffer));
|
||||||
|
} else if (n > 0) {
|
||||||
|
cdc_usb_writ_bytes((uint8_t*)aBuffer, n);
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* EOF
|
* EOF
|
||||||
*/
|
*/
|
||||||
@ -28,6 +28,8 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "imp_out_port.h"
|
||||||
/* define --------------------------------------------------------------------*/
|
/* define --------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define IMP_TASK_ID_IDLE (0)
|
#define IMP_TASK_ID_IDLE (0)
|
||||||
@ -42,10 +44,8 @@ extern char* imp_main_task_table[];
|
|||||||
/* Private function(only *.c) -----------------------------------------------*/
|
/* Private function(only *.c) -----------------------------------------------*/
|
||||||
/* Exported functions --------------------------------------------------------*/
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
|
||||||
extern void cdc_acm_msc_init();
|
uint8_t imp_main_common_init();
|
||||||
extern int cdc_printf(const char* fmt, ...);
|
int cdc_printf(const char* fmt, ...);
|
||||||
extern signed short cdc_usb_read_bytes(char* data, unsigned short len);
|
|
||||||
extern signed short cdc_usb_writ_bytes(char* data, unsigned short len);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file ext_trans_service.c
|
* @file ext_trans_service.c
|
||||||
* @author Alvin Young (impressionyang@outlook.com)
|
* @author Alvin Young (impressionyang@outlook.com)
|
||||||
* @brief
|
* @brief 这里用来转换对外输出是字符串还是命令流的
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @date 2024-12-04
|
* @date 2024-12-04
|
||||||
*
|
*
|
||||||
@ -49,7 +49,9 @@ uint8_t imp_ext_trans_service_task()
|
|||||||
cdc_printf("read msg ok from %d to %d value: %d\r\n",
|
cdc_printf("read msg ok from %d to %d value: %d\r\n",
|
||||||
msg_item.send_id, msg_item.recv_id, msg_item.msg_data);
|
msg_item.send_id, msg_item.recv_id, msg_item.msg_data);
|
||||||
}
|
}
|
||||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
||||||
|
|
||||||
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,12 +14,14 @@
|
|||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "main_common.h"
|
#include "main_common.h"
|
||||||
|
|
||||||
|
|
||||||
#define SHELL_UART UART_NUM_0
|
#define SHELL_UART UART_NUM_0
|
||||||
|
|
||||||
Shell shell;
|
Shell shell;
|
||||||
char shellBuffer[512];
|
char shellBuffer[512];
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 用户shell写
|
* @brief 用户shell写
|
||||||
*
|
*
|
||||||
@ -28,7 +30,7 @@ char shellBuffer[512];
|
|||||||
*
|
*
|
||||||
* @return unsigned short 写入实际长度
|
* @return unsigned short 写入实际长度
|
||||||
*/
|
*/
|
||||||
unsigned short userShellWrite(char *data, unsigned short len)
|
unsigned short userShellWrite(char* data, unsigned short len)
|
||||||
{
|
{
|
||||||
// return uart_write_bytes(SHELL_UART, (const char *)data, len);
|
// return uart_write_bytes(SHELL_UART, (const char *)data, len);
|
||||||
// return cdc_usb_writ_bytes(data, len);
|
// return cdc_usb_writ_bytes(data, len);
|
||||||
@ -36,10 +38,14 @@ unsigned short userShellWrite(char *data, unsigned short len)
|
|||||||
int idx = 0, n = 0;
|
int idx = 0, n = 0;
|
||||||
while (idx < len) {
|
while (idx < len) {
|
||||||
n = len - idx >= 64 ? 64 : len - idx;
|
n = len - idx >= 64 ? 64 : len - idx;
|
||||||
ret = cdc_usb_writ_bytes(data + idx, n);
|
// ret = cdc_usb_writ_bytes((uint8_t*)(data + idx), n);
|
||||||
|
ret = imp_comp_out_port_write(EM_IMP_OUT_PORT_TYPE_STRING,
|
||||||
|
(uint8_t*)(data + idx), n);
|
||||||
while (!ret) {
|
while (!ret) {
|
||||||
vTaskDelay(10);
|
vTaskDelay(10);
|
||||||
ret = cdc_usb_writ_bytes(data + idx, n);
|
// ret = cdc_usb_writ_bytes((uint8_t*)(data + idx), n);
|
||||||
|
ret = imp_comp_out_port_write(EM_IMP_OUT_PORT_TYPE_STRING,
|
||||||
|
(uint8_t*)(data + idx), n);
|
||||||
}
|
}
|
||||||
idx += n;
|
idx += n;
|
||||||
}
|
}
|
||||||
@ -48,7 +54,6 @@ unsigned short userShellWrite(char *data, unsigned short len)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 用户shell读
|
* @brief 用户shell读
|
||||||
*
|
*
|
||||||
@ -57,17 +62,18 @@ unsigned short userShellWrite(char *data, unsigned short len)
|
|||||||
*
|
*
|
||||||
* @return unsigned short 读取实际长度
|
* @return unsigned short 读取实际长度
|
||||||
*/
|
*/
|
||||||
signed char userShellRead(char *data, unsigned short len)
|
signed char userShellRead(char* data, unsigned short len)
|
||||||
{
|
{
|
||||||
// return uart_read_bytes(SHELL_UART, (uint8_t *)data, len, portMAX_DELAY);
|
// return uart_read_bytes(SHELL_UART, (uint8_t *)data, len, portMAX_DELAY);
|
||||||
vTaskDelay(10);
|
vTaskDelay(10);
|
||||||
signed char ret = 0;
|
signed char ret = 0;
|
||||||
ret = cdc_usb_read_bytes(data, len);
|
// ret = cdc_usb_read_bytes((uint8_t*)data, len);
|
||||||
|
ret = imp_comp_out_port_read(EM_IMP_OUT_PORT_TYPE_STRING, (uint8_t*)data,
|
||||||
|
len);
|
||||||
// cdc_printf("read need : %d, get %d\r\n", len, ret);
|
// cdc_printf("read need : %d, get %d\r\n", len, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 用户shell初始化
|
* @brief 用户shell初始化
|
||||||
*
|
*
|
||||||
|
|||||||
@ -20,12 +20,14 @@
|
|||||||
#define USBD_LANGID_STRING 1033
|
#define USBD_LANGID_STRING 1033
|
||||||
|
|
||||||
/*!< config descriptor size */
|
/*!< config descriptor size */
|
||||||
#define USB_CONFIG_SIZE (9 + CDC_ACM_DESCRIPTOR_LEN )// + MSC_DESCRIPTOR_LEN)
|
#define USB_CONFIG_SIZE (9 + CDC_ACM_DESCRIPTOR_LEN) // + MSC_DESCRIPTOR_LEN)
|
||||||
|
|
||||||
/*!< global descriptor */
|
/*!< global descriptor */
|
||||||
static const uint8_t cdc_msc_descriptor[] = {
|
static const uint8_t cdc_msc_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID,
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
0x0100, 0x01),
|
||||||
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01,
|
||||||
|
USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, 0x02),
|
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, 0x02),
|
||||||
// MSC_DESCRIPTOR_INIT(0x02, MSC_OUT_EP, MSC_IN_EP, 0x00),
|
// MSC_DESCRIPTOR_INIT(0x02, MSC_OUT_EP, MSC_IN_EP, 0x00),
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
@ -88,16 +90,8 @@ static const uint8_t cdc_msc_descriptor[] = {
|
|||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// device qualifier descriptor
|
/// device qualifier descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
0x0a,
|
0x0a, USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER, 0x00, 0x02, 0x02, 0x02, 0x01,
|
||||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
0x40, 0x01, 0x00,
|
||||||
0x00,
|
|
||||||
0x02,
|
|
||||||
0x02,
|
|
||||||
0x02,
|
|
||||||
0x01,
|
|
||||||
0x40,
|
|
||||||
0x01,
|
|
||||||
0x00,
|
|
||||||
#endif
|
#endif
|
||||||
0x00
|
0x00
|
||||||
};
|
};
|
||||||
@ -109,11 +103,11 @@ usbd_interface_t cdc_cmd_intf;
|
|||||||
/*!< interface two */
|
/*!< interface two */
|
||||||
usbd_interface_t cdc_data_intf;
|
usbd_interface_t cdc_data_intf;
|
||||||
|
|
||||||
imp_util_ring_queue_t ring_q_cdc_recv = {0};
|
imp_util_ring_queue_t ring_q_cdc_recv = { 0 };
|
||||||
unsigned char ring_q_cdc_recv_swap_data[1024 + 1] = { 0 };
|
unsigned char ring_q_cdc_recv_swap_data[1024 + 1] = { 0 };
|
||||||
|
|
||||||
/* function ------------------------------------------------------------------*/
|
/* function ------------------------------------------------------------------*/
|
||||||
int cdc_printf(const char *fmt, ...);
|
int cdc_printf(const char* fmt, ...);
|
||||||
|
|
||||||
void usbd_cdc_acm_out(uint8_t ep)
|
void usbd_cdc_acm_out(uint8_t ep)
|
||||||
{
|
{
|
||||||
@ -139,15 +133,10 @@ void usbd_cdc_acm_in(uint8_t ep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!< endpoint call back */
|
/*!< endpoint call back */
|
||||||
usbd_endpoint_t cdc_out_ep = {
|
usbd_endpoint_t cdc_out_ep = { .ep_addr = CDC_OUT_EP,
|
||||||
.ep_addr = CDC_OUT_EP,
|
.ep_cb = usbd_cdc_acm_out };
|
||||||
.ep_cb = usbd_cdc_acm_out
|
|
||||||
};
|
|
||||||
|
|
||||||
usbd_endpoint_t cdc_in_ep = {
|
usbd_endpoint_t cdc_in_ep = { .ep_addr = CDC_IN_EP, .ep_cb = usbd_cdc_acm_in };
|
||||||
.ep_addr = CDC_IN_EP,
|
|
||||||
.ep_cb = usbd_cdc_acm_in
|
|
||||||
};
|
|
||||||
|
|
||||||
/* function ------------------------------------------------------------------*/
|
/* function ------------------------------------------------------------------*/
|
||||||
void cdc_acm_msc_init(void)
|
void cdc_acm_msc_init(void)
|
||||||
@ -165,7 +154,6 @@ void cdc_acm_msc_init(void)
|
|||||||
usbd_initialize();
|
usbd_initialize();
|
||||||
|
|
||||||
imp_util_ring_queue_init(&ring_q_cdc_recv, ring_q_cdc_recv_swap_data, 1025);
|
imp_util_ring_queue_init(&ring_q_cdc_recv, ring_q_cdc_recv_swap_data, 1025);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile uint8_t dtr_enable = 0;
|
volatile uint8_t dtr_enable = 0;
|
||||||
@ -182,21 +170,22 @@ void usbd_cdc_acm_set_dtr(bool dtr)
|
|||||||
void cdc_acm_data_send_with_dtr_test(void)
|
void cdc_acm_data_send_with_dtr_test(void)
|
||||||
{
|
{
|
||||||
if (dtr_enable) {
|
if (dtr_enable) {
|
||||||
uint8_t data_buffer[10] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x31, 0x32, 0x33, 0x34, 0x35 };
|
uint8_t data_buffer[10] = { 0x31, 0x32, 0x33, 0x34, 0x35,
|
||||||
|
0x31, 0x32, 0x33, 0x34, 0x35 };
|
||||||
usbd_ep_write(CDC_IN_EP, data_buffer, 10, NULL);
|
usbd_ep_write(CDC_IN_EP, data_buffer, 10, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signed short cdc_usb_read_bytes(char* data, unsigned short len)
|
uint16_t cdc_usb_read_bytes(uint8_t* data, uint16_t len)
|
||||||
{
|
{
|
||||||
signed short ret = len;
|
uint16_t ret = len;
|
||||||
if (len >= 64) {
|
if (len >= 64) {
|
||||||
ret = 64;
|
ret = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imp_util_ring_queue_get_wlvl(&ring_q_cdc_recv) >= len) {
|
if (imp_util_ring_queue_get_wlvl(&ring_q_cdc_recv) >= len) {
|
||||||
imp_util_ring_queue_read(&ring_q_cdc_recv, (uint8_t*)data, len);
|
imp_util_ring_queue_read(&ring_q_cdc_recv, (uint8_t*)data, len);
|
||||||
}else {
|
} else {
|
||||||
data[0] = 0;
|
data[0] = 0;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
@ -204,14 +193,11 @@ signed short cdc_usb_read_bytes(char* data, unsigned short len)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
signed short cdc_usb_writ_bytes(char* data, unsigned short len)
|
uint16_t cdc_usb_writ_bytes(uint8_t* data, uint16_t len)
|
||||||
{
|
{
|
||||||
signed short n;
|
uint16_t n;
|
||||||
char aBuffer[64] = { 0 };
|
|
||||||
n = len >= 64 ? 64 : len;
|
n = len >= 64 ? 64 : len;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
// aBuffer[63] = '\n';
|
|
||||||
strncpy(aBuffer, data, n);
|
|
||||||
|
|
||||||
if (dtr_enable) {
|
if (dtr_enable) {
|
||||||
ret = usbd_ep_write(CDC_IN_EP, (uint8_t*)data, n, NULL);
|
ret = usbd_ep_write(CDC_IN_EP, (uint8_t*)data, n, NULL);
|
||||||
@ -220,24 +206,6 @@ signed short cdc_usb_writ_bytes(char* data, unsigned short len)
|
|||||||
return ret == 0 ? len : 0;
|
return ret == 0 ? len : 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 (dtr_enable) {
|
|
||||||
if (n > (int)sizeof(aBuffer)) {
|
|
||||||
usbd_ep_write(CDC_IN_EP, (uint8_t *)aBuffer, sizeof(aBuffer), NULL);
|
|
||||||
} else if (n > 0) {
|
|
||||||
usbd_ep_write(CDC_IN_EP, (uint8_t *)aBuffer, n, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
va_end(args);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BLOCK_SIZE 512
|
#define BLOCK_SIZE 512
|
||||||
#define BLOCK_COUNT 10
|
#define BLOCK_COUNT 10
|
||||||
|
|
||||||
@ -248,19 +216,19 @@ typedef struct
|
|||||||
|
|
||||||
BLOCK_TYPE mass_block[BLOCK_COUNT];
|
BLOCK_TYPE mass_block[BLOCK_COUNT];
|
||||||
|
|
||||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
void usbd_msc_get_cap(uint8_t lun, uint32_t* block_num, uint16_t* block_size)
|
||||||
{
|
{
|
||||||
*block_num = 1000; //Pretend having so many buffer,not has actually.
|
*block_num = 1000; //Pretend having so many buffer,not has actually.
|
||||||
*block_size = BLOCK_SIZE;
|
*block_size = BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
int usbd_msc_sector_read(uint32_t sector, uint8_t *buffer, uint32_t length)
|
int usbd_msc_sector_read(uint32_t sector, uint8_t* buffer, uint32_t length)
|
||||||
{
|
{
|
||||||
if (sector < 10)
|
if (sector < 10)
|
||||||
memcpy(buffer, mass_block[sector].BlockSpace, length);
|
memcpy(buffer, mass_block[sector].BlockSpace, length);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usbd_msc_sector_write(uint32_t sector, uint8_t *buffer, uint32_t length)
|
int usbd_msc_sector_write(uint32_t sector, uint8_t* buffer, uint32_t length)
|
||||||
{
|
{
|
||||||
if (sector < 10)
|
if (sector < 10)
|
||||||
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user