Skip to content

Commit

Permalink
feat(Examples,MiscDrivers): Add OV5640 DVP camera driver (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicloginov committed Jul 12, 2023
1 parent 2b10962 commit ea51800
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 38 deletions.
1 change: 1 addition & 0 deletions Examples/MAX78000/CameraIF/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 24 additions & 10 deletions Examples/MAX78000/CameraIF/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Examples/MAX78000/CameraIF/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Examples/MAX78002/CameraIF/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 21 additions & 8 deletions Examples/MAX78002/CameraIF/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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 \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -226,6 +238,7 @@ int main(void)
// Prepare for another frame capture.
LED_Toggle(LED1);
camera_start_capture_image();
printf(".\n");
}
}

Expand Down
13 changes: 9 additions & 4 deletions Examples/MAX78002/CameraIF/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
# 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

# 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
MXC_OPTIMIZE_CFLAGS = -O2
4 changes: 4 additions & 0 deletions Libraries/Boards/MAX78000/EvKit_V1/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Libraries/MiscDrivers/Camera/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions Libraries/MiscDrivers/Camera/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions Libraries/MiscDrivers/Camera/mipi_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
#define LIBRARIES_MISCDRIVERS_CAMERA_MIPI_CAMERA_H_

#include <stdint.h>
#ifndef OV5640_DVP
#include "csi2.h"

#endif
/**
* @brief Pixel format enumerations.
*/
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit ea51800

Please sign in to comment.