Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Pixy2.h
00001 //-------------------------------------------------------------------------------------------- 00002 //Original Property of: charmedlabs.com/pixystart -> arduino_pixy-x.y.z.zip 00003 // 00004 //Modifications made by: Mathieu Malone 00005 //Modifications: Modified Arduino code to function with mbed development platform 00006 //Output Method: This program uses "Serial pc(USBTX, USBRX)" in order to allow communication 00007 // between the mbed platform and putty terminal through USB 00008 // 00009 //Latest update by: Mathieu Malone 00010 //Date of last update: July 24th, 2014 00011 //-------------------------------------------------------------------------------------------- 00012 // 00013 // begin license header 00014 // 00015 // This file is part of Pixy CMUcam5 or "Pixy" for short 00016 // 00017 // All Pixy source code is provided under the terms of the 00018 // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html). 00019 // Those wishing to use Pixy source code, software and/or 00020 // technologies under different licensing terms should contact us at 00021 // cmucam@cs.cmu.edu. Such licensing terms are available for 00022 // all portions of the Pixy codebase presented here. 00023 // 00024 // end license header 00025 // 00026 00027 /* 00028 Pixy.h - Library for interfacing with Pixy. 00029 Created by Scott Robinson, October 22, 2013. 00030 Released into the public domain. 00031 00032 06.04.2014 v0.1.3 John Leimon 00033 + LinkSPI.init() should be called from the setup() 00034 function instead of being called automatically from 00035 the TPixy<LinkSPI> constructor in global scope. This 00036 is a workaround for a bug (?) in the Arduino DUE in which 00037 calling SPI.begin() from global scope (via a constructor) 00038 inhibits the operation of the Serial peripheral in the 00039 DUE. [As of: Arduino 1.5.6-r2] 00040 */ 00041 00042 #ifndef PIXY_H2 00043 #define PIXY_H2 00044 00045 #include "TPixy2.h" 00046 #include "SPI2.h" 00047 00048 00049 #define PIXY_SYNC_BYTE2 0x5a 00050 #define PIXY_SYNC_BYTE_DATA2 0x5b 00051 #define PIXY_OUTBUF_SIZE2 6 00052 00053 SPI spi2(p11, p12, p13); // mosi, miso, sclk 00054 00055 class LinkSPI2 00056 { 00057 public: 00058 void init2() 00059 { 00060 outLen2 = 0; 00061 #ifdef __SAM3X8E__ 00062 // DUE clock divider // 00063 SPI.setClockDivider2(84); 00064 #else 00065 // Default clock divider // 00066 //SPI.setClockDivider(SPI_CLOCK_DIV16); 00067 #endif 00068 } 00069 00070 uint16_t getWord2() 00071 { 00072 // ordering is different because Pixy is sending 16 bits through SPI 00073 // instead of 2 bytes in a 16-bit word as with I2C 00074 uint16_t w2; 00075 uint8_t c2, count2 = 0; 00076 00077 if (outLen2) 00078 { 00079 w2 = spi2.write(PIXY_SYNC_BYTE_DATA2); 00080 count2 = outBuf2[outIndex2++]; 00081 if (outIndex2==outLen2) 00082 outLen2 = 0; 00083 } 00084 else 00085 w2 = spi2.write(PIXY_SYNC_BYTE2); 00086 w2 <<= 8; 00087 c2 = spi2.write(count2); 00088 w2 |= c2; 00089 00090 return w2; 00091 } 00092 00093 uint8_t getByte2() 00094 { 00095 return spi2.write(0x00); 00096 } 00097 00098 int8_t send(uint8_t *data2, uint8_t len2) 00099 { 00100 if (len2>PIXY_OUTBUF_SIZE2 || outLen2!=0) 00101 return -1; 00102 memcpy(outBuf2, data2, len2); 00103 outLen2 = len2; 00104 outIndex2 = 0; 00105 return len2; 00106 } 00107 00108 void setAddress2(uint8_t addr2) 00109 { 00110 addr_2 = addr2; 00111 } 00112 00113 private: 00114 uint8_t outBuf2[PIXY_OUTBUF_SIZE2]; 00115 uint8_t outLen2; 00116 uint8_t outIndex2; 00117 uint8_t addr_2; 00118 }; 00119 00120 00121 typedef TPixy2<LinkSPI2> Pixy2; 00122 00123 #endif 00124 00125
Generated on Thu Jul 14 2022 04:45:17 by
1.7.2