test

Dependencies:   Nanopb iSerial mbed BaseJpegDecode FatFileSystem SDFileSystem RingBuffer Camera_LS_Y201

Committer:
cgraham
Date:
Thu Sep 18 15:21:47 2014 +0000
Revision:
0:d69efd0ee139
test

Who changed what in which revision?

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