From ea518008b05e066ad15639fbb9b2b93429c47e48 Mon Sep 17 00:00:00 2001 From: Victor Loginov <65688219+vicloginov@users.noreply.github.com> Date: Tue, 11 Jul 2023 17:16:07 -0700 Subject: [PATCH] feat(Examples,MiscDrivers): Add OV5640 DVP camera driver (#644) --- Examples/MAX78000/CameraIF/README.md | 1 + Examples/MAX78000/CameraIF/main.c | 34 ++- Examples/MAX78000/CameraIF/project.mk | 1 + Examples/MAX78002/CameraIF/README.md | 1 + Examples/MAX78002/CameraIF/main.c | 29 ++- Examples/MAX78002/CameraIF/project.mk | 13 +- Libraries/Boards/MAX78000/EvKit_V1/board.mk | 4 + Libraries/MiscDrivers/Camera/camera.c | 2 +- Libraries/MiscDrivers/Camera/camera.h | 6 +- Libraries/MiscDrivers/Camera/mipi_camera.h | 9 +- Libraries/MiscDrivers/Camera/ov5640.c | 223 +++++++++++++++++++- Libraries/MiscDrivers/Camera/ov5640_regs.h | 1 + Libraries/MiscDrivers/Camera/ov5642.c | 17 +- Libraries/MiscDrivers/Camera/ov5642_regs.h | 2 +- 14 files changed, 305 insertions(+), 38 deletions(-) diff --git a/Examples/MAX78000/CameraIF/README.md b/Examples/MAX78000/CameraIF/README.md index 17518cf4594..e68bbdca1e5 100644 --- a/Examples/MAX78000/CameraIF/README.md +++ b/Examples/MAX78000/CameraIF/README.md @@ -5,6 +5,7 @@ This example demonstrates the Parallel Camera Interface (PCIF) drivers and camer * OV7962 (Default) * HM0360 (MONO), for color use the CameraIF_Debayer example * OV5642 +* OV5640 * HM01B0 ## Software diff --git a/Examples/MAX78000/CameraIF/main.c b/Examples/MAX78000/CameraIF/main.c index aa8e595b20e..5fc43f3ae13 100644 --- a/Examples/MAX78000/CameraIF/main.c +++ b/Examples/MAX78000/CameraIF/main.c @@ -33,7 +33,7 @@ /** * @file main.c - * @brief Parallel camera example with the OV7692/OV5642/HM01B0/HM0360/PAG7920 camera sensors as defined in the makefile. + * @brief Parallel camera example with the OV7692/OV5642/OV5640/HM01B0/HM0360/PAG7920 camera sensors as defined in the makefile. * * @details This example uses the UART to stream out the image captured from the camera. * Alternatively, it can display the captured image on TFT is it is enabled in the make file. @@ -56,8 +56,10 @@ #include "uart.h" #include "led.h" #include "board.h" - #include "camera.h" +#if defined(OV5640_DVP) +#include "mipi_camera.h" +#endif #include "utils.h" #include "dma.h" @@ -68,8 +70,8 @@ /* If enabled, camera is setup in streaming mode to send the image line by line to TFT, or serial port as they are captured. Otherwise, it buffers the entire image first and then sends to TFT or serial port. -With serial port set at 900kbps, it can stream for up to 80x80 with OV5642 camera in -stream mode, or 176x144 when stream mode is disabled. It can display on TFT up to 176x144 +With serial port set at 900kbps, it can stream for up to 80x80 with OV5642 camera in +stream mode, or 176x144 when stream mode is disabled. It can display on TFT up to 176x144 if stream mode is disabled, or 320x240 if enabled */ // #define BUTTON @@ -134,8 +136,7 @@ Compiler definitions... These configure TFT and camera settings based on the op #endif -#if defined(CAMERA_OV7692) || defined(CAMERA_OV5642) - +#if defined(CAMERA_OV7692) || defined(CAMERA_OV5642) || defined(CAMERA_OV5640) #ifdef ENABLE_TFT #ifdef STREAM_ENABLE #define IMAGE_XRES 320 @@ -281,13 +282,13 @@ int main(void) // Initialize the camera driver. camera_init(CAMERA_FREQ); - printf("\n\nCamera Example\n"); + printf("\n\nCameraIF Example\n"); slaveAddress = camera_get_slave_address(); printf("Camera I2C slave address: %02x\n", slaveAddress); - // Obtain the manufacturer ID of the camera. - ret = camera_get_manufacture_id(&id); + // Obtain product ID of the camera. + ret = camera_get_product_id(&id); if (ret != STATUS_OK) { printf("Error returned from reading camera id. Error %d\n", ret); @@ -334,8 +335,13 @@ int main(void) // Setup the camera image dimensions, pixel format and data acquiring details. #ifndef STREAM_ENABLE #ifndef CAMERA_MONO +#if defined(OV5640_DVP) + ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXEL_FORMAT_RGB565, FIFO_FOUR_BYTE, USE_DMA, + dma_channel); // RGB565 +#else ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXFORMAT_RGB565, FIFO_FOUR_BYTE, USE_DMA, dma_channel); // RGB565 +#endif #else ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXFORMAT_BAYER, FIFO_FOUR_BYTE, USE_DMA, dma_channel); // Mono @@ -352,8 +358,13 @@ int main(void) #else //STREAM_ENABLE #ifndef CAMERA_MONO #ifndef FEATHER_FAST_STREAM +#if defined(OV5640_DVP) + ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXEL_FORMAT_RGB565, FIFO_FOUR_BYTE, STREAMING_DMA, + dma_channel); // RGB565 +#else ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXFORMAT_RGB565, FIFO_FOUR_BYTE, STREAMING_DMA, - dma_channel); // RGB565 stream + dma_channel); // RGB565 +#endif #else MXC_TFT_Stream(0, 0, IMAGE_XRES, IMAGE_YRES); ret = camera_setup_tft(IMAGE_XRES, IMAGE_YRES, PIXFORMAT_RGB565, FIFO_FOUR_BYTE, STREAMING_DMA, @@ -379,6 +390,9 @@ int main(void) return -1; } +#if defined(OV5640_DVP) + camera_write_reg(0x503d, 0x0); // workaround: disable test pattern: color bar +#endif MXC_Delay(SEC(1)); // Start capturing a first camera image frame. diff --git a/Examples/MAX78000/CameraIF/project.mk b/Examples/MAX78000/CameraIF/project.mk index 2a2dbc7f7dc..da83f20e476 100644 --- a/Examples/MAX78000/CameraIF/project.mk +++ b/Examples/MAX78000/CameraIF/project.mk @@ -14,6 +14,7 @@ # For a full list of options for the 'CAMERA' variable, # see the documentation. CAMERA=OV7692 +#CAMERA=OV5640 #CAMERA=OV5642 #CAMERA=HM0360_MONO #CAMERA=HM01B0 diff --git a/Examples/MAX78002/CameraIF/README.md b/Examples/MAX78002/CameraIF/README.md index 57aea45e9b4..81a04a32c38 100644 --- a/Examples/MAX78002/CameraIF/README.md +++ b/Examples/MAX78002/CameraIF/README.md @@ -34,6 +34,7 @@ To change the camera drivers set the `CAMERA` build configuration variable in [p Additionally, ensure JP38 (DVP CAM PWR) is connected properly. - OV7692: Connect JP38 to "ON" +- OV5640: Connect JP38 to "ON" - HM0360: Connect JP38 to "OFF" Consult your camera module's power-down logic and the MAX78002EVKIT schematic for other camera modules. diff --git a/Examples/MAX78002/CameraIF/main.c b/Examples/MAX78002/CameraIF/main.c index 01e4599bfd1..2275c47b75c 100644 --- a/Examples/MAX78002/CameraIF/main.c +++ b/Examples/MAX78002/CameraIF/main.c @@ -33,7 +33,7 @@ /** * @file main.c - * @brief Parallel camera example with the OV7692/OV5642/HM01B0/HM0360 camera sensors as defined in the makefile. + * @brief Parallel camera example with the OV7692/OV5642/OV5640/HM01B0/HM0360/PAG7920 camera sensors as defined in the makefile. * * @details This example uses the UART to stream out the image captured from the camera. * Alternatively, it can display the captured image on TFT is it is enabled in the make file. @@ -58,6 +58,7 @@ #include "led.h" #include "board.h" #include "camera.h" +#include "mipi_camera.h" #include "utils.h" #include "dma.h" #ifdef TFT_ADAFRUIT @@ -75,17 +76,18 @@ #if defined(CAMERA_HM01B0) #define IMAGE_XRES 324 / 2 #define IMAGE_YRES 244 / 2 +#define CAMERA_MONO #endif -#if defined(CAMERA_HM0360_MONO) +#if defined(CAMERA_HM0360_MONO) || defined(CAMERA_PAG7920) #define IMAGE_XRES 320 #define IMAGE_YRES 240 +#define CAMERA_MONO #endif -#if defined(CAMERA_OV7692) || defined(CAMERA_OV5642) +#if defined(CAMERA_OV7692) || defined(CAMERA_OV5642) || defined(CAMERA_OV5640) #define IMAGE_XRES 320 #define IMAGE_YRES 240 - #endif #define CON_BAUD \ @@ -160,7 +162,8 @@ int main(void) printf("Camera ID detected: %04x\n", id); -#if defined(CAMERA_HM01B0) || defined(CAMERA_HM0360_MONO) || defined(CAMERA_OV5642) +#if defined(CAMERA_HM01B0) || defined(CAMERA_HM0360_MONO) || defined(CAMERA_OV5642) || \ + defined(CAMERA_OV5640) camera_set_vflip(0); #ifdef TFT_NEWHAVEN // Newhaven display needs a horizontal flip to match orientation @@ -192,14 +195,19 @@ int main(void) } // Set 0 rotation to match camera orientation MXC_TFT_SetRotation(ROTATE_0); -#endif #endif MXC_TFT_SetBackGroundColor(0); +#endif // Setup the camera image dimensions, pixel format and data acquiring details. #ifndef CAMERA_MONO +#if defined(OV5640_DVP) + ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXEL_FORMAT_RGB565, FIFO_FOUR_BYTE, USE_DMA, + dma_channel); // RGB565 +#else ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXFORMAT_RGB565, FIFO_FOUR_BYTE, USE_DMA, dma_channel); // RGB565 +#endif #else ret = camera_setup(IMAGE_XRES, IMAGE_YRES, PIXFORMAT_BAYER, FIFO_FOUR_BYTE, USE_DMA, dma_channel); // Mono @@ -210,9 +218,13 @@ int main(void) return -1; } - // Start capturing a first camera image frame. - printf("Capture image\n"); +#if defined(OV5640_DVP) + camera_write_reg(0x503d, 0x0); // workaround: disable test pattern: color bar +#endif + + // Start capturing a first camera image frame. camera_start_capture_image(); + printf("Capture image\n"); while (1) { // Check if image is acquired. @@ -226,6 +238,7 @@ int main(void) // Prepare for another frame capture. LED_Toggle(LED1); camera_start_capture_image(); + printf(".\n"); } } diff --git a/Examples/MAX78002/CameraIF/project.mk b/Examples/MAX78002/CameraIF/project.mk index 898b9820f2c..1ef517fe06d 100644 --- a/Examples/MAX78002/CameraIF/project.mk +++ b/Examples/MAX78002/CameraIF/project.mk @@ -15,11 +15,16 @@ # connected camera. These are some common values. # For a full list of options for the 'CAMERA' variable, # see the documentation. -CAMERA=OV7692 -#CAMERA=OV5640 -# CAMERA=HM0360_MONO +#CAMERA=OV7692 +CAMERA=OV5640 +#CAMERA=OV5642 +#CAMERA=HM0360_MONO #CAMERA=HM01B0 +ifeq "$(CAMERA)" "OV5640" +PROJ_CFLAGS+=-DOV5640_DVP +endif + # Uncomment to use legacy Adafruit 3315 TFT drivers (TFT = ADAFRUIT) # Otherwise, default drivers (TFT = NEWHAVEN) will be used for NewHaven NHD-2.4 # TFT = ADAFRUIT @@ -27,4 +32,4 @@ CAMERA=OV7692 # Set a higher optimization level. The increased performance # is required for the CameraIF DMA code to work within the # timing requirements of the Parallel Camera Interface. -MXC_OPTIMIZE_CFLAGS = -O2 \ No newline at end of file +MXC_OPTIMIZE_CFLAGS = -O2 diff --git a/Libraries/Boards/MAX78000/EvKit_V1/board.mk b/Libraries/Boards/MAX78000/EvKit_V1/board.mk index 6e77af7710e..bad3a9cf8c9 100644 --- a/Libraries/Boards/MAX78000/EvKit_V1/board.mk +++ b/Libraries/Boards/MAX78000/EvKit_V1/board.mk @@ -67,6 +67,10 @@ PROJ_CFLAGS+=-DCAMERA_HM0360_COLOR else ifeq "$(CAMERA)" "OV5642" SRCS += ov5642.c PROJ_CFLAGS+=-DCAMERA_OV5642 +else ifeq "$(CAMERA)" "OV5640" +SRCS += ov5640.c +PROJ_CFLAGS+=-DCAMERA_OV5640 +PROJ_CFLAGS+=-DOV5640_DVP else ifeq "$(CAMERA)" "OV7692" SRCS += ov7692.c PROJ_CFLAGS+=-DCAMERA_OV7692 diff --git a/Libraries/MiscDrivers/Camera/camera.c b/Libraries/MiscDrivers/Camera/camera.c index 2c91b6cde56..3f47b3e3a24 100644 --- a/Libraries/MiscDrivers/Camera/camera.c +++ b/Libraries/MiscDrivers/Camera/camera.c @@ -788,7 +788,7 @@ int camera_setup_tft(int xres, int yres, pixformat_t pixformat, fifomode_t fifo_ #endif #if defined(CAMERA_HM01B0) || defined(CAMERA_HM0360_MONO) || defined(CAMERA_HM0360_COLOR) || \ - defined(CAMERA_OV5642) + defined(CAMERA_OV5642) || defined(CAMERA_OV5640) int camera_read_reg(uint16_t reg_addr, uint8_t *reg_data) { return camera.read_reg(reg_addr, reg_data); diff --git a/Libraries/MiscDrivers/Camera/camera.h b/Libraries/MiscDrivers/Camera/camera.h index 66621804d01..76acbc99b14 100644 --- a/Libraries/MiscDrivers/Camera/camera.h +++ b/Libraries/MiscDrivers/Camera/camera.h @@ -46,6 +46,8 @@ #include "hm0360_regs.h" #elif defined(CAMERA_OV5642) #include "ov5642_regs.h" +#elif defined(CAMERA_OV5640) +#include "ov5640_regs.h" #elif defined(CAMERA_OV7692) #include "ov7692_regs.h" #elif defined(CAMERA_PAG7920) @@ -100,7 +102,7 @@ typedef struct _camera { int (*reset)(void); int (*sleep)(int enable); #if defined(CAMERA_HM01B0) || (CAMERA_HM0360_MONO) || (CAMERA_HM0360_COLOR) || \ - defined(CAMERA_OV5642) + defined(CAMERA_OV5642) || defined(CAMERA_OV5640) int (*read_reg)(uint16_t reg_addr, uint8_t *reg_data); int (*write_reg)(uint16_t reg_addr, uint8_t reg_data); #else //(CAMERA_OV7692) || (CAMERA_PAG7920) @@ -153,7 +155,7 @@ int camera_sleep(int enable); int camera_shutdown(int enable); #if defined(CAMERA_HM01B0) || (CAMERA_HM0360_MONO) || (CAMERA_HM0360_COLOR) || \ - defined(CAMERA_OV5642) + defined(CAMERA_OV5642) || defined(CAMERA_OV5640) // Write a sensor register. int camera_write_reg(uint16_t reg_addr, uint8_t reg_data); int camera_read_reg(uint16_t reg_addr, uint8_t *reg_data); diff --git a/Libraries/MiscDrivers/Camera/mipi_camera.h b/Libraries/MiscDrivers/Camera/mipi_camera.h index c54f4020831..ea720a362d3 100644 --- a/Libraries/MiscDrivers/Camera/mipi_camera.h +++ b/Libraries/MiscDrivers/Camera/mipi_camera.h @@ -35,8 +35,9 @@ #define LIBRARIES_MISCDRIVERS_CAMERA_MIPI_CAMERA_H_ #include +#ifndef OV5640_DVP #include "csi2.h" - +#endif /** * @brief Pixel format enumerations. */ @@ -89,12 +90,15 @@ typedef struct _mipi_camera_format { * @brief Camera settings struct. This is the "top-level" configuration struct * encapsulating all camera settings. Pass this in to the @ref mipi_camera_init function. */ + typedef struct _mipi_camera_settings_t { unsigned int width; /**< Image width in pixels */ unsigned int height; /**< Image height in pixels */ mipi_camera_format_t camera_format; /**< Image format */ +#ifndef OV5640_DVP mxc_csi2_line_handler_cb_t line_handler; /**< Line handler provided by application to process incoming camera data */ +#endif } mipi_camera_settings_t; typedef enum { @@ -208,8 +212,9 @@ mipi_camera_settings_t mipi_camera_get_camera_settings(void); * @brief Get detailed statistics about the last image capture and any errors that occurred. * @return A @ref mxc_csi2_capture_stats_t struct */ +#ifndef OV5640_DVP mxc_csi2_capture_stats_t mipi_camera_get_capture_stats(void); - +#endif /** * @brief Parse a string containing information about the last captured image. * This is used with console.py utilities. diff --git a/Libraries/MiscDrivers/Camera/ov5640.c b/Libraries/MiscDrivers/Camera/ov5640.c index 33f487c1c19..5e4ee10487b 100644 --- a/Libraries/MiscDrivers/Camera/ov5640.c +++ b/Libraries/MiscDrivers/Camera/ov5640.c @@ -49,6 +49,212 @@ #define cambus_writeb(addr, x) sccb_write_byt(g_slv_addr, addr, x) #define cambus_readb(addr, x) sccb_read_byt(g_slv_addr, addr, x) +#ifdef OV5640_DVP +static struct camera_reg default_regs[] = { + // power down + {0x3008, 0x42}, + //# enable pll + {0x3103, 0x03}, + // io direction + {0x3017, 0xFF}, + {0x3018, 0xFF}, + {0x302C, 0xC3}, + {0x4740, 0x20}, // VSYNC = active low, HREF= active low, PCLK=high + {0x4713, 0x06}, // JPEG mode select + // sys reset + {0x3000, 0x00}, // enable all blocks + {0x3002, 0x1C}, // reset jfifo, sfifo, jpg, fmux, avg + // clock enable + {0x3004, 0xFF}, + {0x3006, 0xC3}, + + {0x3034, 0x1a}, // PLL, 10-bit + {0x3037, 0x12}, // PLL + {0x3108, 0x01}, // clock divider + {0x3039, 0x0}, + //{0x3034, 0x1A}, + {0x3035, 0x11}, + {0x3036, 0x20}, + //{0x3037, 0x1A}, + //{0x3108, 0x1}, + {0x3824, 0x1}, + + // ISP control + {0x5000, 0xA7}, + {0x5001, 0xa3}, // ISP Control: turn color matrix, awb, SDE and scaling + {0x5003, 0x04}, // bin enable + + {0x370C, 0x02}, + {0x3634, 0x40}, + // AEC/AGC + {0x3A02, 0x03}, + {0x3A03, 0xD8}, + {0x3A08, 0x01}, + {0x3A09, 0x27}, + {0x3A0A, 0x00}, + {0x3A0B, 0xF6}, + {0x3A0D, 0x04}, + {0x3A0E, 0x03}, + {0x3A0F, 0x30}, // ae_level + {0x3A10, 0x28}, // ae_level + {0x3A11, 0x60}, // ae_level + {0x3A13, 0x43}, + {0x3A14, 0x03}, + {0x3A15, 0xD8}, + {0x3A18, 0x00}, // gainceiling + {0x3A19, 0xF8}, // gainceiling + {0x3A1B, 0x30}, // ae_level + {0x3A1E, 0x26}, // ae_level + {0x3A1F, 0x14}, // ae_level + // vcm debug + {0x3600, 0x08}, + {0x3601, 0x33}, + // 50/60Hz + {0x3C01, 0xA4}, + {0x3C04, 0x28}, + {0x3C05, 0x98}, + {0x3C06, 0x00}, + {0x3C07, 0x08}, + {0x3C08, 0x00}, + {0x3C09, 0x1C}, + {0x3C0A, 0x9C}, + {0x3C0B, 0x40}, + {0x460C, 0x24}, // disable JPEG footer + // BLC + {0x4001, 0x02}, + {0x4004, 0x02}, + // AWB0 + {0x5180, 0xFF}, + {0x5181, 0xF2}, + {0x5182, 0x00}, + {0x5183, 0x14}, + {0x5184, 0x25}, + {0x5185, 0x24}, + {0x5186, 0x09}, + {0x5187, 0x09}, + {0x5188, 0x09}, + {0x5189, 0x75}, + {0x518A, 0x54}, + {0x518B, 0xE0}, + {0x518C, 0xB2}, + {0x518D, 0x42}, + {0x518E, 0x3D}, + {0x518F, 0x56}, + {0x5190, 0x46}, + {0x5191, 0xF8}, + {0x5192, 0x04}, + {0x5193, 0x70}, + {0x5194, 0xF0}, + {0x5195, 0xF0}, + {0x5196, 0x03}, + {0x5197, 0x01}, + {0x5198, 0x04}, + {0x5199, 0x12}, + {0x519A, 0x04}, + {0x519B, 0x00}, + {0x519C, 0x06}, + {0x519D, 0x82}, + {0x519E, 0x38}, + // color matrix (Saturation) + {0x5381, 0x1E}, + {0x5382, 0x5B}, + {0x5383, 0x08}, + {0x5384, 0x0A}, + {0x5385, 0x7E}, + {0x5386, 0x88}, + {0x5387, 0x7C}, + {0x5388, 0x6C}, + {0x5389, 0x10}, + {0x538A, 0x01}, + {0x538B, 0x98}, + // CIP control (Sharpness) + {0x5300, 0x10}, //# sharpness + {0x5301, 0x10}, //# sharpness + {0x5302, 0x18}, //# sharpness + {0x5303, 0x19}, //# sharpness + {0x5304, 0x10}, + {0x5305, 0x10}, + {0x5306, 0x08}, //# denoise + {0x5307, 0x16}, + {0x5308, 0x40}, + {0x5309, 0x10}, //# sharpness + {0x530A, 0x10}, //# sharpness + {0x530B, 0x04}, //# sharpness + {0x530C, 0x06}, //# sharpness + // GAMMA 1 + {0x5480, 0x01}, + {0x5481, 0x00}, + {0x5482, 0x1E}, + {0x5483, 0x3B}, + {0x5484, 0x58}, + {0x5485, 0x66}, + {0x5486, 0x71}, + {0x5487, 0x7D}, + {0x5488, 0x83}, + {0x5489, 0x8F}, + {0x548A, 0x98}, + {0x548B, 0xA6}, + {0x548C, 0xB8}, + {0x548D, 0xCA}, + {0x548E, 0xD7}, + {0x548F, 0xE3}, + {0x5490, 0x1D}, + // Special Digital Effects (SDE) (UV adjust) + {0x5580, 0x06}, // enable brightness and contrast + {0x5583, 0x40}, // special_effect + {0x5584, 0x10}, // special_effect + {0x5586, 0x20}, // contrast + {0x5587, 0x00}, // brightness + {0x5588, 0x00}, // brightness + {0x5589, 0x10}, + {0x558A, 0x00}, + {0x558B, 0xF8}, + {0x501D, 0x40}, // enable manual offset of contrast + + {0x501F, 0x01}, // RGB + {0x4300, 0x61}, // RGB565 (BGR) + {0x3002, 0x1C}, // reset jfifo, sfifo, jpg, fmux, avg + {0x3006, 0xC3}, // reset to how it was before (no jpg clock) + + {0x3800, 0x0 }, // XSTART=0 + {0x3801, 0x0}, + {0x3802, 0x0 }, // YSTART=0 + {0x3803, 0x0 }, + {0x3804, 0xa }, // XEND=2623 + {0x3805, 0x3f}, + {0x3806, 0x7 }, // YEND=1951 + {0x3807, 0x9f}, + {0x3808, 0x1 }, // out width=320 + {0x3809, 0x40}, + {0x380a, 0x0 }, // out height=240 + {0x380b, 0xf0}, + {0x380c, 0x8 }, // Total HSIZE=2060 + {0x380d, 0x0c}, + {0x380e, 0x3 }, // Total VSIZE=984 + {0x380f, 0xd8}, + {0x3810, 0x00}, // X offset + {0x3811, 0x10}, + {0x3812, 0x00}, // Y offset + {0x3813, 0x08}, + {0x4520, 0x0B}, + {0x3814, 0x31}, // timing X inc + {0x3815, 0x31}, // timing Y inc + {0x3820, 0x06}, + {0x3821, 0x00}, + {0x4514, 0xBB}, + +// {0x503d, 0x80}, // Test pattern: Color bar + {0x503d, 0x00}, // No test pattern + {0x4741, 0x00}, + {0x503e, 0x00}, + + {0x3008, 0x02}, // wake up from software power down + // Delay + {0xffff, 150}, + // End + {0, 0} +}; +#else static struct camera_reg default_regs[] = { // Reset {0x3102, 0x11}, @@ -450,6 +656,7 @@ static struct camera_reg default_regs[] = { // End {0, 0} }; +#endif //clang-format on static int g_slv_addr; @@ -485,7 +692,12 @@ static int get_product_id(int* id) static int get_manufacture_id(int* id) { - return E_NOT_SUPPORTED; + int ret = 0; + uint8_t rev; + + ret |= cambus_read(CHIPREV, &rev); + *id = rev; + return ret; } static int dump_registers(void) @@ -621,6 +833,9 @@ static int set_pixformat(mipi_camera_format_t camera_format) break; case PIXEL_FORMAT_RGB565: + #if defined(OV5640_DVP) + out_seq = 1; + #endif ret |= cambus_write(FORMAT_CTRL00h, (0x06 << 4) | out_seq); break; @@ -1149,7 +1364,7 @@ static int set_hmirror(int enable) ret = cambus_read(TIMING_TC_REG21, ®); if (enable) { - reg |= 0x02;; + reg |= 0x02; } else { reg &= ~0x02; } @@ -1217,7 +1432,11 @@ static int get_luminance(int* lum) // clang-format off /******************************** Public Functions ***************************/ +#ifdef OV5640_DVP +int sensor_register(mipi_camera_t* camera) +#else int mipi_sensor_register(mipi_camera_t* camera) +#endif { // Initialize sensor structure. camera->init = init; diff --git a/Libraries/MiscDrivers/Camera/ov5640_regs.h b/Libraries/MiscDrivers/Camera/ov5640_regs.h index a7f9cde6025..b3d4f827120 100644 --- a/Libraries/MiscDrivers/Camera/ov5640_regs.h +++ b/Libraries/MiscDrivers/Camera/ov5640_regs.h @@ -67,6 +67,7 @@ #define SYS_CTRL0 (0x3008) #define CHIPID_H (0x300a) #define CHIPID_L (0x300b) +#define CHIPREV (0x302a) #define MIPI_CTRL0 (0x300e) diff --git a/Libraries/MiscDrivers/Camera/ov5642.c b/Libraries/MiscDrivers/Camera/ov5642.c index ff573b81000..8ce9cb61733 100644 --- a/Libraries/MiscDrivers/Camera/ov5642.c +++ b/Libraries/MiscDrivers/Camera/ov5642.c @@ -784,6 +784,7 @@ static int set_saturation(int level) return ret; } + #if 0 static int set_hue(int degree) { @@ -903,50 +904,50 @@ static int set_special_effect(ov5642_effect_t effect) int ret = 0; switch (effect) { - case NORMAL: + case SE_NORMAL: ret |= cambus_write(0x5001, 0x7f); ret |= cambus_write(0x5580, 0x00); break; - case BLUE: + case SE_BLUE: ret |= cambus_write(0x5001, 0xff); ret |= cambus_write(0x5580, 0x18); ret |= cambus_write(0x5585, 0xa0); ret |= cambus_write(0x5586, 0x40); break; - case GREEN: + case SE_GREEN: ret |= cambus_write(0x5001, 0xff); ret |= cambus_write(0x5580, 0x18); ret |= cambus_write(0x5585, 0x60); ret |= cambus_write(0x5586, 0x60); break; - case RED: + case SE_RED: ret |= cambus_write(0x5001, 0xff); ret |= cambus_write(0x5580, 0x18); ret |= cambus_write(0x5585, 0x80); ret |= cambus_write(0x5586, 0xc0); break; - case BLACK_WHITE: + case SE_BLACK_WHITE: ret |= cambus_write(0x5001, 0xff); ret |= cambus_write(0x5580, 0x18); ret |= cambus_write(0x5585, 0x80); ret |= cambus_write(0x5586, 0x80); break; - case NEGATIVE: + case SE_NEGATIVE: ret |= cambus_write(0x5001, 0xff); ret |= cambus_write(0x5580, 0x40); break; - case GRAY: + case SE_GRAY: ret |= cambus_write(0x5001, 0xff); ret |= cambus_write(0x5580, 0x20); break; - case SEPIA: + case SE_SEPIA: ret |= cambus_write(0x5001, 0xff); ret |= cambus_write(0x5580, 0x18); ret |= cambus_write(0x5585, 0x40); diff --git a/Libraries/MiscDrivers/Camera/ov5642_regs.h b/Libraries/MiscDrivers/Camera/ov5642_regs.h index 53abbc09a10..66f3edb36b5 100644 --- a/Libraries/MiscDrivers/Camera/ov5642_regs.h +++ b/Libraries/MiscDrivers/Camera/ov5642_regs.h @@ -100,6 +100,6 @@ // clang-format on // Special effects -typedef enum { NORMAL = 0, BLUE, GREEN, RED, BLACK_WHITE, NEGATIVE, GRAY, SEPIA } ov5642_effect_t; +typedef enum { SE_NORMAL = 0, SE_BLUE, SE_GREEN, SE_RED, SE_BLACK_WHITE, SE_NEGATIVE, SE_GRAY, SE_SEPIA } ov5642_effect_t; #endif // LIBRARIES_MISCDRIVERS_CAMERA_OV5642_REGS_H_