// // Created by misaki on 2025/8/23. // #include #include "tools.h" #include "I2C_Driver.h" #include "QMI8658.h" extern IMUdata Accel; extern IMUdata Gyro; void imu_test(void) { I2C_Init(); QMI8658_Init(); while (1) { QMI8658_Loop(); ESP_LOGI("app_main", "Accel x: %f, y: %f, z: %f", Accel.x, Accel.y, Accel.z); ESP_LOGD("app_main", "Gyro X: %f, Y: %f, Z: %f", Gyro.x, Gyro.y, Gyro.z); } } #include "BAT_Driver.h" void battery_test(void) { // 初始化电池驱动 BAT_Init(); while(1) { float voltage = BAT_Get_Volts(); ESP_LOGI("BAT_TEST", "Battery Voltage: %.2f V", voltage); // 电池状态判断 if (voltage > 4.0) { ESP_LOGI("BAT_TEST", "Battery Status: Full"); } else if (voltage > 3.7) { ESP_LOGI("BAT_TEST", "Battery Status: Good"); } else if (voltage > 3.4) { ESP_LOGI("BAT_TEST", "Battery Status: Low"); } else { ESP_LOGI("BAT_TEST", "Battery Status: Critical"); } } } #include "Wireless.h" void wireless_test(void) { printf("Starting wireless scan test...\n"); // 初始化无线模块 Wireless_Init(); // 等待扫描完成 while (!Scan_finish) { printf("Waiting for scan to complete...\n"); vTaskDelay(pdMS_TO_TICKS(1000)); } // 打印所有WiFi AP信息 wireless_print_wifi_aps(); // 打印所有BLE设备信息 wireless_print_ble_devices(); } #include "SD_MMC.h" void sd_card_module_test(void) { printf("\n=== 开始SD卡模块测试 ===\n\n"); // 1. 初始化SD卡 printf("1. 初始化SD卡...\n"); SD_Init(); if(SDCard_Size > 0) { printf(" SD卡初始化成功,容量: %lu MB\n", SDCard_Size); } else { printf(" SD卡初始化失败!\n"); return; // 如果SD卡初始化失败,终止测试 } // 2. 获取Flash大小 printf("2. 获取Flash大小...\n"); Flash_Searching(); printf(" Flash大小: %lu MB\n", Flash_Size); // 3. 测试文件写入 printf("3. 测试文件写入...\n"); char test_file_path[] = MOUNT_POINT"/test.txt"; char test_data[] = "这是一段测试数据,用于验证SD卡写入功能。"; esp_err_t write_result = s_example_write_file(test_file_path, test_data); if(write_result == ESP_OK) { printf(" 文件写入成功: %s\n", test_file_path); } else { printf(" 文件写入失败!\n"); } // 4. 测试文件读取 printf("4. 测试文件读取...\n"); esp_err_t read_result = s_example_read_file(test_file_path); if(read_result != ESP_OK) { printf(" 文件读取失败!\n"); } // 5. 测试文件打开功能 printf("5. 测试文件打开功能...\n"); FILE* test_file = Open_File(test_file_path); if(test_file != NULL) { printf(" 文件打开成功\n"); fclose(test_file); // 记得关闭文件 } else { printf(" 文件打开失败!\n"); } // 6. 测试文件夹检索功能 printf("6. 测试文件夹检索功能...\n"); char file_names[10][100]; // 存储最多10个文件名 uint16_t file_count = Folder_retrieval(MOUNT_POINT, ".txt", file_names, 10); printf(" 找到 %d 个txt文件:\n", file_count); for(int i = 0; i < file_count; i++) { printf(" %d. %s\n", i+1, file_names[i]); } // 7. 清理测试文件 printf("7. 清理测试文件...\n"); if(remove(test_file_path)) { printf(" 删除文件失败: %s\n", test_file_path); } else { printf(" 成功删除测试文件: %s\n", test_file_path); } printf("\n=== SD卡模块测试完成 ===\n"); } #include "PCF85063.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" static const char *TAG = "PCF85063_TEST"; void pcf85063_test(void) { /* 1. 初始化 I2C 与 PCF85063 */ I2C_Init(); // 初始化 ESP32 I2C 外设 PCF85063_Init(); // 配置 PCF85063 进入 24h 模式、RTC 启动 ESP_LOGI(TAG, "PCF85063 初始化完成"); /* 2. 设置当前系统时间(示例:2025-08-24 周日 14:30:00)*/ datetime_t set_time = { .year = 2025, .month = 8, .day = 24, .dotw = 0, // 0 表示星期日 .hour = 14, .minute = 30, .second = 0 }; PCF85063_Set_All(set_time); ESP_LOGI(TAG, "已设置时间:2025-08-24 14:30:00"); /* 3. 设置闹钟(示例:14:31:15 触发一次)*/ datetime_t alarm_time = { .hour = 14, .minute = 31, .second = 15, /* 日/星期字段无需关心,已在 PCF85063_Set_Alarm 中屏蔽 */ }; PCF85063_Set_Alarm(alarm_time); PCF85063_Enable_Alarm(); // 使能闹钟中断并清除 AF 标志 ESP_LOGI(TAG, "已设置闹钟:14:31:15"); /* 4. 周期性读取时间与检查闹钟标志位 */ char str_buf[64]; while (true) { /* 4.1 读取当前时间 */ datetime_t now; PCF85063_Read_Time(&now); datetime_to_str(str_buf, now); ESP_LOGI(TAG, "当前时间:%s", str_buf); /* 4.2 检查闹钟标志位 */ uint8_t flag = PCF85063_Get_Alarm_Flag(); if (flag & RTC_CTRL_2_AF) { ESP_LOGI(TAG, "闹钟触发!AF=1"); /* 如需重复闹钟,可在此重新设置新时间或清除 AF 后再次使能 */ PCF85063_Enable_Alarm(); // 清除 AF 并重新使能 } vTaskDelay(pdMS_TO_TICKS(1000)); // 每秒读一次 } } #include "TCA9554PWR_Test.h" void exio_text(void) { if (EXIO_Test() == ESP_FAIL) { ESP_LOGE("EXIO_TEST", "EXIO_Test() failed"); } } #include "audio_test.h" void audio_test(void) { run_audio_test(); } #include "ST77916.h" #include "LVGL_Driver.h" #include "LVGL_Example.h" void lcd_touch_lvgl_test(void) { // 1. 初始化硬件 I2C_Init(); LCD_Init(); // 初始化屏幕和背光 LVGL_Init(); // 初始化 LVGL // 2. 创建一个简单的测试界面 lv_obj_t *label = lv_label_create(lv_scr_act()); lv_label_set_text(label, "Hello, ST77916 + LVGL!"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); // 3. 创建一个按钮用于测试触摸 lv_obj_t *btn = lv_btn_create(lv_scr_act()); lv_obj_align(btn, LV_ALIGN_CENTER, 0, 50); lv_obj_t *btn_label = lv_label_create(btn); lv_label_set_text(btn_label, "Click Me"); lv_obj_center(btn_label); // lv_obj_add_event_cb(btn, [](lv_event_t *e) { // lv_label_set_text(label, "Button Clicked!"); // }, LV_EVENT_CLICKED, NULL); // 4. 在主循环中运行 LVGL while (1) { lv_timer_handler(); vTaskDelay(pdMS_TO_TICKS(10)); } } #include "gif_test.h" void gif_test(void) { gif_display_test(); } #include "PWR_Key.h" static void pwr_task(void *arg) { while (true) { PWR_Loop(); // 电源键扫描 vTaskDelay(pdMS_TO_TICKS(100)); // 让出 CPU,防止 WDT } } void pwr_key_test(void) { ESP_LOGI("PWR_KEY_TEST", "正在创建内存使用信息打印任务"); create_print_sys_memory_task(); PWR_Init(); // 电源键初始化 I2C_Init(); LCD_Init(); // 屏幕初始化 LVGL_Init(); /* 创建独立任务 */ xTaskCreate(pwr_task, "pwr_task", 2048, NULL, 5, NULL); /* 主任务到这里就可以退出,进入 idle,WDT 不会再触发 */ ESP_LOGI("PWR_KEY_TEST", "pwr_key_test task created"); while (1) { // raise the task priority of LVGL and/or reduce the handler period can improve the performance vTaskDelay(pdMS_TO_TICKS(10)); // The task running lv_timer_handler should have lower priority than that running `lv_tick_inc` lv_timer_handler(); } } #include "MIC_Speech.h" void mic_speech_test(void) { I2C_Init(); LCD_Init(); // 屏幕初始化 SD_Init(); // 初始化 SD 卡以方便读出模型文件 LVGL_Init(); MIC_Speech_init(); while (1) { print_sys_memory(); // raise the task priority of LVGL and/or reduce the handler period can improve the performance vTaskDelay(pdMS_TO_TICKS(100)); // The task running lv_timer_handler should have lower priority than that running `lv_tick_inc` lv_timer_handler(); } } void mic_speech_and_gif_and_music_test(void) { I2C_Init(); LCD_Init(); // 屏幕初始化 SD_Init(); // 初始化 SD 卡以方便读出模型文件 LVGL_Init(); gif_display_test_1(); MIC_Speech_init(); while (1) { print_sys_memory(); // raise the task priority of LVGL and/or reduce the handler period can improve the performance vTaskDelay(pdMS_TO_TICKS(100)); // The task running lv_timer_handler should have lower priority than that running `lv_tick_inc` lv_timer_handler(); } }