Skip to content

Commit

Permalink
reduce spi speed
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-ard committed Apr 6, 2023
1 parent ef65a66 commit cd28f5e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Language: Cpp
DerivePointerAlignment: false
PointerAlignment: Left

# AlignConsecutiveAssignments: true
AlignConsecutiveAssignments: true
# AlignConsecutiveDeclarations: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
Expand Down
34 changes: 17 additions & 17 deletions examples/Pico/pico4ml/example/full_featured/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions examples/Pico/pico4ml/example/multitude_camera_app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
int main()
{
pico4ml_init(true);
pico4ml_camera_spi_init(8 * 1000 * 1000);
multicore_launch_core1(display_loop);
capture_loop();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Arducam_Mega
version=2.0.1
version=2.0.2
author=Arducam <[email protected]>
maintainer=Arducam<[email protected]>
sentence=Examples of spi cameras used on different hardware.
Expand Down
10 changes: 4 additions & 6 deletions src/Arducam/ArducamCamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions src/Arducam/ArducamCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down Expand Up @@ -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, /**<Reserve*/
CAM_IMAGE_MODE_13 = 0x0e, /**<Reserve*/
CAM_IMAGE_MODE_14 = 0x0f, /**<Reserve*/
Expand Down
6 changes: 3 additions & 3 deletions src/Arducam_Mega.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/**
* @file Arducam_Mega.h
* @author Arducam
* @date 2021/12/6
* @version V1.0
* @date 2023/3/3
* @version V2.0.1
* @copyright Arducam
*/
/**
Expand Down Expand Up @@ -346,4 +346,4 @@ class Arducam_Mega
ArducamCamera* getCameraInstance(void);
};

#endif /*__SMARTSPICAM_H*/
#endif /*__SMARTSPICAM_H*/

0 comments on commit cd28f5e

Please sign in to comment.