Tedd OKANO / MARY_CAMERA
Committer:
okano
Date:
Tue Mar 11 05:31:41 2014 +0000
Revision:
17:756fb618c0ed
Parent:
13:210f4bbd0cd6
Child:
19:1d07d6d762a9
QCIF - VGA switch by compile option

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 4:cb0ef3fd89c9 1 #ifndef MBED_MARY_CAMERA
okano 4:cb0ef3fd89c9 2 #define MBED_MARY_CAMERA
okano 0:f4584dba3bac 3
okano 11:61a025e8ab68 4 #define SPI_FREQUENCY 12000000
okano 0:f4584dba3bac 5
okano 4:cb0ef3fd89c9 6 /** MARY_CAMERA class
okano 4:cb0ef3fd89c9 7 *
okano 4:cb0ef3fd89c9 8 * MARY_CAMERA driver library
okano 4:cb0ef3fd89c9 9 * This driver has been made to get camera data from MARY CAMERA.
okano 4:cb0ef3fd89c9 10 *
okano 4:cb0ef3fd89c9 11 * Example:
okano 4:cb0ef3fd89c9 12 * @code
okano 13:210f4bbd0cd6 13 *
okano 4:cb0ef3fd89c9 14 * #include "mbed.h"
okano 4:cb0ef3fd89c9 15 * #include "MARMEX_OB_oled.h"
okano 4:cb0ef3fd89c9 16 * #include "MARY_CAMERA.h"
okano 13:210f4bbd0cd6 17 *
okano 4:cb0ef3fd89c9 18 * MARMEX_OB_oled oled1( p5, p7, p20, p16, p15 ); // mosi, sclk, cs, rst, power_control -- maple-mini-type-b-slot1
okano 4:cb0ef3fd89c9 19 * MARY_CAMERA camera( p5, p6, p7, p22, p26, p28, p27 ); // mosi, miso, sclk, cs, reset, I2C_SDA, I2C_SCL
okano 4:cb0ef3fd89c9 20 * BusOut led( LED3, LED4 );
okano 13:210f4bbd0cd6 21 *
okano 4:cb0ef3fd89c9 22 * #define X_OFFSET ((MARY_CAMERA::PIXEL_PER_LINE - MARMEX_OB_oled::WIDTH ) / 2)
okano 4:cb0ef3fd89c9 23 * #define Y_OFFSET ((MARY_CAMERA::LINE_PER_FRAME - MARMEX_OB_oled::HEIGHT) / 2)
okano 13:210f4bbd0cd6 24 *
okano 4:cb0ef3fd89c9 25 * int main()
okano 4:cb0ef3fd89c9 26 * {
okano 4:cb0ef3fd89c9 27 * led = 0x3;
okano 13:210f4bbd0cd6 28 *
okano 4:cb0ef3fd89c9 29 * oled1.cls();
okano 13:210f4bbd0cd6 30 *
okano 4:cb0ef3fd89c9 31 * short buf[ MARMEX_OB_oled::WIDTH ];
okano 13:210f4bbd0cd6 32 *
okano 4:cb0ef3fd89c9 33 * while ( 1 ) {
okano 13:210f4bbd0cd6 34 *
okano 4:cb0ef3fd89c9 35 * led = 0x1;
okano 4:cb0ef3fd89c9 36 * camera.open_transfer();
okano 13:210f4bbd0cd6 37 *
okano 4:cb0ef3fd89c9 38 * for ( int line = 0; line < 128; line++ ) {
okano 4:cb0ef3fd89c9 39 * camera.transfer_a_line( buf, line + Y_OFFSET, X_OFFSET, 128 );
okano 4:cb0ef3fd89c9 40 * oled1.blit565( 0, line, 128, 1, buf );
okano 4:cb0ef3fd89c9 41 * }
okano 13:210f4bbd0cd6 42 *
okano 4:cb0ef3fd89c9 43 * camera.close_transfer();
okano 4:cb0ef3fd89c9 44 * led = 0x2;
okano 4:cb0ef3fd89c9 45 * }
okano 4:cb0ef3fd89c9 46 * }
okano 4:cb0ef3fd89c9 47 * @endcode
okano 4:cb0ef3fd89c9 48 */
okano 13:210f4bbd0cd6 49
okano 13:210f4bbd0cd6 50
okano 17:756fb618c0ed 51 #define CAMERA__PICTSIZE_VGA
okano 17:756fb618c0ed 52 //#define CAMERA__PICTSIZE_QCIF
okano 17:756fb618c0ed 53
okano 0:f4584dba3bac 54 class MARY_CAMERA
okano 0:f4584dba3bac 55 {
okano 0:f4584dba3bac 56 public:
okano 0:f4584dba3bac 57
okano 8:23d14d5254d2 58 /** General parameters for MARY_CAMERA */
okano 4:cb0ef3fd89c9 59 enum {
okano 17:756fb618c0ed 60
okano 17:756fb618c0ed 61 #ifdef CAMERA__PICTSIZE_QCIF
okano 4:cb0ef3fd89c9 62 PIXEL_PER_LINE = 176, /**< pixels in a line */
okano 4:cb0ef3fd89c9 63 LINE_PER_FRAME = 144, /**< pixels in a line */
okano 17:756fb618c0ed 64 #endif
okano 17:756fb618c0ed 65
okano 17:756fb618c0ed 66 #ifdef CAMERA__PICTSIZE_VGA
okano 13:210f4bbd0cd6 67 PIXEL_PER_LINE = 640, /**< pixels in a line */
okano 13:210f4bbd0cd6 68 LINE_PER_FRAME = 480, /**< pixels in a line */
okano 13:210f4bbd0cd6 69 #endif
okano 17:756fb618c0ed 70
okano 4:cb0ef3fd89c9 71 BYTE_PER_PIXEL = 2, /**< bytes per pixel */
okano 4:cb0ef3fd89c9 72 BYTE_PER_LINE = (PIXEL_PER_LINE * BYTE_PER_PIXEL) /**< data size of 1 line */
okano 4:cb0ef3fd89c9 73 };
okano 4:cb0ef3fd89c9 74
okano 8:23d14d5254d2 75 /** General parameters for MARMEX_OB_oled */
okano 8:23d14d5254d2 76 enum {
okano 8:23d14d5254d2 77 NO_ERROR = 0 /**< zero */
okano 8:23d14d5254d2 78 };
okano 8:23d14d5254d2 79
okano 4:cb0ef3fd89c9 80 /** Create a MARY_CAMERA instance connected to specified SPI, DigitalOut and I2C pins
okano 0:f4584dba3bac 81 *
okano 4:cb0ef3fd89c9 82 * @param SPI_mosi SPI-bus MOSI pin
okano 4:cb0ef3fd89c9 83 * @param SPI_miso SPI-bus MISO pin
okano 4:cb0ef3fd89c9 84 * @param SPI_sclk SPI-bus SCLK pin
okano 4:cb0ef3fd89c9 85 * @param SPI_cs SPI-bus Chip Select pin
okano 4:cb0ef3fd89c9 86 * @param cam_reset Camera reset pin
okano 4:cb0ef3fd89c9 87 * @param I2C_sda I2C-bus SDA pin
okano 4:cb0ef3fd89c9 88 * @param I2C_scl I2C-bus SCL pin
okano 0:f4584dba3bac 89 */
okano 0:f4584dba3bac 90
okano 0:f4584dba3bac 91 MARY_CAMERA(
okano 4:cb0ef3fd89c9 92 PinName SPI_mosi,
okano 4:cb0ef3fd89c9 93 PinName SPI_miso,
okano 4:cb0ef3fd89c9 94 PinName SPI_sck,
okano 4:cb0ef3fd89c9 95 PinName SPI_cs,
okano 0:f4584dba3bac 96 PinName cam_reset,
okano 4:cb0ef3fd89c9 97 PinName I2C_sda,
okano 4:cb0ef3fd89c9 98 PinName I2C_scl
okano 0:f4584dba3bac 99 );
okano 4:cb0ef3fd89c9 100
okano 4:cb0ef3fd89c9 101 /** Initialization
okano 4:cb0ef3fd89c9 102 *
okano 4:cb0ef3fd89c9 103 * Performs MARY_CAMERA reset and initializations
okano 13:210f4bbd0cd6 104 * This function is called from MARY_CAMERA constoructor. So user don't have to call in the user code.
okano 4:cb0ef3fd89c9 105 *
okano 13:210f4bbd0cd6 106 * This function takes about 2 seconds because there is 99 times I2C access with 20ms interval.
okano 4:cb0ef3fd89c9 107 */
okano 11:61a025e8ab68 108 int init( void );
okano 4:cb0ef3fd89c9 109
okano 8:23d14d5254d2 110 /** Check camera availability
okano 8:23d14d5254d2 111 *
okano 8:23d14d5254d2 112 * Returns last I2C access result
okano 8:23d14d5254d2 113 * This returns non-zero value id the camera initialization failed
okano 8:23d14d5254d2 114 *
okano 13:210f4bbd0cd6 115 * This function takes about 2 seconds because there is 99 times I2C access with 20ms interval.
okano 11:61a025e8ab68 116 *
okano 11:61a025e8ab68 117 * @return error code in init function (I2C API return value)
okano 8:23d14d5254d2 118 */
okano 8:23d14d5254d2 119 int ready( void );
okano 8:23d14d5254d2 120
okano 4:cb0ef3fd89c9 121 /** Open transfer
okano 4:cb0ef3fd89c9 122 *
okano 13:210f4bbd0cd6 123 * Let the MARY_CAMERA get ready to transfer the data.
okano 13:210f4bbd0cd6 124 * When this function is called, the camera will stop updating buffer at end of frame.
okano 8:23d14d5254d2 125 *
okano 8:23d14d5254d2 126 * @return error code in init function (I2C API return value)
okano 4:cb0ef3fd89c9 127 */
okano 0:f4584dba3bac 128 void open_transfer( void );
okano 4:cb0ef3fd89c9 129
okano 4:cb0ef3fd89c9 130 /** Close transfer
okano 4:cb0ef3fd89c9 131 *
okano 13:210f4bbd0cd6 132 * Letting the MARY_CAMERA to know the data transfer done.
okano 4:cb0ef3fd89c9 133 * This function should be called when the data transfer done to resume the buffer update by camera
okano 4:cb0ef3fd89c9 134 */
okano 0:f4584dba3bac 135 void close_transfer( void );
okano 13:210f4bbd0cd6 136
okano 4:cb0ef3fd89c9 137 /** Transfer a line
okano 4:cb0ef3fd89c9 138 *
okano 4:cb0ef3fd89c9 139 * Reads 1 line data from MARY_CAMERA
okano 4:cb0ef3fd89c9 140 * This function should be called when the data transfer done to resume the buffer update by camera
okano 13:210f4bbd0cd6 141 *
okano 4:cb0ef3fd89c9 142 * @param *p pointer to array of short
okano 4:cb0ef3fd89c9 143 * @param line_number to select which line want to read
okano 4:cb0ef3fd89c9 144 * @param x_offset holizontal offset (from left) to start the read
okano 4:cb0ef3fd89c9 145 * @param n_of_pixels pixels to be read
okano 4:cb0ef3fd89c9 146 */
okano 0:f4584dba3bac 147 void transfer_a_line( short *p, int line_number, int x_offset, int n_of_pixels );
okano 0:f4584dba3bac 148
okano 0:f4584dba3bac 149 private:
okano 11:61a025e8ab68 150 int send_spi( char data );
okano 11:61a025e8ab68 151 void write_register( char reg, char value );
okano 11:61a025e8ab68 152 int read_register( char reg );
okano 11:61a025e8ab68 153 void set_address( int address );
okano 0:f4584dba3bac 154
okano 4:cb0ef3fd89c9 155 SPI _spi;
okano 4:cb0ef3fd89c9 156 DigitalOut _cs;
okano 4:cb0ef3fd89c9 157 DigitalOut _reset;
okano 4:cb0ef3fd89c9 158 I2C _i2c;
okano 8:23d14d5254d2 159 int _error_state;
okano 0:f4584dba3bac 160 };
okano 0:f4584dba3bac 161
okano 0:f4584dba3bac 162 #endif // MBED_MARY_CAMERA