Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Committer:
okano
Date:
Fri Feb 14 08:33:14 2014 +0000
Revision:
2:2e03fc4f485b
Parent:
1:ce27bc7b44d4
Child:
3:152362acd181
it's working!

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 2:2e03fc4f485b 50 SPI camspi( p5, p6, p7 );
okano 1:ce27bc7b44d4 51 DigitalOut cs2( p22 );
okano 1:ce27bc7b44d4 52 DigitalOut vsync( p9 );
okano 1:ce27bc7b44d4 53 DigitalOut camera_reset( p26 );
okano 1:ce27bc7b44d4 54
okano 1:ce27bc7b44d4 55 void init( void )
okano 0:1062142e5718 56 {
okano 0:1062142e5718 57 I2C i2c( p28, p27 );
okano 0:1062142e5718 58
okano 1:ce27bc7b44d4 59 vsync = 0;
okano 1:ce27bc7b44d4 60 cs2 = 1;
okano 1:ce27bc7b44d4 61 camera_reset = 0;
okano 1:ce27bc7b44d4 62 wait_ms( 100 );
okano 1:ce27bc7b44d4 63 camera_reset = 1;
okano 1:ce27bc7b44d4 64 wait_ms( 100 );
okano 1:ce27bc7b44d4 65
okano 1:ce27bc7b44d4 66
okano 0:1062142e5718 67 for ( int i = 0; i < PARAM_NUM; i++ ) {
okano 0:1062142e5718 68 i2c.start();
okano 0:1062142e5718 69 i2c.write( CAM_I2C_ADDR );
okano 0:1062142e5718 70 i2c.write( param[ 0 ][ i ] );
okano 0:1062142e5718 71 i2c.write( param[ 1 ][ i ] );
okano 0:1062142e5718 72 i2c.stop();
okano 0:1062142e5718 73 wait_ms( 20 );
okano 0:1062142e5718 74 }
okano 1:ce27bc7b44d4 75
okano 1:ce27bc7b44d4 76
okano 2:2e03fc4f485b 77 camspi.format(8);
okano 2:2e03fc4f485b 78 camspi.frequency( 1000000 );
okano 1:ce27bc7b44d4 79 vsync = 0;
okano 0:1062142e5718 80
okano 1:ce27bc7b44d4 81 }
okano 0:1062142e5718 82
okano 2:2e03fc4f485b 83 int send_camspi2( char data )
okano 0:1062142e5718 84 {
okano 0:1062142e5718 85 int tmp;
okano 0:1062142e5718 86
okano 0:1062142e5718 87 cs2 = 0;
okano 2:2e03fc4f485b 88 tmp = camspi.write( data );
okano 0:1062142e5718 89 cs2 = 1;
okano 0:1062142e5718 90
okano 0:1062142e5718 91 return ( tmp );
okano 0:1062142e5718 92 }
okano 0:1062142e5718 93
okano 1:ce27bc7b44d4 94 #define PREPARE 0x1
okano 1:ce27bc7b44d4 95 #define DONE 0x0
okano 1:ce27bc7b44d4 96
okano 1:ce27bc7b44d4 97 void transfer_control( int flag )
okano 1:ce27bc7b44d4 98 {
okano 2:2e03fc4f485b 99 send_camspi2( 0x03 );
okano 2:2e03fc4f485b 100 send_camspi2( flag ); // 1 for PREPARE, 0 for DONE
okano 2:2e03fc4f485b 101 vsync = flag ? 0 : 1; // 0 for PREPARE, 1 for DONE
okano 2:2e03fc4f485b 102 send_camspi2( 0x84 );
okano 1:ce27bc7b44d4 103
okano 2:2e03fc4f485b 104 while ( (send_camspi2( 0x84 ) ^ flag) & 0x1 ); // wait until LSB becomes '1'(for PREPARE) or '0'(for done)
okano 1:ce27bc7b44d4 105
okano 1:ce27bc7b44d4 106 }
okano 1:ce27bc7b44d4 107
okano 1:ce27bc7b44d4 108 void open_transfer( void )
okano 1:ce27bc7b44d4 109 {
okano 2:2e03fc4f485b 110 // transfer_control( PREPARE );
okano 2:2e03fc4f485b 111
okano 2:2e03fc4f485b 112 send_camspi2( 0x03 );
okano 2:2e03fc4f485b 113 send_camspi2( 1 );
okano 2:2e03fc4f485b 114 vsync = 0;
okano 2:2e03fc4f485b 115 send_camspi2( 0x84 );
okano 2:2e03fc4f485b 116
okano 2:2e03fc4f485b 117 while ( (send_camspi2( 0x84 ) & 0x1) == 0 );
okano 1:ce27bc7b44d4 118 }
okano 1:ce27bc7b44d4 119
okano 1:ce27bc7b44d4 120 void close_transfer( void )
okano 1:ce27bc7b44d4 121 {
okano 2:2e03fc4f485b 122 // transfer_control( DONE );
okano 2:2e03fc4f485b 123
okano 2:2e03fc4f485b 124 send_camspi2( 0x03 );
okano 2:2e03fc4f485b 125 send_camspi2( 0 );
okano 2:2e03fc4f485b 126 send_camspi2( 0x84 );
okano 2:2e03fc4f485b 127
okano 2:2e03fc4f485b 128 while ( (send_camspi2( 0x84 ) & 0x1) );
okano 2:2e03fc4f485b 129
okano 2:2e03fc4f485b 130 vsync = 1;
okano 1:ce27bc7b44d4 131 }
okano 1:ce27bc7b44d4 132
okano 1:ce27bc7b44d4 133
okano 1:ce27bc7b44d4 134 void set_address( int address )
okano 1:ce27bc7b44d4 135 {
okano 2:2e03fc4f485b 136 send_camspi2( 0x00 );
okano 2:2e03fc4f485b 137 send_camspi2( (address >> 0) & 0xFF );
okano 2:2e03fc4f485b 138 send_camspi2( 0x01 );
okano 2:2e03fc4f485b 139 send_camspi2( (address >> 8) & 0xFF );
okano 2:2e03fc4f485b 140 send_camspi2( 0x02 );
okano 2:2e03fc4f485b 141 send_camspi2( (address >> 16) & 0xFF );
okano 1:ce27bc7b44d4 142 }
okano 1:ce27bc7b44d4 143
okano 1:ce27bc7b44d4 144 #define PIXEL_PER_LINE 176
okano 1:ce27bc7b44d4 145 #define BYTE_PER_PIXEL 2
okano 1:ce27bc7b44d4 146 #define BYTE_PER_LINE (PIXEL_PER_LINE * BYTE_PER_PIXEL)
okano 1:ce27bc7b44d4 147
okano 1:ce27bc7b44d4 148
okano 1:ce27bc7b44d4 149 void transfer_a_line( short *p, int line_number, int x_offset, int n_of_pixels )
okano 1:ce27bc7b44d4 150 {
okano 2:2e03fc4f485b 151 // set_address( line_number * BYTE_PER_LINE + x_offset * BYTE_PER_PIXEL );
okano 2:2e03fc4f485b 152 set_address( line_number * BYTE_PER_LINE );
okano 2:2e03fc4f485b 153 send_camspi2( 0xA8 );
okano 1:ce27bc7b44d4 154 for( int x = 0; x < n_of_pixels; x++ )
okano 2:2e03fc4f485b 155 *p++ = (send_camspi2( 0xA8 ) << 8) | (send_camspi2( 0xA8 ) << 0);
okano 1:ce27bc7b44d4 156 }
okano 1:ce27bc7b44d4 157
okano 1:ce27bc7b44d4 158
okano 1:ce27bc7b44d4 159 #define X_OFFSET 24
okano 1:ce27bc7b44d4 160 #define Y_OFFSET 8
okano 0:1062142e5718 161
okano 0:1062142e5718 162 int main()
okano 0:1062142e5718 163 {
okano 1:ce27bc7b44d4 164 short buf[ 128 ];
okano 0:1062142e5718 165
okano 1:ce27bc7b44d4 166 oled1.cls();
okano 1:ce27bc7b44d4 167
okano 1:ce27bc7b44d4 168 short p[3][ 128 ] = { { 0xF800 }, {0x07E0}, { 0x001F } };
okano 1:ce27bc7b44d4 169
okano 1:ce27bc7b44d4 170 for ( int i = 0; i < 128; i++ )
okano 1:ce27bc7b44d4 171 p[ 0 ][ i ] = 0xF800;
okano 1:ce27bc7b44d4 172 for ( int i = 0; i < 128; i++ )
okano 1:ce27bc7b44d4 173 p[ 1 ][ i ] = 0x07E0;
okano 1:ce27bc7b44d4 174 for ( int i = 0; i < 128; i++ )
okano 1:ce27bc7b44d4 175 p[ 2 ][ i ] = 0x001F;
okano 0:1062142e5718 176
okano 1:ce27bc7b44d4 177 int count = 0;
okano 1:ce27bc7b44d4 178 #if 0
okano 1:ce27bc7b44d4 179 while ( 1 ) {
okano 1:ce27bc7b44d4 180 for ( int i = 0; i < 128; i++ ) {
okano 1:ce27bc7b44d4 181 oled1.blit565( 0, i, 128, 1, p[ count % 3 ] );
okano 1:ce27bc7b44d4 182 }
okano 1:ce27bc7b44d4 183 count++;
okano 1:ce27bc7b44d4 184
okano 1:ce27bc7b44d4 185 if ( count == 3 )
okano 1:ce27bc7b44d4 186 break;
okano 1:ce27bc7b44d4 187 }
okano 1:ce27bc7b44d4 188 #endif
okano 0:1062142e5718 189
okano 1:ce27bc7b44d4 190 init();
okano 0:1062142e5718 191
okano 0:1062142e5718 192 while ( 1 ) {
okano 0:1062142e5718 193
okano 1:ce27bc7b44d4 194 open_transfer();
okano 1:ce27bc7b44d4 195 printf( "transfer ready\r\n" );
okano 0:1062142e5718 196
okano 1:ce27bc7b44d4 197 for ( int line = 0 + Y_OFFSET; line < 128 + Y_OFFSET; line++ ) {
okano 1:ce27bc7b44d4 198 transfer_a_line( buf, line, X_OFFSET, 128 );
okano 1:ce27bc7b44d4 199
okano 1:ce27bc7b44d4 200 oled1.blit565( 0, line, 128, 1, buf );
okano 0:1062142e5718 201 }
okano 0:1062142e5718 202
okano 1:ce27bc7b44d4 203 close_transfer();
okano 1:ce27bc7b44d4 204 printf( "loop done\r\n" );
okano 0:1062142e5718 205
okano 0:1062142e5718 206 }
okano 0:1062142e5718 207
okano 1:ce27bc7b44d4 208 #if 0
okano 0:1062142e5718 209 oled1.background( 0x000000 );
okano 0:1062142e5718 210 oled1.cls();
okano 0:1062142e5718 211
okano 0:1062142e5718 212 int colorbar_width = MARMEX_OB_oled::WIDTH / 8;
okano 0:1062142e5718 213
okano 0:1062142e5718 214 for ( int i = 0; i < 8; i++ )
okano 0:1062142e5718 215 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 216
okano 0:1062142e5718 217 oled1.fill( 50, 50, 64, 64, 0xCCCCCC );;
okano 0:1062142e5718 218
okano 0:1062142e5718 219 oled1.locate( 0, 3 );
okano 0:1062142e5718 220 oled1.printf( "Hello World!" );
okano 0:1062142e5718 221 oled1.locate( 0, 4 );
okano 2:2e03fc4f485b 222 oled1.printf( "camspi = %s", MERMEX_OB_camspi_MODE_STR );
okano 0:1062142e5718 223
okano 0:1062142e5718 224 for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ ) {
okano 0:1062142e5718 225 oled1.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 );
okano 0:1062142e5718 226 }
okano 0:1062142e5718 227
okano 0:1062142e5718 228 short p[3][ 128 ] = { { 0xF800 }, {0x07E0}, { 0x001F } };
okano 0:1062142e5718 229
okano 0:1062142e5718 230 for ( int i = 0; i < 128; i++ )
okano 0:1062142e5718 231 p[ 0 ][ i ] = 0xF800;
okano 0:1062142e5718 232 for ( int i = 0; i < 128; i++ )
okano 0:1062142e5718 233 p[ 1 ][ i ] = 0x07E0;
okano 0:1062142e5718 234 for ( int i = 0; i < 128; i++ )
okano 0:1062142e5718 235 p[ 2 ][ i ] = 0x001F;
okano 0:1062142e5718 236
okano 0:1062142e5718 237 int count = 0;
okano 0:1062142e5718 238 while ( 1 ) {
okano 0:1062142e5718 239 for ( int i = 0; i < 128; i++ ) {
okano 0:1062142e5718 240 oled1.blit565( 0, i, 128, 1, p[ count % 3 ] );
okano 0:1062142e5718 241 }
okano 0:1062142e5718 242 count++;
okano 0:1062142e5718 243 }
okano 1:ce27bc7b44d4 244 #endif
okano 0:1062142e5718 245 }