From e323939cdfdf2bf8c0d109ba309a7ea36a06e4bc Mon Sep 17 00:00:00 2001 From: Gee Bartlett Date: Fri, 24 Feb 2023 12:27:27 +0000 Subject: [PATCH] added some control for size and format. --- drivers/ov2640/ov2640.cpp | 33 ++++++++-- drivers/ov2640/ov2640.hpp | 6 +- drivers/ov2640/ov2640_init.h | 65 ++++++++++++++++++- examples/camera_pack/CMakeLists.txt | 16 +---- examples/camera_pack/camera_pack_ascii.cmake | 15 +++++ ...ra_pack_demo.cpp => camera_pack_ascii.cpp} | 1 + 6 files changed, 111 insertions(+), 25 deletions(-) create mode 100644 examples/camera_pack/camera_pack_ascii.cmake rename examples/camera_pack/{camera_pack_demo.cpp => camera_pack_ascii.cpp} (96%) diff --git a/drivers/ov2640/ov2640.cpp b/drivers/ov2640/ov2640.cpp index 3c3d9498..7328878c 100644 --- a/drivers/ov2640/ov2640.cpp +++ b/drivers/ov2640/ov2640.cpp @@ -48,7 +48,7 @@ namespace pimoroni { sleep_ms(100); // Initialise the camera itself over SCCB - regs_write(ov2640_svga); + regs_write(ov2640_init); //ov2640_regs_write(config, ov2640_uxga_cif); // TODO: Support other sizes @@ -75,6 +75,20 @@ namespace pimoroni { } void OV2640::set_image_size(ImageSize size) { + if (size == SIZE_352x288){ + regs_write(ov2640_cif); + } + else if (size == SIZE_800x600){ + regs_write(ov2640_svga); + } + else if (size == SIZE_1600x1200) + { + regs_write(ov2640_uxga); + } + else{ + return; + } + // TODO current_size = size; @@ -82,13 +96,22 @@ namespace pimoroni { void OV2640::set_image_mode(ImageMode mode) { // Set output mode - i2c->reg_write_uint8(OV2640_I2C_ADDRESS, 0xff, 0x00); + i2c->reg_write_uint8(OV2640_I2C_ADDRESS, 0xff, 0x00); // Select sensor bank if (mode == MODE_RGB565) { i2c->reg_write_uint8(OV2640_I2C_ADDRESS, 0xDA, 0x09); } - else { + else if (mode == MODE_YUYV) { i2c->reg_write_uint8(OV2640_I2C_ADDRESS, 0xDA, 0x00); } + else if (mode == MODE_RAW) { + i2c->reg_write_uint8(OV2640_I2C_ADDRESS, 0xDA, 0x04); + } + else if (mode == MODE_JPEG){ + i2c->reg_write_uint8(OV2640_I2C_ADDRESS, 0xDA, 0x10); + } + else{ + return; + } current_mode = mode; } @@ -96,8 +119,8 @@ namespace pimoroni { uint32_t OV2640::get_image_len_in_bytes() const { switch (current_size) { case SIZE_1600x1200: return 1600 * 1200 * 2; - //case SIZE_800x600: return 800 * 600 * 2; - //case SIZE_352x288: return 352 * 288 * 2; + case SIZE_800x600: return 800 * 600 * 2; + case SIZE_352x288: return 352 * 288 * 2; default: return 0; } } diff --git a/drivers/ov2640/ov2640.hpp b/drivers/ov2640/ov2640.hpp index cf910b51..52ac2ec7 100644 --- a/drivers/ov2640/ov2640.hpp +++ b/drivers/ov2640/ov2640.hpp @@ -21,13 +21,15 @@ namespace pimoroni { // TODO: Changing image size not supported yet enum ImageSize { SIZE_1600x1200, - //SIZE_800x600, - //SIZE_352x288, + SIZE_800x600, + SIZE_352x288, }; enum ImageMode { MODE_RGB565, MODE_YUYV, + MODE_RAW, + MODE_JPEG }; OV2640() : OV2640(new I2C()) {} diff --git a/drivers/ov2640/ov2640_init.h b/drivers/ov2640/ov2640_init.h index a8cc9a5d..cc4f40d9 100644 --- a/drivers/ov2640/ov2640_init.h +++ b/drivers/ov2640/ov2640_init.h @@ -2,7 +2,7 @@ #define OV2640_INIT_H #include -static const uint8_t ov2640_svga[][2] = { +static const uint8_t ov2640_init[][2] = { {0xff, 0x00}, /* Device control register list Table 12 */ {0x2c, 0xff}, /* Reserved */ {0x2e, 0xdf}, /* Reserved */ @@ -185,7 +185,7 @@ static const uint8_t ov2640_svga[][2] = { {0xdd, 0x7f}, {0x05, 0x00}, {0xFF, 0x00}, - {0x05, 0x00}, + {0x05, 0x00}, // DSP bypass off // {0xda, 0x09}, // Byte swapped RGB565 {0xda, 0x00}, // YUV422 YUYV {0x98, 0x00}, @@ -226,7 +226,7 @@ static const uint8_t ov2640_svga[][2] = { {0x00, 0x00} }; -static const uint8_t ov2640_uxga_cif[][2] = { +static const uint8_t ov2640_cif[][2] = { {0xff, 0x00}, {0xe0, 0x04}, // RESET DVP {0xc0, 0xc8}, // HSIZE8: 1600 @@ -246,4 +246,63 @@ static const uint8_t ov2640_uxga_cif[][2] = { {0xe0, 0x00} }; +static const uint8_t ov2640_uxga[][2]{ + {0xff, 0x00}, // Bank switch + {0xe0, 0x04}, // RESET DVP + {0x50, 0x00}, // CTRLI: VDIV=0, HDIV=0 + {0x51, 0x90}, // HSIZE: 400 * 4 + {0x52, 0x2c}, // VSIZE: 300 * 4 + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x88}, + {0x57, 0x00}, + {0x5a, 0x90}, // OUTW: 400 * 4 = 1600 + {0x5b, 0x2c}, // OUTH: 300 * 4 = 1200 + {0x5c, 0x05}, + {0xd3, 0x80}, // PCLK_DIV = AUTO +}; + +static const uint8_t ov2640_svga[][2]{ + {0xff, 0x00}, // Bank switch + {0xe0, 0x04}, // RESET DVP + {0x50, 0x89}, // CTRLI: LP_DP, VDIV=1, HDIV=1 + {0x51, 0x90}, // HSIZE: 400 * 4 + {0x52, 0x2c}, // VSIZE: 300 * 4 + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x88}, + {0x57, 0x00}, + {0x5a, 0xc8}, // OUTW: 200 * 4 = 800 + {0x5b, 0x96}, // OUTH: 150 * 4 = 600 + {0x5c, 0x00}, + {0xd3, 0x02}, // PCLK_DIV = 2 + {0xff, 0x01}, // Bank switch + {0x12, 0x00}, /* Common control 7 */ +}; +static const uint8_t ov2640_mode_YUV422[][2]{ + {0xda, 0x00}, // YUV422 YUYV +}; +static const uint8_t ov2640_mode_RGB565[][2]{ + {0xda, 0x09}, // RGB565 RGB +}; + +static const uint8_t ov2640_dsp_gain_reg = 0x00; + + + + + +static const uint8_t ov2640_dsp_com7_reg = 0x12; + +static const uint8_t ov2640_dsp_com7_testpattern_bm = (1 << 1); +static const uint8_t ov2640_dsp_com7_zoommode_bm = (1 << 2); +static const uint8_t ov2640_dsp_com7_sysrest_bm = (1 << 7); + +static const uint8_t ov2640_dsp_com8_reg = 0x13; + +static const uint8_t ov2640_dsp_com8_bandingfilter_bm = (1 << 5); +static const uint8_t ov2640_dsp_com8_agc_en_bm = (1 << 2); +static const uint8_t ov2640_dsp_com8_aec_bm = (1 << 0); + +static const uint8_t ov2640_dsp_agc_ceiling_reg = 0x14; #endif diff --git a/examples/camera_pack/CMakeLists.txt b/examples/camera_pack/CMakeLists.txt index 59b6759a..5b2db18a 100644 --- a/examples/camera_pack/CMakeLists.txt +++ b/examples/camera_pack/CMakeLists.txt @@ -1,15 +1 @@ -set(OUTPUT_NAME camera_pack_demo) - -add_executable( - ${OUTPUT_NAME} - camera_pack_demo.cpp -) - -pico_enable_stdio_uart(${OUTPUT_NAME} 0) -pico_enable_stdio_usb(${OUTPUT_NAME} 1) - -# Pull in pico libraries that we need -target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_camera) - -# create map/bin/hex file etc. -pico_add_extra_outputs(${OUTPUT_NAME}) \ No newline at end of file +include (camera_pack_ascii.cmake) \ No newline at end of file diff --git a/examples/camera_pack/camera_pack_ascii.cmake b/examples/camera_pack/camera_pack_ascii.cmake new file mode 100644 index 00000000..9545a89a --- /dev/null +++ b/examples/camera_pack/camera_pack_ascii.cmake @@ -0,0 +1,15 @@ +set(OUTPUT_NAME camera_pack_ascii) + +add_executable( + ${OUTPUT_NAME} + camera_pack_ascii.cpp +) + +pico_enable_stdio_uart(${OUTPUT_NAME} 0) +pico_enable_stdio_usb(${OUTPUT_NAME} 1) + +# Pull in pico libraries that we need +target_link_libraries(${OUTPUT_NAME} pico_stdlib pico_camera) + +# create map/bin/hex file etc. +pico_add_extra_outputs(${OUTPUT_NAME}) \ No newline at end of file diff --git a/examples/camera_pack/camera_pack_demo.cpp b/examples/camera_pack/camera_pack_ascii.cpp similarity index 96% rename from examples/camera_pack/camera_pack_demo.cpp rename to examples/camera_pack/camera_pack_ascii.cpp index 8be1b608..70cfb936 100644 --- a/examples/camera_pack/camera_pack_demo.cpp +++ b/examples/camera_pack/camera_pack_ascii.cpp @@ -23,6 +23,7 @@ int main() { // Press the button to take a picture! while (1) { while (gpio_get(camera.SW_A)); + printf("image capture started\n"); camera.capture_image(0); printf("Image capture complete\n");