Library used to initialize and to communicate with the CMUcam5 Pixy

Dependencies:   mbed

Dependents:   PixyStereoCam

Committer:
MBM
Date:
Tue Aug 12 11:01:31 2014 +0000
Revision:
0:56a3009221d3
The PixyLibrary was created from the Arduino libraries for the CMUcam5 Pixy found on http://cmucam.org/projects/cmucam5/files.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MBM 0:56a3009221d3 1 //--------------------------------------------------------------------------------------------
MBM 0:56a3009221d3 2 //Original Property of: charmedlabs.com/pixystart -> arduino_pixy-x.y.z.zip
MBM 0:56a3009221d3 3 //
MBM 0:56a3009221d3 4 //Modifications made by: Mathieu Malone
MBM 0:56a3009221d3 5 //Modifications: Modified Arduino code to function with mbed development platform
MBM 0:56a3009221d3 6 //Output Method: This program uses "Serial pc(USBTX, USBRX)" in order to allow communication
MBM 0:56a3009221d3 7 // between the mbed platform and putty terminal through USB
MBM 0:56a3009221d3 8 //
MBM 0:56a3009221d3 9 //Latest update by: Mathieu Malone
MBM 0:56a3009221d3 10 //Date of last update: July 24th, 2014
MBM 0:56a3009221d3 11 //--------------------------------------------------------------------------------------------
MBM 0:56a3009221d3 12 //
MBM 0:56a3009221d3 13 // begin license header
MBM 0:56a3009221d3 14 //
MBM 0:56a3009221d3 15 // This file is part of Pixy CMUcam5 or "Pixy" for short
MBM 0:56a3009221d3 16 //
MBM 0:56a3009221d3 17 // All Pixy source code is provided under the terms of the
MBM 0:56a3009221d3 18 // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
MBM 0:56a3009221d3 19 // Those wishing to use Pixy source code, software and/or
MBM 0:56a3009221d3 20 // technologies under different licensing terms should contact us at
MBM 0:56a3009221d3 21 // cmucam@cs.cmu.edu. Such licensing terms are available for
MBM 0:56a3009221d3 22 // all portions of the Pixy codebase presented here.
MBM 0:56a3009221d3 23 //
MBM 0:56a3009221d3 24 // end license header
MBM 0:56a3009221d3 25 //
MBM 0:56a3009221d3 26
MBM 0:56a3009221d3 27 #ifndef _SPI_H2
MBM 0:56a3009221d3 28 #define _SPI_H2
MBM 0:56a3009221d3 29 #include "iserial2.h"
MBM 0:56a3009221d3 30
MBM 0:56a3009221d3 31 #define SPI_RECEIVEBUF_SIZE2 16
MBM 0:56a3009221d3 32 #define SPI_TRANSMITBUF_SIZE2 16
MBM 0:56a3009221d3 33
MBM 0:56a3009221d3 34 #define SS_ASSERT2() LPC_SGPIO->GPIO_OUTREG2 = 0;
MBM 0:56a3009221d3 35 #define SS_NEGATE2() LPC_SGPIO->GPIO_OUTREG2 = 1<<14;
MBM 0:56a3009221d3 36
MBM 0:56a3009221d3 37 #define SPI_SYNC_MASK2 0xff00
MBM 0:56a3009221d3 38 #define SPI_SYNC_WORD2 0x5a00
MBM 0:56a3009221d3 39 #define SPI_SYNC_WORD_DATA2 0x5b00
MBM 0:56a3009221d3 40 #define SPI_MIN_SYNC_COUNT2 5
MBM 0:56a3009221d3 41
MBM 0:56a3009221d3 42 class Spi2 : public Iserial2
MBM 0:56a3009221d3 43 {
MBM 0:56a3009221d3 44 public:
MBM 0:56a3009221d3 45 Spi2(SerialCallback2 callback2);
MBM 0:56a3009221d3 46
MBM 0:56a3009221d3 47 // Iserial methods
MBM 0:56a3009221d3 48 virtual int open2();
MBM 0:56a3009221d3 49 virtual int close2();
MBM 0:56a3009221d3 50 virtual int receive2(uint8_t *buf2, uint32_t len2);
MBM 0:56a3009221d3 51 virtual int receiveLen2();
MBM 0:56a3009221d3 52 virtual int update2();
MBM 0:56a3009221d3 53
MBM 0:56a3009221d3 54 void slaveHandler2();
MBM 0:56a3009221d3 55
MBM 0:56a3009221d3 56 private:
MBM 0:56a3009221d3 57 int checkIdle2();
MBM 0:56a3009221d3 58 int sync2();
MBM 0:56a3009221d3 59 ReceiveQ2<uint16_t> m_rq2;
MBM 0:56a3009221d3 60 TransmitQ2<uint16_t> m_tq2;
MBM 0:56a3009221d3 61
MBM 0:56a3009221d3 62 bool m_sync2;
MBM 0:56a3009221d3 63 uint32_t m_recvCounter2;
MBM 0:56a3009221d3 64 uint32_t m_lastRecvCounter2;
MBM 0:56a3009221d3 65 uint8_t m_syncCounter2;
MBM 0:56a3009221d3 66 };
MBM 0:56a3009221d3 67
MBM 0:56a3009221d3 68 void SPIinit2(SerialCallback2 callback2);
MBM 0:56a3009221d3 69
MBM 0:56a3009221d3 70 extern Spi2 *g_spi2;
MBM 0:56a3009221d3 71
MBM 0:56a3009221d3 72 #endif