Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Committer:
okano
Date:
Thu Feb 13 01:22:36 2014 +0000
Revision:
0:1062142e5718
Child:
1:ce27bc7b44d4
not working correctly

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:1062142e5718 1 /** A sample app of MARMEX_OB OLED screen drawing library
okano 0:1062142e5718 2 *
okano 0:1062142e5718 3 * @author Tedd
okano 0:1062142e5718 4 * @version 0.5
okano 0:1062142e5718 5 * @date 07-Apr-2011
okano 0:1062142e5718 6 *
okano 0:1062142e5718 7 * Released under the MIT License: http://mbed.org/license/mit
okano 0:1062142e5718 8 *
okano 0:1062142e5718 9 * MARMEX_OB_oled OLED screen drawing library for mbed
okano 0:1062142e5718 10 * This code has been written based on sample code and advises
okano 0:1062142e5718 11 * from Ochiai-san (Marutsu-Elec). Thank you!
okano 0:1062142e5718 12 *
okano 0:1062142e5718 13 * To build this code, "NokiaLCD" and "mbed" libraries are needed to be imported in a project.
okano 0:1062142e5718 14 * NokiaLCD library : http://mbed.org/users/simon/libraries/NokiaLCD/
okano 0:1062142e5718 15 */
okano 0:1062142e5718 16
okano 0:1062142e5718 17
okano 0:1062142e5718 18 #include "mbed.h"
okano 0:1062142e5718 19 #include "MARMEX_OB_oled.h"
okano 0:1062142e5718 20
okano 0:1062142e5718 21
okano 0:1062142e5718 22 #define PARAM_NUM 99
okano 0:1062142e5718 23 #define CAM_I2C_ADDR 0x42
okano 0:1062142e5718 24
okano 0:1062142e5718 25 const char param[2][PARAM_NUM] = {
okano 0:1062142e5718 26 {
okano 0:1062142e5718 27 0x01,0x02,0x03,0x0c,0x0e,0x0f,0x11,0x12,0x15,0x16,0x17,0x18,0x19,0x1a,0x1e,0x21,0x22,
okano 0:1062142e5718 28 0x29,0x32,0x33,0x34,0x35,0x37,0x38,0x39,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x41,
okano 0:1062142e5718 29 0x43,0x44,0x45,0x46,0x47,0x48,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,
okano 0:1062142e5718 30 0x54,0x56,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,
okano 0:1062142e5718 31 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x8d,0x8e,0x8f,0x90,
okano 0:1062142e5718 32 0x91,0x96,0x96,0x97,0x98,0x99,0x9a,0x9a,0x9b,0x9c,0x9d,0x9e,0xa2,0xa4,0xb0,
okano 0:1062142e5718 33 0xb1,0xb2,0xb3,0xb8,0xc8,0xc9
okano 0:1062142e5718 34 },
okano 0:1062142e5718 35 {
okano 0:1062142e5718 36 0x40,0x60,0x02,0x0c,0x61,0x4b,0x81,0x04 ,0x00,0x02,0x39,0x03,0x03,0x7b,0x37,0x02,0x91,
okano 0:1062142e5718 37 0x07,0x80,0x0b,0x11,0x0b,0x1d,0x71,0x2a,0x12,0x78,0xc3,0x11,0x00,0xd0,0x08,0x38,
okano 0:1062142e5718 38 0x0a,0xf0,0x34,0x58,0x28,0x3a,0x09,0x00,0x40,0x20,0x80,0x80,0x00,0x22,0x5e,
okano 0:1062142e5718 39 0x80,0x40,0x9e,0x88,0x88,0x44,0x67,0x49,0x0e,0x00,0x40,0x0a,0x0a,0x55,0x11,
okano 0:1062142e5718 40 0x9f,0x3a,0x35,0x11,0xf1,0x10,0x05,0xe1,0x01,0x04,0x01,0x4f,0x00,0x00,0x00,
okano 0:1062142e5718 41 0x00,0x00,0x00,0x30,0x20,0x30,0x00,0x84,0x29,0x03,0x4c,0x3f,0x52,0x88,0x84,
okano 0:1062142e5718 42 0x0c,0x0e,0x82,0x0a,0xf0,0x60
okano 0:1062142e5718 43 }
okano 0:1062142e5718 44 };
okano 0:1062142e5718 45
okano 0:1062142e5718 46
okano 0:1062142e5718 47 MARMEX_OB_oled oled1( p5, p7, p20, p16, p15 ); // mosi, sclk, cs, rst, power_control -- maple-mini-type-b-slot1
okano 0:1062142e5718 48
okano 0:1062142e5718 49
okano 0:1062142e5718 50 void init_camera( void )
okano 0:1062142e5718 51 {
okano 0:1062142e5718 52 I2C i2c( p28, p27 );
okano 0:1062142e5718 53
okano 0:1062142e5718 54 for ( int i = 0; i < PARAM_NUM; i++ ) {
okano 0:1062142e5718 55 i2c.start();
okano 0:1062142e5718 56 i2c.write( CAM_I2C_ADDR );
okano 0:1062142e5718 57 i2c.write( param[ 0 ][ i ] );
okano 0:1062142e5718 58 i2c.write( param[ 1 ][ i ] );
okano 0:1062142e5718 59 i2c.stop();
okano 0:1062142e5718 60 wait_ms( 20 );
okano 0:1062142e5718 61 }
okano 0:1062142e5718 62 }
okano 0:1062142e5718 63
okano 0:1062142e5718 64 SPI spi( p5, p6, p7 );
okano 0:1062142e5718 65 DigitalOut cs2( p22 );
okano 0:1062142e5718 66
okano 0:1062142e5718 67 int send_spi2( char data )
okano 0:1062142e5718 68 {
okano 0:1062142e5718 69 int tmp;
okano 0:1062142e5718 70
okano 0:1062142e5718 71 cs2 = 0;
okano 0:1062142e5718 72 tmp = spi.write( data );
okano 0:1062142e5718 73 cs2 = 1;
okano 0:1062142e5718 74
okano 0:1062142e5718 75 return ( tmp );
okano 0:1062142e5718 76 }
okano 0:1062142e5718 77
okano 0:1062142e5718 78
okano 0:1062142e5718 79 int main()
okano 0:1062142e5718 80 {
okano 0:1062142e5718 81
okano 0:1062142e5718 82 int my_address;
okano 0:1062142e5718 83 short buf[ 128 ];
okano 0:1062142e5718 84 int c;
okano 0:1062142e5718 85
okano 0:1062142e5718 86 cs2 = 1;
okano 0:1062142e5718 87 init_camera();
okano 0:1062142e5718 88
okano 0:1062142e5718 89 spi.format(8);
okano 0:1062142e5718 90 spi.frequency( 1000000 );
okano 0:1062142e5718 91
okano 0:1062142e5718 92
okano 0:1062142e5718 93 while ( 1 ) {
okano 0:1062142e5718 94
okano 0:1062142e5718 95 send_spi2( 0x03 );
okano 0:1062142e5718 96 send_spi2( 0x01 );
okano 0:1062142e5718 97 send_spi2( 0x84 );
okano 0:1062142e5718 98
okano 0:1062142e5718 99 while ( !(c = send_spi2( 0x00 ) & 0x1) ) {
okano 0:1062142e5718 100 printf( "val = 0x%02X\r\n", c );
okano 0:1062142e5718 101 }
okano 0:1062142e5718 102
okano 0:1062142e5718 103 printf( "camera ready\r\n" );
okano 0:1062142e5718 104
okano 0:1062142e5718 105 my_address = 24 * 2 + 176 * 8 * 2;
okano 0:1062142e5718 106
okano 0:1062142e5718 107 for ( int y = 0; y < 128; y++ ) {
okano 0:1062142e5718 108 send_spi2( 0x00 );
okano 0:1062142e5718 109 send_spi2( (my_address >> 0) & 0xFF );
okano 0:1062142e5718 110 send_spi2( 0x01 );
okano 0:1062142e5718 111 send_spi2( (my_address >> 8) & 0xFF );
okano 0:1062142e5718 112 send_spi2( 0x02 );
okano 0:1062142e5718 113 send_spi2( (my_address >> 16) & 0xFF );
okano 0:1062142e5718 114
okano 0:1062142e5718 115 my_address += 176 * 2;
okano 0:1062142e5718 116
okano 0:1062142e5718 117 for( int x = 0; x < 128; x++ ) {
okano 0:1062142e5718 118 buf[ x ] = (send_spi2( 0xA8 ) << 8) | send_spi2( 0xA8 );
okano 0:1062142e5718 119 }
okano 0:1062142e5718 120 oled1.blit565( 0, y, 128, 1, buf );
okano 0:1062142e5718 121 }
okano 0:1062142e5718 122
okano 0:1062142e5718 123 send_spi2( 0x03 );
okano 0:1062142e5718 124 send_spi2( 0x00 );
okano 0:1062142e5718 125 send_spi2( 0x84 );
okano 0:1062142e5718 126
okano 0:1062142e5718 127 while ( !(send_spi2( 0x84 ) & 0x1) )
okano 0:1062142e5718 128 ;
okano 0:1062142e5718 129 printf( "loop done\r\n" );
okano 0:1062142e5718 130 }
okano 0:1062142e5718 131
okano 0:1062142e5718 132 oled1.background( 0x000000 );
okano 0:1062142e5718 133 oled1.cls();
okano 0:1062142e5718 134
okano 0:1062142e5718 135 int colorbar_width = MARMEX_OB_oled::WIDTH / 8;
okano 0:1062142e5718 136
okano 0:1062142e5718 137 for ( int i = 0; i < 8; i++ )
okano 0:1062142e5718 138 oled1.fill( colorbar_width * i, 0, colorbar_width, MARMEX_OB_oled::HEIGHT, ((i & 0x4) ? 0xFF0000 : 0x000000) | ((i & 0x2) ? 0x00FF00 : 0x000000) | ((i & 0x1) ? 0x0000FF : 0x000000) );
okano 0:1062142e5718 139
okano 0:1062142e5718 140 oled1.fill( 50, 50, 64, 64, 0xCCCCCC );;
okano 0:1062142e5718 141
okano 0:1062142e5718 142 oled1.locate( 0, 3 );
okano 0:1062142e5718 143 oled1.printf( "Hello World!" );
okano 0:1062142e5718 144 oled1.locate( 0, 4 );
okano 0:1062142e5718 145 oled1.printf( "SPI = %s", MERMEX_OB_SPI_MODE_STR );
okano 0:1062142e5718 146
okano 0:1062142e5718 147 for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ ) {
okano 0:1062142e5718 148 oled1.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 );
okano 0:1062142e5718 149 }
okano 0:1062142e5718 150
okano 0:1062142e5718 151 short p[3][ 128 ] = { { 0xF800 }, {0x07E0}, { 0x001F } };
okano 0:1062142e5718 152
okano 0:1062142e5718 153 for ( int i = 0; i < 128; i++ )
okano 0:1062142e5718 154 p[ 0 ][ i ] = 0xF800;
okano 0:1062142e5718 155 for ( int i = 0; i < 128; i++ )
okano 0:1062142e5718 156 p[ 1 ][ i ] = 0x07E0;
okano 0:1062142e5718 157 for ( int i = 0; i < 128; i++ )
okano 0:1062142e5718 158 p[ 2 ][ i ] = 0x001F;
okano 0:1062142e5718 159
okano 0:1062142e5718 160 int count = 0;
okano 0:1062142e5718 161 while ( 1 ) {
okano 0:1062142e5718 162 for ( int i = 0; i < 128; i++ ) {
okano 0:1062142e5718 163 oled1.blit565( 0, i, 128, 1, p[ count % 3 ] );
okano 0:1062142e5718 164 }
okano 0:1062142e5718 165 count++;
okano 0:1062142e5718 166 }
okano 0:1062142e5718 167 }