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