Tedd OKANO / MARY_CAMERA
Committer:
okano
Date:
Tue Mar 11 03:25:00 2014 +0000
Revision:
13:210f4bbd0cd6
Parent:
11:61a025e8ab68
Child:
17:756fb618c0ed
test code

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 0:f4584dba3bac 51 class MARY_CAMERA
okano 0:f4584dba3bac 52 {
okano 0:f4584dba3bac 53 public:
okano 0:f4584dba3bac 54
okano 8:23d14d5254d2 55 /** General parameters for MARY_CAMERA */
okano 4:cb0ef3fd89c9 56 enum {
okano 13:210f4bbd0cd6 57 #if 0
okano 4:cb0ef3fd89c9 58 PIXEL_PER_LINE = 176, /**< pixels in a line */
okano 4:cb0ef3fd89c9 59 LINE_PER_FRAME = 144, /**< pixels in a line */
okano 13:210f4bbd0cd6 60 #else
okano 13:210f4bbd0cd6 61 PIXEL_PER_LINE = 640, /**< pixels in a line */
okano 13:210f4bbd0cd6 62 LINE_PER_FRAME = 480, /**< pixels in a line */
okano 13:210f4bbd0cd6 63 #endif
okano 4:cb0ef3fd89c9 64 BYTE_PER_PIXEL = 2, /**< bytes per pixel */
okano 4:cb0ef3fd89c9 65 BYTE_PER_LINE = (PIXEL_PER_LINE * BYTE_PER_PIXEL) /**< data size of 1 line */
okano 4:cb0ef3fd89c9 66 };
okano 4:cb0ef3fd89c9 67
okano 8:23d14d5254d2 68 /** General parameters for MARMEX_OB_oled */
okano 8:23d14d5254d2 69 enum {
okano 8:23d14d5254d2 70 NO_ERROR = 0 /**< zero */
okano 8:23d14d5254d2 71 };
okano 8:23d14d5254d2 72
okano 4:cb0ef3fd89c9 73 /** Create a MARY_CAMERA instance connected to specified SPI, DigitalOut and I2C pins
okano 0:f4584dba3bac 74 *
okano 4:cb0ef3fd89c9 75 * @param SPI_mosi SPI-bus MOSI pin
okano 4:cb0ef3fd89c9 76 * @param SPI_miso SPI-bus MISO pin
okano 4:cb0ef3fd89c9 77 * @param SPI_sclk SPI-bus SCLK pin
okano 4:cb0ef3fd89c9 78 * @param SPI_cs SPI-bus Chip Select pin
okano 4:cb0ef3fd89c9 79 * @param cam_reset Camera reset pin
okano 4:cb0ef3fd89c9 80 * @param I2C_sda I2C-bus SDA pin
okano 4:cb0ef3fd89c9 81 * @param I2C_scl I2C-bus SCL pin
okano 0:f4584dba3bac 82 */
okano 0:f4584dba3bac 83
okano 0:f4584dba3bac 84 MARY_CAMERA(
okano 4:cb0ef3fd89c9 85 PinName SPI_mosi,
okano 4:cb0ef3fd89c9 86 PinName SPI_miso,
okano 4:cb0ef3fd89c9 87 PinName SPI_sck,
okano 4:cb0ef3fd89c9 88 PinName SPI_cs,
okano 0:f4584dba3bac 89 PinName cam_reset,
okano 4:cb0ef3fd89c9 90 PinName I2C_sda,
okano 4:cb0ef3fd89c9 91 PinName I2C_scl
okano 0:f4584dba3bac 92 );
okano 4:cb0ef3fd89c9 93
okano 4:cb0ef3fd89c9 94 /** Initialization
okano 4:cb0ef3fd89c9 95 *
okano 4:cb0ef3fd89c9 96 * Performs MARY_CAMERA reset and initializations
okano 13:210f4bbd0cd6 97 * This function is called from MARY_CAMERA constoructor. So user don't have to call in the user code.
okano 4:cb0ef3fd89c9 98 *
okano 13:210f4bbd0cd6 99 * This function takes about 2 seconds because there is 99 times I2C access with 20ms interval.
okano 4:cb0ef3fd89c9 100 */
okano 11:61a025e8ab68 101 int init( void );
okano 4:cb0ef3fd89c9 102
okano 8:23d14d5254d2 103 /** Check camera availability
okano 8:23d14d5254d2 104 *
okano 8:23d14d5254d2 105 * Returns last I2C access result
okano 8:23d14d5254d2 106 * This returns non-zero value id the camera initialization failed
okano 8:23d14d5254d2 107 *
okano 13:210f4bbd0cd6 108 * This function takes about 2 seconds because there is 99 times I2C access with 20ms interval.
okano 11:61a025e8ab68 109 *
okano 11:61a025e8ab68 110 * @return error code in init function (I2C API return value)
okano 8:23d14d5254d2 111 */
okano 8:23d14d5254d2 112 int ready( void );
okano 8:23d14d5254d2 113
okano 4:cb0ef3fd89c9 114 /** Open transfer
okano 4:cb0ef3fd89c9 115 *
okano 13:210f4bbd0cd6 116 * Let the MARY_CAMERA get ready to transfer the data.
okano 13:210f4bbd0cd6 117 * When this function is called, the camera will stop updating buffer at end of frame.
okano 8:23d14d5254d2 118 *
okano 8:23d14d5254d2 119 * @return error code in init function (I2C API return value)
okano 4:cb0ef3fd89c9 120 */
okano 0:f4584dba3bac 121 void open_transfer( void );
okano 4:cb0ef3fd89c9 122
okano 4:cb0ef3fd89c9 123 /** Close transfer
okano 4:cb0ef3fd89c9 124 *
okano 13:210f4bbd0cd6 125 * Letting the MARY_CAMERA to know the data transfer done.
okano 4:cb0ef3fd89c9 126 * This function should be called when the data transfer done to resume the buffer update by camera
okano 4:cb0ef3fd89c9 127 */
okano 0:f4584dba3bac 128 void close_transfer( void );
okano 13:210f4bbd0cd6 129
okano 4:cb0ef3fd89c9 130 /** Transfer a line
okano 4:cb0ef3fd89c9 131 *
okano 4:cb0ef3fd89c9 132 * Reads 1 line data from MARY_CAMERA
okano 4:cb0ef3fd89c9 133 * This function should be called when the data transfer done to resume the buffer update by camera
okano 13:210f4bbd0cd6 134 *
okano 4:cb0ef3fd89c9 135 * @param *p pointer to array of short
okano 4:cb0ef3fd89c9 136 * @param line_number to select which line want to read
okano 4:cb0ef3fd89c9 137 * @param x_offset holizontal offset (from left) to start the read
okano 4:cb0ef3fd89c9 138 * @param n_of_pixels pixels to be read
okano 4:cb0ef3fd89c9 139 */
okano 0:f4584dba3bac 140 void transfer_a_line( short *p, int line_number, int x_offset, int n_of_pixels );
okano 0:f4584dba3bac 141
okano 0:f4584dba3bac 142 private:
okano 11:61a025e8ab68 143 int send_spi( char data );
okano 11:61a025e8ab68 144 void write_register( char reg, char value );
okano 11:61a025e8ab68 145 int read_register( char reg );
okano 11:61a025e8ab68 146 void set_address( int address );
okano 0:f4584dba3bac 147
okano 4:cb0ef3fd89c9 148 SPI _spi;
okano 4:cb0ef3fd89c9 149 DigitalOut _cs;
okano 4:cb0ef3fd89c9 150 DigitalOut _reset;
okano 4:cb0ef3fd89c9 151 I2C _i2c;
okano 8:23d14d5254d2 152 int _error_state;
okano 0:f4584dba3bac 153 };
okano 0:f4584dba3bac 154
okano 0:f4584dba3bac 155 #endif // MBED_MARY_CAMERA