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.
MARY_CAMERA.h@4:cb0ef3fd89c9, 2014-02-17 (annotated)
- Committer:
- okano
- Date:
- Mon Feb 17 23:44:08 2014 +0000
- Revision:
- 4:cb0ef3fd89c9
- Parent:
- 3:e5752853eb26
- Child:
- 5:960221bde814
- Child:
- 7:942d8d0a1760
add comments, cleaned-up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 4:cb0ef3fd89c9 | 1 | #ifndef MBED_MARY_CAMERA |
okano | 4:cb0ef3fd89c9 | 2 | #define MBED_MARY_CAMERA |
okano | 0:f4584dba3bac | 3 | |
okano | 4:cb0ef3fd89c9 | 4 | #define SPI_FREQUENCY 12000000 |
okano | 0:f4584dba3bac | 5 | |
okano | 0:f4584dba3bac | 6 | |
okano | 4:cb0ef3fd89c9 | 7 | /** MARY_CAMERA class |
okano | 4:cb0ef3fd89c9 | 8 | * |
okano | 4:cb0ef3fd89c9 | 9 | * MARY_CAMERA driver library |
okano | 4:cb0ef3fd89c9 | 10 | * This driver has been made to get camera data from MARY CAMERA. |
okano | 4:cb0ef3fd89c9 | 11 | * |
okano | 4:cb0ef3fd89c9 | 12 | * Example: |
okano | 4:cb0ef3fd89c9 | 13 | * @code |
okano | 4:cb0ef3fd89c9 | 14 | * |
okano | 4:cb0ef3fd89c9 | 15 | * #include "mbed.h" |
okano | 4:cb0ef3fd89c9 | 16 | * #include "MARMEX_OB_oled.h" |
okano | 4:cb0ef3fd89c9 | 17 | * #include "MARY_CAMERA.h" |
okano | 4:cb0ef3fd89c9 | 18 | * |
okano | 4:cb0ef3fd89c9 | 19 | * MARMEX_OB_oled oled1( p5, p7, p20, p16, p15 ); // mosi, sclk, cs, rst, power_control -- maple-mini-type-b-slot1 |
okano | 4:cb0ef3fd89c9 | 20 | * MARY_CAMERA camera( p5, p6, p7, p22, p26, p28, p27 ); // mosi, miso, sclk, cs, reset, I2C_SDA, I2C_SCL |
okano | 4:cb0ef3fd89c9 | 21 | * BusOut led( LED3, LED4 ); |
okano | 4:cb0ef3fd89c9 | 22 | * |
okano | 4:cb0ef3fd89c9 | 23 | * #define X_OFFSET ((MARY_CAMERA::PIXEL_PER_LINE - MARMEX_OB_oled::WIDTH ) / 2) |
okano | 4:cb0ef3fd89c9 | 24 | * #define Y_OFFSET ((MARY_CAMERA::LINE_PER_FRAME - MARMEX_OB_oled::HEIGHT) / 2) |
okano | 4:cb0ef3fd89c9 | 25 | * |
okano | 4:cb0ef3fd89c9 | 26 | * int main() |
okano | 4:cb0ef3fd89c9 | 27 | * { |
okano | 4:cb0ef3fd89c9 | 28 | * led = 0x3; |
okano | 4:cb0ef3fd89c9 | 29 | * |
okano | 4:cb0ef3fd89c9 | 30 | * oled1.cls(); |
okano | 4:cb0ef3fd89c9 | 31 | * |
okano | 4:cb0ef3fd89c9 | 32 | * short buf[ MARMEX_OB_oled::WIDTH ]; |
okano | 4:cb0ef3fd89c9 | 33 | * |
okano | 4:cb0ef3fd89c9 | 34 | * while ( 1 ) { |
okano | 4:cb0ef3fd89c9 | 35 | * |
okano | 4:cb0ef3fd89c9 | 36 | * led = 0x1; |
okano | 4:cb0ef3fd89c9 | 37 | * camera.open_transfer(); |
okano | 4:cb0ef3fd89c9 | 38 | * |
okano | 4:cb0ef3fd89c9 | 39 | * for ( int line = 0; line < 128; line++ ) { |
okano | 4:cb0ef3fd89c9 | 40 | * camera.transfer_a_line( buf, line + Y_OFFSET, X_OFFSET, 128 ); |
okano | 4:cb0ef3fd89c9 | 41 | * oled1.blit565( 0, line, 128, 1, buf ); |
okano | 4:cb0ef3fd89c9 | 42 | * } |
okano | 4:cb0ef3fd89c9 | 43 | * |
okano | 4:cb0ef3fd89c9 | 44 | * camera.close_transfer(); |
okano | 4:cb0ef3fd89c9 | 45 | * led = 0x2; |
okano | 4:cb0ef3fd89c9 | 46 | * } |
okano | 4:cb0ef3fd89c9 | 47 | * } |
okano | 4:cb0ef3fd89c9 | 48 | * @endcode |
okano | 4:cb0ef3fd89c9 | 49 | */ |
okano | 4:cb0ef3fd89c9 | 50 | |
okano | 4:cb0ef3fd89c9 | 51 | |
okano | 0:f4584dba3bac | 52 | class MARY_CAMERA |
okano | 0:f4584dba3bac | 53 | { |
okano | 0:f4584dba3bac | 54 | public: |
okano | 0:f4584dba3bac | 55 | |
okano | 4:cb0ef3fd89c9 | 56 | /** General parameters for MARMEX_OB_oled */ |
okano | 4:cb0ef3fd89c9 | 57 | enum { |
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 | 4:cb0ef3fd89c9 | 60 | BYTE_PER_PIXEL = 2, /**< bytes per pixel */ |
okano | 4:cb0ef3fd89c9 | 61 | BYTE_PER_LINE = (PIXEL_PER_LINE * BYTE_PER_PIXEL) /**< data size of 1 line */ |
okano | 4:cb0ef3fd89c9 | 62 | }; |
okano | 4:cb0ef3fd89c9 | 63 | |
okano | 4:cb0ef3fd89c9 | 64 | /** Create a MARY_CAMERA instance connected to specified SPI, DigitalOut and I2C pins |
okano | 0:f4584dba3bac | 65 | * |
okano | 4:cb0ef3fd89c9 | 66 | * @param SPI_mosi SPI-bus MOSI pin |
okano | 4:cb0ef3fd89c9 | 67 | * @param SPI_miso SPI-bus MISO pin |
okano | 4:cb0ef3fd89c9 | 68 | * @param SPI_sclk SPI-bus SCLK pin |
okano | 4:cb0ef3fd89c9 | 69 | * @param SPI_cs SPI-bus Chip Select pin |
okano | 4:cb0ef3fd89c9 | 70 | * @param cam_reset Camera reset pin |
okano | 4:cb0ef3fd89c9 | 71 | * @param I2C_sda I2C-bus SDA pin |
okano | 4:cb0ef3fd89c9 | 72 | * @param I2C_scl I2C-bus SCL pin |
okano | 0:f4584dba3bac | 73 | */ |
okano | 0:f4584dba3bac | 74 | |
okano | 0:f4584dba3bac | 75 | MARY_CAMERA( |
okano | 4:cb0ef3fd89c9 | 76 | PinName SPI_mosi, |
okano | 4:cb0ef3fd89c9 | 77 | PinName SPI_miso, |
okano | 4:cb0ef3fd89c9 | 78 | PinName SPI_sck, |
okano | 4:cb0ef3fd89c9 | 79 | PinName SPI_cs, |
okano | 0:f4584dba3bac | 80 | PinName cam_reset, |
okano | 4:cb0ef3fd89c9 | 81 | PinName I2C_sda, |
okano | 4:cb0ef3fd89c9 | 82 | PinName I2C_scl |
okano | 0:f4584dba3bac | 83 | ); |
okano | 4:cb0ef3fd89c9 | 84 | |
okano | 4:cb0ef3fd89c9 | 85 | /** Initialization |
okano | 4:cb0ef3fd89c9 | 86 | * |
okano | 4:cb0ef3fd89c9 | 87 | * Performs MARY_CAMERA reset and initializations |
okano | 4:cb0ef3fd89c9 | 88 | * This function is called from MARY_CAMERA constoructor. So user don't have to call in the user code. |
okano | 4:cb0ef3fd89c9 | 89 | * |
okano | 4:cb0ef3fd89c9 | 90 | * This function takes about 2 seconds because there is 99 times I2C access with 20ms interval. |
okano | 4:cb0ef3fd89c9 | 91 | */ |
okano | 0:f4584dba3bac | 92 | void init( void ); |
okano | 4:cb0ef3fd89c9 | 93 | |
okano | 4:cb0ef3fd89c9 | 94 | /** Open transfer |
okano | 4:cb0ef3fd89c9 | 95 | * |
okano | 4:cb0ef3fd89c9 | 96 | * Let the MARY_CAMERA get ready to transfer the data. |
okano | 4:cb0ef3fd89c9 | 97 | * When this function is called, the camera will stop updating buffer at end of frame. |
okano | 4:cb0ef3fd89c9 | 98 | */ |
okano | 0:f4584dba3bac | 99 | void open_transfer( void ); |
okano | 4:cb0ef3fd89c9 | 100 | |
okano | 4:cb0ef3fd89c9 | 101 | /** Close transfer |
okano | 4:cb0ef3fd89c9 | 102 | * |
okano | 4:cb0ef3fd89c9 | 103 | * Letting the MARY_CAMERA to know the data transfer done. |
okano | 4:cb0ef3fd89c9 | 104 | * This function should be called when the data transfer done to resume the buffer update by camera |
okano | 4:cb0ef3fd89c9 | 105 | */ |
okano | 0:f4584dba3bac | 106 | void close_transfer( void ); |
okano | 4:cb0ef3fd89c9 | 107 | |
okano | 4:cb0ef3fd89c9 | 108 | /** Transfer a line |
okano | 4:cb0ef3fd89c9 | 109 | * |
okano | 4:cb0ef3fd89c9 | 110 | * Reads 1 line data from MARY_CAMERA |
okano | 4:cb0ef3fd89c9 | 111 | * This function should be called when the data transfer done to resume the buffer update by camera |
okano | 4:cb0ef3fd89c9 | 112 | * |
okano | 4:cb0ef3fd89c9 | 113 | * @param *p pointer to array of short |
okano | 4:cb0ef3fd89c9 | 114 | * @param line_number to select which line want to read |
okano | 4:cb0ef3fd89c9 | 115 | * @param x_offset holizontal offset (from left) to start the read |
okano | 4:cb0ef3fd89c9 | 116 | * @param n_of_pixels pixels to be read |
okano | 4:cb0ef3fd89c9 | 117 | */ |
okano | 0:f4584dba3bac | 118 | void transfer_a_line( short *p, int line_number, int x_offset, int n_of_pixels ); |
okano | 0:f4584dba3bac | 119 | |
okano | 0:f4584dba3bac | 120 | private: |
okano | 0:f4584dba3bac | 121 | int send_spi( char data ); |
okano | 0:f4584dba3bac | 122 | void write_register( char reg, char value ); |
okano | 0:f4584dba3bac | 123 | int read_register( char reg ); |
okano | 0:f4584dba3bac | 124 | void set_address( int address ); |
okano | 0:f4584dba3bac | 125 | |
okano | 4:cb0ef3fd89c9 | 126 | SPI _spi; |
okano | 4:cb0ef3fd89c9 | 127 | DigitalOut _cs; |
okano | 4:cb0ef3fd89c9 | 128 | DigitalOut _reset; |
okano | 4:cb0ef3fd89c9 | 129 | I2C _i2c; |
okano | 0:f4584dba3bac | 130 | }; |
okano | 0:f4584dba3bac | 131 | |
okano | 0:f4584dba3bac | 132 | |
okano | 0:f4584dba3bac | 133 | |
okano | 0:f4584dba3bac | 134 | #endif // MBED_MARY_CAMERA |