Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MARY_CAMERA NokiaLCD mbed
Diff: main.cpp
- Revision:
- 1:ce27bc7b44d4
- Parent:
- 0:1062142e5718
- Child:
- 2:2e03fc4f485b
--- a/main.cpp Thu Feb 13 01:22:36 2014 +0000 +++ b/main.cpp Fri Feb 14 06:56:12 2014 +0000 @@ -47,10 +47,23 @@ MARMEX_OB_oled oled1( p5, p7, p20, p16, p15 ); // mosi, sclk, cs, rst, power_control -- maple-mini-type-b-slot1 -void init_camera( void ) +SPI spi( p5, p6, p7 ); +DigitalOut cs2( p22 ); +DigitalOut vsync( p9 ); +DigitalOut camera_reset( p26 ); + +void init( void ) { I2C i2c( p28, p27 ); + vsync = 0; + cs2 = 1; + camera_reset = 0; + wait_ms( 100 ); + camera_reset = 1; + wait_ms( 100 ); + + for ( int i = 0; i < PARAM_NUM; i++ ) { i2c.start(); i2c.write( CAM_I2C_ADDR ); @@ -59,10 +72,13 @@ i2c.stop(); wait_ms( 20 ); } -} + + + spi.format(8); + spi.frequency( 1000000 ); + vsync = 0; -SPI spi( p5, p6, p7 ); -DigitalOut cs2( p22 ); +} int send_spi2( char data ) { @@ -75,60 +91,106 @@ return ( tmp ); } +#define PREPARE 0x1 +#define DONE 0x0 + +void transfer_control( int flag ) +{ + send_spi2( 0x03 ); + send_spi2( flag ); + send_spi2( 0x84 ); + + while ( (send_spi2( 0x84 ) ^ flag) & 0x1 ) + ; + + vsync = flag ? 0 : 1; +} + +void open_transfer( void ) +{ + transfer_control( PREPARE ); +} + +void close_transfer( void ) +{ + transfer_control( DONE ); +} + + +void set_address( int address ) +{ + send_spi2( 0x00 ); + send_spi2( (address >> 0) & 0xFF ); + send_spi2( 0x01 ); + send_spi2( (address >> 8) & 0xFF ); + send_spi2( 0x02 ); + send_spi2( (address >> 16) & 0xFF ); +} + +#define PIXEL_PER_LINE 176 +#define BYTE_PER_PIXEL 2 +#define BYTE_PER_LINE (PIXEL_PER_LINE * BYTE_PER_PIXEL) + + +void transfer_a_line( short *p, int line_number, int x_offset, int n_of_pixels ) +{ + set_address( line_number * BYTE_PER_LINE + x_offset * BYTE_PER_PIXEL); + + for( int x = 0; x < n_of_pixels; x++ ) + *p++ = (send_spi2( 0xA8 ) << 8) | send_spi2( 0xA8 ); +} + + +#define X_OFFSET 24 +#define Y_OFFSET 8 int main() { + short buf[ 128 ]; - int my_address; - short buf[ 128 ]; - int c; + oled1.cls(); + + short p[3][ 128 ] = { { 0xF800 }, {0x07E0}, { 0x001F } }; + + for ( int i = 0; i < 128; i++ ) + p[ 0 ][ i ] = 0xF800; + for ( int i = 0; i < 128; i++ ) + p[ 1 ][ i ] = 0x07E0; + for ( int i = 0; i < 128; i++ ) + p[ 2 ][ i ] = 0x001F; - cs2 = 1; - init_camera(); + int count = 0; +#if 0 + while ( 1 ) { + for ( int i = 0; i < 128; i++ ) { + oled1.blit565( 0, i, 128, 1, p[ count % 3 ] ); + } + count++; + + if ( count == 3 ) + break; + } +#endif - spi.format(8); - spi.frequency( 1000000 ); - + init(); while ( 1 ) { - send_spi2( 0x03 ); - send_spi2( 0x01 ); - send_spi2( 0x84 ); + open_transfer(); + printf( "transfer ready\r\n" ); - while ( !(c = send_spi2( 0x00 ) & 0x1) ) { - printf( "val = 0x%02X\r\n", c ); + for ( int line = 0 + Y_OFFSET; line < 128 + Y_OFFSET; line++ ) { + transfer_a_line( buf, line, X_OFFSET, 128 ); + + oled1.blit565( 0, line, 128, 1, buf ); } - printf( "camera ready\r\n" ); - - my_address = 24 * 2 + 176 * 8 * 2; - - for ( int y = 0; y < 128; y++ ) { - send_spi2( 0x00 ); - send_spi2( (my_address >> 0) & 0xFF ); - send_spi2( 0x01 ); - send_spi2( (my_address >> 8) & 0xFF ); - send_spi2( 0x02 ); - send_spi2( (my_address >> 16) & 0xFF ); - - my_address += 176 * 2; + close_transfer(); + printf( "loop done\r\n" ); - for( int x = 0; x < 128; x++ ) { - buf[ x ] = (send_spi2( 0xA8 ) << 8) | send_spi2( 0xA8 ); - } - oled1.blit565( 0, y, 128, 1, buf ); - } - - send_spi2( 0x03 ); - send_spi2( 0x00 ); - send_spi2( 0x84 ); - - while ( !(send_spi2( 0x84 ) & 0x1) ) - ; - printf( "loop done\r\n" ); } +#if 0 oled1.background( 0x000000 ); oled1.cls(); @@ -164,4 +226,5 @@ } count++; } +#endif }