Any changes are to allow conversion to BMP

Fork of Camera_LS_Y201 by Shinichiro Nakamura

Committer:
kylepost3
Date:
Wed Apr 30 14:16:47 2014 +0000
Revision:
2:2eedbc23d0b9
Parent:
1:43358d40f879
Any changes are to allow for conversion to BMP.

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 /**
kylepost3 2:2eedbc23d0b9 36 * Image size.
kylepost3 2:2eedbc23d0b9 37 */
kylepost3 2:2eedbc23d0b9 38 enum ImageSize {
kylepost3 2:2eedbc23d0b9 39 ImageSize160x120, /**< 160x120. */
kylepost3 2:2eedbc23d0b9 40 ImageSize320x280, /**< 320x280. */
kylepost3 2:2eedbc23d0b9 41 ImageSize640x480 /**< 640x480. */
kylepost3 2:2eedbc23d0b9 42 };
kylepost3 2:2eedbc23d0b9 43
kylepost3 2:2eedbc23d0b9 44 /**
shintamainjp 0:f71232252dcf 45 * Camera
shintamainjp 0:f71232252dcf 46 */
shintamainjp 0:f71232252dcf 47 class Camera_LS_Y201 {
shintamainjp 0:f71232252dcf 48 public:
shintamainjp 0:f71232252dcf 49
shintamainjp 0:f71232252dcf 50 /**
shintamainjp 0:f71232252dcf 51 * Create.
shintamainjp 0:f71232252dcf 52 *
shintamainjp 0:f71232252dcf 53 * @param tx Transmitter.
shintamainjp 0:f71232252dcf 54 * @param rx Receiver.
shintamainjp 0:f71232252dcf 55 */
shintamainjp 0:f71232252dcf 56 Camera_LS_Y201(PinName tx, PinName rx);
shintamainjp 0:f71232252dcf 57
shintamainjp 0:f71232252dcf 58 /**
shintamainjp 0:f71232252dcf 59 * Dispose.
shintamainjp 0:f71232252dcf 60 */
shintamainjp 0:f71232252dcf 61 ~Camera_LS_Y201();
shintamainjp 0:f71232252dcf 62
shintamainjp 0:f71232252dcf 63 /**
shintamainjp 0:f71232252dcf 64 * Error code.
shintamainjp 0:f71232252dcf 65 */
shintamainjp 0:f71232252dcf 66 enum ErrorCode {
shintamainjp 0:f71232252dcf 67 NoError = 0,
shintamainjp 0:f71232252dcf 68 UnexpectedReply,
shintamainjp 0:f71232252dcf 69 Timeout,
shintamainjp 0:f71232252dcf 70 SendError,
shintamainjp 0:f71232252dcf 71 RecvError,
shintamainjp 0:f71232252dcf 72 InvalidArguments
shintamainjp 0:f71232252dcf 73 };
shintamainjp 0:f71232252dcf 74
kylepost3 2:2eedbc23d0b9 75
shintamainjp 0:f71232252dcf 76
shintamainjp 0:f71232252dcf 77 /**
shintamainjp 0:f71232252dcf 78 * Reset module.
shintamainjp 0:f71232252dcf 79 *
shintamainjp 0:f71232252dcf 80 * @return Error code.
shintamainjp 0:f71232252dcf 81 */
shintamainjp 0:f71232252dcf 82 ErrorCode reset();
shintamainjp 0:f71232252dcf 83
shintamainjp 0:f71232252dcf 84 /**
shintamainjp 0:f71232252dcf 85 * Set image size.
shintamainjp 0:f71232252dcf 86 *
shintamainjp 0:f71232252dcf 87 * @param is Image size.
shintamainjp 0:f71232252dcf 88 * @return Error code.
shintamainjp 0:f71232252dcf 89 */
shintamainjp 0:f71232252dcf 90 ErrorCode setImageSize(ImageSize is);
shintamainjp 0:f71232252dcf 91
shintamainjp 0:f71232252dcf 92 /**
shintamainjp 0:f71232252dcf 93 * Take picture.
shintamainjp 0:f71232252dcf 94 *
shintamainjp 0:f71232252dcf 95 * @return Error code.
shintamainjp 0:f71232252dcf 96 */
shintamainjp 0:f71232252dcf 97 ErrorCode takePicture();
shintamainjp 0:f71232252dcf 98
shintamainjp 0:f71232252dcf 99 /**
shintamainjp 0:f71232252dcf 100 * Read jpeg file size.
shintamainjp 0:f71232252dcf 101 *
shintamainjp 0:f71232252dcf 102 * @param fileSize File size.
shintamainjp 0:f71232252dcf 103 * @return Error code.
shintamainjp 0:f71232252dcf 104 */
shintamainjp 0:f71232252dcf 105 ErrorCode readJpegFileSize(int *fileSize);
shintamainjp 0:f71232252dcf 106
shintamainjp 0:f71232252dcf 107 /**
shintamainjp 0:f71232252dcf 108 * Read jpeg file content.
shintamainjp 0:f71232252dcf 109 *
shintamainjp 0:f71232252dcf 110 * @param func A pointer to a call back function.
shintamainjp 0:f71232252dcf 111 * @return Error code.
shintamainjp 0:f71232252dcf 112 */
shintamainjp 1:43358d40f879 113 ErrorCode readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz));
shintamainjp 0:f71232252dcf 114
shintamainjp 0:f71232252dcf 115 /**
shintamainjp 0:f71232252dcf 116 * Stop taking pictures.
shintamainjp 0:f71232252dcf 117 *
shintamainjp 0:f71232252dcf 118 * @return Error code.
shintamainjp 0:f71232252dcf 119 */
shintamainjp 0:f71232252dcf 120 ErrorCode stopTakingPictures();
shintamainjp 0:f71232252dcf 121
shintamainjp 0:f71232252dcf 122 private:
shintamainjp 0:f71232252dcf 123 SerialBuffered serial;
shintamainjp 0:f71232252dcf 124
shintamainjp 0:f71232252dcf 125 /**
shintamainjp 0:f71232252dcf 126 * Wait init end codes.
shintamainjp 0:f71232252dcf 127 *
shintamainjp 0:f71232252dcf 128 * @return Error code.
shintamainjp 0:f71232252dcf 129 */
shintamainjp 0:f71232252dcf 130 ErrorCode waitInitEnd();
shintamainjp 0:f71232252dcf 131
shintamainjp 0:f71232252dcf 132 /**
shintamainjp 0:f71232252dcf 133 * Send bytes to camera module.
shintamainjp 0:f71232252dcf 134 *
shintamainjp 0:f71232252dcf 135 * @param buf Pointer to the data buffer.
shintamainjp 0:f71232252dcf 136 * @param len Length of the data buffer.
shintamainjp 0:f71232252dcf 137 *
shintamainjp 0:f71232252dcf 138 * @return True if the data sended.
shintamainjp 0:f71232252dcf 139 */
shintamainjp 0:f71232252dcf 140 bool sendBytes(uint8_t *buf, size_t len, int timeout_us);
shintamainjp 0:f71232252dcf 141
shintamainjp 0:f71232252dcf 142 /**
shintamainjp 0:f71232252dcf 143 * Receive bytes from camera module.
shintamainjp 0:f71232252dcf 144 *
shintamainjp 0:f71232252dcf 145 * @param buf Pointer to the data buffer.
shintamainjp 0:f71232252dcf 146 * @param len Length of the data buffer.
shintamainjp 0:f71232252dcf 147 *
shintamainjp 0:f71232252dcf 148 * @return True if the data received.
shintamainjp 0:f71232252dcf 149 */
shintamainjp 0:f71232252dcf 150 bool recvBytes(uint8_t *buf, size_t len, int timeout_us);
shintamainjp 0:f71232252dcf 151
shintamainjp 0:f71232252dcf 152 /**
shintamainjp 0:f71232252dcf 153 * Wait received.
shintamainjp 0:f71232252dcf 154 *
shintamainjp 0:f71232252dcf 155 * @return True if the data received.
shintamainjp 0:f71232252dcf 156 */
shintamainjp 0:f71232252dcf 157 bool waitRecv();
shintamainjp 0:f71232252dcf 158
shintamainjp 0:f71232252dcf 159 /**
shintamainjp 0:f71232252dcf 160 * Wait idle state.
shintamainjp 0:f71232252dcf 161 *
shintamainjp 0:f71232252dcf 162 * @return True if it succeed.
shintamainjp 0:f71232252dcf 163 */
shintamainjp 0:f71232252dcf 164 bool waitIdle();
shintamainjp 0:f71232252dcf 165
shintamainjp 0:f71232252dcf 166 };
shintamainjp 0:f71232252dcf 167
shintamainjp 0:f71232252dcf 168 #endif