Mitesh Patel
/
CameraC328_TestProgram1
CameraC328/CameraC328.h@1:78aaadfd1ece, 2010-12-14 (annotated)
- Committer:
- mitesh2patel
- Date:
- Tue Dec 14 13:27:41 2010 +0000
- Revision:
- 1:78aaadfd1ece
- Parent:
- 0:162e214baa3d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mitesh2patel | 0:162e214baa3d | 1 | /** |
mitesh2patel | 0:162e214baa3d | 2 | * C328-7640 device driver class (Version 0.0.6) |
mitesh2patel | 0:162e214baa3d | 3 | * Reference documents: C328-7640 User Manual v3.0 2004.8.19 |
mitesh2patel | 0:162e214baa3d | 4 | * |
mitesh2patel | 0:162e214baa3d | 5 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
mitesh2patel | 0:162e214baa3d | 6 | * http://shinta.main.jp/ |
mitesh2patel | 0:162e214baa3d | 7 | */ |
mitesh2patel | 0:162e214baa3d | 8 | |
mitesh2patel | 0:162e214baa3d | 9 | #include "mbed.h" |
mitesh2patel | 0:162e214baa3d | 10 | #include "SerialBuffered.h" |
mitesh2patel | 0:162e214baa3d | 11 | |
mitesh2patel | 0:162e214baa3d | 12 | #ifndef _CAMERA_C328_H_ |
mitesh2patel | 0:162e214baa3d | 13 | #define _CAMERA_C328_H_ |
mitesh2patel | 0:162e214baa3d | 14 | |
mitesh2patel | 0:162e214baa3d | 15 | /* |
mitesh2patel | 0:162e214baa3d | 16 | * Class: CameraC328 |
mitesh2patel | 0:162e214baa3d | 17 | */ |
mitesh2patel | 0:162e214baa3d | 18 | class CameraC328 { |
mitesh2patel | 0:162e214baa3d | 19 | public: |
mitesh2patel | 0:162e214baa3d | 20 | |
mitesh2patel | 0:162e214baa3d | 21 | /** |
mitesh2patel | 0:162e214baa3d | 22 | * Color type. |
mitesh2patel | 0:162e214baa3d | 23 | */ |
mitesh2patel | 0:162e214baa3d | 24 | enum ColorType { |
mitesh2patel | 0:162e214baa3d | 25 | GrayScale2bit = 0x01, // 2bit for Y only |
mitesh2patel | 0:162e214baa3d | 26 | GrayScale4bit = 0x02, // 4bit for Y only |
mitesh2patel | 0:162e214baa3d | 27 | GrayScale8bit = 0x03, // 8bit for Y only |
mitesh2patel | 0:162e214baa3d | 28 | Color12bit = 0x05, // 444 (RGB) |
mitesh2patel | 0:162e214baa3d | 29 | Color16bit = 0x06, // 565 (RGB) |
mitesh2patel | 0:162e214baa3d | 30 | Jpeg = 0x07 |
mitesh2patel | 0:162e214baa3d | 31 | }; |
mitesh2patel | 0:162e214baa3d | 32 | |
mitesh2patel | 0:162e214baa3d | 33 | /** |
mitesh2patel | 0:162e214baa3d | 34 | * Raw resolution. |
mitesh2patel | 0:162e214baa3d | 35 | */ |
mitesh2patel | 0:162e214baa3d | 36 | enum RawResolution { |
mitesh2patel | 0:162e214baa3d | 37 | RawResolution80x60 = 0x01, |
mitesh2patel | 0:162e214baa3d | 38 | RawResolution160x120 = 0x03 |
mitesh2patel | 0:162e214baa3d | 39 | }; |
mitesh2patel | 0:162e214baa3d | 40 | |
mitesh2patel | 0:162e214baa3d | 41 | /** |
mitesh2patel | 0:162e214baa3d | 42 | * JPEG resolution. |
mitesh2patel | 0:162e214baa3d | 43 | */ |
mitesh2patel | 0:162e214baa3d | 44 | enum JpegResolution { |
mitesh2patel | 0:162e214baa3d | 45 | JpegResolution80x64 = 0x01, |
mitesh2patel | 0:162e214baa3d | 46 | JpegResolution160x128 = 0x03, |
mitesh2patel | 0:162e214baa3d | 47 | JpegResolution320x240 = 0x05, |
mitesh2patel | 0:162e214baa3d | 48 | JpegResolution640x480 = 0x07 |
mitesh2patel | 0:162e214baa3d | 49 | }; |
mitesh2patel | 0:162e214baa3d | 50 | |
mitesh2patel | 0:162e214baa3d | 51 | /** |
mitesh2patel | 0:162e214baa3d | 52 | * Error number. |
mitesh2patel | 0:162e214baa3d | 53 | */ |
mitesh2patel | 0:162e214baa3d | 54 | enum ErrorNumber { |
mitesh2patel | 0:162e214baa3d | 55 | NoError = 0x00, |
mitesh2patel | 0:162e214baa3d | 56 | PictureTypeError = 0x01, |
mitesh2patel | 0:162e214baa3d | 57 | PictureUpScale = 0x02, |
mitesh2patel | 0:162e214baa3d | 58 | PictureScaleError = 0x03, |
mitesh2patel | 0:162e214baa3d | 59 | UnexpectedReply = 0x04, |
mitesh2patel | 0:162e214baa3d | 60 | SendPictureTimeout = 0x05, |
mitesh2patel | 0:162e214baa3d | 61 | UnexpectedCommand = 0x06, |
mitesh2patel | 0:162e214baa3d | 62 | SramJpegTypeError = 0x07, |
mitesh2patel | 0:162e214baa3d | 63 | SramJpegSizeError = 0x08, |
mitesh2patel | 0:162e214baa3d | 64 | PictureFormatError = 0x09, |
mitesh2patel | 0:162e214baa3d | 65 | PictureSizeError = 0x0a, |
mitesh2patel | 0:162e214baa3d | 66 | ParameterError = 0x0b, |
mitesh2patel | 0:162e214baa3d | 67 | SendRegisterTimeout = 0x0c, |
mitesh2patel | 0:162e214baa3d | 68 | CommandIdError = 0x0d, |
mitesh2patel | 0:162e214baa3d | 69 | PictureNotReady = 0x0f, |
mitesh2patel | 0:162e214baa3d | 70 | TransferPackageNumberError = 0x10, |
mitesh2patel | 0:162e214baa3d | 71 | SetTransferPackageSizeWrong = 0x11, |
mitesh2patel | 0:162e214baa3d | 72 | CommandHeaderError = 0xf0, |
mitesh2patel | 0:162e214baa3d | 73 | CommandLengthError = 0xf1, |
mitesh2patel | 0:162e214baa3d | 74 | SendPictureError = 0xf5, |
mitesh2patel | 0:162e214baa3d | 75 | SendCommandError = 0xff |
mitesh2patel | 0:162e214baa3d | 76 | }; |
mitesh2patel | 0:162e214baa3d | 77 | |
mitesh2patel | 0:162e214baa3d | 78 | /** |
mitesh2patel | 0:162e214baa3d | 79 | * Picture type. |
mitesh2patel | 0:162e214baa3d | 80 | */ |
mitesh2patel | 0:162e214baa3d | 81 | enum PictureType { |
mitesh2patel | 0:162e214baa3d | 82 | SnapshotPicture = 0x01, |
mitesh2patel | 0:162e214baa3d | 83 | PreviewPicture = 0x02, |
mitesh2patel | 0:162e214baa3d | 84 | JpegPreviewPicture = 0x05 |
mitesh2patel | 0:162e214baa3d | 85 | }; |
mitesh2patel | 0:162e214baa3d | 86 | |
mitesh2patel | 0:162e214baa3d | 87 | /** |
mitesh2patel | 0:162e214baa3d | 88 | * Snapshot type. |
mitesh2patel | 0:162e214baa3d | 89 | */ |
mitesh2patel | 0:162e214baa3d | 90 | enum SnapshotType { |
mitesh2patel | 0:162e214baa3d | 91 | CompressedPicture = 0x00, |
mitesh2patel | 0:162e214baa3d | 92 | UncompressedPicture = 0x01 |
mitesh2patel | 0:162e214baa3d | 93 | }; |
mitesh2patel | 0:162e214baa3d | 94 | |
mitesh2patel | 0:162e214baa3d | 95 | /** |
mitesh2patel | 0:162e214baa3d | 96 | * Baud rate. |
mitesh2patel | 0:162e214baa3d | 97 | */ |
mitesh2patel | 0:162e214baa3d | 98 | enum Baud { |
mitesh2patel | 0:162e214baa3d | 99 | Baud7200 = 7200, |
mitesh2patel | 0:162e214baa3d | 100 | Baud9600 = 9600, |
mitesh2patel | 0:162e214baa3d | 101 | Baud14400 = 14400, |
mitesh2patel | 0:162e214baa3d | 102 | Baud19200 = 19200, // Default. |
mitesh2patel | 0:162e214baa3d | 103 | Baud28800 = 28800, |
mitesh2patel | 0:162e214baa3d | 104 | Baud38400 = 38400, |
mitesh2patel | 0:162e214baa3d | 105 | Baud57600 = 57600, |
mitesh2patel | 0:162e214baa3d | 106 | Baud115200 = 115200 |
mitesh2patel | 0:162e214baa3d | 107 | }; |
mitesh2patel | 0:162e214baa3d | 108 | |
mitesh2patel | 0:162e214baa3d | 109 | /** |
mitesh2patel | 0:162e214baa3d | 110 | * Reset type. |
mitesh2patel | 0:162e214baa3d | 111 | */ |
mitesh2patel | 0:162e214baa3d | 112 | enum ResetType { |
mitesh2patel | 0:162e214baa3d | 113 | ResetWholeSystem = 0x00, |
mitesh2patel | 0:162e214baa3d | 114 | ResetStateMachines = 0x01 |
mitesh2patel | 0:162e214baa3d | 115 | }; |
mitesh2patel | 0:162e214baa3d | 116 | |
mitesh2patel | 0:162e214baa3d | 117 | /** |
mitesh2patel | 0:162e214baa3d | 118 | * Data type. |
mitesh2patel | 0:162e214baa3d | 119 | */ |
mitesh2patel | 0:162e214baa3d | 120 | enum DataType { |
mitesh2patel | 0:162e214baa3d | 121 | DataTypeSnapshotPicture = 0x01, |
mitesh2patel | 0:162e214baa3d | 122 | DataTypePreviewPicture = 0x02, |
mitesh2patel | 0:162e214baa3d | 123 | DataTypeJpegPreviewPicture = 0x05 |
mitesh2patel | 0:162e214baa3d | 124 | }; |
mitesh2patel | 0:162e214baa3d | 125 | |
mitesh2patel | 0:162e214baa3d | 126 | /** |
mitesh2patel | 0:162e214baa3d | 127 | * Constructor. |
mitesh2patel | 0:162e214baa3d | 128 | * |
mitesh2patel | 0:162e214baa3d | 129 | * @param tx A pin for transmit. |
mitesh2patel | 0:162e214baa3d | 130 | * @param rx A pin for receive. |
mitesh2patel | 0:162e214baa3d | 131 | * @param baud Baud rate. (Default is Baud19200.) |
mitesh2patel | 0:162e214baa3d | 132 | */ |
mitesh2patel | 0:162e214baa3d | 133 | CameraC328(PinName tx, PinName rx, Baud baud = Baud115200); |
mitesh2patel | 0:162e214baa3d | 134 | |
mitesh2patel | 0:162e214baa3d | 135 | /** |
mitesh2patel | 0:162e214baa3d | 136 | * Destructor. |
mitesh2patel | 0:162e214baa3d | 137 | */ |
mitesh2patel | 0:162e214baa3d | 138 | ~CameraC328(); |
mitesh2patel | 0:162e214baa3d | 139 | |
mitesh2patel | 0:162e214baa3d | 140 | /** |
mitesh2patel | 0:162e214baa3d | 141 | * Make a sync. for baud rate. |
mitesh2patel | 0:162e214baa3d | 142 | */ |
mitesh2patel | 0:162e214baa3d | 143 | ErrorNumber sync(); |
mitesh2patel | 0:162e214baa3d | 144 | |
mitesh2patel | 0:162e214baa3d | 145 | /** |
mitesh2patel | 0:162e214baa3d | 146 | * Initialize. |
mitesh2patel | 0:162e214baa3d | 147 | * |
mitesh2patel | 0:162e214baa3d | 148 | * @param ct Color type. |
mitesh2patel | 0:162e214baa3d | 149 | * @param rr Raw resolution. |
mitesh2patel | 0:162e214baa3d | 150 | * @param jr JPEG resolution. |
mitesh2patel | 0:162e214baa3d | 151 | */ |
mitesh2patel | 0:162e214baa3d | 152 | ErrorNumber init(ColorType ct, RawResolution rr, JpegResolution jr); |
mitesh2patel | 0:162e214baa3d | 153 | |
mitesh2patel | 0:162e214baa3d | 154 | /** |
mitesh2patel | 0:162e214baa3d | 155 | * Get uncompressed snapshot picture. |
mitesh2patel | 0:162e214baa3d | 156 | * |
mitesh2patel | 0:162e214baa3d | 157 | * @param func A pointer to a callback function. |
mitesh2patel | 0:162e214baa3d | 158 | * Please do NOT block this callback function. |
mitesh2patel | 0:162e214baa3d | 159 | * Because the camera module transmit image datas continuously. |
mitesh2patel | 0:162e214baa3d | 160 | * @return Status of the error. |
mitesh2patel | 0:162e214baa3d | 161 | */ |
mitesh2patel | 0:162e214baa3d | 162 | ErrorNumber getUncompressedSnapshotPicture(void(*func)(size_t done, size_t total, char c)); |
mitesh2patel | 0:162e214baa3d | 163 | |
mitesh2patel | 0:162e214baa3d | 164 | /** |
mitesh2patel | 0:162e214baa3d | 165 | * Get uncompressed preview picture. |
mitesh2patel | 0:162e214baa3d | 166 | * |
mitesh2patel | 0:162e214baa3d | 167 | * @param func A pointer to a callback function. |
mitesh2patel | 0:162e214baa3d | 168 | * Please do NOT block this callback function. |
mitesh2patel | 0:162e214baa3d | 169 | * Because the camera module transmit image datas continuously. |
mitesh2patel | 0:162e214baa3d | 170 | * @return Status of the error. |
mitesh2patel | 0:162e214baa3d | 171 | */ |
mitesh2patel | 0:162e214baa3d | 172 | ErrorNumber getUncompressedPreviewPicture(void(*func)(size_t done, size_t total, char c)); |
mitesh2patel | 0:162e214baa3d | 173 | |
mitesh2patel | 0:162e214baa3d | 174 | /** |
mitesh2patel | 0:162e214baa3d | 175 | * Get JPEG snapshot picture. |
mitesh2patel | 0:162e214baa3d | 176 | * |
mitesh2patel | 0:162e214baa3d | 177 | * @param func A pointer to a callback function. |
mitesh2patel | 0:162e214baa3d | 178 | * You can block this function until saving the image datas. |
mitesh2patel | 0:162e214baa3d | 179 | * @return Status of the error. |
mitesh2patel | 0:162e214baa3d | 180 | */ |
mitesh2patel | 0:162e214baa3d | 181 | ErrorNumber getJpegSnapshotPicture(void(*func)(char *buf, size_t siz)); |
mitesh2patel | 0:162e214baa3d | 182 | |
mitesh2patel | 0:162e214baa3d | 183 | /** |
mitesh2patel | 0:162e214baa3d | 184 | * Get JPEG preview picture. |
mitesh2patel | 0:162e214baa3d | 185 | * |
mitesh2patel | 0:162e214baa3d | 186 | * @param func A pointer to a callback function. |
mitesh2patel | 0:162e214baa3d | 187 | * You can block this function until saving the image datas. |
mitesh2patel | 0:162e214baa3d | 188 | * @return Status of the error. |
mitesh2patel | 0:162e214baa3d | 189 | */ |
mitesh2patel | 0:162e214baa3d | 190 | ErrorNumber getJpegPreviewPicture(void(*func)(char *buf, size_t siz)); |
mitesh2patel | 0:162e214baa3d | 191 | |
mitesh2patel | 0:162e214baa3d | 192 | private: |
mitesh2patel | 0:162e214baa3d | 193 | SerialBuffered serial; |
mitesh2patel | 0:162e214baa3d | 194 | static const int COMMAND_LENGTH = 6; |
mitesh2patel | 0:162e214baa3d | 195 | static const int SYNCMAX = 60; |
mitesh2patel | 0:162e214baa3d | 196 | static const int packageSize = 512; |
mitesh2patel | 0:162e214baa3d | 197 | |
mitesh2patel | 0:162e214baa3d | 198 | ErrorNumber sendInitial(ColorType ct, RawResolution rr, JpegResolution jr); |
mitesh2patel | 0:162e214baa3d | 199 | ErrorNumber sendGetPicture(PictureType pt); |
mitesh2patel | 0:162e214baa3d | 200 | ErrorNumber sendSnapshot(SnapshotType st, uint16_t skipFrames); |
mitesh2patel | 0:162e214baa3d | 201 | ErrorNumber sendSetPackageSize(uint16_t packageSize); |
mitesh2patel | 0:162e214baa3d | 202 | ErrorNumber sendSetBaudrate(Baud baud); |
mitesh2patel | 0:162e214baa3d | 203 | ErrorNumber sendReset(ResetType rt, bool specialReset); |
mitesh2patel | 0:162e214baa3d | 204 | ErrorNumber sendPowerOff(); |
mitesh2patel | 0:162e214baa3d | 205 | ErrorNumber recvData(DataType *dt, uint32_t *length); |
mitesh2patel | 0:162e214baa3d | 206 | ErrorNumber sendSync(); |
mitesh2patel | 0:162e214baa3d | 207 | ErrorNumber recvSync(); |
mitesh2patel | 0:162e214baa3d | 208 | ErrorNumber sendAck(uint8_t commandId, uint16_t packageId); |
mitesh2patel | 0:162e214baa3d | 209 | ErrorNumber recvAckOrNck(); |
mitesh2patel | 0:162e214baa3d | 210 | |
mitesh2patel | 0:162e214baa3d | 211 | bool sendBytes(char *buf, size_t len, int timeout_us = 20000); |
mitesh2patel | 0:162e214baa3d | 212 | bool recvBytes(char *buf, size_t len, int timeout_us = 20000); |
mitesh2patel | 0:162e214baa3d | 213 | bool waitRecv(); |
mitesh2patel | 0:162e214baa3d | 214 | bool waitIdle(); |
mitesh2patel | 0:162e214baa3d | 215 | }; |
mitesh2patel | 0:162e214baa3d | 216 | |
mitesh2patel | 0:162e214baa3d | 217 | #endif |