diff --git a/main/APP/main_app/main_app.c b/main/APP/main_app/main_app.c
index e14d1ae..9d9943b 100644
--- a/main/APP/main_app/main_app.c
+++ b/main/APP/main_app/main_app.c
@@ -83,13 +83,22 @@ uint8_t _main_task_wake_up_services()
uint8_t imp_main_app_task()
{
- uint16_t i = 0;
- msg_q_handle = imp_msg_queue_create_handle(IMP_TASK_ID_MAIN_TASK);
+ uint16_t i = 0;
+ uint8_t msg_recv_ret = 0;
+ msg_q_handle = imp_msg_queue_create_handle(IMP_TASK_ID_MAIN_TASK);
imp_msg_item_t msg_item = { 0 };
_main_task_wake_up_services();
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) {
cdc_printf("hello %d\r\n", i);
}
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 5360c41..6a83d5e 100755
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -13,6 +13,7 @@ idf_component_register(
"utilities/imp_types/"
"APP/main_app/"
"components/msq_queue"
+ "components/imp_out_port"
"services/ext_trans_service"
EXCLUDE_SRCS
@@ -37,6 +38,7 @@ idf_component_register(
"APP/main_app/"
"utilities/imp_types/"
"components/msq_queue"
+ "components/imp_out_port"
"services/ext_trans_service"
LDFRAGMENTS
diff --git a/main/components/imp_out_port/imp_out_port.c b/main/components/imp_out_port/imp_out_port.c
new file mode 100644
index 0000000..d7683fa
--- /dev/null
+++ b/main/components/imp_out_port/imp_out_port.c
@@ -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 修改日志:
+ *
+ * | Date | Version | Author | Description
+ * |
|---|
| 2024-12-18 | v1.0 | Alvin Young | 首次创建
+ * |
+ *
+ */
+/* Define to prevent recursive inclusion -------------------------------------*/
+/* Includes ------------------------------------------------------------------*/
+#include "imp_out_port.h"
+#include
+#include
+
+/* 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
+ */
\ No newline at end of file
diff --git a/main/components/imp_out_port/imp_out_port.h b/main/components/imp_out_port/imp_out_port.h
new file mode 100644
index 0000000..848fcf2
--- /dev/null
+++ b/main/components/imp_out_port/imp_out_port.h
@@ -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 修改日志:
+ *
+ * | Date | Version | Author | Description
+ * |
|---|
| 2024-12-08 | v1.0 | Alvin Young | 首次创建
+ * |
+ *
+ */
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __IMP_OUT_PORT_H__
+#define __IMP_OUT_PORT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+
+#include
+
+/* 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
+ */
\ No newline at end of file
diff --git a/main/main.c b/main/main.c
index c08b037..9ffb844 100755
--- a/main/main.c
+++ b/main/main.c
@@ -38,10 +38,7 @@ void app_main(void)
{
_init_esp();
vTaskDelay(10);
- cdc_acm_msc_init();
- vTaskDelay(10);
- userShellInit();
- vTaskDelay(10);
+ imp_main_common_init();
cdc_printf("Hello world!\r\n");
/* Print chip information */
@@ -79,7 +76,6 @@ void app_main(void)
// }
cdc_printf("start run app:\r\n");
-
imp_msg_queue_init();
xTaskCreate(imp_main_app_task, "main", 2048, NULL, 10, NULL);
diff --git a/main/main_common.c b/main/main_common.c
index 5e1f535..20252af 100644
--- a/main/main_common.c
+++ b/main/main_common.c
@@ -22,6 +22,10 @@
/* Define to prevent recursive inclusion -------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "main_common.h"
+#include
+#include "shell_port.h"
+#include "main_app.h"
+#include "imp_msg_queue.h"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
@@ -33,7 +37,44 @@ char* imp_main_task_table[] = {
"ext_trans_task",
};
/* 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 --------------------------------------------------------*/
+
+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
*/
\ No newline at end of file
diff --git a/main/main_common.h b/main/main_common.h
index d0bc67d..af168be 100644
--- a/main/main_common.h
+++ b/main/main_common.h
@@ -28,6 +28,8 @@ extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
+#include
+#include "imp_out_port.h"
/* define --------------------------------------------------------------------*/
#define IMP_TASK_ID_IDLE (0)
@@ -42,10 +44,8 @@ extern char* imp_main_task_table[];
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
-extern void cdc_acm_msc_init();
-extern 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);
+uint8_t imp_main_common_init();
+int cdc_printf(const char* fmt, ...);
#ifdef __cplusplus
}
diff --git a/main/services/ext_trans_service/ext_trans_service.c b/main/services/ext_trans_service/ext_trans_service.c
index 893d489..a535d3f 100644
--- a/main/services/ext_trans_service/ext_trans_service.c
+++ b/main/services/ext_trans_service/ext_trans_service.c
@@ -1,7 +1,7 @@
/**
* @file ext_trans_service.c
* @author Alvin Young (impressionyang@outlook.com)
- * @brief
+ * @brief 这里用来转换对外输出是字符串还是命令流的
* @version 0.1
* @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",
msg_item.send_id, msg_item.recv_id, msg_item.msg_data);
}
- vTaskDelay(100 / portTICK_PERIOD_MS);
+
+
+ vTaskDelay(10 / portTICK_PERIOD_MS);
}
return 0;
}
diff --git a/main/utilities/letter_shell/port/esp-idf/shell_port.c b/main/utilities/letter_shell/port/esp-idf/shell_port.c
index 0decb3f..afca837 100644
--- a/main/utilities/letter_shell/port/esp-idf/shell_port.c
+++ b/main/utilities/letter_shell/port/esp-idf/shell_port.c
@@ -14,11 +14,13 @@
#include "driver/uart.h"
#include "main_common.h"
-
-#define SHELL_UART UART_NUM_0
+#define SHELL_UART UART_NUM_0
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写
@@ -28,18 +30,22 @@ char shellBuffer[512];
*
* @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 cdc_usb_writ_bytes(data, len);
unsigned short ret = 0;
int idx = 0, n = 0;
while (idx < len) {
- n = len - idx >= 64 ? 64 : len - idx;
- ret = cdc_usb_writ_bytes(data + idx, n);
+ n = len - idx >= 64 ? 64 : len - idx;
+ // 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) {
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;
}
@@ -48,7 +54,6 @@ unsigned short userShellWrite(char *data, unsigned short len)
return len;
}
-
/**
* @brief 用户shell读
*
@@ -57,17 +62,18 @@ unsigned short userShellWrite(char *data, unsigned short len)
*
* @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);
vTaskDelay(10);
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);
return ret;
}
-
/**
* @brief 用户shell初始化
*
@@ -84,7 +90,7 @@ void userShellInit(void)
// uart_param_config(SHELL_UART, &uartConfig);
// uart_driver_install(SHELL_UART, 256 * 2, 0, 0, NULL, 0);
shell.write = userShellWrite;
- shell.read = userShellRead;
+ shell.read = userShellRead;
shellInit(&shell, shellBuffer, 512);
xTaskCreate(shellTask, "shell", 2048, &shell, 8, NULL);
diff --git a/main/utilities/usb_cherry/esp_setup/my_usb_setup.c b/main/utilities/usb_cherry/esp_setup/my_usb_setup.c
index 8079be1..41521bb 100644
--- a/main/utilities/usb_cherry/esp_setup/my_usb_setup.c
+++ b/main/utilities/usb_cherry/esp_setup/my_usb_setup.c
@@ -6,26 +6,28 @@
#include "imp_util_ring_queue.h"
/*!< endpoint address */
-#define CDC_IN_EP 0x81
+#define CDC_IN_EP 0x81
#define CDC_OUT_EP 0x02
#define CDC_INT_EP 0x83
// #define MSC_IN_EP 0x85
-#define MSC_IN_EP 0x84 // esp32s2 的 IN 端点号不能大于 4,这是硬件限制
+#define MSC_IN_EP 0x84 // esp32s2 的 IN 端点号不能大于 4,这是硬件限制
#define MSC_OUT_EP 0x04
-#define USBD_VID 0xFFFF
-#define USBD_PID 0xFFFF
-#define USBD_MAX_POWER 100
+#define USBD_VID 0xFFFF
+#define USBD_PID 0xFFFF
+#define USBD_MAX_POWER 100
#define USBD_LANGID_STRING 1033
/*!< 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 */
static const uint8_t cdc_msc_descriptor[] = {
- USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
- USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
+ USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID,
+ 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),
// 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
///////////////////////////////////////
- 0x0a,
- USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
- 0x00,
- 0x02,
- 0x02,
- 0x02,
- 0x01,
- 0x40,
- 0x01,
- 0x00,
+ 0x0a, USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER, 0x00, 0x02, 0x02, 0x02, 0x01,
+ 0x40, 0x01, 0x00,
#endif
0x00
};
@@ -109,15 +103,15 @@ usbd_interface_t cdc_cmd_intf;
/*!< interface two */
usbd_interface_t cdc_data_intf;
-imp_util_ring_queue_t ring_q_cdc_recv = {0};
-unsigned char ring_q_cdc_recv_swap_data[1024 + 1] = { 0 };
+imp_util_ring_queue_t ring_q_cdc_recv = { 0 };
+unsigned char ring_q_cdc_recv_swap_data[1024 + 1] = { 0 };
/* function ------------------------------------------------------------------*/
-int cdc_printf(const char *fmt, ...);
+int cdc_printf(const char* fmt, ...);
void usbd_cdc_acm_out(uint8_t ep)
{
- uint8_t data[64];
+ uint8_t data[64];
uint32_t read_byte;
usbd_ep_read(ep, data, 64, &read_byte);
@@ -139,15 +133,10 @@ void usbd_cdc_acm_in(uint8_t ep)
}
/*!< endpoint call back */
-usbd_endpoint_t cdc_out_ep = {
- .ep_addr = CDC_OUT_EP,
- .ep_cb = usbd_cdc_acm_out
-};
+usbd_endpoint_t cdc_out_ep = { .ep_addr = CDC_OUT_EP,
+ .ep_cb = usbd_cdc_acm_out };
-usbd_endpoint_t cdc_in_ep = {
- .ep_addr = CDC_IN_EP,
- .ep_cb = usbd_cdc_acm_in
-};
+usbd_endpoint_t cdc_in_ep = { .ep_addr = CDC_IN_EP, .ep_cb = usbd_cdc_acm_in };
/* function ------------------------------------------------------------------*/
void cdc_acm_msc_init(void)
@@ -165,7 +154,6 @@ void cdc_acm_msc_init(void)
usbd_initialize();
imp_util_ring_queue_init(&ring_q_cdc_recv, ring_q_cdc_recv_swap_data, 1025);
-
}
volatile uint8_t dtr_enable = 0;
@@ -182,36 +170,34 @@ void usbd_cdc_acm_set_dtr(bool dtr)
void cdc_acm_data_send_with_dtr_test(void)
{
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);
}
}
-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) {
ret = 64;
}
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);
- }else {
+ } else {
data[0] = 0;
- ret = 1;
+ ret = 1;
}
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;
- char aBuffer[64] = { 0 };
- n = len >= 64 ? 64 : len;
+ uint16_t n;
+ n = len >= 64 ? 64 : len;
int ret = -1;
- // aBuffer[63] = '\n';
- strncpy(aBuffer, data, n);
if (dtr_enable) {
ret = usbd_ep_write(CDC_IN_EP, (uint8_t*)data, n, NULL);
@@ -220,25 +206,7 @@ signed short cdc_usb_writ_bytes(char* data, unsigned short len)
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
typedef struct
@@ -248,19 +216,19 @@ typedef struct
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;
}
-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)
memcpy(buffer, mass_block[sector].BlockSpace, length);
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)
memcpy(mass_block[sector].BlockSpace, buffer, length);