CQ Publishing / Mbed 2 deprecated MARMEX_VB_test

Dependencies:   MARMEX_VB NokiaLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
nxpfan
Date:
Fri Jun 06 03:37:02 2014 +0000
Child:
1:dbe2dc31542d
Commit message:
version 0.1

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
MARY_CAMERA.lib Show annotated file Show diff for this revision Revisions of this file
NokiaLCD.lib Show annotated file Show diff for this revision Revisions of this file
bmp_handler.cpp Show annotated file Show diff for this revision Revisions of this file
bmp_handler.h 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MARMEX_OB_oled.h	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,496 @@
+/** MARMEX_OB OLED screen drawing library
+ *
+ *  @class   MARMEX_OB_oled
+ *  @author  tedd
+ *  @version 0.51
+ *  @date    08-Apr-2011
+ *
+ *  Released under the MIT License: http://mbed.org/license/mit
+ *
+ *  MARMEX_OB_oled OLED screen drawing library for mbed
+ *  This code has been written based on sample code and advises
+ *    from Ochiai-san (Marutsu-Elec). Thank you!
+ *
+ *  SPI mode:
+ *    9bit or 8bit SPI mode can be selected by disabling/enabling "#define MARMEX_OB_SPI_8BIT_MODE".
+ *    See source code in this (MARMEX_OB_oled.h) file.
+ */
+
+#ifndef     MBED_MARMEX_OB_OLED
+#define     MBED_MARMEX_OB_OLED
+
+#include    "mbed.h"
+#include    "NokiaLCD.h"
+
+/** @def MARMEX_OB_SPI_8BIT_MODE
+ *
+ *  MARMEX_OB_oled_oled OLED screen SPI access length setting
+ *  Enabling "MARMEX_OB_SPI_8BIT_MODE" makes 9bit SPI access by 8bit * 2 times.
+ *  This may be useful if other 8bit access SPI device on same SPI bus.
+ *
+ *  If disabled (just coment out the "#define MARMEX_OB_SPI_8BIT_MODE"), SPI access willbe done by 9 bit format.
+ */
+#define MARMEX_OB_SPI_8BIT_MODE
+
+/** MARMEX_OB_oled OLED screen drawing class
+ *
+ *  This is a driver code for MARMEX_OB_oled board OLED screen.
+ *  This class inherits NokiaLCD class of mbed.org.
+ *  To use this class, import the NokiaLCD class from here..
+ *   http://mbed.org/users/simon/libraries/NokiaLCD/
+ *
+ *  Example:
+ *  @code
+ * #include "mbed.h"
+ * #include "MARMEX_OB_oled.h"
+ *
+ * //  oled1 is for MARMEX_OB_oled board on MAPLE slot 1
+ * //  oled2 is for MARMEX_OB_oled board on MAPLE slot 2
+ *
+ * //MARMEX_OB_oled   oled1( p5, p7,  p8, p30, p11 ); // mosi, sclk, cs, rst, power_control
+ * MARMEX_OB_oled   oled2( p5, p7, p26, p21, p17 ); // mosi, sclk, cs, rst, power_control
+ *
+ * int main() {
+ *     oled2.background( 0x000000 );
+ *     oled2.cls();
+ *
+ *     for ( int i = 0; i < 8; i++ )
+ *         oled2.fill(  (MARMEX_OB_oled::WIDTH / 8) * i,  0,  (MARMEX_OB_oled::WIDTH / 8),  128, ((i & 0x4) ? 0xFF0000 : 0x000000) | ((i & 0x2) ? 0x00FF00 : 0x000000) |((i & 0x1) ? 0x0000FF : 0x000000) );
+ *
+ *     oled2.fill(  50,  50,  64,  64, 0xCCCCCC );
+ *
+ *     oled2.locate( 0, 3 );
+ *     oled2.printf( "Hello World!" );
+ *     oled2.locate( 0, 4 );
+ *     oled2.printf( "SPI = %s", MERMEX_OB_SPI_MODE_STR );
+ *
+ *     for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ ) {
+ *         oled2.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 );
+ *     }
+ * }
+ *  @endcode
+ */
+
+class MARMEX_OB_oled : public NokiaLCD {
+
+public:
+
+    /** General parameters for MARMEX_OB_oled */
+    enum  {
+        ROWS          = 15,         /**< # of rows (lines) for displaying characters  */
+        COLS          = 16,         /**< # of columns (width) for displaying characters  */
+        WIDTH         = 128,        /**< screen width [pixels]  */
+        HEIGHT        = 128,        /**< screen height [pixels]  */
+        SPI_FREQUENCY = 12000000    /**< SPI (sclk) SPI_FREQUENCY  */
+    };
+
+    /** Constants for power() function */
+    enum  {
+        OFF   = 0,  /**< : to turning-OFF  */
+        ON          /**< : to turning-ON   */
+    };
+
+    /** Create a MARMEX_OB_oled object connected to specified SPI and DigitalOut pins
+     *
+     *  @param mosi SPI-MOSI pin (for MAPLE board, use p5)
+     *  @param sclk SPI-SCLK pin (for MAPLE board, use p8)
+     *  @param cs   chip select signal (for MAPLE board, use p8(slot1), p26(slot2))
+     *  @param rst  reset signal (for MAPLE board, use p30(slot1), p21(slot2))
+     *  @param power_pin backlight power control signal (for MAPLE board, use p11(slot1), p17(slot2))
+     *
+     *  Example of MARMEX_OB_oled on MAPLE board:
+     *  @code
+     *  #include "mbed.h"
+     *  #include "MARMEX_OB_oled.h"
+     *
+     *  MARMEX_OB_oled   oled_on_maple_slot1( p5, p7,  p8, p30, p11 ); // mosi, sclk, cs, rst, power_control
+     *  MARMEX_OB_oled   oled_on_maple_slot2( p5, p7, p26, p21, p17 ); // mosi, sclk, cs, rst, power_control
+     *  ...
+     *  ..
+     *  @endcode
+     */
+
+    MARMEX_OB_oled( PinName mosi, PinName sclk, PinName cs, PinName rst, PinName power_pin ) : NokiaLCD( mosi, sclk, cs, rst, NokiaLCD::LCD6100 ), _power_pin( power_pin ) {
+        power( ON );
+        reset();
+    }
+
+#if DOXYGEN_ONLY
+    /** Write a character to the LCD
+     *
+     * @param c The character to write to the display
+     */
+    int putc( int c );
+
+    /** Write a formated string to the LCD
+     *
+     * @param format A printf-style format string, followed by the
+     *               variables to use in formating the string.
+     *
+     *  !!! 16th character in the string will be disappeared
+     *  !!! This problem is due to difference of screen size NokiaLCD library and its internal mechanism...
+     */
+    int printf( const char* format, ... );
+
+    /** Set the foreground colour
+     *
+     * @param c 24-bit colour
+     */
+    void foreground(int c);
+
+    /** Set the background colour
+     *
+     * @param c 24-bit colour
+     */
+    void background(int c);
+
+#endif
+
+    /** reset MARMEX_OB_oled
+     *
+     *  Executes hardware reset and initialize.
+     *  See MARMEX_OB_oled manual for the initialization sequence and values
+     *  For gamma correction table, using math function to make the code simple
+     */
+
+    void reset( void ) {
+
+#define GAMMA_LUT_SIZE 63
+        unsigned char    gamma_LUT[ GAMMA_LUT_SIZE ];
+
+        for ( int i = 0; i < GAMMA_LUT_SIZE; i++ )
+            gamma_LUT[ i ]  = (unsigned char)(powf( ((float)i / 62.0), (1.0 / 0.58) ) * 178.0 + 2.0);
+
+        // setup the SPI interface and bring display out of reset
+        _cs = 1;
+        _rst = 0;
+#ifdef MARMEX_OB_SPI_8BIT_MODE
+        _spi.format( 8 );
+#else
+        _spi.format( 9 );
+#endif
+
+        _spi.frequency( SPI_FREQUENCY );
+        wait_ms( 1 );
+        _rst = 1;
+        wait_ms( 1 );
+
+        _cs = 0;
+
+        command( SET_DISPLAY_MODE_ALL_OFF );
+        command( SET_COMMAND_LOCK );
+        data( 0x12 );
+
+        command( SET_COMMAND_LOCK );
+        data( 0xb1 );
+
+        command( SET_SLEEP_MODE_ON );
+
+        command( FRONT_CLOCK_DRIVER_OSC_FREQ );
+        data( 0xF1 );
+
+        command( SET_MUX_RATIO );
+        data( 0x7F );
+
+        command( SET_DISPAY_OFFSET );
+        data( 0x00 );
+
+        command( SET_DISPAY_START_LINE );
+        data( 0x00 );
+
+        command( SET_REMAP_COLOR_DEPTH );
+        data( 0x74 );
+
+        command( SET_GPIO );
+        data( 0x00);
+
+        command( FUNCTION_SELECTION );
+        data( 0x01 );
+
+        command( SET_SEGMENT_LOW_VOLTAGE );
+        data( 0xA0 );
+        data( 0xB5 );
+        data( 0x55 );
+
+        command( SET_CONTRAST_CURRENT_FOR_COLOR_ABC );
+        data( 0xC8 );
+        data( 0x80 );
+        data( 0xC8 );
+
+        command( MASTER_CONTRAST_CURRENT_CONTROL );
+        data( 0x0F );
+
+        command( LOOKUP_TABLE_FOR_GRAYSCALE_PULSE_WIDTH );
+        for ( int i = 0; i < GAMMA_LUT_SIZE; i++ )
+            data(  gamma_LUT[ i ] );
+
+        command( SET_RESET_PRECHARGE_PERIOD );
+        data( 0x32 );
+
+        command( ENHANCE_DRIVING_SCHEME_CAPABILITY );
+        data( 0x04 );
+        data( 0x00 );
+        data( 0x00 );
+
+        command( SET_PRECHARGE_VOLTAGE );
+        data( 0x17 );
+
+        command( SET_SECOND_PRECHARGE_VOLTAGE );
+        data( 0x01 );
+
+        command( SET_VCOMH_VOLTAGE );
+        data( 0x05 );
+
+        command( SET_DISPLAY_MODE_RESET );
+
+#if 0
+        command( SET_COLUMN_ADDRESS );
+        data( 0x00 );
+        data( 0x7F );
+
+        command( SET_ROW_ADDRESS );
+        data( 0x00 );
+        data( 0x7F);
+
+        command( WRITE_RAM_COMMAND );
+        for ( int i = 0; i < WIDTH * HEIGHT; i++ )
+            data( 0x00 );
+#endif
+        _cs = 1;
+
+        cls();
+        wait_ms( 200 );
+
+        command( SET_SLEEP_MODE_OFF );
+    }
+
+    /** Clear the screen and locate to 0,0 */
+
+    void cls( void ) {
+        fill( 0, 0, WIDTH , HEIGHT, _background );
+        _row = 0;
+        _column = 0;
+    }
+
+    /** Set a pixel on te screen
+     *
+     * @param x horizontal position from left
+     * @param y vertical position from top
+     * @param colour 24-bit colour in format 0x00RRGGBB
+     */
+
+    virtual void pixel( int x, int y, int colour ) {
+        _cs = 0;
+        _window( x, y, 1, 1 );
+        _putp( colour );
+        _cs = 1;
+    }
+
+    /** Fill an area of the screen
+     *
+     * @param x horizontal position from left
+     * @param y vertical position from top
+     * @param width width in pixels
+     * @param height height in pixels
+     * @param colour 24-bit colour in format 0x00RRGGBB
+     */
+
+    void fill( int x, int y, int width, int height, int colour ) {
+        _cs = 0;
+        _window( x, y, width, height );
+
+        for (int i = 0; i < width * height; i++ ) {
+            _putp( colour );
+        }
+
+        _window( 0, 0, WIDTH, HEIGHT );
+        _cs = 1;
+    }
+
+    void blit( int x, int y, int width, int height, const int* colour ) {
+        _cs = 0;
+        _window( x, y, width, height );
+
+        for (int i = 0; i < width * height; i++ ) {
+            _putp( colour[i] );
+        }
+        _window( 0, 0, WIDTH, HEIGHT );
+        _cs = 1;
+    }
+
+    void blit565( int x, int y, int width, int height, const short* colour ) {
+        _cs = 0;
+        _window( x, y, width, height );
+
+        for (int i = 0; i < width * height; i++ ) {
+            _putp565( colour[i] );
+        }
+        _window( 0, 0, WIDTH, HEIGHT );
+        _cs = 1;
+    }
+    void bitblit( int x, int y, int width, int height, const char* bitstream ) {
+        _cs = 0;
+        _window( x, y, width, height );
+
+        for (int i = 0; i < height * width; i++ ) {
+            int byte = i / 8;
+            int bit = i % 8;
+            int colour = ((bitstream[ byte ] << bit) & 0x80) ? _foreground : _background;
+            _putp( colour );
+        }
+        _window( 0, 0, _width, _height );
+        _cs = 1;
+    }
+
+    /** Screen width
+     *
+     *  @return screen width [pixel]
+     */
+    int width() {
+        return WIDTH;
+    }
+
+    /** Screen height
+     *
+     *  @return screen height [pixel]
+     */
+    int height() {
+        return HEIGHT;
+    }
+    /** Columns
+     *
+     *  @return screen columns
+     */
+    int columns() {
+        return COLS;
+    }
+
+    /** Rows
+     *
+     *  @return screen rows
+     */
+    int rows() {
+        return ROWS;
+    }
+
+    /** Power switch for OLED backlight
+     *
+     * @param sw argument can be MARMEX_OB_oled::ON or MARMEX_OB_oled::OFF
+     */
+
+    void power( unsigned char sw ) {
+        _power_pin  = sw;
+    }
+
+private:
+    /** Command list for the OLED controller */
+    enum {
+        SET_DISPLAY_MODE_ALL_OFF                = 0xA4,
+        SET_COMMAND_LOCK                        = 0xFD,
+        SET_SLEEP_MODE_ON                       = 0xAE,
+        FRONT_CLOCK_DRIVER_OSC_FREQ             = 0xB3,
+        SET_MUX_RATIO                           = 0xCA,
+        SET_DISPAY_OFFSET                       = 0xA2,
+        SET_DISPAY_START_LINE                   = 0xA1,
+        SET_REMAP_COLOR_DEPTH                   = 0xA0,
+        SET_GPIO                                = 0xB5,
+        FUNCTION_SELECTION                      = 0xAB,
+        SET_SEGMENT_LOW_VOLTAGE                 = 0xB4,
+        SET_CONTRAST_CURRENT_FOR_COLOR_ABC      = 0xC1,
+        MASTER_CONTRAST_CURRENT_CONTROL         = 0xC7,
+        LOOKUP_TABLE_FOR_GRAYSCALE_PULSE_WIDTH  = 0xB8,
+        SET_RESET_PRECHARGE_PERIOD              = 0xB1,
+        ENHANCE_DRIVING_SCHEME_CAPABILITY       = 0xB2,
+        SET_PRECHARGE_VOLTAGE                   = 0xBB,
+        SET_SECOND_PRECHARGE_VOLTAGE            = 0xB6,
+        SET_VCOMH_VOLTAGE                       = 0xBE,
+        SET_DISPLAY_MODE_RESET                  = 0xA6,
+        SET_COLUMN_ADDRESS                      = 0x15,
+        SET_ROW_ADDRESS                         = 0x75,
+        WRITE_RAM_COMMAND                       = 0x5C,
+        SET_SLEEP_MODE_OFF                      = 0xAF
+    };
+
+#ifdef MARMEX_OB_SPI_8BIT_MODE
+    void command( int value ) {
+        int tmp = value & 0x00ff;
+        _cs = 0;
+        _spi.write( tmp >> 1 );
+        _spi.write( tmp << 7 );
+        _cs = 1;
+    }
+
+    void data( int value ) {
+        int tmp  = value & 0x00ff;
+        tmp |= 0x0100;
+        _cs = 0;
+        _spi.write( tmp >> 1 );
+        _spi.write( tmp << 7 );
+        _cs = 1;
+    }
+#else
+    void command( int value ) {
+        _cs = 0;
+        _spi.write( value & 0xFF );
+        _cs = 1;
+    }
+
+    void data(int value) {
+        _cs = 0;
+        _spi.write( value | 0x100 );
+        _cs = 1;
+    }
+#endif
+
+    virtual void _window( int x, int y, int width, int height ) {
+        int x1 = x + 0;
+        int y1 = y + 0;
+        int x2 = x1 + width - 1;
+        int y2 = y1 + height - 1;
+
+        command( SET_COLUMN_ADDRESS );
+        data( x1 );
+        data( x2 );
+        command( SET_ROW_ADDRESS );
+        data( y1 );
+        data( y2 );
+        command( WRITE_RAM_COMMAND );
+    }
+
+    void window( int x, int y, int width, int height ) {
+        _cs = 0;
+        _window( x, y, width, height );
+        _cs = 1;
+    }
+
+    virtual void _putp( int colour ) {
+        int cnv = 0;
+
+        cnv  = (colour >> 8) & 0xf800;
+        cnv |= (colour >> 5) & 0x07e0;
+        cnv |= (colour >> 3) & 0x001f;
+
+        data( cnv >> 8);
+        data( cnv );
+    }
+    virtual void _putp565( short colour ) {
+        data( colour >> 8);
+        data( colour );
+    }
+
+    DigitalOut     _power_pin;
+}
+;
+
+#ifdef  MARMEX_OB_SPI_8BIT_MODE
+#define MERMEX_OB_SPI_MODE_STR  "8bit mode"
+#else
+#define MERMEX_OB_SPI_MODE_STR  "9bit mode"
+#endif
+#endif  //  MBED_MARMEX_OB_OLED
+
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MARMEX_VB.lib	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,1 @@
+MARMEX_VB#c4d14dd5d479
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MARY_CAMERA.lib	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/okano/code/MARY_CAMERA/#7599da3895e1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NokiaLCD.lib	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/NokiaLCD/#2d1b23692cbb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bmp_handler.cpp	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,168 @@
+#include "mbed.h"                   //  for mbed
+#include "MARMEX_VB.h"
+#include "bmp_handler.h"
+
+#if defined( TARGET_MBED_LPC1768 ) || defined( TARGET_LPC11U24_401 )
+LocalFileSystem     local("local"); //  for mbed to access local file system
+#endif
+
+#ifdef  RGB565_FORMAT
+char bhp[]   = {
+    0x42, 0x4d, 0x8a, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
+    0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
+    0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x1f, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+#else
+#if 0
+char bhp[]   = {
+    0x42, 0x4d, 0x8a, 0x8c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
+    0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x03, 0x00,
+    0x00, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+#else
+typedef struct  bmp_header_st    {
+    unsigned short  bfType            __attribute__((packed));
+    unsigned long   bfSize            __attribute__((packed));
+    unsigned short  bfReserved1       __attribute__((packed));
+    unsigned short  bfReserved2       __attribute__((packed));
+    unsigned long   bfOffBits         __attribute__((packed));
+
+    unsigned long   biSize            __attribute__((packed));
+    long            biWidth           __attribute__((packed));
+    long            biHeight          __attribute__((packed));
+    unsigned short  biPlanes          __attribute__((packed));
+    unsigned short  biBitCount        __attribute__((packed));
+    unsigned long   biCompression     __attribute__((packed));
+    unsigned long   biSizeImage       __attribute__((packed));
+    long            biXPixPerMeter    __attribute__((packed));
+    long            biYPixPerMeter    __attribute__((packed));
+    unsigned long   biClrUsed         __attribute__((packed));
+    unsigned long   biCirImportant    __attribute__((packed));
+}
+bmp_header;
+#endif
+#endif
+
+
+FILE    *fp;
+
+int open_BMP( char *file_name, int get_horizontal_size, int get_vertical_size )
+{
+    bmp_header  bh  =   {
+        0x4D42,
+        get_horizontal_size * get_vertical_size * 4 + 54,
+        0,
+        0,
+        54,
+        40,
+        get_horizontal_size,
+        get_vertical_size,
+        1,
+        32,
+        0,
+        get_horizontal_size * get_vertical_size * 4,
+        2835,
+        2835,
+        0,
+        0
+    };
+    char    s[ 80 ];
+
+    sprintf( s, "/local/%s", file_name );
+
+    if ( NULL == (fp    = fopen( s, "wb" )) )
+        return 1;
+
+    fwrite( &bh, sizeof( bh ), 1, fp );
+//    fwrite( bhp, sizeof( bhp ), 1, fp );
+
+    return 0;
+}
+
+void write_BMP( short *p, int length )
+{
+#ifdef  RGB565_FORMAT
+    fwrite( p, sizeof( short ), length, fp );
+#else
+    unsigned long   v[ length ];
+    unsigned long   tmp;
+
+    for ( int i = 0; i < length; i++ ) {
+        tmp     = p[ i ];
+        //tmp     = 0xF800;
+        v[ i ]  = (tmp & 0x001F) << 3;
+        v[ i ] |= (tmp & 0x07E0) << 5;
+        v[ i ] |= (tmp & 0xF800) << 8;
+    }
+
+    fwrite( v, sizeof( unsigned long ), length, fp );
+#endif
+}
+
+void write_BMP( short *p, int length, char mask )
+{
+    unsigned long   v[ length ];
+    unsigned long   tmp;
+
+    for ( int i = 0; i < length; i++ ) {
+        tmp     = p[ i ];
+        //tmp     = 0xF800;
+        v[ i ]  = (mask & 0x4) ? (tmp & 0x001F) << 3 : 0;
+        v[ i ] |= (mask & 0x2) ? (tmp & 0x07E0) << 5 : 0;
+        v[ i ] |= (mask & 0x1) ? (tmp & 0xF800) << 8 : 0;
+    }
+
+    fwrite( v, sizeof( unsigned long ), length, fp );
+}
+
+void close_BMP( void )
+{
+    fclose( fp );
+}
+
+
+char *read_alpha_BMP( char *file_name, alpha_param *azp )
+{
+    bmp_header  bh;
+    char        s[ 80 ];
+    int         data_size;
+
+    sprintf( s, "/local/%s", file_name );
+
+    if ( NULL == (fp    = fopen( s, "rb" )) ) {
+        azp->buffer = NULL;
+        return NULL;
+    }
+
+    fread( &bh, sizeof( bh ), 1, fp );
+    azp->h    = bh.biWidth;
+    azp->v    = bh.biHeight;
+    azp->byte_per_pixel = bh.biBitCount / 8;
+
+    data_size   = sizeof( char ) * azp->h * azp->v * azp->byte_per_pixel;
+
+    fseek( fp, bh.bfOffBits - sizeof( bh ), SEEK_CUR );
+
+    if ( NULL == ( azp->buffer = (char *)malloc( data_size ) ) ) {
+        fclose( fp );
+        return ( NULL );
+    }
+
+    fread( azp->buffer, data_size, 1, fp );
+    fclose( fp );
+
+    printf( "alpha image loaded. (from \"%s\", size = %d/%d, %d bytes/pixel)\r\n", s, azp->h, azp->v, azp->byte_per_pixel );
+
+    return azp->buffer;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bmp_handler.h	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,22 @@
+
+
+#ifndef MBED_BMP_HANDLING__
+#define MBED_BMP_HANDLING__
+
+typedef struct  alpha_param_st    {
+    int     h;
+    int     v;
+    int     byte_per_pixel;
+    char    *buffer;
+}
+alpha_param;
+
+int     open_BMP( char *file_name, int horizontal_size, int vertical_size );
+void    write_BMP( short *p, int length );
+void    write_BMP( short *p, int length, char mask );
+void    close_BMP( void );
+
+char *read_alpha_BMP( char *file_name, alpha_param *azp );
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,349 @@
+/** Test program for MARMEX_VB Camera control library
+ *
+ *  @version 0.1
+ *  @date    10-Jun-2014
+ *
+ *  Released under the Apache License, Version 2.0 : http://mbed.org/handbook/Apache-Licence
+ *
+ *  Test program for MARMEX_VB Camera control library
+ *
+ *      ** This program runs on mbed_NXP_LPC1768 only **
+ */
+
+
+#include    "mbed.h"
+#include    "MARMEX_OB_oled.h"
+#include    "MARMEX_VB.h"
+#include    "bmp_handler.h"
+
+MARMEX_OB_oled  oled1( p5, p7,  p20, p16, p15 );
+// mosi, sclk, cs, rst, power_control               -- maple-mini-type-b-board-slot1
+
+MARMEX_VB       camera( p5, p6, p7, p22, p26, p28, p27 );
+// mosi, miso, sclk, cs, reset, sda, scl    -- maple-mini-type-b-board-slot2
+
+BusOut          led( LED4, LED3, LED2, LED1 );
+Timer           timer;
+
+void test_camera( void );
+void test_camera_resolution_change( void );
+
+void copy_image_from_camera_to_oled( void );
+void copy_image_from_camera_to_oled_interlaced( void );
+void line_mirroring( short *buf );
+void save_still_image( char *file_name );
+void oled_test_screen( void );
+void capture_to_bmp( void );
+
+//#define     SAVE_EACH_SIZES_OF_STILL_IMAGE
+
+alpha_param ap;
+
+
+int main()
+{
+    printf( "\r\n\r\nMARY-CAMERA test program\r\n\r\n" );
+
+    read_alpha_BMP( "alpha.bmp", &ap );
+
+
+    led    = 0x3;
+
+    oled1.cls();
+    oled_test_screen();
+
+#ifdef  SAVE_EACH_SIZES_OF_STILL_IMAGE
+    led    = 0x1;
+    camera.resolution( MARMEX_VB::QCIF );
+    save_still_image( "i_qcif.bmp" );
+
+    led    = 0x2;
+    camera.resolution( MARMEX_VB::QQVGA );
+    save_still_image( "i_qqvga.bmp" );
+
+    led    = 0x4;
+    camera.resolution( MARMEX_VB::QVGA );
+    save_still_image( "i_qvga.bmp" );
+
+    led    = 0x8;
+    camera.resolution( MARMEX_VB::VGA );
+    save_still_image( "i_vga.bmp" );
+
+    camera.resolution( MARMEX_VB::QCIF );
+#endif
+
+    printf( "  camera operation started\r\n" );
+    printf( "    hit key [c] for saving data into BMP (for blue-mbed only)\r\n" );
+    printf( "    hit key [o] to change data reading order\r\n" );
+    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" );
+
+    timer.start();  //  timer for measureing frame rate
+    test_camera();  //  this function doesn't return
+}
+
+#if defined( TARGET_MBED_LPC1768 ) || defined( TARGET_LPC11U24_401 )
+Serial      pc(USBTX, USBRX);    // tx, rx
+#endif
+
+
+void test_camera( void )
+{
+    int     interlace   = 0;
+    int     frame_count = 0;
+
+    while ( 1 ) {
+        if ( pc.readable() ) {
+            switch ( pc.getc() ) {
+                case 'c' :
+                    capture_to_bmp();
+                    printf( "  [c] : capture started\r\n" );
+                    break;
+                case 'o' :
+                    printf( "  [o] read order change : %s\r\n", camera.read_order_change() ? "ENABLED" : "DISABLED" );
+                    break;
+                case 'i' :
+                    interlace   = !interlace;
+                    printf( "  [i] : interlace setting : %s\r\n", interlace ? "ENABLED" : "DISABLED" );
+                    /*  FALL THROUGH  */
+                case 'f' :
+                    if ( frame_count ) {
+                        timer.stop();
+                        float   t   = timer.read();
+                        printf( "  [f] : %s rate : %5.3f\r\n", interlace ? "field" : "frame", (float)frame_count / t );
+                        frame_count = 0;
+                        timer.reset();
+                        timer.start();
+                    } else {
+                        printf( "  [f] : no frame drawn yet. try again later\r\n" );
+                    }
+                    break;
+                case '1' :
+                    printf( "  [1] resolution change : QCIF\r\n" );
+                    camera.init( MARMEX_VB::QCIF );
+                    break;
+                case '2' :
+                    printf( "  [2] resolution change : QQVGA\r\n" );
+                    camera.init( MARMEX_VB::QQVGA );
+                    break;
+                case '3' :
+                    printf( "  [3] resolution change : QVGA\r\n" );
+                    camera.init( MARMEX_VB::QVGA );
+                    break;
+                case '4' :
+                    printf( "  [4] resolution change : VGA\r\n" );
+                    camera.init( MARMEX_VB::VGA );
+                    break;
+            }
+        }
+
+        led    = 0x1;
+
+        if ( interlace )
+            copy_image_from_camera_to_oled_interlaced();
+        else
+            copy_image_from_camera_to_oled();
+
+
+//        camera.colorbar( ((count++ >> 2) & 0x1) ? MARMEX_VB::ON : MARMEX_VB::OFF );
+
+        led    = 0x2;
+
+        frame_count++;
+    }
+}
+
+
+void test_camera_resolution_change( void )
+{
+    int     count   = (3 << 3);
+    int     setting;
+
+    while ( 1 ) {
+
+        if ( !(count & 0x7) ) {
+            setting     = (count >> 3) & 0x3;
+            camera.init( (MARMEX_VB::CameraResolution)(setting + 1) );
+            led    = 0x1 << setting;
+        }
+
+        count++;
+
+        copy_image_from_camera_to_oled();
+    }
+}
+
+
+void alpha( int line_num, short *bf, int offset_x, int offset_y, alpha_param *app )
+{
+    short   r, g, b;
+    int     y_pos;
+
+    if ( (line_num < offset_y) || (offset_y + app->v) <= line_num || (app->buffer == NULL) )
+        return;
+
+    bf     += offset_x;
+    y_pos   = ((app->v - (line_num - offset_y + 1)) * (app->h * app->byte_per_pixel));
+
+    for ( int i = 0; i < 60; i++ ) {
+        r   = ((*bf >>  1) & 0x0F) + (*(app->buffer + i * 3 + 0 + y_pos ) >> 4);
+        g   = ((*bf >>  6) & 0x1F) + (*(app->buffer + i * 3 + 1 + y_pos ) >> 3);
+        b   = ((*bf >> 12) & 0x0F) + (*(app->buffer + i * 3 + 2 + y_pos ) >> 4);
+
+        *bf++ = (b << 11) | (g << 5) | (r << 0);
+    }
+}
+
+
+void copy_image_from_camera_to_oled( void )
+{
+    short   buf[ MARMEX_OB_oled::WIDTH ];
+    static int  count   = 0;
+
+    camera.open_transfer();
+
+    for ( int line = 0; 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 );
+        oled1.blit565( 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; 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;
+
+    for ( int i = 0; i < (MARMEX_OB_oled::WIDTH / 2); i++ ) {
+        tmp         = buf[ i ];
+        buf[ i ]    = buf[ (MARMEX_OB_oled::WIDTH - 1) - i ];
+        buf[ (MARMEX_OB_oled::WIDTH - 1) - i ]  = tmp;
+    }
+}
+
+
+void oled_test_screen( void )
+{
+    oled1.background( 0x000000 );
+    oled1.cls();
+
+    int colorbar_width  = MARMEX_OB_oled::WIDTH / 8;
+
+    for ( int i = 0; i < 8; i++ )
+        oled1.fill( colorbar_width * i, 0, colorbar_width, MARMEX_OB_oled::HEIGHT, ((i & 0x4) ? 0xFF0000 : 0x000000) | ((i & 0x2) ? 0x00FF00 : 0x000000) | ((i & 0x1) ? 0x0000FF : 0x000000) );
+
+    oled1.fill(  50,  50,  64,  64, 0xCCCCCC );;
+
+    oled1.locate( 0, 2 );
+    oled1.printf( "MaryCemara test" );
+    oled1.locate( 0, 3 );
+    oled1.printf( "%s", (MARMEX_VB::NO_ERROR == camera.ready()) ? "Camera is ready" : "No Camera found" );
+    oled1.locate( 0, 4 );
+    oled1.printf( "%s", "saving into BMP" );
+    oled1.locate( 0, 5 );
+    oled1.printf( "%d", camera.get_horizontal_size() );
+    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 );
+}
+
+
+#include    "bmp_handler.h"
+
+void save_still_image( char *file_name )
+{
+    short   buf[ camera.get_horizontal_size() ];
+
+    if ( open_BMP( file_name, camera.get_horizontal_size(), camera.get_vertical_size() ) )
+        return;
+
+    camera.open_transfer();
+
+    for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line--  ) {
+        camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
+        write_BMP( buf, camera.get_horizontal_size() );
+    }
+    camera.close_transfer();
+
+    close_BMP();
+}
+
+void capture_to_bmp( void )
+{
+    short   buf[ camera.get_horizontal_size() ];
+    camera.open_transfer();
+
+    if ( open_BMP( "RGB.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
+        return;
+
+    for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line--  ) {
+        camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
+//        write_BMP( buf, camera.get_horizontal_size(), 0x7 );
+        write_BMP( buf, camera.get_horizontal_size() );
+    }
+
+    close_BMP();
+
+#if 0
+
+    if ( open_BMP( "R.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
+        return;
+
+    for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line--  ) {
+        camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
+        write_BMP( buf, camera.get_horizontal_size(), 0x4 );
+    }
+
+    close_BMP();
+
+
+    if ( open_BMP( "G.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
+        return;
+
+    for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line--  ) {
+        camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
+        write_BMP( buf, camera.get_horizontal_size(), 0x2 );
+    }
+
+    close_BMP();
+
+
+    if ( open_BMP( "B.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
+        return;
+
+    for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line--  ) {
+        camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
+        write_BMP( buf, camera.get_horizontal_size(), 0x1 );
+    }
+
+    close_BMP();
+
+#endif
+    camera.close_transfer();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 06 03:37:02 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43
\ No newline at end of file