test

Fork of CameraC1098 by Tadao Iida

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CameraC1098.h Source File

CameraC1098.h

00001 /**
00002  * C1098-SS device driver class (Version 1.0)
00003  * Reference documents: C1098-SS User Manual v1.0 2012.5.6
00004  *
00005  * CameraC328Library
00006  * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
00007  * http://shinta.main.jp/
00008  *
00009  * CameraC1098-SS Library
00010  * Copyright (C) 2012 Tadao Iida
00011  */
00012 
00013 #include "mbed.h"
00014 #include "SerialBuffered.h"
00015 
00016 #ifndef _CAMERA_C1098_H_
00017 #define _CAMERA_C1098_H_
00018 
00019 /*
00020  * Class: CameraC1098
00021  */
00022  
00023 class CameraC1098 {
00024 public:
00025 
00026     /**
00027      * @enum JPEG resolution.
00028      */
00029     enum JpegResolution {
00030          JpegResolution80x64 = 0x01,   // unofficial
00031          JpegResolution160x128 = 0x03, // unofficial
00032          JpegResolution320x240 = 0x05, // QVGA
00033          JpegResolution640x480 = 0x07  // VGA
00034     };
00035 
00036     /**
00037      * @enum Error number.
00038      */
00039     enum ErrorNumber {
00040         NoError = 0x00,
00041         UnexpectedReply = 0x04,
00042         ParameterError = 0x0b,
00043         SendRegisterTimeout = 0x0c,
00044         CommandIdError = 0x0d,
00045         CommandHeaderError = 0xf0,
00046         SetTransferPackageSizeWrong = 0x11
00047     };
00048 
00049     /**
00050      * @enum Baud rate.
00051      */
00052     enum Baud {
00053         Baud460800 = 0x02,
00054         Baud230400 = 0x03,
00055         Baud115200 = 0x04,
00056         Baud57600  = 0x05,
00057         Baud28800  = 0x06,
00058         Baud14400  = 0x07  // Default. 
00059     };
00060 
00061     /**
00062      *  @enum Reset type.
00063      */
00064     enum ResetType {
00065         Nomal = 0x00,
00066         High  = 0xff
00067     };
00068 
00069     /** Constructor.
00070      *
00071      * @param tx A pin for transmit.
00072      * @param rx A pin for receive.
00073      * @param baud Baud rate. (Default is 14400.)
00074      */
00075     CameraC1098(PinName tx, PinName rx, int baud = 14400);
00076 
00077     /** Destructor.
00078      * 
00079      */
00080     ~CameraC1098();
00081 
00082     /** sync 
00083      * Make a sync. for baud rate.
00084      */
00085     ErrorNumber sync();
00086 
00087     /** Initialize.
00088      * 
00089      *
00090      * @param baud Camera Interface Speed.
00091      * @param jr JPEG resolution.
00092      */
00093     ErrorNumber init(Baud baud, JpegResolution jr);
00094 
00095     /** getJpegSnapshotPicture
00096      * Get JPEG snapshot picture.
00097      *
00098      * @param func A pointer to a callback function.
00099      *             You can block this function until saving the image datas.
00100      * @return Status of the error.
00101      */
00102     ErrorNumber getJpegSnapshotPicture();
00103 
00104     /** setmbedBaud
00105      *  mbed Interface Speed.
00106      *
00107      *  @param baud mbed Interface Speed.
00108      */
00109     void setmbedBaud(Baud baud);
00110     void Sync(void);
00111     void jpeg_snapshot(int CAPTURE_FRAMES);
00112     ErrorNumber sendReset(ResetType specialReset);  
00113     
00114 private:
00115     SerialBuffered serial;
00116     static const int COMMAND_LENGTH = 6;
00117     static const int SYNCMAX = 60;
00118     static const int packageSize = 256;
00119     ErrorNumber sendInitial(Baud band, JpegResolution jr);
00120     ErrorNumber sendGetPicture(void);
00121     ErrorNumber sendSnapshot(void);    
00122     ErrorNumber sendSetPackageSize(uint16_t packageSize);
00123     //ErrorNumber sendReset(ResetType specialReset);  
00124     ErrorNumber recvData(uint32_t *length);
00125     ErrorNumber sendSync();
00126     ErrorNumber recvSync();
00127     ErrorNumber sendAck(uint8_t commandId, uint16_t packageId);
00128     ErrorNumber recvAckOrNck();
00129 
00130     bool sendBytes(char *buf, size_t len, int timeout_us = 20000);
00131     bool recvBytes(char *buf, size_t len, int timeout_us = 20000);
00132     bool waitRecv();
00133     bool waitIdle();
00134 };
00135 
00136 #endif