fork of Camera_LS_Y201 lib supporting the 2MP variant/successor

Fork of Camera_LS_Y201 by Shinichiro Nakamura

Committer:
humlet
Date:
Tue Mar 18 17:28:47 2014 +0000
Revision:
2:ce4d1351bdeb
Parent:
1:43358d40f879
Got it running for the crappy LS-Y201-2MP; quickNdirty

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 {
humlet 2:ce4d1351bdeb 70 ImageSize160x120, // crappy ... firmware seems to record the upper left part of the image
humlet 2:ce4d1351bdeb 71 ImageSize320x240, // OK
humlet 2:ce4d1351bdeb 72 ImageSize640x480, // OK
humlet 2:ce4d1351bdeb 73 ImageSize800x600,
humlet 2:ce4d1351bdeb 74 ImageSize1024x768,
humlet 2:ce4d1351bdeb 75 ImageSize1280x960,
humlet 2:ce4d1351bdeb 76 ImageSize1600x1200 // OK
shintamainjp 0:f71232252dcf 77 };
shintamainjp 0:f71232252dcf 78
humlet 2:ce4d1351bdeb 79 enum BaudRate {
humlet 2:ce4d1351bdeb 80 //BaudRate9600=0xae, // doesn't seem to work, not investiated, as no one seriously will use 9600 baud anyway
humlet 2:ce4d1351bdeb 81 BaudRate38400=0x2a,
humlet 2:ce4d1351bdeb 82 BaudRate57600=0x1c,
humlet 2:ce4d1351bdeb 83 BaudRate115200=0x0d,
humlet 2:ce4d1351bdeb 84 BaudRate128000=0x7e,
humlet 2:ce4d1351bdeb 85 BaudRate256000=0x56
humlet 2:ce4d1351bdeb 86 };
humlet 2:ce4d1351bdeb 87
humlet 2:ce4d1351bdeb 88
shintamainjp 0:f71232252dcf 89 /**
shintamainjp 0:f71232252dcf 90 * Reset module.
shintamainjp 0:f71232252dcf 91 *
shintamainjp 0:f71232252dcf 92 * @return Error code.
shintamainjp 0:f71232252dcf 93 */
shintamainjp 0:f71232252dcf 94 ErrorCode reset();
shintamainjp 0:f71232252dcf 95
shintamainjp 0:f71232252dcf 96 /**
shintamainjp 0:f71232252dcf 97 * Set image size.
shintamainjp 0:f71232252dcf 98 *
shintamainjp 0:f71232252dcf 99 * @param is Image size.
shintamainjp 0:f71232252dcf 100 * @return Error code.
shintamainjp 0:f71232252dcf 101 */
shintamainjp 0:f71232252dcf 102 ErrorCode setImageSize(ImageSize is);
shintamainjp 0:f71232252dcf 103
humlet 2:ce4d1351bdeb 104
humlet 2:ce4d1351bdeb 105 // values: 0..9 highest compression at 9
humlet 2:ce4d1351bdeb 106 // Ups, and value 5 is simply ignored by the firmware
humlet 2:ce4d1351bdeb 107 ErrorCode setCompressionRatio(int cr);
humlet 2:ce4d1351bdeb 108
humlet 2:ce4d1351bdeb 109 ErrorCode setBaudRate(BaudRate br);
humlet 2:ce4d1351bdeb 110
shintamainjp 0:f71232252dcf 111 /**
shintamainjp 0:f71232252dcf 112 * Take picture.
shintamainjp 0:f71232252dcf 113 *
shintamainjp 0:f71232252dcf 114 * @return Error code.
shintamainjp 0:f71232252dcf 115 */
shintamainjp 0:f71232252dcf 116 ErrorCode takePicture();
shintamainjp 0:f71232252dcf 117
shintamainjp 0:f71232252dcf 118 /**
shintamainjp 0:f71232252dcf 119 * Read jpeg file size.
shintamainjp 0:f71232252dcf 120 *
shintamainjp 0:f71232252dcf 121 * @param fileSize File size.
shintamainjp 0:f71232252dcf 122 * @return Error code.
shintamainjp 0:f71232252dcf 123 */
shintamainjp 0:f71232252dcf 124 ErrorCode readJpegFileSize(int *fileSize);
shintamainjp 0:f71232252dcf 125
shintamainjp 0:f71232252dcf 126 /**
shintamainjp 0:f71232252dcf 127 * Read jpeg file content.
shintamainjp 0:f71232252dcf 128 *
shintamainjp 0:f71232252dcf 129 * @param func A pointer to a call back function.
shintamainjp 0:f71232252dcf 130 * @return Error code.
shintamainjp 0:f71232252dcf 131 */
shintamainjp 1:43358d40f879 132 ErrorCode readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz));
shintamainjp 0:f71232252dcf 133
shintamainjp 0:f71232252dcf 134 /**
shintamainjp 0:f71232252dcf 135 * Stop taking pictures.
shintamainjp 0:f71232252dcf 136 *
shintamainjp 0:f71232252dcf 137 * @return Error code.
shintamainjp 0:f71232252dcf 138 */
shintamainjp 0:f71232252dcf 139 ErrorCode stopTakingPictures();
shintamainjp 0:f71232252dcf 140
shintamainjp 0:f71232252dcf 141 private:
shintamainjp 0:f71232252dcf 142 SerialBuffered serial;
shintamainjp 0:f71232252dcf 143
shintamainjp 0:f71232252dcf 144 /**
shintamainjp 0:f71232252dcf 145 * Wait init end codes.
shintamainjp 0:f71232252dcf 146 *
shintamainjp 0:f71232252dcf 147 * @return Error code.
shintamainjp 0:f71232252dcf 148 */
shintamainjp 0:f71232252dcf 149 ErrorCode waitInitEnd();
shintamainjp 0:f71232252dcf 150
shintamainjp 0:f71232252dcf 151 /**
shintamainjp 0:f71232252dcf 152 * Send bytes to camera module.
shintamainjp 0:f71232252dcf 153 *
shintamainjp 0:f71232252dcf 154 * @param buf Pointer to the data buffer.
shintamainjp 0:f71232252dcf 155 * @param len Length of the data buffer.
shintamainjp 0:f71232252dcf 156 *
shintamainjp 0:f71232252dcf 157 * @return True if the data sended.
shintamainjp 0:f71232252dcf 158 */
shintamainjp 0:f71232252dcf 159 bool sendBytes(uint8_t *buf, size_t len, int timeout_us);
shintamainjp 0:f71232252dcf 160
shintamainjp 0:f71232252dcf 161 /**
shintamainjp 0:f71232252dcf 162 * Receive bytes from camera module.
shintamainjp 0:f71232252dcf 163 *
shintamainjp 0:f71232252dcf 164 * @param buf Pointer to the data buffer.
shintamainjp 0:f71232252dcf 165 * @param len Length of the data buffer.
shintamainjp 0:f71232252dcf 166 *
shintamainjp 0:f71232252dcf 167 * @return True if the data received.
shintamainjp 0:f71232252dcf 168 */
shintamainjp 0:f71232252dcf 169 bool recvBytes(uint8_t *buf, size_t len, int timeout_us);
shintamainjp 0:f71232252dcf 170
shintamainjp 0:f71232252dcf 171 /**
shintamainjp 0:f71232252dcf 172 * Wait received.
shintamainjp 0:f71232252dcf 173 *
shintamainjp 0:f71232252dcf 174 * @return True if the data received.
shintamainjp 0:f71232252dcf 175 */
shintamainjp 0:f71232252dcf 176 bool waitRecv();
shintamainjp 0:f71232252dcf 177
shintamainjp 0:f71232252dcf 178 /**
shintamainjp 0:f71232252dcf 179 * Wait idle state.
shintamainjp 0:f71232252dcf 180 *
shintamainjp 0:f71232252dcf 181 * @return True if it succeed.
shintamainjp 0:f71232252dcf 182 */
shintamainjp 0:f71232252dcf 183 bool waitIdle();
shintamainjp 0:f71232252dcf 184
shintamainjp 0:f71232252dcf 185 };
shintamainjp 0:f71232252dcf 186
shintamainjp 0:f71232252dcf 187 #endif