From cd28f5e60bbf57143c85d1dc42cf2d03d153c8a5 Mon Sep 17 00:00:00 2001 From: dennis Date: Thu, 6 Apr 2023 13:46:34 +0800 Subject: [PATCH] reduce spi speed --- .clang-format | 2 +- .../Pico/pico4ml/example/full_featured/main.c | 34 +++++++-------- .../example/multitude_camera_app/main.c | 2 + .../src/multitude_camera_app.c | 43 +++++++++++-------- library.properties | 2 +- src/Arducam/ArducamCamera.c | 10 ++--- src/Arducam/ArducamCamera.h | 6 +-- src/Arducam_Mega.h | 6 +-- 8 files changed, 55 insertions(+), 50 deletions(-) diff --git a/.clang-format b/.clang-format index de03738..7e4b54a 100644 --- a/.clang-format +++ b/.clang-format @@ -6,7 +6,7 @@ Language: Cpp DerivePointerAlignment: false PointerAlignment: Left -# AlignConsecutiveAssignments: true +AlignConsecutiveAssignments: true # AlignConsecutiveDeclarations: true AllowShortBlocksOnASingleLine: false AllowShortFunctionsOnASingleLine: Empty diff --git a/examples/Pico/pico4ml/example/full_featured/main.c b/examples/Pico/pico4ml/example/full_featured/main.c index 524cafe..f746bee 100644 --- a/examples/Pico/pico4ml/example/full_featured/main.c +++ b/examples/Pico/pico4ml/example/full_featured/main.c @@ -6,9 +6,9 @@ UINT btw; FIL fp; static enum save_picture_state _save_state = save_picture_idle; -CAM_IMAGE_MODE picture_resolution = CAM_IMAGE_MODE_FHD; -char* array_label[] = {"WIFI", "<---", "1600X1200", "1920X1080", "2048X1536"}; -CAM_IMAGE_MODE camera_resoultion[] = {CAM_IMAGE_MODE_UXGA, CAM_IMAGE_MODE_FHD, CAM_IMAGE_MODE_QXGA}; +CAM_IMAGE_MODE picture_resolution = CAM_IMAGE_MODE_FHD; +char* array_label[] = {"WIFI", "<---", "1600X1200", "1920X1080", "2048X1536"}; +CAM_IMAGE_MODE camera_resoultion[] = {CAM_IMAGE_MODE_UXGA, CAM_IMAGE_MODE_FHD, CAM_IMAGE_MODE_QXGA}; void SD_Init(void) { @@ -22,10 +22,10 @@ void SD_Init(void) } struct ClassCamera CAM = {0, 0}; -volatile bool reflash = false; +volatile bool reflash = false; void core1_entry() { - CAM.cam = createArducamCamera(13); + CAM.cam = createArducamCamera(13); CAM.status = Camera_init; while (true) { @@ -37,13 +37,13 @@ void core1_entry() begin(&CAM.cam); CAM.status = Camera_open; if (CAM.cam.cameraId == SENSOR_5MP_1) { - array_label[4] = "2592X1944"; + array_label[4] = "2592X1944"; camera_resoultion[2] = CAM_IMAGE_MODE_WQXGA2; } else if (CAM.cam.cameraId == SENSOR_5MP_2) { - array_label[4] = "2592X1936"; + array_label[4] = "2592X1936"; camera_resoultion[2] = CAM_IMAGE_MODE_WQXGA2; } else { - array_label[4] = "2048X1536"; + array_label[4] = "2048X1536"; camera_resoultion[2] = CAM_IMAGE_MODE_QXGA; } reflash = true; @@ -85,10 +85,10 @@ void draw_ui() int main() { char filename[20]; - int click_btn_idx = -1; + int click_btn_idx = -1; uint8_t wifiserver_state = false, find_jpg_head = false; pico4ml_init(false); - pico4ml_camera_spi_init(SPI1_BAUDRATE); + pico4ml_camera_spi_init(8 * 1000 * 1000); uint32_t wait_cnt = 0; irq_set_exclusive_handler(UART_IRQ, uart_rx_handler); irq_set_enabled(UART_IRQ, true); @@ -113,8 +113,8 @@ int main() _save_state = save_picture_error; } else { save_buffer_ready = false; - find_jpg_head = true; - _save_state = save_picture_runnig; + find_jpg_head = true; + _save_state = save_picture_runnig; } break; case save_picture_runnig: @@ -134,7 +134,7 @@ int main() case save_picture_complete: f_close(&fp); sleep_ms(10); - _save_state = save_picture_idle; + _save_state = save_picture_idle; preview_buffer_ready = false; diplay_label(click_btn_idx, GRAY); draw_rect(win_loc, GREEN); @@ -161,7 +161,7 @@ int main() _save_state = save_picture_start; // while (save_buffer_ready != true) // tight_loop_contents(); - save_buffer_ready = false; + save_buffer_ready = false; picture_resolution = camera_resoultion[click_btn_idx - 2]; diplay_label(click_btn_idx, GREEN); break; @@ -174,7 +174,7 @@ int main() } break; case save_picture_error: - _save_state = save_picture_idle; + _save_state = save_picture_idle; preview_buffer_ready = false; diplay_label(click_btn_idx, GRAY); draw_rect(win_loc, RED); @@ -193,8 +193,8 @@ int main() switch (select_touch(&array_btn[0], 2)) { case 0: preview_buffer_ready = false; - _save_state = save_picture_idle; - wifi_buffer_ready = false; + _save_state = save_picture_idle; + wifi_buffer_ready = false; draw_rect(array_btn[0], BLACK); wait_cnt = 0; break; diff --git a/examples/Pico/pico4ml/example/multitude_camera_app/main.c b/examples/Pico/pico4ml/example/multitude_camera_app/main.c index 9f654fa..9415e59 100644 --- a/examples/Pico/pico4ml/example/multitude_camera_app/main.c +++ b/examples/Pico/pico4ml/example/multitude_camera_app/main.c @@ -5,6 +5,8 @@ int main() { pico4ml_init(true); + pico4ml_camera_spi_init(8 * 1000 * 1000); multicore_launch_core1(display_loop); capture_loop(); + } diff --git a/examples/Pico/pico4ml/example/multitude_camera_app/src/multitude_camera_app.c b/examples/Pico/pico4ml/example/multitude_camera_app/src/multitude_camera_app.c index aa88787..1e86b6b 100644 --- a/examples/Pico/pico4ml/example/multitude_camera_app/src/multitude_camera_app.c +++ b/examples/Pico/pico4ml/example/multitude_camera_app/src/multitude_camera_app.c @@ -4,14 +4,14 @@ #include "apps_config.h" #include "gui_func.h" #include "static_data.h" -uint8_t frame_buff[23477]; +uint8_t frame_buff[18432]; // uint8_t buff[96 * 96 * 2]; UI_LOG_MSG_T list_cam_loc[] = {{0, 52, 14, 96, 96, 52 + 96, 14 + 96}, {0, 194, 14, 96, 96, 194 + 96, 14 + 96}, {0, 52, 128, 96, 96, 52 + 96, 128 + 96}, - {0, 194, 128, 96, 96, 194 + 96, 129 + 96}}; + {0, 194, 128, 96, 96, 194 + 96, 128 + 96}}; UI_LOG_MSG_T list_win_loc[] = {{window, 23, 9, 130, 106, 23 + 130, 9 + 106}, {window, 165, 9, 130, 106, 165 + 130, 9 + 106}, @@ -28,11 +28,13 @@ UI_LOG_MSG_T list_cam_num[] = {{gImage_num_1, 29, 99, 16, 12, 29 + 16, 99 + 12}, {gImage_num_3, 29, 85 + 129, 16, 12, 29 + 16, 85 + 129 + 12}, {gImage_num_4, 29 + 142, 85 + 129, 16, 12, 29 + 142 + 16, 85 + 129 + 12}}; -void camera_get_picture(ArducamCamera* camera) +int camera_get_picture(ArducamCamera* camera) { - takePicture(camera, CAM_IMAGE_MODE_96X96, - CAM_IMAGE_PIX_FMT_RGB565); // CAM_IMAGE_PIX_FMT_JPG - int rs = readBuff(camera, frame_buff, camera->totalLength); + // CAM_IMAGE_PIX_FMT_JPG + takePicture(camera, CAM_IMAGE_MODE_96X96, CAM_IMAGE_PIX_FMT_RGB565); + if (camera->totalLength > 18432) + return false; + return readBuff(camera, frame_buff, camera->totalLength) > 0; } void draw_multitude_camera(void) @@ -45,23 +47,22 @@ void draw_multitude_camera(void) } } static volatile bool buffer_ready = false; -static volatile uint8_t camera_idx = 0; +static volatile uint8_t camera_idx = -1; void capture_loop(void) { - pico4ml_camera_spi_init(SPI1_BAUDRATE); - sleep_ms(300); struct ClassCamera cameras[4] = {0}; // 4,3,1,2 int cameras_cs[] = {13, 28, 17, 25}; - for (size_t i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { cameras[i].cam = createArducamCamera(cameras_cs[i]); cameras[i].status = Camera_init; } - - for (uint8_t i = 0;; i++) { - if (i >= 4) + printf("for befor\r\n"); + uint8_t i = 0; + while (true) { + if (++i >= 4) i = 0; if (cameraHeartBeat(&cameras[i].cam)) { switch (cameras[i].status) { @@ -74,9 +75,13 @@ void capture_loop(void) case Camera_open: while (buffer_ready != false) tight_loop_contents(); - camera_get_picture(&cameras[i].cam); - buffer_ready = true; - camera_idx = i; + + if (camera_get_picture(&cameras[i].cam)) { + camera_idx = i; + buffer_ready = true; + } else { + cameras[i].status = Camera_close; + } break; } } else { @@ -90,11 +95,11 @@ void display_loop(void) printf("multitude_camera_app\n"); draw_multitude_camera(); while (true) { - if (buffer_ready == true) { + if (buffer_ready) { display_image(list_cam_loc[camera_idx], frame_buff); + // camera_idx = -1; buffer_ready = false; + // printf("display_loop\r\n"); } - // test_spi(0xaa); - // test_spi(0x55); } } \ No newline at end of file diff --git a/library.properties b/library.properties index 086af0d..315e8b5 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arducam_Mega -version=2.0.1 +version=2.0.2 author=Arducam maintainer=Arducam sentence=Examples of spi cameras used on different hardware. diff --git a/src/Arducam/ArducamCamera.c b/src/Arducam/ArducamCamera.c index 20ef868..bb59d91 100644 --- a/src/Arducam/ArducamCamera.c +++ b/src/Arducam/ArducamCamera.c @@ -273,14 +273,13 @@ CamStatus cameraSetAutoFocus(ArducamCamera* camera, uint8_t val) CamStatus cameraTakePicture(ArducamCamera* camera, CAM_IMAGE_MODE mode, CAM_IMAGE_PIX_FMT pixel_format) { if (camera->currentPixelFormat != pixel_format) { - camera->currentPictureMode = mode; + camera->currentPixelFormat = pixel_format; writeReg(camera, CAM_REG_FORMAT, pixel_format); // set the data format waitI2cIdle(camera); // Wait I2c Idle } if (camera->currentPictureMode != mode) { - camera->currentPixelFormat = pixel_format; - // camera->cameraDataFormat = pixel_format; + camera->currentPictureMode = mode; writeReg(camera, CAM_REG_CAPTURE_RESOLUTION, CAM_SET_CAPTURE_MODE | mode); waitI2cIdle(camera); // Wait I2c Idle } @@ -293,14 +292,13 @@ CamStatus cameratakeMultiPictures(ArducamCamera* camera, CAM_IMAGE_MODE mode, CA uint8_t num) { if (camera->currentPixelFormat != pixel_format) { - camera->currentPictureMode = mode; + camera->currentPixelFormat = pixel_format; writeReg(camera, CAM_REG_FORMAT, pixel_format); // set the data format waitI2cIdle(camera); // Wait I2c Idle } if (camera->currentPictureMode != mode) { - camera->currentPixelFormat = pixel_format; - // camera->cameraDataFormat = pixel_format; + camera->currentPictureMode = mode; writeReg(camera, CAM_REG_CAPTURE_RESOLUTION, CAM_SET_CAPTURE_MODE | mode); waitI2cIdle(camera); // Wait I2c Idle } diff --git a/src/Arducam/ArducamCamera.h b/src/Arducam/ArducamCamera.h index ef2b42c..6f54b07 100644 --- a/src/Arducam/ArducamCamera.h +++ b/src/Arducam/ArducamCamera.h @@ -14,8 +14,8 @@ /** * @file ArducamCamera.h * @author Arducam - * @date 2021/12/6 - * @version V1.0 + * @date 2023/3/6 + * @version V2.0.1 * @copyright Arducam */ @@ -96,9 +96,9 @@ typedef enum { CAM_IMAGE_MODE_QXGA = 0x08, /**<2048x1536*/ CAM_IMAGE_MODE_WQXGA2 = 0x09, /**<2592x1944*/ CAM_IMAGE_MODE_96X96 = 0x0a, /**<96x96*/ - /// @cond CAM_IMAGE_MODE_128X128 = 0x0b, /**<128x128*/ CAM_IMAGE_MODE_320X320 = 0x0c, /**<320x320*/ + /// @cond CAM_IMAGE_MODE_12 = 0x0d, /**