Committer:
esmiwa
Date:
Sun Jun 17 01:15:35 2012 +0000
Revision:
0:5bf7e3564c3b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
esmiwa 0:5bf7e3564c3b 1 //CameraC1098.h
esmiwa 0:5bf7e3564c3b 2 //#include "mbed.h"
esmiwa 0:5bf7e3564c3b 3 #include "SerialBuffered.h"
esmiwa 0:5bf7e3564c3b 4
esmiwa 0:5bf7e3564c3b 5 #ifndef _CAMERA_C1098_H_
esmiwa 0:5bf7e3564c3b 6 #define _CAMERA_C1098_H_
esmiwa 0:5bf7e3564c3b 7
esmiwa 0:5bf7e3564c3b 8 // Class: CameraC1098
esmiwa 0:5bf7e3564c3b 9 class CameraC1098 {
esmiwa 0:5bf7e3564c3b 10 public:
esmiwa 0:5bf7e3564c3b 11 /**
esmiwa 0:5bf7e3564c3b 12 * Color type.
esmiwa 0:5bf7e3564c3b 13 */
esmiwa 0:5bf7e3564c3b 14 enum ColorType {
esmiwa 0:5bf7e3564c3b 15 Jpeg = 0x07
esmiwa 0:5bf7e3564c3b 16 };
esmiwa 0:5bf7e3564c3b 17 /**
esmiwa 0:5bf7e3564c3b 18 * JPEG resolution.
esmiwa 0:5bf7e3564c3b 19 */
esmiwa 0:5bf7e3564c3b 20 enum JpegResolution {
esmiwa 0:5bf7e3564c3b 21 JpegResolution320x240 = 0x05,
esmiwa 0:5bf7e3564c3b 22 JpegResolution640x480 = 0x07
esmiwa 0:5bf7e3564c3b 23 };
esmiwa 0:5bf7e3564c3b 24 /**
esmiwa 0:5bf7e3564c3b 25 * Picture type.
esmiwa 0:5bf7e3564c3b 26 */
esmiwa 0:5bf7e3564c3b 27 enum PictureType {
esmiwa 0:5bf7e3564c3b 28 SnapshotPicture = 0x01,
esmiwa 0:5bf7e3564c3b 29 PreviewPicture = 0x02,
esmiwa 0:5bf7e3564c3b 30 JpegPreviewPicture = 0x05
esmiwa 0:5bf7e3564c3b 31 };
esmiwa 0:5bf7e3564c3b 32 /**
esmiwa 0:5bf7e3564c3b 33 * Snapshot type.
esmiwa 0:5bf7e3564c3b 34 */
esmiwa 0:5bf7e3564c3b 35 enum SnapshotType {
esmiwa 0:5bf7e3564c3b 36 CompressedPicture = 0x00,
esmiwa 0:5bf7e3564c3b 37 UncompressedPicture = 0x01
esmiwa 0:5bf7e3564c3b 38 };
esmiwa 0:5bf7e3564c3b 39 /**
esmiwa 0:5bf7e3564c3b 40 * Baud rate.
esmiwa 0:5bf7e3564c3b 41 */
esmiwa 0:5bf7e3564c3b 42 enum Baud {
esmiwa 0:5bf7e3564c3b 43 Baud14400 = 14400, //Default
esmiwa 0:5bf7e3564c3b 44 Baud19200 = 19200,
esmiwa 0:5bf7e3564c3b 45 Baud28800 = 28800,
esmiwa 0:5bf7e3564c3b 46 Baud38400 = 38400,
esmiwa 0:5bf7e3564c3b 47 Baud57600 = 57600,
esmiwa 0:5bf7e3564c3b 48 Baud115200 = 115200, //Default
esmiwa 0:5bf7e3564c3b 49 Baud230400 = 230400,
esmiwa 0:5bf7e3564c3b 50 Baud460800 = 460800
esmiwa 0:5bf7e3564c3b 51 };
esmiwa 0:5bf7e3564c3b 52 /**
esmiwa 0:5bf7e3564c3b 53 * Reset type.
esmiwa 0:5bf7e3564c3b 54 */
esmiwa 0:5bf7e3564c3b 55 enum ResetType {
esmiwa 0:5bf7e3564c3b 56 ResetWholeSystem = 0x00,
esmiwa 0:5bf7e3564c3b 57 ResetStateMachines = 0x01
esmiwa 0:5bf7e3564c3b 58 };
esmiwa 0:5bf7e3564c3b 59 /**
esmiwa 0:5bf7e3564c3b 60 * Data type.
esmiwa 0:5bf7e3564c3b 61 */
esmiwa 0:5bf7e3564c3b 62 enum DataType {
esmiwa 0:5bf7e3564c3b 63 DataTypeSnapshotPicture = 0x01,
esmiwa 0:5bf7e3564c3b 64 DataTypePreviewPicture = 0x02,
esmiwa 0:5bf7e3564c3b 65 DataTypeJpegPreviewPicture = 0x05
esmiwa 0:5bf7e3564c3b 66 };
esmiwa 0:5bf7e3564c3b 67 /**
esmiwa 0:5bf7e3564c3b 68 * Constructor.
esmiwa 0:5bf7e3564c3b 69 *
esmiwa 0:5bf7e3564c3b 70 * @param tx A pin for transmit.
esmiwa 0:5bf7e3564c3b 71 * @param rx A pin for receive.
esmiwa 0:5bf7e3564c3b 72 * @param baud Baud rate. (Default is Baud115200.)
esmiwa 0:5bf7e3564c3b 73 */
esmiwa 0:5bf7e3564c3b 74 //CameraC1098(PinName tx, PinName rx, Baud baud = Baud19200);
esmiwa 0:5bf7e3564c3b 75 CameraC1098(PinName tx, PinName rx, Baud baud = Baud115200);
esmiwa 0:5bf7e3564c3b 76 /**
esmiwa 0:5bf7e3564c3b 77 * Destructor.
esmiwa 0:5bf7e3564c3b 78 */
esmiwa 0:5bf7e3564c3b 79 ~CameraC1098();
esmiwa 0:5bf7e3564c3b 80 /**
esmiwa 0:5bf7e3564c3b 81 * Make a sync. for baud rate.
esmiwa 0:5bf7e3564c3b 82 */
esmiwa 0:5bf7e3564c3b 83 bool sync();
esmiwa 0:5bf7e3564c3b 84 /**
esmiwa 0:5bf7e3564c3b 85 * Initialize.
esmiwa 0:5bf7e3564c3b 86 * @param jr JPEG resolution.
esmiwa 0:5bf7e3564c3b 87 */
esmiwa 0:5bf7e3564c3b 88 bool init(JpegResolution jr);
esmiwa 0:5bf7e3564c3b 89 /**
esmiwa 0:5bf7e3564c3b 90 *set packet size
esmiwa 0:5bf7e3564c3b 91 */
esmiwa 0:5bf7e3564c3b 92 bool setupPackageSize(uint16_t packageSize);
esmiwa 0:5bf7e3564c3b 93 /**
esmiwa 0:5bf7e3564c3b 94 * Get uncompressed snapshot picture.
esmiwa 0:5bf7e3564c3b 95 *
esmiwa 0:5bf7e3564c3b 96 * @param func A pointer to a callback function.
esmiwa 0:5bf7e3564c3b 97 * Please do NOT block this callback function.
esmiwa 0:5bf7e3564c3b 98 * Because the camera module transmit image datas continuously.
esmiwa 0:5bf7e3564c3b 99 * @return Status of the error.
esmiwa 0:5bf7e3564c3b 100 */
esmiwa 0:5bf7e3564c3b 101 bool getUncompressedSnapshotPicture(void(*func)(size_t done, size_t total, char c));
esmiwa 0:5bf7e3564c3b 102 /**
esmiwa 0:5bf7e3564c3b 103 * Get uncompressed preview picture.
esmiwa 0:5bf7e3564c3b 104 *
esmiwa 0:5bf7e3564c3b 105 * @param func A pointer to a callback function.
esmiwa 0:5bf7e3564c3b 106 * Please do NOT block this callback function.
esmiwa 0:5bf7e3564c3b 107 * Because the camera module transmit image datas continuously.
esmiwa 0:5bf7e3564c3b 108 * @return Status of the error.
esmiwa 0:5bf7e3564c3b 109 */
esmiwa 0:5bf7e3564c3b 110 bool getUncompressedPreviewPicture(void(*func)(size_t done, size_t total, char c));
esmiwa 0:5bf7e3564c3b 111 /**
esmiwa 0:5bf7e3564c3b 112 * Get JPEG snapshot picture.
esmiwa 0:5bf7e3564c3b 113 *
esmiwa 0:5bf7e3564c3b 114 * @param func A pointer to a callback function.
esmiwa 0:5bf7e3564c3b 115 * You can block this function until saving the image datas.
esmiwa 0:5bf7e3564c3b 116 * @return Status of the error.
esmiwa 0:5bf7e3564c3b 117 */
esmiwa 0:5bf7e3564c3b 118 // bool getJpegSnapshotPicture(void(*func)(char *buf, size_t siz));
esmiwa 0:5bf7e3564c3b 119 bool getJpegSnapshotPicture(void(*func)(char *buf, size_t siz));
esmiwa 0:5bf7e3564c3b 120 /**
esmiwa 0:5bf7e3564c3b 121 * Get JPEG preview picture.
esmiwa 0:5bf7e3564c3b 122 *
esmiwa 0:5bf7e3564c3b 123 * @param func A pointer to a callback function.
esmiwa 0:5bf7e3564c3b 124 * You can block this function until saving the image datas.
esmiwa 0:5bf7e3564c3b 125 * @return Status of the error.
esmiwa 0:5bf7e3564c3b 126 */
esmiwa 0:5bf7e3564c3b 127 bool getJpegPreviewPicture(void(*func)(char *buf, size_t siz));
esmiwa 0:5bf7e3564c3b 128 //NEW
esmiwa 0:5bf7e3564c3b 129 bool getnewbaud();
esmiwa 0:5bf7e3564c3b 130
esmiwa 0:5bf7e3564c3b 131 private:
esmiwa 0:5bf7e3564c3b 132 SerialBuffered serial;
esmiwa 0:5bf7e3564c3b 133 static const int COMMAND_LENGTH = 6;
esmiwa 0:5bf7e3564c3b 134 static const int SYNCMAX = 60;
esmiwa 0:5bf7e3564c3b 135 static const int packageSize = 512;
esmiwa 0:5bf7e3564c3b 136
esmiwa 0:5bf7e3564c3b 137 bool sendInitial(JpegResolution jr);
esmiwa 0:5bf7e3564c3b 138 bool sendGetPicture(PictureType pt);
esmiwa 0:5bf7e3564c3b 139 bool sendSnapshot(SnapshotType st, uint16_t skipFrames);
esmiwa 0:5bf7e3564c3b 140 bool sendSetPackageSize(uint16_t packageSize);
esmiwa 0:5bf7e3564c3b 141 // bool sendSetBaudrate(Baud baud);
esmiwa 0:5bf7e3564c3b 142 bool sendReset(ResetType rt, bool specialReset);
esmiwa 0:5bf7e3564c3b 143 bool sendPowerOff();
esmiwa 0:5bf7e3564c3b 144 bool recvData(DataType *dt, uint32_t *length);
esmiwa 0:5bf7e3564c3b 145 bool sendSync();
esmiwa 0:5bf7e3564c3b 146 bool recvSync();
esmiwa 0:5bf7e3564c3b 147 bool sendAck(uint8_t commandId, uint16_t packageId);
esmiwa 0:5bf7e3564c3b 148 bool recvAckOrNck();
esmiwa 0:5bf7e3564c3b 149
esmiwa 0:5bf7e3564c3b 150 bool sendBytes(char *buf, size_t len, int timeout_us = 20000);
esmiwa 0:5bf7e3564c3b 151 bool recvBytes(char *buf, size_t len, int timeout_us = 20000);
esmiwa 0:5bf7e3564c3b 152 bool waitRecv();
esmiwa 0:5bf7e3564c3b 153 bool waitIdle();
esmiwa 0:5bf7e3564c3b 154 //NEW
esmiwa 0:5bf7e3564c3b 155 bool newbaud();
esmiwa 0:5bf7e3564c3b 156 };
esmiwa 0:5bf7e3564c3b 157
esmiwa 0:5bf7e3564c3b 158 #endif