More OV2640 initialization logic
This commit is contained in:
parent
5809637722
commit
5761d57f5f
@ -144,7 +144,7 @@ CONFIG_SAMA5_USART1=y
|
|||||||
# CONFIG_SAMA5_USART2 is not set
|
# CONFIG_SAMA5_USART2 is not set
|
||||||
# CONFIG_SAMA5_USART3 is not set
|
# CONFIG_SAMA5_USART3 is not set
|
||||||
# CONFIG_SAMA5_TWI0 is not set
|
# CONFIG_SAMA5_TWI0 is not set
|
||||||
# CONFIG_SAMA5_TWI1 is not set
|
CONFIG_SAMA5_TWI1=y
|
||||||
# CONFIG_SAMA5_TWI2 is not set
|
# CONFIG_SAMA5_TWI2 is not set
|
||||||
# CONFIG_SAMA5_HSMCI0 is not set
|
# CONFIG_SAMA5_HSMCI0 is not set
|
||||||
# CONFIG_SAMA5_HSMCI1 is not set
|
# CONFIG_SAMA5_HSMCI1 is not set
|
||||||
@ -203,6 +203,11 @@ CONFIG_SAMA5_LCDC_BASE_RGB565=y
|
|||||||
# CONFIG_SAMA5_LCDC_BASE_ARGB8888 is not set
|
# CONFIG_SAMA5_LCDC_BASE_ARGB8888 is not set
|
||||||
# CONFIG_SAMA5_LCDC_BASE_RGBA8888 is not set
|
# CONFIG_SAMA5_LCDC_BASE_RGBA8888 is not set
|
||||||
|
|
||||||
|
#
|
||||||
|
# TWI device driver options
|
||||||
|
#
|
||||||
|
CONFIG_SAMA5_TWI1_FREQUENCY=100000
|
||||||
|
|
||||||
#
|
#
|
||||||
# External Memory Configuration
|
# External Memory Configuration
|
||||||
#
|
#
|
||||||
@ -391,7 +396,6 @@ CONFIG_I2C_TRANSFER=y
|
|||||||
# CONFIG_AUDIO_DEVICES is not set
|
# CONFIG_AUDIO_DEVICES is not set
|
||||||
CONFIG_VIDEO_DEVICES=y
|
CONFIG_VIDEO_DEVICES=y
|
||||||
CONFIG_VIDEO_OV2640=y
|
CONFIG_VIDEO_OV2640=y
|
||||||
# CONFIG_OV2640_MULTIPLE is not set
|
|
||||||
CONFIG_OV2640_I2CADDR=0x21
|
CONFIG_OV2640_I2CADDR=0x21
|
||||||
CONFIG_OV2640_FREQUENCY=400000
|
CONFIG_OV2640_FREQUENCY=400000
|
||||||
CONFIG_OV2640_RGB565_COLORFMT=y
|
CONFIG_OV2640_RGB565_COLORFMT=y
|
||||||
|
@ -42,8 +42,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/i2c.h>
|
||||||
#include <nuttx/fb.h>
|
#include <nuttx/fb.h>
|
||||||
#include <nuttx/nx/nx.h>
|
#include <nuttx/video/ov2640.h>
|
||||||
|
|
||||||
#include "up_arch.h"
|
#include "up_arch.h"
|
||||||
|
|
||||||
@ -52,7 +53,7 @@
|
|||||||
#include "sam_pck.h"
|
#include "sam_pck.h"
|
||||||
#include "sama5d3x-ek.h"
|
#include "sama5d3x-ek.h"
|
||||||
|
|
||||||
#if defined(CONFIG_SAMA5_ISI) && defined(CONFIG_SAMA5_OV2640_DEMO)
|
#ifdef HAVE_CAMERA
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
@ -63,10 +64,6 @@
|
|||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* The connection handler */
|
|
||||||
|
|
||||||
static NXHANDLE g_hnx = NULL;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -75,120 +72,28 @@ static NXHANDLE g_hnx = NULL;
|
|||||||
* Name: ov2640_lcd_initialize
|
* Name: ov2640_lcd_initialize
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_NX_MULTIUSER
|
static inline FAR struct fb_vtable_s *ov2640_lcd_initialize(void)
|
||||||
static inline int ov2640_lcd_initialize(void)
|
|
||||||
{
|
{
|
||||||
FAR NX_DRIVERTYPE *dev;
|
FAR struct fb_vtable_s *vplane;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Initialize the frame buffer device */
|
/* Initialize the frame buffer device */
|
||||||
|
|
||||||
gvdbg("Initializing framebuffer\n");
|
|
||||||
ret = up_fbinitialize();
|
ret = up_fbinitialize();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
gdbg("ERROR: up_fbinitialize failed: %d\n", -ret);
|
gdbg("ERROR: up_fbinitialize failed: %d\n", -ret);
|
||||||
return EXIT_FAILURE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = up_fbgetvplane(0);
|
vplane = up_fbgetvplane(0);
|
||||||
if (!dev)
|
if (!vplane)
|
||||||
{
|
{
|
||||||
gdbg("ERROR: up_fbgetvplane failed\n");
|
gdbg("ERROR: up_fbgetvplane failed\n");
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Then open NX */
|
return vplane;
|
||||||
|
|
||||||
gvdbg("Open NX\n");
|
|
||||||
g_hnx = nx_open(dev);
|
|
||||||
if (!g_hnx)
|
|
||||||
{
|
|
||||||
gdbg("ERROR: nx_open failed: %d\n", errno);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_NX_MULTIUSER
|
|
||||||
static inline int ov2640_lcd_initialize(void)
|
|
||||||
{
|
|
||||||
struct sched_param param;
|
|
||||||
pthread_t thread;
|
|
||||||
pid_t servrid;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Set the client task priority */
|
|
||||||
|
|
||||||
param.sched_priority = CONFIG_EXAMPLES_NX_CLIENTPRIO;
|
|
||||||
ret = sched_setparam(0, ¶m);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
gdbg("ERROR: sched_setparam failed: %d\n" , ret);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the server task */
|
|
||||||
|
|
||||||
gvdbg("Starting nx_servertask task\n");
|
|
||||||
servrid = task_create("NX Server", CONFIG_EXAMPLES_NX_SERVERPRIO,
|
|
||||||
CONFIG_EXAMPLES_NX_STACKSIZE, nx_servertask, NULL);
|
|
||||||
if (servrid < 0)
|
|
||||||
{
|
|
||||||
gdbg("ERROR: Failed to create nx_servertask task: %d\n", errno);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a bit to let the server get started */
|
|
||||||
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
/* Connect to the server */
|
|
||||||
|
|
||||||
g_hnx = nx_connect();
|
|
||||||
if (g_hnx)
|
|
||||||
{
|
|
||||||
pthread_attr_t attr;
|
|
||||||
|
|
||||||
/* Start a separate thread to listen for server events. This is probably
|
|
||||||
* the least efficient way to do this, but it makes this example flow more
|
|
||||||
* smoothly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
(void)pthread_attr_init(&attr);
|
|
||||||
param.sched_priority = CONFIG_EXAMPLES_NX_LISTENERPRIO;
|
|
||||||
(void)pthread_attr_setschedparam(&attr, ¶m);
|
|
||||||
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NX_STACKSIZE);
|
|
||||||
|
|
||||||
ret = pthread_create(&thread, &attr, nx_listenerthread, NULL);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("pthread_create failed: %d\n", ret);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't return until we are connected to the server */
|
|
||||||
|
|
||||||
while (!g_connected)
|
|
||||||
{
|
|
||||||
/* Wait for the listener thread to wake us up when we really
|
|
||||||
* are connected.
|
|
||||||
*/
|
|
||||||
|
|
||||||
(void)sem_wait(&g_semevent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gdbg("ERROR: nx_connect failed: %d\n", errno);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ov2640_camera_initialize
|
* Name: ov2640_camera_initialize
|
||||||
@ -196,11 +101,33 @@ static inline int ov2640_lcd_initialize(void)
|
|||||||
|
|
||||||
static inline int ov2640_camera_initialize(void)
|
static inline int ov2640_camera_initialize(void)
|
||||||
{
|
{
|
||||||
|
FAR struct i2c_dev_s *i2c;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Get the I2C driver that interfaces with the camers (OV2640_BUS)*/
|
||||||
|
|
||||||
|
i2c = up_i2cinitialize(OV2640_BUS);
|
||||||
|
if (!i2c)
|
||||||
|
{
|
||||||
|
fdbg("ERROR: Failed to initialize TWI%d\n", OV2640_BUS);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Enable clocking to the ISI peripheral */
|
/* Enable clocking to the ISI peripheral */
|
||||||
|
|
||||||
sam_isi_enableclk();
|
sam_isi_enableclk();
|
||||||
|
|
||||||
#warning Missing Logic
|
#warning Missing Logic
|
||||||
|
|
||||||
|
/* Initialize the OV2640 camera */
|
||||||
|
|
||||||
|
ret = ov2640_initialize(i2c);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fdbg("ERROR: Failed to initialize the OV2640: %d\n", ret);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,12 +145,13 @@ static inline int ov2640_camera_initialize(void)
|
|||||||
|
|
||||||
int ov2640_main(int argc, char *argv[])
|
int ov2640_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
FAR struct fb_vtable_s *vplane;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* First, initialize the display */
|
/* First, initialize the display */
|
||||||
|
|
||||||
ret = ov2640_lcd_initialize();
|
vplane = ov2640_lcd_initialize();
|
||||||
if (ret != EXIT_SUCCESS)
|
if (!vplane)
|
||||||
{
|
{
|
||||||
gdbg("ERROR: ov2640_lcd_initialize failed\n");
|
gdbg("ERROR: ov2640_lcd_initialize failed\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -235,24 +163,10 @@ int ov2640_main(int argc, char *argv[])
|
|||||||
if (ret != EXIT_SUCCESS)
|
if (ret != EXIT_SUCCESS)
|
||||||
{
|
{
|
||||||
gdbg("ERROR: ov2640_camera_initialize failed\n");
|
gdbg("ERROR: ov2640_camera_initialize failed\n");
|
||||||
goto errout_with_nx;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
errout_with_nx:
|
|
||||||
#ifdef CONFIG_NX_MULTIUSER
|
|
||||||
/* Disconnect from the server */
|
|
||||||
|
|
||||||
gvdbg("Disconnect from the server\n");
|
|
||||||
nx_disconnect(g_hnx);
|
|
||||||
#else
|
|
||||||
/* Close the server */
|
|
||||||
|
|
||||||
gvdbg("Close NX\n");
|
|
||||||
nx_close(g_hnx);
|
|
||||||
#endif
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_SAMA5_ISI && CONFIG_SAMA5_OV2640_DEMO */
|
#endif /* HAVE_CAMERA */
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
#define HAVE_USBDEV 1
|
#define HAVE_USBDEV 1
|
||||||
#define HAVE_USBMONITOR 1
|
#define HAVE_USBMONITOR 1
|
||||||
#define HAVE_NETWORK 1
|
#define HAVE_NETWORK 1
|
||||||
|
#define HAVE_CAMERA 1
|
||||||
|
|
||||||
/* HSMCI */
|
/* HSMCI */
|
||||||
/* Can't support MMC/SD if the card interface(s) are not enable */
|
/* Can't support MMC/SD if the card interface(s) are not enable */
|
||||||
@ -317,6 +318,24 @@
|
|||||||
# undef HAVE_NETWORK
|
# undef HAVE_NETWORK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Camera */
|
||||||
|
|
||||||
|
#define OV2640_BUS 1
|
||||||
|
|
||||||
|
#ifndef CONFIG_SAMA5_OV2640_DEMO
|
||||||
|
# undef HAVE_CAMERA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_CAMERA) && !defined(CONFIG_SAMA5_ISI)
|
||||||
|
# warning OV2640 camera demo requires CONFIG_SAMA5_ISI
|
||||||
|
# undef HAVE_CAMERA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_CAMERA) && !defined(CONFIG_SAMA5_TWI1)
|
||||||
|
# warning OV2640 camera demo requires CONFIG_SAMA5_TWI1
|
||||||
|
# undef HAVE_CAMERA
|
||||||
|
#endif
|
||||||
|
|
||||||
/* LEDs *****************************************************************************/
|
/* LEDs *****************************************************************************/
|
||||||
/* There are two LEDs on the SAMA5D3 series-CM board that can be controlled
|
/* There are two LEDs on the SAMA5D3 series-CM board that can be controlled
|
||||||
* by software. A blue LED is controlled via PIO pins. A red LED normally
|
* by software. A blue LED is controlled via PIO pins. A red LED normally
|
||||||
|
Loading…
Reference in New Issue
Block a user