diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..9fd8f3d
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,6 @@
+[submodule "main/utilities/imp_util_ring_queue"]
+ path = main/utilities/imp_util_ring_queue
+ url = ssh://git@192.168.124.23:222/Utilities/imp_util_ring_queue.git
+[submodule "main/utilities/imp_types"]
+ path = main/utilities/imp_types
+ url = ssh://git@192.168.124.23:222/Utilities/imp_types.git
diff --git a/main/APP/README.md b/main/APP/README.md
new file mode 100644
index 0000000..e69de29
diff --git a/main/APP/main_app/main_app.c b/main/APP/main_app/main_app.c
new file mode 100644
index 0000000..c328ec1
--- /dev/null
+++ b/main/APP/main_app/main_app.c
@@ -0,0 +1,51 @@
+/**
+ * @file main_app.c
+ * @author Alvin Young (impressionyang@outlook.com)
+ * @brief
+ * @version 0.1
+ * @date 2024-11-25
+ *
+ * _ _
+ * (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
+ * / / ' \/ _ \/ __/ -_|_-<(_- / _ \/ _ \/ // / _ `/ _ \/ _ `/
+ * /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
+ * /_/ /___/ /___/
+ * @copyright Copyright (c) 2024 impressionyang
+ *
+ * @par 修改日志:
+ *
+ * | Date | Version | Author | Description
+ * |
|---|
| 2024-11-25 | v1.0 | Alvin Young | 首次创建
+ * |
+ *
+ */
+/* Define to prevent recursive inclusion -------------------------------------*/
+/* Includes ------------------------------------------------------------------*/
+#include "main_app.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "esp_system.h"
+#include "esp_chip_info.h"
+#include "sdkconfig.h"
+#include
+
+#include "main_common.h"
+
+/* define --------------------------------------------------------------------*/
+/* typedef -------------------------------------------------------------------*/
+/* variables -----------------------------------------------------------------*/
+/* Private function(only *.c) -----------------------------------------------*/
+/* Exported functions --------------------------------------------------------*/
+
+uint8_t imp_main_app_task()
+{
+ int i = 0;
+ while (1) {
+ cdc_printf("hello %d\r\n", i++);
+ vTaskDelay(1000 / portTICK_PERIOD_MS);
+ }
+ return 0;
+}
+/*
+ * EOF
+ */
\ No newline at end of file
diff --git a/main/APP/main_app/main_app.h b/main/APP/main_app/main_app.h
new file mode 100644
index 0000000..f6bce4d
--- /dev/null
+++ b/main/APP/main_app/main_app.h
@@ -0,0 +1,47 @@
+/**
+ * @file main_app.h
+ * @author Alvin Young (impressionyang@outlook.com)
+ * @brief
+ * @version 0.1
+ * @date 2024-11-25
+ *
+ * _ _
+ * (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
+ * / / ' \/ _ \/ __/ -_|_-<(_- / _ \/ _ \/ // / _ `/ _ \/ _ `/
+ * /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
+ * /_/ /___/ /___/
+ * @copyright Copyright (c) 2024 impressionyang
+ *
+ * @par 修改日志:
+ *
+ * | Date | Version | Author | Description
+ * |
|---|
| 2024-11-25 | v1.0 | Alvin Young | 首次创建
+ * |
+ *
+ */
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __MAIN_APP_H__
+#define __MAIN_APP_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/* Includes ------------------------------------------------------------------*/
+
+#include
+
+/* define --------------------------------------------------------------------*/
+/* typedef -------------------------------------------------------------------*/
+/* variables -----------------------------------------------------------------*/
+/* Private function(only *.c) -----------------------------------------------*/
+/* Exported functions --------------------------------------------------------*/
+
+uint8_t imp_main_app_task();
+
+#ifdef __cplusplus
+}
+#endif
+#endif //__MAIN_APP_H__
+ /*
+ * EOF
+ */
\ No newline at end of file
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 91f5adc..ba97d06 100755
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -8,13 +8,17 @@ idf_component_register(
"utilities/usb_cherry/CherryUSB/class/cdc/"
"utilities/usb_cherry/CherryUSB/class/msc/"
"utilities/usb_cherry/CherryUSB/core/"
- "utilities/usb_cherry/CherryUSB/port/dwc2"
+ "utilities/usb_cherry/CherryUSB/port/dwc2/"
+ "utilities/imp_util_ring_queue/"
+ "utilities/imp_types/"
+ "APP/main_app/"
EXCLUDE_SRCS
"utilities/usb_cherry/CherryUSB/class/cdc/usbh_cdc_acm.c"
"utilities/usb_cherry/CherryUSB/class/msc/usbh_msc.c"
"utilities/usb_cherry/CherryUSB/core/usbh_core.c"
"utilities/usb_cherry/CherryUSB/port/dwc2/usb_hc_dwc2.c"
+ "utilities/imp_util_ring_queue/ring_queue_test.c"
INCLUDE_DIRS
"."
@@ -27,6 +31,9 @@ idf_component_register(
"utilities/usb_cherry/CherryUSB/common"
"utilities/usb_cherry/CherryUSB/core"
"utilities/usb_cherry/CherryUSB/port/dwc2"
+ "utilities/imp_util_ring_queue/"
+ "APP/main_app/"
+ "utilities/imp_types/"
LDFRAGMENTS
"utilities/letter_shell/port/esp-idf/shell.lf"
diff --git a/main/main.c b/main/main.c
index 83d37c7..ea1a95e 100755
--- a/main/main.c
+++ b/main/main.c
@@ -18,6 +18,8 @@
#include
#include "shell_port.h"
+#include "main_app.h"
+#include "main_common.h"
static void _init_esp()
{
@@ -31,18 +33,14 @@ static void _init_esp()
ESP_ERROR_CHECK(ret);
}
-extern void cdc_acm_msc_init();
-extern int cdc_printf(const char* fmt, ...);
-
void app_main(void)
{
_init_esp();
vTaskDelay(10);
- userShellInit();
- vTaskDelay(10);
-
- printf("Hello world!\n");
cdc_acm_msc_init();
+ vTaskDelay(10);
+ userShellInit();
+ cdc_printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
@@ -74,13 +72,11 @@ void app_main(void)
// for (int i = 10; i >= 0; i--) {
// printf("Restarting in %d seconds...\n", i);
- // vTaskDelay(1000 / portTICK_PERIOD_MS);
+ // vTaskDelay(1000 / portTICK_PERIOD_MS);
// }
- int i = 0;
- while (1) {
- cdc_printf("hello %d\r\n", i++);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- }
+ cdc_printf("start run app:\r\n");
+ imp_main_app_task();
+
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
diff --git a/main/main_common.h b/main/main_common.h
new file mode 100644
index 0000000..0e15478
--- /dev/null
+++ b/main/main_common.h
@@ -0,0 +1,49 @@
+/**
+ * @file main_common.h
+ * @author Alvin Young (impressionyang@outlook.com)
+ * @brief
+ * @version 0.1
+ * @date 2024-11-25
+ *
+ * _ _
+ * (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
+ * / / ' \/ _ \/ __/ -_|_-<(_- / _ \/ _ \/ // / _ `/ _ \/ _ `/
+ * /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
+ * /_/ /___/ /___/
+ * @copyright Copyright (c) 2024 impressionyang
+ *
+ * @par 修改日志:
+ *
+ * | Date | Version | Author | Description
+ * |
|---|
| 2024-11-25 | v1.0 | Alvin Young | 首次创建
+ * |
+ *
+ */
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __MAIN_COMMON_H__
+#define __MAIN_COMMON_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+/* define --------------------------------------------------------------------*/
+/* typedef -------------------------------------------------------------------*/
+/* variables -----------------------------------------------------------------*/
+/* 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);
+
+#ifdef __cplusplus
+}
+#endif
+#endif //__MAIN_COMMON_H__
+
+/*
+ * EOF
+ */
\ No newline at end of file
diff --git a/main/utilities/imp_types b/main/utilities/imp_types
new file mode 160000
index 0000000..6cf82b2
--- /dev/null
+++ b/main/utilities/imp_types
@@ -0,0 +1 @@
+Subproject commit 6cf82b2d2c8f3c944dd93f079f9cc7f0eef6018c
diff --git a/main/utilities/imp_util_ring_queue b/main/utilities/imp_util_ring_queue
new file mode 160000
index 0000000..61a122b
--- /dev/null
+++ b/main/utilities/imp_util_ring_queue
@@ -0,0 +1 @@
+Subproject commit 61a122b22be15ef94e2d114a819aee8fb7f39e0d
diff --git a/main/utilities/letter_shell/port/esp-idf/shell_cfg.h b/main/utilities/letter_shell/port/esp-idf/shell_cfg.h
index 05b0446..3d87e98 100644
--- a/main/utilities/letter_shell/port/esp-idf/shell_cfg.h
+++ b/main/utilities/letter_shell/port/esp-idf/shell_cfg.h
@@ -124,7 +124,7 @@
* @brief shell格式化输出的缓冲大小
* 为0时不使用shell格式化输出
*/
-#define SHELL_PRINT_BUFFER 128
+#define SHELL_PRINT_BUFFER 64
/**
* @brief shell格式化输入的缓冲大小
@@ -171,13 +171,13 @@
/**
* @brief shell默认用户
*/
-#define SHELL_DEFAULT_USER "letter"
+#define SHELL_DEFAULT_USER "alvin"
/**
* @brief shell默认用户密码
* 若默认用户不需要密码,设为""
*/
-#define SHELL_DEFAULT_USER_PASSWORD ""
+#define SHELL_DEFAULT_USER_PASSWORD "passwd"
/**
* @brief shell自动锁定超时
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 d08b4f6..f7bf36f 100644
--- a/main/utilities/letter_shell/port/esp-idf/shell_port.c
+++ b/main/utilities/letter_shell/port/esp-idf/shell_port.c
@@ -12,6 +12,7 @@
#include "shell.h"
#include "freertos/FreeRTOS.h"
#include "driver/uart.h"
+#include "main_common.h"
#define SHELL_UART UART_NUM_0
@@ -29,7 +30,13 @@ char shellBuffer[512];
*/
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);
+ unsigned short ret = 0;
+ ret = cdc_usb_writ_bytes(data, len);
+ // cdc_printf("write need : %d, get %d\r\n", len, ret);
+ // cdc_printf("%s", data);
+ return len;
}
@@ -43,7 +50,11 @@ unsigned short userShellWrite(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);
+ signed char ret = 0;
+ ret = cdc_usb_read_bytes(data, len);
+ // cdc_printf("read need : %d, get %d\r\n", len, ret);
+ return ret;
}
diff --git a/main/utilities/letter_shell/src/shell_cfg.h b/main/utilities/letter_shell/src/shell_cfg.h.old
similarity index 100%
rename from main/utilities/letter_shell/src/shell_cfg.h
rename to main/utilities/letter_shell/src/shell_cfg.h.old
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 68af6d9..0bf196b 100644
--- a/main/utilities/usb_cherry/esp_setup/my_usb_setup.c
+++ b/main/utilities/usb_cherry/esp_setup/my_usb_setup.c
@@ -3,6 +3,8 @@
#include "usbd_msc.h"
#include
+#include "imp_util_ring_queue.h"
+
/*!< endpoint address */
#define CDC_IN_EP 0x81
#define CDC_OUT_EP 0x02
@@ -107,18 +109,27 @@ 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 };
+
/* function ------------------------------------------------------------------*/
+int cdc_printf(const char *fmt, ...);
+
void usbd_cdc_acm_out(uint8_t ep)
{
uint8_t data[64];
uint32_t read_byte;
usbd_ep_read(ep, data, 64, &read_byte);
- for (uint8_t i = 0; i < read_byte; i++) {
- USB_LOG_RAW("%02x ", data[i]);
- }
- USB_LOG_RAW("\r\n");
- USB_LOG_RAW("read len:%d\r\n", read_byte);
+ imp_util_ring_queue_write(&ring_q_cdc_recv, data, read_byte);
+ // for (uint8_t i = 0; i < read_byte; i++) {
+ // USB_LOG_RAW("%02x ", data[i]);
+ // cdc_printf("%02x ", data[i]);
+ // }
+ // USB_LOG_RAW("\r\n");
+ // USB_LOG_RAW("read len:%d\r\n", read_byte);
+ // cdc_printf("\r\n");
+ // cdc_printf("read len:%d\r\n", read_byte);
usbd_ep_read(ep, NULL, 0, NULL);
}
@@ -152,6 +163,9 @@ void cdc_acm_msc_init(void)
// usbd_msc_class_init(MSC_OUT_EP, MSC_IN_EP);
usbd_initialize();
+
+ imp_util_ring_queue_init(&ring_q_cdc_recv, ring_q_cdc_recv_swap_data, 1025);
+
}
volatile uint8_t dtr_enable = 0;
@@ -173,9 +187,41 @@ void cdc_acm_data_send_with_dtr_test(void)
}
}
+signed short cdc_usb_read_bytes(char* data, unsigned short len)
+{
+ signed short 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 {
+ data[0] = 0;
+ ret = 1;
+ }
+
+ return ret;
+}
+
+signed short cdc_usb_writ_bytes(char* data, unsigned short len)
+{
+ signed short n;
+ char aBuffer[64] = { 0 };
+ n = len >= 64 ? 64 : len;
+ aBuffer[63] = '\n';
+ strncpy(aBuffer, data, n);
+
+ if (dtr_enable) {
+ usbd_ep_write(CDC_IN_EP, (uint8_t*)data, n, NULL);
+ }
+
+ return len;
+}
+
int cdc_printf(const char *fmt, ...) {
int n;
- char aBuffer[64];
+ char aBuffer[64] = {0};
va_list args;
va_start(args, fmt);