MARMEX-VB : "Mary Camera module" library
Dependents: MARMEX_VB_test MARMEX_VB_Hello
MARMEX-VB (MARY-VB) camera module library for mbed. (This module may be available in Japan only.)
Kown problem / 既知の問題
The read data may have contouring. In this case, it may require reset or changing order of data reading. The order change API is available as "read_order_change()" function.
カメラから読み出したデータに擬似輪郭が発生することがあります.この問題にはシステム全体のリセットを行うか,または読み出し順の変更を行うことで対処して下さい.読み出し順の変更はAPIの"read_order_change()"関数を使うことができます.
Revision 4:8ef31b67c0ab, committed 2014-06-19
- Comitter:
- nxpfan
- Date:
- Thu Jun 19 12:21:43 2014 +0000
- Parent:
- 3:7f26004cfbce
- Child:
- 5:84e6c89a9a6d
- Commit message:
- optimized SPI : FIFO
Changed in this revision
MARMEX_VB.cpp | Show annotated file Show diff for this revision Revisions of this file |
MARMEX_VB.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MARMEX_VB.cpp Mon Jun 16 14:02:58 2014 +0000 +++ b/MARMEX_VB.cpp Thu Jun 19 12:21:43 2014 +0000 @@ -1,8 +1,8 @@ /** MARMEX_VB Camera control library * * @class MARMEX_VB - * @version 0.3 - * @date 16-Jun-2014 + * @version 0.4 + * @date 19-Jun-2014 * * Released under the Apache License, Version 2.0 : http://mbed.org/handbook/Apache-Licence * @@ -275,7 +275,7 @@ } else { #define OPTIMIZE_KEEP_ASSERTING_CS_DURING_LINE_DATA_TRANSFER -#ifdef OPTIMIZE_KEEP_ASSERTING_CS_DURING_LINE_DATA_TRANSFER +#ifdef OPTIMIZE_KEEP_ASSERTING_CS_DURING_LINE_DATA_TRANSFER // optimized by IO register access and loop unroll _cs = 0; @@ -321,6 +321,91 @@ #endif } + + + +void MARMEX_VB::read_a_line_SPI_FIFO_READ( short *p, int line_number, int x_offset, int n_of_pixels ) +{ +#define FIFO_DEPTH 4 + +#ifdef TARGET_MBED_LPC1768 +#define SPI_PORT_SELECTOR LPC_SSP1 +#endif + +#ifdef TARGET_LPC11U35_501 +#define SPI_PORT_SELECTOR LPC_SSP0 +#endif + +#ifdef TARGET_LPC11U24_401 +#define SPI_PORT_SELECTOR LPC_SSP0 +#endif + + char reg = COMMAND_READ | CAMERA_DATA_REGISTER | COMMAND_ADDR_INCREMENT; + int n; + + if ( line_number < 0 ) + return; + + // set camera module's buffer address + set_address( line_number * get_horizontal_size() * BYTE_PER_PIXEL + x_offset * BYTE_PER_PIXEL ); + + // put a read command, first return byte should be ignored + read_register( CAMERA_DATA_REGISTER ); + + + // optimized by SPI-FIFO access + + if ( _read_order_change ) { + _cs = 0; + + for(n = FIFO_DEPTH; n > 0; n--) { + SPI_PORT_SELECTOR->DR = reg; + } + + do { + while (!(SPI_PORT_SELECTOR->SR & 0x4)); + *p = (SPI_PORT_SELECTOR->DR & 0xFF); + + if (n++ < (n_of_pixels << 1) - FIFO_DEPTH) + SPI_PORT_SELECTOR->DR = reg; + + while (!(SPI_PORT_SELECTOR->SR & 0x4)); + *p++ |= (SPI_PORT_SELECTOR->DR << 8); + + if (n++ < (n_of_pixels << 1) - FIFO_DEPTH) + SPI_PORT_SELECTOR->DR = reg; + + } while(n < (n_of_pixels << 1)); + + _cs = 1; + } else { + read_register( CAMERA_DATA_REGISTER ); + + _cs = 0; + + for(n = FIFO_DEPTH; n > 0; n--) { + SPI_PORT_SELECTOR->DR = reg; + } + + do { + while (!(SPI_PORT_SELECTOR->SR & 0x4)); + *p = (SPI_PORT_SELECTOR->DR << 8); + + if (n++ < (n_of_pixels << 1) - FIFO_DEPTH) + SPI_PORT_SELECTOR->DR = reg; + + while (!(SPI_PORT_SELECTOR->SR & 0x4)); + *p++ |= (SPI_PORT_SELECTOR->DR & 0xFF); + + if (n++ < (n_of_pixels << 1) - FIFO_DEPTH) + SPI_PORT_SELECTOR->DR = reg; + + } while(n < (n_of_pixels << 1)); + + _cs = 1; + } +} + void MARMEX_VB::open_transfer( void ) { // send command to pause the camera buffer update
--- a/MARMEX_VB.h Mon Jun 16 14:02:58 2014 +0000 +++ b/MARMEX_VB.h Thu Jun 19 12:21:43 2014 +0000 @@ -8,7 +8,7 @@ * * MARMEX_VB Camera control library for mbed */ - + #ifndef MBED_MARMEX_VB #define MBED_MARMEX_VB @@ -56,6 +56,8 @@ * @endcode */ +#define OPTIMIZATION_ENABLED + #define DEFAULT_PICTURE_SIZE QCIF //#define DEFAULT_PICTURE_SIZE VGA //#define DEFAULT_PICTURE_SIZE QVGA @@ -183,6 +185,22 @@ * @param n_of_pixels pixels to be read */ void read_a_line( short *p, int line_number, int x_offset, int n_of_pixels ); + + /** Read one line data + * + * Reads 1 line data from MARMEX_VB + * This function should be called when the data transfer done to resume the buffer update by camera + * + * This function is highly optimized for LPC1768 and LPC11U35 with a specific SPI port + * LPC1768 : LPC_SSP1 + * LPC11U35 : LPC_SSP0 + * + * @param *p pointer to array of short + * @param line_number to select which line want to read + * @param x_offset holizontal offset (from left) to start the read + * @param n_of_pixels pixels to be read + */ + void read_a_line_SPI_FIFO_READ( short *p, int line_number, int x_offset, int n_of_pixels ); /** Read order change *