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.
Diff: MARY_CAMERA.cpp
- Revision:
- 29:4432c5282c7b
- Parent:
- 28:b5d5a2f7f0d0
- Child:
- 30:5d8e86cd337d
--- a/MARY_CAMERA.cpp Sat Mar 22 01:26:45 2014 +0000 +++ b/MARY_CAMERA.cpp Sat Mar 22 01:50:50 2014 +0000 @@ -4,9 +4,6 @@ #define CAM_I2C_ADDR 0x42 -#define RESET_PULSE_WIDTH 100 // mili-seconds -#define RESET_RECOVERY_TIME 100 // mili-seconds - #define COMMAND_WRITE 0x00 #define COMMAND_READ 0x80 #define COMMAND_ADDR_INCREMENT 0x20 @@ -46,8 +43,12 @@ int MARY_CAMERA::init( CameraResolution res ) { -#define PARAM_NUM 99 -#define RES_CHANGE_PARAM_NUM 12 +#define PARAM_NUM 99 +#define RES_CHANGE_PARAM_NUM 12 +#define RESET_PULSE_WIDTH 100 // mili-seconds +#define RESET_RECOVERY_TIME 100 // mili-seconds +#define COMMAND_INTERVAL 20 // mili-seconds + char camera_register_setting[ PARAM_NUM ][ 2 ] = { { 0x01, 0x40 }, { 0x02, 0x60 }, { 0x03, 0x02 }, { 0x0C, 0x0C }, @@ -105,6 +106,7 @@ _horizontal_size = QCIF_PIXEL_PER_LINE; _vertical_size = QCIF_LINE_PER_FRAME; +#ifdef UNIFIED_RESOLUTION_CHANGE if ( QCIF != res ) { for ( int i = 0; i < RES_CHANGE_PARAM_NUM; i++ ) { for ( int j = 0; j < PARAM_NUM; j++ ) { @@ -114,22 +116,49 @@ } } } +#endif + + switch ( res ) { + case QCIF: + _horizontal_size = QCIF_PIXEL_PER_LINE; + _vertical_size = QCIF_LINE_PER_FRAME; + break; + case VGA: + _horizontal_size = VGA_PIXEL_PER_LINE; + _vertical_size = VGA_LINE_PER_FRAME; + break; + case QVGA: + _horizontal_size = VGA_PIXEL_PER_LINE / 2; + _vertical_size = VGA_LINE_PER_FRAME / 2; + break; + case QQVGA: + _horizontal_size = VGA_PIXEL_PER_LINE / 4; + _vertical_size = VGA_LINE_PER_FRAME / 4; + break; + } for ( int i = 0; i < PARAM_NUM; i++ ) { if ( 0 != (_error_state = _i2c.write( CAM_I2C_ADDR, camera_register_setting[ i ], 2 )) ) break; - wait_ms( 20 ); // camera register writing requires this interval + wait_ms( COMMAND_INTERVAL ); // camera register writing requires this interval } +#ifndef UNIFIED_RESOLUTION_CHANGE + char d[ 2 ]; + for ( int i = 0; i < RES_CHANGE_PARAM_NUM; i++ ) { + d[ 0 ] = res_change_param[ 0 ][ i ]; + d[ 1 ] = res_change_param[ res ][ i ]; + + if ( 0 != (_error_state = _i2c.write( CAM_I2C_ADDR, d, 2 )) ) + break; + } +#endif + + return _error_state; // return non-zero if I2C access failed } -void MARY_CAMERA::resolution( CameraResolution res ) -{ - init( res ); -} - void MARY_CAMERA::colorbar( SwitchState sw ) { char s[ 2 ]; @@ -138,7 +167,6 @@ s[ 1 ] = sw ? 0x06 : 0x04; _error_state = _i2c.write( CAM_I2C_ADDR, s, 2 ); - } int MARY_CAMERA::horizontal_size( void )