Homologation Cachan

Fork of TPixy-Interface by Stephen Wilkins

Committer:
swilkins8
Date:
Mon Mar 14 18:53:43 2016 +0000
Revision:
3:66df7d295245
Parent:
0:ef0e3c67dc5b
Completed comments/documentation for all classes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
swilkins8 0:ef0e3c67dc5b 1 //
swilkins8 0:ef0e3c67dc5b 2 // begin license header
swilkins8 0:ef0e3c67dc5b 3 //
swilkins8 0:ef0e3c67dc5b 4 // This file is part of Pixy CMUcam5 or "Pixy" for short
swilkins8 0:ef0e3c67dc5b 5 //
swilkins8 0:ef0e3c67dc5b 6 // All Pixy source code is provided under the terms of the
swilkins8 0:ef0e3c67dc5b 7 // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
swilkins8 0:ef0e3c67dc5b 8 // Those wishing to use Pixy source code, software and/or
swilkins8 0:ef0e3c67dc5b 9 // technologies under different licensing terms should contact us at
swilkins8 0:ef0e3c67dc5b 10 // cmucam@cs.cmu.edu. Such licensing terms are available for
swilkins8 0:ef0e3c67dc5b 11 // all portions of the Pixy codebase presented here.
swilkins8 0:ef0e3c67dc5b 12 //
swilkins8 0:ef0e3c67dc5b 13 // end license header
swilkins8 0:ef0e3c67dc5b 14 //
swilkins8 0:ef0e3c67dc5b 15 // This file is for defining the SPI-related classes. It's called Pixy.h instead
swilkins8 0:ef0e3c67dc5b 16 // of Pixy_SPI.h because it's the default/recommended communication method
swilkins8 0:ef0e3c67dc5b 17 // with Arduino. This class assumes you are using the ICSP connector to talk to
swilkins8 0:ef0e3c67dc5b 18 // Pixy from your Arduino. For more information go to:
swilkins8 0:ef0e3c67dc5b 19 //
swilkins8 0:ef0e3c67dc5b 20 //http://cmucam.org/projects/cmucam5/wiki/Hooking_up_Pixy_to_a_Microcontroller_(like_an_Arduino)
swilkins8 0:ef0e3c67dc5b 21 //
swilkins8 0:ef0e3c67dc5b 22
swilkins8 0:ef0e3c67dc5b 23 #ifndef _TPIXY_INTERFACE_H
swilkins8 0:ef0e3c67dc5b 24 #define _TPIXY_INTERFACE_H
swilkins8 0:ef0e3c67dc5b 25
swilkins8 0:ef0e3c67dc5b 26 #include "TPixy.h"
swilkins8 0:ef0e3c67dc5b 27
swilkins8 0:ef0e3c67dc5b 28 #define PIXY_SYNC_BYTE 0x5a
swilkins8 0:ef0e3c67dc5b 29 #define PIXY_SYNC_BYTE_DATA 0x5b
swilkins8 0:ef0e3c67dc5b 30 #define PIXY_BUF_SIZE 16
swilkins8 0:ef0e3c67dc5b 31
swilkins8 3:66df7d295245 32 /** An interface for communicating between the Pixy and a specific hardware interface
swilkins8 3:66df7d295245 33 */
swilkins8 0:ef0e3c67dc5b 34 class TPixyInterface
swilkins8 0:ef0e3c67dc5b 35 {
swilkins8 0:ef0e3c67dc5b 36 public:
swilkins8 3:66df7d295245 37 /** Creates a TPixyInterface
swilkins8 3:66df7d295245 38 */
swilkins8 0:ef0e3c67dc5b 39 TPixyInterface() {}
swilkins8 3:66df7d295245 40 /** Initializes a TPixyInterface
swilkins8 3:66df7d295245 41 */
swilkins8 0:ef0e3c67dc5b 42 virtual void init() = 0;
swilkins8 3:66df7d295245 43 /** Sends the given data to the Pixy with a given data length
swilkins8 3:66df7d295245 44 * @param data the data to send
swilkins8 3:66df7d295245 45 * @param len the length of the data to send
swilkins8 3:66df7d295245 46 * @return the interface return signal
swilkins8 3:66df7d295245 47 */
swilkins8 0:ef0e3c67dc5b 48 virtual int8_t send(uint8_t *data, uint8_t len) = 0;
swilkins8 3:66df7d295245 49 /** Sets an argument for the interface to use
swilkins8 3:66df7d295245 50 * @param arg the argument to use
swilkins8 3:66df7d295245 51 */
swilkins8 0:ef0e3c67dc5b 52 virtual void setArg(uint16_t arg) = 0;
swilkins8 3:66df7d295245 53 /** Reads a word from the interface
swilkins8 3:66df7d295245 54 * @return the word read from the interface
swilkins8 3:66df7d295245 55 */
swilkins8 0:ef0e3c67dc5b 56 virtual uint16_t getWord() = 0;
swilkins8 3:66df7d295245 57 /** Reads a byte from the interface
swilkins8 3:66df7d295245 58 * @return the byte read from the interface
swilkins8 3:66df7d295245 59 */
swilkins8 0:ef0e3c67dc5b 60 virtual uint8_t getByte() = 0;
swilkins8 0:ef0e3c67dc5b 61 };
swilkins8 0:ef0e3c67dc5b 62
swilkins8 0:ef0e3c67dc5b 63
swilkins8 0:ef0e3c67dc5b 64 template <class BufType> class CircularQ
swilkins8 0:ef0e3c67dc5b 65 {
swilkins8 0:ef0e3c67dc5b 66 public:
swilkins8 0:ef0e3c67dc5b 67 BufType buf[PIXY_BUF_SIZE];
swilkins8 0:ef0e3c67dc5b 68 uint8_t len;
swilkins8 0:ef0e3c67dc5b 69 uint8_t writeIndex;
swilkins8 0:ef0e3c67dc5b 70 uint8_t readIndex;
swilkins8 0:ef0e3c67dc5b 71
swilkins8 0:ef0e3c67dc5b 72 CircularQ();
swilkins8 0:ef0e3c67dc5b 73 bool read(BufType *c);
swilkins8 0:ef0e3c67dc5b 74 uint8_t freeLen();
swilkins8 0:ef0e3c67dc5b 75 bool write(BufType c);
swilkins8 0:ef0e3c67dc5b 76 };
swilkins8 0:ef0e3c67dc5b 77
swilkins8 3:66df7d295245 78 /** An interface for communicating between the Pixy via an SPI interface
swilkins8 3:66df7d295245 79 */
swilkins8 0:ef0e3c67dc5b 80 class PixyInterfaceSPI : TPixyInterface
swilkins8 0:ef0e3c67dc5b 81 {
swilkins8 0:ef0e3c67dc5b 82 public:
swilkins8 0:ef0e3c67dc5b 83 SPI* spi;
swilkins8 3:66df7d295245 84 /** Constructs a PixyInterfaceSPI object
swilkins8 3:66df7d295245 85 * @param interface the SPI pointer
swilkins8 3:66df7d295245 86 */
swilkins8 0:ef0e3c67dc5b 87 PixyInterfaceSPI(SPI* interface);
swilkins8 3:66df7d295245 88 /** Initializes the PixyInterfaceSPI
swilkins8 3:66df7d295245 89 */
swilkins8 0:ef0e3c67dc5b 90 virtual void init();
swilkins8 3:66df7d295245 91 /** Reads a word from the interface
swilkins8 3:66df7d295245 92 * @return the word read from the interface
swilkins8 3:66df7d295245 93 */
swilkins8 0:ef0e3c67dc5b 94 virtual uint16_t getWord();
swilkins8 3:66df7d295245 95 /** Reads a byte from the interface
swilkins8 3:66df7d295245 96 * @return the byte read from the interface
swilkins8 3:66df7d295245 97 */
swilkins8 0:ef0e3c67dc5b 98 virtual uint8_t getByte();
swilkins8 3:66df7d295245 99 /** Sends the given data to the Pixy with a given data length
swilkins8 3:66df7d295245 100 * @param data the data to send
swilkins8 3:66df7d295245 101 * @param len the length of the data to send
swilkins8 3:66df7d295245 102 * @return the interface return signal
swilkins8 3:66df7d295245 103 */
swilkins8 0:ef0e3c67dc5b 104 virtual int8_t send(uint8_t *data, uint8_t len);
swilkins8 3:66df7d295245 105 /** Sets an argument for the interface to use [unused]
swilkins8 3:66df7d295245 106 * @param arg the argument to use
swilkins8 3:66df7d295245 107 */
swilkins8 0:ef0e3c67dc5b 108 virtual void setArg(uint16_t arg);
swilkins8 0:ef0e3c67dc5b 109
swilkins8 0:ef0e3c67dc5b 110 private:
swilkins8 0:ef0e3c67dc5b 111 // we need a little circular queues for both directions
swilkins8 0:ef0e3c67dc5b 112 CircularQ<uint8_t> outQ;
swilkins8 0:ef0e3c67dc5b 113 CircularQ<uint16_t> inQ;
swilkins8 0:ef0e3c67dc5b 114
swilkins8 0:ef0e3c67dc5b 115 uint16_t getWordHw();
swilkins8 0:ef0e3c67dc5b 116 void flushSend();
swilkins8 0:ef0e3c67dc5b 117 };
swilkins8 0:ef0e3c67dc5b 118
swilkins8 0:ef0e3c67dc5b 119
swilkins8 0:ef0e3c67dc5b 120 /*
swilkins8 0:ef0e3c67dc5b 121 class PixyInterfaceI2C : TPixyInterface
swilkins8 0:ef0e3c67dc5b 122 {
swilkins8 0:ef0e3c67dc5b 123 public:
swilkins8 0:ef0e3c67dc5b 124 SPI* spi;
swilkins8 0:ef0e3c67dc5b 125 PixyInterfaceI2C(I2C* interface);
swilkins8 0:ef0e3c67dc5b 126 virtual void init();
swilkins8 0:ef0e3c67dc5b 127 virtual uint16_t getWord();
swilkins8 0:ef0e3c67dc5b 128 virtual uint8_t getByte();
swilkins8 0:ef0e3c67dc5b 129 virtual int8_t send(uint8_t *data, uint8_t len);
swilkins8 0:ef0e3c67dc5b 130 virtual void setArg(uint16_t arg);
swilkins8 0:ef0e3c67dc5b 131
swilkins8 0:ef0e3c67dc5b 132 private:
swilkins8 0:ef0e3c67dc5b 133 // we need a little circular queues for both directions
swilkins8 0:ef0e3c67dc5b 134 CircularQ<uint8_t> outQ;
swilkins8 0:ef0e3c67dc5b 135 CircularQ<uint16_t> inQ;
swilkins8 0:ef0e3c67dc5b 136
swilkins8 0:ef0e3c67dc5b 137 uint16_t getWordHw();
swilkins8 0:ef0e3c67dc5b 138 void flushSend();
swilkins8 0:ef0e3c67dc5b 139 };*/
swilkins8 0:ef0e3c67dc5b 140
swilkins8 0:ef0e3c67dc5b 141 #endif