Description.

Dependents:   RoboPanorama 4180_Project ProjetMacIntel

Fork of Camera_LS_Y201 by Shinichiro Nakamura

Files at this revision

API Documentation at this revision

Comitter:
lndv3
Date:
Fri Oct 12 16:41:24 2012 +0000
Parent:
1:43358d40f879
Commit message:
Commit.

Changed in this revision

Camera_LS_Y201.cpp Show annotated file Show diff for this revision Revisions of this file
Camera_LS_Y201.h Show annotated file Show diff for this revision Revisions of this file
SerialBuffered.cpp Show annotated file Show diff for this revision Revisions of this file
SerialBuffered.h Show annotated file Show diff for this revision Revisions of this file
diff -r 43358d40f879 -r e92ce527b8b0 Camera_LS_Y201.cpp
--- a/Camera_LS_Y201.cpp	Wed Dec 01 23:10:56 2010 +0000
+++ b/Camera_LS_Y201.cpp	Fri Oct 12 16:41:24 2012 +0000
@@ -1,449 +1,449 @@
-/**
- * =============================================================================
- * LS-Y201 device driver class (Version 0.0.1)
- * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
- *                      January 2010
- * =============================================================================
- * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- * =============================================================================
- */
-
-#include "Camera_LS_Y201.h"
-
-/**
- * Create.
- *
- * @param tx Transmitter.
- * @param rx Receiver.
- */
-Camera_LS_Y201::Camera_LS_Y201(PinName tx, PinName rx) : serial(tx, rx) {
-    serial.baud(38400);
-}
-
-/**
- * Dispose.
- */
-Camera_LS_Y201::~Camera_LS_Y201() {
-}
-
-/**
- * Reset module.
- *
- * @return Error code.
- */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::reset() {
-    uint8_t send[4] = {
-        0x56,
-        0x00,
-        0x26,
-        0x00
-    };
-    uint8_t recv[4];
-
-    waitIdle();
-    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
-        return SendError;
-    }
-    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
-        return RecvError;
-    }
-    if ((recv[0] == 0x76)
-            && (recv[1] == 0x00)
-            && (recv[2] == 0x26)
-            && (recv[3] == 0x00)) {
-        ErrorCode r = waitInitEnd();
-        if (r != NoError) {
-            return r;
-        }
-        wait(4);
-        return NoError;
-    } else {
-        return UnexpectedReply;
-    }
-}
-
-/**
- * Set image size.
- *
- * @param is Image size.
- * @return Error code.
- */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::setImageSize(ImageSize is) {
-    uint8_t send[9] = {
-        0x56,
-        0x00,
-        0x31,
-        0x05,
-        0x04,
-        0x01,
-        0x00,
-        0x19,
-        0x00    // 0x11:320x240, 0x00:640x480, 0x22:160x120
-    };
-    uint8_t recv[5];
-    switch (is) {
-        case ImageSize160x120:
-            send[8] = 0x22;
-            break;
-        case ImageSize320x280:
-            send[8] = 0x11;
-            break;
-        case ImageSize640x480:
-            send[8] = 0x00;
-            break;
-        default:
-            return InvalidArguments;
-    }
-    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
-        return SendError;
-    }
-    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
-        return RecvError;
-    }
-    if ((recv[0] == 0x76)
-            && (recv[1] == 0x00)
-            && (recv[2] == 0x31)
-            && (recv[3] == 0x00)
-            && (recv[4] == 0x00)) {
-        wait(1);
-        return reset();
-    } else {
-        return UnexpectedReply;
-    }
-}
-
-/**
- * Take picture.
- *
- * @return Error code.
- */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::takePicture() {
-    uint8_t send[5] = {
-        0x56,
-        0x00,
-        0x36,
-        0x01,
-        0x00
-    };
-    uint8_t recv[5];
-
-    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
-        return SendError;
-    }
-    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
-        return RecvError;
-    }
-
-    if ((recv[0] == 0x76)
-            && (recv[1] == 0x00)
-            && (recv[2] == 0x36)
-            && (recv[3] == 0x00)
-            && (recv[4] == 0x00)) {
-        /*
-         * I think the camera need a time for operating.
-         * But there is no any comments on the documents.
-         */
-        wait_ms(100);
-        return NoError;
-    } else {
-        return UnexpectedReply;
-    }
-}
-
-/**
- * Read jpeg file size.
- *
- * @param fileSize File size.
- * @return Error code.
- */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileSize(int *fileSize) {
-    uint8_t send[5] = {
-        0x56,
-        0x00,
-        0x34,
-        0x01,
-        0x00
-    };
-    uint8_t recv[9];
-
-    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
-        return SendError;
-    }
-    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
-        return RecvError;
-    }
-
-    if ((recv[0] == 0x76)
-            && (recv[1] == 0x00)
-            && (recv[2] == 0x34)
-            && (recv[3] == 0x00)
-            && (recv[4] == 0x04)
-            && (recv[5] == 0x00)
-            && (recv[6] == 0x00)) {
-        *fileSize = ((recv[7] & 0x00ff) << 8)
-                    | ((recv[8] & 0x00ff) << 0);
-        return NoError;
-    } else {
-        return UnexpectedReply;
-    }
-}
-
-/**
- * Read jpeg file content.
- *
- * @param func A pointer to a call back function.
- * @return Error code.
- */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz)) {
-    uint8_t send[16] = {
-        0x56,
-        0x00,
-        0x32,
-        0x0C,
-        0x00,
-        0x0A,
-        0x00,
-        0x00,
-        0x00, // MH
-        0x00, // ML
-        0x00,
-        0x00,
-        0x00, // KH
-        0x00, // KL
-        0x00, // XX
-        0x00  // XX
-    };
-    uint8_t body[32];
-    uint16_t m = 0; // Staring address.
-    uint16_t k = sizeof(body); // Packet size.
-    uint16_t x = 10;    // Interval time. XX XX * 0.01m[sec]
-    bool end = false;
-
-    /*
-     * Get the data size.
-     */
-    int siz_done = 0;
-    int siz_total = 0;
-    ErrorCode r = readJpegFileSize(&siz_total);
-    if (r != NoError) {
-        return r;
-    }
-
-    do {
-        send[8] = (m >> 8) & 0xff;
-        send[9] = (m >> 0) & 0xff;
-        send[12] = (k >> 8) & 0xff;
-        send[13] = (k >> 0) & 0xff;
-        send[14] = (x >> 8) & 0xff;
-        send[15] = (x >> 0) & 0xff;
-        /*
-         * Send a command.
-         */
-        if (!sendBytes(send, sizeof(send), 200 * 1000)) {
-            return SendError;
-        }
-        /*
-         * Read the header of the response.
-         */
-        uint8_t header[5];
-        if (!recvBytes(header, sizeof(header), 2 * 1000 * 1000)) {
-            return RecvError;
-        }
-        /*
-         * Check the response and fetch an image data.
-         */
-        if ((header[0] == 0x76)
-                && (header[1] == 0x00)
-                && (header[2] == 0x32)
-                && (header[3] == 0x00)
-                && (header[4] == 0x00)) {
-            if (!recvBytes(body, sizeof(body), 2 * 1000 * 1000)) {
-                return RecvError;
-            }
-            siz_done += sizeof(body);
-            if (func != NULL) {
-                if (siz_done > siz_total) {
-                    siz_done = siz_total;
-                }
-                func(siz_done, siz_total, body, sizeof(body));
-            }
-            for (int i = 1; i < sizeof(body); i++) {
-                if ((body[i - 1] == 0xFF) && (body[i - 0] == 0xD9)) {
-                    end = true;
-                }
-            }
-        } else {
-            return UnexpectedReply;
-        }
-        /*
-         * Read the footer of the response.
-         */
-        uint8_t footer[5];
-        if (!recvBytes(footer, sizeof(footer), 2 * 1000 * 1000)) {
-            return RecvError;
-        }
-
-        m += sizeof(body);
-    } while (!end);
-    return NoError;
-}
-
-/**
- * Stop taking pictures.
- *
- * @return Error code.
- */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::stopTakingPictures() {
-    uint8_t send[5] = {
-        0x56,
-        0x00,
-        0x36,
-        0x01,
-        0x03
-    };
-    uint8_t recv[5];
-
-    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
-        return SendError;
-    }
-    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
-        return RecvError;
-    }
-
-    if ((recv[0] == 0x76)
-            && (recv[1] == 0x00)
-            && (recv[2] == 0x36)
-            && (recv[3] == 0x00)
-            && (recv[4] == 0x00)) {
-        /*
-         * I think the camera need a time for operating.
-         * But there is no any comments on the documents.
-         */
-        wait_ms(100);
-        return NoError;
-    } else {
-        return UnexpectedReply;
-    }
-}
-
-/**
- * Wait init end codes.
- *
- * @return True if the data sended.
- */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::waitInitEnd() {
-    static const char *PWR_ON_MSG = "Init end\x0d\x0a";
-    for (int i = 0; i < strlen(PWR_ON_MSG); i++) {
-        static const int MAXCNT = 128;
-        int cnt = 0;
-        uint8_t c = 0x00;
-        do {
-            if (!recvBytes(&c, sizeof(c), 500 * 1000)) {
-                return Timeout;
-            }
-
-            /*
-             * What is the version of the camera.
-             * You can check the version with this code.
-             *
-             * VC0703 1.00
-             * 3o ctrl in
-             * Init end
-             */
-#if 0
-            printf("%c", c);
-#endif
-
-            cnt++;
-            if (MAXCNT < cnt) {
-                return UnexpectedReply;
-            }
-        } while (c != PWR_ON_MSG[i]);
-    }
-    return NoError;
-}
-
-/**
- * Send bytes to camera module.
- *
- * @param buf Pointer to the data buffer.
- * @param len Length of the data buffer.
- *
- * @return True if the data sended.
- */
-bool Camera_LS_Y201::sendBytes(uint8_t *buf, size_t len, int timeout_us) {
-    for (uint32_t i = 0; i < (uint32_t)len; i++) {
-        int cnt = 0;
-        while (!serial.writeable()) {
-            wait_us(1);
-            cnt++;
-            if (timeout_us < cnt) {
-                return false;
-            }
-        }
-        serial.putc(buf[i]);
-    }
-    return true;
-}
-
-/**
- * Receive bytes from camera module.
- *
- * @param buf Pointer to the data buffer.
- * @param len Length of the data buffer.
- *
- * @return True if the data received.
- */
-bool Camera_LS_Y201::recvBytes(uint8_t *buf, size_t len, int timeout_us) {
-    for (uint32_t i = 0; i < (uint32_t)len; i++) {
-        int cnt = 0;
-        while (!serial.readable()) {
-            wait_us(1);
-            cnt++;
-            if (timeout_us < cnt) {
-                return false;
-            }
-        }
-        buf[i] = serial.getc();
-    }
-    return true;
-}
-
-/**
- * Wait received.
- *
- * @return True if the data received.
- */
-bool Camera_LS_Y201::waitRecv() {
-    while (!serial.readable()) {
-    }
-    return true;
-}
-
-/**
- * Wait idle state.
- */
-bool Camera_LS_Y201::waitIdle() {
-    while (serial.readable()) {
-        serial.getc();
-    }
-    return true;
-}
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#include "Camera_LS_Y201.h"
+
+/**
+ * Create.
+ *
+ * @param tx Transmitter.
+ * @param rx Receiver.
+ */
+Camera_LS_Y201::Camera_LS_Y201(PinName tx, PinName rx) : serial(tx, rx) {
+    serial.baud(38400);
+}
+
+/**
+ * Dispose.
+ */
+Camera_LS_Y201::~Camera_LS_Y201() {
+}
+
+/**
+ * Reset module.
+ *
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::reset() {
+    uint8_t send[4] = {
+        0x56,
+        0x00,
+        0x26,
+        0x00
+    };
+    uint8_t recv[4];
+
+    waitIdle();
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x26)
+            && (recv[3] == 0x00)) {
+        ErrorCode r = waitInitEnd();
+        if (r != NoError) {
+            return r;
+        }
+        wait(4);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Set image size.
+ *
+ * @param is Image size.
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::setImageSize(ImageSize is) {
+    uint8_t send[9] = {
+        0x56,
+        0x00,
+        0x31,
+        0x05,
+        0x04,
+        0x01,
+        0x00,
+        0x19,
+        0x00    // 0x11:320x240, 0x00:640x480, 0x22:160x120
+    };
+    uint8_t recv[5];
+    switch (is) {
+        case ImageSize160x120:
+            send[8] = 0x22;
+            break;
+        case ImageSize320x280:
+            send[8] = 0x11;
+            break;
+        case ImageSize640x480:
+            send[8] = 0x00;
+            break;
+        default:
+            return InvalidArguments;
+    }
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x31)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x00)) {
+        wait(1);
+        return reset();
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Take picture.
+ *
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::takePicture() {
+    uint8_t send[5] = {
+        0x56,
+        0x00,
+        0x36,
+        0x01,
+        0x00
+    };
+    uint8_t recv[5];
+
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x36)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x00)) {
+        /*
+         * I think the camera need a time for operating.
+         * But there is no any comments on the documents.
+         */
+        wait_ms(100);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Read jpeg file size.
+ *
+ * @param fileSize File size.
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileSize(int *fileSize) {
+    uint8_t send[5] = {
+        0x56,
+        0x00,
+        0x34,
+        0x01,
+        0x00
+    };
+    uint8_t recv[9];
+
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x34)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x04)
+            && (recv[5] == 0x00)
+            && (recv[6] == 0x00)) {
+        *fileSize = ((recv[7] & 0x00ff) << 8)
+                    | ((recv[8] & 0x00ff) << 0);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Read jpeg file content.
+ *
+ * @param func A pointer to a call back function.
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz)) {
+    uint8_t send[16] = {
+        0x56,
+        0x00,
+        0x32,
+        0x0C,
+        0x00,
+        0x0A,
+        0x00,
+        0x00,
+        0x00, // MH
+        0x00, // ML
+        0x00,
+        0x00,
+        0x00, // KH
+        0x00, // KL
+        0x00, // XX
+        0x00  // XX
+    };
+    uint8_t body[32];
+    uint16_t m = 0; // Staring address.
+    uint16_t k = sizeof(body); // Packet size.
+    uint16_t x = 10;    // Interval time. XX XX * 0.01m[sec]
+    bool end = false;
+
+    /*
+     * Get the data size.
+     */
+    int siz_done = 0;
+    int siz_total = 0;
+    ErrorCode r = readJpegFileSize(&siz_total);
+    if (r != NoError) {
+        return r;
+    }
+
+    do {
+        send[8] = (m >> 8) & 0xff;
+        send[9] = (m >> 0) & 0xff;
+        send[12] = (k >> 8) & 0xff;
+        send[13] = (k >> 0) & 0xff;
+        send[14] = (x >> 8) & 0xff;
+        send[15] = (x >> 0) & 0xff;
+        /*
+         * Send a command.
+         */
+        if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+            return SendError;
+        }
+        /*
+         * Read the header of the response.
+         */
+        uint8_t header[5];
+        if (!recvBytes(header, sizeof(header), 2 * 1000 * 1000)) {
+            return RecvError;
+        }
+        /*
+         * Check the response and fetch an image data.
+         */
+        if ((header[0] == 0x76)
+                && (header[1] == 0x00)
+                && (header[2] == 0x32)
+                && (header[3] == 0x00)
+                && (header[4] == 0x00)) {
+            if (!recvBytes(body, sizeof(body), 2 * 1000 * 1000)) {
+                return RecvError;
+            }
+            siz_done += sizeof(body);
+            if (func != NULL) {
+                if (siz_done > siz_total) {
+                    siz_done = siz_total;
+                }
+                func(siz_done, siz_total, body, sizeof(body));
+            }
+            for (int i = 1; i < sizeof(body); i++) {
+                if ((body[i - 1] == 0xFF) && (body[i - 0] == 0xD9)) {
+                    end = true;
+                }
+            }
+        } else {
+            return UnexpectedReply;
+        }
+        /*
+         * Read the footer of the response.
+         */
+        uint8_t footer[5];
+        if (!recvBytes(footer, sizeof(footer), 2 * 1000 * 1000)) {
+            return RecvError;
+        }
+
+        m += sizeof(body);
+    } while (!end);
+    return NoError;
+}
+
+/**
+ * Stop taking pictures.
+ *
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::stopTakingPictures() {
+    uint8_t send[5] = {
+        0x56,
+        0x00,
+        0x36,
+        0x01,
+        0x03
+    };
+    uint8_t recv[5];
+
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x36)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x00)) {
+        /*
+         * I think the camera need a time for operating.
+         * But there is no any comments on the documents.
+         */
+        wait_ms(100);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Wait init end codes.
+ *
+ * @return True if the data sended.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::waitInitEnd() {
+    static const char *PWR_ON_MSG = "Init end\x0d\x0a";
+    for (int i = 0; i < strlen(PWR_ON_MSG); i++) {
+        static const int MAXCNT = 128;
+        int cnt = 0;
+        uint8_t c = 0x00;
+        do {
+            if (!recvBytes(&c, sizeof(c), 500 * 1000)) {
+                return Timeout;
+            }
+
+            /*
+             * What is the version of the camera.
+             * You can check the version with this code.
+             *
+             * VC0703 1.00
+             * 3o ctrl in
+             * Init end
+             */
+#if 0
+            printf("%c", c);
+#endif
+
+            cnt++;
+            if (MAXCNT < cnt) {
+                return UnexpectedReply;
+            }
+        } while (c != PWR_ON_MSG[i]);
+    }
+    return NoError;
+}
+
+/**
+ * Send bytes to camera module.
+ *
+ * @param buf Pointer to the data buffer.
+ * @param len Length of the data buffer.
+ *
+ * @return True if the data sended.
+ */
+bool Camera_LS_Y201::sendBytes(uint8_t *buf, size_t len, int timeout_us) {
+    for (uint32_t i = 0; i < (uint32_t)len; i++) {
+        int cnt = 0;
+        while (!serial.writeable()) {
+            wait_us(1);
+            cnt++;
+            if (timeout_us < cnt) {
+                return false;
+            }
+        }
+        serial.putc(buf[i]);
+    }
+    return true;
+}
+
+/**
+ * Receive bytes from camera module.
+ *
+ * @param buf Pointer to the data buffer.
+ * @param len Length of the data buffer.
+ *
+ * @return True if the data received.
+ */
+bool Camera_LS_Y201::recvBytes(uint8_t *buf, size_t len, int timeout_us) {
+    for (uint32_t i = 0; i < (uint32_t)len; i++) {
+        int cnt = 0;
+        while (!serial.readable()) {
+            wait_us(1);
+            cnt++;
+            if (timeout_us < cnt) {
+                return false;
+            }
+        }
+        buf[i] = serial.getc();
+    }
+    return true;
+}
+
+/**
+ * Wait received.
+ *
+ * @return True if the data received.
+ */
+bool Camera_LS_Y201::waitRecv() {
+    while (!serial.readable()) {
+    }
+    return true;
+}
+
+/**
+ * Wait idle state.
+ */
+bool Camera_LS_Y201::waitIdle() {
+    while (serial.readable()) {
+        serial.getc();
+    }
+    return true;
+}
diff -r 43358d40f879 -r e92ce527b8b0 Camera_LS_Y201.h
--- a/Camera_LS_Y201.h	Wed Dec 01 23:10:56 2010 +0000
+++ b/Camera_LS_Y201.h	Fri Oct 12 16:41:24 2012 +0000
@@ -1,166 +1,166 @@
-/**
- * =============================================================================
- * LS-Y201 device driver class (Version 0.0.1)
- * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
- *                      January 2010
- * =============================================================================
- * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- * =============================================================================
- */
-
-#ifndef LS_Y201_H
-#define LS_Y201_H
-
-#include "mbed.h"
-#include "SerialBuffered.h"
-
-/**
- * Camera
- */
-class Camera_LS_Y201 {
-public:
-
-    /**
-     * Create.
-     *
-     * @param tx Transmitter.
-     * @param rx Receiver.
-     */
-    Camera_LS_Y201(PinName tx, PinName rx);
-    
-    /**
-     * Dispose.
-     */
-    ~Camera_LS_Y201();
-    
-    /**
-     * Error code.
-     */
-    enum ErrorCode {
-        NoError = 0,
-        UnexpectedReply,
-        Timeout,
-        SendError,
-        RecvError,
-        InvalidArguments
-    };
-    
-    /**
-     * Image size.
-     */
-    enum ImageSize {
-        ImageSize160x120,   /**< 160x120. */
-        ImageSize320x280,   /**< 320x280. */
-        ImageSize640x480    /**< 640x480. */
-    };
-
-    /**
-     * Reset module.
-     *
-     * @return Error code.
-     */
-    ErrorCode reset();
-
-    /**
-     * Set image size.
-     *
-     * @param is Image size.
-     * @return Error code.
-     */
-    ErrorCode setImageSize(ImageSize is);
-
-    /**
-     * Take picture.
-     *
-     * @return Error code.
-     */
-    ErrorCode takePicture();
-
-    /**
-     * Read jpeg file size.
-     *
-     * @param fileSize File size.
-     * @return Error code.
-     */
-    ErrorCode readJpegFileSize(int *fileSize);
-
-    /**
-     * Read jpeg file content.
-     *
-     * @param func A pointer to a call back function.
-     * @return Error code.
-     */
-    ErrorCode readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz));
-
-    /**
-     * Stop taking pictures.
-     *
-     * @return Error code.
-     */
-    ErrorCode stopTakingPictures();
-
-private:
-    SerialBuffered serial;
-
-    /**
-     * Wait init end codes.
-     *
-     * @return Error code.
-     */
-    ErrorCode waitInitEnd();
-
-    /**
-     * Send bytes to camera module.
-     *
-     * @param buf Pointer to the data buffer.
-     * @param len Length of the data buffer.
-     *
-     * @return True if the data sended.
-     */
-    bool sendBytes(uint8_t *buf, size_t len, int timeout_us);
-
-    /**
-     * Receive bytes from camera module.
-     *
-     * @param buf Pointer to the data buffer.
-     * @param len Length of the data buffer.
-     *
-     * @return True if the data received.
-     */
-    bool recvBytes(uint8_t *buf, size_t len, int timeout_us);
-
-    /**
-     * Wait received.
-     *
-     * @return True if the data received.
-     */
-    bool waitRecv();
-
-    /**
-     * Wait idle state.
-     *
-     * @return True if it succeed.
-     */
-    bool waitIdle();
-
-};
-
-#endif
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#ifndef LS_Y201_H
+#define LS_Y201_H
+
+#include "mbed.h"
+#include "SerialBuffered.h"
+
+/**
+ * Camera
+ */
+class Camera_LS_Y201 {
+public:
+
+    /**
+     * Create.
+     *
+     * @param tx Transmitter.
+     * @param rx Receiver.
+     */
+    Camera_LS_Y201(PinName tx, PinName rx);
+    
+    /**
+     * Dispose.
+     */
+    ~Camera_LS_Y201();
+    
+    /**
+     * Error code.
+     */
+    enum ErrorCode {
+        NoError = 0,
+        UnexpectedReply,
+        Timeout,
+        SendError,
+        RecvError,
+        InvalidArguments
+    };
+    
+    /**
+     * Image size.
+     */
+    enum ImageSize {
+        ImageSize160x120,   /**< 160x120. */
+        ImageSize320x280,   /**< 320x280. */
+        ImageSize640x480    /**< 640x480. */
+    };
+
+    /**
+     * Reset module.
+     *
+     * @return Error code.
+     */
+    ErrorCode reset();
+
+    /**
+     * Set image size.
+     *
+     * @param is Image size.
+     * @return Error code.
+     */
+    ErrorCode setImageSize(ImageSize is);
+
+    /**
+     * Take picture.
+     *
+     * @return Error code.
+     */
+    ErrorCode takePicture();
+
+    /**
+     * Read jpeg file size.
+     *
+     * @param fileSize File size.
+     * @return Error code.
+     */
+    ErrorCode readJpegFileSize(int *fileSize);
+
+    /**
+     * Read jpeg file content.
+     *
+     * @param func A pointer to a call back function.
+     * @return Error code.
+     */
+    ErrorCode readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz));
+
+    /**
+     * Stop taking pictures.
+     *
+     * @return Error code.
+     */
+    ErrorCode stopTakingPictures();
+
+private:
+    SerialBuffered serial;
+
+    /**
+     * Wait init end codes.
+     *
+     * @return Error code.
+     */
+    ErrorCode waitInitEnd();
+
+    /**
+     * Send bytes to camera module.
+     *
+     * @param buf Pointer to the data buffer.
+     * @param len Length of the data buffer.
+     *
+     * @return True if the data sended.
+     */
+    bool sendBytes(uint8_t *buf, size_t len, int timeout_us);
+
+    /**
+     * Receive bytes from camera module.
+     *
+     * @param buf Pointer to the data buffer.
+     * @param len Length of the data buffer.
+     *
+     * @return True if the data received.
+     */
+    bool recvBytes(uint8_t *buf, size_t len, int timeout_us);
+
+    /**
+     * Wait received.
+     *
+     * @return True if the data received.
+     */
+    bool waitRecv();
+
+    /**
+     * Wait idle state.
+     *
+     * @return True if it succeed.
+     */
+    bool waitIdle();
+
+};
+
+#endif
diff -r 43358d40f879 -r e92ce527b8b0 SerialBuffered.cpp
--- a/SerialBuffered.cpp	Wed Dec 01 23:10:56 2010 +0000
+++ b/SerialBuffered.cpp	Fri Oct 12 16:41:24 2012 +0000
@@ -1,127 +1,127 @@
-/**
- * =============================================================================
- * LS-Y201 device driver class (Version 0.0.1)
- * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
- *                      January 2010
- * =============================================================================
- * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- * =============================================================================
- */
-
-#include "mbed.h"
-#include "SerialBuffered.h"
-
-/**
- * Create a buffered serial class.
- *
- * @param tx A pin for transmit.
- * @param rx A pin for receive.
- */
-SerialBuffered::SerialBuffered(PinName tx, PinName rx) : Serial(tx, rx) {
-    indexContentStart = 0;
-    indexContentEnd = 0;
-    timeout = 1;
-    attach(this, &SerialBuffered::handleInterrupt);
-}
-
-/**
- * Destroy.
- */
-SerialBuffered::~SerialBuffered() {
-}
-
-/**
- * Set timeout for getc().
- *
- * @param ms milliseconds. (-1:Disable timeout)
- */
-void SerialBuffered::setTimeout(int ms) {
-    timeout = ms;
-}
-
-/**
- * Read requested bytes.
- *
- * @param bytes A pointer to a buffer.
- * @param requested Length.
- *
- * @return Readed byte length.
- */
-size_t SerialBuffered::readBytes(uint8_t *bytes, size_t requested) {
-    int i = 0;
-    while (i < requested) {
-        int c = getc();
-        if (c < 0) {
-            break;
-        }
-        bytes[i] = c;
-        i++;
-    }
-    return i;
-}
-
-/**
- * Get a character.
- *
- * @return A character. (-1:timeout)
- */
-int SerialBuffered::getc() {
-    timer.reset();
-    timer.start();
-    while (indexContentStart == indexContentEnd) {
-        wait_ms(1);
-        if ((timeout > 0) && (timer.read_ms() > timeout)) {
-            /*
-             * Timeout occured.
-             */
-            // printf("Timeout occured.\n");
-            return EOF;
-        }
-    }
-    timer.stop();
-
-    uint8_t result = buffer[indexContentStart++];
-    indexContentStart =  indexContentStart % BUFFERSIZE;
-
-    return result;
-}
-
-/**
- * Returns 1 if there is a character available to read, 0 otherwise.
- */
-int SerialBuffered::readable() {
-    return indexContentStart != indexContentEnd;
-}
-
-void SerialBuffered::handleInterrupt() {
-    while (Serial::readable()) {
-        if (indexContentStart == ((indexContentEnd + 1) % BUFFERSIZE)) {
-            /*
-             * Buffer overrun occured.
-             */
-            // printf("Buffer overrun occured.\n");
-            Serial::getc();
-        } else {
-            buffer[indexContentEnd++] = Serial::getc();
-            indexContentEnd = indexContentEnd % BUFFERSIZE;
-        }
-    }
-}
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#include "mbed.h"
+#include "SerialBuffered.h"
+
+/**
+ * Create a buffered serial class.
+ *
+ * @param tx A pin for transmit.
+ * @param rx A pin for receive.
+ */
+SerialBuffered::SerialBuffered(PinName tx, PinName rx) : Serial(tx, rx) {
+    indexContentStart = 0;
+    indexContentEnd = 0;
+    timeout = 1;
+    attach(this, &SerialBuffered::handleInterrupt);
+}
+
+/**
+ * Destroy.
+ */
+SerialBuffered::~SerialBuffered() {
+}
+
+/**
+ * Set timeout for getc().
+ *
+ * @param ms milliseconds. (-1:Disable timeout)
+ */
+void SerialBuffered::setTimeout(int ms) {
+    timeout = ms;
+}
+
+/**
+ * Read requested bytes.
+ *
+ * @param bytes A pointer to a buffer.
+ * @param requested Length.
+ *
+ * @return Readed byte length.
+ */
+size_t SerialBuffered::readBytes(uint8_t *bytes, size_t requested) {
+    int i = 0;
+    while (i < requested) {
+        int c = getc();
+        if (c < 0) {
+            break;
+        }
+        bytes[i] = c;
+        i++;
+    }
+    return i;
+}
+
+/**
+ * Get a character.
+ *
+ * @return A character. (-1:timeout)
+ */
+int SerialBuffered::getc() {
+    timer.reset();
+    timer.start();
+    while (indexContentStart == indexContentEnd) {
+        wait_ms(1);
+        if ((timeout > 0) && (timer.read_ms() > timeout)) {
+            /*
+             * Timeout occured.
+             */
+            // printf("Timeout occured.\n");
+            return EOF;
+        }
+    }
+    timer.stop();
+
+    uint8_t result = buffer[indexContentStart++];
+    indexContentStart =  indexContentStart % BUFFERSIZE;
+
+    return result;
+}
+
+/**
+ * Returns 1 if there is a character available to read, 0 otherwise.
+ */
+int SerialBuffered::readable() {
+    return indexContentStart != indexContentEnd;
+}
+
+void SerialBuffered::handleInterrupt() {
+    while (Serial::readable()) {
+        if (indexContentStart == ((indexContentEnd + 1) % BUFFERSIZE)) {
+            /*
+             * Buffer overrun occured.
+             */
+            // printf("Buffer overrun occured.\n");
+            Serial::getc();
+        } else {
+            buffer[indexContentEnd++] = Serial::getc();
+            indexContentEnd = indexContentEnd % BUFFERSIZE;
+        }
+    }
+}
diff -r 43358d40f879 -r e92ce527b8b0 SerialBuffered.h
--- a/SerialBuffered.h	Wed Dec 01 23:10:56 2010 +0000
+++ b/SerialBuffered.h	Fri Oct 12 16:41:24 2012 +0000
@@ -1,89 +1,89 @@
-/**
- * =============================================================================
- * LS-Y201 device driver class (Version 0.0.1)
- * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
- *                      January 2010
- * =============================================================================
- * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- * =============================================================================
- */
-
-#ifndef _SERIAL_BUFFERED_H_
-#define _SERIAL_BUFFERED_H_
-
-/**
- * Buffered serial class.
- */
-class SerialBuffered : public Serial {
-public:
-    /**
-     * Create a buffered serial class.
-     *
-     * @param tx A pin for transmit.
-     * @param rx A pin for receive.
-     */
-    SerialBuffered(PinName tx, PinName rx);
-
-    /**
-     * Destroy.
-     */
-    virtual ~SerialBuffered();
-
-    /**
-     * Get a character.
-     *
-     * @return A character. (-1:timeout)
-     */
-    int getc();
-
-    /**
-     * Returns 1 if there is a character available to read, 0 otherwise.
-     */
-    int readable();
-
-    /**
-     * Set timeout for getc().
-     *
-     * @param ms milliseconds. (-1:Disable timeout)
-     */
-    void setTimeout(int ms);
-
-    /**
-     * Read requested bytes.
-     *
-     * @param bytes A pointer to a buffer.
-     * @param requested Length.
-     *
-     * @return Readed byte length.
-     */
-    size_t readBytes(uint8_t *bytes, size_t requested);
-
-private:
-    void handleInterrupt();
-    static const int BUFFERSIZE = 4096;
-    uint8_t buffer[BUFFERSIZE];            // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
-    uint16_t indexContentStart;   // index of first bytes of content
-    uint16_t indexContentEnd;     // index of bytes after last byte of content
-    int timeout;
-    Timer timer;
-};
-
-#endif
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#ifndef _SERIAL_BUFFERED_H_
+#define _SERIAL_BUFFERED_H_
+
+/**
+ * Buffered serial class.
+ */
+class SerialBuffered : public Serial {
+public:
+    /**
+     * Create a buffered serial class.
+     *
+     * @param tx A pin for transmit.
+     * @param rx A pin for receive.
+     */
+    SerialBuffered(PinName tx, PinName rx);
+
+    /**
+     * Destroy.
+     */
+    virtual ~SerialBuffered();
+
+    /**
+     * Get a character.
+     *
+     * @return A character. (-1:timeout)
+     */
+    int getc();
+
+    /**
+     * Returns 1 if there is a character available to read, 0 otherwise.
+     */
+    int readable();
+
+    /**
+     * Set timeout for getc().
+     *
+     * @param ms milliseconds. (-1:Disable timeout)
+     */
+    void setTimeout(int ms);
+
+    /**
+     * Read requested bytes.
+     *
+     * @param bytes A pointer to a buffer.
+     * @param requested Length.
+     *
+     * @return Readed byte length.
+     */
+    size_t readBytes(uint8_t *bytes, size_t requested);
+
+private:
+    void handleInterrupt();
+    static const int BUFFERSIZE = 4096;
+    uint8_t buffer[BUFFERSIZE];            // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
+    uint16_t indexContentStart;   // index of first bytes of content
+    uint16_t indexContentEnd;     // index of bytes after last byte of content
+    int timeout;
+    Timer timer;
+};
+
+#endif