LinkSprite LS-Y201 JPEG Color Camera.

Dependents:   Camera_LS_Y201_TestProgram Camera_LS_Y201_TestProgram ServoCamV1 RFIDdoor ... more

Committer:
shintamainjp
Date:
Thu Nov 25 15:43:42 2010 +0000
Revision:
0:f71232252dcf
Child:
1:43358d40f879
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shintamainjp 0:f71232252dcf 1 /**
shintamainjp 0:f71232252dcf 2 * =============================================================================
shintamainjp 0:f71232252dcf 3 * LS-Y201 device driver class (Version 0.0.1)
shintamainjp 0:f71232252dcf 4 * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
shintamainjp 0:f71232252dcf 5 * January 2010
shintamainjp 0:f71232252dcf 6 * =============================================================================
shintamainjp 0:f71232252dcf 7 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
shintamainjp 0:f71232252dcf 8 *
shintamainjp 0:f71232252dcf 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
shintamainjp 0:f71232252dcf 10 * of this software and associated documentation files (the "Software"), to deal
shintamainjp 0:f71232252dcf 11 * in the Software without restriction, including without limitation the rights
shintamainjp 0:f71232252dcf 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
shintamainjp 0:f71232252dcf 13 * copies of the Software, and to permit persons to whom the Software is
shintamainjp 0:f71232252dcf 14 * furnished to do so, subject to the following conditions:
shintamainjp 0:f71232252dcf 15 *
shintamainjp 0:f71232252dcf 16 * The above copyright notice and this permission notice shall be included in
shintamainjp 0:f71232252dcf 17 * all copies or substantial portions of the Software.
shintamainjp 0:f71232252dcf 18 *
shintamainjp 0:f71232252dcf 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
shintamainjp 0:f71232252dcf 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
shintamainjp 0:f71232252dcf 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
shintamainjp 0:f71232252dcf 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
shintamainjp 0:f71232252dcf 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
shintamainjp 0:f71232252dcf 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
shintamainjp 0:f71232252dcf 25 * THE SOFTWARE.
shintamainjp 0:f71232252dcf 26 * =============================================================================
shintamainjp 0:f71232252dcf 27 */
shintamainjp 0:f71232252dcf 28
shintamainjp 0:f71232252dcf 29 #ifndef LS_Y201_H
shintamainjp 0:f71232252dcf 30 #define LS_Y201_H
shintamainjp 0:f71232252dcf 31
shintamainjp 0:f71232252dcf 32 #include "mbed.h"
shintamainjp 0:f71232252dcf 33 #include "SerialBuffered.h"
shintamainjp 0:f71232252dcf 34
shintamainjp 0:f71232252dcf 35 /**
shintamainjp 0:f71232252dcf 36 * Camera
shintamainjp 0:f71232252dcf 37 */
shintamainjp 0:f71232252dcf 38 class Camera_LS_Y201 {
shintamainjp 0:f71232252dcf 39 public:
shintamainjp 0:f71232252dcf 40
shintamainjp 0:f71232252dcf 41 /**
shintamainjp 0:f71232252dcf 42 * Create.
shintamainjp 0:f71232252dcf 43 *
shintamainjp 0:f71232252dcf 44 * @param tx Transmitter.
shintamainjp 0:f71232252dcf 45 * @param rx Receiver.
shintamainjp 0:f71232252dcf 46 */
shintamainjp 0:f71232252dcf 47 Camera_LS_Y201(PinName tx, PinName rx);
shintamainjp 0:f71232252dcf 48
shintamainjp 0:f71232252dcf 49 /**
shintamainjp 0:f71232252dcf 50 * Dispose.
shintamainjp 0:f71232252dcf 51 */
shintamainjp 0:f71232252dcf 52 ~Camera_LS_Y201();
shintamainjp 0:f71232252dcf 53
shintamainjp 0:f71232252dcf 54 /**
shintamainjp 0:f71232252dcf 55 * Error code.
shintamainjp 0:f71232252dcf 56 */
shintamainjp 0:f71232252dcf 57 enum ErrorCode {
shintamainjp 0:f71232252dcf 58 NoError = 0,
shintamainjp 0:f71232252dcf 59 UnexpectedReply,
shintamainjp 0:f71232252dcf 60 Timeout,
shintamainjp 0:f71232252dcf 61 SendError,
shintamainjp 0:f71232252dcf 62 RecvError,
shintamainjp 0:f71232252dcf 63 InvalidArguments
shintamainjp 0:f71232252dcf 64 };
shintamainjp 0:f71232252dcf 65
shintamainjp 0:f71232252dcf 66 /**
shintamainjp 0:f71232252dcf 67 * Image size.
shintamainjp 0:f71232252dcf 68 */
shintamainjp 0:f71232252dcf 69 enum ImageSize {
shintamainjp 0:f71232252dcf 70 ImageSize160x120, /**< 160x120. */
shintamainjp 0:f71232252dcf 71 ImageSize320x280, /**< 320x280. */
shintamainjp 0:f71232252dcf 72 ImageSize640x480 /**< 640x480. */
shintamainjp 0:f71232252dcf 73 };
shintamainjp 0:f71232252dcf 74
shintamainjp 0:f71232252dcf 75 /**
shintamainjp 0:f71232252dcf 76 * Reset module.
shintamainjp 0:f71232252dcf 77 *
shintamainjp 0:f71232252dcf 78 * @return Error code.
shintamainjp 0:f71232252dcf 79 */
shintamainjp 0:f71232252dcf 80 ErrorCode reset();
shintamainjp 0:f71232252dcf 81
shintamainjp 0:f71232252dcf 82 /**
shintamainjp 0:f71232252dcf 83 * Set image size.
shintamainjp 0:f71232252dcf 84 *
shintamainjp 0:f71232252dcf 85 * @param is Image size.
shintamainjp 0:f71232252dcf 86 * @return Error code.
shintamainjp 0:f71232252dcf 87 */
shintamainjp 0:f71232252dcf 88 ErrorCode setImageSize(ImageSize is);
shintamainjp 0:f71232252dcf 89
shintamainjp 0:f71232252dcf 90 /**
shintamainjp 0:f71232252dcf 91 * Take picture.
shintamainjp 0:f71232252dcf 92 *
shintamainjp 0:f71232252dcf 93 * @return Error code.
shintamainjp 0:f71232252dcf 94 */
shintamainjp 0:f71232252dcf 95 ErrorCode takePicture();
shintamainjp 0:f71232252dcf 96
shintamainjp 0:f71232252dcf 97 /**
shintamainjp 0:f71232252dcf 98 * Read jpeg file size.
shintamainjp 0:f71232252dcf 99 *
shintamainjp 0:f71232252dcf 100 * @param fileSize File size.
shintamainjp 0:f71232252dcf 101 * @return Error code.
shintamainjp 0:f71232252dcf 102 */
shintamainjp 0:f71232252dcf 103 ErrorCode readJpegFileSize(int *fileSize);
shintamainjp 0:f71232252dcf 104
shintamainjp 0:f71232252dcf 105 /**
shintamainjp 0:f71232252dcf 106 * Read jpeg file content.
shintamainjp 0:f71232252dcf 107 *
shintamainjp 0:f71232252dcf 108 * @param func A pointer to a call back function.
shintamainjp 0:f71232252dcf 109 * @return Error code.
shintamainjp 0:f71232252dcf 110 */
shintamainjp 0:f71232252dcf 111 ErrorCode readJpegFileContent(void (*func)(uint8_t *buf, size_t siz));
shintamainjp 0:f71232252dcf 112
shintamainjp 0:f71232252dcf 113 /**
shintamainjp 0:f71232252dcf 114 * Stop taking pictures.
shintamainjp 0:f71232252dcf 115 *
shintamainjp 0:f71232252dcf 116 * @return Error code.
shintamainjp 0:f71232252dcf 117 */
shintamainjp 0:f71232252dcf 118 ErrorCode stopTakingPictures();
shintamainjp 0:f71232252dcf 119
shintamainjp 0:f71232252dcf 120 private:
shintamainjp 0:f71232252dcf 121 SerialBuffered serial;
shintamainjp 0:f71232252dcf 122
shintamainjp 0:f71232252dcf 123 /**
shintamainjp 0:f71232252dcf 124 * Wait init end codes.
shintamainjp 0:f71232252dcf 125 *
shintamainjp 0:f71232252dcf 126 * @return Error code.
shintamainjp 0:f71232252dcf 127 */
shintamainjp 0:f71232252dcf 128 ErrorCode waitInitEnd();
shintamainjp 0:f71232252dcf 129
shintamainjp 0:f71232252dcf 130 /**
shintamainjp 0:f71232252dcf 131 * Send bytes to camera module.
shintamainjp 0:f71232252dcf 132 *
shintamainjp 0:f71232252dcf 133 * @param buf Pointer to the data buffer.
shintamainjp 0:f71232252dcf 134 * @param len Length of the data buffer.
shintamainjp 0:f71232252dcf 135 *
shintamainjp 0:f71232252dcf 136 * @return True if the data sended.
shintamainjp 0:f71232252dcf 137 */
shintamainjp 0:f71232252dcf 138 bool sendBytes(uint8_t *buf, size_t len, int timeout_us);
shintamainjp 0:f71232252dcf 139
shintamainjp 0:f71232252dcf 140 /**
shintamainjp 0:f71232252dcf 141 * Receive bytes from camera module.
shintamainjp 0:f71232252dcf 142 *
shintamainjp 0:f71232252dcf 143 * @param buf Pointer to the data buffer.
shintamainjp 0:f71232252dcf 144 * @param len Length of the data buffer.
shintamainjp 0:f71232252dcf 145 *
shintamainjp 0:f71232252dcf 146 * @return True if the data received.
shintamainjp 0:f71232252dcf 147 */
shintamainjp 0:f71232252dcf 148 bool recvBytes(uint8_t *buf, size_t len, int timeout_us);
shintamainjp 0:f71232252dcf 149
shintamainjp 0:f71232252dcf 150 /**
shintamainjp 0:f71232252dcf 151 * Wait received.
shintamainjp 0:f71232252dcf 152 *
shintamainjp 0:f71232252dcf 153 * @return True if the data received.
shintamainjp 0:f71232252dcf 154 */
shintamainjp 0:f71232252dcf 155 bool waitRecv();
shintamainjp 0:f71232252dcf 156
shintamainjp 0:f71232252dcf 157 /**
shintamainjp 0:f71232252dcf 158 * Wait idle state.
shintamainjp 0:f71232252dcf 159 *
shintamainjp 0:f71232252dcf 160 * @return True if it succeed.
shintamainjp 0:f71232252dcf 161 */
shintamainjp 0:f71232252dcf 162 bool waitIdle();
shintamainjp 0:f71232252dcf 163
shintamainjp 0:f71232252dcf 164 };
shintamainjp 0:f71232252dcf 165
shintamainjp 0:f71232252dcf 166 #endif