Description.

Dependents:   RoboPanorama 4180_Project ProjetMacIntel

Fork of Camera_LS_Y201 by Shinichiro Nakamura

Committer:
lndv3
Date:
Fri Oct 12 16:41:24 2012 +0000
Revision:
2:e92ce527b8b0
Parent:
0:f71232252dcf
Commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lndv3 2:e92ce527b8b0 1 /**
lndv3 2:e92ce527b8b0 2 * =============================================================================
lndv3 2:e92ce527b8b0 3 * LS-Y201 device driver class (Version 0.0.1)
lndv3 2:e92ce527b8b0 4 * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
lndv3 2:e92ce527b8b0 5 * January 2010
lndv3 2:e92ce527b8b0 6 * =============================================================================
lndv3 2:e92ce527b8b0 7 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
lndv3 2:e92ce527b8b0 8 *
lndv3 2:e92ce527b8b0 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
lndv3 2:e92ce527b8b0 10 * of this software and associated documentation files (the "Software"), to deal
lndv3 2:e92ce527b8b0 11 * in the Software without restriction, including without limitation the rights
lndv3 2:e92ce527b8b0 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
lndv3 2:e92ce527b8b0 13 * copies of the Software, and to permit persons to whom the Software is
lndv3 2:e92ce527b8b0 14 * furnished to do so, subject to the following conditions:
lndv3 2:e92ce527b8b0 15 *
lndv3 2:e92ce527b8b0 16 * The above copyright notice and this permission notice shall be included in
lndv3 2:e92ce527b8b0 17 * all copies or substantial portions of the Software.
lndv3 2:e92ce527b8b0 18 *
lndv3 2:e92ce527b8b0 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
lndv3 2:e92ce527b8b0 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
lndv3 2:e92ce527b8b0 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
lndv3 2:e92ce527b8b0 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
lndv3 2:e92ce527b8b0 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
lndv3 2:e92ce527b8b0 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
lndv3 2:e92ce527b8b0 25 * THE SOFTWARE.
lndv3 2:e92ce527b8b0 26 * =============================================================================
lndv3 2:e92ce527b8b0 27 */
lndv3 2:e92ce527b8b0 28
lndv3 2:e92ce527b8b0 29 #ifndef _SERIAL_BUFFERED_H_
lndv3 2:e92ce527b8b0 30 #define _SERIAL_BUFFERED_H_
lndv3 2:e92ce527b8b0 31
lndv3 2:e92ce527b8b0 32 /**
lndv3 2:e92ce527b8b0 33 * Buffered serial class.
lndv3 2:e92ce527b8b0 34 */
lndv3 2:e92ce527b8b0 35 class SerialBuffered : public Serial {
lndv3 2:e92ce527b8b0 36 public:
lndv3 2:e92ce527b8b0 37 /**
lndv3 2:e92ce527b8b0 38 * Create a buffered serial class.
lndv3 2:e92ce527b8b0 39 *
lndv3 2:e92ce527b8b0 40 * @param tx A pin for transmit.
lndv3 2:e92ce527b8b0 41 * @param rx A pin for receive.
lndv3 2:e92ce527b8b0 42 */
lndv3 2:e92ce527b8b0 43 SerialBuffered(PinName tx, PinName rx);
lndv3 2:e92ce527b8b0 44
lndv3 2:e92ce527b8b0 45 /**
lndv3 2:e92ce527b8b0 46 * Destroy.
lndv3 2:e92ce527b8b0 47 */
lndv3 2:e92ce527b8b0 48 virtual ~SerialBuffered();
lndv3 2:e92ce527b8b0 49
lndv3 2:e92ce527b8b0 50 /**
lndv3 2:e92ce527b8b0 51 * Get a character.
lndv3 2:e92ce527b8b0 52 *
lndv3 2:e92ce527b8b0 53 * @return A character. (-1:timeout)
lndv3 2:e92ce527b8b0 54 */
lndv3 2:e92ce527b8b0 55 int getc();
lndv3 2:e92ce527b8b0 56
lndv3 2:e92ce527b8b0 57 /**
lndv3 2:e92ce527b8b0 58 * Returns 1 if there is a character available to read, 0 otherwise.
lndv3 2:e92ce527b8b0 59 */
lndv3 2:e92ce527b8b0 60 int readable();
lndv3 2:e92ce527b8b0 61
lndv3 2:e92ce527b8b0 62 /**
lndv3 2:e92ce527b8b0 63 * Set timeout for getc().
lndv3 2:e92ce527b8b0 64 *
lndv3 2:e92ce527b8b0 65 * @param ms milliseconds. (-1:Disable timeout)
lndv3 2:e92ce527b8b0 66 */
lndv3 2:e92ce527b8b0 67 void setTimeout(int ms);
lndv3 2:e92ce527b8b0 68
lndv3 2:e92ce527b8b0 69 /**
lndv3 2:e92ce527b8b0 70 * Read requested bytes.
lndv3 2:e92ce527b8b0 71 *
lndv3 2:e92ce527b8b0 72 * @param bytes A pointer to a buffer.
lndv3 2:e92ce527b8b0 73 * @param requested Length.
lndv3 2:e92ce527b8b0 74 *
lndv3 2:e92ce527b8b0 75 * @return Readed byte length.
lndv3 2:e92ce527b8b0 76 */
lndv3 2:e92ce527b8b0 77 size_t readBytes(uint8_t *bytes, size_t requested);
lndv3 2:e92ce527b8b0 78
lndv3 2:e92ce527b8b0 79 private:
lndv3 2:e92ce527b8b0 80 void handleInterrupt();
lndv3 2:e92ce527b8b0 81 static const int BUFFERSIZE = 4096;
lndv3 2:e92ce527b8b0 82 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
lndv3 2:e92ce527b8b0 83 uint16_t indexContentStart; // index of first bytes of content
lndv3 2:e92ce527b8b0 84 uint16_t indexContentEnd; // index of bytes after last byte of content
lndv3 2:e92ce527b8b0 85 int timeout;
lndv3 2:e92ce527b8b0 86 Timer timer;
lndv3 2:e92ce527b8b0 87 };
lndv3 2:e92ce527b8b0 88
lndv3 2:e92ce527b8b0 89 #endif