MARMEX_VB test application program. This application works on "mbed NXP LPC1768" only. This application expects to have the MARMEX_VB module on a "MAPLE mini type-B (MARM03-BASE)" baseboard (slot2) with MARMEX_OB module (on slot1)

Dependencies:   MARMEX_VB NokiaLCD mbed

This is the library test program.
The program can test features of the library (refer to MARMEX-VB's API document) and can save captured data into BMP file.

Warning!

This test program can run on "mbed NXP LPC1768" only.

/media/uploads/nxpfan/dsc_0506_-1-.jpg
Picture : sample of test program operation
The modules of MARMEX-VB and MARMEX-OB are set on the "MAPLE mini type-B (MARM03-BASE)" baseboard.
The image data from camera is mirrored and alpha graphics added by software.

Files at this revision

API Documentation at this revision

Comitter:
nxpfan
Date:
Thu Jun 19 12:21:50 2014 +0000
Parent:
6:b61b876d50a8
Child:
8:86aae677a68b
Commit message:
optimized SPI : FIFO

Changed in this revision

MARMEX_OB_oled.h Show annotated file Show diff for this revision Revisions of this file
MARMEX_VB.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/MARMEX_OB_oled.h	Wed Jun 18 06:44:44 2014 +0000
+++ b/MARMEX_OB_oled.h	Thu Jun 19 12:21:50 2014 +0000
@@ -2,8 +2,8 @@
  *
  *  @class   MARMEX_OB_oled
  *  @author  tedd
- *  @version 0.53 (optimized for "line data transfer")
- *  @date    16-Jun-2014
+ *  @version 0.54 (optimized for "line data transfer")
+ *  @date    19-Jun-2014
  *
  *  Released under the MIT License: http://mbed.org/license/mit
  *
@@ -352,7 +352,7 @@
             _spi.write( 0x100 | (*colour >> 8) );
             _spi.write( 0x100 | *colour++ );
         }
-        
+
         _cs = 0;
 
 #else
@@ -361,9 +361,64 @@
         }
 #endif
 
-        _window( 0, 0, WIDTH, HEIGHT );
         _cs = 1;
+        _window( 0, 0, WIDTH, HEIGHT );
     }
+
+
+
+
+    void blit565_SPI_FIFO_WRITE( int x, int y, int width, int height, short* colour ) {
+        _window( x, y, width, height );
+
+#define FIFO_DEPTH  4
+
+#ifdef  TARGET_MBED_LPC1768
+#define SPI_PORT_SELECTOR   LPC_SSP1
+#endif
+
+#ifdef  TARGET_LPC11U35_501
+#define SPI_PORT_SELECTOR   LPC_SSP0
+#endif
+
+#ifdef  TARGET_LPC11U24_401
+#define SPI_PORT_SELECTOR   LPC_SSP0
+#endif
+
+        char                dummy;
+        int                 n;
+        int                 length;
+
+        length      = width * height;
+
+        _cs = 0;
+
+        for(n = (FIFO_DEPTH >> 1); n > 0; n--) {
+            SPI_PORT_SELECTOR->DR = (*colour >> 8) | 0x100;
+            SPI_PORT_SELECTOR->DR = ((*colour++) & 0xFF) | 0x100;
+        }
+
+        do {
+            while (!(SPI_PORT_SELECTOR->SR & 0x4));
+            dummy   = SPI_PORT_SELECTOR->DR;
+
+            if (n < length - (FIFO_DEPTH >> 1))
+                SPI_PORT_SELECTOR->DR = (*colour >> 8) | 0x100;
+
+            while (!(SPI_PORT_SELECTOR->SR & 0x4));
+            dummy   = SPI_PORT_SELECTOR->DR;
+
+            if (n++ < length - (FIFO_DEPTH >> 1))
+                SPI_PORT_SELECTOR->DR = ((*colour++) & 0xFF) | 0x100;
+
+
+        } while(n < length);
+
+        _cs = 1;
+        _window( 0, 0, WIDTH, HEIGHT );
+    }
+
+
     void bitblit( int x, int y, int width, int height, const char* bitstream ) {
         _cs = 0;
         _window( x, y, width, height );
--- a/MARMEX_VB.lib	Wed Jun 18 06:44:44 2014 +0000
+++ b/MARMEX_VB.lib	Thu Jun 19 12:21:50 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/CQ-Publishing/code/MARMEX_VB/#7f26004cfbce
+http://mbed.org/teams/CQ-Publishing/code/MARMEX_VB/#8ef31b67c0ab
--- a/main.cpp	Wed Jun 18 06:44:44 2014 +0000
+++ b/main.cpp	Thu Jun 19 12:21:50 2014 +0000
@@ -1,7 +1,7 @@
 /** Test program for MARMEX_VB Camera control library
  *
- *  @version 0.2
- *  @date    10-Jun-2014
+ *  @version 0.3
+ *  @date    19-Jun-2014
  *
  *  Released under the Apache License, Version 2.0 : http://mbed.org/handbook/Apache-Licence
  *
@@ -36,6 +36,8 @@
 
 BusOut          led( LED4, LED3, LED2, LED1 );
 Timer           timer;
+Timer           looptimer;
+
 
 void test_camera( void );
 void test_camera_resolution_change( void );
@@ -64,6 +66,7 @@
 
     oled1.cls();
     oled_test_screen();
+    oled1.cls();
 
 #ifdef  SAVE_EACH_SIZES_OF_STILL_IMAGE
     led    = 0x1;
@@ -91,21 +94,29 @@
     printf( "    hit key [i] to toggle interlace mode\r\n" );
     printf( "    hit key [1], [2], [3] or [4] to change resolution QCIF, QQVGA, QVGA, VGA\r\n" );
 
+    looptimer.start();
+
     timer.start();  //  timer for measureing frame rate
     test_camera();  //  this function doesn't return
 }
 
-#if defined( TARGET_MBED_LPC1768 ) || defined( TARGET_LPC11U24_401 )
+#if defined( TARGET_MBED_LPC1768 )
 Serial      pc(USBTX, USBRX);    // tx, rx
 #endif
 
+int     disp  = 1;
+
 
 void test_camera( void )
 {
-    int     interlace   = 0;
-    int     frame_count = 0;
+    int     interlace           = 1;
+    int     frame_count         = 0;
+
+    float   t;
 
     while ( 1 ) {
+
+#ifdef TARGET_MBED_LPC1768
         if ( pc.readable() ) {
             switch ( pc.getc() ) {
                 case 'c' :
@@ -122,7 +133,7 @@
                 case 'f' :
                     if ( frame_count ) {
                         timer.stop();
-                        float   t   = timer.read();
+                        t   = timer.read();
                         printf( "  [f] : %s rate : %5.3f\r\n", interlace ? "field" : "frame", (float)frame_count / t );
                         frame_count = 0;
                         timer.reset();
@@ -149,6 +160,7 @@
                     break;
             }
         }
+#endif
 
         led    = 0x1;
 
@@ -159,6 +171,11 @@
 
 //        camera.colorbar( ((count++ >> 2) & 0x1) ? MARMEX_VB::ON : MARMEX_VB::OFF );
 
+        t   = looptimer.read();
+        looptimer.reset();
+        oled1.locate( 0, 0 );
+        oled1.printf( " %.2f %s/s", 1.0 / t, interlace ? "field" : "frame" );
+
         led    = 0x2;
 
         frame_count++;
@@ -207,6 +224,10 @@
 }
 
 
+#define OPTIMIZATION_ENABLED
+#define SCREEN_TOP  9
+
+#ifdef  OPTIMIZATION_ENABLED
 void copy_image_from_camera_to_oled( void )
 {
     short   buf[ MARMEX_OB_oled::WIDTH ];   //  array size should be multiple of 8 for "mbed LPC1768" optimization
@@ -214,10 +235,47 @@
 
     camera.open_transfer();
 
-    for ( int line = 0; line < MARMEX_OB_oled::HEIGHT; line++  ) {
+    for ( int line = SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line++  ) {
+        camera.read_a_line_SPI_FIFO_READ( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
+        line_mirroring( buf );
+        alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
+        oled1.blit565_SPI_FIFO_WRITE( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
+    }
+
+    count++;
+    camera.close_transfer();
+}
+
+
+void copy_image_from_camera_to_oled_interlaced( void )
+{
+    short       buf[ MARMEX_OB_oled::WIDTH ];
+    static int  count   = 0;
+
+    camera.open_transfer();
+
+    for ( int line = ((count++) & 1) + SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line += 2 ) {
+        camera.read_a_line_SPI_FIFO_READ( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
+        line_mirroring( buf );
+        alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
+        oled1.blit565_SPI_FIFO_WRITE( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
+    }
+
+    camera.close_transfer();
+}
+
+#else
+void copy_image_from_camera_to_oled( void )
+{
+    short   buf[ MARMEX_OB_oled::WIDTH ];   //  array size should be multiple of 8 for "mbed LPC1768" optimization
+    static int  count   = 0;
+
+    camera.open_transfer();
+
+    for ( int line = SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line++  ) {
         camera.read_a_line( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
         line_mirroring( buf );
-        alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4, &ap );
+        alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
         oled1.blit565( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
     }
 
@@ -226,6 +284,24 @@
 }
 
 
+void copy_image_from_camera_to_oled_interlaced( void )
+{
+    short       buf[ MARMEX_OB_oled::WIDTH ];
+    static int  count   = 0;
+
+    camera.open_transfer();
+
+    for ( int line = ((count++) & 1) + SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line += 2 ) {
+        camera.read_a_line( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
+        line_mirroring( buf );
+        alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
+        oled1.blit565( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
+    }
+
+    camera.close_transfer();
+}
+#endif
+
 void copy_image_from_camera_to_oled_small( void )
 {
     short   buf[ 64 ];
@@ -243,25 +319,6 @@
 }
 
 
-void copy_image_from_camera_to_oled_interlaced( void )
-{
-    short       buf[ MARMEX_OB_oled::WIDTH ];
-    static int  count   = 0;
-
-    camera.open_transfer();
-
-    for ( int line = (count++) & 1; line < MARMEX_OB_oled::HEIGHT; line += 2 ) {
-        camera.read_a_line( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
-        line_mirroring( buf );
-        alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4, &ap );
-        oled1.blit565( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
-    }
-
-    camera.close_transfer();
-}
-
-
-
 void line_mirroring( short *buf )
 {
     short   tmp;
@@ -297,7 +354,6 @@
     oled1.locate( 0, 6 );
     oled1.printf( "%d", camera.get_vertical_size() );
 
-
     for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ )
         oled1.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 );
 }
--- a/mbed.bld	Wed Jun 18 06:44:44 2014 +0000
+++ b/mbed.bld	Thu Jun 19 12:21:50 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file