CameraC328

Dependents:   CameraC328_TestProgram CameraC328_Thresholding Camera_TestProgram_2015 Camera_TestProgram_2015 ... more

Committer:
shintamainjp
Date:
Wed Oct 13 10:45:29 2010 +0000
Revision:
15:49cfda6c547f

        

Who changed what in which revision?

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