same
Fork of PixyLibrary by
SPI1.h@0:56a3009221d3, 2014-08-12 (annotated)
- 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?
User | Revision | Line number | New 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_H1 |
MBM | 0:56a3009221d3 | 28 | #define _SPI_H1 |
MBM | 0:56a3009221d3 | 29 | #include "iserial1.h" |
MBM | 0:56a3009221d3 | 30 | |
MBM | 0:56a3009221d3 | 31 | #define SPI_RECEIVEBUF_SIZE1 16 |
MBM | 0:56a3009221d3 | 32 | #define SPI_TRANSMITBUF_SIZE1 16 |
MBM | 0:56a3009221d3 | 33 | |
MBM | 0:56a3009221d3 | 34 | #define SS_ASSERT1() LPC_SGPIO1->GPIO_OUTREG1 = 0; |
MBM | 0:56a3009221d3 | 35 | #define SS_NEGATE1() LPC_SGPIO1->GPIO_OUTREG1 = 1<<14; |
MBM | 0:56a3009221d3 | 36 | |
MBM | 0:56a3009221d3 | 37 | #define SPI_SYNC_MASK1 0xff00 |
MBM | 0:56a3009221d3 | 38 | #define SPI_SYNC_WORD1 0x5a00 |
MBM | 0:56a3009221d3 | 39 | #define SPI_SYNC_WORD_DATA1 0x5b00 |
MBM | 0:56a3009221d3 | 40 | #define SPI_MIN_SYNC_COUNT1 5 |
MBM | 0:56a3009221d3 | 41 | |
MBM | 0:56a3009221d3 | 42 | class Spi1 : public Iserial1 |
MBM | 0:56a3009221d3 | 43 | { |
MBM | 0:56a3009221d3 | 44 | public: |
MBM | 0:56a3009221d3 | 45 | Spi1(SerialCallback1 callback1); |
MBM | 0:56a3009221d3 | 46 | |
MBM | 0:56a3009221d3 | 47 | // Iserial methods |
MBM | 0:56a3009221d3 | 48 | virtual int open1(); |
MBM | 0:56a3009221d3 | 49 | virtual int close1(); |
MBM | 0:56a3009221d3 | 50 | virtual int receive1(uint8_t *buf1, uint32_t len1); |
MBM | 0:56a3009221d3 | 51 | virtual int receiveLen1(); |
MBM | 0:56a3009221d3 | 52 | virtual int update1(); |
MBM | 0:56a3009221d3 | 53 | |
MBM | 0:56a3009221d3 | 54 | void slaveHandler1(); |
MBM | 0:56a3009221d3 | 55 | |
MBM | 0:56a3009221d3 | 56 | private: |
MBM | 0:56a3009221d3 | 57 | int checkIdle1(); |
MBM | 0:56a3009221d3 | 58 | int sync1(); |
MBM | 0:56a3009221d3 | 59 | ReceiveQ1<uint16_t> m_rq1; |
MBM | 0:56a3009221d3 | 60 | TransmitQ1<uint16_t> m_tq1; |
MBM | 0:56a3009221d3 | 61 | |
MBM | 0:56a3009221d3 | 62 | bool m_sync1; |
MBM | 0:56a3009221d3 | 63 | uint32_t m_recvCounter1; |
MBM | 0:56a3009221d3 | 64 | uint32_t m_lastRecvCounter1; |
MBM | 0:56a3009221d3 | 65 | uint8_t m_syncCounter1; |
MBM | 0:56a3009221d3 | 66 | }; |
MBM | 0:56a3009221d3 | 67 | |
MBM | 0:56a3009221d3 | 68 | void SPIinit1(SerialCallback1 callback1); |
MBM | 0:56a3009221d3 | 69 | |
MBM | 0:56a3009221d3 | 70 | extern Spi1 *g_spi1; |
MBM | 0:56a3009221d3 | 71 | |
MBM | 0:56a3009221d3 | 72 | #endif |