mbed serial interface for the OV528 camera (uCAM TTL 120 from 4D systems).

Dependencies:   MODSERIAL

Dependents:   mbed_uCAM_TTL120_20141118

Library for interfacing the mbed to the OV528 jpeg engine camera from Omnivision. I tested this program using the uCAM TTL 120 from 4D systems, now obsolete.

/media/uploads/jebradshaw/pic0003.jpg

Above is a saved jpeg image from the camera at 480x640 resolution

/media/uploads/jebradshaw/fullsizerender.jpg

Camera and TFT screen setup

/media/uploads/jebradshaw/tft_closeup_60x80.jpg

Closeup of the TFT screen displaying a 60x80 pixel 16 bit color bitmap image. The RGB (565) pixel colors were reversed when read from the camera relative to the TFT screen so a bit mask and shift had to be applied when displaying the pixel color.

bit mask and shift

         int k=12;
         for(int i=0;i<60;i++){
                for(int j=0;j<80;j++){                    
                    //returned 16-bit color is 565(RGB)
                     pixel_col = (imageData[k] << 8);
                     k++;                       
                     pixel_col += imageData[k];
                     k++;
//                 fputc(((picture[k] >> 8) & 0xff), fp);     //write pixel high byte to file 
//                 fputc(picture[k] & 0xff, fp);                 //write low byte
                                        
                //swap R and B bits in returned pixel for TFT display
                int TFT_pix_col = 0;
                TFT_pix_col += (pixel_col & 0x001f) << 11;
                TFT_pix_col += (pixel_col & 0xf800) >> 11;
                TFT_pix_col += (pixel_col & 0x07e0);
                                        
                 TFT.pixel(j, i, TFT_pix_col);  //Do something with the pixel
                }
             }

uCAM_TTL120.h

Committer:
jebradshaw
Date:
2014-11-26
Revision:
3:85db6ea8c0a4
Parent:
2:f80257456c6e

File content as of revision 3:85db6ea8c0a4:

// uCAM TTL(120) jpeg camera class for mbed
// J. Bradshaw 20141106

#include "mbed.h"
//define larger buffers for return packets
#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 1024
#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE 1024 
#include "MODSERIAL.h"

#ifndef uCAM_TTL120_H
#define uCAM_TTL120_H

//uCAM command defines, page 8 of uCAM manual
#define uCAM_INITIAL            0xAA01
#define uCAM_GET_PICTURE        0xAA04
#define uCAM_SNAPSHOT           0xAA05
#define uCAM_SET_PACKAGE_SIZE   0xAA06
#define uCAM_SET_BAUD_RATE      0xAA07
#define uCAM_RESET              0xAA08
#define uCAM_DATA               0xAA0A
#define uCAM_SYNC               0xAA0D
#define uCAM_ACK                0xAA0E
#define uCAM_NAK                00xAA0F
#define uCAM_LIGHT              0xAA13

/**
 * uCAM_TTL120 Class.
 */
 
class uCAM_TTL120{
public:
    /**
     * Constructor.
     * @param tx - Serial port transmit pin
     * @param rx - Serial port recieve pin
     */ 
    uCAM_TTL120(PinName tx, PinName rx);
    int uCAM_read(char *str, int numchars, float timeout);

    void uCAM_Command_Send(int command,char p1,char p2,char p3,char p4);
    int uCAM_GetACK(int command);
    int uCAM_Connect(void);
    void uCAM_FlushBuffer(void);
    int uCAM_send_INITIAL_80x60_16RAW(void);
    int uCAM_send_INITIAL_80x60_2RAW(void);
    int uCAM_send_INITIAL_128x128_4RAW(void);
    int uCAM_send_SNAPSHOT(void);
    int uCAM_send_GET_PICTURE_80x60_16COL_RAW(FILE *fp);
    int uCAM_send_GET_PICTURE_80x60_2GRAY_RAW(void);
    int uCAM_send_GET_PICTURE_128x128_4GRAY_RAW(void);
    
    void uCAM_TakePic_RAW_16COLOR_80x60(FILE *fp);
    void uCAM_TakePic_RAW_2GRAY_80x60(void);
    void uCAM_TakePic_RAW_4GRAY_128x128(void);

    int uCAM_get_jpeg(FILE *fp);

    void uCAM_set_baud(void);

    char picture[10000];
    MODSERIAL _cam;
private:    
    Timer *timerCam; 
};

#endif /* uCAM_TTL120_H */